Skip to content

Commit

Permalink
Number datatypes (#8)
Browse files Browse the repository at this point in the history
* better numeric handling

* better numeric handling

* varchar 4000
  • Loading branch information
radbrt authored Mar 24, 2023
1 parent cec1756 commit 3160670
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions target_oracle/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ def to_sql_type(self, jsonschema_type: dict) -> sqlalchemy.types.TypeEngine: #
if datelike_type == "date":
return cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.DATE())

maxlength = jsonschema_type.get("maxLength", 2000)
maxlength = jsonschema_type.get("maxLength", 4000)
return cast(
sqlalchemy.types.TypeEngine, sqlalchemy.types.VARCHAR(maxlength)
)

if self._jsonschema_type_check(jsonschema_type, ("integer",)):
return cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.INTEGER())

if self._jsonschema_type_check(jsonschema_type, ("number",)):
return cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.NUMERIC(22, 16))
if self.config.get("prefer_float_over_numeric", False):
return cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.FLOAT())
return cast(sqlalchemy.types.TypeEngine, sqlalchemy.types.NUMERIC(38, 10))

if self._jsonschema_type_check(jsonschema_type, ("boolean",)):
return cast(sqlalchemy.types.TypeEngine, oracle.VARCHAR(1))

Expand Down
6 changes: 6 additions & 0 deletions target_oracle/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class TargetOracle(SQLTarget):
th.StringType,
description="Oracle database",
),
th.Property(
"prefer_float_over_numeric",
th.BooleanType,
description="Use float data type for numbers (otherwise number type is used)",
default=False
),
).to_dict()

default_sink_class = OracleSink
Expand Down
3 changes: 3 additions & 0 deletions target_oracle/tests/data_files/numerics.singer
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"type": "SCHEMA", "stream": "TestNumbersTable", "schema": {"type": "object", "properties": { "cid": {"type": "integer"}, "value": {"type": "number"} }}, "key_properties": ["cid"]}
{"type": "RECORD", "stream": "TestNumbersTable", "record": {"cid": 1, "value": 1001.94593928398394944838238393}}
{"type": "RECORD", "stream": "TestNumbersTable", "record": {"cid": 2, "value": 99493837283283.39483783838383394}}
5 changes: 5 additions & 0 deletions target_oracle/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def oracle_config():
"host": "localhost",
"port": "1521",
"database": "XE",
"prefer_float_over_numeric": False
}

oracle_config_dict = {
Expand Down Expand Up @@ -250,3 +251,7 @@ def test_db_schema(oracle_target):
def test_illegal_colnames(oracle_target):
file_name = "illegal_colnames.singer"
singer_file_to_target(file_name, oracle_target)

def test_numerics(oracle_target):
file_name = "numerics.singer"
singer_file_to_target(file_name, oracle_target)

0 comments on commit 3160670

Please sign in to comment.