Esempio n. 1
0
 def _handle_target_table_token(self, sub_token: TokenList) -> None:
     if isinstance(sub_token, Function):
         # insert into tab (col1, col2) values (val1, val2); Here tab (col1, col2) will be parsed as Function
         # referring https://github.com/andialbrecht/sqlparse/issues/483 for further information
         if not isinstance(sub_token.token_first(skip_cm=True), Identifier):
             raise SQLLineageException(
                 "An Identifier is expected, got %s[value: %s] instead" %
                 (type(sub_token).__name__, sub_token))
         self._lineage_result.write.add(
             Table.create(sub_token.token_first(skip_cm=True)))
     elif isinstance(sub_token, Comparison):
         # create table tab1 like tab2, tab1 like tab2 will be parsed as Comparison
         # referring https://github.com/andialbrecht/sqlparse/issues/543 for further information
         if not (isinstance(sub_token.left, Identifier)
                 and isinstance(sub_token.right, Identifier)):
             raise SQLLineageException(
                 "An Identifier is expected, got %s[value: %s] instead" %
                 (type(sub_token).__name__, sub_token))
         self._lineage_result.write.add(Table.create(sub_token.left))
         self._lineage_result.read.add(Table.create(sub_token.right))
     else:
         if not isinstance(sub_token, Identifier):
             raise SQLLineageException(
                 "An Identifier is expected, got %s[value: %s] instead" %
                 (type(sub_token).__name__, sub_token))
         self._lineage_result.write.add(Table.create(sub_token))
Esempio n. 2
0
 def _handle_source_table_token(self, sub_token: TokenList) -> None:
     if isinstance(sub_token, Identifier):
         if isinstance(sub_token.token_first(skip_cm=True), Parenthesis):
             # SELECT col1 FROM (SELECT col2 FROM tab1) dt, the subquery will be parsed as Identifier
             # and this Identifier's get_real_name method would return alias name dt
             # referring https://github.com/andialbrecht/sqlparse/issues/218 for further information
             pass
         else:
             self._lineage_result.read.add(Table.create(sub_token))
     elif isinstance(sub_token, IdentifierList):
         # This is to support join in ANSI-89 syntax
         for token in sub_token.tokens:
             if isinstance(token, Identifier):
                 self._lineage_result.read.add(Table.create(token))
     elif isinstance(sub_token, Parenthesis):
         # SELECT col1 FROM (SELECT col2 FROM tab1), the subquery will be parsed as Parenthesis
         # This syntax without alias for subquery is invalid in MySQL, while valid for SparkSQL
         pass
     else:
         raise SQLLineageException(
             "An Identifier is expected, got %s[value: %s] instead" %
             (type(sub_token).__name__, sub_token))