<#1890 feat: Support Singer Decimal as a config it...
# meltano-repo-activity
g
#1890 feat: Support Singer Decimal as a config item Issue created by s7clarke10 ### Feature scope Taps (catalog, state, stream maps, tests, etc.) ### Description There have been discussions before about whether it is a best practice to emit Decimal, Integer, and Float datatypes as a string or in their native formats. I have mentioned this in passing in this JSON dicussion #1046 . The author of msgspec strongly recommends sending numeric data as a string. There was an informal standard called Singer Decimal where the tap would emit the Numeric data as a string (and if possible) try and turn it back into a numeric format in the target. You may ask, why would you do this? The key reasons are : 1. Rounding issues with float datatypes 2. Inability to handle large numbers or decimal places 3. Python not handling the numeric data well 4. The tap does not have enough information in the database schema to hint the correct format. For example in Oracle it is a common practice to specify a datatype of number without supplying a precision or scale. The only accurate way to determine the correct precision and scale in the target is to sample the data. In this situation the only reasonable way to send this data is as a string, and then use a transform tool to cast the data. For a number of database related taps we have implement a setting called
use_singer_decimal
. When this is set to true, it will send the data as a string but provides additional information about the scale and precision (if available) in the singer messages. When the target receives the message, if it has this additional singer decimal data, it can cast the data with the correct datatype. The good thing about this approach is that it is a setting, therefore based on your use case, you can emit numeric data in its native numeric format (default setting), or preferable enable the
use_singer_decimal
setting to gain more accurate numeric data. We have found by using this methodology, there is no loss of precision. It would be great to introduce this ability into the SDK as it will ensure accurate numeric data being sent. Examples of enhanced database taps which support this are: • pipelinewise-tap-oracle • pipelinewise-tap-mssql • tap-sybase • tap-db2 Example enhanced target with support for decoding singer-decimal data: • pipelinewise-target-snowflake More detail for tap-db2 written by @mjsqu . DECIMALs from DB2 are given format property "singer.decimal" in the schema, with type property "number". The numeric scale & precision are stored as
schema[additionalProperties][scale_precision]
, e.g.
"additionalProperties":{"scale_precision":"(15,9)"}
. When the tap writes the RECORD message, "singer.decimal" informs the data value to be output into the message as a string The snowflake target obtains the scale/precision from the schema message to create a column of type NUMBER(scale, precision). meltano/sdk