Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 111af5a

Browse files
committed
Add type tests
1 parent b707743 commit 111af5a

File tree

6 files changed

+33
-7
lines changed

6 files changed

+33
-7
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
python-version: ${{ matrix.python-version }}
3535

3636
- name: Build the stack
37-
run: docker-compose up -d mysql postgres presto
37+
run: docker-compose up -d mysql postgres presto trino
3838

3939
- name: Install Poetry
4040
run: pip install poetry
@@ -46,4 +46,5 @@ jobs:
4646
env:
4747
DATADIFF_SNOWFLAKE_URI: '${{ secrets.DATADIFF_SNOWFLAKE_URI }}'
4848
DATADIFF_PRESTO_URI: '${{ secrets.DATADIFF_PRESTO_URI }}'
49+
DATADIFF_TRINO_URI: '${{ secrets.DATADIFF_TRINO_URI }}'
4950
run: poetry run unittest-parallel -j 16

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ While you may install them manually, we offer an easy way to install them along
169169

170170
- `pip install 'data-diff[oracle]'`
171171

172+
- `pip install 'data-diff[trino]'`
173+
172174
- For BigQuery, see: https://pypi.org/project/google-cloud-bigquery/
173175

174176

data_diff/databases/trino.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ def _query(self, sql_code: str) -> list:
5454
c.execute(sql_code)
5555
if sql_code.lower().startswith("select"):
5656
return c.fetchall()
57+
if re.match(r"(insert|create|truncate|drop)", sql_code, re.IGNORECASE):
58+
return c.fetchone()
5759

5860
def close(self):
5961
self._conn.close()
6062

6163
def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:
6264
if coltype.rounds:
63-
s = f"date_format(cast({coltype.precision} as timestamp(6)), '%Y-%m-%d %H:%i:%S.%f')"
65+
s = f"date_format(cast({value} as timestamp({coltype.precision})), '%Y-%m-%d %H:%i:%S.%f')"
6466
else:
6567
s = f"date_format(cast({value} as timestamp(6)), '%Y-%m-%d %H:%i:%S.%f')"
6668

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
connector.name=jmx

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ services:
7070
ports:
7171
- '8080:8080'
7272
volumes:
73-
- ./dev/trino-conf/etc:/etc/trino
73+
- ./dev/trino-conf/etc:/etc/trino:ro
7474
networks:
7575
- local
7676

tests/test_database_types.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,27 @@ def __iter__(self):
375375
"uuid": [
376376
"STRING",
377377
]
378-
}
378+
},
379+
db.Trino: {
380+
"int": [
381+
"int",
382+
"bigint",
383+
],
384+
"datetime": [
385+
"timestamp",
386+
"timestamp with time zone",
387+
],
388+
"float": [
389+
"real",
390+
"double",
391+
"decimal(10,2)",
392+
"decimal(30,6)",
393+
],
394+
"uuid": [
395+
"varchar",
396+
"char(100)",
397+
],
398+
},
379399
}
380400

381401

@@ -460,7 +480,7 @@ def _insert_to_table(conn, table, values, type):
460480

461481
if isinstance(sample, (float, Decimal, int)):
462482
value = str(sample)
463-
elif isinstance(sample, datetime) and isinstance(conn, (db.Presto, db.Oracle)):
483+
elif isinstance(sample, datetime) and isinstance(conn, (db.Presto, db.Oracle, db.Trino)):
464484
value = f"timestamp '{sample}'"
465485
elif isinstance(sample, datetime) and isinstance(conn, db.BigQuery) and type == 'datetime':
466486
value = f"cast(timestamp '{sample}' as datetime)"
@@ -492,7 +512,7 @@ def _insert_to_table(conn, table, values, type):
492512
def _create_indexes(conn, table):
493513
# It is unfortunate that Presto doesn't support creating indexes...
494514
# Technically we could create it in the backing Postgres behind the scenes.
495-
if isinstance(conn, (db.Snowflake, db.Redshift, db.Presto, db.BigQuery, db.Databricks)):
515+
if isinstance(conn, (db.Snowflake, db.Redshift, db.Presto, db.BigQuery, db.Databricks, db.Trino)):
496516
return
497517

498518
try:
@@ -583,7 +603,7 @@ def test_types(self, source_db, target_db, source_type, target_type, type_catego
583603
insertion_source_duration = time.time() - start
584604

585605
values_in_source = PaginatedTable(src_table, src_conn)
586-
if source_db is db.Presto:
606+
if source_db is db.Presto or source_db is db.Trino:
587607
if source_type.startswith("decimal"):
588608
values_in_source = ((a, Decimal(b)) for a, b in values_in_source)
589609
elif source_type.startswith("timestamp"):

0 commit comments

Comments
 (0)