Esempio n. 1
0
    def test_truncated_placeholder_keeps_dependencies(self):

        graph = QueryGraph()

        node = SqlCTENode("test", "test")
        node1 = SqlCTENode("test1", "test")
        node2 = SqlCTENode("test2", "test")
        node3 = SqlCTENode("test3", "test")

        node.add_dependency_node(node1)
        node1.add_dependency_node(node2)
        node2.add_dependency_node(node3)
        graph.add_node(node)
        graph.add_node(node1)
        graph.add_node(node2)
        graph.add_node(node3)

        factory = QueryGraphFactory()
        testGraph = factory.create_truncated_runnable_graph_from_node(
            node, ["test2"])

        self.assertEqual(type(testGraph.get_node_by_name("test2")),
                         PlaceholderNode)
        self.assertEqual(
            testGraph.get_node_by_name("test2").get_dependencies(),
            node2.get_dependencies())
        self.assertEqual(len(testGraph.node_lookup), 3)
Esempio n. 2
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
Esempio n. 3
0
    def test_truncated_placeholder_keeps_dependencies(self):

        graph = QueryGraph()

        node = SqlCTENode("test", "test")
        node1 = SqlCTENode("test1", "test")
        node2 = SqlCTENode("test2", "test")
        node3 = SqlCTENode("test3", "test")

        node.add_dependency_node(node1)
        node1.add_dependency_node(node2)
        node2.add_dependency_node(node3)
        graph.add_node(node)
        graph.add_node(node1)
        graph.add_node(node2)
        graph.add_node(node3)

        factory = QueryGraphFactory()
        testGraph = factory.create_truncated_runnable_graph_from_node(node, ["test2"])

        self.assertEqual(type(testGraph.get_node_by_name("test2")), PlaceholderNode)
        self.assertEqual(testGraph.get_node_by_name("test2").get_dependencies(), node2.get_dependencies())
        self.assertEqual(len(testGraph.node_lookup), 3)