You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/06/13 07:46:42 UTC
[12/39] ignite git commit: IGNITE-5325: CREATE TABLE: added
"cacheGroup" property. This closes #2099.
IGNITE-5325: CREATE TABLE: added "cacheGroup" property. This closes #2099.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/45bb5b3a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/45bb5b3a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/45bb5b3a
Branch: refs/heads/ignite-5272
Commit: 45bb5b3a2faca318ede6dd194bd2fb7fb9898d7c
Parents: 5c77dab
Author: Alexander Paschenko <al...@gmail.com>
Authored: Thu Jun 8 13:00:34 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Thu Jun 8 13:00:34 2017 +0300
----------------------------------------------------------------------
.../processors/query/GridQueryProcessor.java | 9 ++++-
.../query/h2/ddl/DdlStatementsProcessor.java | 3 +-
.../query/h2/sql/GridSqlCreateTable.java | 20 +++++++++-
.../query/h2/sql/GridSqlQueryParser.java | 10 +++++
.../cache/index/H2DynamicTableSelfTest.java | 39 +++++++++++++++-----
5 files changed, 65 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/45bb5b3a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 4311b12..dd07584 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -1278,6 +1278,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
* @param schemaName Schema name to create table in.
* @param entity Entity to create table from.
* @param templateName Template name.
+ * @param cacheGroup Cache group name.
* @param affinityKey Affinity key column name.
* @param atomicityMode Atomicity mode.
* @param backups Backups.
@@ -1285,8 +1286,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
- public void dynamicTableCreate(String schemaName, QueryEntity entity, String templateName, String affinityKey,
- @Nullable CacheAtomicityMode atomicityMode, int backups, boolean ifNotExists) throws IgniteCheckedException {
+ public void dynamicTableCreate(String schemaName, QueryEntity entity, String templateName, String cacheGroup,
+ String affinityKey, @Nullable CacheAtomicityMode atomicityMode, int backups, boolean ifNotExists)
+ throws IgniteCheckedException {
assert !F.isEmpty(templateName);
assert backups >= 0;
@@ -1307,6 +1309,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
ccfg.setName(QueryUtils.createTableCacheName(schemaName, entity.getTableName()));
+ if (!F.isEmpty(cacheGroup))
+ ccfg.setGroupName(cacheGroup);
+
if (atomicityMode != null)
ccfg.setAtomicityMode(atomicityMode);
http://git-wip-us.apache.org/repos/asf/ignite/blob/45bb5b3a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
index d6bcabd..65e402d 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
@@ -22,7 +22,6 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.cache.QueryIndex;
@@ -177,7 +176,7 @@ public class DdlStatementsProcessor {
if (err != null)
throw err;
- ctx.query().dynamicTableCreate(cmd.schemaName(), e, cmd.templateName(),
+ ctx.query().dynamicTableCreate(cmd.schemaName(), e, cmd.templateName(), cmd.cacheGroup(),
cmd.affinityKey(), cmd.atomicityMode(), cmd.backups(), cmd.ifNotExists());
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/45bb5b3a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
index edced6b..fa76123 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
@@ -17,11 +17,10 @@
package org.apache.ignite.internal.processors.query.h2.sql;
-import org.apache.ignite.cache.CacheAtomicityMode;
-
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import org.apache.ignite.cache.CacheAtomicityMode;
/**
* CREATE TABLE statement.
@@ -38,6 +37,9 @@ public class GridSqlCreateTable extends GridSqlStatement {
/** Cache name upon which new cache configuration for this table must be based. */
private String templateName;
+ /** Group to put new cache into. */
+ private String cacheGrp;
+
/** Atomicity mode for new cache. */
private CacheAtomicityMode atomicityMode;
@@ -74,6 +76,20 @@ public class GridSqlCreateTable extends GridSqlStatement {
}
/**
+ * @return Group to put new cache into.
+ */
+ public String cacheGroup() {
+ return cacheGrp;
+ }
+
+ /**
+ * @param cacheGrp Group to put new cache into.
+ */
+ public void cacheGroup(String cacheGrp) {
+ this.cacheGrp = cacheGrp;
+ }
+
+ /**
* @return Atomicity mode for new cache.
*/
public CacheAtomicityMode atomicityMode() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/45bb5b3a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
----------------------------------------------------------------------
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 d8baed3..0d6a0b2 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
@@ -405,6 +405,9 @@ public class GridSqlQueryParser {
private static final String PARAM_ATOMICITY = "ATOMICITY";
/** */
+ private static final String PARAM_CACHE_GROUP = "CACHEGROUP";
+
+ /** */
private static final String PARAM_AFFINITY_KEY = "AFFINITYKEY";
/** */
@@ -1051,6 +1054,13 @@ public class GridSqlQueryParser {
break;
+ case PARAM_CACHE_GROUP:
+ ensureNotEmpty(name, val);
+
+ res.cacheGroup(val);
+
+ break;
+
case PARAM_AFFINITY_KEY:
ensureNotEmpty(name, val);
http://git-wip-us.apache.org/repos/asf/ignite/blob/45bb5b3a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
index e4babba..2255fb8 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
@@ -105,7 +105,15 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
* @throws Exception if failed.
*/
public void testCreateTable() throws Exception {
- doTestCreateTable(CACHE_NAME, null);
+ doTestCreateTable(CACHE_NAME, null, null);
+ }
+
+ /**
+ * Test that {@code CREATE TABLE} actually creates new cache, H2 table and type descriptor on all nodes.
+ * @throws Exception if failed.
+ */
+ public void testCreateTableWithCacheGroup() throws Exception {
+ doTestCreateTable(CACHE_NAME, "MyGroup", null);
}
/**
@@ -114,7 +122,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
* @throws Exception if failed.
*/
public void testCreateTableReplicated() throws Exception {
- doTestCreateTable("REPLICATED", CacheMode.REPLICATED);
+ doTestCreateTable("REPLICATED", null, CacheMode.REPLICATED);
}
/**
@@ -123,7 +131,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
* @throws Exception if failed.
*/
public void testCreateTablePartitioned() throws Exception {
- doTestCreateTable("PARTITIONED", CacheMode.PARTITIONED);
+ doTestCreateTable("PARTITIONED", null, CacheMode.PARTITIONED);
}
/**
@@ -132,7 +140,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
* @throws Exception if failed.
*/
public void testCreateTableReplicatedCaseInsensitive() throws Exception {
- doTestCreateTable("replicated", CacheMode.REPLICATED);
+ doTestCreateTable("replicated", null, CacheMode.REPLICATED);
}
/**
@@ -141,7 +149,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
* @throws Exception if failed.
*/
public void testCreateTablePartitionedCaseInsensitive() throws Exception {
- doTestCreateTable("partitioned", CacheMode.PARTITIONED);
+ doTestCreateTable("partitioned", null, CacheMode.PARTITIONED);
}
/**
@@ -150,19 +158,21 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
* @throws Exception if failed.
*/
public void testCreateTableNoTemplate() throws Exception {
- doTestCreateTable(null, CacheMode.PARTITIONED);
+ doTestCreateTable(null, null, CacheMode.PARTITIONED);
}
/**
* Test that {@code CREATE TABLE} with given template cache name actually creates new cache,
* H2 table and type descriptor on all nodes, optionally with cache type check.
* @param tplCacheName Template cache name.
+ * @param cacheGrp Cache group name, or {@code null} if no group is set.
* @param mode Expected cache mode, or {@code null} if no check is needed.
*/
- private void doTestCreateTable(String tplCacheName, CacheMode mode) {
+ private void doTestCreateTable(String tplCacheName, String cacheGrp, CacheMode mode) {
executeDdl("CREATE TABLE \"Person\" (\"id\" int, \"city\" varchar," +
" \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\")) WITH " +
- (F.isEmpty(tplCacheName) ? "" : "\"template=" + tplCacheName + "\",") + "\"backups=10,atomicity=atomic\"");
+ (F.isEmpty(tplCacheName) ? "" : "\"template=" + tplCacheName + "\",") + "\"backups=10,atomicity=atomic\"" +
+ (F.isEmpty(cacheGrp) ? "" : ",\"cacheGroup=" + cacheGrp + '"'));
String cacheName = cacheName("Person");
@@ -184,6 +194,8 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
assertTrue(cacheDesc.sql());
+ assertEquals(cacheGrp, cacheDesc.groupDescriptor().groupName());
+
if (mode != null)
assertEquals(mode, cacheDesc.cacheConfiguration().getCacheMode());
@@ -236,7 +248,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
}
/**
- * Test that attempting to omit mandatory value of ATOMICITY parameter yields an error.
+ * Test that providing an invalid value of ATOMICITY parameter yields an error.
*/
public void testInvalidAtomicity() {
assertCreateTableWithParamsThrows("atomicity=InvalidValue",
@@ -244,6 +256,13 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
}
/**
+ * Test that attempting to omit mandatory value of CACHEGROUP parameter yields an error.
+ */
+ public void testEmptyCacheGroup() {
+ assertCreateTableWithParamsThrows("cachegroup=", "Parameter value cannot be empty: CACHEGROUP");
+ }
+
+ /**
* Test that attempting to {@code CREATE TABLE} that already exists does not yield an error if the statement
* contains {@code IF NOT EXISTS} clause.
* @throws Exception if failed.
@@ -405,7 +424,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
e.setValueType("City");
queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null,
- CacheAtomicityMode.ATOMIC, 10, false);
+ null, CacheAtomicityMode.ATOMIC, 10, false);
return null;
}