コード例 #1
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_common_like_double_where_from_in_modes(self, dialect):
        categories = [
            'COLUMNS',
            'FIELDS',
            'INDEX',
            'INDEXES',
            'KEYS',
        ]
        modes = [
            ['EXTENDED'],
            ['FULL'],
            ['EXTENDED', 'FULL'],
        ]
        for cat in categories:
            for mode in modes:

                sql = f"SHOW {' '.join(mode)} {cat} from tab1 from db1 in tab2 in db2 like 'pattern' where a=1"
                ast = parse_sql(sql, dialect=dialect)
                expected_ast = Show(category=cat,
                                    like='pattern',
                                    from_table=Identifier('db1.tab1'),
                                    in_table=Identifier('db2.tab2'),
                                    modes=mode,
                                    where=BinaryOperation(
                                        op='=',
                                        args=[Identifier('a'),
                                              Constant(1)]))

                assert str(ast) == str(expected_ast)
                assert ast.to_tree() == expected_ast.to_tree()
コード例 #2
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_show_tables_from_db(self, dialect):
        sql = "SHOW tables from db"
        ast = parse_sql(sql, dialect=dialect)
        expected_ast = Show(category='tables', from_table=Identifier('db'))

        assert str(ast).lower() == sql.lower()
        assert str(ast) == str(expected_ast)
        assert ast.to_tree() == expected_ast.to_tree()
コード例 #3
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_full_columns(self, dialect):
        sql = "SHOW FULL COLUMNS FROM `concrete` FROM `files`"
        ast = parse_sql(sql, dialect=dialect)
        expected_ast = Show(category='COLUMNS',
                            modes=['FULL'],
                            from_table=Identifier('files.concrete'))

        assert str(ast) == str(expected_ast)
        assert ast.to_tree() == expected_ast.to_tree()
コード例 #4
0
    def test_show_tables_arg(self):
        for keyword in ['VIEWS', 'TABLES']:
            sql = f"SHOW {keyword} from integration_name"
            ast = parse_sql(sql, dialect='mindsdb')
            expected_ast = Show(category=keyword,
                                from_table=Identifier('integration_name'))

            assert str(ast).lower() == sql.lower()
            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()
コード例 #5
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_common_like_where(self, dialect, cat):

        sql = f"SHOW {cat} like 'pattern' where a=1"
        ast = parse_sql(sql, dialect=dialect)
        expected_ast = Show(category=cat,
                            like='pattern',
                            where=BinaryOperation(
                                op='=', args=[Identifier('a'),
                                              Constant(1)]))

        assert str(ast) == str(expected_ast)
        assert ast.to_tree() == expected_ast.to_tree()
コード例 #6
0
    def test_show_keyword(self):
        for keyword in [
                'STREAMS', 'PREDICTORS', 'INTEGRATIONS', 'DATASOURCES',
                'PUBLICATIONS', 'DATASETS', 'ALL'
        ]:
            sql = f"SHOW {keyword}"
            ast = parse_sql(sql, dialect='mindsdb')
            expected_ast = Show(category=keyword)

            assert str(ast).lower() == sql.lower()
            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()
コード例 #7
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_from_where(self, dialect):
        sql = "SHOW FULL TABLES FROM ttt LIKE 'zzz' WHERE xxx"
        ast = parse_sql(sql, dialect=dialect)
        expected_ast = Show(
            category='TABLES',
            modes=['FULL'],
            from_table=Identifier('ttt'),
            like='zzz',
            where=Identifier('xxx'),
        )

        assert str(ast) == str(expected_ast)
        assert ast.to_tree() == expected_ast.to_tree()
コード例 #8
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_show_character_set(self, dialect):
        sql = "show character set where charset = 'utf8mb4'"
        ast = parse_sql(sql, dialect=dialect)
        expected_ast = Show(
            category='character set',
            where=BinaryOperation(
                '=', args=[Identifier('charset'),
                           Constant('utf8mb4')]),
        )

        # assert str(ast).lower() == sql.lower()
        assert str(ast) == str(expected_ast)
        assert ast.to_tree() == expected_ast.to_tree()
