Skip to content

Commit

Permalink
Downgraded all Java 21 dependent code to Java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
kenstott committed Oct 10, 2024
1 parent 533b0d0 commit 5de6054
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 168 deletions.
112 changes: 56 additions & 56 deletions calcite-rs-jni/jni/src/main/java/org/kenstott/CalciteQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private Collection<TableMetadata> getTables() {
tableTypeList.add(tableType);
}
}
} catch (SQLException e) {
} catch (Throwable e) {
logger.error(e.toString());
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -240,11 +240,11 @@ private Collection<TableMetadata> getTables() {
} catch (SQLException e) { /* ignore */ }
list.add(new TableMetadata(catalog, schemaName, tableName, remarks, primaryKeys, exportedKeys, localCatalogName, localSchemaName));
}
} catch (Exception e) {
} catch (Throwable e) {
span.setAttribute("Error", e.toString());
}
}
} catch(Exception e) {
} catch (Throwable e) {
System.err.println(e.toString());
}
}
Expand Down Expand Up @@ -280,54 +280,54 @@ private Map<String, ColumnMetadata> getTableColumnInfo(TableMetadata table) {
String description = columnsSet.getString("REMARKS");
String dataTypeName = columnsSet.getString("TYPE_NAME");
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"),
entry("VARCHAR NOT NULL", "VARCHAR"),
entry("JavaType(class java.util.ArrayList)", "LIST"),
entry("JavaType(class org.apache.calcite.adapter.file.ComparableArrayList)", "LIST"),
entry("ANY ARRAY", "LIST"),
entry("VARCHAR NOT NULL ARRAY", "LIST"),
entry("JavaType(class java.util.LinkedHashMap)", "MAP"),
entry("JavaType(class org.apache.calcite.adapter.file.ComparableLinkedHashMap)", "MAP"),
entry("JavaType(class java.lang.String)", "VARCHAR"),
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"),
entry("TINYINT", "INTEGER"),
entry("BIGINT NOT NULL", "INTEGER"),
entry("BIGINT", "INTEGER"),
entry("FLOAT NOT NULL", "FLOAT"),
entry("FLOAT", "FLOAT"),
entry("DOUBLE NOT NULL", "DOUBLE"),
entry("DOUBLE", "DOUBLE"),
entry("BOOLEAN NOT NULL", "BOOLEAN"),
entry("BOOLEAN", "BOOLEAN"),
entry("VARBINARY NOT NULL", "VARBINARY"),
entry("VARBINARY", "VARBINARY"),
entry("BINARY NOT NULL", "BINARY"),
entry("BINARY", "BINARY"),
entry("DATE NOT NULL", "DATE"),
entry("DATE", "DATE"),
entry("TIME(0) NOT NULL", "TIME"),
entry("TIME(0)", "TIME"),
entry("TIMESTAMP(0) NOT NULL", "TIMESTAMP"),
entry("TIMESTAMP(0)", "TIMESTAMP"),
entry("TIMESTAMP(3) NOT NULL", "TIMESTAMP"),
entry("TIMESTAMP(3)", "TIMESTAMP"),
entry("TIMESTAMP NOT NULL", "TIMESTAMPTZ"),
entry("TIMESTAMP", "TIMESTAMPTZ"),
entry("DECIMAL(10,2)", "FLOAT"),
entry("DECIMAL(12,2)", "FLOAT")
);
Map<String, String> remapTypes = new HashMap<>();
remapTypes.put("CHAR", "CHAR");
remapTypes.put("CHAR(1)", "VARCHAR");
remapTypes.put("VARCHAR", "VARCHAR");
remapTypes.put("VARCHAR(65536)", "VARCHAR");
remapTypes.put("VARCHAR(65536) NOT NULL", "VARCHAR");
remapTypes.put("VARCHAR NOT NULL", "VARCHAR");
remapTypes.put("JavaType(class java.util.ArrayList)", "LIST");
remapTypes.put("JavaType(class org.apache.calcite.adapter.file.ComparableArrayList)", "LIST");
remapTypes.put("ANY ARRAY", "LIST");
remapTypes.put("VARCHAR NOT NULL ARRAY", "LIST");
remapTypes.put("JavaType(class java.util.LinkedHashMap)", "MAP");
remapTypes.put("JavaType(class org.apache.calcite.adapter.file.ComparableLinkedHashMap)", "MAP");
remapTypes.put("JavaType(class java.lang.String)", "VARCHAR");
remapTypes.put("JavaType(class java.lang.Integer)", "INTEGER");
remapTypes.put("INTEGER NOT NULL", "INTEGER");
remapTypes.put("INTEGER", "INTEGER");
remapTypes.put("JSON", "JSON");
remapTypes.put("JSONB", "JSON");
remapTypes.put("SMALLINT NOT NULL", "INTEGER");
remapTypes.put("SMALLINT", "INTEGER");
remapTypes.put("TINYINT NOT NULL", "INTEGER");
remapTypes.put("TINYINT", "INTEGER");
remapTypes.put("BIGINT NOT NULL", "INTEGER");
remapTypes.put("BIGINT", "INTEGER");
remapTypes.put("FLOAT NOT NULL", "FLOAT");
remapTypes.put("FLOAT", "FLOAT");
remapTypes.put("DOUBLE NOT NULL", "DOUBLE");
remapTypes.put("DOUBLE", "DOUBLE");
remapTypes.put("BOOLEAN NOT NULL", "BOOLEAN");
remapTypes.put("BOOLEAN", "BOOLEAN");
remapTypes.put("VARBINARY NOT NULL", "VARBINARY");
remapTypes.put("VARBINARY", "VARBINARY");
remapTypes.put("BINARY NOT NULL", "BINARY");
remapTypes.put("BINARY", "BINARY");
remapTypes.put("DATE NOT NULL", "DATE");
remapTypes.put("DATE", "DATE");
remapTypes.put("TIME(0) NOT NULL", "TIME");
remapTypes.put("TIME(0)", "TIME");
remapTypes.put("TIMESTAMP(0) NOT NULL", "TIMESTAMP");
remapTypes.put("TIMESTAMP(0)", "TIMESTAMP");
remapTypes.put("TIMESTAMP(3) NOT NULL", "TIMESTAMP");
remapTypes.put("TIMESTAMP(3)", "TIMESTAMP");
remapTypes.put("TIMESTAMP NOT NULL", "TIMESTAMPTZ");
remapTypes.put("TIMESTAMP", "TIMESTAMPTZ");
remapTypes.put("DECIMAL(10,2)", "FLOAT");
remapTypes.put("DECIMAL(12,2)", "FLOAT");

String mappedType = remapTypes.get(dataTypeName);
if (mappedType == null) {
if (dataTypeName.toLowerCase().contains("varchar") && !dataTypeName.toLowerCase().endsWith("map")) {
Expand Down Expand Up @@ -474,13 +474,13 @@ public String queryModels(String query, String parentTraceId, String parentSpanI
Object value = resultSet.getObject(i);

// handling Dates and Timestamps
if (value instanceof java.sql.Date sqlDate) {
if (value instanceof java.sql.Date) {
java.sql.Date sqlDate = (java.sql.Date) value;
java.util.Date utilDate = new java.util.Date(sqlDate.getTime());
String rfcDateString = rfcDateFormat.format(utilDate.toInstant());
columns.put(metaData.getColumnLabel(i), rfcDateString);
}
else if (value instanceof java.sql.Timestamp sqlTimestamp) {
// convert to java.util.Date first
} else if (value instanceof java.sql.Timestamp) {
java.sql.Timestamp sqlTimestamp = (java.sql.Timestamp) value;
java.util.Date utilDate = new java.util.Date(sqlTimestamp.getTime());
String rfcDateString = rfcFormat.format(utilDate.toInstant());
columns.put(metaData.getColumnLabel(i), rfcDateString);
Expand All @@ -492,7 +492,7 @@ else if (value instanceof java.sql.Timestamp sqlTimestamp) {
}
rows.add(columns);
}
} catch(Exception e) {
} catch(Throwable e) {
e.printStackTrace();
} finally {
resultSet.close();
Expand Down
15 changes: 2 additions & 13 deletions calcite-rs-jni/jni/src/main/java/org/kenstott/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
public class Main {
public static void main(String[] args) throws IOException, SQLException, ClassNotFoundException {

// String jdbcUrl = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443?ProjectId=MyProject26996&OAuthType=0&[email protected]";
// String encodedUrl = URLEncoder.encode(url, StandardCharsets.UTF_8.toString());
// System.out.println(encodedUrl);
// Class.forName("com.simba.googlebigquery.jdbc42.Driver");
// Connection conn = DriverManager.getConnection(jdbcUrl);

String modelPath = "../../adapters/databricks/model.json";
String modelPath = "../../adapters/file/model.json";
String username = "<username>";
String password = "<password>";
Connection calciteConnection = null;
Expand All @@ -30,12 +24,7 @@ public static void main(String[] args) throws IOException, SQLException, ClassNo
calciteConnection = query.createCalciteConnection(modelPath);
String x = query.getModels();
System.out.println(x);
String q1 = """
SELECT * from "lineitem"
OFFSET 2 ROWS
FETCH NEXT 5 ROWS ONLY
""";
String q1 = "SELECT * from \"DEPTS\"";
String z1 = query.queryModels(q1);
System.out.println(z1);
// String z2 = query.queryModels("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ public void unparseCall(SqlWriter writer, SqlCall call, int leftPrec, int rightP
String phrasesList = String.join(", ", selectItems);

// Create the new SQL query
String newSqlQuery = String.format("""
SELECT %s FROM "%s" WHERE "%s" IN (%s)""", phrasesList, tableName, idColumn, valuesList);
String newSqlQuery = String.format(
"\n SELECT %s FROM \"%s\" WHERE \"%s\" IN (%s)",
phrasesList, tableName, idColumn, valuesList
);
writer.reset();
writer.print(newSqlQuery);
} else {
Expand Down
Loading

0 comments on commit 5de6054

Please sign in to comment.