Skip to content

Commit 85c8e60

Browse files
authored
fix(ingest): consider sql parsing fallback as failure (#11896)
1 parent 44affd7 commit 85c8e60

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

metadata-ingestion/src/datahub/cli/check_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ def sql_lineage(
268268
)
269269

270270
logger.debug("Sql parsing debug info: %s", lineage.debug_info)
271-
if lineage.debug_info.error:
271+
if lineage.debug_info.table_error:
272+
raise lineage.debug_info.table_error
273+
elif lineage.debug_info.error:
272274
logger.debug("Sql parsing error details", exc_info=lineage.debug_info.error)
273275

274276
click.echo(lineage.json(indent=4))

metadata-ingestion/src/datahub/sql_parsing/sqlglot_lineage.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,15 @@ def _sqlglot_lineage_inner(
904904
logger.debug("Parsing lineage from sql statement: %s", sql)
905905
statement = parse_statement(sql, dialect=dialect)
906906

907+
if isinstance(statement, sqlglot.exp.Command):
908+
# For unsupported syntax, sqlglot will usually fallback to parsing as a Command.
909+
# This is effectively a parsing error, and we won't get any lineage from it.
910+
# See https://github.com/tobymao/sqlglot/commit/3a13fdf4e597a2f0a3f9fc126a129183fe98262f
911+
# and https://github.com/tobymao/sqlglot/pull/2874
912+
raise UnsupportedStatementTypeError(
913+
f"Got unsupported syntax for statement: {sql}"
914+
)
915+
907916
original_statement, statement = statement, statement.copy()
908917
# logger.debug(
909918
# "Formatted sql statement: %s",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"query_type": "UNKNOWN",
3+
"query_type_props": {},
4+
"query_fingerprint": null,
5+
"in_tables": [],
6+
"out_tables": [],
7+
"column_lineage": null,
8+
"debug_info": {
9+
"confidence": 0.0,
10+
"generalized_statement": null
11+
}
12+
}

metadata-ingestion/tests/unit/sql_parsing/test_sqlglot_lineage.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,3 +1268,14 @@ def test_bigquery_subquery_column_inference() -> None:
12681268
dialect="bigquery",
12691269
expected_file=RESOURCE_DIR / "test_bigquery_subquery_column_inference.json",
12701270
)
1271+
1272+
1273+
def test_sqlite_attach_database() -> None:
1274+
assert_sql_result(
1275+
"""\
1276+
ATTACH DATABASE ':memory:' AS aux1
1277+
""",
1278+
dialect="sqlite",
1279+
expected_file=RESOURCE_DIR / "test_sqlite_attach_database.json",
1280+
allow_table_error=True,
1281+
)

0 commit comments

Comments
 (0)