|
66 | 66 | "SQL_LINEAGE_TIMEOUT_ENABLED", True
|
67 | 67 | )
|
68 | 68 | SQL_LINEAGE_TIMEOUT_SECONDS = 10
|
| 69 | +SQL_PARSER_TRACE = get_boolean_env_variable("DATAHUB_SQL_PARSER_TRACE", False) |
69 | 70 |
|
70 | 71 |
|
71 | 72 | # These rules are a subset of the rules in sqlglot.optimizer.optimizer.RULES.
|
@@ -365,10 +366,11 @@ def _sqlglot_force_column_normalizer(
|
365 | 366 |
|
366 | 367 | return node
|
367 | 368 |
|
368 |
| - # logger.debug( |
369 |
| - # "Prior to case normalization sql %s", |
370 |
| - # statement.sql(pretty=True, dialect=dialect), |
371 |
| - # ) |
| 369 | + if SQL_PARSER_TRACE: |
| 370 | + logger.debug( |
| 371 | + "Prior to case normalization sql %s", |
| 372 | + statement.sql(pretty=True, dialect=dialect), |
| 373 | + ) |
372 | 374 | statement = statement.transform(_sqlglot_force_column_normalizer, copy=False)
|
373 | 375 | # logger.debug(
|
374 | 376 | # "Sql after casing normalization %s",
|
@@ -562,7 +564,7 @@ def _select_statement_cll( # noqa: C901
|
562 | 564 | )
|
563 | 565 | )
|
564 | 566 |
|
565 |
| - # TODO: Also extract referenced columns (aka auxillary / non-SELECT lineage) |
| 567 | + # TODO: Also extract referenced columns (aka auxiliary / non-SELECT lineage) |
566 | 568 | except (sqlglot.errors.OptimizeError, ValueError, IndexError) as e:
|
567 | 569 | raise SqlUnderstandingError(
|
568 | 570 | f"sqlglot failed to compute some lineage: {e}"
|
@@ -1022,6 +1024,14 @@ def _sqlglot_lineage_inner(
|
1022 | 1024 | logger.debug(
|
1023 | 1025 | f"Resolved {total_schemas_resolved} of {total_tables_discovered} table schemas"
|
1024 | 1026 | )
|
| 1027 | + if SQL_PARSER_TRACE: |
| 1028 | + for qualified_table, schema_info in table_name_schema_mapping.items(): |
| 1029 | + logger.debug( |
| 1030 | + "Table name %s resolved to %s with schema %s", |
| 1031 | + qualified_table, |
| 1032 | + table_name_urn_mapping[qualified_table], |
| 1033 | + schema_info, |
| 1034 | + ) |
1025 | 1035 |
|
1026 | 1036 | column_lineage: Optional[List[_ColumnLineageInfo]] = None
|
1027 | 1037 | try:
|
|
0 commit comments