Exemplo n.º 1
0
    def test_create_stream_as_with_condition_with_partitions(self):
        sql_type = "create_as"
        table_name = "pageviews_valid"
        src_table = "pageviews_original"
        kafka_topic = "pageviews_valid"
        value_format = "DELIMITED"
        select_columns = ["rowtime as logtime", "*"]
        conditions = "userid like 'User_%' AND pageid like 'Page_%'"
        paritions = 5

        built_sql_str = SQLBuilder.build(
            sql_type=sql_type,
            table_type="stream",
            table_name=table_name,
            src_table=src_table,
            kafka_topic=kafka_topic,
            select_columns=select_columns,
            timestamp="logtime",
            value_format=value_format,
            conditions=conditions,
            partitions=paritions,
        )

        self.assertEqual(
            built_sql_str.lower(),
            self.create_stream_as_with_condition_with_partitions.lower())
Exemplo n.º 2
0
    def test_create_table_without_key(self):
        table_name = "users_original"
        columns_type = [
            "registertime bigint", "gender varchar", "regionid varchar",
            "userid varchar"
        ]
        topic = "users"
        value_format = "JSON"

        SQLBuilder.build(
            "create",
            table_type="table",
            table_name=table_name,
            columns_type=columns_type,
            topic=topic,
            value_format=value_format,
        )
Exemplo n.º 3
0
    def test_value_format_error(self):
        sql_type = "create"
        table_type = "stream"
        table_name = "users_original"
        columns_type = [
            "registertime bigint", "gender varchar", "regionid varchar",
            "userid varchar"
        ]
        topic = "users"
        value_format = "foo"

        with self.assertRaises(IllegalValueFormatError):
            SQLBuilder.build(
                sql_type=sql_type,
                table_type=table_type,
                table_name=table_name,
                columns_type=columns_type,
                topic=topic,
                value_format=value_format,
            )
Exemplo n.º 4
0
    def test_sql_type_error(self):
        sql_type = "view"
        table_type = "stream"
        table_name = "users_original"
        columns_type = [
            "registertime bigint", "gender varchar", "regionid varchar",
            "userid varchar"
        ]
        topic = "users"
        value_format = "JSON"

        with self.assertRaises(SQLTypeNotImplementYetError):
            SQLBuilder.build(
                sql_type=sql_type,
                table_type=table_type,
                table_name=table_name,
                columns_type=columns_type,
                topic=topic,
                value_format=value_format,
            )
Exemplo n.º 5
0
    def test_create_table_without_key(self):
        table_name = 'users_original'
        columns_type = [
            'registertime bigint', 'gender varchar', 'regionid varchar',
            'userid varchar'
        ]
        topic = 'users'
        value_format = 'JSON'

        build_sql_str = SQLBuilder.build('create',
                                         table_type='table',
                                         table_name=table_name,
                                         columns_type=columns_type,
                                         topic=topic,
                                         value_format=value_format)
Exemplo n.º 6
0
    def test_create_table_without_key_delimited(self):
        table_name = 'users_original'
        columns_type = [
            'registertime bigint', 'gender varchar', 'regionid varchar',
            'userid varchar'
        ]
        topic = 'users'
        value_format = 'DELIMITED'

        build_sql_str = SQLBuilder.build('create',
                                         table_type='table',
                                         table_name=table_name,
                                         columns_type=columns_type,
                                         topic=topic,
                                         value_format=value_format)

        self.assertEqual(build_sql_str.lower(),
                         self.create_table_without_key_delimited.lower())
Exemplo n.º 7
0
    def test_value_format_error(self):
        sql_type = 'create'
        table_type = 'stream'
        table_name = 'users_original'
        columns_type = [
            'registertime bigint', 'gender varchar', 'regionid varchar',
            'userid varchar'
        ]
        topic = 'users'
        value_format = 'foo'

        with self.assertRaises(IllegalValueFormatError):
            build_sql_str = SQLBuilder.build(sql_type=sql_type,
                                             table_type=table_type,
                                             table_name=table_name,
                                             columns_type=columns_type,
                                             topic=topic,
                                             value_format=value_format)
Exemplo n.º 8
0
    def test_sql_type_error(self):
        sql_type = 'view'
        table_type = 'stream'
        table_name = 'users_original'
        columns_type = [
            'registertime bigint', 'gender varchar', 'regionid varchar',
            'userid varchar'
        ]
        topic = 'users'
        value_format = 'JSON'

        with self.assertRaises(SQLTypeNotImplementYetError):
            build_sql_str = SQLBuilder.build(sql_type=sql_type,
                                             table_type=table_type,
                                             table_name=table_name,
                                             columns_type=columns_type,
                                             topic=topic,
                                             value_format=value_format)
Exemplo n.º 9
0
    def test_create_stream_as_without_condition_select_star(self):
        sql_type = 'create_as'
        table_name = 'pageviews_valid'
        src_table = 'pageviews_original'
        kafka_topic = 'pageviews_valid'
        value_format = 'DELIMITED'

        built_sql_str = SQLBuilder.build(sql_type=sql_type,
                                         table_type='stream',
                                         table_name=table_name,
                                         src_table=src_table,
                                         kafka_topic=kafka_topic,
                                         timestamp='logtime',
                                         value_format=value_format)

        self.assertEqual(
            built_sql_str.lower(),
            self.create_stream_as_without_condition_select_star.lower())
