Exemplo n.º 1
0
 def test_discover_catalog_with_not_existing_table(self):
     """Validate if discovering catalog raises as exception when table not exist"""
     # Create config to discover a not existing table
     with self.assertRaises(snowflake.connector.errors.ProgrammingError):
         test_utils.discover_catalog(
             self.snowflake_conn, {
                 'tables':
                 f'{SCHEMA_NAME}.empty_table_2,{SCHEMA_NAME}.not_existing_table'
             })
Exemplo n.º 2
0
    def setUp(self):
        self.conn = test_utils.get_test_connection()

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute('CREATE TABLE a (`b c` int)')
                cursor.execute('INSERT INTO a (`b c`) VALUES (1)')

        self.catalog = test_utils.discover_catalog(self.conn, {})

        self.catalog.streams[0].stream = 'some_stream_name'

        self.catalog.streams[0].metadata = [{
            'breadcrumb': (),
            'metadata': {
                'selected': True,
                'table-key-properties': [],
                'database-name': 'tap_mysql_test'
            }
        }, {
            'breadcrumb': ('properties', 'b c'),
            'metadata': {
                'selected': True
            }
        }]

        test_utils.set_replication_method_and_key(self.catalog.streams[0],
                                                  'FULL_TABLE', None)
    def setUp(self):
        self.conn = test_utils.get_test_connection()

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute('CREATE TABLE incremental (val int, updated datetime)')
                cursor.execute('INSERT INTO incremental (val, updated) VALUES (1, \'2017-06-01\')')
                cursor.execute('INSERT INTO incremental (val, updated) VALUES (2, \'2017-06-20\')')
                cursor.execute('INSERT INTO incremental (val, updated) VALUES (3, \'2017-09-22\')')
                cursor.execute('CREATE TABLE integer_incremental (val int, updated int)')
                cursor.execute('INSERT INTO integer_incremental (val, updated) VALUES (1, 1)')
                cursor.execute('INSERT INTO integer_incremental (val, updated) VALUES (2, 2)')
                cursor.execute('INSERT INTO integer_incremental (val, updated) VALUES (3, 3)')

        self.catalog = test_utils.discover_catalog(self.conn, {})

        for stream in self.catalog.streams:
            stream.metadata = [
                {'breadcrumb': (),
                 'metadata': {
                     'selected': True,
                     'table-key-properties': [],
                     'database-name': 'tap_mysql_test'
                 }},
                {'breadcrumb': ('properties', 'val'), 'metadata': {'selected': True}}
            ]

            stream.stream = stream.table
            test_utils.set_replication_method_and_key(stream, 'INCREMENTAL', 'updated')
    def runTest(self):
        conn = test_utils.get_test_connection()

        with connect_with_backoff(conn) as open_conn:
            with open_conn.cursor() as cur:
                cur.execute('''
                    CREATE TABLE tab (
                      id INTEGER PRIMARY KEY,
                      a INTEGER,
                      b INTEGER)
                ''')

        catalog = test_utils.discover_catalog(conn, {})
        catalog.streams[0].stream = 'tab'
        catalog.streams[0].metadata = [
            {'breadcrumb': (), 'metadata': {'selected': True, 'database-name': 'tap_mysql_test'}},
            {'breadcrumb': ('properties', 'a'), 'metadata': {'selected': True}}
        ]

        test_utils.set_replication_method_and_key(catalog.streams[0], 'FULL_TABLE', None)

        global SINGER_MESSAGES
        SINGER_MESSAGES.clear()
        tap_mysql.do_sync(conn, {}, catalog, {})

        schema_message = list(filter(lambda m: isinstance(m, singer.SchemaMessage), SINGER_MESSAGES))[0]
        self.assertTrue(isinstance(schema_message, singer.SchemaMessage))
        # tap-mysql selects new fields by default. If a field doesn't appear in the schema, then it should be
        # selected
        expectedKeys = ['id', 'a', 'b']

        self.assertEqual(schema_message.schema['properties'].keys(), set(expectedKeys))
