Skip to content

Commit

Permalink
Improved data type introspection for JSON-like column types.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenstott committed Sep 21, 2024
1 parent 9ef9fe8 commit cec42d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion calcite-rs-jni/src/main/java/org/kenstott/CalciteQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ private Collection<TableMetadata> getTables() {
span.setAttribute("Error", e.toString());
}
}
} catch(Exception e) {
System.err.println(e.toString());
}
}
}
Expand Down Expand Up @@ -270,6 +272,7 @@ private Map<String, ColumnMetadata> getTableColumnInfo(TableMetadata table) {
boolean nullable = columnsSet.getBoolean("NULLABLE");
Map<String, String> remapTypes = Map.ofEntries(
entry("CHAR", "CHAR"),
entry("CHAR(1)", "VARCHAR"),
entry("VARCHAR", "VARCHAR"),
entry("VARCHAR(65536)", "VARCHAR"),
entry("VARCHAR(65536) NOT NULL", "VARCHAR"),
Expand All @@ -283,6 +286,8 @@ private Map<String, ColumnMetadata> getTableColumnInfo(TableMetadata table) {
entry("JavaType(class java.lang.Integer)", "INTEGER"),
entry("INTEGER NOT NULL", "INTEGER"),
entry("INTEGER", "INTEGER"),
entry("JSON", "JSON"),
entry("JSONB", "JSON"),
entry("SMALLINT NOT NULL", "INTEGER"),
entry("SMALLINT", "INTEGER"),
entry("TINYINT NOT NULL", "INTEGER"),
Expand Down Expand Up @@ -314,14 +319,18 @@ private Map<String, ColumnMetadata> getTableColumnInfo(TableMetadata table) {
);
String mappedType = remapTypes.get(dataTypeName);
if (mappedType == null) {
if (dataTypeName.toLowerCase().contains("varchar")) {
if (dataTypeName.toLowerCase().contains("varchar") && !dataTypeName.toLowerCase().endsWith("map")) {
mappedType = "VARCHAR";
} else if (dataTypeName.toLowerCase().contains("timestamp")) {
mappedType = "TIMESTAMP";
} else if (dataTypeName.toLowerCase().contains("decimal")) {
mappedType = "FLOAT";
} else if (dataTypeName.toLowerCase().startsWith("any")) {
mappedType = "VARBINARY";
} else if (dataTypeName.toLowerCase().endsWith("map")) {
mappedType = "MAP";
} else if (dataTypeName.toLowerCase().contains("for json")) {
mappedType = "JSON";
} else {
span.setAttribute(dataTypeName, "unknown column type");
mappedType = "VARCHAR";
Expand Down
2 changes: 1 addition & 1 deletion crates/calcite-schema/src/calcite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub struct Operand {
#[serde(skip_serializing_if = "Option::is_none")]
pub ssl: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dc: Option<bool>,
pub dc: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "pathToCert")]
pub path_to_cert: Option<String>,
Expand Down

0 comments on commit cec42d6

Please sign in to comment.