17.10 - Publishing NUMBER or DECIMAL Types to an Avro Value - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - DATASET Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1198-171K
Language
English (United States)

When publishing NUMBER or DECIMAL types from a table to an Avro value, the schema is written out as a string instead of a double type. Because NUMBER and DECIMAL use a higher precision, using a double or other relevant primitive type can result in a loss of precision. Using a string prevents this loss of information.

The schema looks like the following when using NUMBER or DECIMAL types:
CREATE TABLE avrotest(a INTEGER, b DECIMAL(38,9), c NUMBER(38,9));
INSERT INTO avrotest(1, 12345678901234567890123456789.012345679, 12345678901234567890123456789.012345679);
SELECT data.tojson(), data.getschema() FROM DATASET_PUBLISH
(
    ON (SELECT * FROM avrotest)
) as L;
*** Query completed. One row found. 2 columns returned.
 *** Total elapsed time was 1 second.

   data.TOJSON() [{"a":{"int":1},"b":
{"string":"12345678901234567890123456789.012345679"},"c":
{"string":"12345678901234567890123456789.012345679"}}]
data.GETSCHEMA() {"type":"array","items":{"type":"record","name":"rec_0","fields":
[{"name":"a","type":["null","int"]},{"name":"b","type":["null","string"]},
{"name":"c","type":["null","string"]}]}}