Skip to content

[SQL] Add a runtime warning about map key deprecation - #8250

Merged
mihaibudiu merged 1 commit into
mainfrom
null-map-key-deprecation
Dec 5, 2026
Merged

mihaibudiu merged 1 commit into
mainfrom
null-map-key-deprecation

Conversation

@mihaibudiu

Copy link
Copy Markdown
Contributor

Linked Issue

This is a temporary alternative until we can merge #8191
The documentation warns that NULL keys in maps will no longer be supported.
The runtime will log an error the first time a map with a NULL key is constructed.
Note that the type system already prevents such MAP values in tables.

Comment thread crates/sqllib/src/map.rs
if key.is_none() {
static LOGGED: Once = Once::new();
LOGGED.call_once(|| {
tracing::error!(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pitfall (medium): This error fires once per process, and it doesn't say which view or SQL expression produced the NULL key, or how to fix it. In a pipeline with many MAP[...] / MAP(SELECT ...) sites, users can't find the offending query. Two possible fixes: have the compiler pass the source position (or the view name) as a &'static str argument and include it in the message, and add the fix hint that's already in the changelog, e.g. "wrap the key in COALESCE(k, ...) or filter with WHERE k IS NOT NULL".

@mythical-fred-oss

Copy link
Copy Markdown
Contributor

What I ran

Check Result
cargo test -p feldera-sqllib null_map_key ✅ passes
mvn test -Dtest=MapTests (existing tests) ✅ 13/13 pass
New end-to-end tests below (MAP[k,x] and MAP(SELECT k,x ...) with a NULL k) ✅ pass; the generated check_map_keyN calls compile on both paths and keep the NULL key

Missing (medium), gate "tests for changed behaviour": the compiler now emits check_map_keyN in two places (the MAP_VALUE_CONSTRUCTOR branch and visitCollect), but no SQL compiler test covers either path with a nullable key. Only the sqllib helper is unit-tested, so a type mismatch in the generated Rust would not be caught. Suggested tests, both of which pass locally. They use UNNEST + IS NULL because the expected-output parser reads { NULL: 2 } as the string key "NULL":

--- a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/MapTests.java
+++ b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/MapTests.java
+    @Test
+    public void nullableMapKeyLiteral() {
+        // NULL map keys are deprecated, but still accepted
+        var ccs = this.getCCS("""
+               CREATE TABLE T(k varchar, x int);
+               CREATE VIEW V AS SELECT p.k IS NULL AS n, p.v
+               FROM T CROSS JOIN UNNEST(MAP[T.k, T.x]) AS p(k, v);""");
+        ccs.stepWeightOne("INSERT INTO T VALUES('a', 1), (NULL, 2)", """
+         n | v
+        -------
+         f | 1
+         t | 2""");
+    }
+
+    @Test
+    public void nullableMapKeySubquery() {
+        var ccs = this.getCCS("""
+               CREATE TABLE T(k varchar, x int);
+               CREATE VIEW V AS SELECT p.k IS NULL AS n, p.v
+               FROM UNNEST(MAP(SELECT k, x FROM T)) AS p(k, v);""");
+        ccs.stepWeightOne("INSERT INTO T VALUES('a', 1), (NULL, 2)", """
+         n | v
+        -------
+         f | 1
+         t | 2""");
+    }

Commit message (low, non-blocking): the subject is cut off with …, and the body only finishes that sentence. A short "why" would help: this is a stopgap until #8191 lands.

Otherwise, the docs and changelog cover the deprecation, and the PR adds no unsafe code and no new dependencies.

@mihaibudiu
mihaibudiu added this pull request to the merge queue Dec 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Dec 5, 2026
… deprecated

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu
mihaibudiu force-pushed the null-map-key-deprecation branch from 444bafb to 1d40b06 Compare December 5, 2026 17:21
@mihaibudiu
mihaibudiu added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit 2d16307 Dec 5, 2026
1 check passed
@mihaibudiu
mihaibudiu deleted the null-map-key-deprecation branch December 5, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants