ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [11/40] ignite git commit: IGNITE-5430: CREATE TABLE: cache name is now masked as follows: "SQL_[schemaName]_[cacheName]". This closes #2101.
Date Fri, 09 Jun 2017 13:45:56 GMT
IGNITE-5430: CREATE TABLE: cache name is now masked as follows: "SQL_[schemaName]_[cacheName]".
This closes #2101.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8555e21e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8555e21e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8555e21e

Branch: refs/heads/ignite-5267
Commit: 8555e21e9063724e6f0a35862549c0b251d4d27b
Parents: 86d0049
Author: Alexander Paschenko <alexander.a.paschenko@gmail.com>
Authored: Wed Jun 7 14:16:47 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Wed Jun 7 14:16:47 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    |  2 +-
 .../internal/processors/query/QueryUtils.java   | 32 +++++++++++++++++
 .../query/h2/ddl/DdlStatementsProcessor.java    | 23 +++++-------
 .../cache/index/H2DynamicTableSelfTest.java     | 37 +++++++++++++-------
 4 files changed, 65 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8555e21e/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 edf8dc1..48c7229 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
@@ -1305,7 +1305,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             throw new SchemaOperationException("Template cache already contains query entities
which it should not: " +
                 templateName);
 
-        ccfg.setName(entity.getTableName());
+        ccfg.setName(QueryUtils.createTableCacheName(schemaName, entity.getTableName()));
 
         if (atomicityMode != null)
             ccfg.setAtomicityMode(atomicityMode);

