コード例 #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())
コード例 #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,
        )
コード例 #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,
            )
コード例 #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,
            )
コード例 #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)
コード例 #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())
コード例 #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)
コード例 #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)
コード例 #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())
コード例 #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')
コード例 #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())
コード例 #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())
コード例 #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())
コード例 #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())
コード例 #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())
コード例 #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")
コード例 #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())