You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/08/10 19:26:35 UTC

[GitHub] [ignite] timoninmaxim opened a new pull request #9315: Add precision test

timoninmaxim opened a new pull request #9315:
URL: https://github.com/apache/ignite/pull/9315


   Allows use QuerySqlField.precision for String, byte[] fields.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688307317



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {
+            validStr.append("0");
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, validStr.toString()));
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "BIN", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("str", validStr.toString())
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "BIN", 5 + i);
+        }
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+        for (int i = 1; i < CNT; i++) {
+            String v = validStr.append("0").toString();
+            int len = 5 + i;
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertTableVarColumns() throws Exception {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("SQL");
+
+            for (int i = 1; i < CNT; i++) {
+                validStr.append("0");
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, validStr.toString())).getAll();
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "BIN", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("str", validStr.toString())
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "BIN", 5 + i);
+            }
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertValueVarColumns() throws Exception {
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("PERSON");
+
+            StringBuilder validStr = new StringBuilder("12345");
+
+            SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+            SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+            for (int i = 1; i < CNT; i++) {
+                String v = validStr.append("0").toString();
+                int len = 5 + i;
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.put(KEY, new Person(v));
+
+                        return null;
+                    } }, "NAME", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                        return null;
+                    } }, "ARR", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, v)).getAll();
+
+                        return null;
+                    } }, "NAME", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "ARR", len);
+            }
+        }
+    }
+
+    /** */
+    private void assertPrecision(Callable<Object> clo, String colName, int len) {
+        GridTestUtils.assertThrows(null, clo, CacheException.class,
+            "Value for a column '" + colName + "' is too long. Maximum length: 5, actual length: " + len);
+
+        assertNull(cache.get(0));
+    }
+
+    /** */
+    private void assertClientPrecision(Callable<Object> clo, String colName, int len) {
+        GridTestUtils.assertThrows(null, clo, ClientException.class,
+            "Value for a column '" + colName + "' is too long. Maximum length: 5, actual length: " + len);
+
+        assertNull(cache.get(0));
+    }
+
+    /** */
+    static class Person {
+        /** */
+        @QuerySqlField(precision = 5)
+        private final String name;
+
+        @QuerySqlField(precision = 5)
+        private final byte[] arr;
+
+        /** */
+        Person(String name) {
+            this.name = name;
+            this.arr = null;
+        }
+
+        /** */
+        Person(byte[] arr) {
+            this.name = null;
+            this.arr = arr;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            if (name != null)

Review comment:
       Where do you use `equals` and `hashCode`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688297460



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {

Review comment:
       I suppose that it is enough to test only for `CNT = 6`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688380685



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {
+            validStr.append("0");
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, validStr.toString()));
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "BIN", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("str", validStr.toString())
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "BIN", 5 + i);
+        }
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+        for (int i = 1; i < CNT; i++) {
+            String v = validStr.append("0").toString();
+            int len = 5 + i;
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertTableVarColumns() throws Exception {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("SQL");
+
+            for (int i = 1; i < CNT; i++) {
+                validStr.append("0");
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, validStr.toString())).getAll();
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "BIN", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("str", validStr.toString())
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "BIN", 5 + i);
+            }
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertValueVarColumns() throws Exception {
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("PERSON");
+
+            StringBuilder validStr = new StringBuilder("12345");
+
+            SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+            SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+            for (int i = 1; i < CNT; i++) {
+                String v = validStr.append("0").toString();
+                int len = 5 + i;
+
+                assertClientPrecision(new Callable<Object>() {

Review comment:
       Works with lambda with return value. Thanks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688296810



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {
+            validStr.append("0");
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, validStr.toString()));
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "BIN", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("str", validStr.toString())
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "BIN", 5 + i);
+        }
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+        for (int i = 1; i < CNT; i++) {
+            String v = validStr.append("0").toString();
+            int len = 5 + i;
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertTableVarColumns() throws Exception {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("SQL");
+
+            for (int i = 1; i < CNT; i++) {
+                validStr.append("0");
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, validStr.toString())).getAll();
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "BIN", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("str", validStr.toString())
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "BIN", 5 + i);
+            }
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertValueVarColumns() throws Exception {
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("PERSON");
+
+            StringBuilder validStr = new StringBuilder("12345");
+
+            SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+            SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+            for (int i = 1; i < CNT; i++) {
+                String v = validStr.append("0").toString();
+                int len = 5 + i;
+
+                assertClientPrecision(new Callable<Object>() {

Review comment:
       I am not insisting, but may be use here just lambda?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688296274



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {
+            validStr.append("0");
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, validStr.toString()));
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "BIN", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("str", validStr.toString())
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "BIN", 5 + i);
+        }
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+        for (int i = 1; i < CNT; i++) {
+            String v = validStr.append("0").toString();
+            int len = 5 + i;
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertTableVarColumns() throws Exception {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("SQL");
+
+            for (int i = 1; i < CNT; i++) {
+                validStr.append("0");
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, validStr.toString())).getAll();
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "BIN", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("str", validStr.toString())
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "BIN", 5 + i);
+            }
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertValueVarColumns() throws Exception {
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("PERSON");
+
+            StringBuilder validStr = new StringBuilder("12345");
+
+            SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+            SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+            for (int i = 1; i < CNT; i++) {
+                String v = validStr.append("0").toString();
+                int len = 5 + i;
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.put(KEY, new Person(v));
+
+                        return null;
+                    } }, "NAME", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                        return null;
+                    } }, "ARR", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, v)).getAll();
+
+                        return null;
+                    } }, "NAME", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "ARR", len);
+            }
+        }
+    }
+
+    /** */
+    private void assertPrecision(Callable<Object> clo, String colName, int len) {
+        GridTestUtils.assertThrows(null, clo, CacheException.class,
+            "Value for a column '" + colName + "' is too long. Maximum length: 5, actual length: " + len);
+
+        assertNull(cache.get(0));
+    }
+
+    /** */
+    private void assertClientPrecision(Callable<Object> clo, String colName, int len) {
+        GridTestUtils.assertThrows(null, clo, ClientException.class,
+            "Value for a column '" + colName + "' is too long. Maximum length: 5, actual length: " + len);
+
+        assertNull(cache.get(0));
+    }
+
+    /** */
+    static class Person {
+        /** */
+        @QuerySqlField(precision = 5)
+        private final String name;
+
+        @QuerySqlField(precision = 5)

Review comment:
       Missing empty javadoc




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688385049



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {
+            validStr.append("0");
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, validStr.toString()));
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "BIN", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("str", validStr.toString())
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "BIN", 5 + i);
+        }
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+        for (int i = 1; i < CNT; i++) {
+            String v = validStr.append("0").toString();
+            int len = 5 + i;
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertTableVarColumns() throws Exception {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {

Review comment:
       Because it is a separate user interface for data. For example DataStreamer is broken, so I've decided to test ThinClient too. But also I agree that forgot to test it with cache created with thin client. Will add test for that.

##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {
+            validStr.append("0");
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, validStr.toString()));
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "BIN", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("str", validStr.toString())
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "BIN", 5 + i);
+        }
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+        for (int i = 1; i < CNT; i++) {
+            String v = validStr.append("0").toString();
+            int len = 5 + i;
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertTableVarColumns() throws Exception {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("SQL");
+
+            for (int i = 1; i < CNT; i++) {
+                validStr.append("0");
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, validStr.toString())).getAll();
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "BIN", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("str", validStr.toString())
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "BIN", 5 + i);
+            }
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertValueVarColumns() throws Exception {
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("PERSON");
+
+            StringBuilder validStr = new StringBuilder("12345");
+
+            SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+            SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+            for (int i = 1; i < CNT; i++) {
+                String v = validStr.append("0").toString();
+                int len = 5 + i;
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.put(KEY, new Person(v));
+
+                        return null;
+                    } }, "NAME", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                        return null;
+                    } }, "ARR", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, v)).getAll();
+
+                        return null;
+                    } }, "NAME", len);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "ARR", len);
+            }
+        }
+    }
+
+    /** */
+    private void assertPrecision(Callable<Object> clo, String colName, int len) {
+        GridTestUtils.assertThrows(null, clo, CacheException.class,
+            "Value for a column '" + colName + "' is too long. Maximum length: 5, actual length: " + len);
+
+        assertNull(cache.get(0));
+    }
+
+    /** */
+    private void assertClientPrecision(Callable<Object> clo, String colName, int len) {
+        GridTestUtils.assertThrows(null, clo, ClientException.class,
+            "Value for a column '" + colName + "' is too long. Maximum length: 5, actual length: " + len);
+
+        assertNull(cache.get(0));
+    }
+
+    /** */
+    static class Person {
+        /** */
+        @QuerySqlField(precision = 5)
+        private final String name;
+
+        @QuerySqlField(precision = 5)
+        private final byte[] arr;
+
+        /** */
+        Person(String name) {
+            this.name = name;
+            this.arr = null;
+        }
+
+        /** */
+        Person(byte[] arr) {
+            this.name = null;
+            this.arr = arr;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            if (name != null)

Review comment:
       Will remove it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688306079



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {
+            validStr.append("0");
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, validStr.toString()));
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "BIN", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("str", validStr.toString())
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "BIN", 5 + i);
+        }
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+        for (int i = 1; i < CNT; i++) {
+            String v = validStr.append("0").toString();
+            int len = 5 + i;
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertTableVarColumns() throws Exception {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {

Review comment:
       I don't understand why you have decided to write tests for thin client. 
   I can understand if you'd  create cache from IgniteClient using ClientCacheConfiguration, it's ok. 
   But not in this case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch closed pull request #9315: IGNITE-15302 Add support of precision parameter for varbinary type

Posted by GitBox <gi...@apache.org>.
ivandasch closed pull request #9315:
URL: https://github.com/apache/ignite/pull/9315


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688305635



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {

Review comment:
       actually for `CNT = 1`, as CNT shows number of additional symbols. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688295572



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
##########
@@ -646,11 +646,15 @@ else if (coCtx.kernalContext().cacheObjects().typeId(prop.type().getName()) !=
             if (propVal == null || prop.precision() == -1)
                 continue;
 
-            if (String.class == propVal.getClass() &&
-                ((String)propVal).length() > prop.precision()) {
-                throw new IgniteSQLException("Value for a column '" + prop.name() + "' is too long. " + 
-                    "Maximum length: " + prop.precision() + ", actual length: " + ((CharSequence)propVal).length(),
-                    isKey ? TOO_LONG_KEY : TOO_LONG_VALUE);
+            if (String.class == propVal.getClass() || byte[].class == propVal.getClass()) {
+                int propValLen = propVal.getClass() == String.class ? ((String) propVal).length()

Review comment:
       According to codestyle it should be
   `((String)propVal).length())`
   The same is for casting to `byte[]`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688304240



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));

Review comment:
       You can set VALUE_TYPE to `Person.class.getName()` and use the same assertions for both cases and eliminate copy-paste




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ivandasch commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
ivandasch commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688302853



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);

Review comment:
       I'd suggests to start grid in one place --`beforeTestsStarted` , grid will be automatically stopped after tests finish.
   You can just clear caches in `beforeTest` and `afterTest`. I'd suggest to create both caches in separate test methods.
   Right now you have mixed approach and this is not consistent




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9315: IGNITE-15302 Enable precision for binary.

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9315:
URL: https://github.com/apache/ignite/pull/9315#discussion_r688300725



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/PrecisionTest.java
##########
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import javax.cache.CacheException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class PrecisionTest extends GridCommonAbstractTest {
+    /** */
+    private IgniteCache<Integer, Person> cache;
+
+    /** */
+    private static final int KEY = 0;
+
+    /** */
+    private static final int CNT = 10;
+
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<Integer, Person>("PERSON")
+            .setIndexedTypes(Integer.class, Person.class);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignite ignite = startGrids(2);
+
+        cache = ignite.cache("PERSON");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testInsertTableVarColumns() {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        IgniteCache tblCache = ignite(0).cache("SQL");
+
+        for (int i = 1; i < CNT; i++) {
+            validStr.append("0");
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, validStr.toString()));
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "BIN", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("str", validStr.toString())
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "STR", 5 + i);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                        .setField("id", KEY)
+                        .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                        .build();
+
+                    tblCache.put(0, bo);
+
+                    return null;
+                } }, "BIN", 5 + i);
+        }
+    }
+
+    /** */
+    @Test
+    public void testInsertValueVarColumns() {
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+        for (int i = 1; i < CNT; i++) {
+            String v = validStr.append("0").toString();
+            int len = 5 + i;
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.put(KEY, new Person(v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(strQry.setArgs(KEY, v));
+
+                    return null;
+                } }, "NAME", len);
+
+            assertPrecision(new Callable<Object>() {
+                @Override public Object call() {
+                    cache.query(binQry.setArgs(KEY, v.getBytes(StandardCharsets.UTF_8)));
+
+                    return null;
+                } }, "ARR", len);
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertTableVarColumns() throws Exception {
+        cache.query(new SqlFieldsQuery("" +
+            "create table TABLE(" +
+            "   id int PRIMARY KEY," +
+            "   str varchar(5)," +
+            "   bin binary(5)" +
+            ") with \"CACHE_NAME=SQL,VALUE_TYPE=SQL_TYPE\""));
+
+        StringBuilder validStr = new StringBuilder("12345");
+
+        SqlFieldsQuery strQry = new SqlFieldsQuery("insert into TABLE(id, str) values (?, ?)");
+        SqlFieldsQuery binQry = new SqlFieldsQuery("insert into TABLE(id, bin) values (?, ?)");
+
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("SQL");
+
+            for (int i = 1; i < CNT; i++) {
+                validStr.append("0");
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(strQry.setArgs(KEY, validStr.toString())).getAll();
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        cc.query(binQry.setArgs(KEY, validStr.toString().getBytes(StandardCharsets.UTF_8))).getAll();
+
+                        return null;
+                    } }, "BIN", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("str", validStr.toString())
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "STR", 5 + i);
+
+                assertClientPrecision(new Callable<Object>() {
+                    @Override public Object call() {
+                        BinaryObject bo = ignite(0).binary().builder("SQL_TYPE")
+                            .setField("id", KEY)
+                            .setField("bin", validStr.toString().getBytes(StandardCharsets.UTF_8))
+                            .build();
+
+                        cc.put(0, bo);
+
+                        return null;
+                    } }, "BIN", 5 + i);
+            }
+        }
+    }
+
+    /** */
+    @Test
+    public void testClientInsertValueVarColumns() throws Exception {
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1"))) {
+            ClientCache cc = client.cache("PERSON");
+
+            StringBuilder validStr = new StringBuilder("12345");
+
+            SqlFieldsQuery strQry = new SqlFieldsQuery("insert into PERSON(_KEY, name) values (?, ?)");
+            SqlFieldsQuery binQry = new SqlFieldsQuery("insert into PERSON(_KEY, arr) values (?, ?)");
+
+            for (int i = 1; i < CNT; i++) {
+                String v = validStr.append("0").toString();
+                int len = 5 + i;
+
+                assertClientPrecision(new Callable<Object>() {

Review comment:
       Usage of pure lambda is broken for assertThrows. It converts lambda to RunnableX that rethrow any exception with IgniteException wrapper. So it's impossible to check exception class then.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org