http://git-wip-us.apache.org/repos/asf/ignite/blob/8555e21e/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
index fd498ad..fbd9afa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
@@ -1112,6 +1112,38 @@ public class QueryUtils {
     }
 
     /**
+     * Construct cache name for table.
+     *
+     * @param schemaName Schema name.
+     * @param tblName Table name.
+     * @return Cache name.
+     */
+    public static String createTableCacheName(String schemaName, String tblName) {
+        return "SQL_" + schemaName + "_" + tblName;
+    }
+
+    /**
+     * Construct value type name for table.
+     *
+     * @param schemaName Schema name.
+     * @param tblName Table name.
+     * @return Value type name.
+     */
+    public static String createTableValueTypeName(String schemaName, String tblName) {
+        return createTableCacheName(schemaName, tblName) + "_" + UUID.randomUUID().toString().replace("-",
"_");
+    }
+
+    /**
+     * Construct key type name for table.
+     *
+     * @param valTypeName Value type name.
+     * @return Key type name.
+     */
+    public static String createTableKeyTypeName(String valTypeName) {
+        return valTypeName + "_KEY";
+    }
+
+    /**
      * Private constructor.
      */
     private QueryUtils() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/8555e21e/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 251ee9f..5efc5c9 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 java.util.UUID;
 
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.QueryEntity;
@@ -191,6 +190,12 @@ public class DdlStatementsProcessor {
 
                 GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
 
+                if (tbl == null && cmd.ifExists()) {
+                    ctx.cache().createMissingQueryCaches();
+
+                    tbl = idx.dataTable(cmd.schemaName(), cmd.tableName());
+                }
+
                 if (tbl == null) {
                     if (!cmd.ifExists())
                         throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND,
@@ -290,8 +295,8 @@ public class DdlStatementsProcessor {
             res.addQueryField(e.getKey(), DataType.getTypeClassName(col.getType()), null);
         }
 
-        String valTypeName = valueType(createTbl.schemaName(), createTbl.tableName());
-        String keyTypeName = valTypeName + "_Key";
+        String valTypeName = QueryUtils.createTableValueTypeName(createTbl.schemaName(),
createTbl.tableName());
+        String keyTypeName = QueryUtils.createTableKeyTypeName(valTypeName);
 
         res.setValueType(valTypeName);
         res.setKeyType(keyTypeName);
@@ -302,18 +307,6 @@ public class DdlStatementsProcessor {
     }
 
     /**
-     * Construct value type name for table.
-     *
-     * @param schemaName Schema name.
-     * @param tblName Table name.
-     * @return Value type name.
-     */
-    private static String valueType(String schemaName, String tblName) {
-        return "sql_" + schemaName + "_" + tblName + "_" + UUID.randomUUID().toString().replace("-",
"_");
-    }
-
-
-    /**
      * @param cmd Statement.
      * @return Whether {@code cmd} is a DDL statement we're able to handle.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/8555e21e/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 efb6cc8..699fdad 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
@@ -91,11 +91,8 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
 
     /** {@inheritDoc} */
     @Override protected void afterTest() throws Exception {
-        if (client().cache("Person") != null)
-            executeDdl("DROP TABLE IF EXISTS PUBLIC.\"Person\"");
-
-
-            executeDdl("DROP TABLE IF EXISTS PUBLIC.\"City\"");
+        executeDdl("DROP TABLE IF EXISTS PUBLIC.\"Person\"");
+        executeDdl("DROP TABLE IF EXISTS PUBLIC.\"City\"");
 
         super.afterTest();
     }
@@ -164,12 +161,14 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
             " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\"))
WITH " +
             (F.isEmpty(tplCacheName) ? "" : "\"template=" + tplCacheName + "\",") + "\"backups=10,atomicity=atomic\"");
 
+        String cacheName = cacheName("Person");
+
         for (int i = 0; i < 4; i++) {
             IgniteEx node = grid(i);
 
-            assertNotNull(node.cache("Person"));
+            assertNotNull(node.cache(cacheName));
 
-            DynamicCacheDescriptor cacheDesc = node.context().cache().cacheDescriptor("Person");
+            DynamicCacheDescriptor cacheDesc = node.context().cache().cacheDescriptor(cacheName);
 
             assertNotNull(cacheDesc);
 
@@ -185,7 +184,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
             if (mode != null)
                 assertEquals(mode, cacheDesc.cacheConfiguration().getCacheMode());
 
-            QueryTypeDescriptorImpl desc = typeExisting(node, "Person", "Person");
+            QueryTypeDescriptorImpl desc = typeExisting(node, cacheName, "Person");
 
             assertEquals(Object.class, desc.keyClass());
             assertEquals(Object.class, desc.valueClass());
@@ -193,7 +192,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
             assertTrue(desc.valueTypeName(), desc.valueTypeName().contains("Person"));
 
             assertTrue(desc.keyTypeName(), desc.keyTypeName().startsWith(desc.valueTypeName()));
-            assertTrue(desc.keyTypeName(), desc.keyTypeName().endsWith("Key"));
+            assertTrue(desc.keyTypeName(), desc.keyTypeName().endsWith("KEY"));
 
             assertEquals(
                 F.asList("id", "city", "name", "surname", "age"),
@@ -352,12 +351,12 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
 
         GridTestUtils.assertThrows(null, new Callable<Object>() {
             @Override public Object call() throws Exception {
-                client().destroyCache("Person");
+                client().destroyCache(cacheName("Person"));
 
                 return null;
             }
         }, CacheException.class,
-        "Only cache created with cache API may be removed with direct call to destroyCache
[cacheName=Person]");
+        "Only cache created with cache API may be removed with direct call to destroyCache");
     }
 
     /**
@@ -372,7 +371,9 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
 
         GridTestUtils.assertThrows(null, new Callable<Object>() {
             @Override public Object call() throws Exception {
-                Ignition.start(clientConfiguration(5).setCacheConfiguration(new CacheConfiguration("Person")));
+                String cacheName = cacheName("Person");
+
+                Ignition.start(clientConfiguration(5).setCacheConfiguration(new CacheConfiguration(cacheName)));
 
                 return null;
             }
@@ -397,7 +398,7 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
                 e.setKeyFields(Collections.singleton("name"));
                 e.setFields(new LinkedHashMap<>(Collections.singletonMap("name", String.class.getName())));
                 e.setIndexes(Collections.singleton(new QueryIndex("name").setName("idx")));
-                e.setValueType("CityKey");
+                e.setKeyType("CityKey");
                 e.setValueType("City");
 
                 queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(),
@@ -621,4 +622,14 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
             .setSqlSchema(QueryUtils.DFLT_SCHEMA)
             .setNodeFilter(F.not(new DynamicIndexAbstractSelfTest.NodeFilter()));
     }
+
+    /**
+     * Get cache name.
+     *
+     * @param tblName Table name.
+     * @return Cache name.
+     */
+    private static String cacheName(String tblName) {
+        return QueryUtils.createTableCacheName("PUBLIC", tblName);
+    }
 }


Mime
View raw message