def init_tables(conn):
    with connect_with_backoff(conn) as open_conn:
        with open_conn.cursor() as cur:
            cur.execute("""
            CREATE TABLE table_1 (
            id  BIGINT AUTO_INCREMENT PRIMARY KEY,
            foo BIGINT,
            bar VARCHAR(10)
            )""")

            cur.execute("""
            CREATE TABLE table_2 (
            id  BIGINT AUTO_INCREMENT PRIMARY KEY,
            foo BIGINT,
            bar VARCHAR(10)
            )""")

    for record in TABLE_1_DATA:
        insert_record(conn, "table_1", record)

    for record in TABLE_2_DATA:
        insert_record(conn, "table_2", record)

    catalog = test_utils.discover_catalog(conn, {})

    return catalog
Exemplo n.º 6
0
    def setUp(self):
        self.conn = test_utils.get_test_connection()

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute("CREATE TABLE full_table (val int)")
                cursor.execute("INSERT INTO full_table (val) VALUES (1)")

        self.catalog = test_utils.discover_catalog(self.conn, {})
        for stream in self.catalog.streams:
            stream.key_properties = []

            stream.metadata = [
                {
                    "breadcrumb": (),
                    "metadata": {
                        "selected": True,
                        "database-name": "tap_mysql_test"
                    },
                },
                {
                    "breadcrumb": ("properties", "val"),
                    "metadata": {
                        "selected": True
                    }
                },
            ]

            stream.stream = stream.table
            test_utils.set_replication_method_and_key(stream, "FULL_TABLE",
                                                      None)
Exemplo n.º 7
0
    def setUp(self):
        self.conn = test_utils.get_test_connection()

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute('CREATE TABLE full_table (val int)')
                cursor.execute('INSERT INTO full_table (val) VALUES (1)')

        self.catalog = test_utils.discover_catalog(self.conn, {})
        for stream in self.catalog.streams:
            stream.key_properties = []

            stream.metadata = [{
                'breadcrumb': (),
                'metadata': {
                    'selected': True,
                    'database-name': 'tap_mysql_test'
                }
            }, {
                'breadcrumb': ('properties', 'val'),
                'metadata': {
                    'selected': True
                }
            }]

            stream.stream = stream.table
            test_utils.set_replication_method_and_key(stream, 'FULL_TABLE',
                                                      None)
Exemplo n.º 8
0
    def setUpClass(cls):
        conn = test_utils.get_test_connection()

        with connect_with_backoff(conn) as open_conn:
            with open_conn.cursor() as cur:
                cur.execute('''
                CREATE TABLE test_type_mapping (
                c_pk INTEGER PRIMARY KEY,
                c_decimal DECIMAL,
                c_decimal_2_unsigned DECIMAL(5, 2) UNSIGNED,
                c_decimal_2 DECIMAL(11, 2),
                c_tinyint TINYINT,
                c_tinyint_1 TINYINT(1),
                c_tinyint_1_unsigned TINYINT(1) UNSIGNED,
                c_smallint SMALLINT,
                c_mediumint MEDIUMINT,
                c_int INT,
                c_bigint BIGINT,
                c_bigint_unsigned BIGINT(20) UNSIGNED,
                c_float FLOAT,
                c_double DOUBLE,
                c_bit BIT(4),
                c_date DATE,
                c_time TIME,
                c_year YEAR
                )''')

        catalog = test_utils.discover_catalog(conn, {})
        cls.schema = catalog.streams[0].schema
        cls.metadata = catalog.streams[0].metadata
Exemplo n.º 9
0
    def setUp(self):
        self.conn = test_utils.get_test_connection()

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute("CREATE TABLE a (`b c` int)")
                cursor.execute("INSERT INTO a (`b c`) VALUES (1)")

        self.catalog = test_utils.discover_catalog(self.conn, {})

        self.catalog.streams[0].stream = "some_stream_name"

        self.catalog.streams[0].metadata = [
            {
                "breadcrumb": (),
                "metadata": {
                    "selected": True,
                    "table-key-properties": [],
                    "database-name": "tap_mysql_test",
                },
            },
            {
                "breadcrumb": ("properties", "b c"),
                "metadata": {
                    "selected": True
                }
            },
        ]

        test_utils.set_replication_method_and_key(self.catalog.streams[0],
                                                  "FULL_TABLE", None)
