Skip to content

Commit

Permalink
fix(ingestion/tableau): Tableau field type parsing (#11202)
Browse files Browse the repository at this point in the history
  • Loading branch information
skrydal authored Aug 20, 2024
1 parent a9ef48e commit 8f7642b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,12 @@ def get_tags_from_params(params: List[str] = []) -> GlobalTagsClass:


def tableau_field_to_schema_field(field, ingest_tags):
nativeDataType = field.get("dataType", "UNKNOWN")
# The check here makes sure that even if 'dataType' key exists in the 'field' dictionary but has value None,
# it will be set as "UNKNOWN" (nativeDataType field can not be None in the SchemaField).
# Hence, field.get("dataType", "UNKNOWN") is not enough
nativeDataType = field.get("dataType")
if nativeDataType is None:
nativeDataType = "UNKNOWN"
TypeClass = FIELD_TYPE_MAPPING.get(nativeDataType, NullTypeClass)

schema_field = SchemaField(
Expand Down
31 changes: 30 additions & 1 deletion metadata-ingestion/tests/unit/test_tableau_source.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
from typing import Any, Dict

import pytest

import datahub.ingestion.source.tableau_constant as c
from datahub.ingestion.source.tableau import TableauSiteSource
from datahub.ingestion.source.tableau_common import get_filter_pages, make_filter
from datahub.ingestion.source.tableau_common import (
get_filter_pages,
make_filter,
tableau_field_to_schema_field,
)
from datahub.metadata.com.linkedin.pegasus2avro.schema import SchemaField


def test_tablea_source_handles_none_nativedatatype():
field: Dict[str, Any] = {
"__typename": "CalculatedField",
"id": "abcd",
"name": "Test Field",
"description": None,
"isHidden": False,
"folderName": None,
"upstreamFields": [],
"upstreamColumns": [],
"role": None,
"dataType": None,
"defaultFormat": "s",
"aggregation": None,
"formula": "a/b + d",
}
schema_field: SchemaField = tableau_field_to_schema_field(
field=field, ingest_tags=False
)
assert schema_field.nativeDataType == "UNKNOWN"


def test_tableau_source_unescapes_lt():
Expand Down

0 comments on commit 8f7642b

Please # to comment.