You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2021/10/05 06:41:30 UTC
[ignite] branch master updated: IGNITE-15484 Implement forbid
duplicated field in CREATE INDEX clause - Fixes #9397.
This is an automated email from the ASF dual-hosted git repository.
ivandasch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 04011e0 IGNITE-15484 Implement forbid duplicated field in CREATE INDEX clause - Fixes #9397.
04011e0 is described below
commit 04011e049a3bc66ed25442752a9a8ef188e87026
Author: Maksim Timonin <ti...@gmail.com>
AuthorDate: Tue Oct 5 09:39:56 2021 +0300
IGNITE-15484 Implement forbid duplicated field in CREATE INDEX clause - Fixes #9397.
Signed-off-by: Ivan Daschinsky <iv...@apache.org>
---
.../query/h2/sql/GridSqlQueryParser.java | 9 ++++-
.../processors/cache/index/BasicIndexTest.java | 47 ++++++++++++++++++++++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
index a372fad..55ee618 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
@@ -1091,7 +1091,14 @@ public class GridSqlQueryParser {
IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
}
- flds.put(INDEX_COLUMN_NAME.get(col), (sortType & SortOrder.DESCENDING) == 0);
+ Boolean prev = flds.put(INDEX_COLUMN_NAME.get(col), (sortType & SortOrder.DESCENDING) == 0);
+
+ if (prev != null) {
+ String prevCol = INDEX_COLUMN_NAME.get(col) + " " + (prev ? "ASC" : "DESC");
+
+ throw new IgniteSQLException("Already defined column in index: " + prevCol,
+ IgniteQueryErrorCode.COLUMN_ALREADY_EXISTS);
+ }
}
idx.setFields(flds);
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
index d719467..6d99e91 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
@@ -44,6 +44,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.failure.StopNodeFailureHandler;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
import org.apache.ignite.internal.processors.query.QueryUtils;
import org.apache.ignite.internal.processors.query.h2.H2TableDescriptor;
import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
@@ -1034,6 +1035,52 @@ public class BasicIndexTest extends AbstractIndexingCommonTest {
assertFalse(checkIdxUsed(qryProc, null, TEST_TBL_NAME, "LAST_NAME", "ADDRESS"));
}
+ /**
+ * Tests that it's forbidden to create index with duplicated columns from SQL.
+ */
+ @Test
+ public void testFailToCreateSqlIndexWithDuplicatedColumn() throws Exception {
+ inlineSize = 10;
+
+ IgniteEx ig0 = startGrid(0);
+
+ GridQueryProcessor qryProc = ig0.context().query();
+
+ populateTable(qryProc, TEST_TBL_NAME, 1, "ID", "NAME");
+
+ GridTestUtils.assertThrows(log, () -> {
+ String sqlIdx1 = String.format("create index \"idx1\" on %s(NAME, NAME)", TEST_TBL_NAME);
+
+ qryProc.querySqlFields(new SqlFieldsQuery(sqlIdx1), true).getAll();
+
+ return null;
+ }, IgniteSQLException.class, "Already defined column in index: NAME ASC");
+
+ GridTestUtils.assertThrows(log, () -> {
+ String sqlIdx1 = String.format("create index \"idx1\" on %s(NAME ASC, NAME DESC)", TEST_TBL_NAME);
+
+ qryProc.querySqlFields(new SqlFieldsQuery(sqlIdx1), true).getAll();
+
+ return null;
+ }, IgniteSQLException.class, "Already defined column in index: NAME ASC");
+
+ GridTestUtils.assertThrows(log, () -> {
+ String sqlIdx1 = String.format("create index \"idx1\" on %s(NAME DESC, ID, NAME)", TEST_TBL_NAME);
+
+ qryProc.querySqlFields(new SqlFieldsQuery(sqlIdx1), true).getAll();
+
+ return null;
+ }, IgniteSQLException.class, "Already defined column in index: NAME DESC");
+
+ GridTestUtils.assertThrows(log, () -> {
+ String sqlIdx1 = String.format("create index \"idx1\" on %s(ID, ID)", TEST_TBL_NAME);
+
+ qryProc.querySqlFields(new SqlFieldsQuery(sqlIdx1), true).getAll();
+
+ return null;
+ }, IgniteSQLException.class, "Already defined column in index: ID");
+ }
+
/** */
@Test
public void testNoIndexesWithPersistence() throws Exception {