From 489654ca5848b34be780a3535ecd0063075f8c97 Mon Sep 17 00:00:00 2001 From: Neha Nene Date: Thu, 8 Sep 2022 17:40:45 -0500 Subject: [PATCH] feat: Oracle row level validation support (#583) * fix: support NUMBER with no precision/scale * feat: oracle support for sanitization functions * adding hash support * upgrades and hash funcion for oracle12+ --- third_party/ibis/ibis_addon/operations.py | 7 +++++++ third_party/ibis/ibis_oracle/alchemy.py | 2 +- third_party/ibis/ibis_oracle/compiler.py | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/third_party/ibis/ibis_addon/operations.py b/third_party/ibis/ibis_addon/operations.py index e8eadd2ba..11101d79b 100644 --- a/third_party/ibis/ibis_addon/operations.py +++ b/third_party/ibis/ibis_addon/operations.py @@ -175,6 +175,12 @@ def sa_format_hashbytes(translator, expr): hash_to_string = sa.func.convert(sa.sql.literal_column('CHAR(64)'), hash_func, sa.sql.literal_column('2')) return sa.func.lower(hash_to_string) +def sa_format_hashbytes_oracle(translator, expr): + arg, how = expr.op().args + compiled_arg = translator.translate(arg) + hash_func = sa.func.standard_hash(compiled_arg, sa.sql.literal_column("'SHA256'")) + return sa.func.lower(hash_func) + _pandas_client._inferable_pandas_dtypes["floating"] = _pandas_client.dt.float64 IntegerColumn.bit_xor = ibis.expr.api._agg_function("bit_xor", BitXor, True) @@ -194,5 +200,6 @@ def sa_format_hashbytes(translator, expr): ImpalaExprTranslator._registry[RawSQL] = format_raw_sql ImpalaExprTranslator._registry[HashBytes] = format_hashbytes_hive OracleExprTranslator._registry[RawSQL] = sa_format_raw_sql +OracleExprTranslator._registry[HashBytes] = sa_format_hashbytes_oracle TeradataExprTranslator._registry[RawSQL] = format_raw_sql TeradataExprTranslator._registry[HashBytes] = format_hashbytes_teradata diff --git a/third_party/ibis/ibis_oracle/alchemy.py b/third_party/ibis/ibis_oracle/alchemy.py index 480d65c52..89d206e7d 100644 --- a/third_party/ibis/ibis_oracle/alchemy.py +++ b/third_party/ibis/ibis_oracle/alchemy.py @@ -28,7 +28,7 @@ dt11.LONGRAW: sa.Binary, } _ibis_type_to_sqla.update(s_al._ibis_type_to_sqla) - +_ibis_type_to_sqla[dt.String] = sa.sql.sqltypes.String(length=4000) def _to_sqla_type(itype, type_map=None): if type_map is None: diff --git a/third_party/ibis/ibis_oracle/compiler.py b/third_party/ibis/ibis_oracle/compiler.py index dd62d64dd..944e48d02 100644 --- a/third_party/ibis/ibis_oracle/compiler.py +++ b/third_party/ibis/ibis_oracle/compiler.py @@ -439,7 +439,8 @@ def _mod(t, expr): def _string_join(t, expr): sep, elements = expr.op().args - return sa.func.concat_ws(t.translate(sep), *map(t.translate, elements)) + columns = [col.name for col in map(t.translate, elements)] + return sa.sql.literal_column(" || ".join(columns)) def _literal(t, expr):