Skip to content

Commit

Permalink
Made DB API compliant with SQL Alchemy DB Dialect spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenstott committed Nov 12, 2024
1 parent 610ff48 commit 062336a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.sql.*;
import java.util.*;
import java.util.regex.Pattern;

class ExportedKey {
String pkTableCatalog;
Expand Down Expand Up @@ -118,6 +119,7 @@ public static void setClassLoader() {

Connection connection;
CalciteSchema rootSchema;
boolean sqliteFlag;

public static void noOpMethod() {
Span span = tracer.spanBuilder("noOpMethod").startSpan();
Expand Down Expand Up @@ -268,7 +270,7 @@ private Map<String, ColumnMetadata> getTableColumnInfo(TableMetadata table) {
String schemaName = table.schema;
CalciteSchema schemaPlus = rootSchema.getSubSchema(schemaName, true);
Schema schema = schemaPlus.schema;
boolean sqliteFlag = false;
sqliteFlag = false;
if (schema instanceof JdbcSchema) {
sqliteFlag = ((JdbcSchema) schema).dialect instanceof SQLiteSqlDialect;
}
Expand Down Expand Up @@ -467,6 +469,7 @@ public String queryModels(String query, String parentTraceId, String parentSpanI
try {
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
Pattern timestampPattern = Pattern.compile("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");

while (resultSet.next()) {
Map<String, Object> columns = new LinkedHashMap<>();
Expand All @@ -486,6 +489,9 @@ public String queryModels(String query, String parentTraceId, String parentSpanI
columns.put(metaData.getColumnLabel(i), rfcDateString);
} else if (value instanceof ArrayImpl) {
columns.put(metaData.getColumnLabel(i), ((ArrayImpl) value).getArray());
} else if (sqliteFlag && value instanceof String && metaData.getColumnLabel(i).toLowerCase().contains("date") && timestampPattern.matcher((String) value).matches()) {
String newDate = ((String) value).replace(" ", "T");
columns.put(metaData.getColumnLabel(i), newDate);
}
// if it is not date - put the value directly
else {
Expand Down
2 changes: 1 addition & 1 deletion calcite-rs-jni/py_graphql_sql/py_graphql_sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
try:
logger.debug("Attempting to register the 'hasura.py_graphql_sql' dialect.")
registry.register('hasura.py_graphql_sql', 'py_graphql_sql.sqlalchemy.hasura.ddnbase', 'HasuraDDNDialect')
registry.register('hasura', 'py_graphql_sql.sqlalchemy.hasura.ddnbase', 'HasuraDDNDialect')
# registry.register('hasura', 'py_graphql_sql.sqlalchemy.hasura.ddnbase', 'HasuraDDNDialect')
logger.debug(registry.load('hasura.py_graphql_sql'))
logger.debug("Successfully registered the 'hasura.py_graphql_sql' dialect.")
except Exception as e:
Expand Down
1 change: 0 additions & 1 deletion calcite-rs-jni/py_graphql_sql/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ homepage = "https://github.com/hasura/ndc-calcite"

[project.entry-points."sqlalchemy.dialects"]
"hasura.py_graphql_sql" = "py_graphql_sql.sqlalchemy.hasura.ddnbase:HasuraDDNDialect"
"hasura" = "py_graphql_sql.sqlalchemy.hasura.ddnbase:HasuraDDNDialect"

[tool.setuptools]
packages = { find = {} }
Expand Down
2 changes: 1 addition & 1 deletion calcite-rs-jni/py_graphql_sql/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

try:
# registered_dialects = list(registry._entry_points.keys())
dialect_names = list(sqlalchemy.dialects.registry.impls)
dialect_names = list(sqlalchemy.dialects.registry.impls) + list(sqlalchemy.dialects.__all__)
print(dialect_names)
print(f"\nCreating engine with URL: {url}")
engine = create_engine(url, echo=True)
Expand Down

0 comments on commit 062336a

Please sign in to comment.