acryl-datahub 1.2.0.7rc4__py3-none-any.whl → 1.2.0.8rc2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of acryl-datahub might be problematic. Click here for more details.
- {acryl_datahub-1.2.0.7rc4.dist-info → acryl_datahub-1.2.0.8rc2.dist-info}/METADATA +2612 -2612
- {acryl_datahub-1.2.0.7rc4.dist-info → acryl_datahub-1.2.0.8rc2.dist-info}/RECORD +35 -33
- datahub/_version.py +1 -1
- datahub/cli/delete_cli.py +1 -0
- datahub/ingestion/api/report.py +4 -0
- datahub/ingestion/autogenerated/capability_summary.json +1 -1
- datahub/ingestion/graph/client.py +8 -1
- datahub/ingestion/source/datahub/config.py +4 -0
- datahub/ingestion/source/datahub/datahub_database_reader.py +6 -1
- datahub/ingestion/source/iceberg/iceberg.py +74 -32
- datahub/ingestion/source/metadata/lineage.py +8 -8
- datahub/ingestion/source/redshift/redshift.py +1 -1
- datahub/ingestion/source/sql/athena.py +95 -18
- datahub/ingestion/source/sql/athena_properties_extractor.py +43 -25
- datahub/ingestion/source/superset.py +3 -2
- datahub/ingestion/source/tableau/tableau.py +8 -5
- datahub/metadata/_internal_schema_classes.py +207 -12
- datahub/metadata/com/linkedin/pegasus2avro/settings/asset/__init__.py +19 -0
- datahub/metadata/com/linkedin/pegasus2avro/template/__init__.py +6 -0
- datahub/metadata/schema.avsc +160 -12
- datahub/metadata/schemas/AssetSettings.avsc +63 -0
- datahub/metadata/schemas/DataHubPageModuleProperties.avsc +9 -1
- datahub/metadata/schemas/DataHubPageTemplateProperties.avsc +77 -1
- datahub/metadata/schemas/DataProductKey.avsc +2 -1
- datahub/metadata/schemas/DomainKey.avsc +2 -1
- datahub/metadata/schemas/GlossaryNodeKey.avsc +2 -1
- datahub/metadata/schemas/GlossaryTermKey.avsc +2 -1
- datahub/metadata/schemas/IncidentInfo.avsc +3 -3
- datahub/metadata/schemas/StructuredPropertyDefinition.avsc +0 -3
- datahub/sql_parsing/sqlglot_lineage.py +121 -28
- datahub/sql_parsing/sqlglot_utils.py +12 -1
- {acryl_datahub-1.2.0.7rc4.dist-info → acryl_datahub-1.2.0.8rc2.dist-info}/WHEEL +0 -0
- {acryl_datahub-1.2.0.7rc4.dist-info → acryl_datahub-1.2.0.8rc2.dist-info}/entry_points.txt +0 -0
- {acryl_datahub-1.2.0.7rc4.dist-info → acryl_datahub-1.2.0.8rc2.dist-info}/licenses/LICENSE +0 -0
- {acryl_datahub-1.2.0.7rc4.dist-info → acryl_datahub-1.2.0.8rc2.dist-info}/top_level.txt +0 -0
|
@@ -73,6 +73,11 @@ except ImportError:
|
|
|
73
73
|
|
|
74
74
|
logger = logging.getLogger(__name__)
|
|
75
75
|
|
|
76
|
+
# Precompiled regex for SQL identifier validation
|
|
77
|
+
# Athena identifiers can only contain lowercase letters, numbers, underscore, and period (for complex types)
|
|
78
|
+
# Note: Athena automatically converts uppercase to lowercase, but we're being strict for security
|
|
79
|
+
_IDENTIFIER_PATTERN = re.compile(r"^[a-zA-Z0-9_.]+$")
|
|
80
|
+
|
|
76
81
|
assert STRUCT, "required type modules are not available"
|
|
77
82
|
register_custom_type(STRUCT, RecordTypeClass)
|
|
78
83
|
register_custom_type(MapType, MapTypeClass)
|
|
@@ -510,20 +515,76 @@ class AthenaSource(SQLAlchemySource):
|
|
|
510
515
|
return [schema for schema in schemas if schema == athena_config.database]
|
|
511
516
|
return schemas
|
|
512
517
|
|
|
518
|
+
@classmethod
|
|
519
|
+
def _sanitize_identifier(cls, identifier: str) -> str:
|
|
520
|
+
"""Sanitize SQL identifiers to prevent injection attacks.
|
|
521
|
+
|
|
522
|
+
Args:
|
|
523
|
+
identifier: The SQL identifier to sanitize
|
|
524
|
+
|
|
525
|
+
Returns:
|
|
526
|
+
Sanitized identifier safe for SQL queries
|
|
527
|
+
|
|
528
|
+
Raises:
|
|
529
|
+
ValueError: If identifier contains unsafe characters
|
|
530
|
+
"""
|
|
531
|
+
if not identifier:
|
|
532
|
+
raise ValueError("Identifier cannot be empty")
|
|
533
|
+
|
|
534
|
+
# Allow only alphanumeric characters, underscores, and periods for identifiers
|
|
535
|
+
# This matches Athena's identifier naming rules
|
|
536
|
+
if not _IDENTIFIER_PATTERN.match(identifier):
|
|
537
|
+
raise ValueError(
|
|
538
|
+
f"Identifier '{identifier}' contains unsafe characters. Only alphanumeric characters, underscores, and periods are allowed."
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
return identifier
|
|
542
|
+
|
|
513
543
|
@classmethod
|
|
514
544
|
def _casted_partition_key(cls, key: str) -> str:
|
|
515
545
|
# We need to cast the partition keys to a VARCHAR, since otherwise
|
|
516
546
|
# Athena may throw an error during concatenation / comparison.
|
|
517
|
-
|
|
547
|
+
sanitized_key = cls._sanitize_identifier(key)
|
|
548
|
+
return f"CAST({sanitized_key} as VARCHAR)"
|
|
549
|
+
|
|
550
|
+
@classmethod
|
|
551
|
+
def _build_max_partition_query(
|
|
552
|
+
cls, schema: str, table: str, partitions: List[str]
|
|
553
|
+
) -> str:
|
|
554
|
+
"""Build SQL query to find the row with maximum partition values.
|
|
555
|
+
|
|
556
|
+
Args:
|
|
557
|
+
schema: Database schema name
|
|
558
|
+
table: Table name
|
|
559
|
+
partitions: List of partition column names
|
|
560
|
+
|
|
561
|
+
Returns:
|
|
562
|
+
SQL query string to find the maximum partition
|
|
563
|
+
|
|
564
|
+
Raises:
|
|
565
|
+
ValueError: If any identifier contains unsafe characters
|
|
566
|
+
"""
|
|
567
|
+
# Sanitize all identifiers to prevent SQL injection
|
|
568
|
+
sanitized_schema = cls._sanitize_identifier(schema)
|
|
569
|
+
sanitized_table = cls._sanitize_identifier(table)
|
|
570
|
+
sanitized_partitions = [
|
|
571
|
+
cls._sanitize_identifier(partition) for partition in partitions
|
|
572
|
+
]
|
|
573
|
+
|
|
574
|
+
casted_keys = [cls._casted_partition_key(key) for key in partitions]
|
|
575
|
+
if len(casted_keys) == 1:
|
|
576
|
+
part_concat = casted_keys[0]
|
|
577
|
+
else:
|
|
578
|
+
separator = "CAST('-' AS VARCHAR)"
|
|
579
|
+
part_concat = f"CONCAT({f', {separator}, '.join(casted_keys)})"
|
|
580
|
+
|
|
581
|
+
return f'select {",".join(sanitized_partitions)} from "{sanitized_schema}"."{sanitized_table}$partitions" where {part_concat} = (select max({part_concat}) from "{sanitized_schema}"."{sanitized_table}$partitions")'
|
|
518
582
|
|
|
519
583
|
@override
|
|
520
584
|
def get_partitions(
|
|
521
585
|
self, inspector: Inspector, schema: str, table: str
|
|
522
586
|
) -> Optional[List[str]]:
|
|
523
|
-
if
|
|
524
|
-
not self.config.extract_partitions
|
|
525
|
-
and not self.config.extract_partitions_using_create_statements
|
|
526
|
-
):
|
|
587
|
+
if not self.config.extract_partitions:
|
|
527
588
|
return None
|
|
528
589
|
|
|
529
590
|
if not self.cursor:
|
|
@@ -557,11 +618,9 @@ class AthenaSource(SQLAlchemySource):
|
|
|
557
618
|
context=f"{schema}.{table}",
|
|
558
619
|
level=StructuredLogLevel.WARN,
|
|
559
620
|
):
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
self._casted_partition_key(key) for key in partitions
|
|
621
|
+
max_partition_query = self._build_max_partition_query(
|
|
622
|
+
schema, table, partitions
|
|
563
623
|
)
|
|
564
|
-
max_partition_query = f'select {",".join(partitions)} from "{schema}"."{table}$partitions" where {part_concat} = (select max({part_concat}) from "{schema}"."{table}$partitions")'
|
|
565
624
|
ret = self.cursor.execute(max_partition_query)
|
|
566
625
|
max_partition: Dict[str, str] = {}
|
|
567
626
|
if ret:
|
|
@@ -678,16 +737,34 @@ class AthenaSource(SQLAlchemySource):
|
|
|
678
737
|
).get(table, None)
|
|
679
738
|
|
|
680
739
|
if partition and partition.max_partition:
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
740
|
+
try:
|
|
741
|
+
# Sanitize identifiers to prevent SQL injection
|
|
742
|
+
sanitized_schema = self._sanitize_identifier(schema)
|
|
743
|
+
sanitized_table = self._sanitize_identifier(table)
|
|
744
|
+
|
|
745
|
+
max_partition_filters = []
|
|
746
|
+
for key, value in partition.max_partition.items():
|
|
747
|
+
# Sanitize partition key and properly escape the value
|
|
748
|
+
sanitized_key = self._sanitize_identifier(key)
|
|
749
|
+
# Escape single quotes in the value to prevent injection
|
|
750
|
+
escaped_value = value.replace("'", "''") if value else ""
|
|
751
|
+
max_partition_filters.append(
|
|
752
|
+
f"{self._casted_partition_key(sanitized_key)} = '{escaped_value}'"
|
|
753
|
+
)
|
|
754
|
+
max_partition = str(partition.max_partition)
|
|
755
|
+
return (
|
|
756
|
+
max_partition,
|
|
757
|
+
f'SELECT * FROM "{sanitized_schema}"."{sanitized_table}" WHERE {" AND ".join(max_partition_filters)}',
|
|
685
758
|
)
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
759
|
+
except ValueError as e:
|
|
760
|
+
# If sanitization fails due to malicious identifiers,
|
|
761
|
+
# return None to disable partition profiling for this table
|
|
762
|
+
# rather than crashing the entire ingestion
|
|
763
|
+
logger.warning(
|
|
764
|
+
f"Failed to generate partition profiler query for {schema}.{table} due to unsafe identifiers: {e}. "
|
|
765
|
+
f"Partition profiling disabled for this table."
|
|
766
|
+
)
|
|
767
|
+
return None, None
|
|
691
768
|
return None, None
|
|
692
769
|
|
|
693
770
|
def close(self):
|
|
@@ -174,20 +174,16 @@ class AthenaPropertiesExtractor:
|
|
|
174
174
|
def format_column_definition(line):
|
|
175
175
|
# Use regex to parse the line more accurately
|
|
176
176
|
# Pattern: column_name data_type [COMMENT comment_text] [,]
|
|
177
|
-
#
|
|
178
|
-
pattern = r"^\s*(
|
|
179
|
-
match = re.match(pattern, line, re.IGNORECASE)
|
|
177
|
+
# Improved pattern to better separate column name, data type, and comment
|
|
178
|
+
pattern = r"^\s*([`\w']+)\s+([\w<>\[\](),\s]+?)(\s+COMMENT\s+(.+?))?(,?)\s*$"
|
|
179
|
+
match = re.match(pattern, line.strip(), re.IGNORECASE)
|
|
180
180
|
|
|
181
181
|
if not match:
|
|
182
182
|
return line
|
|
183
|
-
column_name = match.group(1)
|
|
184
|
-
data_type = match.group(2)
|
|
185
|
-
comment_part = match.group(
|
|
186
|
-
|
|
187
|
-
if comment_part:
|
|
188
|
-
trailing_comma = match.group(6) if match.group(6) else ""
|
|
189
|
-
else:
|
|
190
|
-
trailing_comma = match.group(7) if match.group(7) else ""
|
|
183
|
+
column_name = match.group(1).strip()
|
|
184
|
+
data_type = match.group(2).strip()
|
|
185
|
+
comment_part = match.group(4) # COMMENT part
|
|
186
|
+
trailing_comma = match.group(5) if match.group(5) else ""
|
|
191
187
|
|
|
192
188
|
# Add backticks to column name if not already present
|
|
193
189
|
if not (column_name.startswith("`") and column_name.endswith("`")):
|
|
@@ -201,17 +197,19 @@ class AthenaPropertiesExtractor:
|
|
|
201
197
|
|
|
202
198
|
# Handle comment quoting and escaping
|
|
203
199
|
if comment_part.startswith("'") and comment_part.endswith("'"):
|
|
204
|
-
# Already
|
|
205
|
-
|
|
200
|
+
# Already single quoted - but check for proper escaping
|
|
201
|
+
inner_content = comment_part[1:-1]
|
|
202
|
+
# Re-escape any single quotes that aren't properly escaped
|
|
203
|
+
escaped_content = inner_content.replace("'", "''")
|
|
204
|
+
formatted_comment = f"'{escaped_content}'"
|
|
206
205
|
elif comment_part.startswith('"') and comment_part.endswith('"'):
|
|
207
206
|
# Double quoted - convert to single quotes and escape internal single quotes
|
|
208
207
|
inner_content = comment_part[1:-1]
|
|
209
208
|
escaped_content = inner_content.replace("'", "''")
|
|
210
209
|
formatted_comment = f"'{escaped_content}'"
|
|
211
210
|
else:
|
|
212
|
-
# Not quoted -
|
|
213
|
-
|
|
214
|
-
formatted_comment = f"'{escaped_content}'"
|
|
211
|
+
# Not quoted - use double quotes to avoid escaping issues with single quotes
|
|
212
|
+
formatted_comment = f'"{comment_part}"'
|
|
215
213
|
|
|
216
214
|
result_parts.extend(["COMMENT", formatted_comment])
|
|
217
215
|
|
|
@@ -240,19 +238,39 @@ class AthenaPropertiesExtractor:
|
|
|
240
238
|
formatted_lines.append(line)
|
|
241
239
|
continue
|
|
242
240
|
|
|
243
|
-
#
|
|
244
|
-
if in_column_definition and "
|
|
245
|
-
in_column_definition = False
|
|
241
|
+
# Skip processing PARTITIONED BY clauses as column definitions
|
|
242
|
+
if in_column_definition and "PARTITIONED BY" in line.upper():
|
|
246
243
|
formatted_lines.append(line)
|
|
247
244
|
continue
|
|
248
245
|
|
|
249
|
-
# Process
|
|
246
|
+
# Process column definitions first, then check for exit condition
|
|
250
247
|
if in_column_definition and stripped_line:
|
|
251
|
-
#
|
|
252
|
-
|
|
253
|
-
line
|
|
254
|
-
|
|
255
|
-
|
|
248
|
+
# Check if this line contains a column definition (before the closing paren)
|
|
249
|
+
if ")" in line:
|
|
250
|
+
# Split the line at the closing parenthesis
|
|
251
|
+
paren_index = line.find(")")
|
|
252
|
+
column_part = line[:paren_index].strip()
|
|
253
|
+
closing_part = line[paren_index:]
|
|
254
|
+
|
|
255
|
+
if column_part:
|
|
256
|
+
# Format the column part
|
|
257
|
+
formatted_column = (
|
|
258
|
+
AthenaPropertiesExtractor.format_column_definition(
|
|
259
|
+
column_part
|
|
260
|
+
)
|
|
261
|
+
)
|
|
262
|
+
# Reconstruct the line
|
|
263
|
+
formatted_line = formatted_column.rstrip() + closing_part
|
|
264
|
+
formatted_lines.append(formatted_line)
|
|
265
|
+
else:
|
|
266
|
+
formatted_lines.append(line)
|
|
267
|
+
in_column_definition = False
|
|
268
|
+
else:
|
|
269
|
+
# Regular column definition line
|
|
270
|
+
formatted_line = AthenaPropertiesExtractor.format_column_definition(
|
|
271
|
+
line
|
|
272
|
+
)
|
|
273
|
+
formatted_lines.append(formatted_line)
|
|
256
274
|
else:
|
|
257
275
|
# For all other lines, keep as-is
|
|
258
276
|
formatted_lines.append(line)
|
|
@@ -154,6 +154,7 @@ class SupersetDataset(BaseModel):
|
|
|
154
154
|
table_name: str
|
|
155
155
|
changed_on_utc: Optional[str] = None
|
|
156
156
|
explore_url: Optional[str] = ""
|
|
157
|
+
description: Optional[str] = ""
|
|
157
158
|
|
|
158
159
|
@property
|
|
159
160
|
def modified_dt(self) -> Optional[datetime]:
|
|
@@ -1062,7 +1063,7 @@ class SupersetSource(StatefulIngestionSourceBase):
|
|
|
1062
1063
|
fieldPath=col.get("column_name", ""),
|
|
1063
1064
|
type=SchemaFieldDataType(data_type),
|
|
1064
1065
|
nativeDataType="",
|
|
1065
|
-
description=col.get("column_name", ""),
|
|
1066
|
+
description=col.get("description") or col.get("column_name", ""),
|
|
1066
1067
|
nullable=True,
|
|
1067
1068
|
)
|
|
1068
1069
|
schema_fields.append(field)
|
|
@@ -1283,7 +1284,7 @@ class SupersetSource(StatefulIngestionSourceBase):
|
|
|
1283
1284
|
|
|
1284
1285
|
dataset_info = DatasetPropertiesClass(
|
|
1285
1286
|
name=dataset.table_name,
|
|
1286
|
-
description="",
|
|
1287
|
+
description=dataset.description or "",
|
|
1287
1288
|
externalUrl=dataset_url,
|
|
1288
1289
|
lastModified=TimeStamp(time=modified_ts),
|
|
1289
1290
|
)
|
|
@@ -1561,12 +1561,15 @@ class TableauSiteSource:
|
|
|
1561
1561
|
}}""",
|
|
1562
1562
|
)
|
|
1563
1563
|
else:
|
|
1564
|
-
# As of Tableau Server 2024.2, the metadata API sporadically returns a 30-second
|
|
1565
|
-
# timeout error.
|
|
1566
|
-
# It doesn't reliably happen, so retrying a couple of times makes sense.
|
|
1567
1564
|
if all(
|
|
1565
|
+
# As of Tableau Server 2024.2, the metadata API sporadically returns a 30-second
|
|
1566
|
+
# timeout error.
|
|
1567
|
+
# It doesn't reliably happen, so retrying a couple of times makes sense.
|
|
1568
1568
|
error.get("message")
|
|
1569
1569
|
== "Execution canceled because timeout of 30000 millis was reached"
|
|
1570
|
+
# The Metadata API sometimes returns an 'unexpected error' message when querying
|
|
1571
|
+
# embeddedDatasourcesConnection. Try retrying a couple of times.
|
|
1572
|
+
or error.get("message") == "Unexpected error occurred"
|
|
1570
1573
|
for error in errors
|
|
1571
1574
|
):
|
|
1572
1575
|
# If it was only a timeout error, we can retry.
|
|
@@ -1578,8 +1581,8 @@ class TableauSiteSource:
|
|
|
1578
1581
|
(self.config.max_retries - retries_remaining + 1) ** 2, 60
|
|
1579
1582
|
)
|
|
1580
1583
|
logger.info(
|
|
1581
|
-
f"Query {connection_type} received a
|
|
1582
|
-
f"
|
|
1584
|
+
f"Query {connection_type} received a retryable error with {retries_remaining} retries remaining, "
|
|
1585
|
+
f"will retry in {backoff_time} seconds: {errors}"
|
|
1583
1586
|
)
|
|
1584
1587
|
time.sleep(backoff_time)
|
|
1585
1588
|
return self.get_connection_object_page(
|