IGNITE-6689: SQL: Added DATA_REGION option for CREATE TABLE.
authordevozerov <ppozerov@gmail.com>
Sat, 21 Oct 2017 15:47:04 +0000 (18:47 +0300)
committerdevozerov <ppozerov@gmail.com>
Sat, 21 Oct 2017 15:47:04 +0000 (18:47 +0300)
RELEASE_NOTES.txt
modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java

index 25007c7..27c5767 100644 (file)
@@ -39,6 +39,7 @@ SQL:
 * CREATE TABLE: Added NOT NULL support.
 * CREATE TABLE: Ability to specify cache, key type and value type names.
 * CREATE TABLE: Added "WRAP_KEY" and "WRAP_VALUE" options to CREATE TABLE command.
+* CREATE TABLE: Added DATA_REGION option.
 * CREATE TABLE: Added WRITE_SYNCHRONIZATION_MODE option.
 * ALTER TABLE: ADD COLUMN support.
 * Added lazy query execution mode (SqlFieldsQuery.setLazy).
index 98428b6..4886b1b 100644 (file)
@@ -1360,6 +1360,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param templateName Template name.
      * @param cacheName Cache name.
      * @param cacheGroup Cache group name.
+     * @param dataRegion Data region name.
      * @param affinityKey Affinity key column name.
      * @param atomicityMode Atomicity mode.
      * @param writeSyncMode Write synchronization mode.
@@ -1369,7 +1370,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      */
     @SuppressWarnings("unchecked")
     public void dynamicTableCreate(String schemaName, QueryEntity entity, String templateName, String cacheName,
-        String cacheGroup, String affinityKey, @Nullable CacheAtomicityMode atomicityMode,
+        String cacheGroup, @Nullable String dataRegion, String affinityKey, @Nullable CacheAtomicityMode atomicityMode,
         @Nullable CacheWriteSynchronizationMode writeSyncMode, int backups, boolean ifNotExists)
         throws IgniteCheckedException {
         assert !F.isEmpty(templateName);
@@ -1403,6 +1404,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         if (!F.isEmpty(cacheGroup))
             ccfg.setGroupName(cacheGroup);
 
+        if (!F.isEmpty(dataRegion))
+            ccfg.setDataRegionName(dataRegion);
+
         if (atomicityMode != null)
             ccfg.setAtomicityMode(atomicityMode);
 
index f39e587..d29a063 100644 (file)
@@ -184,7 +184,7 @@ public class DdlStatementsProcessor {
                         throw err;
 
                     ctx.query().dynamicTableCreate(cmd.schemaName(), e, cmd.templateName(), cmd.cacheName(),
-                        cmd.cacheGroup(),cmd.affinityKey(), cmd.atomicityMode(),
+                        cmd.cacheGroup(), cmd.dataRegionName(), cmd.affinityKey(), cmd.atomicityMode(),
                         cmd.writeSynchronizationMode(), cmd.backups(), cmd.ifNotExists());
                 }
             }
index de10826..3608aed 100644 (file)
@@ -77,6 +77,9 @@ public class GridSqlCreateTable extends GridSqlStatement {
     /** Forcefully turn single column value into an Object. */
     private Boolean wrapVal;
 
+    /** Data region. */
+    private String dataRegionName;
+
     /** Extra WITH-params. */
     private List<String> params;
 
@@ -305,6 +308,20 @@ public class GridSqlCreateTable extends GridSqlStatement {
     }
 
     /**
+     * @return Data region name.
+     */
+    public String dataRegionName() {
+        return dataRegionName;
+    }
+
+    /**
+     * @param dataRegionName Data region name.
+     */
+    public void dataRegionName(String dataRegionName) {
+        this.dataRegionName = dataRegionName;
+    }
+
+    /**
      * @return Extra WITH-params.
      */
     public List<String> params() {
index 280fb2d..46b2aee 100644 (file)
@@ -480,6 +480,9 @@ public class GridSqlQueryParser {
     /** */
     public static final String PARAM_WRAP_VALUE = "WRAP_VALUE";
 
+    /** Data region name. */
+    public static final String PARAM_DATA_REGION = "DATA_REGION";
+
     /** */
     private final IdentityHashMap<Object, Object> h2ObjToGridObj = new IdentityHashMap<>();
 
@@ -1392,6 +1395,13 @@ public class GridSqlQueryParser {
 
                 break;
 
+            case PARAM_DATA_REGION:
+                ensureNotEmpty(name, val);
+
+                res.dataRegionName(val);
+
+                break;
+
             default:
                 throw new IgniteSQLException("Unsupported parameter: " + name, IgniteQueryErrorCode.PARSING);
         }
index c56db84..ef59a62 100644 (file)
@@ -44,6 +44,8 @@ import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.binary.BinaryMarshaller;
@@ -80,6 +82,12 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
     /** */
     private final static String INDEXED_CACHE_NAME_2 = INDEXED_CACHE_NAME + "_2";
 
+    /** Data region name. */
+    public static final String DATA_REGION_NAME = "my_data_region";
+
+    /** Bad data region name. */
+    public static final String DATA_REGION_NAME_BAD = "my_data_region_bad";
+
     /** {@inheritDoc} */
     @Override protected void beforeTestsStarted() throws Exception {
         super.beforeTestsStarted();
@@ -779,7 +787,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
                 e.setKeyType("CityKey");
                 e.setValueType("City");
 
-                queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null, null,
+                queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null, null, null,
                     null, CacheAtomicityMode.ATOMIC, null, 10, false);
 
                 return null;
@@ -863,6 +871,33 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
     }
 
     /**
+     * Test data region.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings({"ThrowableNotThrown", "unchecked"})
+    public void testDataRegion() throws Exception {
+        // Empty region name.
+        GridTestUtils.assertThrows(log, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                execute("CREATE TABLE TEST_DATA_REGION (name varchar primary key, code int) WITH \"data_region=\"");
+
+                return null;
+            }
+        }, IgniteSQLException.class, "Parameter value cannot be empty: DATA_REGION");
+
+        // Valid region name.
+        execute("CREATE TABLE TEST_DATA_REGION (name varchar primary key, code int) WITH \"data_region=" +
+            DATA_REGION_NAME + "\"");
+
+        CacheConfiguration ccfg =
+            client().cache("SQL_PUBLIC_TEST_DATA_REGION").getConfiguration(CacheConfiguration.class);
+
+        assertEquals(DATA_REGION_NAME, ccfg.getDataRegionName());
+    }
+
+
+    /**
      * Test various cases of affinity key column specification.
      */
     @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@@ -1461,7 +1496,10 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
     private IgniteConfiguration commonConfiguration(int idx) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(getTestIgniteInstanceName(idx));
 
+        DataRegionConfiguration dataRegionCfg = new DataRegionConfiguration().setName(DATA_REGION_NAME);
+
         cfg.setMarshaller(new BinaryMarshaller());
+        cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDataRegionConfigurations(dataRegionCfg));
 
         return optimize(cfg);
     }