ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: IGNITE-5334: Fixed SQL schema handling, so that quoted name is treated as case-sensitive. This closes #2027.
Date Tue, 30 May 2017 07:54:00 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 64ab5cdfe -> b7f20211e


IGNITE-5334: Fixed SQL schema handling, so that quoted name is treated as case-sensitive.
This closes #2027.


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

Branch: refs/heads/master
Commit: b7f20211e372431bf61d661660fbaf8334a919f0
Parents: 64ab5cd
Author: devozerov <vozerov@gridgain.com>
Authored: Tue May 30 10:53:49 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Tue May 30 10:53:49 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java      |  2 +-
 .../internal/processors/query/QueryUtils.java     | 14 +++++++++++---
 .../query/IgniteSqlSchemaIndexingTest.java        | 18 ++++++++++++------
 .../query/IgniteSqlSplitterSelfTest.java          |  2 --
 4 files changed, 24 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b7f20211/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 f3da6d0..4187e2b 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
@@ -677,7 +677,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                 String cacheName = cctx.name();
 
-                String schemaName = QueryUtils.normalizeSchemaName(cacheName, cctx.config().getSqlSchema(),
escape);
+                String schemaName = QueryUtils.normalizeSchemaName(cacheName, cctx.config().getSqlSchema());
 
                 // Prepare candidates.
                 List<Class<?>> mustDeserializeClss = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/ignite/blob/b7f20211/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 c327820..b4feea4 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
@@ -268,10 +268,11 @@ public class QueryUtils {
      *
      * @param cacheName Cache name.
      * @param schemaName Schema name.
-     * @param escape Whether to perform escape.
      * @return Proper schema name according to ANSI-99 standard.
      */
-    public static String normalizeSchemaName(String cacheName, @Nullable String schemaName,
boolean escape) {
+    public static String normalizeSchemaName(String cacheName, @Nullable String schemaName)
{
+        boolean escape = false;
+
         String res = schemaName;
 
         if (res == null) {
@@ -282,6 +283,13 @@ public class QueryUtils {
             // SQL synthax perspective. We do not want node to fail on startup due to this.
             escape = true;
         }
+        else {
+            if (res.startsWith("\"") && res.endsWith("\"")) {
+                res = res.substring(1, res.length() - 1);
+
+                escape = true;
+            }
+        }
 
         if (!escape)
             res = normalizeObjectName(res, false);
@@ -308,7 +316,7 @@ public class QueryUtils {
      * Normalize object name.
      *
      * @param str String.
-     * @param replace Whether to perform replace.
+     * @param replace Whether to perform replace of special characters.
      * @return Escaped string.
      */
     public static @Nullable String normalizeObjectName(@Nullable String str, boolean replace)
{

http://git-wip-us.apache.org/repos/asf/ignite/blob/b7f20211/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
index 4672290..3d994c2 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java
@@ -160,12 +160,12 @@ public class IgniteSqlSchemaIndexingTest extends GridCommonAbstractTest
{
             .setSqlEscapeAll(true);
 
         final CacheConfiguration<Integer, Fact> cfgEsc = cacheConfig("escapedSchema",
true, Integer.class, Fact.class)
-            .setSqlSchema("SchemaName2")
+            .setSqlSchema("\"SchemaName2\"")
             .setSqlEscapeAll(true);
 
-        escapeCheckSchemaName(ignite(0).createCache(cfg), log, cfg.getSqlSchema());
+        escapeCheckSchemaName(ignite(0).createCache(cfg), log, cfg.getSqlSchema(), false);
 
-        escapeCheckSchemaName(ignite(0).createCache(cfgEsc), log, "SchemaName2");
+        escapeCheckSchemaName(ignite(0).createCache(cfgEsc), log, "SchemaName2", true);
 
         ignite(0).destroyCache(cfg.getName());
         ignite(0).destroyCache(cfgEsc.getName());
@@ -175,9 +175,11 @@ public class IgniteSqlSchemaIndexingTest extends GridCommonAbstractTest
{
      * Executes query with and without escaped schema name.
      * @param cache cache for querying
      * @param log logger for assertThrows
-     * @param schemaName - schema name without quotes for testing
+     * @param schemaName Schema name without quotes for testing
+     * @param caseSensitive Whether schema name is case sensitive.
      */
-    private static void escapeCheckSchemaName(final IgniteCache<Integer, Fact> cache,
IgniteLogger log, String schemaName) {
+    private static void escapeCheckSchemaName(final IgniteCache<Integer, Fact> cache,
IgniteLogger log,
+        String schemaName, boolean caseSensitive) {
         final SqlFieldsQuery qryWrong = new SqlFieldsQuery("select f.id, f.name " +
             "from " + schemaName.toUpperCase() + ".Fact f");
 
@@ -186,12 +188,16 @@ public class IgniteSqlSchemaIndexingTest extends GridCommonAbstractTest
{
         GridTestUtils.assertThrows(log, new Callable<Object>() {
             @Override public Object call() throws Exception {
                 cache.query(qryWrong);
+
                 return null;
             }
         }, CacheException.class, "Failed to parse query");
 
+        if (caseSensitive)
+            schemaName = "\"" + schemaName + "\"";
+
         SqlFieldsQuery qryCorrect = new SqlFieldsQuery("select f.\"id\", f.\"name\" " +
-            "from \""+schemaName+"\".\"Fact\" f");
+            "from "+  schemaName + ".\"Fact\" f");
 
         for ( List<?> row : cache.query(qryCorrect)) {
             assertEquals(2, row.size());

http://git-wip-us.apache.org/repos/asf/ignite/blob/b7f20211/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
index 6b984bf..9b5c17a 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java
@@ -1125,14 +1125,12 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest
{
     /**
      */
     public void testSchemaQuoted() {
-        assert false; // TODO test hangs
         doTestSchemaName("\"ppAf\"");
     }
 
     /**
      */
     public void testSchemaQuotedUpper() {
-        assert false; // TODO test hangs
         doTestSchemaName("\"PPAF\"");
     }
 


Mime
View raw message