From a4420748aa14c534863659b61adfb8024fab8755 Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Wed, 13 Nov 2024 10:30:33 +0530 Subject: [PATCH 01/10] Fix CVEs about h2database dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a2dc8d37c01e4..f1cd78a10dffd 100644 --- a/pom.xml +++ b/pom.xml @@ -1180,7 +1180,7 @@ com.h2database h2 - 1.4.199 + 2.2.220 From 07d24ed86516157a1d7b7b53a311deaf63961deb Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Thu, 14 Nov 2024 09:50:17 +0530 Subject: [PATCH 02/10] Upgrad H2database to 1.4.200 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f1cd78a10dffd..9a523a8af3be1 100644 --- a/pom.xml +++ b/pom.xml @@ -1180,7 +1180,7 @@ com.h2database h2 - 2.2.220 + 1.4.200 From 2a60472ae3db30f6bffd9b4c05b2cafaee3e5443 Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Wed, 20 Nov 2024 14:49:10 +0530 Subject: [PATCH 03/10] Upgrade the H2db version to 2.2.220 and update the expected query syntax --- pom.xml | 3 ++- .../presto/tests/AbstractTestAggregations.java | 12 ++++++------ .../facebook/presto/tests/AbstractTestQueries.java | 4 ++-- .../com/facebook/presto/tests/H2QueryRunner.java | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 9a523a8af3be1..e1f9b18890ea1 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ 3.9.0 3.4.0 19.3.0.0 + 1.38 @@ -1180,7 +1181,7 @@ com.h2database h2 - 1.4.200 + 2.2.220 diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestAggregations.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestAggregations.java index 295952d923702..e9897a248ff28 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestAggregations.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestAggregations.java @@ -1276,14 +1276,14 @@ public void testOrderedAggregations() "WHERE orderkey IN (1, 2, 3, 4, 5) " + "GROUP BY GROUPING SETS ((), (orderpriority), (orderpriority, custkey))", "VALUES " + - "(NULL, NULL , ('F', 'O', 'O'))," + - "('5-LOW', NULL , ('F', 'O'))," + - "('1-URGENT', NULL , ('O'))," + + "(NULL, NULL , ARRAY['F', 'O', 'O'])," + + "('5-LOW', NULL , ARRAY['F', 'O'])," + + "('1-URGENT', NULL , ARRAY['O'])," + "('5-LOW', 370 , NULL)," + - "('5-LOW', 1234, ('F'))," + - "('5-LOW', 1369, ('O'))," + + "('5-LOW', 1234, ARRAY['F'])," + + "('5-LOW', 1369, ARRAY['O'])," + "('5-LOW', 445 , NULL)," + - "('1-URGENT', 781 , ('O'))"); + "('1-URGENT', 781 , ARRAY['O'])"); } /** diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java index 787d43f37279f..b3121b4d4be38 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java @@ -7061,10 +7061,10 @@ public void testArrayCumSum() // decimal sql = "select array_cum_sum(k) from (values (array[cast(5.1 as decimal(38, 1)), 6, 0]), (ARRAY[]), (CAST(NULL AS array(decimal)))) t(k)"; - assertQuery(sql, "values array[cast(5.1 as decimal), cast(11.1 as decimal), cast(11.1 as decimal)], array[], null"); + assertQuery(sql, "values array[cast(5.1 as DECIMAL(3,1)), cast(11.1 as DECIMAL(3,1)), cast(11.1 as DECIMAL(3,1))], array[], null"); sql = "select array_cum_sum(k) from (values (array[cast(5.1 as decimal(38, 1)), 6, null, 3]), (array[cast(null as decimal(38, 1)), 6, null, 3])) t(k)"; - assertQuery(sql, "values array[cast(5.1 as decimal), cast(11.1 as decimal), cast(null as decimal), cast(null as decimal)], " + + assertQuery(sql, "values array[cast(5.1 as decimal(3,1)), cast(11.1 as decimal(3,1)), cast(null as decimal(3,1)), cast(null as decimal(3,1))], " + "array[cast(null as decimal), cast(null as decimal), cast(null as decimal), cast(null as decimal)]"); // varchar diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java index f8ea8009f3d7c..1b54c582d3798 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java @@ -116,8 +116,8 @@ public H2QueryRunner() " orderstatus CHAR(1) NOT NULL,\n" + " totalprice DOUBLE NOT NULL,\n" + " orderdate DATE NOT NULL,\n" + - " orderpriority CHAR(15) NOT NULL,\n" + - " clerk CHAR(15) NOT NULL,\n" + + " orderpriority VARCHAR(15) NOT NULL,\n" + + " clerk VARCHAR(15) NOT NULL,\n" + " shippriority INTEGER NOT NULL,\n" + " comment VARCHAR(79) NOT NULL\n" + ")"); From 6315d1c3a84e6d85b4980736db8c2b7c4a24c731 Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Thu, 21 Nov 2024 09:49:58 +0530 Subject: [PATCH 04/10] Set non keywords in H2 database 2.x --- .../src/main/java/com/facebook/presto/tests/H2QueryRunner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java index 1b54c582d3798..f49b790683687 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java @@ -107,7 +107,7 @@ public class H2QueryRunner public H2QueryRunner() { - handle = Jdbi.open("jdbc:h2:mem:test" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt()); + handle = Jdbi.open("jdbc:h2:mem:test" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextLong() + ";NON_KEYWORDS=KEY,VALUE"); // key and value are reserved keywords in H2 2.x TpchMetadata tpchMetadata = new TpchMetadata(""); handle.execute("CREATE TABLE orders (\n" + From fd0a5f7ed539fbea99568e337da83c8748c4781d Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Thu, 21 Nov 2024 10:47:48 +0530 Subject: [PATCH 05/10] Update the H2db startdate as after 1890-09-30 --- .../presto/tests/AbstractTestWindowQueries.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestWindowQueries.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestWindowQueries.java index 14fa5afa8ebf3..2e9640997f84a 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestWindowQueries.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestWindowQueries.java @@ -1338,11 +1338,11 @@ public void testMultipleWindowFunctions() assertQuery("SELECT x, array_agg(date) OVER(ORDER BY x RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING), avg(number) OVER(ORDER BY x RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING) " + "FROM (VALUES " + "(2, DATE '2222-01-01', 4.4), " + - "(1, DATE '1111-01-01', 2.2), " + + "(1, DATE '1999-01-01', 2.2), " + "(3, DATE '3333-01-01', 6.6)) T(x, date, number)", "VALUES " + - "(1, ARRAY[DATE '1111-01-01', DATE '2222-01-01'], 3.3), " + - "(2, ARRAY[DATE '1111-01-01', DATE '2222-01-01', DATE '3333-01-01'], 4.4), " + + "(1, ARRAY[DATE '1999-01-01', DATE '2222-01-01'], 3.3), " + + "(2, ARRAY[DATE '1999-01-01', DATE '2222-01-01', DATE '3333-01-01'], 4.4), " + "(3, ARRAY[DATE '2222-01-01', DATE '3333-01-01'], 5.5)"); assertQuery("SELECT x, array_agg(a) OVER(ORDER BY x RANGE BETWEEN 2 PRECEDING AND CURRENT ROW), array_agg(a) OVER(ORDER BY x RANGE BETWEEN CURRENT ROW AND 2 FOLLOWING) " + @@ -1733,11 +1733,11 @@ public void testMultipleWindowFunctionsGroup() assertQuery("SELECT x, array_agg(date) OVER(ORDER BY x GROUPS BETWEEN 1 PRECEDING AND 1 PRECEDING), avg(number) OVER(ORDER BY x GROUPS BETWEEN 1 FOLLOWING AND 1 FOLLOWING) " + "FROM (VALUES " + "(2, DATE '2222-01-01', 4.4), " + - "(1, DATE '1111-01-01', 2.2), " + + "(1, DATE '1999-01-01', 2.2), " + "(3, DATE '3333-01-01', 6.6)) T(x, date, number)", "VALUES " + "(1, null, 4.4), " + - "(2, ARRAY[DATE '1111-01-01'], 6.6), " + + "(2, ARRAY[DATE '1999-01-01'], 6.6), " + "(3, ARRAY[DATE '2222-01-01'], null)"); // three functions with different frame types From 861fb9041b1c5ba354f34f3339dd9006f7f4be54 Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Fri, 22 Nov 2024 17:12:27 +0530 Subject: [PATCH 06/10] Fix cast null as array syntax error in AbstractTestWindowQueries class --- .../tests/AbstractTestWindowQueries.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestWindowQueries.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestWindowQueries.java index 2e9640997f84a..6c2902030a9fe 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestWindowQueries.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestWindowQueries.java @@ -1021,7 +1021,7 @@ public void testEmptyFrame() assertQuery("SELECT array_agg(a) OVER(ORDER BY a DESC NULLS LAST RANGE BETWEEN 1 PRECEDING AND 10 PRECEDING) " + "FROM (VALUES 1, 2, 3, null, null, 2, 1, null, null) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null, " + "null, " + @@ -1034,7 +1034,7 @@ public void testEmptyFrame() assertQuery("SELECT array_agg(a) OVER(ORDER BY a DESC NULLS LAST RANGE BETWEEN 10 FOLLOWING AND 1 FOLLOWING) " + "FROM (VALUES 1, 2, 3, null, null, 2, 1, null, null) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null, " + "null, " + @@ -1054,20 +1054,20 @@ public void testEmptyFrame() assertQuery("SELECT array_agg(a) OVER(ORDER BY a RANGE BETWEEN 1 FOLLOWING AND 2 FOLLOWING) " + "FROM (VALUES 1.0, 1.1) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null"); assertQuery("SELECT array_agg(a) OVER(ORDER BY a NULLS LAST RANGE BETWEEN 1 FOLLOWING AND 2 FOLLOWING) " + "FROM (VALUES 1.0, 1.1, null) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "ARRAY[null]"); assertQuery("SELECT array_agg(a) OVER(ORDER BY a RANGE BETWEEN 2 PRECEDING AND 1 PRECEDING) " + "FROM (VALUES 1.0, 1.1) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null"); assertQuery("SELECT array_agg(a) OVER(ORDER BY a NULLS FIRST RANGE BETWEEN 2 PRECEDING AND 1 PRECEDING) " + @@ -1122,14 +1122,14 @@ public void testAllPartitionSameValues() assertQuery("SELECT array_agg(a) OVER(ORDER BY a RANGE BETWEEN 1 FOLLOWING AND 2 FOLLOWING) " + "FROM (VALUES 1, 1, 1) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null"); assertQuery("SELECT array_agg(a) OVER(ORDER BY a RANGE BETWEEN 2 PRECEDING AND 1 PRECEDING) " + "FROM (VALUES 1, 1, 1) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null"); @@ -1428,7 +1428,7 @@ public void testConstantOffset() assertQuery("SELECT array_agg(a) OVER(ORDER BY a ASC NULLS FIRST GROUPS BETWEEN 2 FOLLOWING AND 1 FOLLOWING) " + "FROM (VALUES 3, 3, 3, 2, 2, 1, null, null) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null, " + "null, " + @@ -1542,7 +1542,7 @@ public void testEmptyFrameGroup() assertQuery("SELECT array_agg(a) OVER(ORDER BY a ASC NULLS LAST GROUPS BETWEEN 90 PRECEDING AND 100 PRECEDING) " + "FROM (VALUES 1, null, null, 2, 1) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null, " + "null, " + @@ -1551,7 +1551,7 @@ public void testEmptyFrameGroup() assertQuery("SELECT array_agg(a) OVER(ORDER BY a ASC NULLS LAST GROUPS BETWEEN 100 FOLLOWING AND 90 FOLLOWING) " + "FROM (VALUES 1, null, null, 2, 1) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null, " + "null, " + @@ -1607,14 +1607,14 @@ public void testOnlyNullsGroup() assertQuery("SELECT array_agg(a) OVER(ORDER BY a GROUPS BETWEEN 1 FOLLOWING AND 2 FOLLOWING) " + "FROM (VALUES CAST(null AS integer), null, null) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null"); assertQuery("SELECT array_agg(a) OVER(ORDER BY a GROUPS BETWEEN 2 PRECEDING AND 1 PRECEDING) " + "FROM (VALUES CAST(null AS integer), null, null) T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null"); } @@ -1625,14 +1625,14 @@ public void testAllPartitionSameValuesGroup() assertQuery("SELECT array_agg(a) OVER(ORDER BY a GROUPS BETWEEN 1 FOLLOWING AND 2 FOLLOWING) " + "FROM (VALUES 'a', 'a', 'a') T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null"); assertQuery("SELECT array_agg(a) OVER(ORDER BY a GROUPS BETWEEN 2 PRECEDING AND 1 PRECEDING) " + "FROM (VALUES 'a', 'a', 'a') T(a)", "VALUES " + - "CAST(null AS array), " + + "null, " + "null, " + "null"); From 467882083cd3847fd472f7a0467af71402467e1b Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Fri, 22 Nov 2024 17:16:03 +0530 Subject: [PATCH 07/10] Set non keyword as Value and Key in jdbc url --- .../java/com/facebook/presto/plugin/jdbc/TestingDatabase.java | 2 +- .../com/facebook/presto/plugin/jdbc/TestingH2JdbcModule.java | 2 +- .../com/facebook/presto/iceberg/rest/IcebergRestTestUtil.java | 2 +- .../presto/resourceGroups/db/TestDbManagerSpecProvider.java | 2 +- .../resourceGroups/db/TestDbSourceExactMatchSelector.java | 2 +- .../presto/resourceGroups/db/TestResourceGroupsDao.java | 2 +- .../TestReloadingResourceGroupConfigurationManager.java | 2 +- .../main/java/com/facebook/presto/tests/H2ConnectionModule.java | 2 +- .../src/main/java/com/facebook/presto/tests/H2QueryRunner.java | 2 +- .../facebook/presto/execution/resourceGroups/db/H2TestUtil.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestingDatabase.java b/presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestingDatabase.java index ad0b4163f8556..795f1370a82c2 100644 --- a/presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestingDatabase.java +++ b/presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestingDatabase.java @@ -50,7 +50,7 @@ final class TestingDatabase public TestingDatabase() throws SQLException { - String connectionUrl = "jdbc:h2:mem:test" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt() + ";LOCK_TIMEOUT=" + LOCK_TIMEOUT.toMillis(); + String connectionUrl = "jdbc:h2:mem:test" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt() + ";LOCK_TIMEOUT=" + LOCK_TIMEOUT.toMillis() + ";NON_KEYWORDS=KEY,VALUE"; // key and value are reserved keywords in H2 2.x jdbcClient = new BaseJdbcClient( new JdbcConnectorId(CONNECTOR_ID), new BaseJdbcConfig(), diff --git a/presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestingH2JdbcModule.java b/presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestingH2JdbcModule.java index 585638b7eb405..303276198766b 100644 --- a/presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestingH2JdbcModule.java +++ b/presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestingH2JdbcModule.java @@ -42,7 +42,7 @@ public JdbcClient provideJdbcClient(JdbcConnectorId id, BaseJdbcConfig config) public static Map createProperties() { return ImmutableMap.builder() - .put("connection-url", format("jdbc:h2:mem:test%s;DB_CLOSE_DELAY=-1", System.nanoTime())) + .put("connection-url", format("jdbc:h2:mem:test%s;DB_CLOSE_DELAY=-1;NON_KEYWORDS=KEY,VALUE", System.nanoTime())) // key and value are reserved keywords in H2 2.x .build(); } } diff --git a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/rest/IcebergRestTestUtil.java b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/rest/IcebergRestTestUtil.java index 4baf4560b28c6..1aa3168fcf6da 100644 --- a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/rest/IcebergRestTestUtil.java +++ b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/rest/IcebergRestTestUtil.java @@ -66,7 +66,7 @@ public static TestingHttpServer getRestServer(String location) backingCatalog.setConf(hdfsEnvironment.getConfiguration(new HdfsContext(SESSION), new Path(location))); Map properties = ImmutableMap.builder() - .put(URI, "jdbc:h2:mem:test_" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt()) + .put(URI, "jdbc:h2:mem:test_" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt() + ";NON_KEYWORDS=KEY,VALUE") // key and value are reserved keywords in H2 2.x .put(WAREHOUSE_LOCATION, location) .put("jdbc.username", "user") .put("jdbc.password", "password") diff --git a/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestDbManagerSpecProvider.java b/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestDbManagerSpecProvider.java index 20a55c2f49ac5..47829b92ce2d6 100644 --- a/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestDbManagerSpecProvider.java +++ b/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestDbManagerSpecProvider.java @@ -37,7 +37,7 @@ public class TestDbManagerSpecProvider private static H2DaoProvider setup(String prefix) { - DbResourceGroupConfig config = new DbResourceGroupConfig().setConfigDbUrl("jdbc:h2:mem:test_" + prefix + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt()); + DbResourceGroupConfig config = new DbResourceGroupConfig().setConfigDbUrl("jdbc:h2:mem:test_" + prefix + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt() + ";NON_KEYWORDS=KEY,VALUE"); // key and value are reserved keywords in H2 2.x return new H2DaoProvider(config); } diff --git a/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestDbSourceExactMatchSelector.java b/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestDbSourceExactMatchSelector.java index f1e30d570268a..c058ef4068c35 100644 --- a/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestDbSourceExactMatchSelector.java +++ b/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestDbSourceExactMatchSelector.java @@ -40,7 +40,7 @@ public class TestDbSourceExactMatchSelector @BeforeClass public void setup() { - DbResourceGroupConfig config = new DbResourceGroupConfig().setConfigDbUrl("jdbc:h2:mem:test_db-exact-match-selector" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt()); + DbResourceGroupConfig config = new DbResourceGroupConfig().setConfigDbUrl("jdbc:h2:mem:test_db-exact-match-selector" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt() + ";NON_KEYWORDS=KEY,VALUE"); // key and value are reserved keywords in H2 2.x dao = new H2DaoProvider(config).get(); dao.createExactMatchSelectorsTable(); } diff --git a/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestResourceGroupsDao.java b/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestResourceGroupsDao.java index cdd6ec6da30a8..50a39acd9c848 100644 --- a/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestResourceGroupsDao.java +++ b/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/db/TestResourceGroupsDao.java @@ -61,7 +61,7 @@ public class TestResourceGroupsDao static H2ResourceGroupsDao setup(String prefix) { - DbResourceGroupConfig config = new DbResourceGroupConfig().setConfigDbUrl("jdbc:h2:mem:test_" + prefix + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt()); + DbResourceGroupConfig config = new DbResourceGroupConfig().setConfigDbUrl("jdbc:h2:mem:test_" + prefix + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt() + ";NON_KEYWORDS=KEY,VALUE"); // key and value are reserved keywords in H2 2.x return new H2DaoProvider(config).get(); } diff --git a/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/reloading/TestReloadingResourceGroupConfigurationManager.java b/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/reloading/TestReloadingResourceGroupConfigurationManager.java index 4911ceffdc899..4c4f0ee1d59a3 100644 --- a/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/reloading/TestReloadingResourceGroupConfigurationManager.java +++ b/presto-resource-group-managers/src/test/java/com/facebook/presto/resourceGroups/reloading/TestReloadingResourceGroupConfigurationManager.java @@ -55,7 +55,7 @@ public class TestReloadingResourceGroupConfigurationManager static H2DaoProvider setup(String prefix) { - DbResourceGroupConfig config = new DbResourceGroupConfig().setConfigDbUrl("jdbc:h2:mem:test_" + prefix + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt()); + DbResourceGroupConfig config = new DbResourceGroupConfig().setConfigDbUrl("jdbc:h2:mem:test_" + prefix + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt() + ";NON_KEYWORDS=KEY,VALUE"); // key and value are reserved keywords in H2 2.x return new H2DaoProvider(config); } diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/H2ConnectionModule.java b/presto-tests/src/main/java/com/facebook/presto/tests/H2ConnectionModule.java index 3cef6184aed45..78f318ed49b65 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/H2ConnectionModule.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/H2ConnectionModule.java @@ -90,6 +90,6 @@ public FunctionNamespaceDao get() public static String getJdbcUrl(String databaseName) { - return format("jdbc:h2:mem:test%s;MODE=MySQL;DATABASE_TO_LOWER=TRUE", databaseName); + return format("jdbc:h2:mem:test%s;MODE=MySQL;DATABASE_TO_LOWER=TRUE;NON_KEYWORDS=KEY,VALUE", databaseName); // key and value are reserved keywords in H2 2.x } } diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java index f49b790683687..27f1f4bf64631 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java @@ -107,7 +107,7 @@ public class H2QueryRunner public H2QueryRunner() { - handle = Jdbi.open("jdbc:h2:mem:test" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextLong() + ";NON_KEYWORDS=KEY,VALUE"); // key and value are reserved keywords in H2 2.x + handle = Jdbi.open("jdbc:h2:mem:test" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt() + ";NON_KEYWORDS=KEY,VALUE"); // key and value are reserved keywords in H2 2.x TpchMetadata tpchMetadata = new TpchMetadata(""); handle.execute("CREATE TABLE orders (\n" + diff --git a/presto-tests/src/test/java/com/facebook/presto/execution/resourceGroups/db/H2TestUtil.java b/presto-tests/src/test/java/com/facebook/presto/execution/resourceGroups/db/H2TestUtil.java index f8f379f79ede8..78e0784ceb80b 100644 --- a/presto-tests/src/test/java/com/facebook/presto/execution/resourceGroups/db/H2TestUtil.java +++ b/presto-tests/src/test/java/com/facebook/presto/execution/resourceGroups/db/H2TestUtil.java @@ -116,7 +116,7 @@ public static void waitForQueryCount(DistributedQueryRunner queryRunner, Set Date: Tue, 26 Nov 2024 15:10:22 +0530 Subject: [PATCH 08/10] Fix the nested Array and Row syntax change issue --- presto-tests/pom.xml | 1 - .../facebook/presto/tests/H2QueryRunner.java | 42 +++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/presto-tests/pom.xml b/presto-tests/pom.xml index 6bdf3acad7455..341c2a350e9d2 100644 --- a/presto-tests/pom.xml +++ b/presto-tests/pom.xml @@ -211,7 +211,6 @@ com.h2database h2 - runtime diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java index 27f1f4bf64631..15e2098c7a8cc 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java @@ -36,6 +36,8 @@ import com.facebook.presto.tpch.TpchTableHandle; import com.google.common.base.Joiner; import io.airlift.tpch.TpchTable; +import org.h2.jdbc.JdbcArray; +import org.h2.jdbc.JdbcResultSet; import org.intellij.lang.annotations.Language; import org.jdbi.v3.core.Handle; import org.jdbi.v3.core.Jdbi; @@ -375,14 +377,14 @@ private static Object[] mapArrayValues(ArrayType arrayType, Object[] values) Type elementType = arrayType.getElementType(); if (elementType instanceof ArrayType) { return Arrays.stream(values) - .map(v -> v == null ? null : newArrayList((Object[]) v)) + .map(v -> v == null ? null : newArrayList(getArrayObject((JdbcArray) v))) .toArray(); } if (elementType instanceof RowType) { RowType rowType = (RowType) elementType; return Arrays.stream(values) - .map(v -> v == null ? null : newArrayList(mapRowValues(rowType, (Object[]) v))) + .map(v -> v == null ? null : newArrayList(mapRowValues(rowType, getRowObject(rowType, (JdbcResultSet) v)))) .toArray(); } @@ -411,10 +413,15 @@ private static Object[] mapRowValues(RowType rowType, Object[] values) { int fieldCount = rowType.getFields().size(); Object[] fields = new Object[fieldCount]; + + if (values.length == 1) { + values = getRowObject(rowType, (JdbcResultSet) values[0]); + } + for (int j = 0; j < fieldCount; j++) { Type fieldType = rowType.getTypeParameters().get(j); if (fieldType instanceof RowType) { - fields[j] = newArrayList(mapRowValues((RowType) fieldType, (Object[]) values[j])); + fields[j] = newArrayList(mapRowValues((RowType) fieldType, getRowObject((RowType) fieldType, (JdbcResultSet) values[j]))); } else { fields[j] = values[j]; @@ -495,4 +502,33 @@ public String nameParameter(String rawName, StatementContext ctx) throw new UnsupportedOperationException(); } } + + private static Object[] getArrayObject(JdbcArray jdbcArray) + { + Object[] objectArray = null; + try { + objectArray = (Object[]) jdbcArray.getArray(); + } + catch (SQLException e) { + throw new RuntimeException(e); + } + return objectArray; + } + + private static Object[] getRowObject(RowType rowType, JdbcResultSet jdbcResultSet) + { + int fieldCount = rowType.getFields().size(); + Object[] objectArray = new Object[fieldCount]; + try { + jdbcResultSet.next(); + for (int i = 0; i < fieldCount; i++) { + // JdbcResultSet getObject index start from 1. + objectArray[i] = jdbcResultSet.getObject(i + 1); + } + } + catch (SQLException e) { + throw new RuntimeException(e); + } + return objectArray; + } } From 248986b0ad62ff96c046271da72bb7f94716005b Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Tue, 26 Nov 2024 16:57:09 +0530 Subject: [PATCH 09/10] Fix decimal cast syntax error --- .../facebook/presto/tests/AbstractTestQueries.java | 2 +- .../com/facebook/presto/tests/TestLocalQueries.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java index b3121b4d4be38..fce76ffa268d9 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java @@ -7061,7 +7061,7 @@ public void testArrayCumSum() // decimal sql = "select array_cum_sum(k) from (values (array[cast(5.1 as decimal(38, 1)), 6, 0]), (ARRAY[]), (CAST(NULL AS array(decimal)))) t(k)"; - assertQuery(sql, "values array[cast(5.1 as DECIMAL(3,1)), cast(11.1 as DECIMAL(3,1)), cast(11.1 as DECIMAL(3,1))], array[], null"); + assertQuery(sql, "values array[cast(5.1 as decimal(3,1)), cast(11.1 as decimal(3,1)), cast(11.1 as decimal(3,1))], array[], null"); sql = "select array_cum_sum(k) from (values (array[cast(5.1 as decimal(38, 1)), 6, null, 3]), (array[cast(null as decimal(38, 1)), 6, null, 3])) t(k)"; assertQuery(sql, "values array[cast(5.1 as decimal(3,1)), cast(11.1 as decimal(3,1)), cast(null as decimal(3,1)), cast(null as decimal(3,1))], " + diff --git a/presto-tests/src/test/java/com/facebook/presto/tests/TestLocalQueries.java b/presto-tests/src/test/java/com/facebook/presto/tests/TestLocalQueries.java index 63d4fc2e5838a..c42380aeb9f33 100644 --- a/presto-tests/src/test/java/com/facebook/presto/tests/TestLocalQueries.java +++ b/presto-tests/src/test/java/com/facebook/presto/tests/TestLocalQueries.java @@ -109,12 +109,12 @@ public void testRejectStarQueryWithoutFromRelation() @Test public void testDecimal() { - assertQuery("SELECT DECIMAL '1.0'", "SELECT CAST('1.0' AS DECIMAL)"); - assertQuery("SELECT DECIMAL '1.'", "SELECT CAST('1.0' AS DECIMAL)"); - assertQuery("SELECT DECIMAL '0.1'", "SELECT CAST('0.1' AS DECIMAL)"); - assertQuery("SELECT 1.0", "SELECT CAST('1.0' AS DECIMAL)"); - assertQuery("SELECT 1.", "SELECT CAST('1.0' AS DECIMAL)"); - assertQuery("SELECT 0.1", "SELECT CAST('0.1' AS DECIMAL)"); + assertQuery("SELECT DECIMAL '1.0'", "SELECT CAST('1.0' AS DECIMAL(2,1))"); + assertQuery("SELECT DECIMAL '1.'", "SELECT CAST('1.0' AS DECIMAL(2,1))"); + assertQuery("SELECT DECIMAL '0.1'", "SELECT CAST('0.1' AS DECIMAL(2,1))"); + assertQuery("SELECT 1.0", "SELECT CAST('1.0' AS DECIMAL(2,1))"); + assertQuery("SELECT 1.", "SELECT CAST('1.0' AS DECIMAL(2,1))"); + assertQuery("SELECT 0.1", "SELECT CAST('0.1' AS DECIMAL(2,1))"); } @Test From 359b804b213bbe552155dd348457c9ea9a5341da Mon Sep 17 00:00:00 2001 From: Shahim Sharafudeen Date: Tue, 17 Dec 2024 12:28:05 +0530 Subject: [PATCH 10/10] Fix the nested array and row syntax issue --- .../hive/TestHivePushdownFilterQueries.java | 22 +-- presto-tests/pom.xml | 1 + .../facebook/presto/tests/H2QueryRunner.java | 131 ++++++------------ 3 files changed, 55 insertions(+), 99 deletions(-) diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/TestHivePushdownFilterQueries.java b/presto-hive/src/test/java/com/facebook/presto/hive/TestHivePushdownFilterQueries.java index 5b0844835b8af..c99fe51c83e9d 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/TestHivePushdownFilterQueries.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/TestHivePushdownFilterQueries.java @@ -81,27 +81,27 @@ public class TestHivePushdownFilterQueries " CASE WHEN orderkey % 5 = 0 THEN null ELSE CAST(discount AS REAL) END AS discount_real, \n" + " CASE WHEN orderkey % 43 = 0 THEN null ELSE discount END as discount, \n" + " CASE WHEN orderkey % 7 = 0 THEN null ELSE CAST(tax AS REAL) END AS tax_real, \n" + - " CASE WHEN linenumber % 2 = 0 THEN null ELSE (CAST(day(shipdate) AS TINYINT) , CAST(month(shipdate) AS TINYINT)) END AS ship_day_month, " + + " CASE WHEN linenumber % 2 = 0 THEN null ELSE ARRAY[CAST(day(shipdate) AS TINYINT) , CAST(month(shipdate) AS TINYINT)] END AS ship_day_month, " + " CASE WHEN orderkey % 37 = 0 THEN null ELSE CAST(discount AS DECIMAL(20, 8)) END AS discount_long_decimal, " + " CASE WHEN orderkey % 41 = 0 THEN null ELSE CAST(tax AS DECIMAL(3, 2)) END AS tax_short_decimal, " + - " CASE WHEN orderkey % 43 = 0 THEN null ELSE (CAST(discount AS DECIMAL(20, 8)), CAST(tax AS DECIMAL(20, 8))) END AS long_decimals, " + - " CASE WHEN orderkey % 11 = 0 THEN null ELSE (orderkey, partkey, suppkey) END AS keys, \n" + - " CASE WHEN orderkey % 41 = 0 THEN null ELSE (extendedprice, discount, tax) END AS doubles, \n" + + " CASE WHEN orderkey % 43 = 0 THEN null ELSE ARRAY[CAST(discount AS DECIMAL(20, 8)), CAST(tax AS DECIMAL(20, 8))] END AS long_decimals, " + + " CASE WHEN orderkey % 11 = 0 THEN null ELSE ARRAY[orderkey, partkey, suppkey] END AS keys, \n" + + " CASE WHEN orderkey % 41 = 0 THEN null ELSE ARRAY[extendedprice, discount, tax] END AS doubles, \n" + " CASE WHEN orderkey % 13 = 0 THEN null ELSE ARRAY[ARRAY[orderkey, partkey], ARRAY[suppkey], CASE WHEN orderkey % 17 = 0 THEN null ELSE ARRAY[orderkey, partkey] END] END AS nested_keys, \n" + - " CASE WHEN orderkey % 17 = 0 THEN null ELSE (shipmode = 'AIR', returnflag = 'R') END as flags, \n" + - " CASE WHEN orderkey % 19 = 0 THEN null ELSE (CAST(discount AS REAL), CAST(tax AS REAL)) END as reals, \n" + + " CASE WHEN orderkey % 17 = 0 THEN null ELSE ARRAY[shipmode = 'AIR', returnflag = 'R'] END as flags, \n" + + " CASE WHEN orderkey % 19 = 0 THEN null ELSE ARRAY[CAST(discount AS REAL), CAST(tax AS REAL)] END as reals, \n" + " CASE WHEN orderkey % 23 = 0 THEN null ELSE (orderkey, linenumber, (CAST(day(shipdate) as TINYINT), CAST(month(shipdate) AS TINYINT), CAST(year(shipdate) AS INTEGER))) END AS info, \n" + - " CASE WHEN orderkey % 31 = 0 THEN null ELSE (" + + " CASE WHEN orderkey % 31 = 0 THEN null ELSE ARRAY[" + " (CAST(day(shipdate) AS TINYINT), CAST(month(shipdate) AS TINYINT), CAST(year(shipdate) AS INTEGER)), " + " (CAST(day(commitdate) AS TINYINT), CAST(month(commitdate) AS TINYINT), CAST(year(commitdate) AS INTEGER)), " + - " (CAST(day(receiptdate) AS TINYINT), CAST(month(receiptdate) AS TINYINT), CAST(year(receiptdate) AS INTEGER))) END AS dates, \n" + - " CASE WHEN orderkey % 37 = 0 THEN null ELSE (CAST(shipdate AS TIMESTAMP), CAST(commitdate AS TIMESTAMP)) END AS timestamps, \n" + + " (CAST(day(receiptdate) AS TINYINT), CAST(month(receiptdate) AS TINYINT), CAST(year(receiptdate) AS INTEGER))] END AS dates, \n" + + " CASE WHEN orderkey % 37 = 0 THEN null ELSE ARRAY[CAST(shipdate AS TIMESTAMP), CAST(commitdate AS TIMESTAMP)] END AS timestamps, \n" + " CASE WHEN orderkey % 43 = 0 THEN null ELSE comment END AS comment, \n" + " CASE WHEN orderkey % 43 = 0 THEN null ELSE upper(comment) END AS uppercase_comment, \n" + " CAST('' as VARBINARY) AS empty_comment, \n" + " CASE WHEN orderkey % 47 = 0 THEN null ELSE CAST(comment AS CHAR(5)) END AS fixed_comment, \n" + - " CASE WHEN orderkey % 49 = 0 THEN null ELSE (CAST(comment AS CHAR(4)), CAST(comment AS CHAR(3)), CAST(SUBSTR(comment,length(comment) - 4) AS CHAR(4))) END AS char_array, \n" + - " CASE WHEN orderkey % 49 = 0 THEN null ELSE (comment, comment) END AS varchar_array \n" + + " CASE WHEN orderkey % 49 = 0 THEN null ELSE ARRAY[CAST(comment AS CHAR(4)), CAST(comment AS CHAR(3)), CAST(SUBSTR(comment,length(comment) - 4) AS CHAR(4))] END AS char_array, \n" + + " CASE WHEN orderkey % 49 = 0 THEN null ELSE ARRAY[comment, comment] END AS varchar_array \n" + "FROM lineitem)\n"; diff --git a/presto-tests/pom.xml b/presto-tests/pom.xml index 341c2a350e9d2..6bdf3acad7455 100644 --- a/presto-tests/pom.xml +++ b/presto-tests/pom.xml @@ -211,6 +211,7 @@ com.h2database h2 + runtime diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java index 15e2098c7a8cc..0782fb3e317e7 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/H2QueryRunner.java @@ -16,11 +16,9 @@ import com.facebook.presto.Session; import com.facebook.presto.common.type.ArrayType; import com.facebook.presto.common.type.CharType; -import com.facebook.presto.common.type.DateType; import com.facebook.presto.common.type.DecimalType; import com.facebook.presto.common.type.DistinctType; import com.facebook.presto.common.type.RowType; -import com.facebook.presto.common.type.TimestampType; import com.facebook.presto.common.type.Type; import com.facebook.presto.common.type.TypeWithName; import com.facebook.presto.common.type.VarcharType; @@ -36,8 +34,6 @@ import com.facebook.presto.tpch.TpchTableHandle; import com.google.common.base.Joiner; import io.airlift.tpch.TpchTable; -import org.h2.jdbc.JdbcArray; -import org.h2.jdbc.JdbcResultSet; import org.intellij.lang.annotations.Language; import org.jdbi.v3.core.Handle; import org.jdbi.v3.core.Jdbi; @@ -54,12 +50,10 @@ import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; @@ -339,12 +333,45 @@ else if (type instanceof DecimalType) { .round(new MathContext(decimalType.getPrecision())); } else if (type instanceof ArrayType) { - Array array = resultSet.getArray(position); - return resultSet.wasNull() ? null : newArrayList(mapArrayValues(((ArrayType) type), (Object[]) array.getArray())); + Type elementType = ((ArrayType) type).getElementType(); + Object[] testData = null; + if (resultSet.getArray(position) != null) { + Array array = resultSet.getArray(position); + ResultSet arrayResultset = array.getResultSet(); + if (arrayResultset != null) { + int rowCount = getResultsetRowCount(arrayResultset); + int arrayIndex = 0; + testData = new Object[rowCount]; + if (arrayResultset.next()) { + do { + //For Array data type, array.getResultSet() return the values in result set as row format and keeping in second column. + testData[arrayIndex] = getValue(elementType, arrayResultset, 2); + arrayIndex++; + } while (arrayResultset.next()); + } + } + } + return resultSet.wasNull() ? null : newArrayList(testData); } else if (type instanceof RowType) { - Array array = resultSet.getArray(position); - return resultSet.wasNull() ? null : newArrayList(mapRowValues((RowType) type, (Object[]) array.getArray())); + Object[] testData = null; + if (resultSet.getArray(position) != null) { + Array array = resultSet.getArray(position); + Object[] data = (Object[]) array.getArray(); + //For ROW data type, array.getArray() return only one value. ie, Resultset. + if (data[0] != null) { + ResultSet rowResultset = (ResultSet) data[0]; + int columnCount = rowResultset.getMetaData().getColumnCount(); + testData = new Object[columnCount]; + if (rowResultset.next()) { + for (int i = 0; i < columnCount; i++) { + Type elementType = type.getTypeParameters().get(i); + testData[i] = getValue(elementType, rowResultset, i + 1); + } + } + } + } + return resultSet.wasNull() ? null : newArrayList(testData); } else if (type instanceof TypeWithName) { return getValue(((TypeWithName) type).getType(), resultSet, position); @@ -372,64 +399,6 @@ public MaterializedRow map(ResultSet resultSet, StatementContext context) }; } - private static Object[] mapArrayValues(ArrayType arrayType, Object[] values) - { - Type elementType = arrayType.getElementType(); - if (elementType instanceof ArrayType) { - return Arrays.stream(values) - .map(v -> v == null ? null : newArrayList(getArrayObject((JdbcArray) v))) - .toArray(); - } - - if (elementType instanceof RowType) { - RowType rowType = (RowType) elementType; - return Arrays.stream(values) - .map(v -> v == null ? null : newArrayList(mapRowValues(rowType, getRowObject(rowType, (JdbcResultSet) v)))) - .toArray(); - } - - if (elementType instanceof CharType) { - int length = ((CharType) elementType).getLength(); - return Arrays.stream(values) - .map(String.class::cast) - .map(v -> v == null ? null : padEnd(v, length, ' ')) - .toArray(); - } - - if (elementType instanceof TimestampType) { - return Arrays.stream(values) - .map(v -> v == null ? null : ((Timestamp) v).toLocalDateTime()) - .toArray(); - } - - if (elementType instanceof DateType) { - return Arrays.stream(values).map(v -> v == null ? null : ((Date) v).toLocalDate()).toArray(); - } - - return values; - } - - private static Object[] mapRowValues(RowType rowType, Object[] values) - { - int fieldCount = rowType.getFields().size(); - Object[] fields = new Object[fieldCount]; - - if (values.length == 1) { - values = getRowObject(rowType, (JdbcResultSet) values[0]); - } - - for (int j = 0; j < fieldCount; j++) { - Type fieldType = rowType.getTypeParameters().get(j); - if (fieldType instanceof RowType) { - fields[j] = newArrayList(mapRowValues((RowType) fieldType, getRowObject((RowType) fieldType, (JdbcResultSet) values[j]))); - } - else { - fields[j] = values[j]; - } - } - return fields; - } - private static void insertRows(ConnectorTableMetadata tableMetadata, Handle handle, RecordSet data) { List columns = tableMetadata.getColumns().stream() @@ -503,32 +472,18 @@ public String nameParameter(String rawName, StatementContext ctx) } } - private static Object[] getArrayObject(JdbcArray jdbcArray) - { - Object[] objectArray = null; - try { - objectArray = (Object[]) jdbcArray.getArray(); - } - catch (SQLException e) { - throw new RuntimeException(e); - } - return objectArray; - } - - private static Object[] getRowObject(RowType rowType, JdbcResultSet jdbcResultSet) + private static int getResultsetRowCount(ResultSet resultset) { - int fieldCount = rowType.getFields().size(); - Object[] objectArray = new Object[fieldCount]; + int rowCount = 0; try { - jdbcResultSet.next(); - for (int i = 0; i < fieldCount; i++) { - // JdbcResultSet getObject index start from 1. - objectArray[i] = jdbcResultSet.getObject(i + 1); + if (resultset.last()) { + rowCount = resultset.getRow(); + resultset.beforeFirst(); } } catch (SQLException e) { throw new RuntimeException(e); } - return objectArray; + return rowCount; } }