ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [04/28] incubator-ignite git commit: ignite-930 - fixed
Date Wed, 27 May 2015 15:07:37 GMT
ignite-930 - fixed


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

Branch: refs/heads/ignite-709_2
Commit: f811f51680928a5e55998ac70f179580b6a5103a
Parents: 7680513
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Thu May 21 11:31:17 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Thu May 21 11:31:17 2015 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryIndexing.java     | 16 ++++++
 .../processors/query/GridQueryProcessor.java    | 52 +++++++-------------
 .../query/h2/GridH2IndexingGeoSelfTest.java     | 20 +++++++-
 .../processors/query/h2/IgniteH2Indexing.java   | 17 +++++++
 .../query/h2/sql/GridSqlOperationType.java      |  2 +-
 .../local/IgniteCacheLocalQuerySelfTest.java    |  6 +++
 6 files changed, 77 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f811f516/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index b1c3970..0bb820d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -149,6 +149,22 @@ public interface GridQueryIndexing {
     public void unregisterCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException;
 
     /**
+     * Checks if the given class can be mapped to a simple SQL type.
+     *
+     * @param cls Class.
+     * @return {@code true} If can.
+     */
+    public boolean isSqlType(Class<?> cls);
+
+    /**
+     * Checks if the given class is GEOMETRY.
+     *
+     * @param cls Class.
+     * @return {@code true} If this is geometry.
+     */
+    public boolean isGeometryClass(Class<?> cls);
+
+    /**
      * Registers type if it was not known before or updates it otherwise.
      *
      * @param spaceName Space name.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f811f516/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 7a3cb68..cd4d543 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
@@ -936,10 +936,19 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param parent Parent in case of embeddable.
      * @throws IgniteCheckedException In case of error.
      */
-    static void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor
type,
+    private void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor
type,
         @Nullable ClassProperty parent) throws IgniteCheckedException {
-        if (U.isJdk(cls))
+        if (U.isJdk(cls) || idx.isGeometryClass(cls)) {
+            if (parent == null && !key && idx.isSqlType(cls) ) { // We have
to index primitive _val.
+                String idxName = "_val_idx";
+
+                type.addIndex(idxName, idx.isGeometryClass(cls) ? GEO_SPATIAL : SORTED);
+
+                type.addFieldToIndex(idxName, "_VAL", 0, false);
+            }
+
             return;
+        }
 
         if (parent != null && parent.knowsClass(cls))
             throw new IgniteCheckedException("Recursive reference found in type: " + cls.getName());
@@ -1011,7 +1020,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param desc Class description.
      * @throws IgniteCheckedException In case of error.
      */
-    static void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn,
+    private void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn,
         Class<?> cls, ClassProperty prop, TypeDescriptor desc) throws IgniteCheckedException
{
         if (sqlAnn != null) {
             processAnnotationsInClass(key, cls, desc, prop);
@@ -1022,7 +1031,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             if (sqlAnn.index()) {
                 String idxName = prop.name() + "_idx";
 
-                desc.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+                desc.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
                 desc.addFieldToIndex(idxName, prop.name(), 0, sqlAnn.descending());
             }
@@ -1049,7 +1058,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param d Type descriptor.
      * @throws IgniteCheckedException If failed.
      */
-    static void processClassMeta(CacheTypeMetadata meta, TypeDescriptor d)
+    private void processClassMeta(CacheTypeMetadata meta, TypeDescriptor d)
         throws IgniteCheckedException {
         Class<?> keyCls = d.keyClass();
         Class<?> valCls = d.valueClass();
@@ -1064,7 +1073,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, false);
         }
@@ -1076,7 +1085,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, true);
         }
@@ -1136,7 +1145,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, false);
         }
@@ -1148,7 +1157,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
             String idxName = prop.name() + "_idx";
 
-            d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+            d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
 
             d.addFieldToIndex(idxName, prop.name(), 0, true);
         }
