@@ -83,6 +83,16 @@ def urn_creator(
8383 )
8484
8585
86+ def get_next_item (items : List [str ], item : str ) -> Optional [str ]:
87+ if item in items :
88+ try :
89+ index = items .index (item )
90+ return items [index + 1 ]
91+ except IndexError :
92+ logger .debug (f'item:"{ item } ", not found in item-list: { items } ' )
93+ return None
94+
95+
8696class AbstractDataPlatformTableCreator (ABC ):
8797 """
8898 Base class to share common functionalities among different dataplatform for M-Query parsing.
@@ -675,7 +685,7 @@ def two_level_access_pattern(
675685 data_access_func_detail .arg_list
676686 )
677687 if server is None or db_name is None :
678- return Lineage .empty () # Return empty list
688+ return Lineage .empty () # Return an empty list
679689
680690 schema_name : str = cast (
681691 IdentifierAccessor , data_access_func_detail .identifier_accessor
@@ -782,32 +792,38 @@ def create_lineage(
782792 ),
783793 )
784794
785- if len (arguments ) == 2 :
786- # It is a regular case of MS-SQL
787- logger .debug ("Handling with regular case" )
788- return self .two_level_access_pattern (data_access_func_detail )
789-
790- if len (arguments ) >= 4 and arguments [2 ] != "Query" :
791- logger .debug ("Unsupported case is found. Second index is not the Query" )
792- return Lineage .empty ()
795+ server , database = self .get_db_detail_from_argument (
796+ data_access_func_detail .arg_list
797+ )
798+ if server is None or database is None :
799+ return Lineage .empty () # Return an empty list
800+
801+ assert server
802+ assert database # to silent the lint
803+
804+ query : Optional [str ] = get_next_item (arguments , "Query" )
805+ if query :
806+ if self .config .enable_advance_lineage_sql_construct is False :
807+ # Use previous parser to generate URN to keep backward compatibility
808+ return Lineage (
809+ upstreams = self .create_urn_using_old_parser (
810+ query = query ,
811+ db_name = database ,
812+ server = server ,
813+ ),
814+ column_lineage = [],
815+ )
793816
794- if self .config .enable_advance_lineage_sql_construct is False :
795- # Use previous parser to generate URN to keep backward compatibility
796- return Lineage (
797- upstreams = self .create_urn_using_old_parser (
798- query = arguments [3 ],
799- db_name = arguments [1 ],
800- server = arguments [0 ],
801- ),
802- column_lineage = [],
817+ return self .parse_custom_sql (
818+ query = query ,
819+ database = database ,
820+ server = server ,
821+ schema = MSSqlDataPlatformTableCreator .DEFAULT_SCHEMA ,
803822 )
804823
805- return self .parse_custom_sql (
806- query = arguments [3 ],
807- database = arguments [1 ],
808- server = arguments [0 ],
809- schema = MSSqlDataPlatformTableCreator .DEFAULT_SCHEMA ,
810- )
824+ # It is a regular case of MS-SQL
825+ logger .debug ("Handling with regular case" )
826+ return self .two_level_access_pattern (data_access_func_detail )
811827
812828
813829class OracleDataPlatformTableCreator (AbstractDataPlatformTableCreator ):
@@ -1154,27 +1170,19 @@ def get_db_name(self, data_access_tokens: List[str]) -> Optional[str]:
11541170 != SupportedDataPlatform .DatabricksMultiCloud_SQL .value .powerbi_data_platform_name
11551171 ):
11561172 return None
1157- try :
1158- if "Database" in data_access_tokens :
1159- index = data_access_tokens .index ("Database" )
1160- if data_access_tokens [index + 1 ] != Constant .M_QUERY_NULL :
1161- # Database name is explicitly set in argument
1162- return data_access_tokens [index + 1 ]
11631173
1164- if "Name" in data_access_tokens :
1165- index = data_access_tokens .index ("Name" )
1166- # Next element is value of the Name. It is a database name
1167- return data_access_tokens [index + 1 ]
1174+ database : Optional [str ] = get_next_item (data_access_tokens , "Database" )
11681175
1169- if "Catalog" in data_access_tokens :
1170- index = data_access_tokens .index ("Catalog" )
1171- # Next element is value of the Catalog. In Databricks Catalog can also be used in place of a database.
1172- return data_access_tokens [index + 1 ]
1173-
1174- except IndexError as e :
1175- logger .debug ("Database name is not available" , exc_info = e )
1176-
1177- return None
1176+ if (
1177+ database and database != Constant .M_QUERY_NULL
1178+ ): # database name is explicitly set
1179+ return database
1180+
1181+ return get_next_item ( # database name is set in Name argument
1182+ data_access_tokens , "Name"
1183+ ) or get_next_item ( # If both above arguments are not available, then try Catalog
1184+ data_access_tokens , "Catalog"
1185+ )
11781186
11791187 def create_lineage (
11801188 self , data_access_func_detail : DataAccessFunctionDetail
0 commit comments