From 291323c22ccba4921c4f1a08d97e4813ba3136ac Mon Sep 17 00:00:00 2001 From: Kaitmazian Maksim <m.kaitmazian@picodata.io> Date: Thu, 14 Nov 2024 10:43:50 +0300 Subject: [PATCH] feat(sql): support COALESCE --- CHANGELOG.md | 1 + Cargo.lock | 10 ---------- sbroad | 2 +- test/conftest.py | 2 +- test/int/test_sql.py | 17 +++++++++++++++++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 090de2e5e3..afba101e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,6 +120,7 @@ with the `YY.MINOR.MICRO` scheme. support WAIT APPLIED (GLOBALLY | LOCALLY) options, allowing users to wait for operations to be committed across all replicasets or only on the current one - EXPLAIN estimates query buckets +- SQL supports `COALESCE` function ### Fixes diff --git a/Cargo.lock b/Cargo.lock index 538ba46cf2..43d8cc98fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3457,7 +3457,6 @@ dependencies = [ "hash32", "itertools", "lazy_static", - "opentelemetry", "pest", "pest_derive", "pretty_assertions 1.4.1", @@ -3465,7 +3464,6 @@ dependencies = [ "rmp", "rmp-serde", "rmpv", - "sbroad-proc", "serde", "serde_bytes", "serde_yaml", @@ -3475,14 +3473,6 @@ dependencies = [ "uuid 1.11.0", ] -[[package]] -name = "sbroad-proc" -version = "0.1.0" -dependencies = [ - "quote 1.0.37", - "syn 1.0.109", -] - [[package]] name = "schannel" version = "0.1.26" diff --git a/sbroad b/sbroad index 73e6815a33..aaa0da6bc4 160000 --- a/sbroad +++ b/sbroad @@ -1 +1 @@ -Subproject commit 73e6815a3399c085fcaff3bca7df86463b284bde +Subproject commit aaa0da6bc442f42adce3780c47e1d7f98fb53f11 diff --git a/test/conftest.py b/test/conftest.py index 2b4a42707a..9cd3d5500a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -2131,7 +2131,7 @@ def cargo_build(with_webui: bool = False) -> None: eprint("Skipping cargo build") return - features = ["error_injection", "sbroad-core/tracing"] + features = ["error_injection"] if with_webui: features.append("webui") diff --git a/test/int/test_sql.py b/test/int/test_sql.py index cf5965b33f..9db03d749e 100644 --- a/test/int/test_sql.py +++ b/test/int/test_sql.py @@ -1380,6 +1380,23 @@ def test_substr(instance: Instance): assert data[0] == [""] +def test_coalesce(instance: Instance): + instance.sql("create table foo (id int primary key, bar unsigned null);") + instance.sql("insert into foo values (1, null), (2, 1);") + + # Coalesce returns first non null value from its arguments. + data = instance.sql("select coalesce(bar, 0) from foo;") + assert data == [[0], [1]] + + # Type mismatch: all values must have the same type. + with pytest.raises(TarantoolError, match=" expected unsigned type, but got string"): + instance.sql("select coalesce(bar, 'none') from foo;") + + # 0 / 0 is not evaluated. + data = instance.sql("select coalesce(bar, 0, 0 / 0) from foo;") + assert data == [[0], [1]] + + def test_lower_upper(instance: Instance): instance.sql( """ -- GitLab