ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [34/50] [abbrv] ignite git commit: IGNITE-4511: SQL: set default index type to "SORTED". This closes #1513.
Date Thu, 02 Mar 2017 11:31:11 GMT
IGNITE-4511: SQL: set default index type to "SORTED". This closes #1513.


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

Branch: refs/heads/ignite-4565-ddl
Commit: 1c9b02462f38cda8fabfbc84aa6c7aae65c8d33d
Parents: f2328a4
Author: Andrey V. Mashenkov <andrey.mashenkov@gmail.com>
Authored: Fri Feb 17 14:33:40 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Fri Feb 17 14:33:40 2017 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cache/QueryEntity.java    |  4 +-
 .../org/apache/ignite/cache/QueryIndex.java     | 25 ++++-
 .../processors/query/GridQueryProcessor.java    | 15 ++-
 .../cache/IgniteCacheAbstractQuerySelfTest.java | 97 ++++++++++++++++++++
 4 files changed, 130 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9b0246/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
index 5a3671b..48cdae5 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
@@ -190,6 +190,9 @@ public class QueryEntity implements Serializable {
                 if (idx.getName() == null)
                     idx.setName(defaultIndexName(idx));
 
+                if (idx.getIndexType() == null)
+                    throw new IllegalArgumentException("Index type is not set " + idx.getName());
+
                 if (!this.idxs.containsKey(idx.getName()))
                     this.idxs.put(idx.getName(), idx);
                 else
@@ -198,7 +201,6 @@ public class QueryEntity implements Serializable {
         }
     }
 
-
     /**
      * Gets table name for this query entity.
      *

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9b0246/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
index af11999..53f9e4c 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
@@ -31,6 +31,9 @@ public class QueryIndex implements Serializable {
     /** */
     private static final long serialVersionUID = 0L;
 
+    /** */
+    private static final QueryIndexType DFLT_IDX_TYP = QueryIndexType.SORTED;
+
     /** Index name. */
     private String name;
 
@@ -38,7 +41,7 @@ public class QueryIndex implements Serializable {
     private LinkedHashMap<String, Boolean> fields;
 
     /** */
-    private QueryIndexType type;
+    private QueryIndexType type = DFLT_IDX_TYP;
 
     /**
      * Creates an empty index. Should be populated via setters.
@@ -163,9 +166,12 @@ public class QueryIndex implements Serializable {
      * Sets index name.
      *
      * @param name Index name.
+     * @return {@code this} for chaining.
      */
-    public void setName(String name) {
+    public QueryIndex setName(String name) {
         this.name = name;
+
+        return this;
     }
 
     /**
@@ -181,9 +187,12 @@ public class QueryIndex implements Serializable {
      * Sets fields included in the index.
      *
      * @param fields Collection of index fields.
+     * @return {@code this} for chaining.
      */
-    public void setFields(LinkedHashMap<String, Boolean> fields) {
+    public QueryIndex setFields(LinkedHashMap<String, Boolean> fields) {
         this.fields = fields;
+
+        return this;
     }
 
     /**
@@ -199,12 +208,15 @@ public class QueryIndex implements Serializable {
      *
      * @param fields Collection of fields.
      * @param asc Ascending flag.
+     * @return {@code this} for chaining.
      */
-    public void setFieldNames(Collection<String> fields, boolean asc) {
+    public QueryIndex setFieldNames(Collection<String> fields, boolean asc) {
         this.fields = new LinkedHashMap<>();
 
         for (String field : fields)
             this.fields.put(field, asc);
+
+        return this;
     }
 
     /**
@@ -220,8 +232,11 @@ public class QueryIndex implements Serializable {
      * Sets index type.
      *
      * @param type Index type.
+     * @return {@code this} for chaining.
      */
-    public void setIndexType(QueryIndexType type) {
+    public QueryIndex setIndexType(QueryIndexType type) {
         this.type = type;
+
+        return this;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9b0246/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 0ff6d8b..24ccb05 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
@@ -1566,8 +1566,10 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 if (idxName == null)
                     idxName = QueryEntity.defaultIndexName(idx);
 
-                if (idx.getIndexType() == QueryIndexType.SORTED || idx.getIndexType() ==
QueryIndexType.GEOSPATIAL) {
-                    d.addIndex(idxName, idx.getIndexType() == QueryIndexType.SORTED ? SORTED
: GEO_SPATIAL);
+                QueryIndexType idxTyp = idx.getIndexType();
+
+                if (idxTyp == QueryIndexType.SORTED || idxTyp == QueryIndexType.GEOSPATIAL)
{
+                    d.addIndex(idxName, idxTyp == QueryIndexType.SORTED ? SORTED : GEO_SPATIAL);
 
                     int i = 0;
 
@@ -1583,9 +1585,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                         d.addFieldToIndex(idxName, field, i++, !asc);
                     }
                 }
-                else {
-                    assert idx.getIndexType() == QueryIndexType.FULLTEXT;
-
+                else if (idxTyp == QueryIndexType.FULLTEXT){
                     for (String field : idx.getFields().keySet()) {
                         String alias = aliases.get(field);
 
@@ -1595,6 +1595,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                         d.addFieldToTextIndex(field);
                     }
                 }
+                else if (idxTyp != null)
+                    throw new IllegalArgumentException("Unsupported index type [idx=" + idx.getName()
+
+                        ", typ=" + idxTyp + ']');
+                else
+                    throw new IllegalArgumentException("Index type is not set: " + idx.getName());
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c9b0246/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
index 81c28a3..2b240e9 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
@@ -207,6 +207,21 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
 
                 entityList.add(qryEntity);
 
+                qryEntity = new QueryEntity();
+
+                qryEntity.setKeyType(Integer.class.getName());
+                qryEntity.setValueType(ObjectValue2.class.getName());
+
+                qryEntity.addQueryField("strVal", String.class.getName(), null);
+
+                final QueryIndex strIdx = new QueryIndex(); // Default index type
+
+                strIdx.setFieldNames(Collections.singletonList("strVal"), true);
+
+                qryEntity.setIndexes(Arrays.asList(strIdx));
+
+                entityList.add(qryEntity);
+
                 cc.setQueryEntities(entityList);
 
                 if (cacheMode() != CacheMode.LOCAL)
@@ -759,6 +774,40 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
      *
      * @throws Exception In case of error.
      */
+    public void testObjectWithString() throws Exception {
+        IgniteCache<Integer, ObjectValue2> cache = ignite().cache(null);
+
+        cache.put(1, new ObjectValue2("value 1"));
+        cache.put(2, new ObjectValue2("value 2"));
+        cache.put(3, new ObjectValue2("value 3"));
+
+        QueryCursor<Cache.Entry<Integer, ObjectValue2>> qry
+            = cache.query(new SqlQuery<Integer, ObjectValue2>(ObjectValue2.class, "strVal
like ?").setArgs("value%"));
+
+        int expCnt = 3;
+
+        List<Cache.Entry<Integer, ObjectValue2>> results = qry.getAll();
+
+        assertEquals(expCnt, results.size());
+
+        qry = cache.query(new SqlQuery<Integer, ObjectValue2>(ObjectValue2.class, "strVal
> ?").setArgs("value 1"));
+
+        results = qry.getAll();
+
+        assertEquals(expCnt - 1, results.size());
+
+        qry = cache.query(new TextQuery<Integer, ObjectValue2>(ObjectValue2.class,
"value"));
+
+        results = qry.getAll();
+
+        assertEquals(0, results.size()); //Should fail for FULL_TEXT index, but SORTED
+    }
+
+    /**
+     * JUnit.
+     *
+     * @throws Exception In case of error.
+     */
     public void testEnumObjectQuery() throws Exception {
         final IgniteCache<Long, EnumObject> cache = ignite().cache(null);
 
@@ -2061,6 +2110,54 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
     }
 
     /**
+     * Another test value object.
+     */
+    private static class ObjectValue2 {
+        /** Value. */
+        private String strVal;
+
+        /**
+         * @param strVal String value.
+         */
+        ObjectValue2(String strVal) {
+            this.strVal = strVal;
+        }
+
+        /**
+         * Gets value.
+         *
+         * @return Value.
+         */
+        public String value() {
+            return strVal;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            ObjectValue2 other = (ObjectValue2)o;
+
+            return strVal == null ? other.strVal == null : strVal.equals(other.strVal);
+
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return strVal != null ? strVal.hashCode() : 0;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(ObjectValue2.class, this);
+        }
+    }
+
+    /**
      * Empty test object.
      */
     @SuppressWarnings("UnusedDeclaration")


Mime
View raw message