You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2020/07/10 06:31:15 UTC
[ignite] branch ignite-2.9 updated: IGNITE-13142 Fixed wrongful
error message regarding SQL not-null constraint - Fixes #7961.
This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch ignite-2.9
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/ignite-2.9 by this push:
new 393bd1e IGNITE-13142 Fixed wrongful error message regarding SQL not-null constraint - Fixes #7961.
393bd1e is described below
commit 393bd1ece77bf9123f7553d9491f7ec5ee4a95ab
Author: Sergey Kalashnikov <zk...@gmail.com>
AuthorDate: Fri Jul 10 11:26:27 2020 +0500
IGNITE-13142 Fixed wrongful error message regarding SQL not-null constraint - Fixes #7961.
Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
(cherry picked from commit 60f38e6ec084b0dd6e666b3554a140804d6cfc71)
---
.../processors/query/QueryTypeDescriptorImpl.java | 9 +-
.../query/SqlNotNullKeyValueFieldTest.java | 123 +++++++++++++++++++++
.../IgniteBinaryCacheQueryTestSuite.java | 2 +
3 files changed, 129 insertions(+), 5 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
index d39ec37..fb0b664 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
@@ -590,17 +590,16 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
boolean isKey = false;
- if (F.eq(prop.name(), keyFieldName) || (keyFieldName == null && F.eq(prop.name(), KEY_FIELD_NAME))) {
+ if (F.eq(prop.name(), keyFieldAlias()) || (keyFieldName == null && F.eq(prop.name(), KEY_FIELD_NAME))) {
propVal = key instanceof KeyCacheObject ? ((CacheObject) key).value(coCtx, true) : key;
isKey = true;
}
- else if (F.eq(prop.name(), valFieldName) || (valFieldName == null && F.eq(prop.name(), VAL_FIELD_NAME))) {
+ else if (F.eq(prop.name(), valueFieldAlias()) ||
+ (valFieldName == null && F.eq(prop.name(), VAL_FIELD_NAME)))
propVal = val instanceof CacheObject ? ((CacheObject)val).value(coCtx, true) : val;
- }
- else {
+ else
propVal = prop.value(key, val);
- }
if (propVal == null && prop.notNull()) {
throw new IgniteSQLException("Null value is not allowed for column '" + prop.name() + "'",
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlNotNullKeyValueFieldTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlNotNullKeyValueFieldTest.java
new file mode 100644
index 0000000..3081381
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlNotNullKeyValueFieldTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.query;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+/**
+ * Tests key and value fields with not-null constraints.
+ */
+@RunWith(Parameterized.class)
+public class SqlNotNullKeyValueFieldTest extends GridCommonAbstractTest {
+ /** */
+ @Parameterized.Parameter(0)
+ public String keyName;
+
+ /** */
+ @Parameterized.Parameter(1)
+ public String valName;
+
+ /** */
+ @Parameterized.Parameters(name = "key={0} val={1}")
+ public static Collection<?> parameters() {
+ return Arrays.asList(new Object[][] {
+ {"id", "val"},
+ {"ID", "VAL"}
+ });
+ }
+
+ /** */
+ @Before
+ public void setup() throws Exception {
+ startGrid(0);
+
+ startClientGrid("client");
+ }
+
+ /** */
+ @After
+ public void clean() {
+ stopAllGrids();
+ }
+
+ /** */
+ @Test
+ public void testQueryEntity() {
+ IgniteCache<?, ?> cache = grid("client").createCache(
+ new CacheConfiguration<>("default").setQueryEntities(
+ Collections.singleton(new QueryEntity()
+ .setTableName("Person")
+ .setKeyFieldName(keyName)
+ .setKeyType(Integer.class.getName())
+ .setValueFieldName(valName)
+ .setValueType(String.class.getName())
+ .setFields(new LinkedHashMap<>(
+ F.asMap(keyName, Integer.class.getName(),
+ valName, String.class.getName())))
+ .setNotNullFields(F.asSet(keyName, valName)))));
+
+ String qry = "insert into Person (" + keyName + ", " + valName + ") values (1, 'John Doe')";
+
+ QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(qry));
+
+ assertEquals(1, ((Number) cursor.getAll().get(0).get(0)).intValue());
+ }
+
+ /** */
+ @Test
+ public void testQuotedDDL() {
+ doTestDDL("\"" + keyName + "\"", "\"" + valName + "\"");
+ }
+
+ /** */
+ @Test
+ public void testUnquotedDDL() {
+ doTestDDL(keyName, valName);
+ }
+
+ /** */
+ private void doTestDDL(String key, String val) {
+ IgniteCache<?, ?> cache = grid("client").createCache(DEFAULT_CACHE_NAME);
+
+ cache.query(new SqlFieldsQuery("CREATE TABLE Person(" + key +
+ " INTEGER PRIMARY KEY NOT NULL, " + val + " VARCHAR NOT NULL)")).getAll();
+
+ String qry = "insert into Person (" + key + ", " + val + ") values (1, 'John Doe')";
+
+ QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(qry));
+
+ assertEquals(1, ((Number) cursor.getAll().get(0).get(0)).intValue());
+ }
+}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
index 691b784..e5d6671 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
@@ -224,6 +224,7 @@ import org.apache.ignite.internal.processors.query.SqlIncompatibleDataTypeExcept
import org.apache.ignite.internal.processors.query.SqlMergeOnClientNodeTest;
import org.apache.ignite.internal.processors.query.SqlMergeTest;
import org.apache.ignite.internal.processors.query.SqlNestedQuerySelfTest;
+import org.apache.ignite.internal.processors.query.SqlNotNullKeyValueFieldTest;
import org.apache.ignite.internal.processors.query.SqlPushDownFunctionTest;
import org.apache.ignite.internal.processors.query.SqlQueryHistoryFromClientSelfTest;
import org.apache.ignite.internal.processors.query.SqlQueryHistorySelfTest;
@@ -521,6 +522,7 @@ import org.junit.runners.Suite;
IgniteCacheDistributedPartitionQueryNodeRestartsSelfTest.class,
IgniteCacheDistributedPartitionQueryConfigurationSelfTest.class,
IgniteSqlKeyValueFieldsTest.class,
+ SqlNotNullKeyValueFieldTest.class,
IgniteSqlRoutingTest.class,
IgniteSqlNotNullConstraintTest.class,
LongIndexNameTest.class,