Exemplo n.º 10
0
    def test_discover_catalog_with_strategy_defined(self):
        """Validate if discovering catalog adds the sync strategy and incrementing col if provided"""
        config = {
            'tables': f'{DB_NAME}.{SCHEMA_NAME}.empty_table_1',
            'metadata': {
                f'{DB_NAME}.{SCHEMA_NAME}.empty_table_1': {
                    'table-key-properties': ['keys'],
                    'replication-key': 'column1',
                    'replication-method': 'INCREMENTAL',
                    'selected': True
                }
            }
        }
        catalog = test_utils.discover_catalog(self.snowflake_conn, config)

        stream = catalog.streams[0]
        stream_metadata = stream.to_dict().get('metadata')[0].get('metadata')
        self.assertEqual(
            stream_metadata, {
                'table-key-properties': ['keys'],
                'replication-key': 'column1',
                'replication-method': 'INCREMENTAL',
                'selected-by-default': False,
                'database-name': f'{DB_NAME}',
                'schema-name': f'{SCHEMA_NAME}',
                'row-count': 0,
                'is-view': False,
                'selected': True
            })
Exemplo n.º 11
0
    def test_do_not_discover_key_properties_for_view(self):
        catalog = test_utils.discover_catalog(self.conn, {})
        primary_keys = {}
        for c in catalog.streams:
            primary_keys[c.table] = singer.metadata.to_map(c.metadata).get(
                (), {}).get('table-key-properties')

        self.assertEqual(primary_keys, {'a_table': ['id'], 'a_view': None})
Exemplo n.º 12
0
    def test_do_not_discover_key_properties_for_view(self):
        catalog = test_utils.discover_catalog(self.conn, {})
        primary_keys = {}
        for c in catalog.streams:
            primary_keys[c.table] = (singer.metadata.to_map(c.metadata).get(
                (), {}).get("table-key-properties"))

        self.assertEqual(primary_keys, {"a_table": ["id"], "a_view": None})
Exemplo n.º 13
0
    def test_discovery_sets_is_view(self):
        catalog = test_utils.discover_catalog(self.conn, {})
        is_view = {}

        for stream in catalog.streams:
            md_map = singer.metadata.to_map(stream.metadata)
            is_view[stream.table] = md_map.get((), {}).get('is-view')

        self.assertEqual(is_view, {'a_table': False, 'a_view': True})
    def setUp(self):
        self.maxDiff = None
        self.state = {}
        self.conn = test_utils.get_test_connection()

        log_file, log_pos = binlog.fetch_current_log_file_and_pos(self.conn)

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute('CREATE TABLE binlog_1 (id int, updated datetime)')
                cursor.execute('CREATE TABLE binlog_2 (id int, updated datetime)')
                cursor.execute('INSERT INTO binlog_1 (id, updated) VALUES (1, \'2017-06-01\')')
                cursor.execute('INSERT INTO binlog_1 (id, updated) VALUES (2, \'2017-06-20\')')
                cursor.execute('INSERT INTO binlog_1 (id, updated) VALUES (3, \'2017-09-22\')')
                cursor.execute('INSERT INTO binlog_2 (id, updated) VALUES (1, \'2017-10-22\')')
                cursor.execute('INSERT INTO binlog_2 (id, updated) VALUES (2, \'2017-11-10\')')
                cursor.execute('INSERT INTO binlog_2 (id, updated) VALUES (3, \'2017-12-10\')')
                cursor.execute('UPDATE binlog_1 set updated=\'2018-06-18\' WHERE id = 3')
                cursor.execute('UPDATE binlog_2 set updated=\'2018-06-18\' WHERE id = 2')
                cursor.execute('DELETE FROM binlog_1 WHERE id = 2')
                cursor.execute('DELETE FROM binlog_2 WHERE id = 1')

            open_conn.commit()

        self.catalog = test_utils.discover_catalog(self.conn, {})

        for stream in self.catalog.streams:
            stream.stream = stream.table

            stream.metadata = [
                {'breadcrumb': (),
                 'metadata': {
                     'selected': True,
                     'database-name': 'tap_mysql_test',
                     'table-key-propertes': ['id']
                 }},
                {'breadcrumb': ('properties', 'id'), 'metadata': {'selected': True}},
                {'breadcrumb': ('properties', 'updated'), 'metadata': {'selected': True}}
            ]

            test_utils.set_replication_method_and_key(stream, 'LOG_BASED', None)

            self.state = singer.write_bookmark(self.state,
                                               stream.tap_stream_id,
                                               'log_file',
                                               log_file)

            self.state = singer.write_bookmark(self.state,
                                               stream.tap_stream_id,
                                               'log_pos',
                                               log_pos)

            self.state = singer.write_bookmark(self.state,
                                               stream.tap_stream_id,
                                               'version',
                                               singer.utils.now())
