← 输入框|github.com|刷新
Skip to content

[sqllib] Return an error instead of panicking when a nullable cast helper gets NULL. - #7825

Merged
mihaibudiu merged 1 commit into
mainfrom
issue7802
Nov 4, 2026
Merged

mihaibudiu merged 1 commit into
mainfrom
issue7802

Conversation

@mihaibudiu

Copy link
Copy Markdown
Contributor

Fixes #7802

@gz
gz enabled auto-merge November 3, 2026 23:56
Comment thread crates/sqllib/src/casts.rs Resolved
@mythical-fred-oss

Copy link
Copy Markdown
Contributor

What I ran

Check Result
cargo test --locked -p feldera-sqllib --lib with the QA test below ✅ pass
pre-commit run --files <changed files> ✅ pass

missing (medium): no tests (Hard Rule 2: unit tests for changed behaviour). The PR changes four helpers (cast_to_s_VN, cast_to_s_FVN, cast_to_bytes_sN, cast_to_bytes_UuidN) from panicking to returning an error, but it adds no tests for them. Nothing covers the None → Err path or checks that the Some path still matches the non-null helper. Here is a test I wrote and ran locally. It passes:

@@ mod saturating_test (end of crates/sqllib/src/casts.rs)
+    #[allow(deprecated)]
+    #[test]
+    fn nullable_cast_helpers_return_error_on_null() {
+        use crate::{
+            ByteArray, SqlString, Uuid, Variant, cast_to_bytes_UuidN, cast_to_bytes_sN,
+            cast_to_s_FVN, cast_to_s_VN,
+        };
+        assert!(cast_to_s_VN(None, -1, false).is_err());
+        assert!(cast_to_bytes_sN(None, -1, false).is_err());
+        assert!(cast_to_bytes_UuidN(None, -1, false).is_err());
+        assert!(cast_to_s_FVN(None, -1, false).is_err());
+        let uuid = Uuid::from_bytes([7; 16]);
+        assert_eq!(cast_to_bytes_UuidN(Some(uuid), -1, false).unwrap(), ByteArray::new(&[7; 16]));
+        assert_eq!(
+            cast_to_s_VN(Some(Variant::String(SqlString::from_ref("ab"))), -1, false).unwrap(),
+            SqlString::from_ref("ab")
+        );
+        assert_eq!(
+            cast_to_bytes_sN(Some(SqlString::from_ref("ab")), -1, false).unwrap(),
+            ByteArray::new(b"ab")
+        );
+    }

Apart from the missing tests and the remaining panic in cast_to_s_V (see the inline comment), the fix looks correct.

…lper gets NULL.

Fixes #7802

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu
mihaibudiu disabled auto-merge November 4, 2026 18:09
@mihaibudiu
mihaibudiu added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit 0d5e7f4 Nov 4, 2026
1 check passed
@mihaibudiu
mihaibudiu deleted the issue7802 branch November 4, 2026 23:15
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.

Nullable UUID-to-BINARY cast helper panics on NULL instead of returning an error

2 participants