Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arrow-format/FlightSql.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ message CommandGetDbSchemas {
* - ARROW:FLIGHT:SQL:IS_READ_ONLY - "1" indicates if the column is read only, "0" otherwise.
* - ARROW:FLIGHT:SQL:IS_SEARCHABLE - "1" indicates if the column is searchable via WHERE clause, "0" otherwise.
* - ARROW:FLIGHT:SQL:REMARKS - A comment describing the column.
* - ARROW:FLIGHT:SQL:COLUMN_DEF - The default value for the column.
* The returned data should be ordered by catalog_name, db_schema_name, table_name, then table_type, followed by table_schema if requested.
*/
message CommandGetTables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ private int setGetColumnsVectorSchemaRootFromFields(
final VarCharVector tableSchemVector = (VarCharVector) currentRoot.getVector("TABLE_SCHEM");
final VarCharVector tableNameVector = (VarCharVector) currentRoot.getVector("TABLE_NAME");
final VarCharVector columnNameVector = (VarCharVector) currentRoot.getVector("COLUMN_NAME");
final VarCharVector columnDefVector = (VarCharVector) currentRoot.getVector("COLUMN_DEF");
final IntVector dataTypeVector = (IntVector) currentRoot.getVector("DATA_TYPE");
final VarCharVector typeNameVector = (VarCharVector) currentRoot.getVector("TYPE_NAME");
final IntVector columnSizeVector = (IntVector) currentRoot.getVector("COLUMN_SIZE");
Expand Down Expand Up @@ -1131,6 +1132,11 @@ private int setGetColumnsVectorSchemaRootFromFields(
columnNameVector.setSafe(insertIndex, columnName.getBytes(CHARSET));
}

final String columnDef = columnMetadata.getDefaultValue();
if (columnDef != null) {
columnDefVector.setSafe(insertIndex, columnDef.getBytes(CHARSET));
}

dataTypeVector.setSafe(insertIndex, SqlTypes.getSqlTypeIdFromArrowType(fieldType));
byte[] typeName =
columnMetadata.getTypeName() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public class ArrowDatabaseMetadataTest {
List<Integer> expectedGetColumnsColumnSize = Arrays.asList(5, 29, 10);
List<Integer> expectedGetColumnsDecimalDigits = Arrays.asList(2, 9, 0);
List<String> expectedGetColumnsIsNullable = Arrays.asList("YES", "YES", "NO");
List<String> expectedGetColumnsDefaultValue = Arrays.asList("123.45", null, "1");
EXPECTED_GET_COLUMNS_RESULTS =
range(0, ROW_COUNT * 3)
.mapToObj(
Expand All @@ -325,7 +326,7 @@ public class ArrowDatabaseMetadataTest {
expectedGetColumnsRadix.get(i % 3),
!Objects.equals(expectedGetColumnsIsNullable.get(i % 3), "NO") ? 1 : 0,
format("column description #%d", (i % 3) + 1),
null,
expectedGetColumnsDefaultValue.get(i % 3),
null,
null,
null,
Expand Down Expand Up @@ -430,6 +431,7 @@ public static void setUpBeforeClass() throws SQLException {
null,
new FlightSqlColumnMetadata.Builder()
.remarks("column description #1")
.defaultValue("123.45")
.build()
.getMetadataMap()),
null);
Expand All @@ -454,6 +456,7 @@ public static void setUpBeforeClass() throws SQLException {
null,
new FlightSqlColumnMetadata.Builder()
.remarks("column description #3")
.defaultValue("1")
.build()
.getMetadataMap()),
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class FlightSqlColumnMetadata {
private static final String TYPE_NAME = "ARROW:FLIGHT:SQL:TYPE_NAME";
private static final String PRECISION = "ARROW:FLIGHT:SQL:PRECISION";
private static final String SCALE = "ARROW:FLIGHT:SQL:SCALE";
private static final String DEFAULT_VALUE = "ARROW:FLIGHT:SQL:COLUMN_DEF";
private static final String IS_AUTO_INCREMENT = "ARROW:FLIGHT:SQL:IS_AUTO_INCREMENT";
private static final String IS_CASE_SENSITIVE = "ARROW:FLIGHT:SQL:IS_CASE_SENSITIVE";
private static final String IS_READ_ONLY = "ARROW:FLIGHT:SQL:IS_READ_ONLY";
Expand Down Expand Up @@ -138,6 +139,15 @@ public Integer getScale() {
return Integer.valueOf(value);
}

/**
* Returns the default value of the column.
*
* @return The default value of the column.
*/
public String getDefaultValue() {
return metadataMap.get(DEFAULT_VALUE);
}

/**
* Returns if the column is auto incremented.
*
Expand Down Expand Up @@ -278,6 +288,17 @@ public Builder scale(int scale) {
return this;
}

/**
* Sets the column's default value.
*
* @param defaultValue The column's default value.
* @return This builder.
*/
public Builder defaultValue(String defaultValue) {
metadataMap.put(DEFAULT_VALUE, defaultValue);
return this;
}

/**
* Sets if the column is auto incremented.
*
Expand Down
Loading