You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2017/10/02 07:52:31 UTC

ignite git commit: IGNITE-6286: SQL: fixed BigDecimal argument handling. This closes #2750.

Repository: ignite
Updated Branches:
  refs/heads/master 59ee8af5c -> 013d7dbf7


IGNITE-6286: SQL: fixed BigDecimal argument handling. This closes #2750.


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

Branch: refs/heads/master
Commit: 013d7dbf7811a1b8e207d6238aff67e43c28adad
Parents: 59ee8af
Author: Sergey Chernolyas <se...@gmail.com>
Authored: Mon Oct 2 10:52:21 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Mon Oct 2 10:52:21 2017 +0300

----------------------------------------------------------------------
 .../processors/query/h2/IgniteH2Indexing.java   |   3 +
 .../query/IgniteSqlParameterizedQueryTest.java  | 392 +++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite.java          |   3 +-
 3 files changed, 397 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/013d7dbf/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 9e6a1fa..fd7b9a8 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.BigDecimal;
 import java.math.BigInteger;
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -511,6 +512,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 stmt.setNull(idx, Types.VARCHAR);
             else if (obj instanceof BigInteger)
                 stmt.setObject(idx, obj, Types.JAVA_OBJECT);
+            else if (obj instanceof BigDecimal)
+                stmt.setObject(idx, obj, Types.DECIMAL);
             else
                 stmt.setObject(idx, obj);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/013d7dbf/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java
new file mode 100644
index 0000000..b5039cd
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlParameterizedQueryTest.java
@@ -0,0 +1,392 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
+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.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Test sql queries with parameters for all types.
+ * The test is fix  for issue 'IGNITE-6286'
+ *
+ * @author Sergey Chernolyas &amp;sergey_chernolyas@gmail.com&amp;
+ * @see <a href="https://issues.apache.org/jira/browse/IGNITE-6286">IGNITE-6286</a>
+ */
+public class IgniteSqlParameterizedQueryTest extends GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final String CACHE_BOOKMARK = "Bookmark";
+
+    /** */
+    private static final String NODE_CLIENT = "client";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration c = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        c.setDiscoverySpi(disco);
+
+        c.setCacheConfiguration(buildCacheConfiguration(CACHE_BOOKMARK));
+        if (gridName.equals(NODE_CLIENT))
+            c.setClientMode(true);
+
+        return c;
+    }
+
+    /**
+     * build cache configuration
+     * @param name cache name
+     * @return configuration
+     * @see CacheConfiguration
+     */
+    private CacheConfiguration buildCacheConfiguration(String name) {
+        CacheConfiguration ccfg = new CacheConfiguration(name);
+        ccfg.setIndexedTypes(String.class, Bookmark.class);
+        return ccfg;
+
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        startGrid(0);
+        startGrid(NODE_CLIENT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * method for create parametrized query and get first result
+     * @param field name of field
+     * @param val value
+     * @return fist searched object
+     * @see Bookmark
+     */
+    private Object columnValue(String field, Object val) {
+        IgniteCache<String, Bookmark> cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK);
+        SqlFieldsQuery qry = new SqlFieldsQuery("SELECT " + field + " from  Bookmark where " + field + " = ?");
+        qry.setArgs(val);
+
+        QueryCursor<List<?>> cursor = cache.query(qry);
+        List<List<?>> results = cursor.getAll();
+        assertEquals("Search by field '" + field +"' returns incorrect row count!",1, results.size());
+        List<?> row0 = results.get(0);
+        return row0.get(0);
+    }
+
+    /**
+     * testing parametrized query by field with supported type
+     * @throws Exception if any error occurs
+     */
+    public void testSupportedTypes() throws Exception {
+        IgniteCache<String, Bookmark> cache = grid(NODE_CLIENT).cache(CACHE_BOOKMARK);
+        Bookmark bookmark = new Bookmark();
+        bookmark.setId(UUID.randomUUID().toString());
+        bookmark.setStockCount(Integer.MAX_VALUE);
+        bookmark.setUrlPort(Short.MAX_VALUE);
+        bookmark.setUserId(Long.MAX_VALUE);
+        bookmark.setVisitRatio(Float.MAX_VALUE);
+        bookmark.setTaxPercentage(Double.MAX_VALUE);
+        bookmark.setFavourite(true);
+        bookmark.setDisplayMask(Byte.MAX_VALUE);
+        bookmark.setSerialNumber(UUID.randomUUID());
+        bookmark.setVisitCount(new BigInteger("1000000000000000"));
+        bookmark.setSiteWeight(new BigDecimal("1000000000000000.001"));
+        bookmark.setCreated(new Date());
+        cache.put(bookmark.id, bookmark);
+
+        assertEquals(bookmark.getId(), columnValue("id", bookmark.getId()));
+        assertEquals(bookmark.getStockCount(), columnValue("stockcount", bookmark.getStockCount()));
+        assertEquals(bookmark.getUrlPort(), columnValue("urlport", bookmark.getUrlPort()));
+        assertEquals(bookmark.getUserId(), columnValue("userid", bookmark.getUserId()));
+        assertEquals(bookmark.getVisitRatio(), columnValue("visitratio", bookmark.getVisitRatio()));
+        assertEquals(bookmark.getTaxPercentage(), columnValue("taxpercentage", bookmark.getTaxPercentage()));
+        assertEquals(bookmark.getFavourite(), columnValue("favourite", bookmark.getFavourite()));
+        assertEquals(bookmark.getDisplayMask(), columnValue("displaymask", bookmark.getDisplayMask()));
+        assertEquals(bookmark.getSerialNumber(), columnValue("serialnumber", bookmark.getSerialNumber()));
+        assertEquals(bookmark.getVisitCount(), columnValue("visitcount", bookmark.getVisitCount()));
+        assertEquals(bookmark.getSiteWeight(), columnValue("siteweight", bookmark.getSiteWeight()));
+        assertEquals(bookmark.getCreated(), columnValue("created", bookmark.getCreated()));
+    }
+
+    /**
+     * Object with all predefined SQL Data Types
+     * @see <a href="https://apacheignite.readme.io/docs/dml#section-advanced-configuration">SQL Data Types</a>
+     */
+    private static class Bookmark implements Serializable {
+        /** */
+        @QuerySqlField
+        private String id;
+
+        /** */
+        @QuerySqlField
+        private Integer stockCount;
+
+        /** */
+        @QuerySqlField
+        private Short urlPort;
+
+        /** */
+        @QuerySqlField
+        private Long userId;
+
+        /** */
+        @QuerySqlField
+        private Float visitRatio;
+
+        /** */
+        @QuerySqlField
+        private Double taxPercentage;
+
+        /** */
+        @QuerySqlField
+        private Boolean favourite;
+
+        /** */
+        @QuerySqlField
+        private Byte displayMask;
+
+        /** */
+        @QuerySqlField
+        private UUID serialNumber;
+
+        /** */
+        @QuerySqlField
+        private BigDecimal siteWeight;
+
+        /** */
+        @QuerySqlField
+        private BigInteger visitCount;
+
+        /** */
+        @QuerySqlField
+        private Date created;
+
+        /**
+         *
+         */
+        public String getId() {
+            return id;
+        }
+
+        /**
+         *
+         */
+        public void setId(String id) {
+            this.id = id;
+        }
+
+        /**
+         *
+         */
+        public Integer getStockCount() {
+            return stockCount;
+        }
+
+        /**
+         *
+         */
+        public void setStockCount(Integer stockCount) {
+            this.stockCount = stockCount;
+        }
+
+        /**
+         *
+         */
+        public Short getUrlPort() {
+            return urlPort;
+        }
+
+        /**
+         *
+         */
+        public void setUrlPort(Short urlPort) {
+            this.urlPort = urlPort;
+        }
+
+        /**
+         *
+         */
+        public Long getUserId() {
+            return userId;
+        }
+
+        /**
+         *
+         */
+        public void setUserId(Long userId) {
+            this.userId = userId;
+        }
+
+        /**
+         *
+         */
+        public Float getVisitRatio() {
+            return visitRatio;
+        }
+
+        /**
+         *
+         */
+        public void setVisitRatio(Float visitRatio) {
+            this.visitRatio = visitRatio;
+        }
+
+        /**
+         *
+         */
+        public Double getTaxPercentage() {
+            return taxPercentage;
+        }
+
+        /**
+         *
+         */
+        public void setTaxPercentage(Double taxPercentage) {
+            this.taxPercentage = taxPercentage;
+        }
+
+        /**
+         *
+         */
+        public Boolean getFavourite() {
+            return favourite;
+        }
+
+        /**
+         *
+         */
+        public void setFavourite(Boolean favourite) {
+            this.favourite = favourite;
+        }
+
+        /**
+         *
+         */
+        public Byte getDisplayMask() {
+            return displayMask;
+        }
+
+        /**
+         *
+         */
+        public void setDisplayMask(Byte displayMask) {
+            this.displayMask = displayMask;
+        }
+
+        /**
+         *
+         */
+        public UUID getSerialNumber() {
+            return serialNumber;
+        }
+
+        /**
+         *
+         */
+        public void setSerialNumber(UUID serialNumber) {
+            this.serialNumber = serialNumber;
+        }
+
+        /**
+         *
+         */
+        public BigDecimal getSiteWeight() {
+            return siteWeight;
+        }
+
+        /**
+         *
+         */
+        public void setSiteWeight(BigDecimal siteWeight) {
+            this.siteWeight = siteWeight;
+        }
+
+        /**
+         *
+         */
+        public BigInteger getVisitCount() {
+            return visitCount;
+        }
+
+        /**
+         *
+         */
+        public void setVisitCount(BigInteger visitCount) {
+            this.visitCount = visitCount;
+        }
+
+        /**
+         *
+         */
+        public Date getCreated() {
+            return created;
+        }
+
+        /**
+         *
+         */
+        public void setCreated(Date created) {
+            this.created = created;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+            Bookmark bookmark = (Bookmark)o;
+            return Objects.equals(id, bookmark.id);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(id);
+        }
+    }
+
+}
+
+

http://git-wip-us.apache.org/repos/asf/ignite/blob/013d7dbf/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 aaa8e57..c49649b 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
@@ -123,6 +123,7 @@ import org.apache.ignite.internal.processors.cache.query.IgniteCacheQueryCacheDe
 import org.apache.ignite.internal.processors.cache.query.IndexingSpiQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.query.IndexingSpiQueryTxSelfTest;
 import org.apache.ignite.internal.processors.client.ClientConnectorConfigurationValidationSelfTest;
+import org.apache.ignite.internal.processors.query.IgniteSqlParameterizedQueryTest;
 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;
@@ -336,8 +337,8 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
         suite.addTestSuite(IgniteSqlRoutingTest.class);
         suite.addTestSuite(IgniteSqlNotNullConstraintTest.class);
         suite.addTestSuite(LongIndexNameTest.class);
-
         suite.addTestSuite(GridCacheQuerySqlFieldInlineSizeSelfTest.class);
+        suite.addTestSuite(IgniteSqlParameterizedQueryTest.class);
 
         return suite;
     }