コード例 #9
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_show_category(self, dialect):
        categories = [
            'SCHEMAS', 'DATABASES', 'TABLES', 'TABLES', 'VARIABLES', 'PLUGINS',
            'SESSION VARIABLES', 'SESSION STATUS', 'GLOBAL VARIABLES',
            'PROCEDURE STATUS', 'FUNCTION STATUS', 'CREATE TABLE', 'WARNINGS',
            'ENGINES', 'CHARSET', 'CHARACTER SET', 'COLLATION', 'TABLE STATUS',
            'STATUS'
        ]
        for cat in categories:
            sql = f"SHOW {cat}"
            ast = parse_sql(sql, dialect=dialect)
            expected_ast = Show(category=cat)

            assert str(ast).lower() == sql.lower()
            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()
コード例 #10
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_category(self, dialect):
        categories = [
            'BINARY LOGS',
            'MASTER LOGS',
            'PROCESSLIST',
            'STORAGE ENGINES',
            'PRIVILEGES',
            'MASTER STATUS',
            'PROFILES',
            'REPLICAS',
        ]

        for cat in categories:
            sql = f"SHOW {cat}"
            ast = parse_sql(sql, dialect=dialect)
            expected_ast = Show(category=cat)

            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()
コード例 #11
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_show_function_status(self, dialect):
        sql = "show function status where Db = 'MINDSDB' AND Name LIKE '%'"
        ast = parse_sql(sql, dialect=dialect)
        expected_ast = Show(
            category='function status',
            where=BinaryOperation(
                'and',
                args=[
                    BinaryOperation(
                        '=', args=[Identifier('Db'),
                                   Constant('MINDSDB')]),
                    BinaryOperation('like',
                                    args=[Identifier('Name'),
                                          Constant('%')])
                ]),
        )

        assert str(ast).lower() == sql.lower()
        assert str(ast) == str(expected_ast)
        assert ast.to_tree() == expected_ast.to_tree()
コード例 #12
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_common_like_where_from_in(self, dialect):
        categories = [
            'TABLE STATUS',
            'OPEN TABLES',
            'TRIGGERS',
        ]

        for cat in categories:
            sql = f"SHOW {cat} from tab1 in tab2 like 'pattern' where a=1"
            ast = parse_sql(sql, dialect=dialect)
            expected_ast = Show(category=cat,
                                like='pattern',
                                from_table=Identifier('tab1'),
                                in_table=Identifier('tab2'),
                                where=BinaryOperation(
                                    op='=',
                                    args=[Identifier('a'),
                                          Constant(1)]))

            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()
コード例 #13
0
ファイル: test_show.py プロジェクト: mindsdb/mindsdb_sql
    def test_custom(self, dialect):

        for arg in ['STATUS', 'MUTEX']:
            sql = f"SHOW ENGINE engine_name {arg}"
            ast = parse_sql(sql, dialect=dialect)
            expected_ast = Show(
                category='ENGINE',
                name='engine_name',
                modes=[arg],
            )

            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()

        for arg in ['FUNCTION', 'PROCEDURE']:
            sql = f"SHOW {arg} CODE obj_name"
            ast = parse_sql(sql, dialect=dialect)
            expected_ast = Show(
                category=f"{arg} CODE",
                name='obj_name',
            )

            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()

        for arg in ['SLAVE', 'REPLICA']:
            sql = f"SHOW {arg} STATUS FOR CHANNEL channel"
            ast = parse_sql(sql, dialect=dialect)
            expected_ast = Show(
                category=f"REPLICA STATUS",
                name='channel',
            )

            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()

            # without channel
            sql = f"SHOW {arg} STATUS"
            ast = parse_sql(sql, dialect=dialect)
            expected_ast = Show(category=f"REPLICA STATUS", )

            assert str(ast) == str(expected_ast)
            assert ast.to_tree() == expected_ast.to_tree()