From f9db68f2edcc2980085945a6a65151b9428b4f48 Mon Sep 17 00:00:00 2001 From: Neha Nene Date: Wed, 26 Jul 2023 16:40:50 -0400 Subject: [PATCH] fix: teradata NUMBER with no precision/scale, small doc fix after Ibis upgrade (#914) Added issue #915 - which will address the testing request Urgent customer request. Sundar Mudupalli --- README.md | 4 ++-- third_party/ibis/ibis_teradata/datatypes.py | 23 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9af00aa5f..752bff8c3 100644 --- a/README.md +++ b/README.md @@ -657,12 +657,12 @@ required, if any, with the 'params' block as shown below: target_calculated_columns: - start_time type: custom - ibis_expr: ibis.expr.api.TimestampValue.strftime + ibis_expr: ibis.expr.types.TemporalValue.strftime params: - format_str: '%m%d%Y' ``` -The above block references the [TimestampValue.strftime](https://ibis-project.org/reference/expressions/timestamps/#ibis.expr.types.temporal.TemporalValue.strftime) Ibis API expression. +The above block references the [TemporalValue.strftime](https://ibis-project.org/reference/expressions/timestamps/#ibis.expr.types.temporal.TemporalValue.strftime) Ibis API expression. See the [Examples page](https://github.com/GoogleCloudPlatform/professional-services-data-validator/blob/develop/docs/examples.md#sample-row-validation-yaml-with-custom-calc-field) for a sample YAML with a custom calculated field. diff --git a/third_party/ibis/ibis_teradata/datatypes.py b/third_party/ibis/ibis_teradata/datatypes.py index cbb3732f0..0712148d0 100644 --- a/third_party/ibis/ibis_teradata/datatypes.py +++ b/third_party/ibis/ibis_teradata/datatypes.py @@ -76,16 +76,33 @@ def to_ibis_from_CV(cls, col_data, return_ibis_type=True): @classmethod def to_ibis_from_N(cls, col_data, return_ibis_type=True): - return cls.to_ibis_from_D(col_data, return_ibis_type=return_ibis_type) + precision = int( + col_data.get("DecimalTotalDigits", col_data.get("Decimal Total Digits", 38)) + ) + scale = int( + col_data.get( + "DecimalFractionalDigits", col_data.get("Decimal Fractional Digits", 38) + ) + ) + if return_ibis_type: + # No precision or scale specified + if precision == -128 or scale ==-128: + return dt.Decimal() + return dt.Decimal(precision, scale) + + if precision == -128 or scale ==-128: + return "DECIMAL" + + return "DECIMAL(%d, %d)" % (precision, scale) @classmethod def to_ibis_from_D(cls, col_data, return_ibis_type=True): precision = int( - col_data.get("DecimalTotalDigits", col_data.get("Decimal Total Digits", 20)) + col_data.get("DecimalTotalDigits", col_data.get("Decimal Total Digits", 5)) ) scale = int( col_data.get( - "DecimalFractionalDigits", col_data.get("Decimal Fractional Digits", 4) + "DecimalFractionalDigits", col_data.get("Decimal Fractional Digits", 0) ) ) if return_ibis_type: