Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for VARCHAR #21

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/examples/sqlalchemy_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
6 changes: 6 additions & 0 deletions src/qdb_superset/db_engine_specs/questdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -226,6 +231,7 @@ def get_column_spec(
elif name_u in (
"SYMBOL",
"STRING",
"VARCHAR",
"CHAR",
"LONG256",
"UUID",
Expand Down
1 change: 1 addition & 0 deletions src/questdb_connect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
String,
Symbol,
Timestamp,
Varchar,
geohash_class,
geohash_type_name,
resolve_type_from_name,
Expand Down
5 changes: 5 additions & 0 deletions src/questdb_connect/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -186,6 +190,7 @@ class IPv4(QDBTypeMixin):
UUID,
Long128,
IPv4,
Varchar,
]


Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 20 additions & 14 deletions tests/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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), {
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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),
])


Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading