Skip to content

Commit

Permalink
feat(flink): implement translation of ZEROIFNULL
Browse files Browse the repository at this point in the history
  • Loading branch information
deepyaman authored and cpcloud committed Sep 21, 2023
1 parent 19514bc commit 31560eb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ibis/backends/flink/registry.py
Expand Up @@ -67,6 +67,11 @@ def _literal(translator: ExprTranslator, op: ops.Literal) -> str:
return translate_literal(op)


def _zeroifnull(translator: ExprTranslator, op: ops.Literal) -> str:
casted = translate_literal(ops.Literal("0", dtype=op.dtype))
return f"COALESCE({translator.translate(op.arg)}, {casted})"


def _nullifzero(translator: ExprTranslator, op: ops.Literal) -> str:
casted = translate_literal(ops.Literal("0", dtype=op.dtype))
return f"NULLIF({translator.translate(op.arg)}, {casted})"
Expand Down Expand Up @@ -206,6 +211,7 @@ def _floor_divide(translator: ExprTranslator, op: ops.Node) -> str:
{
# Unary operations
ops.IfNull: fixed_arity("ifnull", 2),
ops.ZeroIfNull: _zeroifnull,
ops.NullIfZero: _nullifzero,
ops.RandomScalar: lambda *_: "rand()",
ops.Degrees: unary("degrees"),
Expand Down

0 comments on commit 31560eb

Please sign in to comment.