diff --git a/pom.xml b/pom.xml index fbe1a5e..97caeef 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ <groupId>org.ebyhr</groupId> <artifactId>trino-storage</artifactId> - <version>421-SNAPSHOT</version> + <version>422-SNAPSHOT</version> <description>Trino - Storage Connector</description> <packaging>trino-plugin</packaging> @@ -16,7 +16,7 @@ <parent> <groupId>io.airlift</groupId> <artifactId>airbase</artifactId> - <version>138</version> + <version>143</version> </parent> <licenses> @@ -37,15 +37,15 @@ <air.check.fail-checkstyle>true</air.check.fail-checkstyle> <air.check.skip-checkstyle>false</air.check.skip-checkstyle> - <dep.trino.version>420</dep.trino.version> - <dep.airlift.version>233</dep.airlift.version> + <dep.trino.version>422</dep.trino.version> + <dep.airlift.version>234</dep.airlift.version> <dep.packaging.version>${dep.airlift.version}</dep.packaging.version> - <dep.aws-sdk.version>1.12.477</dep.aws-sdk.version> - <dep.errorprone.version>2.20.0</dep.errorprone.version> - <dep.jackson.version>2.15.1</dep.jackson.version> + <dep.aws-sdk.version>1.12.522</dep.aws-sdk.version> + <dep.errorprone.version>2.21.0</dep.errorprone.version> + <dep.jackson.version>2.15.2</dep.jackson.version> <dep.testcontainers.version>1.18.3</dep.testcontainers.version> - <dep.docker-java.version>3.3.0</dep.docker-java.version> - <dep.testng.version>7.7.1</dep.testng.version> + <dep.docker-java.version>3.3.2</dep.docker-java.version> + <dep.testng.version>7.8.0</dep.testng.version> <dep.joda.version>2.12.5</dep.joda.version> <dep.opentelemetry.version>1.26.0</dep.opentelemetry.version> <dep.opentelemetry-instrumentation.version>1.25.1</dep.opentelemetry-instrumentation.version> @@ -76,7 +76,17 @@ <dependency> <groupId>net.bytebuddy</groupId> <artifactId>byte-buddy</artifactId> - <version>1.14.4</version> + <version>1.14.5</version> + </dependency> + <dependency> + <groupId>io.airlift</groupId> + <artifactId>slice</artifactId> + <version>0.45</version> + </dependency> + <dependency> + <groupId>org.openjdk.jol</groupId> + <artifactId>jol-core</artifactId> + <version>0.17</version> </dependency> </dependencies> </dependencyManagement> @@ -205,7 +215,7 @@ <groupId>io.trino.hadoop</groupId> <artifactId>hadoop-apache</artifactId> <scope>runtime</scope> - <version>3.2.0-18</version> + <version>3.3.5-1</version> </dependency> <dependency> @@ -229,7 +239,7 @@ <dependency> <groupId>io.airlift</groupId> <artifactId>units</artifactId> - <version>1.8</version> + <version>1.10</version> <scope>runtime</scope> </dependency> @@ -258,7 +268,6 @@ <dependency> <groupId>io.airlift</groupId> <artifactId>slice</artifactId> - <version>0.45</version> <scope>provided</scope> </dependency> @@ -287,7 +296,6 @@ <groupId>org.openjdk.jol</groupId> <artifactId>jol-core</artifactId> <scope>provided</scope> - <version>0.17</version> </dependency> <!-- for testing --> @@ -361,12 +369,6 @@ <scope>test</scope> </dependency> - <dependency> - <groupId>org.jetbrains.kotlin</groupId> - <artifactId>kotlin-stdlib-common</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers</artifactId> diff --git a/src/main/java/org/ebyhr/trino/storage/operator/JsonPlugin.java b/src/main/java/org/ebyhr/trino/storage/operator/JsonPlugin.java index cf2d400..178d8b7 100644 --- a/src/main/java/org/ebyhr/trino/storage/operator/JsonPlugin.java +++ b/src/main/java/org/ebyhr/trino/storage/operator/JsonPlugin.java @@ -21,6 +21,7 @@ import io.airlift.slice.Slice; import io.trino.spi.TrinoException; import io.trino.spi.block.BlockBuilder; +import io.trino.spi.block.RowBlockBuilder; import io.trino.spi.type.ArrayType; import io.trino.spi.type.BooleanType; import io.trino.spi.type.RowType; @@ -34,6 +35,7 @@ import java.io.UncheckedIOException; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -150,35 +152,43 @@ private List<?> nodeToRow(JsonNode node) private Object mapValue(JsonNode node) { - BlockBuilder values; switch (node.getNodeType()) { - case ARRAY: + case ARRAY -> { Iterator<JsonNode> elements = node.elements(); if (!elements.hasNext()) { throw new VerifyException("Cannot infer the SQL type of an empty JSON array"); } Type type = mapType(elements.next()); - values = type.createBlockBuilder(null, 10); + BlockBuilder values = type.createBlockBuilder(null, 10); node.elements().forEachRemaining(value -> writeObject(values, value)); return values.build(); - case BOOLEAN: + } + case BOOLEAN -> { return node.asBoolean(); - case NUMBER: + } + case NUMBER -> { return node.canConvertToLong() ? node.asLong() : node.asDouble(); - case OBJECT: + } + case OBJECT -> { Type rowType = mapType(node); - values = rowType.createBlockBuilder(null, 10); - BlockBuilder rowBuilder = values.beginBlockEntry(); - node.fields().forEachRemaining(field -> writeObject(rowBuilder, field.getValue())); - values.closeEntry(); - return rowType.getObject(values, values.getPositionCount() - 1); - case NULL: + RowBlockBuilder rowBlockBuilder = (RowBlockBuilder) rowType.createBlockBuilder(null, 10); + rowBlockBuilder.buildEntry(elementBuilder -> { + Iterator<Map.Entry<String, JsonNode>> fields = node.fields(); + for (int i = 0; fields.hasNext(); i++) { + writeObject(elementBuilder.get(i), fields.next().getValue()); + } + }); + return rowType.getObject(rowBlockBuilder, rowBlockBuilder.getPositionCount() - 1); + } + case NULL -> { return null; - case STRING: + } + case STRING -> { return node.asText(); - default: + } + default -> // BINARY, MISSING, POJO - throw new VerifyException("Unhandled JSON type: " + node.getNodeType()); + throw new VerifyException("Unhandled JSON type: " + node.getNodeType()); } } diff --git a/src/test/java/org/ebyhr/trino/storage/TestingHadoopServer.java b/src/test/java/org/ebyhr/trino/storage/TestingHadoopServer.java index 6f334d3..b0dd401 100644 --- a/src/test/java/org/ebyhr/trino/storage/TestingHadoopServer.java +++ b/src/test/java/org/ebyhr/trino/storage/TestingHadoopServer.java @@ -40,7 +40,7 @@ public class TestingHadoopServer public TestingHadoopServer(Network network) { - dockerContainer = new GenericContainer<>(DockerImageName.parse("ghcr.io/trinodb/testing/hdp2.6-hive:65")) + dockerContainer = new GenericContainer<>(DockerImageName.parse("ghcr.io/trinodb/testing/hdp2.6-hive:82")) .withCreateContainerCmdModifier(cmd -> cmd.withHostName(HOSTNAME)) .withCopyFileToContainer(MountableFile.forClasspathResource("minio/hive-core-site.xml"), "/etc/hadoop/conf/core-site.xml") .withStartupCheckStrategy(new IsRunningStartupCheckStrategy())