This is an automated email from the ASF dual-hosted git repository.

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 5bfcd8a8 feat: Add ArrowSchemaSetNullability (#1029)
5bfcd8a8 is described below

commit 5bfcd8a8bd1c2751c6bb0c089e0e021fde16aab7
Author: Muhammad Umar Nadeem <[email protected]>
AuthorDate: Mon Nov 23 13:52:31 2026 -0800

    feat: Add ArrowSchemaSetNullability (#1029)
    
    Fixes #604.
    
    Add `ArrowSchemaSetNullability(schema, nullable)` so C callers can clear
    or restore `ARROW_FLAG_NULLABLE` without editing the flags directly.
    This follows the setter suggested in the issue. It preserves other flags
    and leaves child schemas alone.
    
    Added a test for toggling nullability and preserving another flag. The
    setter is static inline in `common/inline_types.h`. The C/C++ CTest
    suite passed (308 registered tests, three skipped), all 30 schema tests
    passed with `NANOARROW_NAMESPACE=InlineTest`, and pre-commit passed. A
    standalone C check also passed using only the inline header without
    linking the library.
---
 src/nanoarrow/common/inline_types.h |  8 ++++++++
 src/nanoarrow/common/schema_test.cc | 14 ++++++++++++++
 src/nanoarrow/nanoarrow.h           |  6 ++++++
 3 files changed, 28 insertions(+)

diff --git a/src/nanoarrow/common/inline_types.h 
b/src/nanoarrow/common/inline_types.h
index 35e0f9e3..a96e6fa2 100644
--- a/src/nanoarrow/common/inline_types.h
+++ b/src/nanoarrow/common/inline_types.h
@@ -343,6 +343,14 @@ static inline size_t _ArrowInt64ToSizeT(int64_t x) {
   return (size_t)x;
 }
 
+static inline void ArrowSchemaSetNullability(struct ArrowSchema* schema, char 
nullable) {
+  if (nullable) {
+    schema->flags |= ARROW_FLAG_NULLABLE;
+  } else {
+    schema->flags &= ~((int64_t)ARROW_FLAG_NULLABLE);
+  }
+}
+
 static inline void ArrowSchemaMove(struct ArrowSchema* src, struct 
ArrowSchema* dst) {
   NANOARROW_DCHECK(src != NULL);
   NANOARROW_DCHECK(dst != NULL);
diff --git a/src/nanoarrow/common/schema_test.cc 
b/src/nanoarrow/common/schema_test.cc
index 873d1ca0..05cf6571 100644
--- a/src/nanoarrow/common/schema_test.cc
+++ b/src/nanoarrow/common/schema_test.cc
@@ -562,6 +562,20 @@ TEST(SchemaTest, SchemaInitUnion) {
 #endif
 }
 
+TEST(SchemaTest, SchemaSetNullability) {
+  nanoarrow::UniqueSchema schema;
+  ASSERT_EQ(ArrowSchemaInitFromType(schema.get(), NANOARROW_TYPE_INT32), 
NANOARROW_OK);
+  schema->flags |= ARROW_FLAG_DICTIONARY_ORDERED;
+
+  ArrowSchemaSetNullability(schema.get(), 0);
+  EXPECT_EQ(schema->flags, ARROW_FLAG_DICTIONARY_ORDERED);
+  ArrowSchemaSetNullability(schema.get(), 0);
+  EXPECT_EQ(schema->flags, ARROW_FLAG_DICTIONARY_ORDERED);
+
+  ArrowSchemaSetNullability(schema.get(), 1);
+  EXPECT_EQ(schema->flags, ARROW_FLAG_DICTIONARY_ORDERED | 
ARROW_FLAG_NULLABLE);
+}
+
 TEST(SchemaTest, SchemaSetFormat) {
   struct ArrowSchema schema;
   ASSERT_EQ(ArrowSchemaInitFromType(&schema, NANOARROW_TYPE_UNINITIALIZED), 
NANOARROW_OK);
diff --git a/src/nanoarrow/nanoarrow.h b/src/nanoarrow/nanoarrow.h
index d31d67a8..d0c954a4 100644
--- a/src/nanoarrow/nanoarrow.h
+++ b/src/nanoarrow/nanoarrow.h
@@ -550,6 +550,12 @@ NANOARROW_DLL ArrowErrorCode ArrowSchemaSetFormat(struct 
ArrowSchema* schema,
 NANOARROW_DLL ArrowErrorCode ArrowSchemaSetName(struct ArrowSchema* schema,
                                                 const char* name);
 
+/// \brief Set whether a schema allows null values
+///
+/// Set ARROW_FLAG_NULLABLE when nullable is nonzero and clear it otherwise.
+/// Other flags and the nullability of children and dictionary values are 
preserved.
+static inline void ArrowSchemaSetNullability(struct ArrowSchema* schema, char 
nullable);
+
 /// \brief Copy metadata into schema->metadata
 ///
 /// schema must have been allocated using ArrowSchemaInitFromType() or

Reply via email to