|
1 | 1 | import logging
|
2 | 2 | from abc import ABC, abstractmethod
|
3 | 3 | from enum import Enum
|
4 |
| -from typing import Dict, List, Optional, Tuple, Type, Union, cast |
| 4 | +from typing import Dict, List, Optional, Tuple, Type, cast |
5 | 5 |
|
6 | 6 | from lark import Tree
|
7 | 7 |
|
|
22 | 22 | )
|
23 | 23 | from datahub.ingestion.source.powerbi.m_query import native_sql_parser, tree_function
|
24 | 24 | from datahub.ingestion.source.powerbi.m_query.data_classes import (
|
25 |
| - AbstractIdentifierAccessor, |
26 | 25 | DataAccessFunctionDetail,
|
27 | 26 | DataPlatformTable,
|
28 | 27 | FunctionName,
|
@@ -412,33 +411,25 @@ def create_lineage(
|
412 | 411 | )
|
413 | 412 | table_detail: Dict[str, str] = {}
|
414 | 413 | temp_accessor: Optional[
|
415 |
| - Union[IdentifierAccessor, AbstractIdentifierAccessor] |
| 414 | + IdentifierAccessor |
416 | 415 | ] = data_access_func_detail.identifier_accessor
|
417 | 416 |
|
418 | 417 | while temp_accessor:
|
419 |
| - if isinstance(temp_accessor, IdentifierAccessor): |
420 |
| - # Condition to handle databricks M-query pattern where table, schema and database all are present in |
421 |
| - # the same invoke statement |
422 |
| - if all( |
423 |
| - element in temp_accessor.items |
424 |
| - for element in ["Item", "Schema", "Catalog"] |
425 |
| - ): |
426 |
| - table_detail["Schema"] = temp_accessor.items["Schema"] |
427 |
| - table_detail["Table"] = temp_accessor.items["Item"] |
428 |
| - else: |
429 |
| - table_detail[temp_accessor.items["Kind"]] = temp_accessor.items[ |
430 |
| - "Name" |
431 |
| - ] |
432 |
| - |
433 |
| - if temp_accessor.next is not None: |
434 |
| - temp_accessor = temp_accessor.next |
435 |
| - else: |
436 |
| - break |
| 418 | + # Condition to handle databricks M-query pattern where table, schema and database all are present in |
| 419 | + # the same invoke statement |
| 420 | + if all( |
| 421 | + element in temp_accessor.items |
| 422 | + for element in ["Item", "Schema", "Catalog"] |
| 423 | + ): |
| 424 | + table_detail["Schema"] = temp_accessor.items["Schema"] |
| 425 | + table_detail["Table"] = temp_accessor.items["Item"] |
437 | 426 | else:
|
438 |
| - logger.debug( |
439 |
| - "expecting instance to be IdentifierAccessor, please check if parsing is done properly" |
440 |
| - ) |
441 |
| - return Lineage.empty() |
| 427 | + table_detail[temp_accessor.items["Kind"]] = temp_accessor.items["Name"] |
| 428 | + |
| 429 | + if temp_accessor.next is not None: |
| 430 | + temp_accessor = temp_accessor.next |
| 431 | + else: |
| 432 | + break |
442 | 433 |
|
443 | 434 | table_reference = self.create_reference_table(
|
444 | 435 | arg_list=data_access_func_detail.arg_list,
|
@@ -786,9 +777,10 @@ def get_db_name(self, data_access_tokens: List[str]) -> Optional[str]:
|
786 | 777 | def create_lineage(
|
787 | 778 | self, data_access_func_detail: DataAccessFunctionDetail
|
788 | 779 | ) -> Lineage:
|
789 |
| - t1: Tree = cast( |
790 |
| - Tree, tree_function.first_arg_list_func(data_access_func_detail.arg_list) |
| 780 | + t1: Optional[Tree] = tree_function.first_arg_list_func( |
| 781 | + data_access_func_detail.arg_list |
791 | 782 | )
|
| 783 | + assert t1 is not None |
792 | 784 | flat_argument_list: List[Tree] = tree_function.flat_argument_list(t1)
|
793 | 785 |
|
794 | 786 | if len(flat_argument_list) != 2:
|
|
0 commit comments