def _determine_opening_parenthesis_type(self, token: SQLToken): """ Determines the type of left parenthesis in query """ if token.previous_token.normalized in SUBQUERY_PRECEDING_KEYWORDS: # inside subquery / derived table token.is_subquery_start = True self._subquery_level += 1 token.subquery_level = self._subquery_level elif token.previous_token.normalized in KEYWORDS_BEFORE_COLUMNS.union({","}): # we are in columns and in a column subquery definition token.is_column_definition_start = True elif token.previous_token.normalized == "AS": token.is_with_query_start = True elif ( token.get_nth_previous(2).normalized == "TABLE" and token.get_nth_previous(3).normalized == "CREATE" ): token.is_create_table_columns_declaration_start = True else: # nested function token.is_nested_function_start = True self._nested_level += 1 self._is_in_nested_function = True self._open_parentheses.append(token) self._parenthesis_level += 1
def _determine_last_relevant_keyword(self, token: SQLToken, last_keyword: str): if token.is_keyword and "".join(token.normalized.split()) in RELEVANT_KEYWORDS: if ( not ( token.normalized == "FROM" and token.get_nth_previous(3).normalized == "EXTRACT" ) and not ( token.normalized == "ORDERBY" and len(self._open_parentheses) > 0 and self._open_parentheses[-1].is_partition_clause_start ) and not (token.normalized == "USING" and last_keyword == "SELECT") ): last_keyword = token.normalized return last_keyword