Skip to content

Commit

Permalink
Merge pull request #21 from jwills/jwills_datagrip_presto_hacking
Browse files Browse the repository at this point in the history
Fixes I found while integrating the BV Presto stuff with DataGrip
  • Loading branch information
jwills committed May 19, 2023
2 parents d7b83e7 + 41c02af commit 5133d53
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion buenavista/backends/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def to_bvtype(t: pa.DataType) -> BVType:
return BVType.STRINGARRAY
else:
# TODO: detailed nested types
return BVType.ARRAY
return BVType.JSON
elif pa.types.is_struct(t) or pa.types.is_map(t):
# TODO: support detailed nested types
return BVType.JSON
Expand Down
4 changes: 2 additions & 2 deletions buenavista/bv_dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ def _duckdb_command_handler(self, expression):
elif entity == "TABLES":
q = "SELECT DISTINCT table_name as Table from information_schema.tables"
if len(tokens) > 1 and tokens[1].upper() == "FROM":
q += f" WHERE schema_name = '{tokens[2]}'"
q += f" WHERE table_schema = '{tokens[2]}'"
if len(tokens) >= 5:
if len(tokens) == 7:
like = tokens[4].replace(tokens[6], "")
else:
like = tokens[4]
q += " AND table_name LIKE " + like
else:
q += " WHERE catalog_name IN (SELECT current_schema())"
q += " WHERE table_schema IN (SELECT current_schema())"
if len(tokens) >= 3:
if len(tokens) == 5:
like = tokens[2].replace(tokens[4], "")
Expand Down
29 changes: 28 additions & 1 deletion buenavista/examples/duckdb_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def jdbc_catalogs():

@rewriter.relation("system.jdbc.table_types")
def jdbc_table_types():
return "SELECT * FROM VALUES ('TABLE'), ('VIEW') AS t(table_type)"
return "SELECT * FROM VALUES ('BASE TABLE'), ('VIEW') AS t(table_type)"


@rewriter.relation("system.jdbc.columns")
Expand Down Expand Up @@ -111,6 +111,33 @@ def jdbc_procedures():
"""


@rewriter.relation("system.jdbc.procedure_columns")
def jdbc_procedure_columns():
return """
SELECT CAST(NULL AS VARCHAR) as procedure_cat
, CAST(NULL AS VARCHAR) as procedure_schem
, CAST(NULL AS VARCHAR) as procedure_name
, CAST(NULL AS VARCHAR) as column_name
, CAST(NULL AS BIGINT) as column_type
, CAST(NULL AS BIGINT) as data_type
, CAST(NULL AS VARCHAR) as type_name
, CAST(NULL AS BIGINT) as precision
, CAST(NULL AS BIGINT) as length
, CAST(NULL AS BIGINT) as scale
, CAST(NULL AS BIGINT) as radix
, CAST(NULL AS BIGINT) as nullable
, CAST(NULL AS VARCHAR) as remarks
, CAST(NULL AS VARCHAR) as column_def
, CAST(NULL AS BIGINT) as sql_data_type
, CAST(NULL AS BIGINT) as sql_datetime_sub
, CAST(NULL AS BIGINT) as char_octet_length
, CAST(NULL AS BIGINT) as ordinal_position
, CAST(NULL AS VARCHAR) as is_nullable
, CAST(NULL AS VARCHAR) as specific_name
WHERE false
"""


if __name__ == "__main__":
import uvicorn

Expand Down
2 changes: 1 addition & 1 deletion buenavista/http/type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _string_col(name: str):


def type_converter(bvtype: BVType) -> Callable:
if bvtype == BVType.DECIMAL:
if bvtype in (BVType.DECIMAL, BVType.TIMESTAMP, BVType.TIME, BVType.DATE):
return lambda x: str(x) if x else None
return lambda x: x

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/duckdb/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def duckdb_postgres_server(db, user_password):
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()
time.sleep(1) # wait for server to start
time.sleep(1) # wait for server to start
yield server
finally:
db.close()
Expand Down

0 comments on commit 5133d53

Please sign in to comment.