Skip to content

Commit 88af60e

Browse files
authored
Fix: Expand default decimal size to (38, 9), resolve issues with large number values (#194)
1 parent 97119c9 commit 88af60e

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

airbyte/_processors/sql/duckdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ def _write_files_to_new_table(
9494
"\n, ".join(
9595
[
9696
self._quote_identifier(self.normalizer.normalize(prop_name))
97-
+ ": "
97+
+ ': "'
9898
+ str(
9999
self._get_sql_column_definitions(stream_name)[
100100
self.normalizer.normalize(prop_name)
101101
]
102102
)
103+
+ '"'
103104
for prop_name in columns_list
104105
]
105106
),

airbyte/types.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
CONVERSION_MAP = {
1414
"string": sqlalchemy.types.VARCHAR,
1515
"integer": sqlalchemy.types.BIGINT,
16-
"number": sqlalchemy.types.DECIMAL,
16+
"number": sqlalchemy.types.DECIMAL(38, 9),
1717
"boolean": sqlalchemy.types.BOOLEAN,
1818
"date": sqlalchemy.types.DATE,
1919
"timestamp_with_timezone": sqlalchemy.types.TIMESTAMP,
@@ -116,11 +116,18 @@ def to_sql_type(
116116
"""Convert a value to a SQL type."""
117117
try:
118118
airbyte_type, _ = _get_airbyte_type(json_schema_property_def)
119-
return self.conversion_map[airbyte_type]()
119+
sql_type = self.conversion_map[airbyte_type]
120120
except SQLTypeConversionError:
121121
print(f"Could not determine airbyte type from JSON schema: {json_schema_property_def}")
122122
except KeyError:
123123
print(f"Could not find SQL type for airbyte type: {airbyte_type}")
124+
else:
125+
# No exceptions were raised, so we can return the SQL type.
126+
if isinstance(sql_type, type):
127+
# This is a class. Call its constructor.
128+
sql_type = sql_type()
129+
130+
return sql_type
124131

125132
json_schema_type = json_schema_property_def.get("type", None)
126133
json_schema_format = json_schema_property_def.get("format", None)

tests/integration_tests/fixtures/source-test/source_test/run.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"Column1": {"type": "string"},
3434
"Column2": {"type": "number"},
3535
"empty_column": {"type": "string"},
36+
"big_number": {"type": "number"},
3637
},
3738
},
3839
},
@@ -102,7 +103,12 @@
102103
sample_record_stream2 = {
103104
"type": "RECORD",
104105
"record": {
105-
"data": {"Column1": "value1", "Column2": 1},
106+
"data": {
107+
"Column1": "value1",
108+
"Column2": 1,
109+
"empty_column": None,
110+
"big_number": 1234567890123456,
111+
},
106112
"stream": "stream2",
107113
"emitted_at": 1704067200,
108114
},

tests/integration_tests/test_source_test_fixture.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ def expected_test_stream_data() -> dict[str, list[dict[str, str | int]]]:
113113
{"column1": "value2", "column2": 2},
114114
],
115115
"stream2": [
116-
{"column1": "value1", "column2": 1, "empty_column": None},
116+
{
117+
"column1": "value1",
118+
"column2": 1,
119+
"empty_column": None,
120+
"big_number": 1234567890123456
121+
},
117122
],
118123
"always-empty-stream": [],
119124
}

0 commit comments

Comments
 (0)