diff --git a/ibis_substrait/compiler/mapping.py b/ibis_substrait/compiler/mapping.py index af78e7ee..23d60079 100644 --- a/ibis_substrait/compiler/mapping.py +++ b/ibis_substrait/compiler/mapping.py @@ -32,6 +32,7 @@ "Less": "lt", "LessEqual": "lte", "Ln": "ln", + "Log": "logb", "Log2": "log2", "Log10": "log10", "Lowercase": "lower", diff --git a/ibis_substrait/compiler/translate.py b/ibis_substrait/compiler/translate.py index a25c9d21..dd0d1c4a 100644 --- a/ibis_substrait/compiler/translate.py +++ b/ibis_substrait/compiler/translate.py @@ -11,10 +11,12 @@ import decimal import functools import itertools +import math import operator import uuid from typing import Any, Mapping, MutableMapping, Sequence, TypeVar +import ibis import ibis.expr.datatypes as dt import ibis.expr.operations as ops import ibis.expr.schema as sch @@ -1054,3 +1056,25 @@ def _extractdatefield( scalar_func.arguments.add(enum=stalg.FunctionArgument.Enum(specified=span)) scalar_func.arguments.extend(arguments) return stalg.Expression(scalar_function=scalar_func) + + +@translate.register(ops.Log) +def _log( + op: ops.Log, + expr: ir.TableExpr, + compiler: SubstraitCompiler, + **kwargs: Any, +) -> stalg.Expression: + arg = stalg.FunctionArgument(value=translate(op.arg, compiler, **kwargs)) + base = stalg.FunctionArgument( + value=translate( + op.base if op.base is not None else ibis.literal(math.e), compiler, **kwargs + ) + ) + + scalar_func = stalg.Expression.ScalarFunction( + function_reference=compiler.function_id(expr), + output_type=translate(expr.type()), + arguments=[arg, base], + ) + return stalg.Expression(scalar_function=scalar_func)