Exemplo n.º 1
0
    def test_value_replace_updates_docstring(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node.set_docstring("im a doc string")
        oldGraph.add_node(node)
        newNode = SqlCTENode("test", "Im the text content of the test node")
        newNode.set_docstring("im a new doc string")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.value_replace(newGraph)

        self.assertEqual(oldGraph.get_node_by_name("test").get_docstring(),"im a new doc string")
Exemplo n.º 2
0
    def test_value_replace_updates_docstring(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node.set_docstring("im a doc string")
        oldGraph.add_node(node)
        newNode = SqlCTENode("test", "Im the text content of the test node")
        newNode.set_docstring("im a new doc string")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.value_replace(newGraph)

        self.assertEqual(
            oldGraph.get_node_by_name("test").get_docstring(),
            "im a new doc string")
Exemplo n.º 3
0
    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