def _parse_node_contents(self, node: SqlCTENode, node_list: List[SqlCTENode]): state = "start" tokens = sqlparse.parse(node.get_text())[0].tokens tokens = [x for x in tokens if not (x.ttype is sqlparse.tokens.Whitespace)] for token in tokens: if type(token) is sqlparse.sql.Comment: node.set_docstring(str(token).replace("/*", "").replace("*/", "").replace("--", "").strip()) if token.ttype is sqlparse.tokens.DML: state = "select" continue if state == "select" and token.ttype is not sqlparse.tokens.Punctuation: if token.value.lower() == "from": state = "from" continue if type(token) is sqlparse.sql.IdentifierList: for item in token.get_identifiers(): node.add_column(self.column_factory.create_column(item)) continue if token.ttype is not sqlparse.tokens.Punctuation and token.ttype is not sqlparse.tokens.Whitespace and str(token.value) != "\n": column = self.column_factory.create_column(str(token)) print("Here") node.add_column(column) if state == "from": if type(token) is sqlparse.sql.Where or token.value.lower() == "group": break if type(token) is sqlparse.sql.Identifier: tableName = "" if token.has_alias(): tableName = str(token).replace(token.get_name(), "").strip() else: tableName = token.get_name() dependency = [x for x in node_list if x.get_name() == tableName] if len(dependency) == 1: node.add_dependency_node(dependency[0]) if node.get_dependencies() == []: node = create_table_node(node) node_list.append(node) return node_list
def create_table_node(from_node : SqlCTENode): new_node = SqlTableNode(from_node.get_name(), from_node.get_text()) new_node.columns = from_node.columns new_node.doc_string = from_node.doc_string return new_node