Skip to content

Commit

Permalink
ARROW-17659: [Java] Populate JDBC schema name metadata when config.sh…
Browse files Browse the repository at this point in the history
…ouldIncludeMetadata provided (apache#14196)

Current implementation include [catalog,table,column,type](https://github.com/apache/arrow/blob/master/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java#L248) metadata, but schema metadata field is missing. In terms of PostgreSQL catalog - is database, schema - namespace inside database, so catalog name is insufficient for table addressing without schema.

Proposed changes is + metadata.put(Constants.SQL_SCHEMA_KEY, rsmd.getSchemaName(i));

Authored-by: igor.suhorukov <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
igor-suhorukov authored and fatemehp committed Oct 17, 2022
1 parent b339a87 commit 75dfe77
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Constants {
private Constants() {}

public static final String SQL_CATALOG_NAME_KEY = "SQL_CATALOG_NAME";
public static final String SQL_SCHEMA_NAME_KEY = "SQL_SCHEMA_NAME";
public static final String SQL_TABLE_NAME_KEY = "SQL_TABLE_NAME";
public static final String SQL_COLUMN_NAME_KEY = "SQL_COLUMN_NAME";
public static final String SQL_TYPE_KEY = "SQL_TYPE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig
if (config.shouldIncludeMetadata()) {
metadata = new HashMap<>();
metadata.put(Constants.SQL_CATALOG_NAME_KEY, rsmd.getCatalogName(i));
metadata.put(Constants.SQL_SCHEMA_NAME_KEY, rsmd.getSchemaName(i));
metadata.put(Constants.SQL_TABLE_NAME_KEY, rsmd.getTableName(i));
metadata.put(Constants.SQL_COLUMN_NAME_KEY, columnName);
metadata.put(Constants.SQL_TYPE_KEY, rsmd.getColumnTypeName(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,10 @@ public static void assertFieldMetadataMatchesResultSetMetadata(ResultSetMetaData
Map<String, String> metadata = fields.get(i - 1).getMetadata();

assertNotNull(metadata);
assertEquals(4, metadata.size());
assertEquals(5, metadata.size());

assertEquals(rsmd.getCatalogName(i), metadata.get(Constants.SQL_CATALOG_NAME_KEY));
assertEquals(rsmd.getSchemaName(i), metadata.get(Constants.SQL_SCHEMA_NAME_KEY));
assertEquals(rsmd.getTableName(i), metadata.get(Constants.SQL_TABLE_NAME_KEY));
assertEquals(rsmd.getColumnLabel(i), metadata.get(Constants.SQL_COLUMN_NAME_KEY));
assertEquals(rsmd.getColumnTypeName(i), metadata.get(Constants.SQL_TYPE_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
},
"children" : [ ],
"metadata" : [ {
"value" : "Record identifier",
"key" : "comment"
}, {
"value" : "TABLE1",
"key" : "SQL_TABLE_NAME"
"value" : "PUBLIC",
"key" : "SQL_SCHEMA_NAME"
}, {
"value" : "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8",
"key" : "SQL_CATALOG_NAME"
Expand All @@ -23,6 +20,12 @@
}, {
"value" : "BIGINT",
"key" : "SQL_TYPE"
}, {
"value" : "Record identifier",
"key" : "comment"
}, {
"value" : "TABLE1",
"key" : "SQL_TABLE_NAME"
} ]
}, {
"name" : "NAME",
Expand All @@ -32,11 +35,8 @@
},
"children" : [ ],
"metadata" : [ {
"value" : "Name of record",
"key" : "comment"
}, {
"value" : "TABLE1",
"key" : "SQL_TABLE_NAME"
"value" : "PUBLIC",
"key" : "SQL_SCHEMA_NAME"
}, {
"value" : "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8",
"key" : "SQL_CATALOG_NAME"
Expand All @@ -46,6 +46,12 @@
}, {
"value" : "VARCHAR",
"key" : "SQL_TYPE"
}, {
"value" : "Name of record",
"key" : "comment"
}, {
"value" : "TABLE1",
"key" : "SQL_TABLE_NAME"
} ]
}, {
"name" : "COLUMN1",
Expand All @@ -55,6 +61,9 @@
},
"children" : [ ],
"metadata" : [ {
"value" : "PUBLIC",
"key" : "SQL_SCHEMA_NAME"
}, {
"value" : "TABLE1",
"key" : "SQL_TABLE_NAME"
}, {
Expand All @@ -77,11 +86,8 @@
},
"children" : [ ],
"metadata" : [ {
"value" : "Informative description of columnN",
"key" : "comment"
}, {
"value" : "TABLE1",
"key" : "SQL_TABLE_NAME"
"value" : "PUBLIC",
"key" : "SQL_SCHEMA_NAME"
}, {
"value" : "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8",
"key" : "SQL_CATALOG_NAME"
Expand All @@ -91,6 +97,12 @@
}, {
"value" : "INTEGER",
"key" : "SQL_TYPE"
}, {
"value" : "Informative description of columnN",
"key" : "comment"
}, {
"value" : "TABLE1",
"key" : "SQL_TABLE_NAME"
} ]
} ],
"metadata" : [ {
Expand Down

0 comments on commit 75dfe77

Please sign in to comment.