@@ -1321,31 +1330,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * @param cls Field type.
-     * @return {@code True} if given type is a spatial geometry type based on {@code com.vividsolutions.jts}
library.
-     * @throws IgniteCheckedException If failed.
-     */
-    private static boolean isGeometryClass(Class<?> cls) throws IgniteCheckedException
{ // TODO optimize
-        Class<?> dataTypeCls;
-
-        try {
-            dataTypeCls = Class.forName("org.h2.value.DataType");
-        }
-        catch (ClassNotFoundException ignored) {
-            return false; // H2 is not in classpath.
-        }
-
-        try {
-            Method method = dataTypeCls.getMethod("isGeometryClass", Class.class);
-
-            return (Boolean)method.invoke(null, cls);
-        }
-        catch (Exception e) {
-            throw new IgniteCheckedException("Failed to invoke 'org.h2.value.DataType.isGeometryClass'
method.", e);
-        }
-    }
-
-    /**
      *
      */
     private abstract static class Property {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f811f516/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
index 8566960..b80944c 100644
--- a/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
+++ b/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
@@ -57,13 +57,31 @@ public class GridH2IndexingGeoSelfTest extends GridCacheAbstractSelfTest
{
     /** {@inheritDoc} */
     @Override protected Class<?>[] indexedTypes() {
         return new Class<?>[]{
-            Integer.class, EnemyCamp.class
+            Integer.class, EnemyCamp.class,
+            Long.class, Geometry.class // Geometry must be indexed here.
         };
     }
 
     /**
      * @throws Exception If failed.
      */
+    public void testPrimitiveGeometry() throws Exception {
+        IgniteCache<Long, Geometry> cache = grid(0).cache(null);
+
+        WKTReader r = new WKTReader();
+
+        for (long i = 0; i < 100; i++)
+            cache.put(i, r.read("POINT(" + i + " " + i + ")"));
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("explain select _key
from Geometry where _val && ?")
+            .setArgs(r.read("POLYGON((5 70, 5 80, 30 80, 30 70, 5 70))")).setLocal(true)).getAll();
+
+        assertTrue("__ explain: " + res, res.get(0).get(0).toString().contains("_val_idx"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     @SuppressWarnings("unchecked")
     public void testGeo() throws Exception {
         IgniteCache<Integer, EnemyCamp> cache = grid(0).cache(null);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f811f516/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 975378c..200da77 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -1412,6 +1412,23 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         }
     }
 
+    /** {@inheritDoc} */
+    @Override public boolean isSqlType(Class<?> cls) {
+        switch (DBTypeEnum.fromClass(cls)) {
+            case OTHER:
+            case ARRAY:
+                return false;
+
+            default:
+                return true;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isGeometryClass(Class<?> cls) {
+        return DataType.isGeometryClass(cls);
+    }
+
     /**
      * Enum that helps to map java types to database types.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f811f516/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
index 7aefbec..a071e73 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperationType.java
@@ -131,7 +131,7 @@ public enum GridSqlOperationType {
         @Override public String getSql(GridSqlOperation operation) {
             assert operation.opType().childrenCnt == 2;
 
-            return "(INTERSECTS(" + operation.child(0) + ", " + operation.child(1) + "))";
+            return "(INTERSECTS(" + operation.child(0).getSQL() + ", " + operation.child(1).getSQL()
+ "))";
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f811f516/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
index c489d35..48dc6f2 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQuerySelfTest.java
@@ -78,5 +78,11 @@ public class IgniteCacheLocalQuerySelfTest extends IgniteCacheAbstractQuerySelfT
         assert iter.next() != null;
         assert iter.next() != null;
         assert !iter.hasNext();
+
+        // Test explain for primitive index.
+        List<List<?>> res = cache.query(new SqlFieldsQuery(
+            "explain select _key from String where _val > 'value1'").setLocal(true)).getAll();
+
+        assertTrue("__ explain: \n" + res, ((String)res.get(0).get(0)).contains("_val_idx"));
     }
 }


Mime
View raw message