Exemplo n.º 10
0
    def test_ksql_create_stream_by_builder(self):
        sql_type = 'create'
        table_type = 'stream'
        table_name = 'test_table'
        columns_type = ['viewtime bigint', 'userid varchar', 'pageid varchar']
        topic = self.exist_topic
        value_format = 'DELIMITED'

        ksql_string = SQLBuilder.build(sql_type=sql_type,
                                       table_type=table_type,
                                       table_name=table_name,
                                       columns_type=columns_type,
                                       topic=topic,
                                       value_format=value_format)

        r = self.api_client.ksql(ksql_string)
        self.assertEqual(r[0]['currentStatus']['commandStatus']['status'],
                         'SUCCESS')
Exemplo n.º 11
0
    def test_create_stream_as_without_condition_avro(self):
        sql_type = 'create_as'
        table_name = 'pageviews_valid'
        src_table = 'pageviews_original'
        kafka_topic = 'pageviews_valid'
        value_format = 'AVRO'
        select_columns = ['rowtime as logtime', '*']

        built_sql_str = SQLBuilder.build(sql_type=sql_type,
                                         table_type='stream',
                                         table_name=table_name,
                                         src_table=src_table,
                                         kafka_topic=kafka_topic,
                                         select_columns=select_columns,
                                         timestamp='logtime',
                                         value_format=value_format)

        self.assertEqual(built_sql_str.lower(),
                         self.create_stream_as_without_condition_avro.lower())
Exemplo n.º 12
0
    def test_create_stream_as_without_condition_select_star(self):
        sql_type = "create_as"
        table_name = "pageviews_valid"
        src_table = "pageviews_original"
        kafka_topic = "pageviews_valid"
        value_format = "DELIMITED"

        built_sql_str = SQLBuilder.build(
            sql_type=sql_type,
            table_type="stream",
            table_name=table_name,
            src_table=src_table,
            kafka_topic=kafka_topic,
            timestamp="logtime",
            value_format=value_format,
        )

        self.assertEqual(
            built_sql_str.lower(),
            self.create_stream_as_without_condition_select_star.lower())
Exemplo n.º 13
0
    def test_create_stream_without_key(self):
        table_name = "users_original"
        columns_type = [
            "registertime bigint", "gender varchar", "regionid varchar",
            "userid varchar"
        ]
        topic = "users"
        value_format = "JSON"

        build_sql_str = SQLBuilder.build(
            "create",
            table_type="stream",
            table_name=table_name,
            columns_type=columns_type,
            topic=topic,
            value_format=value_format,
        )

        self.assertEqual(build_sql_str.lower(),
                         self.create_stream_without_key.lower())
Exemplo n.º 14
0
    def test_create_table_with_key(self):
        table_name = 'users_original'
        columns_type = [
            'registertime bigint', 'gender varchar', 'regionid varchar',
            'userid varchar'
        ]
        topic = 'users'
        value_format = 'JSON'
        key = 'userid'

        build_sql_str = SQLBuilder.build('create',
                                         table_type='table',
                                         table_name=table_name,
                                         columns_type=columns_type,
                                         topic=topic,
                                         value_format=value_format,
                                         key=key)

        self.assertEqual(build_sql_str.lower(),
                         self.create_table_with_key.lower())
Exemplo n.º 15
0
    def test_create_stream_as_with_condition_double_qoute(self):
        sql_type = 'create_as'
        table_name = 'pageviews_valid'
        src_table = 'pageviews_original'
        kafka_topic = 'pageviews_valid'
        value_format = 'DELIMITED'
        select_columns = ['rowtime as logtime', '*']
        conditions = 'userid like "User_%" AND pageid like "Page_%"'

        built_sql_str = SQLBuilder.build(sql_type=sql_type,
                                         table_type='stream',
                                         table_name=table_name,
                                         src_table=src_table,
                                         kafka_topic=kafka_topic,
                                         select_columns=select_columns,
                                         timestamp='logtime',
                                         value_format=value_format,
                                         conditions=conditions)

        self.assertEqual(built_sql_str.lower(),
                         self.create_stream_as_with_condition.lower())
Exemplo n.º 16
0
    def test_ksql_create_stream_by_builder(self):
        sql_type = "create"
        table_type = "stream"
        table_name = "test_table"
        columns_type = ["viewtime bigint", "userid varchar", "pageid varchar"]
        topic = self.exist_topic
        value_format = "DELIMITED"

        utils.drop_stream(self.api_client, table_name)

        ksql_string = SQLBuilder.build(
            sql_type=sql_type,
            table_type=table_type,
            table_name=table_name,
            columns_type=columns_type,
            topic=topic,
            value_format=value_format,
        )

        r = self.api_client.ksql(ksql_string)
        self.assertEqual(r[0]["commandStatus"]["status"], "SUCCESS")
Exemplo n.º 17
0
    def test_create_stream_as_without_condition_avro(self):
        sql_type = "create_as"
        table_name = "pageviews_valid"
        src_table = "pageviews_original"
        kafka_topic = "pageviews_valid"
        value_format = "AVRO"
        select_columns = ["rowtime as logtime", "*"]

        built_sql_str = SQLBuilder.build(
            sql_type=sql_type,
            table_type="stream",
            table_name=table_name,
            src_table=src_table,
            kafka_topic=kafka_topic,
            select_columns=select_columns,
            timestamp="logtime",
            value_format=value_format,
        )

        self.assertEqual(built_sql_str.lower(),
                         self.create_stream_as_without_condition_avro.lower())