Skip to content

Commit

Permalink
feat(postgres): implement array union
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Aug 5, 2023
1 parent 8d42794 commit 6d3d518
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions ibis/backends/postgres/registry.py
Expand Up @@ -382,7 +382,7 @@ def translate(t, op):
return translate


def _literal(t, op):
def _literal(_, op):
dtype = op.output_dtype
value = op.value

Expand Down Expand Up @@ -784,12 +784,24 @@ def _array_filter(t, op):
),
2,
),
ops.ArrayDistinct: fixed_arity(
lambda arg: sa.func.array(
sa.select(
sa.distinct(sa.func.unnest(arg).column_valued())
ops.ArrayUnion: fixed_arity(
lambda left, right: sa.func.array(
sa.union(
sa.select(sa.func.unnest(left).column_valued()),
sa.select(sa.func.unnest(right).column_valued()),
).scalar_subquery()
),
2,
),
ops.ArrayDistinct: fixed_arity(
lambda arg: sa.case(
(arg.is_(sa.null()), sa.null()),
else_=sa.func.array(
sa.select(
sa.distinct(sa.func.unnest(arg).column_valued())
).scalar_subquery()
),
),
1,
),
ops.ArrayPosition: fixed_arity(_array_position, 2),
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_array.py
Expand Up @@ -648,7 +648,7 @@ def test_array_sort(backend, con):


@pytest.mark.notimpl(
["dask", "datafusion", "impala", "mssql", "pandas", "polars", "postgres"],
["dask", "datafusion", "impala", "mssql", "pandas", "polars"],
raises=com.OperationNotDefinedError,
)
@pytest.mark.notyet(
Expand Down

0 comments on commit 6d3d518

Please sign in to comment.