You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2025/04/14 12:55:45 UTC

(ignite-3) branch ignite-25125 created (now a09f50db2cf)

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

amashenkov pushed a change to branch ignite-25125
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


      at a09f50db2cf Allow null values in agruments.

This branch includes the following new commits:

     new a09f50db2cf Allow null values in agruments.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(ignite-3) 01/01: Allow null values in agruments.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-25125
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit a09f50db2cf6b8c44be02c71e23ca57eab2dd6d6
Author: amashenkov <am...@apache.org>
AuthorDate: Mon Apr 14 15:55:27 2025 +0300

    Allow null values in agruments.
---
 .../org/apache/ignite/sql/BatchedArguments.java    |  7 ++--
 .../apache/ignite/sql/BatchedArgumentsTest.java    | 37 +++++++++++++++++++---
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/modules/api/src/main/java/org/apache/ignite/sql/BatchedArguments.java b/modules/api/src/main/java/org/apache/ignite/sql/BatchedArguments.java
index 9c34593e3c7..96daec1519f 100644
--- a/modules/api/src/main/java/org/apache/ignite/sql/BatchedArguments.java
+++ b/modules/api/src/main/java/org/apache/ignite/sql/BatchedArguments.java
@@ -18,6 +18,8 @@
 package org.apache.ignite.sql;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
@@ -74,7 +76,7 @@ public final class BatchedArguments implements Iterable<List<Object>> {
     public BatchedArguments add(Object... args) {
         Objects.requireNonNull(args, "args");
 
-        return addArguments(List.of(args));
+        return addArguments(Arrays.asList(args));
     }
 
     /**
@@ -140,7 +142,8 @@ public final class BatchedArguments implements Iterable<List<Object>> {
                 ensureRowLength(requiredLength, arguments.size());
             }
 
-            resultList.add(List.copyOf(arguments));
+            //noinspection Java9CollectionFactory
+            resultList.add(Collections.unmodifiableList(new ArrayList<>(arguments)));
 
             ++pos;
         }
diff --git a/modules/api/src/test/java/org/apache/ignite/sql/BatchedArgumentsTest.java b/modules/api/src/test/java/org/apache/ignite/sql/BatchedArgumentsTest.java
index b9ae453d0a0..9b7501afdb1 100644
--- a/modules/api/src/test/java/org/apache/ignite/sql/BatchedArgumentsTest.java
+++ b/modules/api/src/test/java/org/apache/ignite/sql/BatchedArgumentsTest.java
@@ -34,10 +34,11 @@ import org.junit.jupiter.api.function.Executable;
  * Tests for {@link BatchedArguments}.
  */
 public class BatchedArgumentsTest {
+    @SuppressWarnings("DataFlowIssue")
     @Test
     public void nullAndEmptyArgumentsAreForbidden() {
         assertThrows(NullPointerException.class, "args", () -> BatchedArguments.of((Object[]) null));
-        assertThrows(NullPointerException.class, "batchedArgs", () -> BatchedArguments.from((List<List<Object>>) null));
+        assertThrows(NullPointerException.class, "batchedArgs", () -> BatchedArguments.from(null));
         assertThrows(NullPointerException.class, "Arguments list cannot be null.", () -> BatchedArguments.from(singletonList(null)));
         assertThrows(IllegalArgumentException.class, "Non empty arguments required.", () -> BatchedArguments.of(new Object[0]));
 
@@ -46,6 +47,27 @@ public class BatchedArgumentsTest {
         assertThrows(IllegalArgumentException.class, "Non empty arguments required.", () -> batch.add(new Object[0]));
     }
 
+    @Test
+    public void nullArgumentValuesAreAllowed() {
+        BatchedArguments batch = BatchedArguments.from(singletonList(singletonList(null)));
+        assertThat(batch.size(), is(1));
+        assertThat(batch.get(0), equalTo(singletonList(null)));
+
+        batch.add((Object) null);
+        assertThat(batch.size(), is(2));
+        assertThat(batch.get(0), equalTo(singletonList(null)));
+        assertThat(batch.get(1), equalTo(singletonList(null)));
+
+        batch =  BatchedArguments.of((Object) null);
+        assertThat(batch.size(), is(1));
+        assertThat(batch.get(0), equalTo(singletonList(null)));
+
+        batch.add((Object) null);
+        assertThat(batch.size(), is(2));
+        assertThat(batch.get(0), equalTo(singletonList(null)));
+        assertThat(batch.get(1), equalTo(singletonList(null)));
+    }
+
     @Test
     public void iteratorIsImmutable() {
         List<List<Object>> argLists = new ArrayList<>(2);
@@ -83,13 +105,13 @@ public class BatchedArgumentsTest {
     @Test
     public void argumentsListsAreImmutable() {
         List<List<Object>> argLists = new ArrayList<>(2);
-        argLists.add(List.of(1));
-        argLists.add(List.of(2));
+        argLists.add(mutableListOf(1));
+        argLists.add(mutableListOf(2));
 
         BatchedArguments batch = BatchedArguments.from(argLists);
         assertThat(batch.size(), is(argLists.size()));
 
-        argLists.add(List.of(3));
+        argLists.add(mutableListOf(3));
         assertThat(batch.size(), is(argLists.size() - 1));
 
         argLists.clear();
@@ -99,6 +121,13 @@ public class BatchedArgumentsTest {
         Assertions.assertThrows(UnsupportedOperationException.class, () -> batch.get(0).remove(0));
     }
 
+    /** Creates mutable list of given argument. */
+    private static List<Object> mutableListOf(Object e1) {
+        ArrayList<Object> args = new ArrayList<>(1);
+        args.add(e1);
+        return args;
+    }
+
     private static <T extends Throwable> void assertThrows(Class<T> expectedType, String expMsg, Executable executable) {
         T ex = Assertions.assertThrows(expectedType, executable);