Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
[AP-NNNN] Map bit to boolean values (#40)
Browse files Browse the repository at this point in the history
* Map bit to boolean values

* Add test for bit2boolean mapping

Co-authored-by: Elena Ghita <[email protected]>
  • Loading branch information
ile-g and Elena Ghita authored Oct 16, 2020
1 parent 60f67df commit 06c1cb3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tap_mysql/sync_strategies/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def row_to_singer_record(catalog_entry, version, row, columns, time_extracted):
elif 'boolean' in property_type or property_type == 'boolean':
if elem is None:
boolean_representation = None
elif elem == 0:
elif elem == 0 or elem == b'\x00':
boolean_representation = False
else:
boolean_representation = True
Expand Down
42 changes: 42 additions & 0 deletions tests/test_tap_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,48 @@ def test_open_connections_with_invalid_session_sqls(self):
'SET SESSION wait_timeout=28800'])


class TestBitBooleanMapping(unittest.TestCase):

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 bit_booleans_table(`id` int, `c_bit` BIT(4))")
cursor.execute("INSERT INTO bit_booleans_table(`id`,`c_bit`) VALUES "
"(1, b'0000'),"
"(2, NULL),"
"(3, b'0010')")

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


def test_sync_messages_are_correct(self):

self.catalog.streams[0] = test_utils.set_replication_method_and_key(self.catalog.streams[0], 'FULL_TABLE', None)
self.catalog.streams[0] = test_utils.set_selected(self.catalog.streams[0], True)

global SINGER_MESSAGES
SINGER_MESSAGES.clear()

tap_mysql.do_sync(self.conn, {}, self.catalog, {})

record_messages = list(filter(lambda m: isinstance(m, singer.RecordMessage), SINGER_MESSAGES))

self.assertEqual(len(record_messages), 3)
self.assertListEqual([
{'id': 1, 'c_bit': False},
{'id': 2, 'c_bit': None},
{'id': 3, 'c_bit': True},
], [rec.record for rec in record_messages])


def tearDown(self) -> None:
with connect_with_backoff(self.conn) as open_conn:
with open_conn.cursor() as cursor:
cursor.execute('DROP TABLE bit_booleans_table;')


if __name__ == "__main__":
test1 = TestBinlogReplication()
test1.setUp()
Expand Down

0 comments on commit 06c1cb3

Please sign in to comment.