From e3f6b7180e170c70ea465caa5217beb1b0bac52d Mon Sep 17 00:00:00 2001 From: David Phillips Date: Thu, 9 Mar 2023 16:15:19 -0800 Subject: [PATCH 1/2] Fix generation of JSON path keyvalue() IDs Previously, separate IDs were generated for each member. --- .../io/trino/json/PathEvaluationVisitor.java | 3 +- .../io/trino/json/TestJsonPathEvaluator.java | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/core/trino-main/src/main/java/io/trino/json/PathEvaluationVisitor.java b/core/trino-main/src/main/java/io/trino/json/PathEvaluationVisitor.java index 17f403f5b5fc..8427b5b77942 100644 --- a/core/trino-main/src/main/java/io/trino/json/PathEvaluationVisitor.java +++ b/core/trino-main/src/main/java/io/trino/json/PathEvaluationVisitor.java @@ -825,7 +825,8 @@ protected List visitIrKeyValueMethod(IrKeyValueMethod node, PathEvaluati ImmutableMap.of( "name", TextNode.valueOf(field.getKey()), "value", field.getValue(), - "id", IntNode.valueOf(objectId++))))); + "id", IntNode.valueOf(objectId))))); + objectId++; } return outputSequence.build(); diff --git a/core/trino-main/src/test/java/io/trino/json/TestJsonPathEvaluator.java b/core/trino-main/src/test/java/io/trino/json/TestJsonPathEvaluator.java index d3aaf7feb6e9..ad7861004ea7 100644 --- a/core/trino-main/src/test/java/io/trino/json/TestJsonPathEvaluator.java +++ b/core/trino-main/src/test/java/io/trino/json/TestJsonPathEvaluator.java @@ -683,6 +683,55 @@ public void testKeyValueMethod() "value", NullNode.instance, "id", IntNode.valueOf(1))))); + // nested methods + assertThat(pathResult( + new ArrayNode( + JsonNodeFactory.instance, + ImmutableList.of( + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of("key1", TextNode.valueOf("first"), "key2", BooleanNode.TRUE)), + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of("key3", IntNode.valueOf(42))))), + path(true, keyValue(keyValue(wildcardArrayAccessor(contextVariable())))))) + .isEqualTo(sequence( + // key1 + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("name"), + "value", TextNode.valueOf("key1"), + "id", IntNode.valueOf(2))), + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("value"), + "value", TextNode.valueOf("first"), + "id", IntNode.valueOf(2))), + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("id"), + "value", IntNode.valueOf(0), + "id", IntNode.valueOf(2))), + // key2 + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("name"), + "value", TextNode.valueOf("key2"), + "id", IntNode.valueOf(3))), + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("value"), + "value", BooleanNode.TRUE, + "id", IntNode.valueOf(3))), + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("id"), + "value", IntNode.valueOf(0), + "id", IntNode.valueOf(3))), + // key3 + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("name"), + "value", TextNode.valueOf("key3"), + "id", IntNode.valueOf(4))), + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("value"), + "value", IntNode.valueOf(42), + "id", IntNode.valueOf(4))), + new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of( + "name", TextNode.valueOf("id"), + "value", IntNode.valueOf(1), + "id", IntNode.valueOf(4))))); + // type mismatch assertThatThrownBy(() -> evaluate( IntNode.valueOf(-5), From 838678b4d4d4d560cf25a3592dc08de6088598e7 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 7 Mar 2023 12:15:58 -0800 Subject: [PATCH 2/2] Update to Airbase 134 --- .../java/io/trino/plugin/hive/TestHive.java | 4 +- pom.xml | 14 ++- .../trino/tests/BaseQueryAssertionsTest.java | 101 ++++++++++-------- .../trino/tests/TestLocalQueryAssertions.java | 24 ++--- 4 files changed, 77 insertions(+), 66 deletions(-) diff --git a/plugin/trino-hive-hadoop2/src/test/java/io/trino/plugin/hive/TestHive.java b/plugin/trino-hive-hadoop2/src/test/java/io/trino/plugin/hive/TestHive.java index 863f5392265b..1fdb20091a50 100644 --- a/plugin/trino-hive-hadoop2/src/test/java/io/trino/plugin/hive/TestHive.java +++ b/plugin/trino-hive-hadoop2/src/test/java/io/trino/plugin/hive/TestHive.java @@ -56,9 +56,9 @@ public void testHideDeltaLakeTables() assertThatThrownBy(super::testHideDeltaLakeTables) .hasMessageMatching("(?s)\n" + "Expecting\n" + - " <\\[.*\\b(\\w+.tmp_trino_test_trino_delta_lake_table_\\w+)\\b.*]>\n" + + " \\[.*\\b(\\w+.tmp_trino_test_trino_delta_lake_table_\\w+)\\b.*]\n" + "not to contain\n" + - " <\\[\\1]>\n" + + " \\[\\1]\n" + "but found.*"); throw new SkipException("not supported"); diff --git a/pom.xml b/pom.xml index 5887dfdc09e8..c6ddaeab9ecc 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.airlift airbase - 133 + 134 io.trino @@ -46,17 +46,14 @@ clean verify -DskipTests - 0.45 1.10.2 2.7.7-1 4.11.1 - 225 9.0.0 ${dep.airlift.version} 1.12.261 3.14.9 - 2.12.2 0.11.2 19.3.0.0 1.14 @@ -1584,6 +1581,13 @@ 8.0.29 + + + net.bytebuddy + byte-buddy + 1.14.1 + + net.java.dev.jna @@ -1808,7 +1812,7 @@ org.javassist javassist - 3.22.0-GA + 3.29.2-GA diff --git a/testing/trino-tests/src/test/java/io/trino/tests/BaseQueryAssertionsTest.java b/testing/trino-tests/src/test/java/io/trino/tests/BaseQueryAssertionsTest.java index 5851061a2fe7..4e6f5de2bf57 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/BaseQueryAssertionsTest.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/BaseQueryAssertionsTest.java @@ -111,11 +111,11 @@ public void testReturnsEmptyResult() QueryAssert queryAssert = assertThat(query("VALUES 'foobar'")); assertThatThrownBy(queryAssert::returnsEmptyResult) - .hasMessage("[Rows for query [VALUES 'foobar']] \nExpecting empty but was:<[[foobar]]>"); + .hasMessageContaining("[Rows for query [VALUES 'foobar']] \nExpecting empty but was: [[foobar]]"); queryAssert = assertThat(query("VALUES 'foo', 'bar'")); assertThatThrownBy(queryAssert::returnsEmptyResult) - .hasMessage("[Rows for query [VALUES 'foo', 'bar']] \nExpecting empty but was:<[[foo], [bar]]>"); + .hasMessageContaining("[Rows for query [VALUES 'foo', 'bar']] \nExpecting empty but was: [[foo], [bar]]"); } @Test @@ -125,24 +125,31 @@ public void testVarbinaryResult() QueryAssert queryAssert = assertThat(query("SELECT X'001234'")); assertThatThrownBy(() -> queryAssert.matches("VALUES X'001299'")) - .hasMessageMatching("" + + .hasMessageMatching( // TODO the representation and thus messages should be the same regardless of query runner in use - // when using local query runner - "(?s).*" + - "(\\Q" + - "Expecting:\n" + - " <(00 12 34)>\n" + - "to contain exactly in any order:\n" + - " <[(00 12 99)]>\n" + - "elements not found:\n" + - " <(00 12 99)>" + - "\\E|\\Q" + - // when using distributed query runner - "Expecting:\n" + - " <([0, 18, 52])>\n" + - "to contain exactly in any order:\n" + - " <[([0, 18, -103])]>" + - "\\E).*"); + getQueryRunner() instanceof LocalQueryRunner + ? "(?s).*" + + "\\Q" + + "Expecting actual:\n" + + " (00 12 34)\n" + + "to contain exactly in any order:\n" + + " [(00 12 99)]\n" + + "elements not found:\n" + + " (00 12 99)\n" + + "and elements not expected:\n" + + " (00 12 34)" + + "\\E.*" + : "(?s).*" + + "\\Q" + + "Expecting actual:\n" + + " ([0, 18, 52])\n" + + "to contain exactly in any order:\n" + + " [([0, 18, -103])]\n" + + "elements not found:\n" + + " ([0, 18, -103])\n" + + "and elements not expected:\n" + + " ([0, 18, 52])" + + "\\E.*"); } @Test @@ -158,25 +165,25 @@ public void testNestedVarbinaryResult() getQueryRunner() instanceof LocalQueryRunner ? "(?s).*" + "\\Q" + - "Expecting:\n" + - " <([00 12 34])>\n" + + "Expecting actual:\n" + + " ([00 12 34])\n" + "to contain exactly in any order:\n" + - " <[([00 12 99])]>\n" + + " [([00 12 99])]\n" + "elements not found:\n" + - " <([00 12 99])>\n" + + " ([00 12 99])\n" + "and elements not expected:\n" + - " <([00 12 34])>" + + " ([00 12 34])" + "\\E.*" : "(?s).*" + "\\Q" + - "Expecting:\n" + - " <([X'00 12 34'])>\n" + + "Expecting actual:\n" + + " ([X'00 12 34'])\n" + "to contain exactly in any order:\n" + - " <[([X'00 12 99'])]>\n" + + " [([X'00 12 99'])]\n" + "elements not found:\n" + - " <([X'00 12 99'])>\n" + + " ([X'00 12 99'])\n" + "and elements not expected:\n" + - " <([X'00 12 34'])>" + + " ([X'00 12 34'])" + "\\E.*"); } @@ -193,10 +200,10 @@ public void testTimeQueryResult() QueryAssert queryAssert = assertThat(query("SELECT TIME '01:23:45.123456789012'")); assertThatThrownBy(() -> queryAssert.matches("SELECT TIME '01:23:45.123456789013'")) - .hasMessageContaining("Expecting:\n" + - " <(01:23:45.123456789012)>\n" + + .hasMessageContaining("Expecting actual:\n" + + " (01:23:45.123456789012)\n" + "to contain exactly in any order:\n" + - " <[(01:23:45.123456789013)]>"); + " [(01:23:45.123456789013)]"); } /** @@ -213,16 +220,16 @@ public void testTimeWithTimeZoneQueryResult() QueryAssert queryAssert = assertThat(query("SELECT TIME '01:23:45.123456789012 +05:07'")); // different second fraction assertThatThrownBy(() -> queryAssert.matches("SELECT TIME '01:23:45.123456789013 +05:07'")) - .hasMessageContaining("Expecting:\n" + - " <(01:23:45.123456789012+05:07)>\n" + + .hasMessageContaining("Expecting actual:\n" + + " (01:23:45.123456789012+05:07)\n" + "to contain exactly in any order:\n" + - " <[(01:23:45.123456789013+05:07)]>"); + " [(01:23:45.123456789013+05:07)]"); // different zone assertThatThrownBy(() -> queryAssert.matches("SELECT TIME '01:23:45.123456789012 +05:42'")) - .hasMessageContaining("Expecting:\n" + - " <(01:23:45.123456789012+05:07)>\n" + + .hasMessageContaining("Expecting actual:\n" + + " (01:23:45.123456789012+05:07)\n" + "to contain exactly in any order:\n" + - " <[(01:23:45.123456789012+05:42)]>"); + " [(01:23:45.123456789012+05:42)]"); } /** @@ -238,10 +245,10 @@ public void testTimestampQueryResult() QueryAssert queryAssert = assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012'")); assertThatThrownBy(() -> queryAssert.matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789013'")) - .hasMessageContaining("Expecting:\n" + - " <(2017-01-02 09:12:34.123456789012)>\n" + + .hasMessageContaining("Expecting actual:\n" + + " (2017-01-02 09:12:34.123456789012)\n" + "to contain exactly in any order:\n" + - " <[(2017-01-02 09:12:34.123456789013)]>"); + " [(2017-01-02 09:12:34.123456789013)]"); } /** @@ -258,16 +265,16 @@ public void testTimestampWithTimeZoneQueryResult() QueryAssert queryAssert = assertThat(query("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012 Europe/Warsaw'")); // different second fraction assertThatThrownBy(() -> queryAssert.matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789013 Europe/Warsaw'")) - .hasMessageContaining("Expecting:\n" + - " <(2017-01-02 09:12:34.123456789012 Europe/Warsaw)>\n" + + .hasMessageContaining("Expecting actual:\n" + + " (2017-01-02 09:12:34.123456789012 Europe/Warsaw)\n" + "to contain exactly in any order:\n" + - " <[(2017-01-02 09:12:34.123456789013 Europe/Warsaw)]>"); + " [(2017-01-02 09:12:34.123456789013 Europe/Warsaw)]"); // different zone assertThatThrownBy(() -> queryAssert.matches("SELECT TIMESTAMP '2017-01-02 09:12:34.123456789012 Europe/Paris'")) - .hasMessageContaining("Expecting:\n" + - " <(2017-01-02 09:12:34.123456789012 Europe/Warsaw)>\n" + + .hasMessageContaining("Expecting actual:\n" + + " (2017-01-02 09:12:34.123456789012 Europe/Warsaw)\n" + "to contain exactly in any order:\n" + - " <[(2017-01-02 09:12:34.123456789012 Europe/Paris)]>"); + " [(2017-01-02 09:12:34.123456789012 Europe/Paris)]"); } @Test diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestLocalQueryAssertions.java b/testing/trino-tests/src/test/java/io/trino/tests/TestLocalQueryAssertions.java index a201c3b4b48b..3bb02e43a1b2 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestLocalQueryAssertions.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestLocalQueryAssertions.java @@ -68,25 +68,25 @@ public void testIsFullyPushedDownWithSession() public void testNullInErrorMessage() { assertThatThrownBy(() -> assertThat(query("SELECT CAST(null AS integer)")).matches("SELECT 1")) - .hasMessage("[Rows for query [SELECT CAST(null AS integer)]] \n" + - "Expecting:\n" + - " <(null)>\n" + + .hasMessageContaining("[Rows for query [SELECT CAST(null AS integer)]] \n" + + "Expecting actual:\n" + + " (null)\n" + "to contain exactly in any order:\n" + - " <[(1)]>\n" + + " [(1)]\n" + "elements not found:\n" + - " <(1)>\n" + + " (1)\n" + "and elements not expected:\n" + - " <(null)>\n"); + " (null)\n"); assertThatThrownBy(() -> assertThat(query("SELECT 1")).matches("SELECT CAST(null AS integer)")) - .hasMessage("[Rows for query [SELECT 1]] \n" + - "Expecting:\n" + - " <(1)>\n" + + .hasMessageContaining("[Rows for query [SELECT 1]] \n" + + "Expecting actual:\n" + + " (1)\n" + "to contain exactly in any order:\n" + - " <[(null)]>\n" + + " [(null)]\n" + "elements not found:\n" + - " <(null)>\n" + + " (null)\n" + "and elements not expected:\n" + - " <(1)>\n"); + " (1)\n"); } }