IGNITE-10356: JDBC: fixed metadata returned for Date and Decimal types. This closes #5454.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d045b842 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d045b842 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d045b842 Branch: refs/heads/ignite-10044 Commit: d045b842931f0adc2bd409936c1ba0251bf1ea88 Parents: 24a50e1 Author: Ray <ray...@cisco.com> Authored: Thu Dec 6 12:08:22 2018 +0300 Committer: devozerov <voze...@gridgain.com> Committed: Thu Dec 6 12:08:22 2018 +0300 ---------------------------------------------------------------------- .../internal/jdbc2/JdbcMetadataSelfTest.java | 72 +++++++++++++++++++- .../ignite/jdbc/JdbcMetadataSelfTest.java | 69 ++++++++++++++++++- .../jdbc/thin/JdbcThinMetadataSelfTest.java | 50 ++++++++++++-- .../apache/ignite/internal/jdbc/JdbcUtils.java | 11 ++- .../internal/jdbc/thin/JdbcThinUtils.java | 11 ++- .../apache/ignite/internal/jdbc2/JdbcUtils.java | 7 +- 6 files changed, 207 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/d045b842/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java index 4c127b6..b18e4d5 100755 --- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcMetadataSelfTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.jdbc2; import java.io.Serializable; +import java.math.BigDecimal; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; @@ -28,6 +29,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; +import java.sql.Date; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -53,6 +55,8 @@ import org.jetbrains.annotations.NotNull; import static java.sql.Types.INTEGER; import static java.sql.Types.VARCHAR; +import static java.sql.Types.DECIMAL; +import static java.sql.Types.DATE; import static org.apache.ignite.IgniteJdbcDriver.CFG_URL_PREFIX; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; import static org.apache.ignite.cache.CacheMode.PARTITIONED; @@ -90,7 +94,10 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest { .setNotNullFields(new HashSet<>(Arrays.asList("age", "name"))) )), cacheConfiguration("org").setQueryEntities(Arrays.asList( - new QueryEntity(AffinityKey.class, Organization.class)))); + new QueryEntity(AffinityKey.class, Organization.class))), + + cacheConfiguration("metaTest").setQueryEntities(Arrays.asList( + new QueryEntity(AffinityKey.class, MetaTest.class)))); TcpDiscoverySpi disco = new TcpDiscoverySpi(); @@ -172,6 +179,40 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ + public void testDecimalAndDateTypeMetaData() throws Exception { + try (Connection conn = DriverManager.getConnection(BASE_URL)) { + Statement stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery( + "select t.decimal, t.date from \"metaTest\".MetaTest as t"); + + assert rs != null; + + ResultSetMetaData meta = rs.getMetaData(); + + assert meta != null; + + assert meta.getColumnCount() == 2; + + assert "METATEST".equalsIgnoreCase(meta.getTableName(1)); + assert "DECIMAL".equalsIgnoreCase(meta.getColumnName(1)); + assert "DECIMAL".equalsIgnoreCase(meta.getColumnLabel(1)); + assert meta.getColumnType(1) == DECIMAL; + assert "DECIMAL".equals(meta.getColumnTypeName(1)); + assert "java.math.BigDecimal".equals(meta.getColumnClassName(1)); + + assert "METATEST".equalsIgnoreCase(meta.getTableName(2)); + assert "DATE".equalsIgnoreCase(meta.getColumnName(2)); + assert "DATE".equalsIgnoreCase(meta.getColumnLabel(2)); + assert meta.getColumnType(2) == DATE; + assert "DATE".equals(meta.getColumnTypeName(2)); + assert "java.sql.Date".equals(meta.getColumnClassName(2)); + } + } + + /** + * @throws Exception If failed. + */ public void testGetTables() throws Exception { try (Connection conn = DriverManager.getConnection(BASE_URL)) { DatabaseMetaData meta = conn.getMetaData(); @@ -455,7 +496,7 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest { try (Connection conn = DriverManager.getConnection(BASE_URL)) { ResultSet rs = conn.getMetaData().getSchemas(); - Set<String> expectedSchemas = new HashSet<>(Arrays.asList("pers", "org")); + Set<String> expectedSchemas = new HashSet<>(Arrays.asList("pers", "org", "metaTest")); Set<String> schemas = new HashSet<>(); @@ -541,4 +582,31 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest { this.name = name; } } + + /** + * Meta Test. + */ + private static class MetaTest implements Serializable { + /** ID. */ + @QuerySqlField + private final int id; + + /** Date. */ + @QuerySqlField + private final Date date; + + /** decimal. */ + @QuerySqlField + private final BigDecimal decimal; + + /** + * @param id ID. + * @param date Date. + */ + private MetaTest(int id, Date date, BigDecimal decimal) { + this.id = id; + this.date = date; + this.decimal = decimal; + } + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/d045b842/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java index 87c1202..0613de7 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java @@ -18,12 +18,14 @@ package org.apache.ignite.jdbc; import java.io.Serializable; +import java.math.BigDecimal; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; +import java.sql.Date; import java.util.ArrayList; import java.util.Collection; import org.apache.ignite.IgniteCache; @@ -40,8 +42,10 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import static java.sql.Types.INTEGER; -import static java.sql.Types.OTHER; import static java.sql.Types.VARCHAR; +import static java.sql.Types.DECIMAL; +import static java.sql.Types.OTHER; +import static java.sql.Types.DATE; import static org.apache.ignite.cache.CacheMode.PARTITIONED; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; @@ -103,6 +107,8 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest { personCache.put(new AffinityKey<>("p1", "o1"), new Person("John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person("Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person("Mike Green", 40, 2)); + + jcache(grid(0), cacheConfiguration(), "metaTest", AffinityKey.class, MetaTest.class); } /** @@ -140,6 +146,40 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ + public void testDecimalAndDateTypeMetaData() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + Statement stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery( + "select t.decimal, t.date from \"metaTest\".MetaTest as t"); + + assert rs != null; + + ResultSetMetaData meta = rs.getMetaData(); + + assert meta != null; + + assert meta.getColumnCount() == 2; + + assert "METATEST".equalsIgnoreCase(meta.getTableName(1)); + assert "DECIMAL".equalsIgnoreCase(meta.getColumnName(1)); + assert "DECIMAL".equalsIgnoreCase(meta.getColumnLabel(1)); + assert meta.getColumnType(1) == DECIMAL; + assert "DECIMAL".equals(meta.getColumnTypeName(1)); + assert "java.math.BigDecimal".equals(meta.getColumnClassName(1)); + + assert "METATEST".equalsIgnoreCase(meta.getTableName(2)); + assert "DATE".equalsIgnoreCase(meta.getColumnName(2)); + assert "DATE".equalsIgnoreCase(meta.getColumnLabel(2)); + assert meta.getColumnType(2) == DATE; + assert "DATE".equals(meta.getColumnTypeName(2)); + assert "java.sql.Date".equals(meta.getColumnClassName(2)); + } + } + + /** + * @throws Exception If failed. + */ public void testGetTables() throws Exception { try (Connection conn = DriverManager.getConnection(URL)) { DatabaseMetaData meta = conn.getMetaData(); @@ -337,4 +377,31 @@ public class JdbcMetadataSelfTest extends GridCommonAbstractTest { this.name = name; } } + + /** + * Meta Test. + */ + private static class MetaTest implements Serializable { + /** ID. */ + @QuerySqlField + private final int id; + + /** Date. */ + @QuerySqlField + private final Date date; + + /** decimal. */ + @QuerySqlField + private final BigDecimal decimal; + + /** + * @param id ID. + * @param date Date. + */ + private MetaTest(int id, Date date, BigDecimal decimal) { + this.id = id; + this.date = date; + this.decimal = decimal; + } + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/d045b842/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java index 9759965..df67666 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java @@ -53,8 +53,10 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import static java.sql.Types.INTEGER; -import static java.sql.Types.OTHER; import static java.sql.Types.VARCHAR; +import static java.sql.Types.DECIMAL; +import static java.sql.Types.DATE; +import static java.sql.Types.OTHER; import static org.apache.ignite.cache.CacheMode.PARTITIONED; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; @@ -158,6 +160,7 @@ public class JdbcThinMetadataSelfTest extends JdbcThinAbstractSelfTest { stmt.execute("CREATE INDEX IDX ON TEST (ID ASC)"); stmt.execute("CREATE TABLE TEST_DECIMAL_COLUMN (ID INT primary key, DEC_COL DECIMAL(8, 3))"); stmt.execute("CREATE TABLE TEST_DECIMAL_COLUMN_PRECISION (ID INT primary key, DEC_COL DECIMAL(8))"); + stmt.execute("CREATE TABLE TEST_DECIMAL_DATE_COLUMN_META (ID INT primary key, DEC_COL DECIMAL(8), DATE_COL DATE)"); } } @@ -200,6 +203,40 @@ public class JdbcThinMetadataSelfTest extends JdbcThinAbstractSelfTest { /** * @throws Exception If failed. */ + public void testDecimalAndDateTypeMetaData() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + Statement stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery( + "select t.dec_col, t.date_col from TEST_DECIMAL_DATE_COLUMN_META as t"); + + assert rs != null; + + ResultSetMetaData meta = rs.getMetaData(); + + assert meta != null; + + assert meta.getColumnCount() == 2; + + assert "TEST_DECIMAL_DATE_COLUMN_META".equalsIgnoreCase(meta.getTableName(1)); + assert "DEC_COL".equalsIgnoreCase(meta.getColumnName(1)); + assert "DEC_COL".equalsIgnoreCase(meta.getColumnLabel(1)); + assert meta.getColumnType(1) == DECIMAL; + assert "DECIMAL".equals(meta.getColumnTypeName(1)); + assert "java.math.BigDecimal".equals(meta.getColumnClassName(1)); + + assert "TEST_DECIMAL_DATE_COLUMN_META".equalsIgnoreCase(meta.getTableName(2)); + assert "DATE_COL".equalsIgnoreCase(meta.getColumnName(2)); + assert "DATE_COL".equalsIgnoreCase(meta.getColumnLabel(2)); + assert meta.getColumnType(2) == DATE; + assert "DATE".equals(meta.getColumnTypeName(2)); + assert "java.sql.Date".equals(meta.getColumnClassName(2)); + } + } + + /** + * @throws Exception If failed. + */ public void testGetTables() throws Exception { try (Connection conn = DriverManager.getConnection(URL)) { DatabaseMetaData meta = conn.getMetaData(); @@ -261,7 +298,8 @@ public class JdbcThinMetadataSelfTest extends JdbcThinAbstractSelfTest { "PUBLIC.TEST", "PUBLIC.Quoted", "PUBLIC.TEST_DECIMAL_COLUMN", - "PUBLIC.TEST_DECIMAL_COLUMN_PRECISION")); + "PUBLIC.TEST_DECIMAL_COLUMN_PRECISION", + "PUBLIC.TEST_DECIMAL_DATE_COLUMN_META")); Set<String> actualTbls = new HashSet<>(expectedTbls.size()); @@ -413,7 +451,10 @@ public class JdbcThinMetadataSelfTest extends JdbcThinAbstractSelfTest { "PUBLIC.TEST_DECIMAL_COLUMN.ID.null", "PUBLIC.TEST_DECIMAL_COLUMN.DEC_COL.null.8.3", "PUBLIC.TEST_DECIMAL_COLUMN_PRECISION.ID.null", - "PUBLIC.TEST_DECIMAL_COLUMN_PRECISION.DEC_COL.null.8" + "PUBLIC.TEST_DECIMAL_COLUMN_PRECISION.DEC_COL.null.8", + "PUBLIC.TEST_DECIMAL_DATE_COLUMN_META.ID.null", + "PUBLIC.TEST_DECIMAL_DATE_COLUMN_META.DEC_COL.null.8", + "PUBLIC.TEST_DECIMAL_DATE_COLUMN_META.DATE_COL.null" )); Set<String> actualCols = new HashSet<>(expectedCols.size()); @@ -566,7 +607,8 @@ public class JdbcThinMetadataSelfTest extends JdbcThinAbstractSelfTest { "PUBLIC.TEST.PK_PUBLIC_TEST.NAME", "PUBLIC.Quoted.PK_PUBLIC_Quoted.Id", "PUBLIC.TEST_DECIMAL_COLUMN.ID.ID", - "PUBLIC.TEST_DECIMAL_COLUMN_PRECISION.ID.ID")); + "PUBLIC.TEST_DECIMAL_COLUMN_PRECISION.ID.ID", + "PUBLIC.TEST_DECIMAL_DATE_COLUMN_META.ID.ID")); Set<String> actualPks = new HashSet<>(expectedPks.size()); http://git-wip-us.apache.org/repos/asf/ignite/blob/d045b842/modules/core/src/main/java/org/apache/ignite/internal/jdbc/JdbcUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/JdbcUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/JdbcUtils.java index 77ef267..7bb1d8b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/JdbcUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/JdbcUtils.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.jdbc; +import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; @@ -44,7 +45,7 @@ import static java.sql.Types.TIME; import static java.sql.Types.TIMESTAMP; import static java.sql.Types.TINYINT; import static java.sql.Types.VARCHAR; - +import static java.sql.Types.DECIMAL; /** * Utility methods for JDBC driver. * @@ -189,8 +190,10 @@ class JdbcUtils { return TIME; else if (Timestamp.class.getName().equals(cls)) return TIMESTAMP; - else if (Date.class.getName().equals(cls)) + else if (Date.class.getName().equals(cls) || java.sql.Date.class.getName().equals(cls)) return DATE; + else if (BigDecimal.class.getName().equals(cls)) + return DECIMAL; else return OTHER; } @@ -224,8 +227,10 @@ class JdbcUtils { return "TIME"; else if (Timestamp.class.getName().equals(cls)) return "TIMESTAMP"; - else if (Date.class.getName().equals(cls)) + else if (Date.class.getName().equals(cls) || java.sql.Date.class.getName().equals(cls)) return "DATE"; + else if (BigDecimal.class.getName().equals(cls)) + return "DECIMAL"; else return "OTHER"; } http://git-wip-us.apache.org/repos/asf/ignite/blob/d045b842/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java index f896e7f..c129370 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinUtils.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.jdbc.thin; +import java.math.BigDecimal; import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; @@ -35,6 +36,8 @@ import static java.sql.Types.TIME; import static java.sql.Types.TIMESTAMP; import static java.sql.Types.TINYINT; import static java.sql.Types.VARCHAR; +import static java.sql.Types.DECIMAL; + import static org.apache.ignite.internal.jdbc.thin.ConnectionPropertiesImpl.PROP_PREFIX; /** @@ -79,8 +82,10 @@ public class JdbcThinUtils { return TIME; else if (Timestamp.class.getName().equals(cls)) return TIMESTAMP; - else if (Date.class.getName().equals(cls)) + else if (Date.class.getName().equals(cls) || java.sql.Date.class.getName().equals(cls)) return DATE; + else if (BigDecimal.class.getName().equals(cls)) + return DECIMAL; else return OTHER; } @@ -114,8 +119,10 @@ public class JdbcThinUtils { return "TIME"; else if (Timestamp.class.getName().equals(cls)) return "TIMESTAMP"; - else if (Date.class.getName().equals(cls)) + else if (Date.class.getName().equals(cls) || java.sql.Date.class.getName().equals(cls)) return "DATE"; + else if (BigDecimal.class.getName().equals(cls)) + return "DECIMAL"; else return "OTHER"; } http://git-wip-us.apache.org/repos/asf/ignite/blob/d045b842/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcUtils.java index cda6ba0..80881d7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcUtils.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.jdbc2; +import java.math.BigDecimal; import java.net.URL; import java.sql.SQLException; import java.sql.Time; @@ -41,7 +42,7 @@ import static java.sql.Types.TIME; import static java.sql.Types.TIMESTAMP; import static java.sql.Types.TINYINT; import static java.sql.Types.VARCHAR; - +import static java.sql.Types.DECIMAL; /** * Utility methods for JDBC driver. */ @@ -77,6 +78,8 @@ public class JdbcUtils { return TIMESTAMP; else if (Date.class.getName().equals(cls) || java.sql.Date.class.getName().equals(cls)) return DATE; + else if (BigDecimal.class.getName().equals(cls)) + return DECIMAL; else return OTHER; } @@ -112,6 +115,8 @@ public class JdbcUtils { return "TIMESTAMP"; else if (Date.class.getName().equals(cls) || java.sql.Date.class.getName().equals(cls)) return "DATE"; + else if (BigDecimal.class.getName().equals(cls)) + return "DECIMAL"; else return "OTHER"; }