Exemplo n.º 15
0
    def test_generate_sql_full_sync(self):
        """Validate the where clause is filtering properly"""
        catalog = test_utils.discover_catalog(
            self.snowflake_conn, {'tables': f'{SCHEMA_NAME}.empty_table_1'},
            select_all=True)

        catalog_entry = catalog.streams[0]
        columns = list(catalog_entry.schema.properties.keys())
        select_sql = common.generate_sql_query(catalog_entry, columns)
        assert select_sql == f'SELECT "C_PK","C_INT" FROM "{DB_NAME}"."{SCHEMA_NAME}"."EMPTY_TABLE_1"'
Exemplo n.º 16
0
    def test_discover_catalog_with_view(self):
        """Validate if discovering catalog with filter_tables option working as expected"""
        # Create config to discover only one view
        catalog = test_utils.discover_catalog(
            self.snowflake_conn, {'tables': f'{SCHEMA_NAME}.empty_view_1'})

        # Only one view should be discovered
        tap_stream_ids = [s.tap_stream_id for s in catalog.streams]
        self.assertCountEqual(tap_stream_ids,
                              [f'{DB_NAME}-TAP_SNOWFLAKE_TEST-EMPTY_VIEW_1'])
    def test_discover_catalog_with_single_table(self):
        """Validate if discovering catalog with filter_tables option working as expected"""
        # Create config to discover only one table
        catalog = test_utils.discover_catalog(
            self.snowflake_conn, {'tables': f'{SCHEMA_NAME}.empty_table_2'})

        # Only one table should be discovered
        tap_stream_ids = [s.tap_stream_id for s in catalog.streams]
        self.assertCountEqual(
            tap_stream_ids,
            ['ANALYTICS_DB_TEST-TAP_SNOWFLAKE_TEST-EMPTY_TABLE_2'])
Exemplo n.º 18
0
    def runTest(self):
        catalog = test_utils.discover_catalog(self.conn, {})

        primary_keys = {}
        for c in catalog.streams:
            primary_keys[c.table] = singer.metadata.to_map(c.metadata).get(
                (), {}).get('table-key-properties')

        self.assertEqual(primary_keys, {
            'good_pk_tab': ['good_pk'],
            'bad_pk_tab': []
        })
Exemplo n.º 19
0
    def runTest(self):
        catalog = test_utils.discover_catalog(self.conn, {})

        primary_keys = {}
        for c in catalog.streams:
            primary_keys[c.table] = (singer.metadata.to_map(c.metadata).get(
                (), {}).get("table-key-properties"))

        self.assertEqual(primary_keys, {
            "good_pk_tab": ["good_pk"],
            "bad_pk_tab": []
        })
Exemplo n.º 20
0
    def setUp(self):
        self.conn = test_utils.get_test_connection()

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute(
                    "CREATE TABLE incremental (val int, updated datetime)")
                cursor.execute(
                    "INSERT INTO incremental (val, updated) VALUES (1, '2017-06-01')"
                )
                cursor.execute(
                    "INSERT INTO incremental (val, updated) VALUES (2, '2017-06-20')"
                )
                cursor.execute(
                    "INSERT INTO incremental (val, updated) VALUES (3, '2017-09-22')"
                )
                cursor.execute(
                    "CREATE TABLE integer_incremental (val int, updated int)")
                cursor.execute(
                    "INSERT INTO integer_incremental (val, updated) VALUES (1, 1)"
                )
                cursor.execute(
                    "INSERT INTO integer_incremental (val, updated) VALUES (2, 2)"
                )
                cursor.execute(
                    "INSERT INTO integer_incremental (val, updated) VALUES (3, 3)"
                )

        self.catalog = test_utils.discover_catalog(self.conn, {})

        for stream in self.catalog.streams:
            stream.metadata = [
                {
                    "breadcrumb": (),
                    "metadata": {
                        "selected": True,
                        "table-key-properties": [],
                        "database-name": "tap_mysql_test",
                    },
                },
                {
                    "breadcrumb": ("properties", "val"),
                    "metadata": {
                        "selected": True
                    }
                },
            ]

            stream.stream = stream.table
            test_utils.set_replication_method_and_key(stream, "INCREMENTAL",
                                                      "updated")
Exemplo n.º 21
0
 def test_generate_sql_incremental_sync_without_bookmark(self):
     """Validate the where clause is filtering properly, when incremental and no bookmark yet"""
     catalog = test_utils.discover_catalog(self.snowflake_conn, {
         'tables': f'{DB_NAME}.{SCHEMA_NAME}.EMPTY_TABLE_1',
         'metadata': {
             f'{DB_NAME}.{SCHEMA_NAME}.EMPTY_TABLE_1': {
                 'replication-method': 'INCREMENTAL',
                 'replication-key': 'REP_KEY'
             }
         }
     },
                                           select_all=True)
     catalog_entry = catalog.streams[0]
     columns = list(catalog_entry.schema.properties.keys())
     select_sql = common.generate_sql_query(catalog_entry, columns)
     assert select_sql == f'SELECT "C_PK","C_INT" FROM "{DB_NAME}"."{SCHEMA_NAME}"."EMPTY_TABLE_1" ORDER BY "REP_KEY" ASC'
Exemplo n.º 22
0
 def test_generate_sql_missing_lookback_config(self):
     """Validate the where clause is filtering properly, when full table and look back window"""
     with pytest.raises(Exception):
         catalog = test_utils.discover_catalog(self.snowflake_conn, {
             'tables': f'{DB_NAME}.{SCHEMA_NAME}.EMPTY_TABLE_1',
             'metadata': {
                 f'{DB_NAME}.{SCHEMA_NAME}.EMPTY_TABLE_1': {
                     'replication-method': 'FULL_TABLE',
                     'rolling_lookback': {'MISSING_REQUIRED_CONFIG'}
                 }
             }
         },
                                               select_all=True)
         catalog_entry = catalog.streams[0]
         columns = list(catalog_entry.schema.properties.keys())
         common.generate_sql_query(catalog_entry, columns)
    def setUp(self):
        self.conn = test_utils.get_test_connection()

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute(
                    # BINARY is presently supported
                    'CREATE TABLE good_pk_tab (good_pk BINARY(10), age INT, PRIMARY KEY (good_pk))')

                cursor.execute("INSERT INTO good_pk_tab (good_pk, age) VALUES "
                               "(BINARY('a'), 20), "
                               "(BINARY('b'), 30), "
                               "(BINARY('c'), 30), "
                               "(BINARY('d'), 40)")

        self.catalog = test_utils.discover_catalog(self.conn, {})
Exemplo n.º 24
0
    def test_discover_catalog_without_strategy_defined(self):
        """Validate if discovering catalog excludes sync strategy if not configured"""
        catalog = test_utils.discover_catalog(
            self.snowflake_conn, {'tables': f'{SCHEMA_NAME}.empty_table_1'})

        # table should be discovered
        stream = catalog.streams[0]
        stream_metadata = stream.to_dict().get('metadata')[0].get('metadata')
        self.assertEqual(
            stream_metadata, {
                'selected-by-default': False,
                'database-name': f'{DB_NAME}',
                'schema-name': f'{SCHEMA_NAME}',
                'row-count': 0,
                'is-view': False,
            })
Exemplo n.º 25
0
    def test_discover_catalog_with_multiple_table(self):
        """Validate if discovering catalog with filter_tables option working as expected"""
        # Create config to discover three tables
        catalog = test_utils.discover_catalog(
            self.snowflake_conn, {
                'tables':
                f'{SCHEMA_NAME}.empty_table_1,{SCHEMA_NAME}.empty_table_2,{SCHEMA_NAME}.test_type_mapping'
            })

        # Three tables should be discovered
        tap_stream_ids = [s.tap_stream_id for s in catalog.streams]
        self.assertCountEqual(tap_stream_ids, [
            f'{DB_NAME}-TAP_SNOWFLAKE_TEST-EMPTY_TABLE_1',
            f'{DB_NAME}-TAP_SNOWFLAKE_TEST-EMPTY_TABLE_2',
            f'{DB_NAME}-TAP_SNOWFLAKE_TEST-TEST_TYPE_MAPPING'
        ])
Exemplo n.º 26
0
    def runTest(self):
        conn = test_utils.get_test_connection()

        with connect_with_backoff(conn) as open_conn:
            with open_conn.cursor() as cur:
                cur.execute("""
                    CREATE TABLE tab (
                      id INTEGER PRIMARY KEY,
                      a INTEGER,
                      b INTEGER)
                """)

        catalog = test_utils.discover_catalog(conn, {})
        catalog.streams[0].stream = "tab"
        catalog.streams[0].metadata = [
            {
                "breadcrumb": (),
                "metadata": {
                    "selected": True,
                    "database-name": "tap_mysql_test"
                }
            },
            {
                "breadcrumb": ("properties", "a"),
                "metadata": {
                    "selected": True
                }
            },
        ]

        test_utils.set_replication_method_and_key(catalog.streams[0],
                                                  "FULL_TABLE", None)

        global SINGER_MESSAGES
        SINGER_MESSAGES.clear()
        tap_mysql.do_sync(conn, {}, catalog, {})

        schema_message = list(
            filter(lambda m: isinstance(m, singer.SchemaMessage),
                   SINGER_MESSAGES))[0]
        self.assertTrue(isinstance(schema_message, singer.SchemaMessage))
        # tap-mysql selects new fields by default. If a field doesn't appear in the schema, then it should be
        # selected
        expectedKeys = ["id", "a", "b"]

        self.assertEqual(schema_message.schema["properties"].keys(),
                         set(expectedKeys))
Exemplo n.º 27
0
    def test_discover_catalog_select_all(self):
        """Validate if discovering catalog select-all works"""
        catalog = test_utils.discover_catalog(
            self.snowflake_conn, {'tables': f'{SCHEMA_NAME}.empty_table_1'},
            select_all=True)

        # table should be discovered
        stream = catalog.streams[0]
        stream_metadata = stream.to_dict().get('metadata')[0].get('metadata')
        self.assertEqual(
            stream_metadata, {
                'replication-method': 'FULL_TABLE',
                'selected-by-default': True,
                'database-name': f'{DB_NAME}',
                'schema-name': f'{SCHEMA_NAME}',
                'row-count': 0,
                'is-view': False,
                'selected': True
            })
Exemplo n.º 28
0
 def test_generate_sql_full_sync_lookback(self):
     """Validate the where clause is filtering properly, when full table and look back window"""
     catalog = test_utils.discover_catalog(self.snowflake_conn, {
         'tables': f'{DB_NAME}.{SCHEMA_NAME}.EMPTY_TABLE_1',
         'metadata': {
             f'{DB_NAME}.{SCHEMA_NAME}.EMPTY_TABLE_1': {
                 'replication-method': 'FULL_TABLE',
                 'rolling_lookback': {
                     'time_unit': 'day',
                     'time_amount': '7',
                     'time_column': 'c_datetime'
                 }
             }
         }
     },
                                           select_all=True)
     catalog_entry = catalog.streams[0]
     columns = list(catalog_entry.schema.properties.keys())
     select_sql = common.generate_sql_query(catalog_entry, columns)
     assert select_sql == f'SELECT "C_PK","C_INT" FROM "{DB_NAME}"."{SCHEMA_NAME}"."EMPTY_TABLE_1" WHERE "c_datetime" >= DATEADD(day, -7, SYSTIMESTAMP())'
