From 4791cb4fe898a0165a6fa4597cceb2039b6a9037 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Fri, 4 Aug 2023 07:23:36 -0400 Subject: [PATCH] feat(postgres): implement array sort --- ibis/backends/postgres/registry.py | 6 ++++++ ibis/backends/tests/test_array.py | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ibis/backends/postgres/registry.py b/ibis/backends/postgres/registry.py index 92a396c8576d..fd8f542459ce 100644 --- a/ibis/backends/postgres/registry.py +++ b/ibis/backends/postgres/registry.py @@ -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, @@ -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), } ) diff --git a/ibis/backends/tests/test_array.py b/ibis/backends/tests/test_array.py index e882db2b07da..06c6b24487d1 100644 --- a/ibis/backends/tests/test_array.py +++ b/ibis/backends/tests/test_array.py @@ -656,7 +656,6 @@ def test_array_unique(backend, con): "mssql", "pandas", "polars", - "postgres", "snowflake", ], raises=com.OperationNotDefinedError,