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-5855: SQL: fixed BigInteger data type handling, This closes #2512.
Date Thu, 07 Sep 2017 11:25:22 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 88cfa73fd -> c6c7d905d


IGNITE-5855: SQL: fixed BigInteger data type handling, This closes #2512.


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

Branch: refs/heads/master
Commit: c6c7d905d6a1f7ce0a31967e881c4d9cccc5a129
Parents: 88cfa73
Author: Ilya Kasnacheev <ilya.kasnacheev@gmail.com>
Authored: Thu Sep 7 14:25:14 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Thu Sep 7 14:25:14 2017 +0300

----------------------------------------------------------------------
 .../processors/query/h2/IgniteH2Indexing.java   |   3 +
 .../query/h2/IgniteSqlBigIntegerKeyTest.java    | 163 +++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite.java          |   2 +
 3 files changed, 168 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c6c7d905/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 dff82d7..f4873a0 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
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.query.h2;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.math.BigInteger;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
@@ -509,6 +510,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         try {
             if (obj == null)
                 stmt.setNull(idx, Types.VARCHAR);
+            else if (obj instanceof BigInteger)
+                stmt.setObject(idx, obj, Types.JAVA_OBJECT);
             else
                 stmt.setObject(idx, obj);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/c6c7d905/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlBigIntegerKeyTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlBigIntegerKeyTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlBigIntegerKeyTest.java
new file mode 100644
index 0000000..196f0e7
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/IgniteSqlBigIntegerKeyTest.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.h2;
+
+import java.math.BigInteger;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Ensures that BigInteger can be used as key
+ */
+public class IgniteSqlBigIntegerKeyTest extends GridCommonAbstractTest {
+    /** */
+    private static final String CACHE_NAME = "Mycache";
+
+    /** */
+    private static final String SELECT_BY_KEY_SQL = "select _val from STUDENT where _key=?";
+
+    /** */
+    private static final String SELECT_BY_ID_SQL = "select _val from STUDENT where id=?";
+
+    /** */
+    private static final Student VALUE_OBJ = new Student(BigInteger.valueOf(42), "John Doe");
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrid("server");
+
+        Ignite cli = startGrid(getConfiguration("client").setClientMode(true));
+
+        IgniteCache<Object, Object> cache = cli.getOrCreateCache(new CacheConfiguration<>()
+            .setIndexedTypes(BigInteger.class, Student.class)
+            .setName(CACHE_NAME));
+
+        cache.put(VALUE_OBJ.id, VALUE_OBJ);
+
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** */
+    private IgniteCache<Object, Object> getCache() {
+        return grid("client").cache(CACHE_NAME);
+    }
+
+    /** */
+    public void testBigIntegerKeyGet() {
+        IgniteCache<Object, Object> cache = getCache();
+
+        Object val = cache.get(BigInteger.valueOf(42));
+
+        assertNotNull(val);
+        assertTrue(val instanceof Student);
+        assertEquals(VALUE_OBJ, val);
+
+        val = cache.get(new BigInteger("42"));
+
+        assertNotNull(val);
+        assertTrue(val instanceof Student);
+        assertEquals(VALUE_OBJ, val);
+    }
+
+    /** */
+    public void testBigIntegerKeyQuery() {
+        IgniteCache<Object, Object> cache = getCache();
+
+        checkQuery(cache, SELECT_BY_KEY_SQL, BigInteger.valueOf(42));
+        checkQuery(cache, SELECT_BY_KEY_SQL, new BigInteger("42"));
+    }
+
+    /** */
+    public void testBigIntegerFieldQuery() {
+        IgniteCache<Object, Object> cache = getCache();
+
+        checkQuery(cache, SELECT_BY_ID_SQL, BigInteger.valueOf(42));
+        checkQuery(cache, SELECT_BY_ID_SQL, new BigInteger("42"));
+    }
+
+    /** */
+    private void checkQuery(IgniteCache<Object, Object> cache, String sql, Object arg)
{
+        SqlFieldsQuery qry = new SqlFieldsQuery(sql).setArgs(arg);
+
+        QueryCursor<List<?>> query = cache.query(qry);
+
+        List<List<?>> res = query.getAll();
+
+        assertEquals(1, res.size());
+
+        Object val = res.get(0).get(0);
+
+        assertNotNull(val);
+        assertTrue(val instanceof Student);
+        assertEquals(VALUE_OBJ, val);
+    }
+
+    /**
+     *
+     */
+    public static class Student {
+        /** */
+        @QuerySqlField(index=true)
+        BigInteger id;
+
+        /** */
+        @QuerySqlField
+        String name;
+
+        /**
+         * Constructor.
+         */
+        Student(BigInteger id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Student student = (Student)o;
+
+            if (!id.equals(student.id))
+                return false;
+            return name.equals(student.name);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int result = id.hashCode();
+            result = 31 * result + name.hashCode();
+            return result;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/c6c7d905/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
index 0c6253b..040d0af 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
@@ -122,6 +122,7 @@ import org.apache.ignite.internal.processors.cache.query.GridCacheQueryTransform
 import org.apache.ignite.internal.processors.cache.query.IgniteCacheQueryCacheDestroySelfTest;
 import org.apache.ignite.internal.processors.cache.query.IndexingSpiQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.query.IndexingSpiQueryTxSelfTest;
+import org.apache.ignite.internal.processors.query.h2.IgniteSqlBigIntegerKeyTest;
 import org.apache.ignite.internal.processors.query.IgniteQueryDedicatedPoolTest;
 import org.apache.ignite.internal.processors.query.IgniteSqlEntryCacheModeAgnosticTest;
 import org.apache.ignite.internal.processors.query.IgniteSqlKeyValueFieldsTest;
@@ -209,6 +210,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
         suite.addTestSuite(IgniteCacheCollocatedQuerySelfTest.class);
         suite.addTestSuite(IgniteCacheLargeResultSelfTest.class);
         suite.addTestSuite(GridCacheQueryInternalKeysSelfTest.class);
+        suite.addTestSuite(IgniteSqlBigIntegerKeyTest.class);
 
         suite.addTestSuite(IgniteCacheOffheapEvictQueryTest.class);
         suite.addTestSuite(IgniteCacheOffheapIndexScanTest.class);


Mime
View raw message