Skip to content

Commit

Permalink
Merge pull request #19 from jwills/jwills_better_presto_errors
Browse files Browse the repository at this point in the history
Bunch of fixes to make the Presto stuff work with DBeaver better
  • Loading branch information
jwills committed May 16, 2023
2 parents 87ea91a + 6b9ee5a commit 66cd34f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
4 changes: 2 additions & 2 deletions buenavista/backends/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def to_bvtype(t: pa.DataType) -> BVType:
return BVType.BIGINT
elif pa.types.is_integer(t):
return BVType.INTEGER
elif pa.types.is_string(t):
elif pa.types.is_string(t) or pa.types.is_large_string(t):
return BVType.TEXT
elif pa.types.is_date(t):
return BVType.DATE
Expand Down Expand Up @@ -47,7 +47,7 @@ def to_bvtype(t: pa.DataType) -> BVType:
# TODO: support detailed nested types
return BVType.JSON
else:
return BVType.UNKNOWN
raise Exception("Could not convert DuckDB type: " + str(t))


class RecordBatchIterator(Iterator[List[Optional[str]]]):
Expand Down
33 changes: 25 additions & 8 deletions buenavista/bv_dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,33 @@ def _duckdb_command_handler(self, expression):
tokens = literal.split()
entity = tokens[0].upper()
if entity == "CATALOGS":
return "SELECT DISTINCT catalog_name as Catalog FROM information_schema.schemata"
# TODO: LIKE
q = "SELECT DISTINCT catalog_name as Catalog FROM information_schema.schemata"
if len(tokens) == 3:
q += " WHERE catalog_name LIKE " + tokens[2]
else:
return q
elif entity == "SCHEMAS":
return (
"SELECT DISTINCT schema_name as Schema FROM information_schema.schemata"
)
# TODO: LIKE
q = "SELECT DISTINCT schema_name as Schema FROM information_schema.schemata"
if len(tokens) > 1 and tokens[1].upper() == "FROM":
q += f" WHERE catalog_name = '{tokens[2]}'"
if len(tokens) == 5:
q += " AND schema_name LIKE " + tokens[4]
else:
q += " WHERE catalog_name IN (SELECT current_database())"
if len(tokens) == 3:
q += " AND schema_name LIKE " + tokens[2]
return q
elif entity == "TABLES":
return "SELECT DISTINCT table_name as Table from information_schema.tables"
# TODO: LIKE
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]}'"
if len(tokens) == 5:
q += " AND table_name LIKE " + tokens[4]
else:
q += " WHERE catalog_name IN (SELECT current_schema())"
if len(tokens) == 3:
q += " AND table_name LIKE " + tokens[2]
return q
elif entity == "COLUMNS" and tokens[1].upper() == "FROM":
return f"DESCRIBE {tokens[2]}"
elif entity == "TRANSACTION":
Expand Down
2 changes: 1 addition & 1 deletion buenavista/http/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _execute(ctx: context.Context, query: str) -> schemas.BaseResult:
id=id,
info_uri="http://127.0.0.1/info",
error=schemas.QueryError(
message=str(e),
message=f"Received error '{e}' executing query {query}",
error_code=-1,
retriable=False,
),
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/duckdb/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def duckdb_postgres_server(db, user_password):
finally:
db.close()


@pytest.fixture(scope="session")
def conn(duckdb_postgres_server, user_password):
assert duckdb_postgres_server is not None
Expand All @@ -43,8 +44,9 @@ def test_select(conn):
assert cur.fetchone() == (1,)
cur.close()


def test_pg_version(conn):
cur = conn.cursor()
cur.execute("SELECT pg_catalog.version()")
assert cur.fetchone() == ("PostgreSQL 9.3",)
cur.close()
cur.close()

0 comments on commit 66cd34f

Please sign in to comment.