Skip to content

Commit

Permalink
fix(snowflake): make array_agg preserve nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Feb 1, 2023
1 parent 5943ce7 commit 24b95bf
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ibis/backends/snowflake/registry.py
Expand Up @@ -4,8 +4,13 @@

import numpy as np
import sqlalchemy as sa
from snowflake.sqlalchemy import ARRAY
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import sqltypes
from sqlalchemy.sql.functions import GenericFunction

import ibis.expr.operations as ops
from ibis import util
from ibis.backends.base.sql.alchemy.registry import (
fixed_arity,
geospatial_functions,
Expand Down Expand Up @@ -251,7 +256,11 @@ def _unnest(t, op):
*map(t.translate, op.cols)
),
ops.ArraySlice: _array_slice,
ops.ArrayCollect: reduction(sa.func.array_agg),
ops.ArrayCollect: reduction(
lambda arg: sa.func.array_agg(
sa.func.ifnull(arg, sa.func.parse_json("null")), type_=ARRAY
)
),
ops.StringSplit: fixed_arity(sa.func.split, 2),
ops.TypeOf: unary(lambda arg: sa.func.typeof(sa.func.to_variant(arg))),
ops.All: reduction(sa.func.booland_agg),
Expand Down Expand Up @@ -284,13 +293,7 @@ def _unnest(t, op):
ops.StructColumn: lambda t, op: sa.func.object_construct_keep_null(
*itertools.chain.from_iterable(zip(op.names, map(t.translate, op.values)))
),
ops.Unnest: unary(
lambda arg: (
sa.func.table(sa.func.flatten(arg))
.table_valued("value")
.columns["value"]
)
),
ops.Unnest: _unnest,
}
)

Expand Down

0 comments on commit 24b95bf

Please sign in to comment.