Skip to content

Commit

Permalink
Add support for more value types in TrinoBatchInsert (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTiemannOSC authored Mar 30, 2022
1 parent 5845260 commit 0dd10ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions osc_ingest_trino/sqltypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"int64": "bigint",
"Int64": "bigint",
"bool": "boolean",
"boolean": "boolean",
"category": "varchar",
"datetime64[ns, UTC]": "timestamp",
}
Expand Down
13 changes: 13 additions & 0 deletions osc_ingest_trino/trino_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import math
import os
from datetime import datetime

import trino
from sqlalchemy.engine import create_engine
Expand Down Expand Up @@ -90,11 +92,22 @@ def _full_table_name(self, sqltbl):

@staticmethod
def _sqlform(x):
if x is None:
return "NULL"
if isinstance(x, str):
# escape any single quotes in the string
t = x.replace("'", "''")
# enclose string with single quotes
return f"'{t}'"
if isinstance(x, datetime):
return f"TIMESTAMP '{x}'"
if isinstance(x, float):
if math.isnan(x):
return "nan()"
if math.isinf(x):
if x < 0:
return "-infinity()"
return "infinity()"
return str(x)

@staticmethod
Expand Down

0 comments on commit 0dd10ee

Please sign in to comment.