Exemplo n.º 29
0
    def setUp(self):
        self.conn = test_utils.get_test_connection()
        self.state = {}

        log_file, log_pos = binlog.fetch_current_log_file_and_pos(self.conn)

        with connect_with_backoff(self.conn) as open_conn:
            with open_conn.cursor() as cursor:
                cursor.execute(
                    'CREATE TABLE datetime_types (id int, datetime_col datetime, timestamp_col timestamp, time_col time, date_col date)'
                )
                cursor.execute(
                    'INSERT INTO datetime_types (id, datetime_col, timestamp_col, time_col, date_col) VALUES (1, \'0000-00-00\', \'0000-00-00 00:00:00\', \'00:00:00\', \'0000-00-00\' )'
                )
                cursor.execute(
                    'INSERT INTO datetime_types (id, datetime_col, timestamp_col, time_col, date_col) VALUES (2, NULL, NULL, NULL, NULL)'
                )
            open_conn.commit()

        self.catalog = test_utils.discover_catalog(self.conn, {})

        for stream in self.catalog.streams:
            stream.stream = stream.table

            stream.metadata = [{
                'breadcrumb': (),
                'metadata': {
                    'selected': True,
                    'database-name': 'tap_mysql_test',
                    'table-key-propertes': ['id']
                }
            }, {
                'breadcrumb': ('properties', 'id'),
                'metadata': {
                    'selected': True
                }
            }, {
                'breadcrumb': ('properties', 'datetime_col'),
                'metadata': {
                    'selected': True
                }
            }, {
                'breadcrumb': ('properties', 'timestamp_col'),
                'metadata': {
                    'selected': True
                }
            }, {
                'breadcrumb': ('properties', 'time_col'),
                'metadata': {
                    'selected': True
                }
            }, {
                'breadcrumb': ('properties', 'date_col'),
                'metadata': {
                    'selected': True
                }
            }]

            test_utils.set_replication_method_and_key(stream, 'LOG_BASED',
                                                      None)

            self.state = singer.write_bookmark(self.state,
                                               stream.tap_stream_id,
                                               'log_file', log_file)

            self.state = singer.write_bookmark(self.state,
                                               stream.tap_stream_id, 'log_pos',
                                               log_pos)

            self.state = singer.write_bookmark(self.state,
                                               stream.tap_stream_id, 'version',
                                               singer.utils.now())
Exemplo n.º 30
0
    def setUpClass(cls):
        cls.snowflake_conn = test_utils.get_test_connection()

        with cls.snowflake_conn.open_connection() as open_conn:
            with open_conn.cursor() as cur:
                cur.execute('''
                CREATE TABLE {}.test_type_mapping (
                c_pk INTEGER PRIMARY KEY,
                c_decimal DECIMAL,
                c_decimal_2 DECIMAL(11, 2),
                c_smallint SMALLINT,
                c_int INT,
                c_bigint BIGINT,
                c_float FLOAT,
                c_double DOUBLE,
                c_date DATE,
                c_datetime DATETIME,
                c_time TIME,
                c_binary BINARY,
                c_varbinary VARBINARY(16),
                c_object OBJECT,
                c_array ARRAY
                )'''.format(SCHEMA_NAME))

                cur.execute(f'''
                INSERT INTO {SCHEMA_NAME}.test_type_mapping
                SELECT 1
                      ,12345
                      ,123456789.12
                      ,123
                      ,12345
                      ,1234567890
                      ,123.123
                      ,123.123
                      ,'2019-08-01'
                      ,'2019-08-01 17:23:59'
                      ,'17:23:59'
                      ,HEX_ENCODE('binary')
                      ,HEX_ENCODE('varbinary')
                      ,parse_json($${{'test_key':['test_val']}}$$)
                      ,array_construct(1, object_construct('foo', 'bar'), array_construct(3,3,3))
                ''')

                cur.execute('''
                CREATE TABLE {}.empty_table_1 (
                c_pk INTEGER PRIMARY KEY,
                c_int INT
                )'''.format(SCHEMA_NAME))

                cur.execute('''
                CREATE TABLE {}.empty_table_2 (
                c_pk INTEGER PRIMARY KEY,
                c_int INT
                )'''.format(SCHEMA_NAME))

                cur.execute('''
                CREATE VIEW {}.empty_view_1 AS
                SELECT c_pk, c_int FROM {}.empty_table_1
                '''.format(SCHEMA_NAME, SCHEMA_NAME))

        # Discover catalog object including only TEST_TYPE_MAPPING table to run detailed tests later
        cls.dt_catalog = test_utils.discover_catalog(
            cls.snowflake_conn, {'tables': f'{SCHEMA_NAME}.test_type_mapping'})

        cls.dt_stream = cls.dt_catalog.streams[0]
        cls.dt_schema = cls.dt_catalog.streams[0].schema
        cls.dt_metadata = cls.dt_catalog.streams[0].metadata