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

add display_in_catalogue tag to filter in search method #383

Merged
merged 7 commits into from
May 31, 2024
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
57 changes: 57 additions & 0 deletions .github/workflows/test-datahub-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: test

on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
paths:
- lib/datahub-client/**
push:
branches:
- main
paths:
- lib/datahub-client/**

permissions: read-all

jobs:
run-datahub-client-tests:
name: Run datahub client tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: lib/datahub-client
strategy:
fail-fast: false
max-parallel: 4
matrix:
python-version:
- "3.10"
steps:
- name: Checkout
id: checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Install Poetry
id: install_poetry
run: |
curl -sSL "https://install.python-poetry.org" | python3 -
echo "${HOME}/.poetry/bin" >>"${GITHUB_PATH}"

- name: Set up Python ${{ matrix.python-version }}
id: setup_python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: ${{ matrix.python-version }}
cache: poetry
cache-dependency-path: lib/datahub-client/poetry.lock

- name: Poetry install
id: poetry_install
run: |
poetry install

- name: Run tests
id: run_tests
run: |
poetry run pytest
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def search(
ResultType.CHART,
ResultType.DATABASE,
),
filters: Sequence[MultiSelectFilter] = (),
filters: Sequence[MultiSelectFilter] = [],
sort: SortOption | None = None,
) -> SearchResponse:
"""
Expand Down Expand Up @@ -499,6 +499,19 @@ def upsert_database(self, database: Database):
self.graph.emit(metadata_event)
logger.info(f"Type updated for Database {name} ")

if database.tags:
tags_to_add = mce_builder.make_global_tag_aspect_with_tag_list(
tags=[str(tag.display_name) for tag in database.tags]
)
event: MetadataChangeProposalWrapper = MetadataChangeProposalWrapper(
entityType="container",
changeType=ChangeTypeClass.UPSERT,
entityUrn=database_urn,
aspect=tags_to_add,
)
self.graph.emit(event)
logger.info(f"Tags updated for Database {name} ")

return database_urn

def list_database_tables(self, urn: str, count: int) -> SearchResponse:
Expand Down
10 changes: 9 additions & 1 deletion lib/datahub-client/data_platform_catalogue/client/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def search(
ResultType.CHART,
ResultType.DATABASE,
),
filters: Sequence[MultiSelectFilter] = (),
filters: Sequence[MultiSelectFilter] = [],
sort: SortOption | None = None,
) -> SearchResponse:
"""
Expand All @@ -75,6 +75,14 @@ def search(
start = 0 if page is None else int(page) * count

types = self._map_result_types(result_types)

# This is the tag that any and every entity we want to present in search results
# now must have.
display_in_catalogue_filter = MultiSelectFilter(
filter_name="tags", included_values=["urn:li:tag:display_in_catalogue"]
)

filters.append(display_in_catalogue_filter)
formatted_filters = self._map_filters(filters)

variables = {
Expand Down
12 changes: 6 additions & 6 deletions lib/datahub-client/tests/client/datahub/test_datahub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class TestCatalogueClientWithDatahub:
@pytest.fixture
def database(self):
return Database(
urn=None,
name="my_database",
display_name="my_database",
fully_qualified_name="my_database",
description="little test db",
governance=Governance(
data_owner=OwnerRef(
Expand All @@ -55,10 +58,7 @@ def database(self):
),
domain=DomainRef(urn="LAA", display_name="LAA"),
last_modified=datetime(2020, 5, 17),
creation_date=datetime(2020, 5, 17),
access_information=AccessInformation(
s3_location="s3://databucket/",
),
created=datetime(2020, 5, 17),
tags=[TagRef(urn="test", display_name="test")],
platform=EntityRef(urn="urn:li:dataPlatform:athena", display_name="athena"),
custom_properties=CustomEntityProperties(
Expand Down Expand Up @@ -307,7 +307,7 @@ def test_get_dataset(
dataset = datahub_client.get_table_details(urn)

assert dataset == Table(
urn=None,
urn="abc",
display_name="Dataset",
name="Dataset",
fully_qualified_name="Foo.Dataset",
Expand Down Expand Up @@ -375,7 +375,7 @@ def test_get_dataset_minimal_properties(
dataset = datahub_client.get_table_details(urn)

assert dataset == Table(
urn=None,
urn="abc",
display_name="notinproperties",
name="notinproperties",
fully_qualified_name="notinproperties",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@
}
}
},
{
"entityType": "container",
"entityUrn": "urn:li:container:my_database",
"changeType": "UPSERT",
"aspectName": "globalTags",
"aspect": {
"json": {
"tags": [
{
"tag": "urn:li:tag:test"
}
]
}
}
},
{
"entityType": "dataset",
"entityUrn": "urn:li:dataset:(urn:li:dataPlatform:athena,database.Dataset,PROD)",
Expand Down Expand Up @@ -172,4 +187,4 @@
}
}
}
]
]
Loading