diff --git a/src/examples/sqlalchemy_orm.py b/src/examples/sqlalchemy_orm.py index 22a8939..84fe8fe 100644 --- a/src/examples/sqlalchemy_orm.py +++ b/src/examples/sqlalchemy_orm.py @@ -35,6 +35,7 @@ class MyTable(Base): col_ts = Column(qdbc.Timestamp, primary_key=True) col_geohash = Column(qdbc.GeohashInt) col_long256 = Column(qdbc.Long256) + col_varchar = Column(qdbc.Varchar) def main(): diff --git a/src/qdb_superset/db_engine_specs/questdb.py b/src/qdb_superset/db_engine_specs/questdb.py index 0ca6d56..335f120 100644 --- a/src/qdb_superset/db_engine_specs/questdb.py +++ b/src/qdb_superset/db_engine_specs/questdb.py @@ -123,6 +123,11 @@ class QuestDbEngineSpec(BaseEngineSpec, BasicParametersMixin): qdbc_types.String, GenericDataType.STRING, ), + ( + re.compile("^VARCHAR$", re.IGNORECASE), + qdbc_types.Varchar, + GenericDataType.STRING, + ), ( re.compile("^SYMBOL$", re.IGNORECASE), qdbc_types.Symbol, @@ -226,6 +231,7 @@ def get_column_spec( elif name_u in ( "SYMBOL", "STRING", + "VARCHAR", "CHAR", "LONG256", "UUID", diff --git a/src/questdb_connect/__init__.py b/src/questdb_connect/__init__.py index 32214a2..82042ef 100644 --- a/src/questdb_connect/__init__.py +++ b/src/questdb_connect/__init__.py @@ -38,6 +38,7 @@ String, Symbol, Timestamp, + Varchar, geohash_class, geohash_type_name, resolve_type_from_name, diff --git a/src/questdb_connect/types.py b/src/questdb_connect/types.py index 0d200a1..a780670 100644 --- a/src/questdb_connect/types.py +++ b/src/questdb_connect/types.py @@ -164,6 +164,10 @@ class IPv4(QDBTypeMixin): __visit_name__ = "IPV4" type_code = 26 +class Varchar(QDBTypeMixin): + __visit_name__ = "VARCHAR" + type_code = 27 + QUESTDB_TYPES = [ Boolean, @@ -186,6 +190,7 @@ class IPv4(QDBTypeMixin): UUID, Long128, IPv4, + Varchar, ] diff --git a/tests/conftest.py b/tests/conftest.py index 6b3a9da..850f5fa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -86,6 +86,7 @@ class TableModel(Base): col_ts = Column('col_ts', qdbc.Timestamp, primary_key=True) col_geohash = Column('col_geohash', qdbc.GeohashInt) col_long256 = Column('col_long256', qdbc.Long256) + col_varchar = Column('col_varchar', qdbc.Varchar) Base.metadata.drop_all(test_engine) Base.metadata.create_all(test_engine) diff --git a/tests/test_dialect.py b/tests/test_dialect.py index 6e03307..d7c0b6f 100644 --- a/tests/test_dialect.py +++ b/tests/test_dialect.py @@ -21,11 +21,11 @@ def test_insert(test_engine, test_model): expected = ("(True, 8, 12, 13, 14, 15.234, 16.88993244, 'coconut', 'banana', 'C', " "UUID('6d5eb038-63d1-4971-8484-30c16e13de5b'), datetime.datetime(2023, 4, 12, " "0, 0), datetime.datetime(2023, 4, 12, 23, 55, 59, 342380), 'dfvgsj', " - "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a')\n" + "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', 'pineapple')\n" "(True, 8, 12, 13, 14, 15.234, 16.88993244, 'coconut', 'banana', 'C', " "UUID('6d5eb038-63d1-4971-8484-30c16e13de5b'), datetime.datetime(2023, 4, 12, " "0, 0), datetime.datetime(2023, 4, 12, 23, 55, 59, 342380), 'dfvgsj', " - "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a')") + "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', 'pineapple')") insert_stmt = sqla.insert(test_model).values( col_boolean=True, col_byte=8, @@ -41,7 +41,8 @@ def test_insert(test_engine, test_model): col_date=now_date, col_ts=now, col_geohash='dfvgsj2vptwu', - col_long256='0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a' + col_long256='0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', + col_varchar='pineapple' ) conn.execute(insert_stmt) conn.execute(sqla.insert(test_model), { @@ -59,7 +60,8 @@ def test_insert(test_engine, test_model): 'col_date': now_date, 'col_ts': now, 'col_geohash': 'dfvgsj2vptwu', - 'col_long256': '0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a' + 'col_long256': '0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', + 'col_varchar': 'pineapple' }) assert collect_select_all(conn, expected_rows=2) == expected assert collect_select_all_raw_connection(test_engine, expected_rows=2) == expected @@ -85,7 +87,8 @@ def test_inspect_1(test_engine, test_model): col_date=now_date, col_ts=now, col_geohash='dfvgsj2vptwu', - col_long256='0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a' + col_long256='0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', + col_varchar='pineapple' )) session.commit() finally: @@ -109,7 +112,8 @@ def test_inspect_1(test_engine, test_model): ('col_date', qdbc.Date(), False), ('col_ts', qdbc.Timestamp(), True), ('col_geohash', qdbc.GeohashInt(), False), - ('col_long256', qdbc.Long256(), False) + ('col_long256', qdbc.Long256(), False), + ('col_varchar', qdbc.Varchar(), False), ]) @@ -133,15 +137,15 @@ def test_multiple_insert(test_engine, test_model): expected = ("(True, 8, 12, 0, 14, 15.234, 16.88993244, 'coconut', 'banana', 'C', " "UUID('6d5eb038-63d1-4971-8484-30c16e13de5b'), datetime.datetime(2023, 4, 12, " "0, 0), datetime.datetime(2023, 4, 12, 23, 55, 59, 342380), 'dfvgsj', " - "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a')\n" + "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', 'pineapple')\n" "(True, 8, 12, 1, 14, 15.234, 16.88993244, 'coconut', 'banana', 'C', " "UUID('6d5eb038-63d1-4971-8484-30c16e13de5b'), datetime.datetime(2023, 4, 12, " "0, 0), datetime.datetime(2023, 4, 12, 23, 55, 59, 342380), 'dfvgsj', " - "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a')\n" + "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', 'pineapple')\n" "(True, 8, 12, 2, 14, 15.234, 16.88993244, 'coconut', 'banana', 'C', " "UUID('6d5eb038-63d1-4971-8484-30c16e13de5b'), datetime.datetime(2023, 4, 12, " "0, 0), datetime.datetime(2023, 4, 12, 23, 55, 59, 342380), 'dfvgsj', " - "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a')") + "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', 'pineapple')") try: for idx in range(num_rows): session.add(test_model( @@ -159,7 +163,8 @@ def test_multiple_insert(test_engine, test_model): col_date=now_date, col_ts=now, col_geohash='dfvgsj2vptwu', - col_long256='0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a' + col_long256='0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', + col_varchar='pineapple' )) session.commit() assert collect_select_all(session, expected_rows=num_rows) == expected @@ -177,15 +182,15 @@ def test_bulk_insert(test_engine, test_model): expected = ("(True, 8, 12, 0, 14, 15.234, 16.88993244, 'coconut', 'banana', 'C', " "UUID('6d5eb038-63d1-4971-8484-30c16e13de5b'), datetime.datetime(2023, 4, 12, " "0, 0), datetime.datetime(2023, 4, 12, 23, 55, 59, 342380), 'dfvgsj', " - "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a')\n" + "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', 'pineapple')\n" "(True, 8, 12, 1, 14, 15.234, 16.88993244, 'coconut', 'banana', 'C', " "UUID('6d5eb038-63d1-4971-8484-30c16e13de5b'), datetime.datetime(2023, 4, 12, " "0, 0), datetime.datetime(2023, 4, 12, 23, 55, 59, 342380), 'dfvgsj', " - "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a')\n" + "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', 'pineapple')\n" "(True, 8, 12, 2, 14, 15.234, 16.88993244, 'coconut', 'banana', 'C', " "UUID('6d5eb038-63d1-4971-8484-30c16e13de5b'), datetime.datetime(2023, 4, 12, " "0, 0), datetime.datetime(2023, 4, 12, 23, 55, 59, 342380), 'dfvgsj', " - "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a')") + "'0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', 'pineapple')") models = [ test_model( col_boolean=True, @@ -202,7 +207,8 @@ def test_bulk_insert(test_engine, test_model): col_date=now_date, col_ts=now, col_geohash='dfvgsj2vptwu', - col_long256='0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a' + col_long256='0xa3b400fcf6ed707d710d5d4e672305203ed3cc6254d1cefe313e4a465861f42a', + col_varchar='pineapple' ) for idx in range(num_rows) ] try: diff --git a/tests/test_types.py b/tests/test_types.py index 882d777..9135bdd 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -34,6 +34,7 @@ def test_superset_default_mappings(): (re.compile("^UUID$", re.IGNORECASE), qdbc.UUID), (re.compile("^LONG118$", re.IGNORECASE), qdbc.UUID), (re.compile("^IPV4$", re.IGNORECASE), qdbc.IPv4), + (re.compile("^VARCHAR$", re.IGNORECASE), qdbc.Varchar), ) for type_class in qdbc.QUESTDB_TYPES: for pattern, _expected_type in default_column_type_mappings: