Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter is not working in athena crawler #1008

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions metaphor/athena/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,24 @@ def __init__(self, config: AthenaRunConfig) -> None:
super().__init__(config)
self._datasets: Dict[str, Dataset] = {}
self._aws_config = config.aws
self._filter = config.filter.normalize()

async def extract(self) -> Collection[ENTITY_TYPES]:
logger.info("Fetching metadata from Athena")

self._client = create_athena_client(self._aws_config)

for catalog in self._get_catalogs():
if not self._filter.include_database(database_name=catalog):
logger.info(f"Skipping catalog: {catalog}")
continue

databases = self._get_databases(catalog)
for database in databases:
if not self._filter.include_schema(database=catalog, schema=database):
logger.info(f"Skipping database: {catalog}.{database}")
continue

self._extract_tables(catalog, database)

return self._datasets.values()
Expand Down Expand Up @@ -110,9 +119,13 @@ def _paginate_and_dump_response(self, api_endpoint: str, **paginator_args):
yield page

def _init_dataset(self, catalog: str, database: str, table_metadata: TableMetadata):
name = dataset_normalized_name(
db=catalog, schema=database, table=table_metadata.Name
)
table = table_metadata.Name

if not self._filter.include_table(catalog, database, table):
logger.info(f"Skipping table: {catalog}.{database}.{table}")
return

name = dataset_normalized_name(db=catalog, schema=database, table=table)

table_type = (
TableTypeEnum(table_metadata.TableType)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metaphor-connectors"
version = "0.14.125"
version = "0.14.126"
license = "Apache-2.0"
description = "A collection of Python-based 'connectors' that extract metadata from various sources to ingest into the Metaphor app."
authors = ["Metaphor <[email protected]>"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
{
"CatalogName": "AwsDataCatalog",
"Type": "GLUE"
},
{
"CatalogName": "Test",
"Type": "GLUE"
}
],
"ResponseMetadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"DatabaseList": [
{
"Name": "spectrum_db2"
},
{
"Name": "Foo"
}
],
"ResponseMetadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@
"presto_view": "true",
"serde.serialization.lib": null
}
},
{
"Name": "table",
"CreateTime": "2022-09-07 21:46:03+08:00",
"LastAccessTime": "1970-01-01 08:00:00+08:00",
"TableType": "EXTERNAL_TABLE",
"Columns": [
{
"Name": "salesid",
"Type": "int"
}
],
"PartitionKeys": [],
"Parameters": {
"EXTERNAL": "TRUE",
"inputformat": "org.apache.hadoop.mapred.TextInputFormat",
"location": "s3://metaphor-specturm/example",
"numRows": "172000",
"outputformat": "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat",
"serde.param.field.delim": "\t",
"serde.param.serialization.format": "\t",
"serde.serialization.lib": "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe",
"transient_lastDdlTime": "1662558363"
}
}
],
"ResponseMetadata": {
Expand Down
7 changes: 7 additions & 0 deletions tests/athena/test_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from metaphor.athena.extractor import AthenaExtractor
from metaphor.common.base_config import OutputConfig
from metaphor.common.event_util import EventUtil
from metaphor.common.filter import DatasetFilter
from tests.test_utils import load_json


Expand All @@ -14,6 +15,12 @@ def dummy_config():
aws=AwsCredentials(
access_key_id="key", secret_access_key="secret", region_name="region"
),
filter=DatasetFilter(
excludes={
"test": None,
"awsdatacatalog": {"foo": None, "spectrum_db2": set(["table"])},
}
),
output=OutputConfig(),
)

Expand Down
Loading