Skip to content

Commit

Permalink
feat(postgres): implement array sort
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Aug 5, 2023
1 parent df14997 commit 4791cb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ibis/backends/postgres/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ def _unnest(t, op):
return sa.func.row(*derived.c)


def _array_sort(arg):
flat = sa.func.unnest(arg).column_valued()
return sa.func.array(sa.select(flat).order_by(flat).scalar_subquery())


operation_registry.update(
{
ops.Literal: _literal,
Expand Down Expand Up @@ -716,5 +721,6 @@ def _unnest(t, op):
lambda arg: sa.extract("microsecond", arg) % 1_000_000, 1
),
ops.Levenshtein: fixed_arity(sa.func.levenshtein, 2),
ops.ArraySort: fixed_arity(_array_sort, 1),
}
)
1 change: 0 additions & 1 deletion ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ def test_array_unique(backend, con):
"mssql",
"pandas",
"polars",
"postgres",
"snowflake",
],
raises=com.OperationNotDefinedError,
Expand Down

0 comments on commit 4791cb4

Please sign in to comment.