From e734f32d7e0ad5c73f68d14e4a6c515ba490eb66 Mon Sep 17 00:00:00 2001 From: david dali susanibar arce Date: Fri, 19 Jan 2024 19:31:35 -0500 Subject: [PATCH 1/8] feat: initial draft to enable spotless java maven --- java/format/pom.xml | 7 --- java/maven/pom.xml | 41 ----------------- java/pom.xml | 106 +++++++++++++++++++++++++------------------- 3 files changed, 60 insertions(+), 94 deletions(-) diff --git a/java/format/pom.xml b/java/format/pom.xml index 3f581311e20..e6b40f93589 100644 --- a/java/format/pom.xml +++ b/java/format/pom.xml @@ -33,13 +33,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - - true - - diff --git a/java/maven/pom.xml b/java/maven/pom.xml index 6e8a4cb0102..55435a33ac7 100644 --- a/java/maven/pom.xml +++ b/java/maven/pom.xml @@ -227,47 +227,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.1.0 - - - com.puppycrawl.tools - checkstyle - 8.19 - - - org.slf4j - jcl-over-slf4j - 2.0.11 - - - - - validate - validate - - check - - - - - ../dev/checkstyle/checkstyle.xml - ../dev/checkstyle/checkstyle.license - ../dev/checkstyle/suppressions.xml - true - UTF-8 - true - ${checkstyle.failOnViolation} - ${checkstyle.failOnViolation} - warning - xml - html - ${project.build.directory}/test/checkstyle-errors.xml - false - - org.cyclonedx cyclonedx-maven-plugin diff --git a/java/pom.xml b/java/pom.xml index 6fc4df67af3..42bb9843522 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -49,6 +49,7 @@ 5.5.0 5.2.0 3.42.0 + 2.42.0 @@ -297,46 +298,72 @@ - org.apache.maven.plugins - maven-checkstyle-plugin - 3.1.0 - - - com.puppycrawl.tools - checkstyle - 8.19 - - - org.slf4j - jcl-over-slf4j - ${dep.slf4j.version} - - + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + + src/**/*.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + src/main/**/*.java + src/test/**/*.java + + + ${maven.multiModuleProjectDirectory}/spotless/asf-java.license + (package|import) + + + + + src/main/**/*.* + src/test/**/*.* + + + src/**/*.jks + src/**/codegen/**/*.* + + + + + true + 2 + + + true + 2 + + + + + + + + + + false + + + - validate - validate + spotless-check check + validate - - **/module-info.java - dev/checkstyle/checkstyle.xml - dev/checkstyle/checkstyle.license - dev/checkstyle/suppressions.xml - true - UTF-8 - true - ${checkstyle.failOnViolation} - ${checkstyle.failOnViolation} - warning - xml - html - ${project.build.directory}/test/checkstyle-errors.xml - false - org.apache.maven.plugins @@ -562,19 +589,6 @@ - - - org.apache.maven.plugins - maven-checkstyle-plugin - [0,) - - check - - - - - - From 97e68f5e66d890c34dde89d0727fbc294a82b869 Mon Sep 17 00:00:00 2001 From: david dali susanibar arce Date: Fri, 19 Jan 2024 20:04:12 -0500 Subject: [PATCH 2/8] feat: initial draft to enable spotless java maven for base modules --- java/bom/pom.xml | 43 ++ java/maven/pom.xml | 62 +- java/pom.xml | 1218 ++++++++++++++++---------------- java/spotless/asf-java.license | 17 + java/spotless/asf-xml.license | 11 + 5 files changed, 730 insertions(+), 621 deletions(-) create mode 100644 java/spotless/asf-java.license create mode 100644 java/spotless/asf-xml.license diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 7ffb833e7f6..e435630c778 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -27,6 +27,7 @@ + 2.42.0 @@ -153,6 +154,48 @@ maven-site-plugin 3.7.1 + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + + pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + diff --git a/java/maven/pom.xml b/java/maven/pom.xml index 55435a33ac7..ee59908a828 100644 --- a/java/maven/pom.xml +++ b/java/maven/pom.xml @@ -1,4 +1,4 @@ - + + + + + + src/main/**/*.xml + src/test/**/*.xml + **/pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + true + 2 + + + true + 2 + + + + ${maven.multiModuleProjectDirectory}/spotless/asf-java.license + (package|import) + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + diff --git a/java/pom.xml b/java/pom.xml index 42bb9843522..e610ba8dbdb 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -27,38 +27,6 @@ Apache Arrow is open source, in-memory columnar data structures and low-overhead messaging https://arrow.apache.org/ - - ${project.build.directory}/generated-sources - 1.9.0 - 5.10.1 - 2.0.11 - 33.0.0-jre - 4.1.105.Final - 1.60.0 - 3.23.1 - 2.16.0 - 2.7.1 - 23.5.26 - 1.11.3 - - 2 - true - 9+181-r4173-1 - 2.24.0 - 3.11.0 - 5.5.0 - 5.2.0 - 3.42.0 - 2.42.0 - - - - scm:git:https://github.com/apache/arrow.git - scm:git:https://github.com/apache/arrow.git - https://github.com/apache/arrow - apache-arrow-2.0.0 - - Developer List @@ -82,354 +50,226 @@ - + + maven + bom + format + memory + vector + tools + adapter/jdbc + flight + performance + algorithm + adapter/avro + compression + - + + scm:git:https://github.com/apache/arrow.git + scm:git:https://github.com/apache/arrow.git + apache-arrow-2.0.0 + https://github.com/apache/arrow + Jira https://issues.apache.org/jira/browse/arrow - - - - - kr.motd.maven - os-maven-plugin - 1.7.0 - - + + ${project.build.directory}/generated-sources + 1.9.0 + 5.10.1 + 2.0.11 + 33.0.0-jre + 4.1.105.Final + 1.60.0 + 3.23.1 + 2.16.0 + 2.7.1 + 23.5.26 + 1.11.3 + + 2 + true + 9+181-r4173-1 + 2.24.0 + 3.11.0 + 5.5.0 + 5.2.0 + 3.42.0 + 2.42.0 + - - - org.apache.rat - apache-rat-plugin - - - rat-checks - validate - - check - - - - - false - - **/dependency-reduced-pom.xml - **/*.log - **/*.css - **/*.js - **/*.md - **/*.eps - **/*.json - **/*.seq - **/*.parquet - **/*.sql - **/arrow-git.properties - **/*.csv - **/*.csvh - **/*.csvh-test - **/*.tsv - **/*.txt - **/*.ssv - **/arrow-*.conf - **/.buildpath - **/*.proto - **/*.fmpp - **/target/** - **/*.tdd - **/*.project - **/TAGS - **/*.checkstyle - **/.classpath - **/.factorypath - **/.settings/** - .*/** - **/*.patch - **/*.pb.cc - **/*.pb.h - **/*.linux - **/client/build/** - **/*.tbl - **/*.iml - **/flight.properties - **/*.idea/** - - - + + + + + org.apache.arrow + arrow-bom + ${project.version} + pom + import + + + org.checkerframework + checker-qual + ${checker.framework.version} + + + com.google.flatbuffers + flatbuffers-java + ${dep.fbs.version} + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + org.slf4j + slf4j-api + ${dep.slf4j.version} + + + javax.annotation + javax.annotation-api + 1.3.2 + + + org.assertj + assertj-core + 3.24.2 + test + + + org.immutables + value + 2.8.2 + provided + + + org.hamcrest + hamcrest + 2.2 + + + com.fasterxml.jackson + jackson-bom + ${dep.jackson-bom.version} + pom + import + + + com.google.guava + guava-bom + ${dep.guava-bom.version} + pom + import + + + io.netty + netty-bom + ${dep.netty-bom.version} + pom + import + + + io.grpc + grpc-bom + ${dep.grpc-bom.version} + pom + import + + + com.google.protobuf + protobuf-bom + ${dep.protobuf-bom.version} + pom + import + + + - - org.apache.maven.plugins - maven-jar-plugin - - - **/logging.properties - **/logback-test.xml - **/logback.out.xml - **/logback.xml - - - true - - true - true - - - org.apache.arrow - ${username} - https://arrow.apache.org/ - - - - - - - test-jar - - - true - - - - + + + + org.slf4j + jul-to-slf4j + ${dep.slf4j.version} + test + + + + org.slf4j + jcl-over-slf4j + ${dep.slf4j.version} + test + + + + org.slf4j + log4j-over-slf4j + ${dep.slf4j.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${dep.junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${dep.junit.jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${dep.junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${dep.junit.jupiter.version} + test + + + + junit + junit + 4.13.1 + test + + + org.mockito + mockito-junit-jupiter + 2.25.1 + test + + + ch.qos.logback + logback-classic + 1.3.14 + test + + + de.huxhorn.lilith + de.huxhorn.lilith.logback.appender.multiplex-classic + 0.9.44 + test + - - org.apache.maven.plugins - maven-resources-plugin - - UTF-8 - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - 2048m - false - true - - - - maven-enforcer-plugin - - - validate_java_and_maven_version - verify - - enforce - - false - - - - [3.3.0,4) - - - - - - avoid_bad_dependencies - verify - - enforce - - - - - - commons-logging - javax.servlet:servlet-api - org.mortbay.jetty:servlet-api - org.mortbay.jetty:servlet-api-2.5 - log4j:log4j - - - - - - - - - pl.project13.maven - git-commit-id-plugin - 4.0.5 - - - for-jars - true - - revision - - - target/classes/arrow-git.properties - - - - for-source-tarball - - revision - - false - - ./arrow-git.properties - - - + - - dd.MM.yyyy '@' HH:mm:ss z - false - false - true - false - - false - false - 7 - -dirty - true - - - + - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version} - - - - - - - src/**/*.xml - - - ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license - (<configuration|<project) - - - - - src/main/**/*.java - src/test/**/*.java - - - ${maven.multiModuleProjectDirectory}/spotless/asf-java.license - (package|import) - - - - - src/main/**/*.* - src/test/**/*.* - - - src/**/*.jks - src/**/codegen/**/*.* - - - - - true - 2 - - - true - 2 - - - - - - - - - - false - - - - - - spotless-check - - check - - validate - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - analyze - verify - - analyze-only - - - true - true - - - javax.annotation:javax.annotation-api:* - org.apache.hadoop:hadoop-client-api - org.checkerframework:checker-qual - - - - - - - org.cyclonedx - cyclonedx-maven-plugin - 2.7.10 - - - package - - makeBom - - - - - - org.apache.arrow.maven.plugins - module-info-compiler-maven-plugin - - - default-compile - - compile - - - - default-testCompile - - testCompile - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - + @@ -482,18 +322,6 @@ maven-surefire-plugin 3.2.3 - - - org.junit.jupiter - junit-jupiter-engine - ${dep.junit.jupiter.version} - - - org.apache.maven.surefire - surefire-junit-platform - 3.2.3 - - true true @@ -508,6 +336,18 @@ 1048576 + + + org.junit.jupiter + junit-jupiter-engine + ${dep.junit.jupiter.version} + + + org.apache.maven.surefire + surefire-junit-platform + 3.2.3 + + maven-failsafe-plugin @@ -545,7 +385,7 @@ - + @@ -558,22 +398,20 @@ - + org.apache.maven.plugins - - maven-remote-resources-plugin - + maven-remote-resources-plugin [1.1,) process - + @@ -586,7 +424,7 @@ - + @@ -621,172 +459,342 @@ - - - - - - - org.apache.arrow - arrow-bom - ${project.version} - pom - import - - - org.checkerframework - checker-qual - ${checker.framework.version} - - - com.google.flatbuffers - flatbuffers-java - ${dep.fbs.version} - - - com.google.code.findbugs - jsr305 - 3.0.2 - - - org.slf4j - slf4j-api - ${dep.slf4j.version} - - - javax.annotation - javax.annotation-api - 1.3.2 - - - org.assertj - assertj-core - 3.24.2 - test - - - org.immutables - value - 2.8.2 - provided - - - org.hamcrest - hamcrest - 2.2 - - - com.fasterxml.jackson - jackson-bom - ${dep.jackson-bom.version} - pom - import - - - com.google.guava - guava-bom - ${dep.guava-bom.version} - pom - import - - - io.netty - netty-bom - ${dep.netty-bom.version} - pom - import - - - io.grpc - grpc-bom - ${dep.grpc-bom.version} - pom - import - - - com.google.protobuf - protobuf-bom - ${dep.protobuf-bom.version} - pom - import - - - - - - - org.slf4j - jul-to-slf4j - ${dep.slf4j.version} - test - + + + org.apache.rat + apache-rat-plugin + + false + + **/dependency-reduced-pom.xml + **/*.log + **/*.css + **/*.js + **/*.md + **/*.eps + **/*.json + **/*.seq + **/*.parquet + **/*.sql + **/arrow-git.properties + **/*.csv + **/*.csvh + **/*.csvh-test + **/*.tsv + **/*.txt + **/*.ssv + **/arrow-*.conf + **/.buildpath + **/*.proto + **/*.fmpp + **/target/** + **/*.tdd + **/*.project + **/TAGS + **/*.checkstyle + **/.classpath + **/.factorypath + **/.settings/** + .*/** + **/*.patch + **/*.pb.cc + **/*.pb.h + **/*.linux + **/client/build/** + **/*.tbl + **/*.iml + **/flight.properties + **/*.idea/** + + + + + rat-checks + + check + + validate + + + - - org.slf4j - jcl-over-slf4j - ${dep.slf4j.version} - test - + + org.apache.maven.plugins + maven-jar-plugin + + + **/logging.properties + **/logback-test.xml + **/logback.out.xml + **/logback.xml + + + true + + true + true + + + org.apache.arrow + ${username} + https://arrow.apache.org/ + + + + + + + test-jar + + + true + + + + - - org.slf4j - log4j-over-slf4j - ${dep.slf4j.version} - test - + + org.apache.maven.plugins + maven-resources-plugin + + UTF-8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + 2048m + false + true + + + + maven-enforcer-plugin + + + validate_java_and_maven_version + + enforce + + verify + false + + + + [3.3.0,4) + + + + + + avoid_bad_dependencies + + enforce + + verify + + + + + commons-logging + javax.servlet:servlet-api + org.mortbay.jetty:servlet-api + org.mortbay.jetty:servlet-api-2.5 + log4j:log4j + + + + + + + + + pl.project13.maven + git-commit-id-plugin + 4.0.5 - - org.junit.jupiter - junit-jupiter-engine - ${dep.junit.jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-api - ${dep.junit.jupiter.version} - test - - - org.junit.vintage - junit-vintage-engine - ${dep.junit.jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-params - ${dep.junit.jupiter.version} - test - - - - junit - junit - 4.13.1 - test - - - org.mockito - mockito-junit-jupiter - 2.25.1 - test - - - ch.qos.logback - logback-classic - 1.3.14 - test - - - de.huxhorn.lilith - de.huxhorn.lilith.logback.appender.multiplex-classic - 0.9.44 - test - + + dd.MM.yyyy '@' HH:mm:ss z + false + false + true + false + + false + false + 7 + -dirty + true + + + + + for-jars + + revision + + true + + target/classes/arrow-git.properties + + + + for-source-tarball + + revision + + false + + ./arrow-git.properties + + + + - + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + + + src/main/**/*.xml + src/test/**/*.xml + **/pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + src/**/Preconditions.java + src/main/codegen/**/*.* + src/main/java/org/apache/arrow/flatbuf/*.java + + + true + 2 + + + true + 2 + + + + + ${maven.multiModuleProjectDirectory}/spotless/asf-java.license + (package|import) + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + analyze + + analyze-only + + verify + + true + true + + + javax.annotation:javax.annotation-api:* + org.apache.hadoop:hadoop-client-api + org.checkerframework:checker-qual + + + + + + + org.cyclonedx + cyclonedx-maven-plugin + 2.7.10 + + + + makeBom + + package + + + + + org.apache.arrow.maven.plugins + module-info-compiler-maven-plugin + + + default-compile + + compile + + + + default-testCompile + + testCompile + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + + + + kr.motd.maven + os-maven-plugin + 1.7.0 + + + @@ -794,25 +802,29 @@ org.apache.maven.plugins maven-javadoc-plugin 3.6.3 + + + **/module-info.java + + - - + + + + javadoc - + + aggregate - false + aggregate + false - - - **/module-info.java - - org.apache.maven.plugins @@ -827,21 +839,6 @@ - - maven - bom - format - memory - vector - tools - adapter/jdbc - flight - performance - algorithm - adapter/avro - compression - - java-nodoclint @@ -885,9 +882,9 @@ error-prone-jdk8 1.8 @@ -1010,11 +1007,12 @@ 0.8.11 - false + report + false @@ -1056,35 +1054,31 @@ cdata-cmake - generate-resources exec + generate-resources cmake - - -S java + -S java -B java-jni -DARROW_JAVA_JNI_ENABLE_C=ON -DARROW_JAVA_JNI_ENABLE_DEFAULT=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX=${arrow.c.jni.dist.dir} - + -DCMAKE_INSTALL_PREFIX=${arrow.c.jni.dist.dir} ../ cdata-build - generate-resources exec + generate-resources cmake - - --build java-jni --target install --config Release - + --build java-jni --target install --config Release ../ @@ -1117,14 +1111,13 @@ jni-cpp-cmake - generate-resources exec + generate-resources cmake - - -S cpp + -S cpp -B cpp-jni -DARROW_BUILD_SHARED=OFF -DARROW_CSV=${ARROW_DATASET} @@ -1142,37 +1135,33 @@ -DARROW_USE_CCACHE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=java-dist - -DCMAKE_UNITY_BUILD=ON - + -DCMAKE_UNITY_BUILD=ON ../ ${cpp.dependencies.builded} jni-cpp-build - generate-resources exec + generate-resources cmake - - --build cpp-jni --target install --config Release - + --build cpp-jni --target install --config Release ../ ${cpp.dependencies.builded} jni-cmake - generate-resources exec + generate-resources cmake - - -S java + -S java -B java-jni -DARROW_JAVA_JNI_ENABLE_C=${ARROW_JAVA_JNI_ENABLE_C} -DARROW_JAVA_JNI_ENABLE_DATASET=${ARROW_JAVA_JNI_ENABLE_DATASET} @@ -1184,22 +1173,19 @@ -DCMAKE_INSTALL_PREFIX=${arrow.dataset.jni.dist.dir} -DCMAKE_PREFIX_PATH=${project.basedir}/../java-dist/lib/${os.detected.arch}/cmake -DProtobuf_USE_STATIC_LIBS=ON - -DProtobuf_ROOT=${project.basedir}/../cpp-jni/protobuf_ep-install - + -DProtobuf_ROOT=${project.basedir}/../cpp-jni/protobuf_ep-install ../ jni-build - generate-resources exec + generate-resources cmake - - --build java-jni --target install --config Release - + --build java-jni --target install --config Release ../ @@ -1232,14 +1218,13 @@ jni-cpp-cmake - generate-resources exec + generate-resources cmake - - -S cpp + -S cpp -B cpp-jni -DARROW_BUILD_SHARED=OFF -DARROW_CSV=${ARROW_DATASET} @@ -1261,37 +1246,33 @@ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=java-dist -DCMAKE_UNITY_BUILD=ON - -GNinja - + -GNinja ../ ${cpp.dependencies.builded} jni-cpp-build - generate-resources exec + generate-resources ninja - - install - + install ../cpp-jni ${cpp.dependencies.builded} jni-cmake - generate-resources exec + generate-resources cmake - - -S java + -S java -B java-jni -DARROW_JAVA_JNI_ENABLE_C=${ARROW_JAVA_JNI_ENABLE_C} -DARROW_JAVA_JNI_ENABLE_DATASET=${ARROW_JAVA_JNI_ENABLE_DATASET} @@ -1301,22 +1282,19 @@ -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${arrow.dataset.jni.dist.dir} - -DCMAKE_PREFIX_PATH=${project.basedir}/../java-dist/lib/${os.detected.arch}/cmake - + -DCMAKE_PREFIX_PATH=${project.basedir}/../java-dist/lib/${os.detected.arch}/cmake ../ jni-build - generate-resources exec + generate-resources cmake - - --build java-jni --target install --config Release - + --build java-jni --target install --config Release ../ diff --git a/java/spotless/asf-java.license b/java/spotless/asf-java.license new file mode 100644 index 00000000000..29400e587da --- /dev/null +++ b/java/spotless/asf-java.license @@ -0,0 +1,17 @@ +/* + * 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. + */ + diff --git a/java/spotless/asf-xml.license b/java/spotless/asf-xml.license new file mode 100644 index 00000000000..a43b97bca8f --- /dev/null +++ b/java/spotless/asf-xml.license @@ -0,0 +1,11 @@ + + \ No newline at end of file From 32aea30b4aca9bf225530ab67fd459c1a665cf36 Mon Sep 17 00:00:00 2001 From: david dali susanibar arce Date: Fri, 19 Jan 2024 20:11:27 -0500 Subject: [PATCH 3/8] fix: automatically fix applied by mvn spotless:apply --- java/adapter/avro/pom.xml | 19 +- .../arrow/adapter/avro/AvroToArrow.java | 14 +- .../arrow/adapter/avro/AvroToArrowConfig.java | 25 +- .../avro/AvroToArrowConfigBuilder.java | 19 +- .../arrow/adapter/avro/AvroToArrowUtils.java | 291 ++-- .../avro/AvroToArrowVectorIterator.java | 38 +- .../avro/consumers/AvroArraysConsumer.java | 8 +- .../avro/consumers/AvroBooleanConsumer.java | 9 +- .../avro/consumers/AvroBytesConsumer.java | 9 +- .../avro/consumers/AvroDoubleConsumer.java | 9 +- .../avro/consumers/AvroEnumConsumer.java | 8 +- .../avro/consumers/AvroFixedConsumer.java | 9 +- .../avro/consumers/AvroFloatConsumer.java | 9 +- .../avro/consumers/AvroIntConsumer.java | 8 +- .../avro/consumers/AvroLongConsumer.java | 9 +- .../avro/consumers/AvroMapConsumer.java | 8 +- .../avro/consumers/AvroNullConsumer.java | 5 +- .../avro/consumers/AvroStringConsumer.java | 9 +- .../avro/consumers/AvroStructConsumer.java | 10 +- .../avro/consumers/AvroUnionsConsumer.java | 12 +- .../avro/consumers/BaseAvroConsumer.java | 2 + .../avro/consumers/CompositeAvroConsumer.java | 14 +- .../adapter/avro/consumers/Consumer.java | 25 +- .../adapter/avro/consumers/SkipConsumer.java | 14 +- .../adapter/avro/consumers/SkipFunction.java | 5 +- .../consumers/logical/AvroDateConsumer.java | 9 +- .../logical/AvroDecimalConsumer.java | 26 +- .../logical/AvroTimeMicroConsumer.java | 9 +- .../logical/AvroTimeMillisConsumer.java | 9 +- .../logical/AvroTimestampMicrosConsumer.java | 9 +- .../logical/AvroTimestampMillisConsumer.java | 9 +- .../adapter/avro/AvroLogicalTypesTest.java | 50 +- .../arrow/adapter/avro/AvroSkipFieldTest.java | 109 +- .../arrow/adapter/avro/AvroTestBase.java | 47 +- .../adapter/avro/AvroToArrowIteratorTest.java | 50 +- .../arrow/adapter/avro/AvroToArrowTest.java | 57 +- .../adapter/avro/TestWriteReadAvroRecord.java | 14 +- .../avro/src/test/resources/logback.xml | 3 +- java/adapter/jdbc/pom.xml | 19 +- .../adapter/jdbc/ArrowVectorIterator.java | 48 +- .../apache/arrow/adapter/jdbc/Constants.java | 5 +- .../arrow/adapter/jdbc/JdbcFieldInfo.java | 73 +- .../adapter/jdbc/JdbcParameterBinder.java | 35 +- .../arrow/adapter/jdbc/JdbcToArrow.java | 66 +- .../arrow/adapter/jdbc/JdbcToArrowConfig.java | 259 ++-- .../jdbc/JdbcToArrowConfigBuilder.java | 129 +- .../arrow/adapter/jdbc/JdbcToArrowUtils.java | 195 ++- .../adapter/jdbc/binder/BaseColumnBinder.java | 1 + .../adapter/jdbc/binder/BigIntBinder.java | 4 +- .../arrow/adapter/jdbc/binder/BitBinder.java | 4 +- .../adapter/jdbc/binder/ColumnBinder.java | 16 +- .../binder/ColumnBinderArrowTypeVisitor.java | 102 +- .../adapter/jdbc/binder/DateDayBinder.java | 8 +- .../adapter/jdbc/binder/DateMilliBinder.java | 9 +- .../adapter/jdbc/binder/Decimal128Binder.java | 13 +- .../adapter/jdbc/binder/Decimal256Binder.java | 13 +- .../jdbc/binder/FixedSizeBinaryBinder.java | 14 +- .../adapter/jdbc/binder/Float4Binder.java | 8 +- .../adapter/jdbc/binder/Float8Binder.java | 11 +- .../arrow/adapter/jdbc/binder/IntBinder.java | 4 +- .../arrow/adapter/jdbc/binder/ListBinder.java | 16 +- .../arrow/adapter/jdbc/binder/MapBinder.java | 18 +- .../jdbc/binder/NullableColumnBinder.java | 8 +- .../adapter/jdbc/binder/SmallIntBinder.java | 7 +- .../adapter/jdbc/binder/Time32Binder.java | 12 +- .../adapter/jdbc/binder/Time64Binder.java | 12 +- .../adapter/jdbc/binder/TimeStampBinder.java | 23 +- .../adapter/jdbc/binder/TinyIntBinder.java | 4 +- .../adapter/jdbc/binder/VarBinaryBinder.java | 15 +- .../adapter/jdbc/binder/VarCharBinder.java | 15 +- .../adapter/jdbc/binder/package-info.java | 5 +- .../adapter/jdbc/consumer/ArrayConsumer.java | 31 +- .../adapter/jdbc/consumer/BaseConsumer.java | 2 + .../adapter/jdbc/consumer/BigIntConsumer.java | 28 +- .../adapter/jdbc/consumer/BinaryConsumer.java | 38 +- .../adapter/jdbc/consumer/BitConsumer.java | 28 +- .../adapter/jdbc/consumer/BlobConsumer.java | 16 +- .../adapter/jdbc/consumer/ClobConsumer.java | 53 +- .../jdbc/consumer/CompositeJdbcConsumer.java | 26 +- .../adapter/jdbc/consumer/DateConsumer.java | 51 +- .../jdbc/consumer/Decimal256Consumer.java | 50 +- .../jdbc/consumer/DecimalConsumer.java | 47 +- .../adapter/jdbc/consumer/DoubleConsumer.java | 28 +- .../adapter/jdbc/consumer/FloatConsumer.java | 28 +- .../adapter/jdbc/consumer/IntConsumer.java | 28 +- .../adapter/jdbc/consumer/JdbcConsumer.java | 14 +- .../adapter/jdbc/consumer/MapConsumer.java | 64 +- .../adapter/jdbc/consumer/NullConsumer.java | 8 +- .../jdbc/consumer/SmallIntConsumer.java | 28 +- .../adapter/jdbc/consumer/TimeConsumer.java | 51 +- .../jdbc/consumer/TimestampConsumer.java | 27 +- .../jdbc/consumer/TimestampTZConsumer.java | 31 +- .../jdbc/consumer/TinyIntConsumer.java | 28 +- .../jdbc/consumer/VarCharConsumer.java | 28 +- .../exceptions/JdbcConsumerException.java | 11 +- .../adapter/jdbc/AbstractJdbcToArrowTest.java | 197 +-- .../arrow/adapter/jdbc/JdbcFieldInfoTest.java | 1 - .../adapter/jdbc/JdbcParameterBinderTest.java | 571 ++++--- .../jdbc/JdbcToArrowCommentMetadataTest.java | 175 ++- .../adapter/jdbc/JdbcToArrowConfigTest.java | 28 +- .../adapter/jdbc/JdbcToArrowTestHelper.java | 75 +- .../arrow/adapter/jdbc/ResultSetUtility.java | 82 +- .../adapter/jdbc/ResultSetUtilityTest.java | 22 +- .../org/apache/arrow/adapter/jdbc/Table.java | 10 +- .../adapter/jdbc/UnreliableMetaDataTest.java | 142 +- .../jdbc/consumer/AbstractConsumerTest.java | 1 - .../jdbc/consumer/BinaryConsumerTest.java | 93 +- .../adapter/jdbc/h2/JdbcAliasToArrowTest.java | 21 +- .../adapter/jdbc/h2/JdbcToArrowArrayTest.java | 81 +- .../jdbc/h2/JdbcToArrowCharSetTest.java | 81 +- .../jdbc/h2/JdbcToArrowDataTypesTest.java | 137 +- .../jdbc/h2/JdbcToArrowMapDataTypeTest.java | 39 +- .../adapter/jdbc/h2/JdbcToArrowNullTest.java | 169 +- .../h2/JdbcToArrowOptionalColumnsTest.java | 25 +- .../adapter/jdbc/h2/JdbcToArrowTest.java | 177 ++- .../jdbc/h2/JdbcToArrowTimeZoneTest.java | 81 +- .../h2/JdbcToArrowVectorIteratorTest.java | 193 ++- .../jdbc/src/test/resources/logback.xml | 3 +- java/adapter/orc/pom.xml | 19 +- java/algorithm/pom.xml | 2 +- .../deduplicate/DeduplicationUtils.java | 15 +- .../deduplicate/VectorRunDeduplicator.java | 26 +- .../dictionary/DictionaryBuilder.java | 29 +- .../dictionary/DictionaryEncoder.java | 10 +- .../HashTableBasedDictionaryBuilder.java | 33 +- .../HashTableDictionaryEncoder.java | 68 +- .../dictionary/LinearDictionaryEncoder.java | 43 +- .../dictionary/SearchDictionaryEncoder.java | 40 +- .../SearchTreeBasedDictionaryBuilder.java | 45 +- .../arrow/algorithm/misc/PartialSumUtils.java | 40 +- .../arrow/algorithm/rank/VectorRank.java | 14 +- .../algorithm/search/ParallelSearcher.java | 180 ++- .../algorithm/search/VectorRangeSearcher.java | 214 ++- .../algorithm/search/VectorSearcher.java | 25 +- .../sort/CompositeVectorComparator.java | 16 +- .../sort/DefaultVectorComparators.java | 125 +- .../sort/FixedWidthInPlaceVectorSorter.java | 24 +- .../FixedWidthOutOfPlaceVectorSorter.java | 34 +- .../sort/GeneralOutOfPlaceVectorSorter.java | 19 +- .../algorithm/sort/InPlaceVectorSorter.java | 6 +- .../arrow/algorithm/sort/IndexSorter.java | 32 +- .../arrow/algorithm/sort/InsertionSorter.java | 22 +- .../arrow/algorithm/sort/OffHeapIntStack.java | 4 +- .../sort/OutOfPlaceVectorSorter.java | 7 +- .../sort/StableVectorComparator.java | 12 +- .../VariableWidthOutOfPlaceVectorSorter.java | 50 +- .../algorithm/sort/VectorValueComparator.java | 55 +- .../deduplicate/TestDeduplicationUtils.java | 44 +- .../TestVectorRunDeduplicator.java | 17 +- .../TestHashTableBasedDictionaryBuilder.java | 22 +- .../TestHashTableDictionaryEncoder.java | 60 +- .../TestLinearDictionaryEncoder.java | 60 +- .../TestSearchDictionaryEncoder.java | 72 +- .../TestSearchTreeBasedDictionaryBuilder.java | 40 +- .../algorithm/misc/TestPartialSumUtils.java | 17 +- .../arrow/algorithm/rank/TestVectorRank.java | 18 +- .../search/TestParallelSearcher.java | 35 +- .../search/TestVectorRangeSearcher.java | 29 +- .../algorithm/search/TestVectorSearcher.java | 28 +- .../sort/TestCompositeVectorComparator.java | 17 +- .../sort/TestDefaultVectorComparator.java | 165 +- .../TestFixedWidthInPlaceVectorSorter.java | 47 +- .../TestFixedWidthOutOfPlaceVectorSorter.java | 68 +- .../algorithm/sort/TestFixedWidthSorting.java | 125 +- .../TestGeneralOutOfPlaceVectorSorter.java | 78 +- .../arrow/algorithm/sort/TestIndexSorter.java | 30 +- .../algorithm/sort/TestInsertionSorter.java | 8 +- .../algorithm/sort/TestOffHeapIntStack.java | 4 +- .../sort/TestOutOfPlaceVectorSorter.java | 5 +- .../arrow/algorithm/sort/TestSortingUtil.java | 135 +- .../sort/TestStableVectorComparator.java | 17 +- ...stVariableWidthOutOfPlaceVectorSorter.java | 13 +- .../sort/TestVariableWidthSorting.java | 40 +- java/algorithm/src/test/resources/logback.xml | 3 +- java/compression/pom.xml | 2 +- .../CommonsCompressionFactory.java | 2 +- .../compression/Lz4CompressionCodec.java | 30 +- .../compression/ZstdCompressionCodec.java | 36 +- .../TestArrowReaderWriterWithCompression.java | 31 +- .../compression/TestCompressionCodec.java | 178 ++- .../src/test/resources/logback.xml | 3 +- java/flight/flight-core/pom.xml | 2 +- .../java/org/apache/arrow/flight/Action.java | 3 +- .../org/apache/arrow/flight/ActionType.java | 22 +- .../org/apache/arrow/flight/ArrowMessage.java | 229 +-- .../apache/arrow/flight/AsyncPutListener.java | 12 +- .../arrow/flight/BackpressureStrategy.java | 64 +- .../org/apache/arrow/flight/CallHeaders.java | 20 +- .../org/apache/arrow/flight/CallInfo.java | 4 +- .../org/apache/arrow/flight/CallOption.java | 7 +- .../org/apache/arrow/flight/CallOptions.java | 11 +- .../org/apache/arrow/flight/CallStatus.java | 62 +- .../arrow/flight/CancelFlightInfoRequest.java | 10 +- .../arrow/flight/CancelFlightInfoResult.java | 15 +- .../org/apache/arrow/flight/CancelStatus.java | 19 +- .../org/apache/arrow/flight/Criteria.java | 7 +- .../apache/arrow/flight/DictionaryUtils.java | 56 +- .../arrow/flight/ErrorFlightMetadata.java | 18 +- .../arrow/flight/FlightBindingService.java | 97 +- .../arrow/flight/FlightCallHeaders.java | 23 +- .../org/apache/arrow/flight/FlightClient.java | 394 ++--- .../arrow/flight/FlightClientMiddleware.java | 19 +- .../apache/arrow/flight/FlightConstants.java | 24 +- .../apache/arrow/flight/FlightDescriptor.java | 25 +- .../apache/arrow/flight/FlightEndpoint.java | 92 +- .../apache/arrow/flight/FlightGrpcUtils.java | 54 +- .../org/apache/arrow/flight/FlightInfo.java | 151 +- .../org/apache/arrow/flight/FlightMethod.java | 4 +- .../apache/arrow/flight/FlightProducer.java | 69 +- .../arrow/flight/FlightRuntimeException.java | 8 +- .../org/apache/arrow/flight/FlightServer.java | 255 +-- .../arrow/flight/FlightServerMiddleware.java | 42 +- .../apache/arrow/flight/FlightService.java | 216 +-- .../apache/arrow/flight/FlightStatusCode.java | 56 +- .../org/apache/arrow/flight/FlightStream.java | 245 +-- .../apache/arrow/flight/HeaderCallOption.java | 8 +- .../org/apache/arrow/flight/Location.java | 53 +- .../apache/arrow/flight/LocationSchemes.java | 4 +- .../arrow/flight/NoOpFlightProducer.java | 37 +- .../arrow/flight/NoOpStreamListener.java | 10 +- .../arrow/flight/OutboundStreamListener.java | 57 +- .../flight/OutboundStreamListenerImpl.java | 42 +- .../org/apache/arrow/flight/PollInfo.java | 70 +- .../org/apache/arrow/flight/PutResult.java | 27 +- .../flight/RenewFlightEndpointRequest.java | 10 +- .../apache/arrow/flight/RequestContext.java | 8 +- .../java/org/apache/arrow/flight/Result.java | 7 +- .../org/apache/arrow/flight/SchemaResult.java | 32 +- .../arrow/flight/ServerHeaderMiddleware.java | 32 +- .../org/apache/arrow/flight/StreamPipe.java | 20 +- .../apache/arrow/flight/SyncPutListener.java | 31 +- .../java/org/apache/arrow/flight/Ticket.java | 20 +- .../arrow/flight/auth/AuthConstants.java | 43 +- .../flight/auth/BasicClientAuthHandler.java | 6 +- .../flight/auth/BasicServerAuthHandler.java | 13 +- .../arrow/flight/auth/ClientAuthHandler.java | 24 +- .../flight/auth/ClientAuthInterceptor.java | 15 +- .../arrow/flight/auth/ClientAuthWrapper.java | 91 +- .../arrow/flight/auth/ServerAuthHandler.java | 38 +- .../flight/auth/ServerAuthInterceptor.java | 36 +- .../arrow/flight/auth/ServerAuthWrapper.java | 93 +- .../arrow/flight/auth2/Auth2Constants.java | 7 +- .../arrow/flight/auth2/AuthUtilities.java | 11 +- .../auth2/BasicAuthCredentialWriter.java | 13 +- .../auth2/BasicCallHeaderAuthenticator.java | 22 +- .../flight/auth2/BearerCredentialWriter.java | 8 +- .../auth2/BearerTokenAuthenticator.java | 9 +- .../flight/auth2/CallHeaderAuthenticator.java | 55 +- .../auth2/ClientBearerHeaderHandler.java | 10 +- .../flight/auth2/ClientHandshakeWrapper.java | 19 +- .../flight/auth2/ClientHeaderHandler.java | 25 +- .../ClientIncomingAuthHeaderMiddleware.java | 20 +- .../GeneratedBearerTokenAuthenticator.java | 62 +- .../auth2/ServerCallHeaderAuthMiddleware.java | 22 +- .../flight/client/ClientCookieMiddleware.java | 53 +- .../arrow/flight/grpc/AddWritableBuffer.java | 29 +- .../flight/grpc/CallCredentialAdapter.java | 25 +- .../flight/grpc/ClientInterceptorAdapter.java | 52 +- .../ContextPropagatingExecutorService.java | 32 +- .../flight/grpc/CredentialCallOption.java | 8 +- .../arrow/flight/grpc/GetReadableBuffer.java | 25 +- .../arrow/flight/grpc/MetadataAdapter.java | 12 +- .../flight/grpc/RequestContextAdapter.java | 14 +- .../flight/grpc/ServerInterceptorAdapter.java | 126 +- .../apache/arrow/flight/grpc/StatusUtils.java | 63 +- .../apache/arrow/flight/FlightTestUtil.java | 26 +- .../arrow/flight/TestApplicationMetadata.java | 308 ++-- .../org/apache/arrow/flight/TestAuth.java | 82 +- .../apache/arrow/flight/TestBackPressure.java | 183 +-- .../arrow/flight/TestBasicOperation.java | 551 ++++--- .../apache/arrow/flight/TestCallOptions.java | 121 +- .../arrow/flight/TestClientMiddleware.java | 169 +- .../arrow/flight/TestDictionaryUtils.java | 25 +- .../apache/arrow/flight/TestDoExchange.java | 139 +- .../arrow/flight/TestErrorMetadata.java | 103 +- .../apache/arrow/flight/TestFlightClient.java | 122 +- .../arrow/flight/TestFlightGrpcUtils.java | 110 +- .../arrow/flight/TestFlightService.java | 139 +- .../apache/arrow/flight/TestLargeMessage.java | 63 +- .../org/apache/arrow/flight/TestLeak.java | 127 +- .../arrow/flight/TestMetadataVersion.java | 128 +- .../arrow/flight/TestServerMiddleware.java | 162 +- .../arrow/flight/TestServerOptions.java | 147 +- .../java/org/apache/arrow/flight/TestTls.java | 130 +- .../arrow/flight/auth/TestBasicAuth.java | 124 +- .../arrow/flight/auth2/TestBasicAuth2.java | 124 +- .../arrow/flight/client/CustomHeaderTest.java | 99 +- .../flight/client/TestCookieHandling.java | 52 +- .../arrow/flight/grpc/TestStatusUtils.java | 5 +- .../flight/perf/PerformanceTestServer.java | 201 +-- .../apache/arrow/flight/perf/TestPerf.java | 119 +- .../src/test/resources/logback.xml | 3 +- ...AppMetadataFlightInfoEndpointScenario.java | 25 +- .../tests/AuthBasicProtoScenario.java | 60 +- ...xpirationTimeCancelFlightInfoScenario.java | 23 +- .../tests/ExpirationTimeDoGetScenario.java | 20 +- .../ExpirationTimeListActionsScenario.java | 13 +- .../tests/ExpirationTimeProducer.java | 108 +- ...rationTimeRenewFlightEndpointScenario.java | 17 +- .../tests/FlightSqlExtensionScenario.java | 112 +- .../integration/tests/FlightSqlScenario.java | 144 +- .../tests/FlightSqlScenarioProducer.java | 696 +++++---- .../tests/IntegrationAssertions.java | 41 +- .../tests/IntegrationProducer.java | 49 +- .../tests/IntegrationTestClient.java | 66 +- .../tests/IntegrationTestServer.java | 30 +- .../integration/tests/MiddlewareScenario.java | 51 +- .../integration/tests/OrderedScenario.java | 4 +- .../tests/PollFlightInfoProducer.java | 20 +- .../tests/PollFlightInfoScenario.java | 27 +- .../flight/integration/tests/Scenario.java | 16 +- .../flight/integration/tests/Scenarios.java | 15 +- .../integration/tests/IntegrationTest.java | 11 +- .../src/test/resources/logback.xml | 3 +- java/flight/flight-sql-jdbc-core/pom.xml | 19 +- .../driver/jdbc/ArrowDatabaseMetadata.java | 465 +++--- .../driver/jdbc/ArrowFlightConnection.java | 67 +- .../driver/jdbc/ArrowFlightInfoStatement.java | 5 +- .../driver/jdbc/ArrowFlightJdbcArray.java | 27 +- ...rowFlightJdbcConnectionPoolDataSource.java | 23 +- .../driver/jdbc/ArrowFlightJdbcCursor.java | 23 +- .../jdbc/ArrowFlightJdbcDataSource.java | 22 +- .../driver/jdbc/ArrowFlightJdbcDriver.java | 78 +- .../driver/jdbc/ArrowFlightJdbcFactory.java | 62 +- .../ArrowFlightJdbcFlightStreamResultSet.java | 74 +- .../jdbc/ArrowFlightJdbcPooledConnection.java | 6 +- .../driver/jdbc/ArrowFlightJdbcTime.java | 10 +- ...owFlightJdbcVectorSchemaRootResultSet.java | 39 +- .../driver/jdbc/ArrowFlightMetaImpl.java | 129 +- .../jdbc/ArrowFlightPreparedStatement.java | 35 +- .../driver/jdbc/ArrowFlightStatement.java | 20 +- .../accessor/ArrowFlightJdbcAccessor.java | 9 +- .../ArrowFlightJdbcAccessorFactory.java | 159 +- .../ArrowFlightJdbcNullVectorAccessor.java | 4 +- .../ArrowFlightJdbcBinaryVectorAccessor.java | 32 +- .../ArrowFlightJdbcDateVectorAccessor.java | 23 +- .../ArrowFlightJdbcDateVectorGetter.java | 11 +- ...ArrowFlightJdbcDurationVectorAccessor.java | 12 +- ...ArrowFlightJdbcIntervalVectorAccessor.java | 79 +- ...rrowFlightJdbcTimeStampVectorAccessor.java | 34 +- .../ArrowFlightJdbcTimeStampVectorGetter.java | 11 +- .../ArrowFlightJdbcTimeVectorAccessor.java | 41 +- .../ArrowFlightJdbcTimeVectorGetter.java | 11 +- ...ractArrowFlightJdbcListVectorAccessor.java | 10 +- ...actArrowFlightJdbcUnionVectorAccessor.java | 15 +- ...rowFlightJdbcDenseUnionVectorAccessor.java | 21 +- ...FlightJdbcFixedSizeListVectorAccessor.java | 12 +- ...rrowFlightJdbcLargeListVectorAccessor.java | 12 +- .../ArrowFlightJdbcListVectorAccessor.java | 14 +- .../ArrowFlightJdbcMapVectorAccessor.java | 14 +- .../ArrowFlightJdbcStructVectorAccessor.java | 19 +- .../ArrowFlightJdbcUnionVectorAccessor.java | 20 +- .../ArrowFlightJdbcBaseIntVectorAccessor.java | 58 +- .../ArrowFlightJdbcBitVectorAccessor.java | 15 +- .../ArrowFlightJdbcDecimalVectorAccessor.java | 22 +- .../ArrowFlightJdbcFloat4VectorAccessor.java | 16 +- .../ArrowFlightJdbcFloat8VectorAccessor.java | 16 +- .../numeric/ArrowFlightJdbcNumericGetter.java | 16 +- .../ArrowFlightJdbcVarCharVectorAccessor.java | 30 +- .../client/ArrowFlightSqlClientHandler.java | 312 ++-- .../client/CloseableEndpointStreamPair.java | 4 +- .../utils/ClientAuthenticationUtils.java | 124 +- .../impl/BaseAvaticaParameterConverter.java | 3 +- .../impl/BinaryAvaticaParameterConverter.java | 7 +- .../impl/BoolAvaticaParameterConverter.java | 7 +- .../impl/DateAvaticaParameterConverter.java | 7 +- .../DecimalAvaticaParameterConverter.java | 8 +- .../DurationAvaticaParameterConverter.java | 7 +- ...edSizeBinaryAvaticaParameterConverter.java | 7 +- ...ixedSizeListAvaticaParameterConverter.java | 21 +- ...loatingPointAvaticaParameterConverter.java | 7 +- .../impl/IntAvaticaParameterConverter.java | 4 +- .../IntervalAvaticaParameterConverter.java | 7 +- .../LargeBinaryAvaticaParameterConverter.java | 7 +- .../LargeListAvaticaParameterConverter.java | 15 +- .../LargeUtf8AvaticaParameterConverter.java | 7 +- .../impl/ListAvaticaParameterConverter.java | 15 +- .../impl/MapAvaticaParameterConverter.java | 7 +- .../impl/NullAvaticaParameterConverter.java | 11 +- .../impl/StructAvaticaParameterConverter.java | 7 +- .../impl/TimeAvaticaParameterConverter.java | 7 +- .../TimestampAvaticaParameterConverter.java | 7 +- .../impl/UnionAvaticaParameterConverter.java | 7 +- .../impl/Utf8AvaticaParameterConverter.java | 7 +- .../ArrowFlightConnectionConfigImpl.java | 31 +- .../jdbc/utils/AvaticaParameterBinder.java | 55 +- .../driver/jdbc/utils/ConnectionWrapper.java | 47 +- .../arrow/driver/jdbc/utils/ConvertUtils.java | 72 +- .../driver/jdbc/utils/DateTimeUtils.java | 12 +- .../jdbc/utils/FlightEndpointDataQueue.java | 140 +- .../jdbc/utils/IntervalStringUtils.java | 24 +- .../arrow/driver/jdbc/utils/SqlTypes.java | 6 +- .../arrow/driver/jdbc/utils/UrlParser.java | 13 +- .../utils/VectorSchemaRootTransformer.java | 89 +- .../jdbc/ArrowDatabaseMetadataTest.java | 1186 +++++++------- .../driver/jdbc/ArrowFlightJdbcArrayTest.java | 4 +- .../ArrowFlightJdbcConnectionCookieTest.java | 7 +- ...lightJdbcConnectionPoolDataSourceTest.java | 20 +- .../jdbc/ArrowFlightJdbcCursorTest.java | 79 +- .../jdbc/ArrowFlightJdbcDriverTest.java | 269 ++-- .../jdbc/ArrowFlightJdbcFactoryTest.java | 44 +- .../driver/jdbc/ArrowFlightJdbcTimeTest.java | 10 +- .../ArrowFlightPreparedStatementTest.java | 95 +- .../jdbc/ArrowFlightStatementExecuteTest.java | 63 +- ...ArrowFlightStatementExecuteUpdateTest.java | 60 +- .../driver/jdbc/ConnectionMutualTlsTest.java | 268 ++-- .../arrow/driver/jdbc/ConnectionTest.java | 406 +++-- .../jdbc/ConnectionTlsRootCertsTest.java | 238 +-- .../arrow/driver/jdbc/ConnectionTlsTest.java | 311 ++-- .../driver/jdbc/FlightServerTestRule.java | 90 +- .../driver/jdbc/ResultSetMetadataTest.java | 28 +- .../arrow/driver/jdbc/ResultSetTest.java | 207 +-- .../driver/jdbc/TokenAuthenticationTest.java | 15 +- .../ArrowFlightJdbcAccessorFactoryTest.java | 216 ++- .../accessor/ArrowFlightJdbcAccessorTest.java | 7 +- ...ArrowFlightJdbcNullVectorAccessorTest.java | 3 +- ...rowFlightJdbcBinaryVectorAccessorTest.java | 142 +- ...ArrowFlightJdbcDateVectorAccessorTest.java | 170 +- ...wFlightJdbcDurationVectorAccessorTest.java | 33 +- ...wFlightJdbcIntervalVectorAccessorTest.java | 151 +- ...FlightJdbcTimeStampVectorAccessorTest.java | 248 +-- ...ArrowFlightJdbcTimeVectorAccessorTest.java | 191 +-- ...stractArrowFlightJdbcListAccessorTest.java | 151 +- ...rrowFlightJdbcUnionVectorAccessorTest.java | 13 +- ...lightJdbcDenseUnionVectorAccessorTest.java | 30 +- .../ArrowFlightJdbcMapVectorAccessorTest.java | 18 +- ...rowFlightJdbcStructVectorAccessorTest.java | 56 +- ...rrowFlightJdbcUnionVectorAccessorTest.java | 26 +- ...owFlightJdbcBaseIntVectorAccessorTest.java | 142 +- ...ightJdbcBaseIntVectorAccessorUnitTest.java | 143 +- .../ArrowFlightJdbcBitVectorAccessorTest.java | 47 +- ...owFlightJdbcDecimalVectorAccessorTest.java | 129 +- ...rowFlightJdbcFloat4VectorAccessorTest.java | 123 +- ...rowFlightJdbcFloat8VectorAccessorTest.java | 111 +- ...owFlightJdbcVarCharVectorAccessorTest.java | 51 +- .../jdbc/authentication/Authentication.java | 2 +- .../authentication/TokenAuthentication.java | 12 +- .../UserPasswordAuthentication.java | 29 +- ...rrowFlightSqlClientHandlerBuilderTest.java | 74 +- .../utils/ClientAuthenticationUtilsTest.java | 115 +- .../driver/jdbc/utils/AccessorTestUtils.java | 47 +- .../ArrowFlightConnectionConfigImplTest.java | 59 +- .../ArrowFlightConnectionPropertyTest.java | 21 +- .../jdbc/utils/ConnectionWrapperTest.java | 160 +- .../driver/jdbc/utils/ConvertUtilsTest.java | 114 +- .../jdbc/utils/CoreMockedSqlProducers.java | 372 ++--- .../driver/jdbc/utils/DateTimeUtilsTest.java | 11 +- .../utils/FlightEndpointDataQueueTest.java | 30 +- .../jdbc/utils/FlightSqlTestCertificates.java | 20 +- .../jdbc/utils/MockFlightSqlProducer.java | 367 +++-- .../utils/PartitionedFlightSqlProducer.java | 31 +- .../driver/jdbc/utils/ResultSetTestUtils.java | 138 +- .../jdbc/utils/RootAllocatorTestRule.java | 363 +++-- .../arrow/driver/jdbc/utils/SqlTypesTest.java | 46 +- .../jdbc/utils/ThrowableAssertionUtils.java | 19 +- .../driver/jdbc/utils/UrlParserTest.java | 1 - .../VectorSchemaRootTransformerTest.java | 41 +- .../src/test/resources/logback.xml | 3 +- java/flight/flight-sql-jdbc-driver/pom.xml | 19 +- .../flight/sql/BasicFlightSqlProducer.java | 61 +- .../arrow/flight/sql/CancelListener.java | 8 +- .../arrow/flight/sql/FlightSqlClient.java | 553 ++++--- .../flight/sql/FlightSqlColumnMetadata.java | 40 +- .../arrow/flight/sql/FlightSqlProducer.java | 825 +++++----- .../arrow/flight/sql/FlightSqlUtils.java | 103 +- .../flight/sql/NoOpFlightSqlProducer.java | 192 ++- .../arrow/flight/sql/ProtoListener.java | 5 +- .../arrow/flight/sql/SqlInfoBuilder.java | 168 +- .../sql/example/FlightSqlClientDemoApp.java | 100 +- .../flight/sql/util/SqlInfoOptionsUtils.java | 18 +- .../arrow/flight/sql/util/TableRef.java | 31 +- .../flight/sql/example/FlightSqlExample.java | 744 +++++---- .../flight/sql/example/StatementContext.java | 1 - .../arrow/flight/sql/test/TestFlightSql.java | 1361 +++++++++++------ .../flight/sql/test/TestFlightSqlStreams.java | 172 ++- .../flight/sql/util/AdhocTestOption.java | 7 +- .../flight/sql/util/FlightStreamUtils.java | 142 +- ...qlInfoOptionsUtilsBitmaskCreationTest.java | 22 +- ...SqlInfoOptionsUtilsBitmaskParsingTest.java | 22 +- .../flight-sql/src/test/resources/logback.xml | 3 +- java/format/pom.xml | 2 +- java/format/src/main/java/module-info.java | 1 + .../plugins/BaseModuleInfoCompilerPlugin.java | 25 +- .../plugins/ModuleInfoCompilerPlugin.java | 9 +- .../plugins/ModuleInfoTestCompilerPlugin.java | 5 +- .../src/main/java/module-info.java | 1 + .../org/apache/arrow/memory/Accountant.java | 117 +- .../arrow/memory/AllocationListener.java | 12 +- .../arrow/memory/AllocationManager.java | 101 +- .../arrow/memory/AllocationOutcome.java | 29 +- .../memory/AllocationOutcomeDetails.java | 33 +- .../arrow/memory/AllocationReservation.java | 22 +- .../memory/AllocatorClosedException.java | 5 +- .../org/apache/arrow/memory/ArrowBuf.java | 491 +++--- .../apache/arrow/memory/BaseAllocator.java | 322 ++-- .../apache/arrow/memory/BoundsChecking.java | 24 +- .../apache/arrow/memory/BufferAllocator.java | 92 +- .../org/apache/arrow/memory/BufferLedger.java | 248 ++- .../apache/arrow/memory/BufferManager.java | 9 +- .../apache/arrow/memory/CheckAllocator.java | 25 +- .../apache/arrow/memory/ChildAllocator.java | 20 +- .../DefaultAllocationManagerOption.java | 57 +- .../arrow/memory/ForeignAllocation.java | 15 +- .../memory/ForeignAllocationManager.java | 7 +- .../arrow/memory/LowCostIdentityHashMap.java | 67 +- .../arrow/memory/OutOfMemoryException.java | 16 +- .../arrow/memory/OwnershipTransferNOOP.java | 4 +- .../arrow/memory/OwnershipTransferResult.java | 4 +- .../apache/arrow/memory/ReferenceManager.java | 166 +- .../apache/arrow/memory/ReusableBuffer.java | 16 +- .../apache/arrow/memory/RootAllocator.java | 32 +- .../arrow/memory/ValueWithKeyIncluded.java | 3 +- .../org/apache/arrow/memory/package-info.java | 6 +- .../rounding/DefaultRoundingPolicy.java | 33 +- .../rounding/SegmentRoundingPolicy.java | 27 +- .../arrow/memory/util/ArrowBufPointer.java | 45 +- .../arrow/memory/util/AssertionUtil.java | 6 +- .../arrow/memory/util/AutoCloseableLock.java | 5 +- .../memory/util/ByteFunctionHelpers.java | 81 +- .../apache/arrow/memory/util/CommonUtil.java | 7 +- .../arrow/memory/util/HistoricalLog.java | 77 +- .../arrow/memory/util/LargeMemoryUtil.java | 9 +- .../apache/arrow/memory/util/MemoryUtil.java | 131 +- .../apache/arrow/memory/util/StackTrace.java | 14 +- .../memory/util/hash/ArrowBufHasher.java | 11 +- .../arrow/memory/util/hash/MurmurHasher.java | 31 +- .../arrow/memory/util/hash/SimpleHasher.java | 34 +- .../org/apache/arrow/util/AutoCloseables.java | 75 +- .../org/apache/arrow/util/Collections2.java | 25 +- .../apache/arrow/util/VisibleForTesting.java | 8 +- .../memory/CountingAllocationListener.java | 17 +- .../DefaultAllocationManagerFactory.java | 9 +- .../apache/arrow/memory/TestAccountant.java | 28 +- .../arrow/memory/TestAllocationManager.java | 4 +- .../org/apache/arrow/memory/TestArrowBuf.java | 33 +- .../arrow/memory/TestBaseAllocator.java | 346 +++-- .../arrow/memory/TestBoundaryChecking.java | 20 +- .../arrow/memory/TestForeignAllocation.java | 26 +- .../memory/TestLowCostIdentityHashMap.java | 12 +- .../org/apache/arrow/memory/TestOpens.java | 14 +- .../memory/util/TestArrowBufPointer.java | 12 +- .../memory/util/TestByteFunctionHelpers.java | 72 +- .../memory/util/TestLargeMemoryUtil.java | 216 +-- .../memory/util/hash/TestArrowBufHasher.java | 55 +- .../apache/arrow/util/TestCollections2.java | 7 +- .../org/apache/arrow/util/TestStackTrace.java | 11 +- .../src/test/resources/logback.xml | 3 +- .../io/netty/buffer/ExpandableByteBuf.java | 4 +- .../netty/buffer/MutableWrappedByteBuf.java | 27 +- .../java/io/netty/buffer/NettyArrowBuf.java | 86 +- .../netty/buffer/PooledByteBufAllocatorL.java | 46 +- .../buffer/UnsafeDirectLittleEndian.java | 8 +- .../memory/patch/ArrowByteBufAllocator.java | 15 +- .../buffer/TestUnsafeDirectLittleEndian.java | 9 +- .../DefaultAllocationManagerFactory.java | 6 +- .../memory/netty/NettyAllocationManager.java | 57 +- .../netty/buffer/TestExpandableByteBuf.java | 48 +- .../io/netty/buffer/TestNettyArrowBuf.java | 59 +- .../memory/netty/ITTestLargeArrowBuf.java | 8 +- .../netty/TestAllocationManagerNetty.java | 4 +- .../arrow/memory/netty/TestEmptyArrowBuf.java | 24 +- .../arrow/memory/netty/TestEndianness.java | 7 +- .../netty/TestNettyAllocationManager.java | 44 +- .../memory/netty/TestNettyAllocator.java | 55 +- .../src/test/resources/logback.xml | 3 +- .../src/main/java/module-info.java | 5 +- .../DefaultAllocationManagerFactory.java | 5 +- .../unsafe/UnsafeAllocationManager.java | 33 +- .../unsafe/TestAllocationManagerUnsafe.java | 5 +- .../unsafe/TestUnsafeAllocationManager.java | 16 +- .../src/test/resources/logback.xml | 3 +- java/memory/pom.xml | 2 +- java/performance/pom.xml | 2 +- .../arrow/adapter/AvroAdapterBenchmarks.java | 46 +- .../adapter/jdbc/JdbcAdapterBenchmarks.java | 44 +- .../search/ParallelSearcherBenchmarks.java | 12 +- .../arrow/memory/AllocatorBenchmarks.java | 23 +- .../arrow/memory/ArrowBufBenchmarks.java | 19 +- .../util/ArrowBufPointerBenchmarks.java | 18 +- .../util/ByteFunctionHelpersBenchmarks.java | 37 +- .../vector/BaseValueVectorBenchmarks.java | 27 +- .../vector/BitVectorHelperBenchmarks.java | 58 +- .../arrow/vector/DecimalVectorBenchmarks.java | 32 +- .../apache/arrow/vector/Float8Benchmarks.java | 30 +- .../arrow/vector/FloatingPointBenchmarks.java | 19 +- .../apache/arrow/vector/IntBenchmarks.java | 13 +- .../arrow/vector/VarCharBenchmarks.java | 21 +- .../vector/VariableWidthVectorBenchmarks.java | 20 +- .../arrow/vector/VectorLoaderBenchmark.java | 23 +- .../arrow/vector/VectorUnloaderBenchmark.java | 18 +- .../DictionaryEncoderBenchmarks.java | 28 +- .../vector/ipc/WriteChannelBenchmark.java | 15 +- .../message/ArrowRecordBatchBenchmarks.java | 21 +- .../vector/util/TransferPairBenchmarks.java | 21 +- java/tools/pom.xml | 2 +- .../org/apache/arrow/tools/EchoServer.java | 25 +- .../org/apache/arrow/tools/FileRoundtrip.java | 17 +- .../org/apache/arrow/tools/FileToStream.java | 16 +- .../org/apache/arrow/tools/Integration.java | 66 +- .../org/apache/arrow/tools/StreamToFile.java | 17 +- .../arrow/tools/ArrowFileTestFixtures.java | 25 +- .../apache/arrow/tools/EchoServerTest.java | 103 +- .../apache/arrow/tools/TestFileRoundtrip.java | 5 +- .../apache/arrow/tools/TestIntegration.java | 154 +- java/tools/src/test/resources/logback.xml | 3 +- java/vector/pom.xml | 2 +- java/vector/src/main/java/module-info.java | 3 +- .../apache/arrow/vector/AllocationHelper.java | 19 +- .../arrow/vector/BaseFixedWidthVector.java | 286 ++-- .../apache/arrow/vector/BaseIntVector.java | 18 +- .../vector/BaseLargeVariableWidthVector.java | 445 +++--- .../apache/arrow/vector/BaseValueVector.java | 35 +- .../arrow/vector/BaseVariableWidthVector.java | 469 +++--- .../org/apache/arrow/vector/BigIntVector.java | 115 +- .../org/apache/arrow/vector/BitVector.java | 157 +- .../apache/arrow/vector/BitVectorHelper.java | 100 +- .../org/apache/arrow/vector/BufferBacked.java | 4 +- .../org/apache/arrow/vector/BufferLayout.java | 11 +- .../apache/arrow/vector/DateDayVector.java | 114 +- .../apache/arrow/vector/DateMilliVector.java | 115 +- .../apache/arrow/vector/Decimal256Vector.java | 230 ++- .../apache/arrow/vector/DecimalVector.java | 227 ++- .../arrow/vector/DensityAwareVector.java | 36 +- .../apache/arrow/vector/DurationVector.java | 136 +- .../vector/ElementAddressableVector.java | 6 +- .../arrow/vector/ExtensionTypeVector.java | 16 +- .../org/apache/arrow/vector/FieldVector.java | 17 +- .../arrow/vector/FixedSizeBinaryVector.java | 142 +- .../apache/arrow/vector/FixedWidthVector.java | 9 +- .../org/apache/arrow/vector/Float4Vector.java | 112 +- .../org/apache/arrow/vector/Float8Vector.java | 113 +- .../arrow/vector/FloatingPointVector.java | 11 +- .../arrow/vector/GenerateSampleData.java | 9 +- .../org/apache/arrow/vector/IntVector.java | 99 +- .../arrow/vector/IntervalDayVector.java | 159 +- .../vector/IntervalMonthDayNanoVector.java | 165 +- .../arrow/vector/IntervalYearVector.java | 123 +- .../arrow/vector/LargeVarBinaryVector.java | 94 +- .../arrow/vector/LargeVarCharVector.java | 118 +- .../arrow/vector/NullCheckingForGet.java | 67 +- .../org/apache/arrow/vector/NullVector.java | 27 +- .../apache/arrow/vector/PeriodDuration.java | 6 +- .../arrow/vector/SchemaChangeCallBack.java | 22 +- .../apache/arrow/vector/SmallIntVector.java | 125 +- .../apache/arrow/vector/TimeMicroVector.java | 112 +- .../apache/arrow/vector/TimeMilliVector.java | 115 +- .../apache/arrow/vector/TimeNanoVector.java | 114 +- .../apache/arrow/vector/TimeSecVector.java | 115 +- .../arrow/vector/TimeStampMicroTZVector.java | 110 +- .../arrow/vector/TimeStampMicroVector.java | 95 +- .../arrow/vector/TimeStampMilliTZVector.java | 109 +- .../arrow/vector/TimeStampMilliVector.java | 95 +- .../arrow/vector/TimeStampNanoTZVector.java | 109 +- .../arrow/vector/TimeStampNanoVector.java | 95 +- .../arrow/vector/TimeStampSecTZVector.java | 101 +- .../arrow/vector/TimeStampSecVector.java | 95 +- .../apache/arrow/vector/TimeStampVector.java | 66 +- .../apache/arrow/vector/TinyIntVector.java | 126 +- .../org/apache/arrow/vector/TypeLayout.java | 668 ++++---- .../org/apache/arrow/vector/UInt1Vector.java | 127 +- .../org/apache/arrow/vector/UInt2Vector.java | 122 +- .../org/apache/arrow/vector/UInt4Vector.java | 113 +- .../org/apache/arrow/vector/UInt8Vector.java | 107 +- .../org/apache/arrow/vector/ValueVector.java | 121 +- .../apache/arrow/vector/VarBinaryVector.java | 92 +- .../apache/arrow/vector/VarCharVector.java | 113 +- .../arrow/vector/VariableWidthVector.java | 11 +- .../arrow/vector/VectorDefinitionSetter.java | 4 +- .../org/apache/arrow/vector/VectorLoader.java | 35 +- .../apache/arrow/vector/VectorSchemaRoot.java | 139 +- .../apache/arrow/vector/VectorUnloader.java | 47 +- .../org/apache/arrow/vector/ZeroVector.java | 40 +- .../vector/compare/ApproxEqualsVisitor.java | 50 +- .../apache/arrow/vector/compare/Range.java | 21 +- .../vector/compare/RangeEqualsVisitor.java | 162 +- .../vector/compare/TypeEqualsVisitor.java | 28 +- .../vector/compare/VectorEqualsVisitor.java | 7 +- .../vector/compare/VectorValueEqualizer.java | 7 +- .../arrow/vector/compare/VectorVisitor.java | 2 +- .../compare/util/ValueEpsilonEqualizers.java | 31 +- .../complex/AbstractContainerVector.java | 26 +- .../vector/complex/AbstractStructVector.java | 136 +- .../arrow/vector/complex/BaseListVector.java | 12 +- .../complex/BaseRepeatedValueVector.java | 88 +- .../vector/complex/EmptyValuePopulator.java | 16 +- .../vector/complex/FixedSizeListVector.java | 98 +- .../arrow/vector/complex/LargeListVector.java | 274 ++-- .../arrow/vector/complex/ListVector.java | 217 +-- .../arrow/vector/complex/MapVector.java | 80 +- .../complex/NonNullableStructVector.java | 161 +- .../arrow/vector/complex/Positionable.java | 5 +- .../vector/complex/PromotableVector.java | 4 +- .../complex/RepeatedFixedWidthVectorLike.java | 8 +- .../vector/complex/RepeatedValueVector.java | 11 +- .../RepeatedVariableWidthVectorLike.java | 6 +- .../arrow/vector/complex/StateTool.java | 15 +- .../arrow/vector/complex/StructVector.java | 238 ++- .../vector/complex/VectorWithOrdinal.java | 4 +- .../complex/impl/AbstractBaseReader.java | 4 +- .../complex/impl/AbstractBaseWriter.java | 7 +- .../complex/impl/ComplexWriterImpl.java | 34 +- .../impl/NullableStructReaderImpl.java | 4 +- .../impl/NullableStructWriterFactory.java | 6 +- .../vector/complex/impl/PromotableWriter.java | 90 +- .../complex/impl/SingleListReaderImpl.java | 12 +- .../complex/impl/SingleStructReaderImpl.java | 5 - .../complex/impl/StructOrListWriterImpl.java | 26 +- .../impl/UnionFixedSizeListReader.java | 8 +- .../complex/impl/UnionLargeListReader.java | 11 +- .../vector/complex/impl/UnionListReader.java | 4 +- .../vector/complex/impl/UnionMapReader.java | 8 +- .../vector/complex/reader/FieldReader.java | 16 +- .../vector/complex/writer/FieldWriter.java | 4 +- .../compression/AbstractCompressionCodec.java | 32 +- .../vector/compression/CompressionCodec.java | 27 +- .../vector/compression/CompressionUtil.java | 39 +- .../compression/NoCompressionCodec.java | 14 +- .../arrow/vector/dictionary/Dictionary.java | 9 +- .../vector/dictionary/DictionaryEncoder.java | 65 +- .../dictionary/DictionaryHashTable.java | 96 +- .../vector/dictionary/DictionaryProvider.java | 18 +- .../dictionary/ListSubfieldEncoder.java | 50 +- .../dictionary/StructSubfieldEncoder.java | 81 +- .../arrow/vector/holders/ComplexHolder.java | 4 +- .../vector/holders/DenseUnionHolder.java | 4 +- .../vector/holders/RepeatedListHolder.java | 4 +- .../vector/holders/RepeatedStructHolder.java | 4 +- .../arrow/vector/holders/UnionHolder.java | 4 +- .../arrow/vector/holders/ValueHolder.java | 13 +- .../arrow/vector/ipc/ArrowFileReader.java | 61 +- .../arrow/vector/ipc/ArrowFileWriter.java | 52 +- .../apache/arrow/vector/ipc/ArrowMagic.java | 5 +- .../apache/arrow/vector/ipc/ArrowReader.java | 23 +- .../arrow/vector/ipc/ArrowStreamReader.java | 38 +- .../arrow/vector/ipc/ArrowStreamWriter.java | 54 +- .../apache/arrow/vector/ipc/ArrowWriter.java | 103 +- .../vector/ipc/InvalidArrowFileException.java | 4 +- .../arrow/vector/ipc/JsonFileReader.java | 595 +++---- .../arrow/vector/ipc/JsonFileWriter.java | 155 +- .../apache/arrow/vector/ipc/ReadChannel.java | 9 +- .../arrow/vector/ipc/SeekableReadChannel.java | 5 +- .../apache/arrow/vector/ipc/WriteChannel.java | 52 +- .../arrow/vector/ipc/message/ArrowBlock.java | 5 +- .../ipc/message/ArrowBodyCompression.java | 7 +- .../arrow/vector/ipc/message/ArrowBuffer.java | 4 +- .../ipc/message/ArrowDictionaryBatch.java | 15 +- .../vector/ipc/message/ArrowFieldNode.java | 8 +- .../arrow/vector/ipc/message/ArrowFooter.java | 19 +- .../vector/ipc/message/ArrowMessage.java | 4 +- .../vector/ipc/message/ArrowRecordBatch.java | 97 +- .../vector/ipc/message/FBSerializable.java | 8 +- .../vector/ipc/message/FBSerializables.java | 19 +- .../arrow/vector/ipc/message/IpcOption.java | 4 +- .../ipc/message/MessageChannelReader.java | 12 +- .../ipc/message/MessageMetadataResult.java | 23 +- .../vector/ipc/message/MessageResult.java | 4 +- .../vector/ipc/message/MessageSerializer.java | 264 ++-- .../apache/arrow/vector/table/BaseTable.java | 59 +- .../org/apache/arrow/vector/table/Row.java | 736 +++++---- .../org/apache/arrow/vector/table/Table.java | 20 +- .../arrow/vector/table/package-info.java | 5 +- .../apache/arrow/vector/types/DateUnit.java | 4 +- .../vector/types/FloatingPointPrecision.java | 6 +- .../arrow/vector/types/IntervalUnit.java | 12 +- .../arrow/vector/types/MetadataVersion.java | 5 +- .../apache/arrow/vector/types/TimeUnit.java | 4 +- .../org/apache/arrow/vector/types/Types.java | 601 ++++---- .../apache/arrow/vector/types/UnionMode.java | 14 +- .../vector/types/pojo/DictionaryEncoding.java | 14 +- .../types/pojo/ExtensionTypeRegistry.java | 5 +- .../apache/arrow/vector/types/pojo/Field.java | 72 +- .../arrow/vector/types/pojo/FieldType.java | 37 +- .../arrow/vector/types/pojo/Schema.java | 115 +- .../ByteArrayReadableSeekableByteChannel.java | 9 +- .../apache/arrow/vector/util/CallBack.java | 4 +- .../vector/util/DataSizeRoundingUtil.java | 28 +- .../apache/arrow/vector/util/DateUtility.java | 41 +- .../arrow/vector/util/DecimalUtility.java | 100 +- .../arrow/vector/util/DictionaryUtility.java | 40 +- .../ElementAddressableVectorIterator.java | 16 +- .../vector/util/JsonStringArrayList.java | 3 +- .../arrow/vector/util/JsonStringHashMap.java | 7 +- .../arrow/vector/util/MapWithOrdinal.java | 18 +- .../arrow/vector/util/MapWithOrdinalImpl.java | 208 +-- .../vector/util/MultiMapWithOrdinal.java | 76 +- .../vector/util/ObjectMapperFactory.java | 13 +- .../util/OversizedAllocationException.java | 14 +- .../util/PromotableMultiMapWithOrdinal.java | 15 +- .../arrow/vector/util/ReusableByteArray.java | 15 +- .../util/SchemaChangeRuntimeException.java | 10 +- .../arrow/vector/util/SchemaUtility.java | 18 +- .../org/apache/arrow/vector/util/Text.java | 381 ++++- .../arrow/vector/util/TransferPair.java | 4 +- .../apache/arrow/vector/util/Validator.java | 72 +- .../arrow/vector/util/ValueVectorUtility.java | 83 +- .../arrow/vector/util/VectorAppender.java | 308 ++-- .../vector/util/VectorBatchAppender.java | 7 +- .../vector/util/VectorSchemaRootAppender.java | 21 +- .../validate/MetadataV4UnionChecker.java | 9 +- .../arrow/vector/validate/ValidateUtil.java | 13 +- .../validate/ValidateVectorBufferVisitor.java | 118 +- .../validate/ValidateVectorDataVisitor.java | 49 +- .../validate/ValidateVectorTypeVisitor.java | 223 ++- .../validate/ValidateVectorVisitor.java | 123 +- .../arrow/vector/ITTestLargeVector.java | 17 +- .../apache/arrow/vector/TestBitVector.java | 49 +- .../arrow/vector/TestBitVectorHelper.java | 15 +- .../vector/TestBufferOwnershipTransfer.java | 18 +- .../org/apache/arrow/vector/TestCopyFrom.java | 12 +- .../arrow/vector/TestDecimal256Vector.java | 165 +- .../arrow/vector/TestDecimalVector.java | 141 +- .../arrow/vector/TestDenseUnionVector.java | 102 +- .../arrow/vector/TestDictionaryVector.java | 284 ++-- .../arrow/vector/TestDurationVector.java | 54 +- .../vector/TestFixedSizeBinaryVector.java | 19 +- .../arrow/vector/TestFixedSizeListVector.java | 99 +- .../TestIntervalMonthDayNanoVector.java | 20 +- .../arrow/vector/TestIntervalYearVector.java | 3 +- .../arrow/vector/TestLargeListVector.java | 104 +- .../vector/TestLargeVarBinaryVector.java | 13 +- .../arrow/vector/TestLargeVarCharVector.java | 134 +- .../apache/arrow/vector/TestListVector.java | 177 ++- .../apache/arrow/vector/TestMapVector.java | 31 +- .../arrow/vector/TestNullCheckingForGet.java | 14 +- .../vector/TestOutOfMemoryForValueVector.java | 4 +- ...TestOversizedAllocationForValueVector.java | 8 +- .../arrow/vector/TestPeriodDuration.java | 2 - .../arrow/vector/TestSplitAndTransfer.java | 57 +- .../apache/arrow/vector/TestStructVector.java | 35 +- .../apache/arrow/vector/TestTypeLayout.java | 85 +- .../apache/arrow/vector/TestUnionVector.java | 104 +- .../org/apache/arrow/vector/TestUtils.java | 7 +- .../apache/arrow/vector/TestValueVector.java | 356 +++-- .../arrow/vector/TestVarCharListVector.java | 7 +- .../apache/arrow/vector/TestVectorAlloc.java | 80 +- .../arrow/vector/TestVectorReAlloc.java | 57 +- .../apache/arrow/vector/TestVectorReset.java | 30 +- .../arrow/vector/TestVectorSchemaRoot.java | 52 +- .../arrow/vector/TestVectorUnloadLoad.java | 97 +- .../compare/TestRangeEqualsVisitor.java | 208 ++- .../vector/compare/TestTypeEqualsVisitor.java | 57 +- .../complex/TestDenseUnionBufferSize.java | 29 +- .../complex/impl/TestComplexCopier.java | 75 +- .../complex/impl/TestPromotableWriter.java | 283 ++-- .../complex/writer/TestComplexWriter.java | 103 +- .../complex/writer/TestSimpleWriter.java | 49 +- .../apache/arrow/vector/ipc/BaseFileTest.java | 115 +- .../ipc/ITTestIPCWithLargeArrowBuffers.java | 42 +- .../vector/ipc/MessageSerializerTest.java | 49 +- .../arrow/vector/ipc/TestArrowFile.java | 19 +- .../arrow/vector/ipc/TestArrowFooter.java | 19 +- .../vector/ipc/TestArrowReaderWriter.java | 312 ++-- .../arrow/vector/ipc/TestArrowStream.java | 19 +- .../arrow/vector/ipc/TestArrowStreamPipe.java | 59 +- .../apache/arrow/vector/ipc/TestJSONFile.java | 214 +-- .../arrow/vector/ipc/TestRoundTrip.java | 305 ++-- .../ipc/TestUIntDictionaryRoundTrip.java | 80 +- .../message/TestMessageMetadataResult.java | 7 +- .../apache/arrow/vector/pojo/TestConvert.java | 85 +- .../arrow/vector/table/BaseTableTest.java | 10 +- .../apache/arrow/vector/table/RowTest.java | 27 +- .../apache/arrow/vector/table/TableTest.java | 6 +- .../apache/arrow/vector/table/TestUtils.java | 38 +- .../vector/test/util/ArrowTestDataUtil.java | 16 +- .../vector/testing/RandomDataGenerator.java | 7 +- .../testing/TestValueVectorPopulator.java | 89 +- .../testing/ValueVectorDataPopulator.java | 131 +- .../vector/types/pojo/TestExtensionType.java | 141 +- .../arrow/vector/types/pojo/TestField.java | 14 +- .../arrow/vector/types/pojo/TestSchema.java | 245 +-- .../arrow/vector/util/DecimalUtilityTest.java | 52 +- .../vector/util/TestDataSizeRoundingUtil.java | 4 +- .../TestElementAddressableVectorIterator.java | 10 +- .../arrow/vector/util/TestMapWithOrdinal.java | 1 - .../vector/util/TestMultiMapWithOrdinal.java | 2 - .../vector/util/TestReusableByteArray.java | 13 +- .../arrow/vector/util/TestSchemaUtil.java | 13 +- .../arrow/vector/util/TestVectorAppender.java | 283 ++-- .../vector/util/TestVectorBatchAppender.java | 8 +- .../util/TestVectorSchemaRootAppender.java | 58 +- .../vector/validate/TestValidateVector.java | 55 +- .../validate/TestValidateVectorFull.java | 110 +- .../TestValidateVectorSchemaRoot.java | 26 +- .../TestValidateVectorTypeVisitor.java | 240 ++- java/vector/src/test/resources/logback.xml | 3 +- 885 files changed, 30542 insertions(+), 27879 deletions(-) diff --git a/java/adapter/avro/pom.xml b/java/adapter/avro/pom.xml index 90864eab006..e69cc856bdb 100644 --- a/java/adapter/avro/pom.xml +++ b/java/adapter/avro/pom.xml @@ -1,15 +1,14 @@ - + 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. --> 4.0.0 diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrow.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrow.java index 8baa60a72dd..3d4380614a0 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrow.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrow.java @@ -18,20 +18,17 @@ package org.apache.arrow.adapter.avro; import java.io.IOException; - import org.apache.arrow.util.Preconditions; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.avro.Schema; import org.apache.avro.io.Decoder; -/** - * Utility class to convert Avro objects to columnar Arrow format objects. - */ +/** Utility class to convert Avro objects to columnar Arrow format objects. */ public class AvroToArrow { /** - * Fetch the data from {@link Decoder} and convert it to Arrow objects. - * Only for testing purpose. + * Fetch the data from {@link Decoder} and convert it to Arrow objects. Only for testing purpose. + * * @param schema avro schema. * @param decoder avro decoder * @param config configuration of the conversion. @@ -48,15 +45,14 @@ static VectorSchemaRoot avroToArrow(Schema schema, Decoder decoder, AvroToArrowC /** * Fetch the data from {@link Decoder} and iteratively convert it to Arrow objects. + * * @param schema avro schema * @param decoder avro decoder * @param config configuration of the conversion. * @throws IOException on error */ public static AvroToArrowVectorIterator avroToArrowIterator( - Schema schema, - Decoder decoder, - AvroToArrowConfig config) throws IOException { + Schema schema, Decoder decoder, AvroToArrowConfig config) throws IOException { Preconditions.checkNotNull(schema, "Avro schema object cannot be null"); Preconditions.checkNotNull(decoder, "Avro decoder object cannot be null"); diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowConfig.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowConfig.java index f9210fb0125..c5419c7e263 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowConfig.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowConfig.java @@ -18,36 +18,33 @@ package org.apache.arrow.adapter.avro; import java.util.Set; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.Preconditions; import org.apache.arrow.vector.dictionary.DictionaryProvider; -/** - * This class configures the Avro-to-Arrow conversion process. - */ +/** This class configures the Avro-to-Arrow conversion process. */ public class AvroToArrowConfig { private final BufferAllocator allocator; + /** - * The maximum rowCount to read each time when partially convert data. - * Default value is 1024 and -1 means read all data into one vector. + * The maximum rowCount to read each time when partially convert data. Default value is 1024 and + * -1 means read all data into one vector. */ private final int targetBatchSize; /** - * The dictionary provider used for enum type. - * If avro schema has enum type, will create dictionary and update this provider. + * The dictionary provider used for enum type. If avro schema has enum type, will create + * dictionary and update this provider. */ private final DictionaryProvider.MapDictionaryProvider provider; - /** - * The field names which to skip when reading decoder values. - */ + /** The field names which to skip when reading decoder values. */ private final Set skipFieldNames; /** * Instantiate an instance. + * * @param allocator The memory allocator to construct the Arrow vectors with. * @param targetBatchSize The maximum rowCount to read each time when partially convert data. * @param provider The dictionary provider used for enum type, adapter will update this provider. @@ -59,8 +56,10 @@ public class AvroToArrowConfig { DictionaryProvider.MapDictionaryProvider provider, Set skipFieldNames) { - Preconditions.checkArgument(targetBatchSize == AvroToArrowVectorIterator.NO_LIMIT_BATCH_SIZE || - targetBatchSize > 0, "invalid targetBatchSize: %s", targetBatchSize); + Preconditions.checkArgument( + targetBatchSize == AvroToArrowVectorIterator.NO_LIMIT_BATCH_SIZE || targetBatchSize > 0, + "invalid targetBatchSize: %s", + targetBatchSize); this.allocator = allocator; this.targetBatchSize = targetBatchSize; diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowConfigBuilder.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowConfigBuilder.java index 41e486d0a1c..f1db4e58909 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowConfigBuilder.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowConfigBuilder.java @@ -19,13 +19,10 @@ import java.util.HashSet; import java.util.Set; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.dictionary.DictionaryProvider; -/** - * This class builds {@link AvroToArrowConfig}s. - */ +/** This class builds {@link AvroToArrowConfig}s. */ public class AvroToArrowConfigBuilder { private BufferAllocator allocator; @@ -36,9 +33,7 @@ public class AvroToArrowConfigBuilder { private Set skipFieldNames; - /** - * Default constructor for the {@link AvroToArrowConfigBuilder}. - */ + /** Default constructor for the {@link AvroToArrowConfigBuilder}. */ public AvroToArrowConfigBuilder(BufferAllocator allocator) { this.allocator = allocator; this.targetBatchSize = AvroToArrowVectorIterator.DEFAULT_BATCH_SIZE; @@ -61,14 +56,8 @@ public AvroToArrowConfigBuilder setSkipFieldNames(Set skipFieldNames) { return this; } - /** - * This builds the {@link AvroToArrowConfig} from the provided params. - */ + /** This builds the {@link AvroToArrowConfig} from the provided params. */ public AvroToArrowConfig build() { - return new AvroToArrowConfig( - allocator, - targetBatchSize, - provider, - skipFieldNames); + return new AvroToArrowConfig(allocator, targetBatchSize, provider, skipFieldNames); } } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowUtils.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowUtils.java index 1f5ad9e7689..a8fe7f8a4e3 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowUtils.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowUtils.java @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; - import org.apache.arrow.adapter.avro.consumers.AvroArraysConsumer; import org.apache.arrow.adapter.avro.consumers.AvroBooleanConsumer; import org.apache.arrow.adapter.avro.consumers.AvroBytesConsumer; @@ -106,36 +105,37 @@ public class AvroToArrowUtils { /** * Creates a {@link Consumer} from the {@link Schema} * -

This method currently performs following type mapping for Avro data types to corresponding Arrow data types. + *

This method currently performs following type mapping for Avro data types to corresponding + * Arrow data types. * *

    - *
  • STRING --> ArrowType.Utf8
  • - *
  • INT --> ArrowType.Int(32, signed)
  • - *
  • LONG --> ArrowType.Int(64, signed)
  • - *
  • FLOAT --> ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)
  • - *
  • DOUBLE --> ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)
  • - *
  • BOOLEAN --> ArrowType.Bool
  • - *
  • BYTES --> ArrowType.Binary
  • - *
  • ARRAY --> ArrowType.List
  • - *
  • MAP --> ArrowType.Map
  • - *
  • FIXED --> ArrowType.FixedSizeBinary
  • - *
  • RECORD --> ArrowType.Struct
  • - *
  • UNION --> ArrowType.Union
  • - *
  • ENUM--> ArrowType.Int
  • - *
  • DECIMAL --> ArrowType.Decimal
  • - *
  • Date --> ArrowType.Date(DateUnit.DAY)
  • - *
  • TimeMillis --> ArrowType.Time(TimeUnit.MILLISECOND, 32)
  • - *
  • TimeMicros --> ArrowType.Time(TimeUnit.MICROSECOND, 64)
  • - *
  • TimestampMillis --> ArrowType.Timestamp(TimeUnit.MILLISECOND, null)
  • - *
  • TimestampMicros --> ArrowType.Timestamp(TimeUnit.MICROSECOND, null)
  • + *
  • STRING --> ArrowType.Utf8 + *
  • INT --> ArrowType.Int(32, signed) + *
  • LONG --> ArrowType.Int(64, signed) + *
  • FLOAT --> ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE) + *
  • DOUBLE --> ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE) + *
  • BOOLEAN --> ArrowType.Bool + *
  • BYTES --> ArrowType.Binary + *
  • ARRAY --> ArrowType.List + *
  • MAP --> ArrowType.Map + *
  • FIXED --> ArrowType.FixedSizeBinary + *
  • RECORD --> ArrowType.Struct + *
  • UNION --> ArrowType.Union + *
  • ENUM--> ArrowType.Int + *
  • DECIMAL --> ArrowType.Decimal + *
  • Date --> ArrowType.Date(DateUnit.DAY) + *
  • TimeMillis --> ArrowType.Time(TimeUnit.MILLISECOND, 32) + *
  • TimeMicros --> ArrowType.Time(TimeUnit.MICROSECOND, 64) + *
  • TimestampMillis --> ArrowType.Timestamp(TimeUnit.MILLISECOND, null) + *
  • TimestampMicros --> ArrowType.Timestamp(TimeUnit.MICROSECOND, null) *
*/ - private static Consumer createConsumer(Schema schema, String name, AvroToArrowConfig config) { return createConsumer(schema, name, false, config, null); } - private static Consumer createConsumer(Schema schema, String name, AvroToArrowConfig config, FieldVector vector) { + private static Consumer createConsumer( + Schema schema, String name, AvroToArrowConfig config, FieldVector vector) { return createConsumer(schema, name, false, config, vector); } @@ -144,7 +144,8 @@ private static Consumer createConsumer(Schema schema, String name, AvroToArrowCo * * @param schema avro schema * @param name arrow field name - * @param consumerVector vector to keep in consumer, if v == null, will create a new vector via field. + * @param consumerVector vector to keep in consumer, if v == null, will create a new vector via + * field. * @return consumer */ private static Consumer createConsumer( @@ -185,7 +186,7 @@ private static Consumer createConsumer( break; case STRING: arrowType = new ArrowType.Utf8(); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroStringConsumer((VarCharVector) vector); break; @@ -193,12 +194,18 @@ private static Consumer createConsumer( Map extProps = createExternalProps(schema); if (logicalType instanceof LogicalTypes.Decimal) { arrowType = createDecimalArrowType((LogicalTypes.Decimal) logicalType); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema, extProps)); + fieldType = + new FieldType( + nullable, arrowType, /* dictionary= */ null, getMetaData(schema, extProps)); vector = createVector(consumerVector, fieldType, name, allocator); - consumer = new AvroDecimalConsumer.FixedDecimalConsumer((DecimalVector) vector, schema.getFixedSize()); + consumer = + new AvroDecimalConsumer.FixedDecimalConsumer( + (DecimalVector) vector, schema.getFixedSize()); } else { arrowType = new ArrowType.FixedSizeBinary(schema.getFixedSize()); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema, extProps)); + fieldType = + new FieldType( + nullable, arrowType, /* dictionary= */ null, getMetaData(schema, extProps)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroFixedConsumer((FixedSizeBinaryVector) vector, schema.getFixedSize()); } @@ -206,84 +213,94 @@ private static Consumer createConsumer( case INT: if (logicalType instanceof LogicalTypes.Date) { arrowType = new ArrowType.Date(DateUnit.DAY); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroDateConsumer((DateDayVector) vector); } else if (logicalType instanceof LogicalTypes.TimeMillis) { arrowType = new ArrowType.Time(TimeUnit.MILLISECOND, 32); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroTimeMillisConsumer((TimeMilliVector) vector); } else { - arrowType = new ArrowType.Int(32, /*signed=*/true); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + arrowType = new ArrowType.Int(32, /* signed= */ true); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroIntConsumer((IntVector) vector); } break; case BOOLEAN: arrowType = new ArrowType.Bool(); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroBooleanConsumer((BitVector) vector); break; case LONG: if (logicalType instanceof LogicalTypes.TimeMicros) { arrowType = new ArrowType.Time(TimeUnit.MICROSECOND, 64); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroTimeMicroConsumer((TimeMicroVector) vector); } else if (logicalType instanceof LogicalTypes.TimestampMillis) { arrowType = new ArrowType.Timestamp(TimeUnit.MILLISECOND, null); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroTimestampMillisConsumer((TimeStampMilliVector) vector); } else if (logicalType instanceof LogicalTypes.TimestampMicros) { arrowType = new ArrowType.Timestamp(TimeUnit.MICROSECOND, null); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroTimestampMicrosConsumer((TimeStampMicroVector) vector); } else { - arrowType = new ArrowType.Int(64, /*signed=*/true); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + arrowType = new ArrowType.Int(64, /* signed= */ true); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroLongConsumer((BigIntVector) vector); } break; case FLOAT: arrowType = new ArrowType.FloatingPoint(SINGLE); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroFloatConsumer((Float4Vector) vector); break; case DOUBLE: arrowType = new ArrowType.FloatingPoint(DOUBLE); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroDoubleConsumer((Float8Vector) vector); break; case BYTES: if (logicalType instanceof LogicalTypes.Decimal) { arrowType = createDecimalArrowType((LogicalTypes.Decimal) logicalType); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroDecimalConsumer.BytesDecimalConsumer((DecimalVector) vector); } else { arrowType = new ArrowType.Binary(); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); + fieldType = + new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); vector = createVector(consumerVector, fieldType, name, allocator); consumer = new AvroBytesConsumer((VarBinaryVector) vector); } break; case NULL: arrowType = new ArrowType.Null(); - fieldType = new FieldType(nullable, arrowType, /*dictionary=*/null, getMetaData(schema)); - vector = fieldType.createNewSingleVector(name, allocator, /*schemaCallback=*/null); + fieldType = new FieldType(nullable, arrowType, /* dictionary= */ null, getMetaData(schema)); + vector = fieldType.createNewSingleVector(name, allocator, /* schemaCallback= */ null); consumer = new AvroNullConsumer((NullVector) vector); break; default: // no-op, shouldn't get here - throw new UnsupportedOperationException("Can't convert avro type %s to arrow type." + type.getName()); + throw new UnsupportedOperationException( + "Can't convert avro type %s to arrow type." + type.getName()); } return consumer; } @@ -291,15 +308,16 @@ private static Consumer createConsumer( private static ArrowType createDecimalArrowType(LogicalTypes.Decimal logicalType) { final int scale = logicalType.getScale(); final int precision = logicalType.getPrecision(); - Preconditions.checkArgument(precision > 0 && precision <= 38, - "Precision must be in range of 1 to 38"); - Preconditions.checkArgument(scale >= 0 && scale <= 38, - "Scale must be in range of 0 to 38."); - Preconditions.checkArgument(scale <= precision, - "Invalid decimal scale: %s (greater than precision: %s)", scale, precision); + Preconditions.checkArgument( + precision > 0 && precision <= 38, "Precision must be in range of 1 to 38"); + Preconditions.checkArgument(scale >= 0 && scale <= 38, "Scale must be in range of 0 to 38."); + Preconditions.checkArgument( + scale <= precision, + "Invalid decimal scale: %s (greater than precision: %s)", + scale, + precision); return new ArrowType.Decimal(precision, scale, 128); - } private static Consumer createSkipConsumer(Schema schema) { @@ -309,41 +327,46 @@ private static Consumer createSkipConsumer(Schema schema) { switch (type) { case UNION: - List unionDelegates = schema.getTypes().stream().map(s -> - createSkipConsumer(s)).collect(Collectors.toList()); + List unionDelegates = + schema.getTypes().stream().map(s -> createSkipConsumer(s)).collect(Collectors.toList()); skipFunction = decoder -> unionDelegates.get(decoder.readInt()).consume(decoder); break; case ARRAY: Consumer elementDelegate = createSkipConsumer(schema.getElementType()); - skipFunction = decoder -> { - for (long i = decoder.skipArray(); i != 0; i = decoder.skipArray()) { - for (long j = 0; j < i; j++) { - elementDelegate.consume(decoder); - } - } - }; + skipFunction = + decoder -> { + for (long i = decoder.skipArray(); i != 0; i = decoder.skipArray()) { + for (long j = 0; j < i; j++) { + elementDelegate.consume(decoder); + } + } + }; break; case MAP: Consumer valueDelegate = createSkipConsumer(schema.getValueType()); - skipFunction = decoder -> { - for (long i = decoder.skipMap(); i != 0; i = decoder.skipMap()) { - for (long j = 0; j < i; j++) { - decoder.skipString(); // Discard key - valueDelegate.consume(decoder); - } - } - }; + skipFunction = + decoder -> { + for (long i = decoder.skipMap(); i != 0; i = decoder.skipMap()) { + for (long j = 0; j < i; j++) { + decoder.skipString(); // Discard key + valueDelegate.consume(decoder); + } + } + }; break; case RECORD: - List delegates = schema.getFields().stream().map(field -> - createSkipConsumer(field.schema())).collect(Collectors.toList()); + List delegates = + schema.getFields().stream() + .map(field -> createSkipConsumer(field.schema())) + .collect(Collectors.toList()); - skipFunction = decoder -> { - for (Consumer consumer : delegates) { - consumer.consume(decoder); - } - }; + skipFunction = + decoder -> { + for (Consumer consumer : delegates) { + consumer.consume(decoder); + } + }; break; case ENUM: @@ -374,7 +397,7 @@ private static Consumer createSkipConsumer(Schema schema) { skipFunction = decoder -> decoder.skipBytes(); break; case NULL: - skipFunction = decoder -> { }; + skipFunction = decoder -> {}; break; default: // no-op, shouldn't get here @@ -384,8 +407,7 @@ private static Consumer createSkipConsumer(Schema schema) { return new SkipConsumer(skipFunction); } - static CompositeAvroConsumer createCompositeConsumer( - Schema schema, AvroToArrowConfig config) { + static CompositeAvroConsumer createCompositeConsumer(Schema schema, AvroToArrowConfig config) { List consumers = new ArrayList<>(); final Set skipFieldNames = config.getSkipFieldNames(); @@ -399,7 +421,6 @@ static CompositeAvroConsumer createCompositeConsumer( Consumer consumer = createConsumer(field.schema(), field.name(), config); consumers.add(consumer); } - } } else { Consumer consumer = createConsumer(schema, "", config); @@ -409,9 +430,11 @@ static CompositeAvroConsumer createCompositeConsumer( return new CompositeAvroConsumer(consumers); } - private static FieldVector createVector(FieldVector consumerVector, FieldType fieldType, - String name, BufferAllocator allocator) { - return consumerVector != null ? consumerVector : fieldType.createNewSingleVector(name, allocator, null); + private static FieldVector createVector( + FieldVector consumerVector, FieldType fieldType, String name, BufferAllocator allocator) { + return consumerVector != null + ? consumerVector + : fieldType.createNewSingleVector(name, allocator, null); } private static String getDefaultFieldName(ArrowType type) { @@ -424,10 +447,7 @@ private static Field avroSchemaToField(Schema schema, String name, AvroToArrowCo } private static Field avroSchemaToField( - Schema schema, - String name, - AvroToArrowConfig config, - Map externalProps) { + Schema schema, String name, AvroToArrowConfig config, Map externalProps) { final Type type = schema.getType(); final LogicalType logicalType = schema.getLogicalType(); @@ -441,7 +461,8 @@ private static Field avroSchemaToField( // Union child vector should use default name children.add(avroSchemaToField(childSchema, null, config)); } - fieldType = createFieldType(new ArrowType.Union(UnionMode.Sparse, null), schema, externalProps); + fieldType = + createFieldType(new ArrowType.Union(UnionMode.Sparse, null), schema, externalProps); break; case ARRAY: Schema elementSchema = schema.getElementType(); @@ -450,14 +471,18 @@ private static Field avroSchemaToField( break; case MAP: // MapVector internal struct field and key field should be non-nullable - FieldType keyFieldType = new FieldType(/*nullable=*/false, new ArrowType.Utf8(), /*dictionary=*/null); - Field keyField = new Field("key", keyFieldType, /*children=*/null); + FieldType keyFieldType = + new FieldType(/* nullable= */ false, new ArrowType.Utf8(), /* dictionary= */ null); + Field keyField = new Field("key", keyFieldType, /* children= */ null); Field valueField = avroSchemaToField(schema.getValueType(), "value", config); - FieldType structFieldType = new FieldType(false, new ArrowType.Struct(), /*dictionary=*/null); - Field structField = new Field("internal", structFieldType, Arrays.asList(keyField, valueField)); + FieldType structFieldType = + new FieldType(false, new ArrowType.Struct(), /* dictionary= */ null); + Field structField = + new Field("internal", structFieldType, Arrays.asList(keyField, valueField)); children.add(structField); - fieldType = createFieldType(new ArrowType.Map(/*keySorted=*/false), schema, externalProps); + fieldType = + createFieldType(new ArrowType.Map(/* keySorted= */ false), schema, externalProps); break; case RECORD: final Set skipFieldNames = config.getSkipFieldNames(); @@ -486,8 +511,12 @@ private static Field avroSchemaToField( int enumCount = schema.getEnumSymbols().size(); ArrowType.Int indexType = DictionaryEncoder.getIndexType(enumCount); - fieldType = createFieldType(indexType, schema, externalProps, - new DictionaryEncoding(current, /*ordered=*/false, /*indexType=*/indexType)); + fieldType = + createFieldType( + indexType, + schema, + externalProps, + new DictionaryEncoding(current, /* ordered= */ false, /* indexType= */ indexType)); break; case STRING: @@ -509,7 +538,7 @@ private static Field avroSchemaToField( } else if (logicalType instanceof LogicalTypes.TimeMillis) { intArrowType = new ArrowType.Time(TimeUnit.MILLISECOND, 32); } else { - intArrowType = new ArrowType.Int(32, /*signed=*/true); + intArrowType = new ArrowType.Int(32, /* signed= */ true); } fieldType = createFieldType(intArrowType, schema, externalProps); break; @@ -525,7 +554,7 @@ private static Field avroSchemaToField( } else if (logicalType instanceof LogicalTypes.TimestampMicros) { longArrowType = new ArrowType.Timestamp(TimeUnit.MICROSECOND, null); } else { - longArrowType = new ArrowType.Int(64, /*signed=*/true); + longArrowType = new ArrowType.Int(64, /* signed= */ true); } fieldType = createFieldType(longArrowType, schema, externalProps); break; @@ -558,8 +587,8 @@ private static Field avroSchemaToField( return new Field(name, fieldType, children.size() == 0 ? null : children); } - private static Consumer createArrayConsumer(Schema schema, String name, AvroToArrowConfig config, - FieldVector consumerVector) { + private static Consumer createArrayConsumer( + Schema schema, String name, AvroToArrowConfig config, FieldVector consumerVector) { ListVector listVector; if (consumerVector == null) { @@ -578,8 +607,8 @@ private static Consumer createArrayConsumer(Schema schema, String name, AvroToAr return new AvroArraysConsumer(listVector, delegate); } - private static Consumer createStructConsumer(Schema schema, String name, AvroToArrowConfig config, - FieldVector consumerVector) { + private static Consumer createStructConsumer( + Schema schema, String name, AvroToArrowConfig config, FieldVector consumerVector) { final Set skipFieldNames = config.getSkipFieldNames(); @@ -601,19 +630,22 @@ private static Consumer createStructConsumer(Schema schema, String name, AvroToA if (skipFieldNames.contains(fullChildName)) { delegate = createSkipConsumer(childField.schema()); } else { - delegate = createConsumer(childField.schema(), fullChildName, config, - structVector.getChildrenFromFields().get(vectorIndex++)); + delegate = + createConsumer( + childField.schema(), + fullChildName, + config, + structVector.getChildrenFromFields().get(vectorIndex++)); } delegates[i] = delegate; } return new AvroStructConsumer(structVector, delegates); - } - private static Consumer createEnumConsumer(Schema schema, String name, AvroToArrowConfig config, - FieldVector consumerVector) { + private static Consumer createEnumConsumer( + Schema schema, String name, AvroToArrowConfig config, FieldVector consumerVector) { BaseIntVector indexVector; if (consumerVector == null) { @@ -630,16 +662,14 @@ private static Consumer createEnumConsumer(Schema schema, String name, AvroToArr for (int i = 0; i < valueCount; i++) { dictVector.set(i, schema.getEnumSymbols().get(i).getBytes(StandardCharsets.UTF_8)); } - Dictionary dictionary = - new Dictionary(dictVector, indexVector.getField().getDictionary()); + Dictionary dictionary = new Dictionary(dictVector, indexVector.getField().getDictionary()); config.getProvider().put(dictionary); return new AvroEnumConsumer(indexVector); - } - private static Consumer createMapConsumer(Schema schema, String name, AvroToArrowConfig config, - FieldVector consumerVector) { + private static Consumer createMapConsumer( + Schema schema, String name, AvroToArrowConfig config, FieldVector consumerVector) { MapVector mapVector; if (consumerVector == null) { @@ -653,10 +683,14 @@ private static Consumer createMapConsumer(Schema schema, String name, AvroToArro StructVector structVector = (StructVector) mapVector.getDataVector(); // keys in avro map are always assumed to be strings. - Consumer keyConsumer = new AvroStringConsumer( - (VarCharVector) structVector.getChildrenFromFields().get(0)); - Consumer valueConsumer = createConsumer(schema.getValueType(), schema.getValueType().getName(), - config, structVector.getChildrenFromFields().get(1)); + Consumer keyConsumer = + new AvroStringConsumer((VarCharVector) structVector.getChildrenFromFields().get(0)); + Consumer valueConsumer = + createConsumer( + schema.getValueType(), + schema.getValueType().getName(), + config, + structVector.getChildrenFromFields().get(1)); AvroStructConsumer internalConsumer = new AvroStructConsumer(structVector, new Consumer[] {keyConsumer, valueConsumer}); @@ -664,8 +698,8 @@ private static Consumer createMapConsumer(Schema schema, String name, AvroToArro return new AvroMapConsumer(mapVector, internalConsumer); } - private static Consumer createUnionConsumer(Schema schema, String name, AvroToArrowConfig config, - FieldVector consumerVector) { + private static Consumer createUnionConsumer( + Schema schema, String name, AvroToArrowConfig config, FieldVector consumerVector) { final int size = schema.getTypes().size(); final boolean nullable = schema.getTypes().stream().anyMatch(t -> t.getType() == Type.NULL); @@ -695,14 +729,12 @@ private static Consumer createUnionConsumer(Schema schema, String name, AvroToAr /** * Read data from {@link Decoder} and generate a {@link VectorSchemaRoot}. + * * @param schema avro schema * @param decoder avro decoder to read data from */ static VectorSchemaRoot avroToArrowVectors( - Schema schema, - Decoder decoder, - AvroToArrowConfig config) - throws IOException { + Schema schema, Decoder decoder, AvroToArrowConfig config) throws IOException { List vectors = new ArrayList<>(); List consumers = new ArrayList<>(); @@ -726,8 +758,8 @@ static VectorSchemaRoot avroToArrowVectors( } long validConsumerCount = consumers.stream().filter(c -> !c.skippable()).count(); - Preconditions.checkArgument(vectors.size() == validConsumerCount, - "vectors size not equals consumers size."); + Preconditions.checkArgument( + vectors.size() == validConsumerCount, "vectors size not equals consumers size."); List fields = vectors.stream().map(t -> t.getField()).collect(Collectors.toList()); @@ -767,9 +799,7 @@ private static Map getMetaData(Schema schema, Map createExternalProps(Schema schema) { final Map extProps = new HashMap<>(); String doc = schema.getDoc(); @@ -783,8 +813,9 @@ private static Map createExternalProps(Schema schema) { return extProps; } - private static FieldType createFieldType(ArrowType arrowType, Schema schema, Map externalProps) { - return createFieldType(arrowType, schema, externalProps, /*dictionary=*/null); + private static FieldType createFieldType( + ArrowType arrowType, Schema schema, Map externalProps) { + return createFieldType(arrowType, schema, externalProps, /* dictionary= */ null); } private static FieldType createFieldType( @@ -793,8 +824,8 @@ private static FieldType createFieldType( Map externalProps, DictionaryEncoding dictionary) { - return new FieldType(/*nullable=*/false, arrowType, dictionary, - getMetaData(schema, externalProps)); + return new FieldType( + /* nullable= */ false, arrowType, dictionary, getMetaData(schema, externalProps)); } private static String convertAliases(Set aliases) { diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowVectorIterator.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowVectorIterator.java index 4a439ade811..bdf554d7371 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowVectorIterator.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/AvroToArrowVectorIterator.java @@ -22,7 +22,6 @@ import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; - import org.apache.arrow.adapter.avro.consumers.CompositeAvroConsumer; import org.apache.arrow.util.Preconditions; import org.apache.arrow.vector.FieldVector; @@ -32,9 +31,7 @@ import org.apache.avro.Schema; import org.apache.avro.io.Decoder; -/** - * VectorSchemaRoot iterator for partially converting avro data. - */ +/** VectorSchemaRoot iterator for partially converting avro data. */ public class AvroToArrowVectorIterator implements Iterator, AutoCloseable { public static final int NO_LIMIT_BATCH_SIZE = -1; @@ -53,28 +50,18 @@ public class AvroToArrowVectorIterator implements Iterator, Au private final int targetBatchSize; - /** - * Construct an instance. - */ - private AvroToArrowVectorIterator( - Decoder decoder, - Schema schema, - AvroToArrowConfig config) { + /** Construct an instance. */ + private AvroToArrowVectorIterator(Decoder decoder, Schema schema, AvroToArrowConfig config) { this.decoder = decoder; this.schema = schema; this.config = config; this.targetBatchSize = config.getTargetBatchSize(); - } - /** - * Create a ArrowVectorIterator to partially convert data. - */ + /** Create a ArrowVectorIterator to partially convert data. */ public static AvroToArrowVectorIterator create( - Decoder decoder, - Schema schema, - AvroToArrowConfig config) { + Decoder decoder, Schema schema, AvroToArrowConfig config) { AvroToArrowVectorIterator iterator = new AvroToArrowVectorIterator(decoder, schema, config); try { @@ -136,9 +123,10 @@ private void load(VectorSchemaRoot root) { ValueVectorUtility.preAllocate(root, targetBatchSize); } - long validConsumerCount = compositeConsumer.getConsumers().stream().filter(c -> - !c.skippable()).count(); - Preconditions.checkArgument(root.getFieldVectors().size() == validConsumerCount, + long validConsumerCount = + compositeConsumer.getConsumers().stream().filter(c -> !c.skippable()).count(); + Preconditions.checkArgument( + root.getFieldVectors().size() == validConsumerCount, "Schema root vectors size not equals to consumers size."); compositeConsumer.resetConsumerVectors(root); @@ -159,9 +147,7 @@ public boolean hasNext() { return nextBatch != null; } - /** - * Gets the next vector. The user is responsible for freeing its resources. - */ + /** Gets the next vector. The user is responsible for freeing its resources. */ public VectorSchemaRoot next() { Preconditions.checkArgument(hasNext()); VectorSchemaRoot returned = nextBatch; @@ -174,9 +160,7 @@ public VectorSchemaRoot next() { return returned; } - /** - * Clean up resources. - */ + /** Clean up resources. */ public void close() { if (nextBatch != null) { nextBatch.close(); diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroArraysConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroArraysConsumer.java index fd25986c32b..ae84a4d9af5 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroArraysConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroArraysConsumer.java @@ -18,21 +18,17 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.complex.ListVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume array type values from avro decoder. - * Write the data to {@link ListVector}. + * Consumer which consume array type values from avro decoder. Write the data to {@link ListVector}. */ public class AvroArraysConsumer extends BaseAvroConsumer { private final Consumer delegate; - /** - * Instantiate a ArrayConsumer. - */ + /** Instantiate a ArrayConsumer. */ public AvroArraysConsumer(ListVector vector, Consumer delegate) { super(vector); this.delegate = delegate; diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroBooleanConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroBooleanConsumer.java index bf41828d19f..88c07173328 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroBooleanConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroBooleanConsumer.java @@ -18,19 +18,16 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.BitVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume boolean type values from avro decoder. - * Write the data to {@link BitVector}. + * Consumer which consume boolean type values from avro decoder. Write the data to {@link + * BitVector}. */ public class AvroBooleanConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroBooleanConsumer. - */ + /** Instantiate a AvroBooleanConsumer. */ public AvroBooleanConsumer(BitVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroBytesConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroBytesConsumer.java index c8370e48060..aa063c31c67 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroBytesConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroBytesConsumer.java @@ -19,21 +19,18 @@ import java.io.IOException; import java.nio.ByteBuffer; - import org.apache.arrow.vector.VarBinaryVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume bytes type values from avro decoder. - * Write the data to {@link VarBinaryVector}. + * Consumer which consume bytes type values from avro decoder. Write the data to {@link + * VarBinaryVector}. */ public class AvroBytesConsumer extends BaseAvroConsumer { private ByteBuffer cacheBuffer; - /** - * Instantiate a AvroBytesConsumer. - */ + /** Instantiate a AvroBytesConsumer. */ public AvroBytesConsumer(VarBinaryVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroDoubleConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroDoubleConsumer.java index 7cc7dd33b15..c387896ffc0 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroDoubleConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroDoubleConsumer.java @@ -18,19 +18,16 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.Float8Vector; import org.apache.avro.io.Decoder; /** - * Consumer which consume double type values from avro decoder. - * Write the data to {@link Float8Vector}. + * Consumer which consume double type values from avro decoder. Write the data to {@link + * Float8Vector}. */ public class AvroDoubleConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroDoubleConsumer. - */ + /** Instantiate a AvroDoubleConsumer. */ public AvroDoubleConsumer(Float8Vector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroEnumConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroEnumConsumer.java index 32a2c85f6fc..6d06f3fbce2 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroEnumConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroEnumConsumer.java @@ -18,20 +18,16 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.BaseIntVector; import org.apache.arrow.vector.IntVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume enum type values from avro decoder. - * Write the data to {@link IntVector}. + * Consumer which consume enum type values from avro decoder. Write the data to {@link IntVector}. */ public class AvroEnumConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroEnumConsumer. - */ + /** Instantiate a AvroEnumConsumer. */ public AvroEnumConsumer(BaseIntVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroFixedConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroFixedConsumer.java index 16b70898fd3..151fd3e653c 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroFixedConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroFixedConsumer.java @@ -18,21 +18,18 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.FixedSizeBinaryVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume fixed type values from avro decoder. - * Write the data to {@link org.apache.arrow.vector.FixedSizeBinaryVector}. + * Consumer which consume fixed type values from avro decoder. Write the data to {@link + * org.apache.arrow.vector.FixedSizeBinaryVector}. */ public class AvroFixedConsumer extends BaseAvroConsumer { private final byte[] reuseBytes; - /** - * Instantiate a AvroFixedConsumer. - */ + /** Instantiate a AvroFixedConsumer. */ public AvroFixedConsumer(FixedSizeBinaryVector vector, int size) { super(vector); reuseBytes = new byte[size]; diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroFloatConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroFloatConsumer.java index b09d2881875..ec37fe0d1f6 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroFloatConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroFloatConsumer.java @@ -18,19 +18,16 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.Float4Vector; import org.apache.avro.io.Decoder; /** - * Consumer which consume float type values from avro decoder. - * Write the data to {@link Float4Vector}. + * Consumer which consume float type values from avro decoder. Write the data to {@link + * Float4Vector}. */ public class AvroFloatConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroFloatConsumer. - */ + /** Instantiate a AvroFloatConsumer. */ public AvroFloatConsumer(Float4Vector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroIntConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroIntConsumer.java index ae5a2719c56..68c93cf8e9e 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroIntConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroIntConsumer.java @@ -18,19 +18,15 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.IntVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume int type values from avro decoder. - * Write the data to {@link IntVector}. + * Consumer which consume int type values from avro decoder. Write the data to {@link IntVector}. */ public class AvroIntConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroIntConsumer. - */ + /** Instantiate a AvroIntConsumer. */ public AvroIntConsumer(IntVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroLongConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroLongConsumer.java index 4db836acc45..525a6303d9e 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroLongConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroLongConsumer.java @@ -18,19 +18,16 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.BigIntVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume long type values from avro decoder. - * Write the data to {@link BigIntVector}. + * Consumer which consume long type values from avro decoder. Write the data to {@link + * BigIntVector}. */ public class AvroLongConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroLongConsumer. - */ + /** Instantiate a AvroLongConsumer. */ public AvroLongConsumer(BigIntVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroMapConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroMapConsumer.java index 1ea97e63b61..87e8a0666df 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroMapConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroMapConsumer.java @@ -18,23 +18,19 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.MapVector; import org.apache.arrow.vector.complex.StructVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume map type values from avro decoder. - * Write the data to {@link MapVector}. + * Consumer which consume map type values from avro decoder. Write the data to {@link MapVector}. */ public class AvroMapConsumer extends BaseAvroConsumer { private final Consumer delegate; - /** - * Instantiate a AvroMapConsumer. - */ + /** Instantiate a AvroMapConsumer. */ public AvroMapConsumer(MapVector vector, Consumer delegate) { super(vector); this.delegate = delegate; diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroNullConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroNullConsumer.java index 4c7bb8c03ba..5e43264a8b9 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroNullConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroNullConsumer.java @@ -18,13 +18,12 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.NullVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume null type values from avro decoder. - * Corresponding to {@link org.apache.arrow.vector.NullVector}. + * Consumer which consume null type values from avro decoder. Corresponding to {@link + * org.apache.arrow.vector.NullVector}. */ public class AvroNullConsumer extends BaseAvroConsumer { diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroStringConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroStringConsumer.java index 072270aa6c0..fe33af4d422 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroStringConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroStringConsumer.java @@ -19,21 +19,18 @@ import java.io.IOException; import java.nio.ByteBuffer; - import org.apache.arrow.vector.VarCharVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume string type values from avro decoder. - * Write the data to {@link VarCharVector}. + * Consumer which consume string type values from avro decoder. Write the data to {@link + * VarCharVector}. */ public class AvroStringConsumer extends BaseAvroConsumer { private ByteBuffer cacheBuffer; - /** - * Instantiate a AvroStringConsumer. - */ + /** Instantiate a AvroStringConsumer. */ public AvroStringConsumer(VarCharVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroStructConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroStructConsumer.java index a02b1577f9f..b5c143e0c9a 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroStructConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroStructConsumer.java @@ -18,23 +18,20 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.util.AutoCloseables; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.StructVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume nested record type values from avro decoder. - * Write the data to {@link org.apache.arrow.vector.complex.StructVector}. + * Consumer which consume nested record type values from avro decoder. Write the data to {@link + * org.apache.arrow.vector.complex.StructVector}. */ public class AvroStructConsumer extends BaseAvroConsumer { private final Consumer[] delegates; - /** - * Instantiate a AvroStructConsumer. - */ + /** Instantiate a AvroStructConsumer. */ public AvroStructConsumer(StructVector vector, Consumer[] delegates) { super(vector); this.delegates = delegates; @@ -49,7 +46,6 @@ public void consume(Decoder decoder) throws IOException { } vector.setIndexDefined(currentIndex); currentIndex++; - } @Override diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroUnionsConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroUnionsConsumer.java index 76287543b06..b25b0ef91b8 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroUnionsConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/AvroUnionsConsumer.java @@ -18,7 +18,6 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.util.AutoCloseables; import org.apache.arrow.vector.ValueVector; import org.apache.arrow.vector.complex.UnionVector; @@ -26,17 +25,15 @@ import org.apache.avro.io.Decoder; /** - * Consumer which consume unions type values from avro decoder. - * Write the data to {@link org.apache.arrow.vector.complex.UnionVector}. + * Consumer which consume unions type values from avro decoder. Write the data to {@link + * org.apache.arrow.vector.complex.UnionVector}. */ public class AvroUnionsConsumer extends BaseAvroConsumer { private Consumer[] delegates; private Types.MinorType[] types; - /** - * Instantiate an AvroUnionConsumer. - */ + /** Instantiate an AvroUnionConsumer. */ public AvroUnionsConsumer(UnionVector vector, Consumer[] delegates, Types.MinorType[] types) { super(vector); @@ -53,7 +50,8 @@ public void consume(Decoder decoder) throws IOException { vector.setType(currentIndex, types[fieldIndex]); // In UnionVector we need to set sub vector writer position before consume a value - // because in the previous iterations we might not have written to the specific union sub vector. + // because in the previous iterations we might not have written to the specific union sub + // vector. delegate.setPosition(currentIndex); delegate.consume(decoder); diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/BaseAvroConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/BaseAvroConsumer.java index 66a6cda6840..3bf8704e45b 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/BaseAvroConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/BaseAvroConsumer.java @@ -21,6 +21,7 @@ /** * Base class for non-skippable avro consumers. + * * @param vector type. */ public abstract class BaseAvroConsumer implements Consumer { @@ -30,6 +31,7 @@ public abstract class BaseAvroConsumer implements Consume /** * Constructs a base avro consumer. + * * @param vector the vector to consume. */ public BaseAvroConsumer(T vector) { diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/CompositeAvroConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/CompositeAvroConsumer.java index 97812226180..cd01af28209 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/CompositeAvroConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/CompositeAvroConsumer.java @@ -19,15 +19,11 @@ import java.io.IOException; import java.util.List; - import org.apache.arrow.util.AutoCloseables; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.avro.io.Decoder; -/** - * Composite consumer which hold all consumers. - * It manages the consume and cleanup process. - */ +/** Composite consumer which hold all consumers. It manages the consume and cleanup process. */ public class CompositeAvroConsumer implements AutoCloseable { private final List consumers; @@ -40,18 +36,14 @@ public CompositeAvroConsumer(List consumers) { this.consumers = consumers; } - /** - * Consume decoder data. - */ + /** Consume decoder data. */ public void consume(Decoder decoder) throws IOException { for (Consumer consumer : consumers) { consumer.consume(decoder); } } - /** - * Reset vector of consumers with the given {@link VectorSchemaRoot}. - */ + /** Reset vector of consumers with the given {@link VectorSchemaRoot}. */ public void resetConsumerVectors(VectorSchemaRoot root) { int index = 0; for (Consumer consumer : consumers) { diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/Consumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/Consumer.java index c2ae1ce77b2..65925630b74 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/Consumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/Consumer.java @@ -18,54 +18,45 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.FieldVector; import org.apache.avro.io.Decoder; /** * Interface that is used to consume values from avro decoder. + * * @param The vector within consumer or its delegate, used for partially consume purpose. */ public interface Consumer extends AutoCloseable { /** * Consume a specific type value from avro decoder and write it to vector. + * * @param decoder avro decoder to read data * @throws IOException on error */ void consume(Decoder decoder) throws IOException; - /** - * Add null value to vector by making writer position + 1. - */ + /** Add null value to vector by making writer position + 1. */ void addNull(); - /** - * Set the position to write value into vector. - */ + /** Set the position to write value into vector. */ void setPosition(int index); - /** - * Get the vector within the consumer. - */ + /** Get the vector within the consumer. */ FieldVector getVector(); - /** - * Close this consumer when occurs exception to avoid potential leak. - */ + /** Close this consumer when occurs exception to avoid potential leak. */ void close() throws Exception; /** * Reset the vector within consumer for partial read purpose. + * * @return true if reset is successful, false if reset is not needed. */ boolean resetValueVector(T vector); - /** - * Indicates whether the consumer is type of {@link SkipConsumer}. - */ + /** Indicates whether the consumer is type of {@link SkipConsumer}. */ default boolean skippable() { return false; } - } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/SkipConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/SkipConsumer.java index 1ac0a6d7155..05a843afd1a 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/SkipConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/SkipConsumer.java @@ -18,13 +18,10 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.arrow.vector.FieldVector; import org.apache.avro.io.Decoder; -/** - * Consumer which skip (throw away) data from the decoder. - */ +/** Consumer which skip (throw away) data from the decoder. */ public class SkipConsumer implements Consumer { private final SkipFunction skipFunction; @@ -39,12 +36,10 @@ public void consume(Decoder decoder) throws IOException { } @Override - public void addNull() { - } + public void addNull() {} @Override - public void setPosition(int index) { - } + public void setPosition(int index) {} @Override public FieldVector getVector() { @@ -52,8 +47,7 @@ public FieldVector getVector() { } @Override - public void close() throws Exception { - } + public void close() throws Exception {} @Override public boolean resetValueVector(FieldVector vector) { diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/SkipFunction.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/SkipFunction.java index 93fc4a7fede..61530cb4e4e 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/SkipFunction.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/SkipFunction.java @@ -18,12 +18,9 @@ package org.apache.arrow.adapter.avro.consumers; import java.io.IOException; - import org.apache.avro.io.Decoder; -/** - * Adapter function to skip (throw away) data from the decoder. - */ +/** Adapter function to skip (throw away) data from the decoder. */ @FunctionalInterface public interface SkipFunction { void apply(Decoder decoder) throws IOException; diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroDateConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroDateConsumer.java index a5c36d88fb7..ee4de339429 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroDateConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroDateConsumer.java @@ -18,20 +18,17 @@ package org.apache.arrow.adapter.avro.consumers.logical; import java.io.IOException; - import org.apache.arrow.adapter.avro.consumers.BaseAvroConsumer; import org.apache.arrow.vector.DateDayVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume date type values from avro decoder. - * Write the data to {@link DateDayVector}. + * Consumer which consume date type values from avro decoder. Write the data to {@link + * DateDayVector}. */ public class AvroDateConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroDateConsumer. - */ + /** Instantiate a AvroDateConsumer. */ public AvroDateConsumer(DateDayVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroDecimalConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroDecimalConsumer.java index ebe5ca3884e..2defa736b19 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroDecimalConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroDecimalConsumer.java @@ -19,35 +19,28 @@ import java.io.IOException; import java.nio.ByteBuffer; - import org.apache.arrow.adapter.avro.consumers.BaseAvroConsumer; import org.apache.arrow.util.Preconditions; import org.apache.arrow.vector.DecimalVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume decimal type values from avro decoder. - * Write the data to {@link DecimalVector}. + * Consumer which consume decimal type values from avro decoder. Write the data to {@link + * DecimalVector}. */ public abstract class AvroDecimalConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroDecimalConsumer. - */ + /** Instantiate a AvroDecimalConsumer. */ public AvroDecimalConsumer(DecimalVector vector) { super(vector); } - /** - * Consumer for decimal logical type with original bytes type. - */ + /** Consumer for decimal logical type with original bytes type. */ public static class BytesDecimalConsumer extends AvroDecimalConsumer { private ByteBuffer cacheBuffer; - /** - * Instantiate a BytesDecimalConsumer. - */ + /** Instantiate a BytesDecimalConsumer. */ public BytesDecimalConsumer(DecimalVector vector) { super(vector); } @@ -60,19 +53,14 @@ public void consume(Decoder decoder) throws IOException { cacheBuffer.get(bytes); vector.setBigEndian(currentIndex++, bytes); } - } - /** - * Consumer for decimal logical type with original fixed type. - */ + /** Consumer for decimal logical type with original fixed type. */ public static class FixedDecimalConsumer extends AvroDecimalConsumer { private byte[] reuseBytes; - /** - * Instantiate a FixedDecimalConsumer. - */ + /** Instantiate a FixedDecimalConsumer. */ public FixedDecimalConsumer(DecimalVector vector, int size) { super(vector); Preconditions.checkArgument(size <= 16, "Decimal bytes length should <= 16."); diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimeMicroConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimeMicroConsumer.java index 89216d4ad14..e838a269765 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimeMicroConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimeMicroConsumer.java @@ -18,20 +18,17 @@ package org.apache.arrow.adapter.avro.consumers.logical; import java.io.IOException; - import org.apache.arrow.adapter.avro.consumers.BaseAvroConsumer; import org.apache.arrow.vector.TimeMicroVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume date time-micro values from avro decoder. - * Write the data to {@link TimeMicroVector}. + * Consumer which consume date time-micro values from avro decoder. Write the data to {@link + * TimeMicroVector}. */ public class AvroTimeMicroConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroTimeMicroConsumer. - */ + /** Instantiate a AvroTimeMicroConsumer. */ public AvroTimeMicroConsumer(TimeMicroVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimeMillisConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimeMillisConsumer.java index ab5df8d4bc8..3780e4bb4a0 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimeMillisConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimeMillisConsumer.java @@ -18,20 +18,17 @@ package org.apache.arrow.adapter.avro.consumers.logical; import java.io.IOException; - import org.apache.arrow.adapter.avro.consumers.BaseAvroConsumer; import org.apache.arrow.vector.TimeMilliVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume date time-millis values from avro decoder. - * Write the data to {@link TimeMilliVector}. + * Consumer which consume date time-millis values from avro decoder. Write the data to {@link + * TimeMilliVector}. */ public class AvroTimeMillisConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroTimeMilliConsumer. - */ + /** Instantiate a AvroTimeMilliConsumer. */ public AvroTimeMillisConsumer(TimeMilliVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimestampMicrosConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimestampMicrosConsumer.java index 93b39d479ff..9eb01ac76db 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimestampMicrosConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimestampMicrosConsumer.java @@ -18,20 +18,17 @@ package org.apache.arrow.adapter.avro.consumers.logical; import java.io.IOException; - import org.apache.arrow.adapter.avro.consumers.BaseAvroConsumer; import org.apache.arrow.vector.TimeStampMicroVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume date timestamp-micro values from avro decoder. - * Write the data to {@link TimeStampMicroVector}. + * Consumer which consume date timestamp-micro values from avro decoder. Write the data to {@link + * TimeStampMicroVector}. */ public class AvroTimestampMicrosConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroTimestampMicroConsumer. - */ + /** Instantiate a AvroTimestampMicroConsumer. */ public AvroTimestampMicrosConsumer(TimeStampMicroVector vector) { super(vector); } diff --git a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimestampMillisConsumer.java b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimestampMillisConsumer.java index 9e651c3959f..e665082d143 100644 --- a/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimestampMillisConsumer.java +++ b/java/adapter/avro/src/main/java/org/apache/arrow/adapter/avro/consumers/logical/AvroTimestampMillisConsumer.java @@ -18,20 +18,17 @@ package org.apache.arrow.adapter.avro.consumers.logical; import java.io.IOException; - import org.apache.arrow.adapter.avro.consumers.BaseAvroConsumer; import org.apache.arrow.vector.TimeStampMilliVector; import org.apache.avro.io.Decoder; /** - * Consumer which consume date timestamp-millis values from avro decoder. - * Write the data to {@link TimeStampMilliVector}. + * Consumer which consume date timestamp-millis values from avro decoder. Write the data to {@link + * TimeStampMilliVector}. */ public class AvroTimestampMillisConsumer extends BaseAvroConsumer { - /** - * Instantiate a AvroTimestampMillisConsumer. - */ + /** Instantiate a AvroTimestampMillisConsumer. */ public AvroTimestampMillisConsumer(TimeStampMilliVector vector) { super(vector); } diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroLogicalTypesTest.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroLogicalTypesTest.java index 6ee04e33a5c..956760fa34b 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroLogicalTypesTest.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroLogicalTypesTest.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.util.DateUtility; @@ -43,13 +42,13 @@ public void testTimestampMicros() throws Exception { Schema schema = getSchema("logical/test_timestamp_micros.avsc"); List data = Arrays.asList(10000L, 20000L, 30000L, 40000L, 50000L); - List expected = Arrays.asList( - DateUtility.getLocalDateTimeFromEpochMicro(10000), - DateUtility.getLocalDateTimeFromEpochMicro(20000), - DateUtility.getLocalDateTimeFromEpochMicro(30000), - DateUtility.getLocalDateTimeFromEpochMicro(40000), - DateUtility.getLocalDateTimeFromEpochMicro(50000) - ); + List expected = + Arrays.asList( + DateUtility.getLocalDateTimeFromEpochMicro(10000), + DateUtility.getLocalDateTimeFromEpochMicro(20000), + DateUtility.getLocalDateTimeFromEpochMicro(30000), + DateUtility.getLocalDateTimeFromEpochMicro(40000), + DateUtility.getLocalDateTimeFromEpochMicro(50000)); VectorSchemaRoot root = writeAndRead(schema, data); FieldVector vector = root.getFieldVectors().get(0); @@ -62,13 +61,13 @@ public void testTimestampMillis() throws Exception { Schema schema = getSchema("logical/test_timestamp_millis.avsc"); List data = Arrays.asList(10000L, 20000L, 30000L, 40000L, 50000L); - List expected = Arrays.asList( - DateUtility.getLocalDateTimeFromEpochMilli(10000), - DateUtility.getLocalDateTimeFromEpochMilli(20000), - DateUtility.getLocalDateTimeFromEpochMilli(30000), - DateUtility.getLocalDateTimeFromEpochMilli(40000), - DateUtility.getLocalDateTimeFromEpochMilli(50000) - ); + List expected = + Arrays.asList( + DateUtility.getLocalDateTimeFromEpochMilli(10000), + DateUtility.getLocalDateTimeFromEpochMilli(20000), + DateUtility.getLocalDateTimeFromEpochMilli(30000), + DateUtility.getLocalDateTimeFromEpochMilli(40000), + DateUtility.getLocalDateTimeFromEpochMilli(50000)); VectorSchemaRoot root = writeAndRead(schema, data); FieldVector vector = root.getFieldVectors().get(0); @@ -93,13 +92,13 @@ public void testTimeMillis() throws Exception { Schema schema = getSchema("logical/test_time_millis.avsc"); List data = Arrays.asList(100, 200, 300, 400, 500); - List expected = Arrays.asList( - DateUtility.getLocalDateTimeFromEpochMilli(100), - DateUtility.getLocalDateTimeFromEpochMilli(200), - DateUtility.getLocalDateTimeFromEpochMilli(300), - DateUtility.getLocalDateTimeFromEpochMilli(400), - DateUtility.getLocalDateTimeFromEpochMilli(500) - ); + List expected = + Arrays.asList( + DateUtility.getLocalDateTimeFromEpochMilli(100), + DateUtility.getLocalDateTimeFromEpochMilli(200), + DateUtility.getLocalDateTimeFromEpochMilli(300), + DateUtility.getLocalDateTimeFromEpochMilli(400), + DateUtility.getLocalDateTimeFromEpochMilli(500)); VectorSchemaRoot root = writeAndRead(schema, data); FieldVector vector = root.getFieldVectors().get(0); @@ -137,7 +136,6 @@ public void testDecimalWithOriginalBytes() throws Exception { VectorSchemaRoot root = writeAndRead(schema, data); FieldVector vector = root.getFieldVectors().get(0); checkPrimitiveResult(expected, vector); - } @Test @@ -174,10 +172,9 @@ public void testInvalidDecimalPrecision() throws Exception { data.add(buffer); } - IllegalArgumentException e = assertThrows(IllegalArgumentException.class, - () -> writeAndRead(schema, data)); + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> writeAndRead(schema, data)); assertTrue(e.getMessage().contains("Precision must be in range of 1 to 38")); - } @Test @@ -197,5 +194,4 @@ public void testFailedToCreateDecimalLogicalType() throws Exception { Schema schema3 = getSchema("logical/test_decimal_invalid4.avsc"); assertNull(schema3.getLogicalType()); } - } diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroSkipFieldTest.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroSkipFieldTest.java index a37eca6514e..7c102610812 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroSkipFieldTest.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroSkipFieldTest.java @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Set; - import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.complex.StructVector; import org.apache.arrow.vector.types.Types; @@ -40,7 +39,10 @@ public class AvroSkipFieldTest extends AvroTestBase { public void testSkipUnionWithOneField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f0"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_union_before.avsc"); Schema expectedSchema = getSchema("skip/test_skip_union_one_field_expected.avsc"); @@ -69,7 +71,10 @@ public void testSkipUnionWithOneField() throws Exception { public void testSkipUnionWithNullableOneField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f1"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_union_before.avsc"); Schema expectedSchema = getSchema("skip/test_skip_union_nullable_field_expected.avsc"); @@ -98,7 +103,10 @@ public void testSkipUnionWithNullableOneField() throws Exception { public void testSkipUnionWithMultiFields() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f2"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_union_before.avsc"); Schema expectedSchema = getSchema("skip/test_skip_union_multi_fields_expected.avsc"); @@ -127,7 +135,10 @@ public void testSkipUnionWithMultiFields() throws Exception { public void testSkipMapField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f1"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_map_before.avsc"); Schema expectedSchema = getSchema("skip/test_skip_map_expected.avsc"); @@ -159,7 +170,10 @@ public void testSkipMapField() throws Exception { public void testSkipArrayField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f1"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_array_before.avsc"); Schema expectedSchema = getSchema("skip/test_skip_array_expected.avsc"); @@ -188,7 +202,10 @@ public void testSkipMultiFields() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f1"); skipFieldNames.add("f2"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("test_record.avsc"); Schema expectedSchema = getSchema("skip/test_skip_multi_fields_expected.avsc"); @@ -215,7 +232,10 @@ public void testSkipMultiFields() throws Exception { public void testSkipStringField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f2"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base1.avsc"); Schema expectedSchema = getSchema("skip/test_skip_string_expected.avsc"); @@ -228,7 +248,8 @@ public void testSkipStringField() throws Exception { GenericData.Fixed fixed = new GenericData.Fixed(schema.getField("f0").schema()); fixed.bytes(testBytes); record.put(0, fixed); - GenericData.EnumSymbol symbol = new GenericData.EnumSymbol(schema.getField("f1").schema(), "TEST" + i % 2); + GenericData.EnumSymbol symbol = + new GenericData.EnumSymbol(schema.getField("f1").schema(), "TEST" + i % 2); record.put(1, symbol); record.put(2, "testtest" + i); record.put(3, ByteBuffer.wrap(testBytes)); @@ -249,7 +270,10 @@ public void testSkipStringField() throws Exception { public void testSkipBytesField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f3"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base1.avsc"); Schema expectedSchema = getSchema("skip/test_skip_bytes_expected.avsc"); @@ -262,7 +286,8 @@ public void testSkipBytesField() throws Exception { GenericData.Fixed fixed = new GenericData.Fixed(schema.getField("f0").schema()); fixed.bytes(testBytes); record.put(0, fixed); - GenericData.EnumSymbol symbol = new GenericData.EnumSymbol(schema.getField("f1").schema(), "TEST" + i % 2); + GenericData.EnumSymbol symbol = + new GenericData.EnumSymbol(schema.getField("f1").schema(), "TEST" + i % 2); record.put(1, symbol); record.put(2, "testtest" + i); record.put(3, ByteBuffer.wrap(testBytes)); @@ -283,7 +308,10 @@ public void testSkipBytesField() throws Exception { public void testSkipFixedField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f0"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base1.avsc"); Schema expectedSchema = getSchema("skip/test_skip_fixed_expected.avsc"); @@ -296,7 +324,8 @@ public void testSkipFixedField() throws Exception { GenericData.Fixed fixed = new GenericData.Fixed(schema.getField("f0").schema()); fixed.bytes(testBytes); record.put(0, fixed); - GenericData.EnumSymbol symbol = new GenericData.EnumSymbol(schema.getField("f1").schema(), "TEST" + i % 2); + GenericData.EnumSymbol symbol = + new GenericData.EnumSymbol(schema.getField("f1").schema(), "TEST" + i % 2); record.put(1, symbol); record.put(2, "testtest" + i); record.put(3, ByteBuffer.wrap(testBytes)); @@ -317,7 +346,10 @@ public void testSkipFixedField() throws Exception { public void testSkipEnumField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f1"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base1.avsc"); Schema expectedSchema = getSchema("skip/test_skip_fixed_expected.avsc"); @@ -330,7 +362,8 @@ public void testSkipEnumField() throws Exception { GenericData.Fixed fixed = new GenericData.Fixed(schema.getField("f0").schema()); fixed.bytes(testBytes); record.put(0, fixed); - GenericData.EnumSymbol symbol = new GenericData.EnumSymbol(schema.getField("f1").schema(), "TEST" + i % 2); + GenericData.EnumSymbol symbol = + new GenericData.EnumSymbol(schema.getField("f1").schema(), "TEST" + i % 2); record.put(1, symbol); record.put(2, "testtest" + i); record.put(3, ByteBuffer.wrap(testBytes)); @@ -351,7 +384,10 @@ public void testSkipEnumField() throws Exception { public void testSkipBooleanField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f0"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base2.avsc"); Schema expectedSchema = getSchema("skip/test_skip_boolean_expected.avsc"); @@ -384,7 +420,10 @@ public void testSkipBooleanField() throws Exception { public void testSkipIntField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f1"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base2.avsc"); Schema expectedSchema = getSchema("skip/test_skip_int_expected.avsc"); @@ -417,7 +456,10 @@ public void testSkipIntField() throws Exception { public void testSkipLongField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f2"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base2.avsc"); Schema expectedSchema = getSchema("skip/test_skip_long_expected.avsc"); @@ -450,7 +492,10 @@ public void testSkipLongField() throws Exception { public void testSkipFloatField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f3"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base2.avsc"); Schema expectedSchema = getSchema("skip/test_skip_float_expected.avsc"); @@ -483,7 +528,10 @@ public void testSkipFloatField() throws Exception { public void testSkipDoubleField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f4"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_base2.avsc"); Schema expectedSchema = getSchema("skip/test_skip_double_expected.avsc"); @@ -516,7 +564,10 @@ public void testSkipDoubleField() throws Exception { public void testSkipRecordField() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f0"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("skip/test_skip_record_before.avsc"); Schema nestedSchema = schema.getFields().get(0).schema(); ArrayList data = new ArrayList<>(); @@ -546,7 +597,10 @@ public void testSkipRecordField() throws Exception { public void testSkipNestedFields() throws Exception { Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f0.f0"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); Schema schema = getSchema("test_nested_record.avsc"); Schema nestedSchema = schema.getFields().get(0).schema(); ArrayList data = new ArrayList<>(); @@ -602,21 +656,26 @@ public void testSkipThirdLevelField() throws Exception { assertEquals(Types.MinorType.STRUCT, root1.getFieldVectors().get(0).getMinorType()); StructVector secondLevelVector = (StructVector) root1.getFieldVectors().get(0); assertEquals(1, secondLevelVector.getChildrenFromFields().size()); - assertEquals(Types.MinorType.STRUCT, secondLevelVector.getChildrenFromFields().get(0).getMinorType()); + assertEquals( + Types.MinorType.STRUCT, secondLevelVector.getChildrenFromFields().get(0).getMinorType()); StructVector thirdLevelVector = (StructVector) secondLevelVector.getChildrenFromFields().get(0); assertEquals(3, thirdLevelVector.getChildrenFromFields().size()); // skip third level field and validate Set skipFieldNames = new HashSet<>(); skipFieldNames.add("f0.f0.f0"); - config = new AvroToArrowConfigBuilder(config.getAllocator()).setSkipFieldNames(skipFieldNames).build(); + config = + new AvroToArrowConfigBuilder(config.getAllocator()) + .setSkipFieldNames(skipFieldNames) + .build(); VectorSchemaRoot root2 = writeAndRead(firstLevelSchema, data); assertEquals(1, root2.getFieldVectors().size()); assertEquals(Types.MinorType.STRUCT, root2.getFieldVectors().get(0).getMinorType()); StructVector secondStruct = (StructVector) root2.getFieldVectors().get(0); assertEquals(1, secondStruct.getChildrenFromFields().size()); - assertEquals(Types.MinorType.STRUCT, secondStruct.getChildrenFromFields().get(0).getMinorType()); + assertEquals( + Types.MinorType.STRUCT, secondStruct.getChildrenFromFields().get(0).getMinorType()); StructVector thirdStruct = (StructVector) secondStruct.getChildrenFromFields().get(0); assertEquals(2, thirdStruct.getChildrenFromFields().size()); diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroTestBase.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroTestBase.java index 60a3a285db3..1c2e551c631 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroTestBase.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroTestBase.java @@ -29,7 +29,6 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.FieldVector; @@ -51,8 +50,7 @@ public class AvroTestBase { - @ClassRule - public static final TemporaryFolder TMP = new TemporaryFolder(); + @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); protected AvroToArrowConfig config; @@ -64,18 +62,21 @@ public void init() { public static Schema getSchema(String schemaName) throws Exception { try { - // Attempt to use JDK 9 behavior of getting the module then the resource stream from the module. + // Attempt to use JDK 9 behavior of getting the module then the resource stream from the + // module. // Note that this code is caller-sensitive. Method getModuleMethod = Class.class.getMethod("getModule"); Object module = getModuleMethod.invoke(TestWriteReadAvroRecord.class); - Method getResourceAsStreamFromModule = module.getClass().getMethod("getResourceAsStream", String.class); - try (InputStream is = (InputStream) getResourceAsStreamFromModule.invoke(module, "/schema/" + schemaName)) { - return new Schema.Parser() - .parse(is); + Method getResourceAsStreamFromModule = + module.getClass().getMethod("getResourceAsStream", String.class); + try (InputStream is = + (InputStream) getResourceAsStreamFromModule.invoke(module, "/schema/" + schemaName)) { + return new Schema.Parser().parse(is); } } catch (NoSuchMethodException ex) { // Use JDK8 behavior. - try (InputStream is = TestWriteReadAvroRecord.class.getResourceAsStream("/schema/" + schemaName)) { + try (InputStream is = + TestWriteReadAvroRecord.class.getResourceAsStream("/schema/" + schemaName)) { return new Schema.Parser().parse(is); } } @@ -84,11 +85,11 @@ public static Schema getSchema(String schemaName) throws Exception { protected VectorSchemaRoot writeAndRead(Schema schema, List data) throws Exception { File dataFile = TMP.newFile(); - BinaryEncoder - encoder = new EncoderFactory().directBinaryEncoder(new FileOutputStream(dataFile), null); + BinaryEncoder encoder = + new EncoderFactory().directBinaryEncoder(new FileOutputStream(dataFile), null); DatumWriter writer = new GenericDatumWriter(schema); - BinaryDecoder - decoder = new DecoderFactory().directBinaryDecoder(new FileInputStream(dataFile), null); + BinaryDecoder decoder = + new DecoderFactory().directBinaryDecoder(new FileInputStream(dataFile), null); for (Object value : data) { writer.write(value, encoder); @@ -145,7 +146,8 @@ protected void checkPrimitiveResult(List data, FieldVector vector) { } } - protected void checkRecordResult(Schema schema, ArrayList data, VectorSchemaRoot root) { + protected void checkRecordResult( + Schema schema, ArrayList data, VectorSchemaRoot root) { assertEquals(data.size(), root.getRowCount()); assertEquals(schema.getFields().size(), root.getFieldVectors().size()); @@ -157,10 +159,10 @@ protected void checkRecordResult(Schema schema, ArrayList data, V checkPrimitiveResult(fieldData, root.getFieldVectors().get(i)); } - } - protected void checkNestedRecordResult(Schema schema, List data, VectorSchemaRoot root) { + protected void checkNestedRecordResult( + Schema schema, List data, VectorSchemaRoot root) { assertEquals(data.size(), root.getRowCount()); assertTrue(schema.getFields().size() == 1); @@ -176,10 +178,8 @@ protected void checkNestedRecordResult(Schema schema, List data, checkPrimitiveResult(fieldData, structVector.getChildrenFromFields().get(i)); } - } - // belows are for iterator api protected void checkArrayResult(List> expected, List vectors) { @@ -194,10 +194,12 @@ protected void checkArrayResult(List> expected, List vectors } } - protected void checkRecordResult(Schema schema, ArrayList data, List roots) { - roots.forEach(root -> { - assertEquals(schema.getFields().size(), root.getFieldVectors().size()); - }); + protected void checkRecordResult( + Schema schema, ArrayList data, List roots) { + roots.forEach( + root -> { + assertEquals(schema.getFields().size(), root.getFieldVectors().size()); + }); for (int i = 0; i < schema.getFields().size(); i++) { List fieldData = new ArrayList(); @@ -210,7 +212,6 @@ protected void checkRecordResult(Schema schema, ArrayList data, L checkPrimitiveResult(fieldData, vectors); } - } protected void checkPrimitiveResult(List data, List vectors) { diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowIteratorTest.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowIteratorTest.java index 02f7a373373..0479e3693e3 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowIteratorTest.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowIteratorTest.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.util.AutoCloseables; @@ -59,11 +58,11 @@ public void init() { private AvroToArrowVectorIterator convert(Schema schema, List data) throws Exception { File dataFile = TMP.newFile(); - BinaryEncoder - encoder = new EncoderFactory().directBinaryEncoder(new FileOutputStream(dataFile), null); + BinaryEncoder encoder = + new EncoderFactory().directBinaryEncoder(new FileOutputStream(dataFile), null); DatumWriter writer = new GenericDatumWriter(schema); - BinaryDecoder - decoder = new DecoderFactory().directBinaryDecoder(new FileInputStream(dataFile), null); + BinaryDecoder decoder = + new DecoderFactory().directBinaryDecoder(new FileInputStream(dataFile), null); for (Object value : data) { writer.write(value, encoder); @@ -107,7 +106,7 @@ public void testNullableStringType() throws Exception { List roots = new ArrayList<>(); List vectors = new ArrayList<>(); - try (AvroToArrowVectorIterator iterator = convert(schema, data);) { + try (AvroToArrowVectorIterator iterator = convert(schema, data); ) { while (iterator.hasNext()) { VectorSchemaRoot root = iterator.next(); FieldVector vector = root.getFieldVectors().get(0); @@ -117,7 +116,6 @@ public void testNullableStringType() throws Exception { } checkPrimitiveResult(expected, vectors); AutoCloseables.close(roots); - } @Test @@ -140,18 +138,18 @@ public void testRecordType() throws Exception { } checkRecordResult(schema, data, roots); AutoCloseables.close(roots); - } @Test public void testArrayType() throws Exception { Schema schema = getSchema("test_array.avsc"); - List> data = Arrays.asList( - Arrays.asList("11", "222", "999"), - Arrays.asList("12222", "2333", "1000"), - Arrays.asList("1rrr", "2ggg"), - Arrays.asList("1vvv", "2bbb"), - Arrays.asList("1fff", "2")); + List> data = + Arrays.asList( + Arrays.asList("11", "222", "999"), + Arrays.asList("12222", "2333", "1000"), + Arrays.asList("1rrr", "2ggg"), + Arrays.asList("1vvv", "2bbb"), + Arrays.asList("1fff", "2")); List roots = new ArrayList<>(); List vectors = new ArrayList<>(); @@ -172,8 +170,9 @@ public void runLargeNumberOfRows() throws Exception { int x = 0; final int targetRows = 600000; Decoder fakeDecoder = new FakeDecoder(targetRows); - try (AvroToArrowVectorIterator iter = AvroToArrow.avroToArrowIterator(schema, fakeDecoder, - new AvroToArrowConfigBuilder(config.getAllocator()).build())) { + try (AvroToArrowVectorIterator iter = + AvroToArrow.avroToArrowIterator( + schema, fakeDecoder, new AvroToArrowConfigBuilder(config.getAllocator()).build())) { while (iter.hasNext()) { VectorSchemaRoot root = iter.next(); x += root.getRowCount(); @@ -184,9 +183,7 @@ public void runLargeNumberOfRows() throws Exception { assertEquals(x, targetRows); } - /** - * Fake avro decoder to test large data. - */ + /** Fake avro decoder to test large data. */ private class FakeDecoder extends Decoder { private int numRows; @@ -204,8 +201,7 @@ private void validate() throws EOFException { } @Override - public void readNull() throws IOException { - } + public void readNull() throws IOException {} @Override public boolean readBoolean() throws IOException { @@ -243,9 +239,7 @@ public String readString() throws IOException { } @Override - public void skipString() throws IOException { - - } + public void skipString() throws IOException {} @Override public ByteBuffer readBytes(ByteBuffer old) throws IOException { @@ -253,9 +247,7 @@ public ByteBuffer readBytes(ByteBuffer old) throws IOException { } @Override - public void skipBytes() throws IOException { - - } + public void skipBytes() throws IOException {} @Override public void readFixed(byte[] bytes, int start, int length) throws IOException { @@ -264,9 +256,7 @@ public void readFixed(byte[] bytes, int start, int length) throws IOException { } @Override - public void skipFixed(int length) throws IOException { - - } + public void skipFixed(int length) throws IOException {} @Override public int readEnum() throws IOException { diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowTest.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowTest.java index 1c642041917..12ec191d953 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowTest.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/AvroToArrowTest.java @@ -26,7 +26,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.VarCharVector; import org.apache.arrow.vector.VectorSchemaRoot; @@ -107,12 +106,13 @@ public void testFixedAttributes() throws Exception { @Test public void testEnumAttributes() throws Exception { Schema schema = getSchema("attrs/test_enum_attrs.avsc"); - List data = Arrays.asList( - new GenericData.EnumSymbol(schema, "SPADES"), - new GenericData.EnumSymbol(schema, "HEARTS"), - new GenericData.EnumSymbol(schema, "DIAMONDS"), - new GenericData.EnumSymbol(schema, "CLUBS"), - new GenericData.EnumSymbol(schema, "SPADES")); + List data = + Arrays.asList( + new GenericData.EnumSymbol(schema, "SPADES"), + new GenericData.EnumSymbol(schema, "HEARTS"), + new GenericData.EnumSymbol(schema, "DIAMONDS"), + new GenericData.EnumSymbol(schema, "CLUBS"), + new GenericData.EnumSymbol(schema, "SPADES")); VectorSchemaRoot root = writeAndRead(schema, data); FieldVector vector = root.getFieldVectors().get(0); @@ -174,12 +174,13 @@ public void testNestedRecordType() throws Exception { @Test public void testEnumType() throws Exception { Schema schema = getSchema("test_primitive_enum.avsc"); - List data = Arrays.asList( - new GenericData.EnumSymbol(schema, "SPADES"), - new GenericData.EnumSymbol(schema, "HEARTS"), - new GenericData.EnumSymbol(schema, "DIAMONDS"), - new GenericData.EnumSymbol(schema, "CLUBS"), - new GenericData.EnumSymbol(schema, "SPADES")); + List data = + Arrays.asList( + new GenericData.EnumSymbol(schema, "SPADES"), + new GenericData.EnumSymbol(schema, "HEARTS"), + new GenericData.EnumSymbol(schema, "DIAMONDS"), + new GenericData.EnumSymbol(schema, "CLUBS"), + new GenericData.EnumSymbol(schema, "SPADES")); List expectedIndices = Arrays.asList(0, 1, 2, 3, 0); @@ -304,12 +305,13 @@ public void testNullableDoubleType() throws Exception { @Test public void testBytesType() throws Exception { Schema schema = getSchema("test_primitive_bytes.avsc"); - List data = Arrays.asList( - ByteBuffer.wrap("value1".getBytes(StandardCharsets.UTF_8)), - ByteBuffer.wrap("value2".getBytes(StandardCharsets.UTF_8)), - ByteBuffer.wrap("value3".getBytes(StandardCharsets.UTF_8)), - ByteBuffer.wrap("value4".getBytes(StandardCharsets.UTF_8)), - ByteBuffer.wrap("value5".getBytes(StandardCharsets.UTF_8))); + List data = + Arrays.asList( + ByteBuffer.wrap("value1".getBytes(StandardCharsets.UTF_8)), + ByteBuffer.wrap("value2".getBytes(StandardCharsets.UTF_8)), + ByteBuffer.wrap("value3".getBytes(StandardCharsets.UTF_8)), + ByteBuffer.wrap("value4".getBytes(StandardCharsets.UTF_8)), + ByteBuffer.wrap("value5".getBytes(StandardCharsets.UTF_8))); VectorSchemaRoot root = writeAndRead(schema, data); FieldVector vector = root.getFieldVectors().get(0); @@ -324,7 +326,8 @@ public void testNullableBytesType() throws Exception { ArrayList data = new ArrayList<>(); for (int i = 0; i < 5; i++) { GenericRecord record = new GenericData.Record(schema); - record.put(0, i % 2 == 0 ? ByteBuffer.wrap(("test" + i).getBytes(StandardCharsets.UTF_8)) : null); + record.put( + 0, i % 2 == 0 ? ByteBuffer.wrap(("test" + i).getBytes(StandardCharsets.UTF_8)) : null); data.add(record); } @@ -361,12 +364,13 @@ public void testNullableBooleanType() throws Exception { @Test public void testArrayType() throws Exception { Schema schema = getSchema("test_array.avsc"); - List> data = Arrays.asList( - Arrays.asList("11", "222", "999"), - Arrays.asList("12222", "2333", "1000"), - Arrays.asList("1rrr", "2ggg"), - Arrays.asList("1vvv", "2bbb"), - Arrays.asList("1fff", "2")); + List> data = + Arrays.asList( + Arrays.asList("11", "222", "999"), + Arrays.asList("12222", "2333", "1000"), + Arrays.asList("1rrr", "2ggg"), + Arrays.asList("1vvv", "2bbb"), + Arrays.asList("1fff", "2")); VectorSchemaRoot root = writeAndRead(schema, data); FieldVector vector = root.getFieldVectors().get(0); @@ -473,5 +477,4 @@ public void testNullableUnionType() throws Exception { checkPrimitiveResult(expected, vector); } - } diff --git a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/TestWriteReadAvroRecord.java b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/TestWriteReadAvroRecord.java index afbddaa6ed8..1924a58a94d 100644 --- a/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/TestWriteReadAvroRecord.java +++ b/java/adapter/avro/src/test/java/org/apache/arrow/adapter/avro/TestWriteReadAvroRecord.java @@ -22,7 +22,6 @@ import java.io.File; import java.util.ArrayList; import java.util.List; - import org.apache.avro.Schema; import org.apache.avro.file.DataFileReader; import org.apache.avro.file.DataFileWriter; @@ -36,11 +35,9 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; - public class TestWriteReadAvroRecord { - @ClassRule - public static final TemporaryFolder TMP = new TemporaryFolder(); + @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); @Test public void testWriteAndRead() throws Exception { @@ -48,7 +45,7 @@ public void testWriteAndRead() throws Exception { File dataFile = TMP.newFile(); Schema schema = AvroTestBase.getSchema("test.avsc"); - //write data to disk + // write data to disk GenericRecord user1 = new GenericData.Record(schema); user1.put("name", "Alyssa"); user1.put("favorite_number", 256); @@ -65,10 +62,10 @@ public void testWriteAndRead() throws Exception { dataFileWriter.append(user2); dataFileWriter.close(); - //read data from disk + // read data from disk DatumReader datumReader = new GenericDatumReader(schema); - DataFileReader - dataFileReader = new DataFileReader(dataFile, datumReader); + DataFileReader dataFileReader = + new DataFileReader(dataFile, datumReader); List result = new ArrayList<>(); while (dataFileReader.hasNext()) { GenericRecord user = dataFileReader.next(); @@ -86,5 +83,4 @@ public void testWriteAndRead() throws Exception { assertEquals(7, deUser2.get("favorite_number")); assertEquals("red", deUser2.get("favorite_color").toString()); } - } diff --git a/java/adapter/avro/src/test/resources/logback.xml b/java/adapter/avro/src/test/resources/logback.xml index 4c54d18a210..9fa3f1e3b43 100644 --- a/java/adapter/avro/src/test/resources/logback.xml +++ b/java/adapter/avro/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/adapter/jdbc/pom.xml b/java/adapter/jdbc/pom.xml index e964aa1871a..9b70b074379 100644 --- a/java/adapter/jdbc/pom.xml +++ b/java/adapter/jdbc/pom.xml @@ -1,15 +1,14 @@ - + 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. --> 4.0.0 diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/ArrowVectorIterator.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/ArrowVectorIterator.java index 427c766982f..56aea04db9d 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/ArrowVectorIterator.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/ArrowVectorIterator.java @@ -23,7 +23,6 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.Iterator; - import org.apache.arrow.adapter.jdbc.consumer.CompositeJdbcConsumer; import org.apache.arrow.adapter.jdbc.consumer.JdbcConsumer; import org.apache.arrow.adapter.jdbc.consumer.exceptions.JdbcConsumerException; @@ -35,9 +34,7 @@ import org.apache.arrow.vector.types.pojo.Schema; import org.apache.arrow.vector.util.ValueVectorUtility; -/** - * VectorSchemaRoot iterator for partially converting JDBC data. - */ +/** VectorSchemaRoot iterator for partially converting JDBC data. */ public class ArrowVectorIterator implements Iterator, AutoCloseable { private final ResultSet resultSet; @@ -54,13 +51,12 @@ public class ArrowVectorIterator implements Iterator, AutoClos private final int targetBatchSize; - // This is used to track whether the ResultSet has been fully read, and is needed specifically for cases where there + // This is used to track whether the ResultSet has been fully read, and is needed specifically for + // cases where there // is a ResultSet having zero rows (empty): private boolean readComplete = false; - /** - * Construct an instance. - */ + /** Construct an instance. */ private ArrowVectorIterator(ResultSet resultSet, JdbcToArrowConfig config) throws SQLException { this.resultSet = resultSet; this.config = config; @@ -73,12 +69,8 @@ private ArrowVectorIterator(ResultSet resultSet, JdbcToArrowConfig config) throw this.nextBatch = config.isReuseVectorSchemaRoot() ? createVectorSchemaRoot() : null; } - /** - * Create a ArrowVectorIterator to partially convert data. - */ - public static ArrowVectorIterator create( - ResultSet resultSet, - JdbcToArrowConfig config) + /** Create a ArrowVectorIterator to partially convert data. */ + public static ArrowVectorIterator create(ResultSet resultSet, JdbcToArrowConfig config) throws SQLException { ArrowVectorIterator iterator = null; try { @@ -142,10 +134,18 @@ private VectorSchemaRoot createVectorSchemaRoot() throws SQLException { private void initialize(VectorSchemaRoot root) throws SQLException { for (int i = 1; i <= consumers.length; i++) { - final JdbcFieldInfo columnFieldInfo = JdbcToArrowUtils.getJdbcFieldInfoForColumn(rsmd, i, config); + final JdbcFieldInfo columnFieldInfo = + JdbcToArrowUtils.getJdbcFieldInfoForColumn(rsmd, i, config); ArrowType arrowType = config.getJdbcToArrowTypeConverter().apply(columnFieldInfo); - consumers[i - 1] = config.getJdbcConsumerGetter().apply( - arrowType, i, isColumnNullable(resultSet.getMetaData(), i, columnFieldInfo), root.getVector(i - 1), config); + consumers[i - 1] = + config + .getJdbcConsumerGetter() + .apply( + arrowType, + i, + isColumnNullable(resultSet.getMetaData(), i, columnFieldInfo), + root.getVector(i - 1), + config); } } @@ -170,16 +170,17 @@ public boolean hasNext() { } /** - * Gets the next vector. - * If {@link JdbcToArrowConfig#isReuseVectorSchemaRoot()} is false, - * the client is responsible for freeing its resources. + * Gets the next vector. If {@link JdbcToArrowConfig#isReuseVectorSchemaRoot()} is false, the + * client is responsible for freeing its resources. + * * @throws JdbcConsumerException on error from VectorConsumer */ @Override public VectorSchemaRoot next() { Preconditions.checkArgument(hasNext()); try { - VectorSchemaRoot ret = config.isReuseVectorSchemaRoot() ? nextBatch : createVectorSchemaRoot(); + VectorSchemaRoot ret = + config.isReuseVectorSchemaRoot() ? nextBatch : createVectorSchemaRoot(); load(ret); return ret; } catch (Exception e) { @@ -193,8 +194,9 @@ public VectorSchemaRoot next() { } /** - * Clean up resources ONLY WHEN THE {@link VectorSchemaRoot} HOLDING EACH BATCH IS REUSED. If a new VectorSchemaRoot - * is created for each batch, each root must be closed manually by the client code. + * Clean up resources ONLY WHEN THE {@link VectorSchemaRoot} HOLDING EACH BATCH IS REUSED. If a + * new VectorSchemaRoot is created for each batch, each root must be closed manually by the client + * code. */ @Override public void close() { diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/Constants.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/Constants.java index 5b01077b179..ce5f28680d8 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/Constants.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/Constants.java @@ -17,9 +17,7 @@ package org.apache.arrow.adapter.jdbc; -/** - * String constants used for metadata returned on Vectors. - */ +/** String constants used for metadata returned on Vectors. */ public class Constants { private Constants() {} @@ -28,5 +26,4 @@ private Constants() {} public static final String SQL_TABLE_NAME_KEY = "SQL_TABLE_NAME"; public static final String SQL_COLUMN_NAME_KEY = "SQL_COLUMN_NAME"; public static final String SQL_TYPE_KEY = "SQL_TYPE"; - } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfo.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfo.java index d16964ea144..536b837d5bd 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfo.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfo.java @@ -21,18 +21,19 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.util.Preconditions; /** - * This class represents the information about a JDBC ResultSet Field that is - * needed to construct an {@link org.apache.arrow.vector.types.pojo.ArrowType}. - * Currently, this is: + * This class represents the information about a JDBC ResultSet Field that is needed to construct an + * {@link org.apache.arrow.vector.types.pojo.ArrowType}. Currently, this is: + * *
    - *
  • The JDBC {@link java.sql.Types} type.
  • - *
  • The nullability.
  • - *
  • The field's precision (used for {@link java.sql.Types#DECIMAL} and {@link java.sql.Types#NUMERIC} types).
  • - *
  • The field's scale (used for {@link java.sql.Types#DECIMAL} and {@link java.sql.Types#NUMERIC} types).
  • + *
  • The JDBC {@link java.sql.Types} type. + *
  • The nullability. + *
  • The field's precision (used for {@link java.sql.Types#DECIMAL} and {@link + * java.sql.Types#NUMERIC} types). + *
  • The field's scale (used for {@link java.sql.Types#DECIMAL} and {@link + * java.sql.Types#NUMERIC} types). *
*/ public class JdbcFieldInfo { @@ -45,12 +46,13 @@ public class JdbcFieldInfo { private final int displaySize; /** - * Builds a JdbcFieldInfo using only the {@link java.sql.Types} type. Do not use this constructor - * if the field type is {@link java.sql.Types#DECIMAL} or {@link java.sql.Types#NUMERIC}; the precision and - * scale will be set to 0. + * Builds a JdbcFieldInfo using only the {@link java.sql.Types} type. Do not use this + * constructor if the field type is {@link java.sql.Types#DECIMAL} or {@link + * java.sql.Types#NUMERIC}; the precision and scale will be set to 0. * * @param jdbcType The {@link java.sql.Types} type. - * @throws IllegalArgumentException if jdbcType is {@link java.sql.Types#DECIMAL} or {@link java.sql.Types#NUMERIC}. + * @throws IllegalArgumentException if jdbcType is {@link java.sql.Types#DECIMAL} or {@link + * java.sql.Types#NUMERIC}. */ public JdbcFieldInfo(int jdbcType) { Preconditions.checkArgument( @@ -67,7 +69,8 @@ public JdbcFieldInfo(int jdbcType) { /** * Builds a JdbcFieldInfo from the {@link java.sql.Types} type, precision, and scale. - * Use this constructor for {@link java.sql.Types#DECIMAL} and {@link java.sql.Types#NUMERIC} types. + * Use this constructor for {@link java.sql.Types#DECIMAL} and {@link java.sql.Types#NUMERIC} + * types. * * @param jdbcType The {@link java.sql.Types} type. * @param precision The field's numeric precision. @@ -84,11 +87,13 @@ public JdbcFieldInfo(int jdbcType, int precision, int scale) { } /** - * Builds a JdbcFieldInfo from the {@link java.sql.Types} type, nullability, precision, and scale. + * Builds a JdbcFieldInfo from the {@link java.sql.Types} type, nullability, + * precision, and scale. * * @param jdbcType The {@link java.sql.Types} type. * @param nullability The nullability. Must be one of {@link ResultSetMetaData#columnNoNulls}, - * {@link ResultSetMetaData#columnNullable}, or {@link ResultSetMetaData#columnNullableUnknown}. + * {@link ResultSetMetaData#columnNullable}, or {@link + * ResultSetMetaData#columnNullableUnknown}. * @param precision The field's numeric precision. * @param scale The field's numeric scale. */ @@ -103,7 +108,8 @@ public JdbcFieldInfo(int jdbcType, int nullability, int precision, int scale) { } /** - * Builds a JdbcFieldInfo from the corresponding {@link java.sql.ResultSetMetaData} column. + * Builds a JdbcFieldInfo from the corresponding {@link java.sql.ResultSetMetaData} + * column. * * @param rsmd The {@link java.sql.ResultSetMetaData} to get the field information from. * @param column The column to get the field information for (on a 1-based index). @@ -113,10 +119,12 @@ public JdbcFieldInfo(int jdbcType, int nullability, int precision, int scale) { */ public JdbcFieldInfo(ResultSetMetaData rsmd, int column) throws SQLException { Preconditions.checkNotNull(rsmd, "ResultSetMetaData cannot be null."); - Preconditions.checkArgument(column > 0, "ResultSetMetaData columns have indices starting at 1."); + Preconditions.checkArgument( + column > 0, "ResultSetMetaData columns have indices starting at 1."); Preconditions.checkArgument( column <= rsmd.getColumnCount(), - "The index must be within the number of columns (1 to %s, inclusive)", rsmd.getColumnCount()); + "The index must be within the number of columns (1 to %s, inclusive)", + rsmd.getColumnCount()); this.column = column; this.jdbcType = rsmd.getColumnType(column); @@ -128,8 +136,8 @@ public JdbcFieldInfo(ResultSetMetaData rsmd, int column) throws SQLException { } /** - * Builds a JdbcFieldInfo from the corresponding row from a {@link java.sql.DatabaseMetaData#getColumns} - * ResultSet. + * Builds a JdbcFieldInfo from the corresponding row from a {@link + * java.sql.DatabaseMetaData#getColumns} ResultSet. * * @param rs The {@link java.sql.ResultSet} to get the field information from. * @throws SQLException If the column information cannot be retrieved. @@ -144,51 +152,42 @@ public JdbcFieldInfo(ResultSet rs) throws SQLException { this.displaySize = rs.getInt("CHAR_OCTET_LENGTH"); } - /** - * The {@link java.sql.Types} type. - */ + /** The {@link java.sql.Types} type. */ public int getJdbcType() { return jdbcType; } - /** - * The nullability. - */ + /** The nullability. */ public int isNullable() { return nullability; } /** - * The numeric precision, for {@link java.sql.Types#NUMERIC} and {@link java.sql.Types#DECIMAL} types. + * The numeric precision, for {@link java.sql.Types#NUMERIC} and {@link java.sql.Types#DECIMAL} + * types. */ public int getPrecision() { return precision; } /** - * The numeric scale, for {@link java.sql.Types#NUMERIC} and {@link java.sql.Types#DECIMAL} types. + * The numeric scale, for {@link java.sql.Types#NUMERIC} and {@link java.sql.Types#DECIMAL} types. */ public int getScale() { return scale; } - /** - * The column index for query column. - */ + /** The column index for query column. */ public int getColumn() { return column; } - /** - * The type name as reported by the database. - */ + /** The type name as reported by the database. */ public String getTypeName() { return typeName; } - /** - * The max number of characters for the column. - */ + /** The max number of characters for the column. */ public int getDisplaySize() { return displaySize; } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinder.java index 2dfc0658cb8..05159d04c86 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinder.java @@ -21,7 +21,6 @@ import java.sql.SQLException; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.adapter.jdbc.binder.ColumnBinder; import org.apache.arrow.util.Preconditions; import org.apache.arrow.vector.VectorSchemaRoot; @@ -29,8 +28,8 @@ /** * A binder binds JDBC prepared statement parameters to rows of Arrow data from a VectorSchemaRoot. * - * Each row of the VectorSchemaRoot will be bound to the configured parameters of the PreparedStatement. - * One row of data is bound at a time. + *

Each row of the VectorSchemaRoot will be bound to the configured parameters of the + * PreparedStatement. One row of data is bound at a time. */ public class JdbcParameterBinder { private final PreparedStatement statement; @@ -44,8 +43,10 @@ public class JdbcParameterBinder { * * @param statement The statement to bind parameters to. * @param root The VectorSchemaRoot to pull data from. - * @param binders Column binders to translate from Arrow data to JDBC parameters, one per parameter. - * @param parameterIndices For each binder in binders, the index of the parameter to bind to. + * @param binders Column binders to translate from Arrow data to JDBC parameters, one per + * parameter. + * @param parameterIndices For each binder in binders, the index of the parameter to bind + * to. */ private JdbcParameterBinder( final PreparedStatement statement, @@ -55,7 +56,8 @@ private JdbcParameterBinder( Preconditions.checkArgument( binders.length == parameterIndices.length, "Number of column binders (%s) must equal number of parameter indices (%s)", - binders.length, parameterIndices.length); + binders.length, + parameterIndices.length); this.statement = statement; this.root = root; this.binders = binders; @@ -66,9 +68,10 @@ private JdbcParameterBinder( /** * Initialize a binder with a builder. * - * @param statement The statement to bind to. The binder does not maintain ownership of the statement. - * @param root The {@link VectorSchemaRoot} to pull data from. The binder does not maintain ownership - * of the vector schema root. + * @param statement The statement to bind to. The binder does not maintain ownership of the + * statement. + * @param root The {@link VectorSchemaRoot} to pull data from. The binder does not maintain + * ownership of the vector schema root. */ public static Builder builder(final PreparedStatement statement, final VectorSchemaRoot root) { return new Builder(statement, root); @@ -82,8 +85,8 @@ public void reset() { /** * Bind the next row of data to the parameters of the statement. * - * After this, the application should call the desired method on the prepared statement, - * such as {@link PreparedStatement#executeUpdate()}, or {@link PreparedStatement#addBatch()}. + *

After this, the application should call the desired method on the prepared statement, such + * as {@link PreparedStatement#executeUpdate()}, or {@link PreparedStatement#addBatch()}. * * @return true if a row was bound, false if rows were exhausted */ @@ -99,9 +102,7 @@ public boolean next() throws SQLException { return true; } - /** - * A builder for a {@link JdbcParameterBinder}. - */ + /** A builder for a {@link JdbcParameterBinder}. */ public static class Builder { private final PreparedStatement statement; private final VectorSchemaRoot root; @@ -116,16 +117,14 @@ public static class Builder { /** Bind each column to the corresponding parameter in order. */ public Builder bindAll() { for (int i = 0; i < root.getFieldVectors().size(); i++) { - bind(/*parameterIndex=*/ i + 1, /*columnIndex=*/ i); + bind(/* parameterIndex= */ i + 1, /* columnIndex= */ i); } return this; } /** Bind the given parameter to the given column using the default binder. */ public Builder bind(int parameterIndex, int columnIndex) { - return bind( - parameterIndex, - ColumnBinder.forVector(root.getVector(columnIndex))); + return bind(parameterIndex, ColumnBinder.forVector(root.getVector(columnIndex))); } /** Bind the given parameter using the given binder. */ diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java index 246451b5b22..89ebd420abc 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.Preconditions; @@ -29,44 +28,32 @@ * *

This utility uses following data mapping to map JDBC/SQL datatype to Arrow data types. * - *

CHAR --> ArrowType.Utf8 - * NCHAR --> ArrowType.Utf8 - * VARCHAR --> ArrowType.Utf8 - * NVARCHAR --> ArrowType.Utf8 - * LONGVARCHAR --> ArrowType.Utf8 - * LONGNVARCHAR --> ArrowType.Utf8 - * NUMERIC --> ArrowType.Decimal(precision, scale) - * DECIMAL --> ArrowType.Decimal(precision, scale) - * BIT --> ArrowType.Bool - * TINYINT --> ArrowType.Int(8, signed) - * SMALLINT --> ArrowType.Int(16, signed) - * INTEGER --> ArrowType.Int(32, signed) - * BIGINT --> ArrowType.Int(64, signed) - * REAL --> ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE) - * FLOAT --> ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE) - * DOUBLE --> ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE) - * BINARY --> ArrowType.Binary - * VARBINARY --> ArrowType.Binary - * LONGVARBINARY --> ArrowType.Binary - * DATE --> ArrowType.Date(DateUnit.MILLISECOND) - * TIME --> ArrowType.Time(TimeUnit.MILLISECOND, 32) - * TIMESTAMP --> ArrowType.Timestamp(TimeUnit.MILLISECOND, timezone=null) - * CLOB --> ArrowType.Utf8 - * BLOB --> ArrowType.Binary + *

CHAR --> ArrowType.Utf8 NCHAR --> ArrowType.Utf8 VARCHAR --> ArrowType.Utf8 NVARCHAR --> + * ArrowType.Utf8 LONGVARCHAR --> ArrowType.Utf8 LONGNVARCHAR --> ArrowType.Utf8 NUMERIC --> + * ArrowType.Decimal(precision, scale) DECIMAL --> ArrowType.Decimal(precision, scale) BIT --> + * ArrowType.Bool TINYINT --> ArrowType.Int(8, signed) SMALLINT --> ArrowType.Int(16, signed) + * INTEGER --> ArrowType.Int(32, signed) BIGINT --> ArrowType.Int(64, signed) REAL --> + * ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE) FLOAT --> + * ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE) DOUBLE --> + * ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE) BINARY --> ArrowType.Binary VARBINARY --> + * ArrowType.Binary LONGVARBINARY --> ArrowType.Binary DATE --> ArrowType.Date(DateUnit.MILLISECOND) + * TIME --> ArrowType.Time(TimeUnit.MILLISECOND, 32) TIMESTAMP --> + * ArrowType.Timestamp(TimeUnit.MILLISECOND, timezone=null) CLOB --> ArrowType.Utf8 BLOB --> + * ArrowType.Binary * * @since 0.10.0 */ public class JdbcToArrow { /*----------------------------------------------------------------* - | | - | Partial Convert API | - | | + | | + | Partial Convert API | + | | *----------------------------------------------------------------*/ /** - * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects. - * Note here uses the default targetBatchSize = 1024. + * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow + * objects. Note here uses the default targetBatchSize = 1024. * * @param resultSet ResultSet to use to fetch the data from underlying database * @param allocator Memory allocator @@ -74,28 +61,25 @@ public class JdbcToArrow { * @throws SQLException on error */ public static ArrowVectorIterator sqlToArrowVectorIterator( - ResultSet resultSet, - BufferAllocator allocator) - throws SQLException, IOException { + ResultSet resultSet, BufferAllocator allocator) throws SQLException, IOException { Preconditions.checkNotNull(allocator, "Memory Allocator object cannot be null"); - JdbcToArrowConfig config = - new JdbcToArrowConfig(allocator, JdbcToArrowUtils.getUtcCalendar()); + JdbcToArrowConfig config = new JdbcToArrowConfig(allocator, JdbcToArrowUtils.getUtcCalendar()); return sqlToArrowVectorIterator(resultSet, config); } /** - * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects. - * Note if not specify {@link JdbcToArrowConfig#targetBatchSize}, will use default value 1024. + * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow + * objects. Note if not specify {@link JdbcToArrowConfig#targetBatchSize}, will use default value + * 1024. + * * @param resultSet ResultSet to use to fetch the data from underlying database - * @param config Configuration of the conversion from JDBC to Arrow. + * @param config Configuration of the conversion from JDBC to Arrow. * @return Arrow Data Objects {@link ArrowVectorIterator} * @throws SQLException on error */ public static ArrowVectorIterator sqlToArrowVectorIterator( - ResultSet resultSet, - JdbcToArrowConfig config) - throws SQLException, IOException { + ResultSet resultSet, JdbcToArrowConfig config) throws SQLException, IOException { Preconditions.checkNotNull(resultSet, "JDBC ResultSet object cannot be null"); Preconditions.checkNotNull(config, "The configuration cannot be null"); return ArrowVectorIterator.create(resultSet, config); diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java index 68851f4a98b..6470dc58a6f 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java @@ -21,7 +21,6 @@ import java.util.Calendar; import java.util.Map; import java.util.function.Function; - import org.apache.arrow.adapter.jdbc.consumer.JdbcConsumer; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.Preconditions; @@ -30,25 +29,23 @@ /** * This class configures the JDBC-to-Arrow conversion process. - *

- * The allocator is used to construct the {@link org.apache.arrow.vector.VectorSchemaRoot}, - * and the calendar is used to define the time zone of any - * {@link org.apache.arrow.vector.types.pojo.ArrowType.Timestamp} - * fields that are created during the conversion. Neither field may be null. - *

- *

- * If the includeMetadata flag is set, the Arrow field metadata will contain information - * from the corresponding {@link java.sql.ResultSetMetaData} that was used to create the - * {@link org.apache.arrow.vector.types.pojo.FieldType} of the corresponding - * {@link org.apache.arrow.vector.FieldVector}. - *

- *

- * If there are any {@link java.sql.Types#ARRAY} fields in the {@link java.sql.ResultSet}, the corresponding - * {@link JdbcFieldInfo} for the array's contents must be defined here. Unfortunately, the sub-type - * information cannot be retrieved from all JDBC implementations (H2 for example, returns - * {@link java.sql.Types#NULL} for the array sub-type), so it must be configured here. The column index - * or name can be used to map to a {@link JdbcFieldInfo}, and that will be used for the conversion. - *

+ * + *

The allocator is used to construct the {@link org.apache.arrow.vector.VectorSchemaRoot}, and + * the calendar is used to define the time zone of any {@link + * org.apache.arrow.vector.types.pojo.ArrowType.Timestamp} fields that are created during the + * conversion. Neither field may be null. + * + *

If the includeMetadata flag is set, the Arrow field metadata will contain + * information from the corresponding {@link java.sql.ResultSetMetaData} that was used to create the + * {@link org.apache.arrow.vector.types.pojo.FieldType} of the corresponding {@link + * org.apache.arrow.vector.FieldVector}. + * + *

If there are any {@link java.sql.Types#ARRAY} fields in the {@link java.sql.ResultSet}, the + * corresponding {@link JdbcFieldInfo} for the array's contents must be defined here. Unfortunately, + * the sub-type information cannot be retrieved from all JDBC implementations (H2 for example, + * returns {@link java.sql.Types#NULL} for the array sub-type), so it must be configured here. The + * column index or name can be used to map to a {@link JdbcFieldInfo}, and that will be used for the + * conversion. */ public final class JdbcToArrowConfig { @@ -65,15 +62,14 @@ public final class JdbcToArrowConfig { private final Map schemaMetadata; private final Map> columnMetadataByColumnIndex; private final RoundingMode bigDecimalRoundingMode; + /** - * The maximum rowCount to read each time when partially convert data. - * Default value is 1024 and -1 means disable partial read. - * default is -1 which means disable partial read. - * Note that this flag only useful for {@link JdbcToArrow#sqlToArrowVectorIterator} - * 1) if targetBatchSize != -1, it will convert full data into multiple vectors - * with valueCount no more than targetBatchSize. - * 2) if targetBatchSize == -1, it will convert full data into a single vector in {@link ArrowVectorIterator} - *

+ * The maximum rowCount to read each time when partially convert data. Default value is 1024 and + * -1 means disable partial read. default is -1 which means disable partial read. Note that this + * flag only useful for {@link JdbcToArrow#sqlToArrowVectorIterator} 1) if targetBatchSize != -1, + * it will convert full data into multiple vectors with valueCount no more than targetBatchSize. + * 2) if targetBatchSize == -1, it will convert full data into a single vector in {@link + * ArrowVectorIterator} */ private final int targetBatchSize; @@ -81,81 +77,100 @@ public final class JdbcToArrowConfig { private final JdbcConsumerFactory jdbcConsumerGetter; /** - * Constructs a new configuration from the provided allocator and calendar. The allocator - * is used when constructing the Arrow vectors from the ResultSet, and the calendar is used to define - * Arrow Timestamp fields, and to read time-based fields from the JDBC ResultSet. + * Constructs a new configuration from the provided allocator and calendar. The allocator + * is used when constructing the Arrow vectors from the ResultSet, and the calendar is + * used to define Arrow Timestamp fields, and to read time-based fields from the JDBC + * ResultSet. * - * @param allocator The memory allocator to construct the Arrow vectors with. - * @param calendar The calendar to use when constructing Timestamp fields and reading time-based results. + * @param allocator The memory allocator to construct the Arrow vectors with. + * @param calendar The calendar to use when constructing Timestamp fields and reading time-based + * results. */ JdbcToArrowConfig(BufferAllocator allocator, Calendar calendar) { - this(allocator, calendar, + this( + allocator, + calendar, /* include metadata */ false, /* reuse vector schema root */ false, /* array sub-types by column index */ null, /* array sub-types by column name */ null, - DEFAULT_TARGET_BATCH_SIZE, null, null); + DEFAULT_TARGET_BATCH_SIZE, + null, + null); } JdbcToArrowConfig( - BufferAllocator allocator, - Calendar calendar, - boolean includeMetadata, - boolean reuseVectorSchemaRoot, - Map arraySubTypesByColumnIndex, - Map arraySubTypesByColumnName, - int targetBatchSize, - Function jdbcToArrowTypeConverter) { - this(allocator, calendar, includeMetadata, reuseVectorSchemaRoot, arraySubTypesByColumnIndex, - arraySubTypesByColumnName, targetBatchSize, jdbcToArrowTypeConverter, null); + BufferAllocator allocator, + Calendar calendar, + boolean includeMetadata, + boolean reuseVectorSchemaRoot, + Map arraySubTypesByColumnIndex, + Map arraySubTypesByColumnName, + int targetBatchSize, + Function jdbcToArrowTypeConverter) { + this( + allocator, + calendar, + includeMetadata, + reuseVectorSchemaRoot, + arraySubTypesByColumnIndex, + arraySubTypesByColumnName, + targetBatchSize, + jdbcToArrowTypeConverter, + null); } /** - * Constructs a new configuration from the provided allocator and calendar. The allocator - * is used when constructing the Arrow vectors from the ResultSet, and the calendar is used to define - * Arrow Timestamp fields, and to read time-based fields from the JDBC ResultSet. + * Constructs a new configuration from the provided allocator and calendar. The allocator + * is used when constructing the Arrow vectors from the ResultSet, and the calendar is + * used to define Arrow Timestamp fields, and to read time-based fields from the JDBC + * ResultSet. * - * @param allocator The memory allocator to construct the Arrow vectors with. - * @param calendar The calendar to use when constructing Timestamp fields and reading time-based results. - * @param includeMetadata Whether to include JDBC field metadata in the Arrow Schema Field metadata. + * @param allocator The memory allocator to construct the Arrow vectors with. + * @param calendar The calendar to use when constructing Timestamp fields and reading time-based + * results. + * @param includeMetadata Whether to include JDBC field metadata in the Arrow Schema Field + * metadata. * @param reuseVectorSchemaRoot Whether to reuse the vector schema root for each data load. * @param arraySubTypesByColumnIndex The type of the JDBC array at the column index (1-based). - * @param arraySubTypesByColumnName The type of the JDBC array at the column name. - * @param targetBatchSize The target batch size to be used in preallocation of the resulting vectors. - * @param jdbcToArrowTypeConverter The function that maps JDBC field type information to arrow type. If set to null, - * the default mapping will be used, which is defined as: - *
    - *
  • CHAR --> ArrowType.Utf8
  • - *
  • NCHAR --> ArrowType.Utf8
  • - *
  • VARCHAR --> ArrowType.Utf8
  • - *
  • NVARCHAR --> ArrowType.Utf8
  • - *
  • LONGVARCHAR --> ArrowType.Utf8
  • - *
  • LONGNVARCHAR --> ArrowType.Utf8
  • - *
  • NUMERIC --> ArrowType.Decimal(precision, scale)
  • - *
  • DECIMAL --> ArrowType.Decimal(precision, scale)
  • - *
  • BIT --> ArrowType.Bool
  • - *
  • TINYINT --> ArrowType.Int(8, signed)
  • - *
  • SMALLINT --> ArrowType.Int(16, signed)
  • - *
  • INTEGER --> ArrowType.Int(32, signed)
  • - *
  • BIGINT --> ArrowType.Int(64, signed)
  • - *
  • REAL --> ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)
  • - *
  • FLOAT --> ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)
  • - *
  • DOUBLE --> ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)
  • - *
  • BINARY --> ArrowType.Binary
  • - *
  • VARBINARY --> ArrowType.Binary
  • - *
  • LONGVARBINARY --> ArrowType.Binary
  • - *
  • DATE --> ArrowType.Date(DateUnit.DAY)
  • - *
  • TIME --> ArrowType.Time(TimeUnit.MILLISECOND, 32)
  • - *
  • TIMESTAMP --> ArrowType.Timestamp(TimeUnit.MILLISECOND, calendar timezone)
  • - *
  • CLOB --> ArrowType.Utf8
  • - *
  • BLOB --> ArrowType.Binary
  • - *
  • ARRAY --> ArrowType.List
  • - *
  • STRUCT --> ArrowType.Struct
  • - *
  • NULL --> ArrowType.Null
  • - *
- * @param bigDecimalRoundingMode The java.math.RoundingMode to be used in coercion of a BigDecimal from a - * ResultSet having a scale which does not match that of the target vector. Use null - * (default value) to require strict scale matching. + * @param arraySubTypesByColumnName The type of the JDBC array at the column name. + * @param targetBatchSize The target batch size to be used in preallocation of the resulting + * vectors. + * @param jdbcToArrowTypeConverter The function that maps JDBC field type information to arrow + * type. If set to null, the default mapping will be used, which is defined as: + *
    + *
  • CHAR --> ArrowType.Utf8 + *
  • NCHAR --> ArrowType.Utf8 + *
  • VARCHAR --> ArrowType.Utf8 + *
  • NVARCHAR --> ArrowType.Utf8 + *
  • LONGVARCHAR --> ArrowType.Utf8 + *
  • LONGNVARCHAR --> ArrowType.Utf8 + *
  • NUMERIC --> ArrowType.Decimal(precision, scale) + *
  • DECIMAL --> ArrowType.Decimal(precision, scale) + *
  • BIT --> ArrowType.Bool + *
  • TINYINT --> ArrowType.Int(8, signed) + *
  • SMALLINT --> ArrowType.Int(16, signed) + *
  • INTEGER --> ArrowType.Int(32, signed) + *
  • BIGINT --> ArrowType.Int(64, signed) + *
  • REAL --> ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE) + *
  • FLOAT --> ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE) + *
  • DOUBLE --> ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE) + *
  • BINARY --> ArrowType.Binary + *
  • VARBINARY --> ArrowType.Binary + *
  • LONGVARBINARY --> ArrowType.Binary + *
  • DATE --> ArrowType.Date(DateUnit.DAY) + *
  • TIME --> ArrowType.Time(TimeUnit.MILLISECOND, 32) + *
  • TIMESTAMP --> ArrowType.Timestamp(TimeUnit.MILLISECOND, calendar timezone) + *
  • CLOB --> ArrowType.Utf8 + *
  • BLOB --> ArrowType.Binary + *
  • ARRAY --> ArrowType.List + *
  • STRUCT --> ArrowType.Struct + *
  • NULL --> ArrowType.Null + *
+ * + * @param bigDecimalRoundingMode The java.math.RoundingMode to be used in coercion of a BigDecimal + * from a ResultSet having a scale which does not match that of the target vector. Use null + * (default value) to require strict scale matching. */ JdbcToArrowConfig( BufferAllocator allocator, @@ -245,16 +260,19 @@ public final class JdbcToArrowConfig { this.bigDecimalRoundingMode = bigDecimalRoundingMode; // set up type converter - this.jdbcToArrowTypeConverter = jdbcToArrowTypeConverter != null ? jdbcToArrowTypeConverter : - (jdbcFieldInfo) -> JdbcToArrowUtils.getArrowTypeFromJdbcType(jdbcFieldInfo, calendar); + this.jdbcToArrowTypeConverter = + jdbcToArrowTypeConverter != null + ? jdbcToArrowTypeConverter + : (jdbcFieldInfo) -> JdbcToArrowUtils.getArrowTypeFromJdbcType(jdbcFieldInfo, calendar); - this.jdbcConsumerGetter = jdbcConsumerGetter != null ? jdbcConsumerGetter : JdbcToArrowUtils::getConsumer; + this.jdbcConsumerGetter = + jdbcConsumerGetter != null ? jdbcConsumerGetter : JdbcToArrowUtils::getConsumer; } /** - * The calendar to use when defining Arrow Timestamp fields - * and retrieving {@link java.sql.Date}, {@link java.sql.Time}, or {@link java.sql.Timestamp} - * data types from the {@link java.sql.ResultSet}, or null if not converting. + * The calendar to use when defining Arrow Timestamp fields and retrieving {@link java.sql.Date}, + * {@link java.sql.Time}, or {@link java.sql.Timestamp} data types from the {@link + * java.sql.ResultSet}, or null if not converting. * * @return the calendar. */ @@ -280,30 +298,22 @@ public boolean shouldIncludeMetadata() { return includeMetadata; } - /** - * Get the target batch size for partial read. - */ + /** Get the target batch size for partial read. */ public int getTargetBatchSize() { return targetBatchSize; } - /** - * Get whether it is allowed to reuse the vector schema root. - */ + /** Get whether it is allowed to reuse the vector schema root. */ public boolean isReuseVectorSchemaRoot() { return reuseVectorSchemaRoot; } - /** - * Gets the mapping between JDBC type information to Arrow type. - */ + /** Gets the mapping between JDBC type information to Arrow type. */ public Function getJdbcToArrowTypeConverter() { return jdbcToArrowTypeConverter; } - /** - * Gets the JDBC consumer getter. - */ + /** Gets the JDBC consumer getter. */ public JdbcConsumerFactory getJdbcConsumerGetter() { return jdbcConsumerGetter; } @@ -311,8 +321,10 @@ public JdbcConsumerFactory getJdbcConsumerGetter() { /** * Returns the array sub-type {@link JdbcFieldInfo} defined for the provided column index. * - * @param index The {@link java.sql.ResultSetMetaData} column index of an {@link java.sql.Types#ARRAY} type. - * @return The {@link JdbcFieldInfo} for that array's sub-type, or null if not defined. + * @param index The {@link java.sql.ResultSetMetaData} column index of an {@link + * java.sql.Types#ARRAY} type. + * @return The {@link JdbcFieldInfo} for that array's sub-type, or null if not + * defined. */ public JdbcFieldInfo getArraySubTypeByColumnIndex(int index) { if (arraySubTypesByColumnIndex == null) { @@ -325,8 +337,10 @@ public JdbcFieldInfo getArraySubTypeByColumnIndex(int index) { /** * Returns the array sub-type {@link JdbcFieldInfo} defined for the provided column name. * - * @param name The {@link java.sql.ResultSetMetaData} column name of an {@link java.sql.Types#ARRAY} type. - * @return The {@link JdbcFieldInfo} for that array's sub-type, or null if not defined. + * @param name The {@link java.sql.ResultSetMetaData} column name of an {@link + * java.sql.Types#ARRAY} type. + * @return The {@link JdbcFieldInfo} for that array's sub-type, or null if not + * defined. */ public JdbcFieldInfo getArraySubTypeByColumnName(String name) { if (arraySubTypesByColumnName == null) { @@ -339,7 +353,8 @@ public JdbcFieldInfo getArraySubTypeByColumnName(String name) { /** * Returns the type {@link JdbcFieldInfo} explicitly defined for the provided column index. * - * @param index The {@link java.sql.ResultSetMetaData} column index to evaluate for explicit type mapping. + * @param index The {@link java.sql.ResultSetMetaData} column index to evaluate for explicit type + * mapping. * @return The {@link JdbcFieldInfo} defined for the column, or null if not defined. */ public JdbcFieldInfo getExplicitTypeByColumnIndex(int index) { @@ -353,7 +368,8 @@ public JdbcFieldInfo getExplicitTypeByColumnIndex(int index) { /** * Returns the type {@link JdbcFieldInfo} explicitly defined for the provided column name. * - * @param name The {@link java.sql.ResultSetMetaData} column name to evaluate for explicit type mapping. + * @param name The {@link java.sql.ResultSetMetaData} column name to evaluate for explicit type + * mapping. * @return The {@link JdbcFieldInfo} defined for the column, or null if not defined. */ public JdbcFieldInfo getExplicitTypeByColumnName(String name) { @@ -364,17 +380,12 @@ public JdbcFieldInfo getExplicitTypeByColumnName(String name) { } } - /** - * Return schema level metadata or null if not provided. - */ + /** Return schema level metadata or null if not provided. */ public Map getSchemaMetadata() { return schemaMetadata; } - /** - * Return metadata from columnIndex->meta map on per field basis - * or null if not provided. - */ + /** Return metadata from columnIndex->meta map on per field basis or null if not provided. */ public Map> getColumnMetadataByColumnIndex() { return columnMetadataByColumnIndex; } @@ -383,12 +394,14 @@ public RoundingMode getBigDecimalRoundingMode() { return bigDecimalRoundingMode; } - /** - * Interface for a function that gets a JDBC consumer for the given values. - */ + /** Interface for a function that gets a JDBC consumer for the given values. */ @FunctionalInterface public interface JdbcConsumerFactory { - JdbcConsumer apply(ArrowType arrowType, int columnIndex, boolean nullable, FieldVector vector, - JdbcToArrowConfig config); + JdbcConsumer apply( + ArrowType arrowType, + int columnIndex, + boolean nullable, + FieldVector vector, + JdbcToArrowConfig config); } } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigBuilder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigBuilder.java index 7d88c238320..cef26b27b7a 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigBuilder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigBuilder.java @@ -23,15 +23,12 @@ import java.util.Calendar; import java.util.Map; import java.util.function.Function; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.Preconditions; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.types.pojo.ArrowType; -/** - * This class builds {@link JdbcToArrowConfig}s. - */ +/** This class builds {@link JdbcToArrowConfig}s. */ public class JdbcToArrowConfigBuilder { private Calendar calendar; private BufferAllocator allocator; @@ -49,9 +46,9 @@ public class JdbcToArrowConfigBuilder { private RoundingMode bigDecimalRoundingMode; /** - * Default constructor for the JdbcToArrowConfigBuilder}. - * Use the setter methods for the allocator and calendar; the allocator must be - * set. Otherwise, {@link #build()} will throw a {@link NullPointerException}. + * Default constructor for the JdbcToArrowConfigBuilder}. Use the setter methods for + * the allocator and calendar; the allocator must be set. Otherwise, {@link #build()} will throw a + * {@link NullPointerException}. */ public JdbcToArrowConfigBuilder() { this.allocator = null; @@ -68,16 +65,13 @@ public JdbcToArrowConfigBuilder() { } /** - * Constructor for the JdbcToArrowConfigBuilder. The - * allocator is required, and a {@link NullPointerException} - * will be thrown if it is null. - *

- * The allocator is used to construct Arrow vectors from the JDBC ResultSet. - * The calendar is used to determine the time zone of {@link java.sql.Timestamp} - * fields and convert {@link java.sql.Date}, {@link java.sql.Time}, and - * {@link java.sql.Timestamp} fields to a single, common time zone when reading - * from the result set. - *

+ * Constructor for the JdbcToArrowConfigBuilder. The allocator is required, and a + * {@link NullPointerException} will be thrown if it is null. + * + *

The allocator is used to construct Arrow vectors from the JDBC ResultSet. The calendar is + * used to determine the time zone of {@link java.sql.Timestamp} fields and convert {@link + * java.sql.Date}, {@link java.sql.Time}, and {@link java.sql.Timestamp} fields to a single, + * common time zone when reading from the result set. * * @param allocator The Arrow Vector memory allocator. * @param calendar The calendar to use when constructing timestamp fields. @@ -95,26 +89,23 @@ public JdbcToArrowConfigBuilder(BufferAllocator allocator, Calendar calendar) { } /** - * Constructor for the JdbcToArrowConfigBuilder. Both the - * allocator and calendar are required. A {@link NullPointerException} - * will be thrown if either of those arguments is null. - *

- * The allocator is used to construct Arrow vectors from the JDBC ResultSet. - * The calendar is used to determine the time zone of {@link java.sql.Timestamp} - * fields and convert {@link java.sql.Date}, {@link java.sql.Time}, and - * {@link java.sql.Timestamp} fields to a single, common time zone when reading - * from the result set. - *

- *

- * The includeMetadata argument, if true will cause - * various information about each database field to be added to the Vector - * Schema's field metadata. - *

+ * Constructor for the JdbcToArrowConfigBuilder. Both the allocator and calendar are + * required. A {@link NullPointerException} will be thrown if either of those arguments is + * null. + * + *

The allocator is used to construct Arrow vectors from the JDBC ResultSet. The calendar is + * used to determine the time zone of {@link java.sql.Timestamp} fields and convert {@link + * java.sql.Date}, {@link java.sql.Time}, and {@link java.sql.Timestamp} fields to a single, + * common time zone when reading from the result set. + * + *

The includeMetadata argument, if true will cause various + * information about each database field to be added to the Vector Schema's field metadata. * * @param allocator The Arrow Vector memory allocator. * @param calendar The calendar to use when constructing timestamp fields. */ - public JdbcToArrowConfigBuilder(BufferAllocator allocator, Calendar calendar, boolean includeMetadata) { + public JdbcToArrowConfigBuilder( + BufferAllocator allocator, Calendar calendar, boolean includeMetadata) { this(allocator, calendar); this.includeMetadata = includeMetadata; } @@ -132,8 +123,8 @@ public JdbcToArrowConfigBuilder setAllocator(BufferAllocator allocator) { } /** - * Sets the {@link Calendar} to use when constructing timestamp fields in the - * Arrow schema, and reading time-based fields from the JDBC ResultSet. + * Sets the {@link Calendar} to use when constructing timestamp fields in the Arrow schema, and + * reading time-based fields from the JDBC ResultSet. * * @param calendar the calendar to set. */ @@ -145,7 +136,8 @@ public JdbcToArrowConfigBuilder setCalendar(Calendar calendar) { /** * Sets whether to include JDBC ResultSet field metadata in the Arrow Schema field metadata. * - * @param includeMetadata Whether to include or exclude JDBC metadata in the Arrow Schema field metadata. + * @param includeMetadata Whether to include or exclude JDBC metadata in the Arrow Schema field + * metadata. * @return This instance of the JdbcToArrowConfig, for chaining. */ public JdbcToArrowConfigBuilder setIncludeMetadata(boolean includeMetadata) { @@ -154,8 +146,8 @@ public JdbcToArrowConfigBuilder setIncludeMetadata(boolean includeMetadata) { } /** - * Sets the mapping of column-index-to-{@link JdbcFieldInfo} used for columns of type {@link java.sql.Types#ARRAY}. - * The column index is 1-based, to match the JDBC column index. + * Sets the mapping of column-index-to-{@link JdbcFieldInfo} used for columns of type {@link + * java.sql.Types#ARRAY}. The column index is 1-based, to match the JDBC column index. * * @param map The mapping. * @return This instance of the JdbcToArrowConfig, for chaining. @@ -166,7 +158,8 @@ public JdbcToArrowConfigBuilder setArraySubTypeByColumnIndexMap(MapJdbcToArrowConfig, for chaining. @@ -178,11 +171,12 @@ public JdbcToArrowConfigBuilder setArraySubTypeByColumnNameMap(Map - * This can be useful to override type information from JDBC drivers that provide incomplete type info, - * e.g. DECIMAL with precision = scale = 0. - *

- * The column index is 1-based, to match the JDBC column index. + * + *

This can be useful to override type information from JDBC drivers that provide incomplete + * type info, e.g. DECIMAL with precision = scale = 0. + * + *

The column index is 1-based, to match the JDBC column index. + * * @param map The mapping. */ public JdbcToArrowConfigBuilder setExplicitTypesByColumnIndex(Map map) { @@ -192,9 +186,10 @@ public JdbcToArrowConfigBuilder setExplicitTypesByColumnIndex(Map - * This can be useful to override type information from JDBC drivers that provide incomplete type info, - * e.g. DECIMAL with precision = scale = 0. + * + *

This can be useful to override type information from JDBC drivers that provide incomplete + * type info, e.g. DECIMAL with precision = scale = 0. + * * @param map The mapping. */ public JdbcToArrowConfigBuilder setExplicitTypesByColumnName(Map map) { @@ -204,8 +199,8 @@ public JdbcToArrowConfigBuilder setExplicitTypesByColumnName(Map - * Use {@link JdbcToArrowConfig#NO_LIMIT_BATCH_SIZE} to read all rows at once. + * + *

Use {@link JdbcToArrowConfig#NO_LIMIT_BATCH_SIZE} to read all rows at once. */ public JdbcToArrowConfigBuilder setTargetBatchSize(int targetBatchSize) { this.targetBatchSize = targetBatchSize; @@ -214,8 +209,9 @@ public JdbcToArrowConfigBuilder setTargetBatchSize(int targetBatchSize) { /** * Set the function used to convert JDBC types to Arrow types. - *

- * Defaults to wrapping {@link JdbcToArrowUtils#getArrowTypeFromJdbcType(JdbcFieldInfo, Calendar)}. + * + *

Defaults to wrapping {@link JdbcToArrowUtils#getArrowTypeFromJdbcType(JdbcFieldInfo, + * Calendar)}. */ public JdbcToArrowConfigBuilder setJdbcToArrowTypeConverter( Function jdbcToArrowTypeConverter) { @@ -225,9 +221,9 @@ public JdbcToArrowConfigBuilder setJdbcToArrowTypeConverter( /** * Set the function used to get a JDBC consumer for a given type. - *

- * Defaults to wrapping {@link - * JdbcToArrowUtils#getConsumer(ArrowType, Integer, Boolean, FieldVector, JdbcToArrowConfig)}. + * + *

Defaults to wrapping {@link JdbcToArrowUtils#getConsumer(ArrowType, Integer, Boolean, + * FieldVector, JdbcToArrowConfig)}. */ public JdbcToArrowConfigBuilder setJdbcConsumerGetter( JdbcToArrowConfig.JdbcConsumerFactory jdbcConsumerGetter) { @@ -236,35 +232,32 @@ public JdbcToArrowConfigBuilder setJdbcConsumerGetter( } /** - * Set whether to use the same {@link org.apache.arrow.vector.VectorSchemaRoot} instance on each iteration, - * or to allocate a new one. + * Set whether to use the same {@link org.apache.arrow.vector.VectorSchemaRoot} instance on each + * iteration, or to allocate a new one. */ public JdbcToArrowConfigBuilder setReuseVectorSchemaRoot(boolean reuseVectorSchemaRoot) { this.reuseVectorSchemaRoot = reuseVectorSchemaRoot; return this; } - /** - * Set metadata for schema. - */ + /** Set metadata for schema. */ public JdbcToArrowConfigBuilder setSchemaMetadata(Map schemaMetadata) { this.schemaMetadata = schemaMetadata; return this; } - /** - * Set metadata from columnIndex->meta map on per field basis. - */ + /** Set metadata from columnIndex->meta map on per field basis. */ public JdbcToArrowConfigBuilder setColumnMetadataByColumnIndex( - Map> columnMetadataByColumnIndex) { + Map> columnMetadataByColumnIndex) { this.columnMetadataByColumnIndex = columnMetadataByColumnIndex; return this; } /** - * Set the rounding mode used when the scale of the actual value does not match the declared scale. - *

- * By default, an error is raised in such cases. + * Set the rounding mode used when the scale of the actual value does not match the declared + * scale. + * + *

By default, an error is raised in such cases. */ public JdbcToArrowConfigBuilder setBigDecimalRoundingMode(RoundingMode bigDecimalRoundingMode) { this.bigDecimalRoundingMode = bigDecimalRoundingMode; @@ -272,8 +265,8 @@ public JdbcToArrowConfigBuilder setBigDecimalRoundingMode(RoundingMode bigDecima } /** - * This builds the {@link JdbcToArrowConfig} from the provided - * {@link BufferAllocator} and {@link Calendar}. + * This builds the {@link JdbcToArrowConfig} from the provided {@link BufferAllocator} and {@link + * Calendar}. * * @return The built {@link JdbcToArrowConfig} * @throws NullPointerException if either the allocator or calendar was not set. diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java index eaee4993607..959083136a7 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java @@ -38,7 +38,6 @@ import java.util.Locale; import java.util.Map; import java.util.TimeZone; - import org.apache.arrow.adapter.jdbc.consumer.ArrayConsumer; import org.apache.arrow.adapter.jdbc.consumer.BigIntConsumer; import org.apache.arrow.adapter.jdbc.consumer.BinaryConsumer; @@ -91,7 +90,8 @@ import org.apache.arrow.vector.util.ValueVectorUtility; /** - * Class that does most of the work to convert JDBC ResultSet data into Arrow columnar format Vector objects. + * Class that does most of the work to convert JDBC ResultSet data into Arrow columnar format Vector + * objects. * * @since 0.10.0 */ @@ -99,9 +99,7 @@ public class JdbcToArrowUtils { private static final int JDBC_ARRAY_VALUE_COLUMN = 2; - /** - * Returns the instance of a {java.util.Calendar} with the UTC time zone and root locale. - */ + /** Returns the instance of a {java.util.Calendar} with the UTC time zone and root locale. */ public static Calendar getUtcCalendar() { return Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT); } @@ -114,7 +112,8 @@ public static Calendar getUtcCalendar() { * @return {@link Schema} * @throws SQLException on error */ - public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, Calendar calendar) throws SQLException { + public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, Calendar calendar) + throws SQLException { Preconditions.checkNotNull(calendar, "Calendar object can't be null"); return jdbcToArrowSchema(rsmd, new JdbcToArrowConfig(new RootAllocator(0), calendar)); @@ -123,25 +122,28 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, Calendar calendar /** * Create Arrow {@link Schema} object for the given JDBC {@link ResultSetMetaData}. * - * @param parameterMetaData The ResultSetMetaData containing the results, to read the JDBC metadata from. - * @param calendar The calendar to use the time zone field of, to construct Timestamp fields from. + * @param parameterMetaData The ResultSetMetaData containing the results, to read the JDBC + * metadata from. + * @param calendar The calendar to use the time zone field of, to construct Timestamp fields from. * @return {@link Schema} * @throws SQLException on error */ - public static Schema jdbcToArrowSchema(final ParameterMetaData parameterMetaData, final Calendar calendar) - throws SQLException { + public static Schema jdbcToArrowSchema( + final ParameterMetaData parameterMetaData, final Calendar calendar) throws SQLException { Preconditions.checkNotNull(calendar, "Calendar object can't be null"); Preconditions.checkNotNull(parameterMetaData); final List parameterFields = new ArrayList<>(parameterMetaData.getParameterCount()); - for (int parameterCounter = 1; parameterCounter <= parameterMetaData.getParameterCount(); - parameterCounter++) { + for (int parameterCounter = 1; + parameterCounter <= parameterMetaData.getParameterCount(); + parameterCounter++) { final int jdbcDataType = parameterMetaData.getParameterType(parameterCounter); final int jdbcIsNullable = parameterMetaData.isNullable(parameterCounter); final boolean arrowIsNullable = jdbcIsNullable != ParameterMetaData.parameterNoNulls; final int precision = parameterMetaData.getPrecision(parameterCounter); final int scale = parameterMetaData.getScale(parameterCounter); - final ArrowType arrowType = getArrowTypeFromJdbcType(new JdbcFieldInfo(jdbcDataType, precision, scale), calendar); - final FieldType fieldType = new FieldType(arrowIsNullable, arrowType, /*dictionary=*/null); + final ArrowType arrowType = + getArrowTypeFromJdbcType(new JdbcFieldInfo(jdbcDataType, precision, scale), calendar); + final FieldType fieldType = new FieldType(arrowIsNullable, arrowType, /* dictionary= */ null); parameterFields.add(new Field(null, fieldType, null)); } @@ -152,10 +154,11 @@ public static Schema jdbcToArrowSchema(final ParameterMetaData parameterMetaData * Converts the provided JDBC type to its respective {@link ArrowType} counterpart. * * @param fieldInfo the {@link JdbcFieldInfo} with information about the original JDBC type. - * @param calendar the {@link Calendar} to use for datetime data types. + * @param calendar the {@link Calendar} to use for datetime data types. * @return a new {@link ArrowType}. */ - public static ArrowType getArrowTypeFromJdbcType(final JdbcFieldInfo fieldInfo, final Calendar calendar) { + public static ArrowType getArrowTypeFromJdbcType( + final JdbcFieldInfo fieldInfo, final Calendar calendar) { switch (fieldInfo.getJdbcType()) { case Types.BOOLEAN: case Types.BIT: @@ -222,30 +225,34 @@ public static ArrowType getArrowTypeFromJdbcType(final JdbcFieldInfo fieldInfo, /** * Create Arrow {@link Schema} object for the given JDBC {@link java.sql.ResultSetMetaData}. * - *

- * If {@link JdbcToArrowConfig#shouldIncludeMetadata()} returns true, the following fields - * will be added to the {@link FieldType#getMetadata()}: + *

If {@link JdbcToArrowConfig#shouldIncludeMetadata()} returns true, the + * following fields will be added to the {@link FieldType#getMetadata()}: + * *

    - *
  • {@link Constants#SQL_CATALOG_NAME_KEY} representing {@link ResultSetMetaData#getCatalogName(int)}
  • - *
  • {@link Constants#SQL_TABLE_NAME_KEY} representing {@link ResultSetMetaData#getTableName(int)}
  • - *
  • {@link Constants#SQL_COLUMN_NAME_KEY} representing {@link ResultSetMetaData#getColumnLabel(int)}
  • - *
  • {@link Constants#SQL_TYPE_KEY} representing {@link ResultSetMetaData#getColumnTypeName(int)}
  • + *
  • {@link Constants#SQL_CATALOG_NAME_KEY} representing {@link + * ResultSetMetaData#getCatalogName(int)} + *
  • {@link Constants#SQL_TABLE_NAME_KEY} representing {@link + * ResultSetMetaData#getTableName(int)} + *
  • {@link Constants#SQL_COLUMN_NAME_KEY} representing {@link + * ResultSetMetaData#getColumnLabel(int)} + *
  • {@link Constants#SQL_TYPE_KEY} representing {@link + * ResultSetMetaData#getColumnTypeName(int)} *
- *

- *

- * If any columns are of type {@link java.sql.Types#ARRAY}, the configuration object will be used to look up - * the array sub-type field. The {@link JdbcToArrowConfig#getArraySubTypeByColumnIndex(int)} method will be - * checked first, followed by the {@link JdbcToArrowConfig#getArraySubTypeByColumnName(String)} method. - *

+ * + *

If any columns are of type {@link java.sql.Types#ARRAY}, the configuration object will be + * used to look up the array sub-type field. The {@link + * JdbcToArrowConfig#getArraySubTypeByColumnIndex(int)} method will be checked first, followed by + * the {@link JdbcToArrowConfig#getArraySubTypeByColumnName(String)} method. * * @param rsmd The ResultSetMetaData containing the results, to read the JDBC metadata from. * @param config The configuration to use when constructing the schema. * @return {@link Schema} * @throws SQLException on error - * @throws IllegalArgumentException if rsmd contains an {@link java.sql.Types#ARRAY} but the - * config does not have a sub-type definition for it. + * @throws IllegalArgumentException if rsmd contains an {@link java.sql.Types#ARRAY} + * but the config does not have a sub-type definition for it. */ - public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig config) throws SQLException { + public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig config) + throws SQLException { Preconditions.checkNotNull(rsmd, "JDBC ResultSetMetaData object can't be null"); Preconditions.checkNotNull(config, "The configuration object must not be null"); @@ -254,8 +261,10 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig for (int i = 1; i <= columnCount; i++) { final String columnName = rsmd.getColumnLabel(i); - final Map columnMetadata = config.getColumnMetadataByColumnIndex() != null ? - config.getColumnMetadataByColumnIndex().get(i) : null; + final Map columnMetadata = + config.getColumnMetadataByColumnIndex() != null + ? config.getColumnMetadataByColumnIndex().get(i) + : null; final Map metadata; if (config.shouldIncludeMetadata()) { metadata = new HashMap<>(); @@ -278,14 +287,19 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig final JdbcFieldInfo columnFieldInfo = getJdbcFieldInfoForColumn(rsmd, i, config); final ArrowType arrowType = config.getJdbcToArrowTypeConverter().apply(columnFieldInfo); if (arrowType != null) { - final FieldType fieldType = new FieldType( - isColumnNullable(rsmd, i, columnFieldInfo), arrowType, /* dictionary encoding */ null, metadata); + final FieldType fieldType = + new FieldType( + isColumnNullable(rsmd, i, columnFieldInfo), + arrowType, /* dictionary encoding */ + null, + metadata); List children = null; if (arrowType.getTypeID() == ArrowType.List.TYPE_TYPE) { final JdbcFieldInfo arrayFieldInfo = getJdbcFieldInfoForArraySubType(rsmd, i, config); if (arrayFieldInfo == null) { - throw new IllegalArgumentException("Configuration does not provide a mapping for array column " + i); + throw new IllegalArgumentException( + "Configuration does not provide a mapping for array column " + i); } children = new ArrayList(); final ArrowType childType = config.getJdbcToArrowTypeConverter().apply(arrayFieldInfo); @@ -295,9 +309,13 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig FieldType keyType = new FieldType(false, new ArrowType.Utf8(), null, null); FieldType valueType = new FieldType(false, new ArrowType.Utf8(), null, null); children = new ArrayList<>(); - children.add(new Field("child", mapType, - Arrays.asList(new Field(MapVector.KEY_NAME, keyType, null), - new Field(MapVector.VALUE_NAME, valueType, null)))); + children.add( + new Field( + "child", + mapType, + Arrays.asList( + new Field(MapVector.KEY_NAME, keyType, null), + new Field(MapVector.VALUE_NAME, valueType, null)))); } fields.add(new Field(columnName, fieldType, children)); @@ -307,18 +325,14 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig } static JdbcFieldInfo getJdbcFieldInfoForColumn( - ResultSetMetaData rsmd, - int arrayColumn, - JdbcToArrowConfig config) - throws SQLException { + ResultSetMetaData rsmd, int arrayColumn, JdbcToArrowConfig config) throws SQLException { Preconditions.checkNotNull(rsmd, "ResultSet MetaData object cannot be null"); Preconditions.checkNotNull(config, "Configuration must not be null"); Preconditions.checkArgument( - arrayColumn > 0, - "ResultSetMetaData columns start with 1; column cannot be less than 1"); + arrayColumn > 0, "ResultSetMetaData columns start with 1; column cannot be less than 1"); Preconditions.checkArgument( - arrayColumn <= rsmd.getColumnCount(), - "Column number cannot be more than the number of columns"); + arrayColumn <= rsmd.getColumnCount(), + "Column number cannot be more than the number of columns"); JdbcFieldInfo fieldInfo = config.getExplicitTypeByColumnIndex(arrayColumn); if (fieldInfo == null) { @@ -334,16 +348,12 @@ static JdbcFieldInfo getJdbcFieldInfoForColumn( * If no sub-type can be found, returns null. */ private static JdbcFieldInfo getJdbcFieldInfoForArraySubType( - ResultSetMetaData rsmd, - int arrayColumn, - JdbcToArrowConfig config) - throws SQLException { + ResultSetMetaData rsmd, int arrayColumn, JdbcToArrowConfig config) throws SQLException { Preconditions.checkNotNull(rsmd, "ResultSet MetaData object cannot be null"); Preconditions.checkNotNull(config, "Configuration must not be null"); Preconditions.checkArgument( - arrayColumn > 0, - "ResultSetMetaData columns start with 1; column cannot be less than 1"); + arrayColumn > 0, "ResultSetMetaData columns start with 1; column cannot be less than 1"); Preconditions.checkArgument( arrayColumn <= rsmd.getColumnCount(), "Column number cannot be more than the number of columns"); @@ -359,10 +369,10 @@ private static JdbcFieldInfo getJdbcFieldInfoForArraySubType( * Iterate the given JDBC {@link ResultSet} object to fetch the data and transpose it to populate * the given Arrow Vector objects. * - * @param rs ResultSet to use to fetch the data from underlying database - * @param root Arrow {@link VectorSchemaRoot} object to populate - * @param calendar The calendar to use when reading {@link Date}, {@link Time}, or {@link Timestamp} - * data types from the {@link ResultSet}, or null if not converting. + * @param rs ResultSet to use to fetch the data from underlying database + * @param root Arrow {@link VectorSchemaRoot} object to populate + * @param calendar The calendar to use when reading {@link Date}, {@link Time}, or {@link + * Timestamp} data types from the {@link ResultSet}, or null if not converting. * @throws SQLException on error */ public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, Calendar calendar) @@ -373,29 +383,30 @@ public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, Calen jdbcToArrowVectors(rs, root, new JdbcToArrowConfig(new RootAllocator(0), calendar)); } - static boolean isColumnNullable(ResultSetMetaData resultSetMetadata, int index, JdbcFieldInfo info) - throws SQLException { + static boolean isColumnNullable( + ResultSetMetaData resultSetMetadata, int index, JdbcFieldInfo info) throws SQLException { int nullableValue; if (info != null && info.isNullable() != ResultSetMetaData.columnNullableUnknown) { nullableValue = info.isNullable(); } else { nullableValue = resultSetMetadata.isNullable(index); } - return nullableValue == ResultSetMetaData.columnNullable || - nullableValue == ResultSetMetaData.columnNullableUnknown; + return nullableValue == ResultSetMetaData.columnNullable + || nullableValue == ResultSetMetaData.columnNullableUnknown; } /** * Iterate the given JDBC {@link ResultSet} object to fetch the data and transpose it to populate * the given Arrow Vector objects. * - * @param rs ResultSet to use to fetch the data from underlying database - * @param root Arrow {@link VectorSchemaRoot} object to populate + * @param rs ResultSet to use to fetch the data from underlying database + * @param root Arrow {@link VectorSchemaRoot} object to populate * @param config The configuration to use when reading the data. * @throws SQLException on error * @throws JdbcConsumerException on error from VectorConsumer */ - public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, JdbcToArrowConfig config) + public static void jdbcToArrowVectors( + ResultSet rs, VectorSchemaRoot root, JdbcToArrowConfig config) throws SQLException, IOException { ResultSetMetaData rsmd = rs.getMetaData(); @@ -405,8 +416,13 @@ public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, JdbcT for (int i = 1; i <= columnCount; i++) { FieldVector vector = root.getVector(rsmd.getColumnLabel(i)); final JdbcFieldInfo columnFieldInfo = getJdbcFieldInfoForColumn(rsmd, i, config); - consumers[i - 1] = getConsumer( - vector.getField().getType(), i, isColumnNullable(rsmd, i, columnFieldInfo), vector, config); + consumers[i - 1] = + getConsumer( + vector.getField().getType(), + i, + isColumnNullable(rsmd, i, columnFieldInfo), + vector, + config); } CompositeJdbcConsumer compositeConsumer = null; @@ -439,18 +455,22 @@ public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, JdbcT } /** - * Default function used for JdbcConsumerFactory. This function gets a JdbcConsumer for the - * given column based on the Arrow type and provided vector. + * Default function used for JdbcConsumerFactory. This function gets a JdbcConsumer for the given + * column based on the Arrow type and provided vector. * - * @param arrowType Arrow type for the column. + * @param arrowType Arrow type for the column. * @param columnIndex Column index to fetch from the ResultSet - * @param nullable Whether the value is nullable or not - * @param vector Vector to store the consumed value - * @param config Associated JdbcToArrowConfig, used mainly for the Calendar. + * @param nullable Whether the value is nullable or not + * @param vector Vector to store the consumed value + * @param config Associated JdbcToArrowConfig, used mainly for the Calendar. * @return {@link JdbcConsumer} */ - public static JdbcConsumer getConsumer(ArrowType arrowType, int columnIndex, boolean nullable, - FieldVector vector, JdbcToArrowConfig config) { + public static JdbcConsumer getConsumer( + ArrowType arrowType, + int columnIndex, + boolean nullable, + FieldVector vector, + JdbcToArrowConfig config) { final Calendar calendar = config.getCalendar(); switch (arrowType.getTypeID()) { @@ -472,10 +492,11 @@ public static JdbcConsumer getConsumer(ArrowType arrowType, int columnIndex, boo case Decimal: final RoundingMode bigDecimalRoundingMode = config.getBigDecimalRoundingMode(); if (((ArrowType.Decimal) arrowType).getBitWidth() == 256) { - return Decimal256Consumer.createConsumer((Decimal256Vector) vector, columnIndex, nullable, - bigDecimalRoundingMode); + return Decimal256Consumer.createConsumer( + (Decimal256Vector) vector, columnIndex, nullable, bigDecimalRoundingMode); } else { - return DecimalConsumer.createConsumer((DecimalVector) vector, columnIndex, nullable, bigDecimalRoundingMode); + return DecimalConsumer.createConsumer( + (DecimalVector) vector, columnIndex, nullable, bigDecimalRoundingMode); } case FloatingPoint: switch (((ArrowType.FloatingPoint) arrowType).getPrecision()) { @@ -495,17 +516,25 @@ public static JdbcConsumer getConsumer(ArrowType arrowType, int columnIndex, boo case Date: return DateConsumer.createConsumer((DateDayVector) vector, columnIndex, nullable, calendar); case Time: - return TimeConsumer.createConsumer((TimeMilliVector) vector, columnIndex, nullable, calendar); + return TimeConsumer.createConsumer( + (TimeMilliVector) vector, columnIndex, nullable, calendar); case Timestamp: if (config.getCalendar() == null) { - return TimestampConsumer.createConsumer((TimeStampMilliVector) vector, columnIndex, nullable); + return TimestampConsumer.createConsumer( + (TimeStampMilliVector) vector, columnIndex, nullable); } else { - return TimestampTZConsumer.createConsumer((TimeStampMilliTZVector) vector, columnIndex, nullable, calendar); + return TimestampTZConsumer.createConsumer( + (TimeStampMilliTZVector) vector, columnIndex, nullable, calendar); } case List: FieldVector childVector = ((ListVector) vector).getDataVector(); - JdbcConsumer delegate = getConsumer(childVector.getField().getType(), JDBC_ARRAY_VALUE_COLUMN, - childVector.getField().isNullable(), childVector, config); + JdbcConsumer delegate = + getConsumer( + childVector.getField().getType(), + JDBC_ARRAY_VALUE_COLUMN, + childVector.getField().isNullable(), + childVector, + config); return ArrayConsumer.createConsumer((ListVector) vector, delegate, columnIndex, nullable); case Map: return MapConsumer.createConsumer((MapVector) vector, columnIndex, nullable); diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BaseColumnBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BaseColumnBinder.java index f24f409072c..e1df0041982 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BaseColumnBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BaseColumnBinder.java @@ -21,6 +21,7 @@ /** * Base class for ColumnBinder implementations. + * * @param The concrete FieldVector subtype. */ public abstract class BaseColumnBinder implements ColumnBinder { diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BigIntBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BigIntBinder.java index fde4642ef90..f84a7c3e22b 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BigIntBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BigIntBinder.java @@ -20,7 +20,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.BigIntVector; /** A column binder for 8-bit integers. */ @@ -34,7 +33,8 @@ public BigIntBinder(BigIntVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { final long value = vector.getDataBuffer().getLong((long) rowIndex * BigIntVector.TYPE_WIDTH); statement.setLong(parameterIndex, value); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BitBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BitBinder.java index adae513e99e..86930dc35cb 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BitBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/BitBinder.java @@ -20,7 +20,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.BitVector; /** A column binder for booleans. */ @@ -34,7 +33,8 @@ public BitBinder(BitVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { // See BitVector#getBit final int byteIndex = rowIndex >> 3; final byte b = vector.getDataBuffer().getByte(byteIndex); diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinder.java index c2b1259e142..0e16b61ef84 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinder.java @@ -19,12 +19,9 @@ import java.sql.PreparedStatement; import java.sql.SQLException; - import org.apache.arrow.vector.FieldVector; -/** - * A helper to bind values from a wrapped Arrow vector to a JDBC PreparedStatement. - */ +/** A helper to bind values from a wrapped Arrow vector to a JDBC PreparedStatement. */ public interface ColumnBinder { /** * Bind the given row to the given parameter. @@ -43,14 +40,10 @@ public interface ColumnBinder { */ int getJdbcType(); - /** - * Get the vector used by this binder. - */ + /** Get the vector used by this binder. */ FieldVector getVector(); - /** - * Create a column binder for a vector, using the default JDBC type code for null values. - */ + /** Create a column binder for a vector, using the default JDBC type code for null values. */ static ColumnBinder forVector(FieldVector vector) { return forVector(vector, /*jdbcType*/ null); } @@ -62,7 +55,8 @@ static ColumnBinder forVector(FieldVector vector) { * @param jdbcType The JDBC type code to use (or null to use the default). */ static ColumnBinder forVector(FieldVector vector, Integer jdbcType) { - final ColumnBinder binder = vector.getField().getType().accept(new ColumnBinderArrowTypeVisitor(vector, jdbcType)); + final ColumnBinder binder = + vector.getField().getType().accept(new ColumnBinderArrowTypeVisitor(vector, jdbcType)); if (vector.getField().isNullable()) { return new NullableColumnBinder(binder); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinderArrowTypeVisitor.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinderArrowTypeVisitor.java index dc708724043..8dd43f25b66 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinderArrowTypeVisitor.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinderArrowTypeVisitor.java @@ -21,7 +21,6 @@ import java.time.ZoneId; import java.util.Calendar; import java.util.TimeZone; - import org.apache.arrow.vector.BigIntVector; import org.apache.arrow.vector.BitVector; import org.apache.arrow.vector.DateDayVector; @@ -50,8 +49,8 @@ /** * Visitor to create the base ColumnBinder for a vector. - *

- * To handle null values, wrap the returned binder in a {@link NullableColumnBinder}. + * + *

To handle null values, wrap the returned binder in a {@link NullableColumnBinder}. */ public class ColumnBinderArrowTypeVisitor implements ArrowType.ArrowTypeVisitor { private final FieldVector vector; @@ -111,17 +110,21 @@ public ColumnBinder visit(ArrowType.Int type) { } switch (type.getBitWidth()) { case 8: - return jdbcType == null ? new TinyIntBinder((TinyIntVector) vector) : - new TinyIntBinder((TinyIntVector) vector, jdbcType); + return jdbcType == null + ? new TinyIntBinder((TinyIntVector) vector) + : new TinyIntBinder((TinyIntVector) vector, jdbcType); case 16: - return jdbcType == null ? new SmallIntBinder((SmallIntVector) vector) : - new SmallIntBinder((SmallIntVector) vector, jdbcType); + return jdbcType == null + ? new SmallIntBinder((SmallIntVector) vector) + : new SmallIntBinder((SmallIntVector) vector, jdbcType); case 32: - return jdbcType == null ? new IntBinder((IntVector) vector) : - new IntBinder((IntVector) vector, jdbcType); + return jdbcType == null + ? new IntBinder((IntVector) vector) + : new IntBinder((IntVector) vector, jdbcType); case 64: - return jdbcType == null ? new BigIntBinder((BigIntVector) vector) : - new BigIntBinder((BigIntVector) vector, jdbcType); + return jdbcType == null + ? new BigIntBinder((BigIntVector) vector) + : new BigIntBinder((BigIntVector) vector, jdbcType); default: throw new UnsupportedOperationException("No column binder implemented for type " + type); } @@ -131,11 +134,13 @@ public ColumnBinder visit(ArrowType.Int type) { public ColumnBinder visit(ArrowType.FloatingPoint type) { switch (type.getPrecision()) { case SINGLE: - return jdbcType == null ? new Float4Binder((Float4Vector) vector) : - new Float4Binder((Float4Vector) vector, jdbcType); + return jdbcType == null + ? new Float4Binder((Float4Vector) vector) + : new Float4Binder((Float4Vector) vector, jdbcType); case DOUBLE: - return jdbcType == null ? new Float8Binder((Float8Vector) vector) : - new Float8Binder((Float8Vector) vector, jdbcType); + return jdbcType == null + ? new Float8Binder((Float8Vector) vector) + : new Float8Binder((Float8Vector) vector, jdbcType); default: throw new UnsupportedOperationException("No column binder implemented for type " + type); } @@ -144,51 +149,62 @@ public ColumnBinder visit(ArrowType.FloatingPoint type) { @Override public ColumnBinder visit(ArrowType.Utf8 type) { VarCharVector varChar = (VarCharVector) vector; - return jdbcType == null ? new VarCharBinder<>(varChar, Types.VARCHAR) : - new VarCharBinder<>(varChar, jdbcType); + return jdbcType == null + ? new VarCharBinder<>(varChar, Types.VARCHAR) + : new VarCharBinder<>(varChar, jdbcType); } @Override public ColumnBinder visit(ArrowType.LargeUtf8 type) { LargeVarCharVector varChar = (LargeVarCharVector) vector; - return jdbcType == null ? new VarCharBinder<>(varChar, Types.LONGVARCHAR) : - new VarCharBinder<>(varChar, jdbcType); + return jdbcType == null + ? new VarCharBinder<>(varChar, Types.LONGVARCHAR) + : new VarCharBinder<>(varChar, jdbcType); } @Override public ColumnBinder visit(ArrowType.Binary type) { VarBinaryVector varBinary = (VarBinaryVector) vector; - return jdbcType == null ? new VarBinaryBinder<>(varBinary, Types.VARBINARY) : - new VarBinaryBinder<>(varBinary, jdbcType); + return jdbcType == null + ? new VarBinaryBinder<>(varBinary, Types.VARBINARY) + : new VarBinaryBinder<>(varBinary, jdbcType); } @Override public ColumnBinder visit(ArrowType.LargeBinary type) { LargeVarBinaryVector varBinary = (LargeVarBinaryVector) vector; - return jdbcType == null ? new VarBinaryBinder<>(varBinary, Types.LONGVARBINARY) : - new VarBinaryBinder<>(varBinary, jdbcType); + return jdbcType == null + ? new VarBinaryBinder<>(varBinary, Types.LONGVARBINARY) + : new VarBinaryBinder<>(varBinary, jdbcType); } @Override public ColumnBinder visit(ArrowType.FixedSizeBinary type) { FixedSizeBinaryVector binary = (FixedSizeBinaryVector) vector; - return jdbcType == null ? new FixedSizeBinaryBinder(binary, Types.BINARY) : - new FixedSizeBinaryBinder(binary, jdbcType); + return jdbcType == null + ? new FixedSizeBinaryBinder(binary, Types.BINARY) + : new FixedSizeBinaryBinder(binary, jdbcType); } @Override public ColumnBinder visit(ArrowType.Bool type) { - return jdbcType == null ? new BitBinder((BitVector) vector) : new BitBinder((BitVector) vector, jdbcType); + return jdbcType == null + ? new BitBinder((BitVector) vector) + : new BitBinder((BitVector) vector, jdbcType); } @Override public ColumnBinder visit(ArrowType.Decimal type) { if (type.getBitWidth() == 128) { DecimalVector decimalVector = (DecimalVector) vector; - return jdbcType == null ? new Decimal128Binder(decimalVector) : new Decimal128Binder(decimalVector, jdbcType); + return jdbcType == null + ? new Decimal128Binder(decimalVector) + : new Decimal128Binder(decimalVector, jdbcType); } else if (type.getBitWidth() == 256) { Decimal256Vector decimalVector = (Decimal256Vector) vector; - return jdbcType == null ? new Decimal256Binder(decimalVector) : new Decimal256Binder(decimalVector, jdbcType); + return jdbcType == null + ? new Decimal256Binder(decimalVector) + : new Decimal256Binder(decimalVector, jdbcType); } throw new UnsupportedOperationException("No column binder implemented for type " + type); } @@ -197,11 +213,13 @@ public ColumnBinder visit(ArrowType.Decimal type) { public ColumnBinder visit(ArrowType.Date type) { switch (type.getUnit()) { case DAY: - return jdbcType == null ? new DateDayBinder((DateDayVector) vector) : - new DateDayBinder((DateDayVector) vector, /*calendar*/null, jdbcType); + return jdbcType == null + ? new DateDayBinder((DateDayVector) vector) + : new DateDayBinder((DateDayVector) vector, /*calendar*/ null, jdbcType); case MILLISECOND: - return jdbcType == null ? new DateMilliBinder((DateMilliVector) vector) : - new DateMilliBinder((DateMilliVector) vector, /*calendar*/null, jdbcType); + return jdbcType == null + ? new DateMilliBinder((DateMilliVector) vector) + : new DateMilliBinder((DateMilliVector) vector, /*calendar*/ null, jdbcType); default: throw new UnsupportedOperationException("No column binder implemented for type " + type); } @@ -211,17 +229,21 @@ public ColumnBinder visit(ArrowType.Date type) { public ColumnBinder visit(ArrowType.Time type) { switch (type.getUnit()) { case SECOND: - return jdbcType == null ? new Time32Binder((TimeSecVector) vector) : - new Time32Binder((TimeSecVector) vector, jdbcType); + return jdbcType == null + ? new Time32Binder((TimeSecVector) vector) + : new Time32Binder((TimeSecVector) vector, jdbcType); case MILLISECOND: - return jdbcType == null ? new Time32Binder((TimeMilliVector) vector) : - new Time32Binder((TimeMilliVector) vector, jdbcType); + return jdbcType == null + ? new Time32Binder((TimeMilliVector) vector) + : new Time32Binder((TimeMilliVector) vector, jdbcType); case MICROSECOND: - return jdbcType == null ? new Time64Binder((TimeMicroVector) vector) : - new Time64Binder((TimeMicroVector) vector, jdbcType); + return jdbcType == null + ? new Time64Binder((TimeMicroVector) vector) + : new Time64Binder((TimeMicroVector) vector, jdbcType); case NANOSECOND: - return jdbcType == null ? new Time64Binder((TimeNanoVector) vector) : - new Time64Binder((TimeNanoVector) vector, jdbcType); + return jdbcType == null + ? new Time64Binder((TimeNanoVector) vector) + : new Time64Binder((TimeNanoVector) vector, jdbcType); default: throw new UnsupportedOperationException("No column binder implemented for type " + type); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/DateDayBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/DateDayBinder.java index bc16790c8f3..92686d54203 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/DateDayBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/DateDayBinder.java @@ -22,12 +22,9 @@ import java.sql.SQLException; import java.sql.Types; import java.util.Calendar; - import org.apache.arrow.vector.DateDayVector; -/** - * A column binder for 32-bit dates. - */ +/** A column binder for 32-bit dates. */ public class DateDayBinder extends BaseColumnBinder { private static final long MILLIS_PER_DAY = 86_400_000; private final Calendar calendar; @@ -46,7 +43,8 @@ public DateDayBinder(DateDayVector vector, Calendar calendar, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { // TODO: multiply with overflow final long index = (long) rowIndex * DateDayVector.TYPE_WIDTH; final Date value = new Date(vector.getDataBuffer().getInt(index) * MILLIS_PER_DAY); diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/DateMilliBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/DateMilliBinder.java index 5cb91b46ac1..df2dcc8639d 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/DateMilliBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/DateMilliBinder.java @@ -22,12 +22,9 @@ import java.sql.SQLException; import java.sql.Types; import java.util.Calendar; - import org.apache.arrow.vector.DateMilliVector; -/** - * A column binder for 64-bit dates. - */ +/** A column binder for 64-bit dates. */ public class DateMilliBinder extends BaseColumnBinder { private final Calendar calendar; @@ -39,14 +36,14 @@ public DateMilliBinder(DateMilliVector vector, Calendar calendar) { this(vector, calendar, Types.DATE); } - public DateMilliBinder(DateMilliVector vector, Calendar calendar, int jdbcType) { super(vector, jdbcType); this.calendar = calendar; } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { final long index = (long) rowIndex * DateMilliVector.TYPE_WIDTH; final Date value = new Date(vector.getDataBuffer().getLong(index)); if (calendar == null) { diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Decimal128Binder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Decimal128Binder.java index 9e9d0e4fdb2..7f7e8774510 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Decimal128Binder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Decimal128Binder.java @@ -21,13 +21,10 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.DecimalVector; import org.apache.arrow.vector.util.DecimalUtility; -/** - * A binder for 128-bit decimals. - */ +/** A binder for 128-bit decimals. */ public class Decimal128Binder extends BaseColumnBinder { public Decimal128Binder(DecimalVector vector) { this(vector, Types.DECIMAL); @@ -38,9 +35,11 @@ public Decimal128Binder(DecimalVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { - final BigDecimal value = DecimalUtility.getBigDecimalFromArrowBuf( - vector.getDataBuffer(), rowIndex, vector.getScale(), DecimalVector.TYPE_WIDTH); + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { + final BigDecimal value = + DecimalUtility.getBigDecimalFromArrowBuf( + vector.getDataBuffer(), rowIndex, vector.getScale(), DecimalVector.TYPE_WIDTH); statement.setBigDecimal(parameterIndex, value); } } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Decimal256Binder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Decimal256Binder.java index bd29e083b45..38de58f76e1 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Decimal256Binder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Decimal256Binder.java @@ -21,13 +21,10 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.Decimal256Vector; import org.apache.arrow.vector.util.DecimalUtility; -/** - * A binder for 256-bit decimals. - */ +/** A binder for 256-bit decimals. */ public class Decimal256Binder extends BaseColumnBinder { public Decimal256Binder(Decimal256Vector vector) { this(vector, Types.DECIMAL); @@ -38,9 +35,11 @@ public Decimal256Binder(Decimal256Vector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { - final BigDecimal value = DecimalUtility.getBigDecimalFromArrowBuf( - vector.getDataBuffer(), rowIndex, vector.getScale(), Decimal256Vector.TYPE_WIDTH); + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { + final BigDecimal value = + DecimalUtility.getBigDecimalFromArrowBuf( + vector.getDataBuffer(), rowIndex, vector.getScale(), Decimal256Vector.TYPE_WIDTH); statement.setBigDecimal(parameterIndex, value); } } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/FixedSizeBinaryBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/FixedSizeBinaryBinder.java index 7edc5e45329..6f39ffe4db3 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/FixedSizeBinaryBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/FixedSizeBinaryBinder.java @@ -19,17 +19,14 @@ import java.sql.PreparedStatement; import java.sql.SQLException; - import org.apache.arrow.vector.FixedSizeBinaryVector; -/** - * A binder for fixed-width binary types. - */ +/** A binder for fixed-width binary types. */ public class FixedSizeBinaryBinder extends BaseColumnBinder { /** * Create a binder for the given vector using the given JDBC type for null values. * - * @param vector The vector to draw values from. + * @param vector The vector to draw values from. * @param jdbcType The JDBC type code. */ public FixedSizeBinaryBinder(FixedSizeBinaryVector vector, int jdbcType) { @@ -37,9 +34,12 @@ public FixedSizeBinaryBinder(FixedSizeBinaryVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { byte[] binaryData = new byte[vector.getByteWidth()]; - vector.getDataBuffer().getBytes((long) rowIndex * binaryData.length, binaryData, 0, binaryData.length); + vector + .getDataBuffer() + .getBytes((long) rowIndex * binaryData.length, binaryData, 0, binaryData.length); statement.setBytes(parameterIndex, binaryData); } } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Float4Binder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Float4Binder.java index a471c1ebadd..af3a3b21604 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Float4Binder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Float4Binder.java @@ -20,12 +20,9 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.Float4Vector; -/** - * A binder for 32-bit floats. - */ +/** A binder for 32-bit floats. */ public class Float4Binder extends BaseColumnBinder { public Float4Binder(Float4Vector vector) { this(vector, Types.REAL); @@ -36,7 +33,8 @@ public Float4Binder(Float4Vector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { final float value = vector.getDataBuffer().getFloat((long) rowIndex * Float4Vector.TYPE_WIDTH); statement.setFloat(parameterIndex, value); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Float8Binder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Float8Binder.java index 4710c3b5986..c85dc926ac0 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Float8Binder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Float8Binder.java @@ -20,12 +20,9 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.Float8Vector; -/** - * A binder for 64-bit floats. - */ +/** A binder for 64-bit floats. */ public class Float8Binder extends BaseColumnBinder { public Float8Binder(Float8Vector vector) { this(vector, Types.DOUBLE); @@ -36,8 +33,10 @@ public Float8Binder(Float8Vector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { - final double value = vector.getDataBuffer().getDouble((long) rowIndex * Float8Vector.TYPE_WIDTH); + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { + final double value = + vector.getDataBuffer().getDouble((long) rowIndex * Float8Vector.TYPE_WIDTH); statement.setDouble(parameterIndex, value); } } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/IntBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/IntBinder.java index 7d47f585a39..2d3bdbab4a8 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/IntBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/IntBinder.java @@ -20,7 +20,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.IntVector; /** A column binder for 32-bit integers. */ @@ -34,7 +33,8 @@ public IntBinder(IntVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { final int value = vector.getDataBuffer().getInt((long) rowIndex * IntVector.TYPE_WIDTH); statement.setInt(parameterIndex, value); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ListBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ListBinder.java index b8aa61234f4..7d59cb8ea01 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ListBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ListBinder.java @@ -20,15 +20,12 @@ import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; - import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.ListVector; import org.apache.arrow.vector.complex.impl.UnionListReader; import org.apache.arrow.vector.util.Text; -/** - * A column binder for list of primitive values. - */ +/** A column binder for list of primitive values. */ public class ListBinder extends BaseColumnBinder { private final UnionListReader listReader; @@ -52,7 +49,9 @@ public ListBinder(ListVector vector, int jdbcType) { try { arrayElementClass = dataVectorClass.getMethod("getObject", Integer.TYPE).getReturnType(); } catch (NoSuchMethodException e) { - final String message = String.format("Issue to determine type for getObject method of data vector class %s ", + final String message = + String.format( + "Issue to determine type for getObject method of data vector class %s ", dataVectorClass.getName()); throw new RuntimeException(message); } @@ -60,7 +59,8 @@ public ListBinder(ListVector vector, int jdbcType) { } @Override - public void bind(java.sql.PreparedStatement statement, int parameterIndex, int rowIndex)throws java.sql.SQLException { + public void bind(java.sql.PreparedStatement statement, int parameterIndex, int rowIndex) + throws java.sql.SQLException { listReader.setPosition(rowIndex); ArrayList sourceArray = (ArrayList) listReader.readObject(); Object array; @@ -69,7 +69,9 @@ public void bind(java.sql.PreparedStatement statement, int parameterIndex, int r Arrays.setAll((Object[]) array, sourceArray::get); } else { array = new String[sourceArray.size()]; - Arrays.setAll((Object[]) array, idx -> sourceArray.get(idx) != null ? sourceArray.get(idx).toString() : null); + Arrays.setAll( + (Object[]) array, + idx -> sourceArray.get(idx) != null ? sourceArray.get(idx).toString() : null); } statement.setObject(parameterIndex, array); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/MapBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/MapBinder.java index 07391eb7cbf..6e347a18123 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/MapBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/MapBinder.java @@ -23,16 +23,13 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Objects; - import org.apache.arrow.vector.complex.MapVector; import org.apache.arrow.vector.complex.impl.UnionMapReader; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.util.JsonStringHashMap; -/** - * A column binder for map of primitive values. - */ +/** A column binder for map of primitive values. */ public class MapBinder extends BaseColumnBinder { private UnionMapReader reader; @@ -58,8 +55,8 @@ public MapBinder(MapVector vector, int jdbcType) { } List keyValueFields = Objects.requireNonNull(structField.get(0)).getChildren(); if (keyValueFields.size() != 2) { - throw new IllegalArgumentException("Expected two children fields " + - "inside nested Struct field in Map"); + throw new IllegalArgumentException( + "Expected two children fields " + "inside nested Struct field in Map"); } ArrowType keyType = Objects.requireNonNull(keyValueFields.get(0)).getType(); ArrowType valueType = Objects.requireNonNull(keyValueFields.get(1)).getType(); @@ -68,15 +65,16 @@ public MapBinder(MapVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, - int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { reader.setPosition(rowIndex); LinkedHashMap tags = new JsonStringHashMap<>(); while (reader.next()) { Object key = reader.key().readObject(); Object value = reader.value().readObject(); - tags.put(isTextKey && key != null ? key.toString() : key, - isTextValue && value != null ? value.toString() : value); + tags.put( + isTextKey && key != null ? key.toString() : key, + isTextValue && value != null ? value.toString() : value); } switch (jdbcType) { case Types.VARCHAR: diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/NullableColumnBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/NullableColumnBinder.java index 123b587ca50..202a723c51a 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/NullableColumnBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/NullableColumnBinder.java @@ -19,12 +19,9 @@ import java.sql.PreparedStatement; import java.sql.SQLException; - import org.apache.arrow.vector.FieldVector; -/** - * A ColumnBinder that checks for nullability before deferring to a type-specific binder. - */ +/** A ColumnBinder that checks for nullability before deferring to a type-specific binder. */ public class NullableColumnBinder implements ColumnBinder { private final ColumnBinder wrapped; @@ -33,7 +30,8 @@ public NullableColumnBinder(ColumnBinder wrapped) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { if (wrapped.getVector().isNull(rowIndex)) { statement.setNull(parameterIndex, wrapped.getJdbcType()); } else { diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/SmallIntBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/SmallIntBinder.java index f9d744b9f54..81af48d83f7 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/SmallIntBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/SmallIntBinder.java @@ -20,7 +20,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.SmallIntVector; /** A column binder for 8-bit integers. */ @@ -34,8 +33,10 @@ public SmallIntBinder(SmallIntVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { - final short value = vector.getDataBuffer().getShort((short) rowIndex * SmallIntVector.TYPE_WIDTH); + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { + final short value = + vector.getDataBuffer().getShort((short) rowIndex * SmallIntVector.TYPE_WIDTH); statement.setShort(parameterIndex, value); } } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Time32Binder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Time32Binder.java index 5dc7e3f513f..ec09ae53cd8 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Time32Binder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Time32Binder.java @@ -21,14 +21,11 @@ import java.sql.SQLException; import java.sql.Time; import java.sql.Types; - import org.apache.arrow.vector.BaseFixedWidthVector; import org.apache.arrow.vector.TimeMilliVector; import org.apache.arrow.vector.TimeSecVector; -/** - * A binder for 32-bit time types. - */ +/** A binder for 32-bit time types. */ public class Time32Binder extends BaseColumnBinder { private static final long TYPE_WIDTH = 4; @@ -43,11 +40,11 @@ public Time32Binder(TimeMilliVector vector) { } public Time32Binder(TimeSecVector vector, int jdbcType) { - this(vector, /*factor*/1_000, jdbcType); + this(vector, /*factor*/ 1_000, jdbcType); } public Time32Binder(TimeMilliVector vector, int jdbcType) { - this(vector, /*factor*/1, jdbcType); + this(vector, /*factor*/ 1, jdbcType); } Time32Binder(BaseFixedWidthVector vector, long factor, int jdbcType) { @@ -56,7 +53,8 @@ public Time32Binder(TimeMilliVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { // TODO: multiply with overflow // TODO: take in a Calendar as well? final Time value = new Time(vector.getDataBuffer().getInt(rowIndex * TYPE_WIDTH) * factor); diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Time64Binder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Time64Binder.java index 8d62ae0eb36..0c858bc46be 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Time64Binder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/Time64Binder.java @@ -21,14 +21,11 @@ import java.sql.SQLException; import java.sql.Time; import java.sql.Types; - import org.apache.arrow.vector.BaseFixedWidthVector; import org.apache.arrow.vector.TimeMicroVector; import org.apache.arrow.vector.TimeNanoVector; -/** - * A binder for 64-bit time types. - */ +/** A binder for 64-bit time types. */ public class Time64Binder extends BaseColumnBinder { private static final long TYPE_WIDTH = 8; @@ -43,11 +40,11 @@ public Time64Binder(TimeNanoVector vector) { } public Time64Binder(TimeMicroVector vector, int jdbcType) { - this(vector, /*factor*/1_000, jdbcType); + this(vector, /*factor*/ 1_000, jdbcType); } public Time64Binder(TimeNanoVector vector, int jdbcType) { - this(vector, /*factor*/1_000_000, jdbcType); + this(vector, /*factor*/ 1_000_000, jdbcType); } Time64Binder(BaseFixedWidthVector vector, long factor, int jdbcType) { @@ -56,7 +53,8 @@ public Time64Binder(TimeNanoVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { // TODO: option to throw on truncation (vendor Guava IntMath#multiply) final Time value = new Time(vector.getDataBuffer().getLong(rowIndex * TYPE_WIDTH) / factor); statement.setTime(parameterIndex, value); diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/TimeStampBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/TimeStampBinder.java index 6677e590990..7e0de9ee59b 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/TimeStampBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/TimeStampBinder.java @@ -22,7 +22,6 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.Calendar; - import org.apache.arrow.vector.TimeStampVector; import org.apache.arrow.vector.types.pojo.ArrowType; @@ -32,15 +31,17 @@ public class TimeStampBinder extends BaseColumnBinder { private final long unitsPerSecond; private final long nanosPerUnit; - /** - * Create a binder for a timestamp vector using the default JDBC type code. - */ + /** Create a binder for a timestamp vector using the default JDBC type code. */ public TimeStampBinder(TimeStampVector vector, Calendar calendar) { - this(vector, calendar, isZoned(vector.getField().getType()) ? Types.TIMESTAMP_WITH_TIMEZONE : Types.TIMESTAMP); + this( + vector, + calendar, + isZoned(vector.getField().getType()) ? Types.TIMESTAMP_WITH_TIMEZONE : Types.TIMESTAMP); } /** * Create a binder for a timestamp vector. + * * @param vector The vector to pull values from. * @param calendar Optionally, the calendar to pass to JDBC. * @param jdbcType The JDBC type code to use for null values. @@ -73,19 +74,23 @@ public TimeStampBinder(TimeStampVector vector, Calendar calendar, int jdbcType) } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { // TODO: option to throw on truncation (vendor Guava IntMath#multiply) or overflow - final long rawValue = vector.getDataBuffer().getLong((long) rowIndex * TimeStampVector.TYPE_WIDTH); + final long rawValue = + vector.getDataBuffer().getLong((long) rowIndex * TimeStampVector.TYPE_WIDTH); final long seconds = rawValue / unitsPerSecond; final int nanos = (int) ((rawValue - (seconds * unitsPerSecond)) * nanosPerUnit); final Timestamp value = new Timestamp(seconds * 1_000); value.setNanos(nanos); if (calendar != null) { - // Timestamp == Date == UTC timestamp (confusingly). Arrow's timestamp with timezone is a UTC value with a + // Timestamp == Date == UTC timestamp (confusingly). Arrow's timestamp with timezone is a UTC + // value with a // zone offset, so we don't need to do any conversion. statement.setTimestamp(parameterIndex, value, calendar); } else { - // Arrow timestamp without timezone isn't strictly convertible to any timezone. So this is technically wrong, + // Arrow timestamp without timezone isn't strictly convertible to any timezone. So this is + // technically wrong, // but there is no 'correct' interpretation here. The application should provide a calendar. statement.setTimestamp(parameterIndex, value); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/TinyIntBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/TinyIntBinder.java index f51d139be86..d430b74ead3 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/TinyIntBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/TinyIntBinder.java @@ -20,7 +20,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.vector.TinyIntVector; /** A column binder for 8-bit integers. */ @@ -34,7 +33,8 @@ public TinyIntBinder(TinyIntVector vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { final byte value = vector.getDataBuffer().getByte((long) rowIndex * TinyIntVector.TYPE_WIDTH); statement.setByte(parameterIndex, value); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/VarBinaryBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/VarBinaryBinder.java index a94cff6a004..54082d8aa52 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/VarBinaryBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/VarBinaryBinder.java @@ -19,7 +19,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; - import org.apache.arrow.memory.util.ArrowBufPointer; import org.apache.arrow.vector.ElementAddressableVector; import org.apache.arrow.vector.FieldVector; @@ -29,13 +28,14 @@ * * @param The binary vector. */ -public class VarBinaryBinder extends BaseColumnBinder { +public class VarBinaryBinder + extends BaseColumnBinder { private final ArrowBufPointer element; /** * Create a binder for the given vector using the given JDBC type for null values. * - * @param vector The vector to draw values from. + * @param vector The vector to draw values from. * @param jdbcType The JDBC type code. */ public VarBinaryBinder(T vector, int jdbcType) { @@ -44,15 +44,18 @@ public VarBinaryBinder(T vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { vector.getDataPointer(rowIndex, element); if (element.getBuf() == null) { statement.setNull(parameterIndex, jdbcType); return; } if (element.getLength() > (long) Integer.MAX_VALUE) { - final String message = String.format("Length of value at index %d (%d) exceeds Integer.MAX_VALUE", - rowIndex, element.getLength()); + final String message = + String.format( + "Length of value at index %d (%d) exceeds Integer.MAX_VALUE", + rowIndex, element.getLength()); throw new RuntimeException(message); } byte[] binaryData = new byte[(int) element.getLength()]; diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/VarCharBinder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/VarCharBinder.java index 73bd5598149..5200506d333 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/VarCharBinder.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/VarCharBinder.java @@ -20,7 +20,6 @@ import java.nio.charset.StandardCharsets; import java.sql.PreparedStatement; import java.sql.SQLException; - import org.apache.arrow.memory.util.ArrowBufPointer; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.VariableWidthVector; @@ -30,13 +29,14 @@ * * @param The text vector. */ -public class VarCharBinder extends BaseColumnBinder { +public class VarCharBinder + extends BaseColumnBinder { private final ArrowBufPointer element; /** * Create a binder for the given vector using the given JDBC type for null values. * - * @param vector The vector to draw values from. + * @param vector The vector to draw values from. * @param jdbcType The JDBC type code. */ public VarCharBinder(T vector, int jdbcType) { @@ -45,15 +45,18 @@ public VarCharBinder(T vector, int jdbcType) { } @Override - public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { + public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) + throws SQLException { vector.getDataPointer(rowIndex, element); if (element.getBuf() == null) { statement.setNull(parameterIndex, jdbcType); return; } if (element.getLength() > (long) Integer.MAX_VALUE) { - final String message = String.format("Length of value at index %d (%d) exceeds Integer.MAX_VALUE", - rowIndex, element.getLength()); + final String message = + String.format( + "Length of value at index %d (%d) exceeds Integer.MAX_VALUE", + rowIndex, element.getLength()); throw new RuntimeException(message); } byte[] utf8Bytes = new byte[(int) element.getLength()]; diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/package-info.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/package-info.java index 4f8936e0c27..945c3c9f84f 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/package-info.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/package-info.java @@ -15,8 +15,5 @@ * limitations under the License. */ -/** - * Utilities to bind Arrow data as JDBC prepared statement parameters. - */ - +/** Utilities to bind Arrow data as JDBC prepared statement parameters. */ package org.apache.arrow.adapter.jdbc.binder; diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/ArrayConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/ArrayConsumer.java index 2f18b8a416d..620f9bb0b30 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/ArrayConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/ArrayConsumer.java @@ -21,22 +21,19 @@ import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.ValueVector; import org.apache.arrow.vector.complex.ListVector; /** - * Consumer which consume array type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.complex.ListVector}. + * Consumer which consume array type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.complex.ListVector}. */ public abstract class ArrayConsumer extends BaseConsumer { - /** - * Creates a consumer for {@link ListVector}. - */ + /** Creates a consumer for {@link ListVector}. */ public static ArrayConsumer createConsumer( - ListVector vector, JdbcConsumer delegate, int index, boolean nullable) { + ListVector vector, JdbcConsumer delegate, int index, boolean nullable) { if (nullable) { return new ArrayConsumer.NullableArrayConsumer(vector, delegate, index); } else { @@ -50,9 +47,7 @@ public static ArrayConsumer createConsumer( protected int innerVectorIndex = 0; - /** - * Instantiate a ArrayConsumer. - */ + /** Instantiate a ArrayConsumer. */ public ArrayConsumer(ListVector vector, JdbcConsumer delegate, int index) { super(vector, index); this.delegate = delegate; @@ -81,14 +76,10 @@ void ensureInnerVectorCapacity(int targetCapacity) { } } - /** - * Nullable consumer for {@link ListVector}. - */ + /** Nullable consumer for {@link ListVector}. */ static class NullableArrayConsumer extends ArrayConsumer { - /** - * Instantiate a nullable array consumer. - */ + /** Instantiate a nullable array consumer. */ public NullableArrayConsumer(ListVector vector, JdbcConsumer delegate, int index) { super(vector, delegate, index); } @@ -113,14 +104,10 @@ public void consume(ResultSet resultSet) throws SQLException, IOException { } } - /** - * Non-nullable consumer for {@link ListVector}. - */ + /** Non-nullable consumer for {@link ListVector}. */ static class NonNullableArrayConsumer extends ArrayConsumer { - /** - * Instantiate a nullable array consumer. - */ + /** Instantiate a nullable array consumer. */ public NonNullableArrayConsumer(ListVector vector, JdbcConsumer delegate, int index) { super(vector, delegate, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BaseConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BaseConsumer.java index 2db128d3e2b..8c5c0209455 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BaseConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BaseConsumer.java @@ -21,6 +21,7 @@ /** * Base class for all consumers. + * * @param vector type. */ public abstract class BaseConsumer implements JdbcConsumer { @@ -33,6 +34,7 @@ public abstract class BaseConsumer implements JdbcConsume /** * Constructs a new consumer. + * * @param vector the underlying vector for the consumer. * @param index the column id for the consumer. */ diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BigIntConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BigIntConsumer.java index 19c8efa9171..532103c8900 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BigIntConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BigIntConsumer.java @@ -19,19 +19,17 @@ import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.BigIntVector; /** - * Consumer which consume bigint type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.BigIntVector}. + * Consumer which consume bigint type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.BigIntVector}. */ public class BigIntConsumer { - /** - * Creates a consumer for {@link BigIntVector}. - */ - public static JdbcConsumer createConsumer(BigIntVector vector, int index, boolean nullable) { + /** Creates a consumer for {@link BigIntVector}. */ + public static JdbcConsumer createConsumer( + BigIntVector vector, int index, boolean nullable) { if (nullable) { return new NullableBigIntConsumer(vector, index); } else { @@ -39,14 +37,10 @@ public static JdbcConsumer createConsumer(BigIntVector vector, int } } - /** - * Nullable consumer for big int. - */ + /** Nullable consumer for big int. */ static class NullableBigIntConsumer extends BaseConsumer { - /** - * Instantiate a BigIntConsumer. - */ + /** Instantiate a BigIntConsumer. */ public NullableBigIntConsumer(BigIntVector vector, int index) { super(vector, index); } @@ -63,14 +57,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for big int. - */ + /** Non-nullable consumer for big int. */ static class NonNullableBigIntConsumer extends BaseConsumer { - /** - * Instantiate a BigIntConsumer. - */ + /** Instantiate a BigIntConsumer. */ public NonNullableBigIntConsumer(BigIntVector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumer.java index 8c5f61169d4..b0f6fce30b3 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumer.java @@ -21,20 +21,17 @@ import java.io.InputStream; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.vector.BitVectorHelper; import org.apache.arrow.vector.VarBinaryVector; /** - * Consumer which consume binary type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.VarBinaryVector}. + * Consumer which consume binary type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.VarBinaryVector}. */ public abstract class BinaryConsumer extends BaseConsumer { - /** - * Creates a consumer for {@link VarBinaryVector}. - */ + /** Creates a consumer for {@link VarBinaryVector}. */ public static BinaryConsumer createConsumer(VarBinaryVector vector, int index, boolean nullable) { if (nullable) { return new NullableBinaryConsumer(vector, index); @@ -45,9 +42,7 @@ public static BinaryConsumer createConsumer(VarBinaryVector vector, int index, b private final byte[] reuseBytes = new byte[1024]; - /** - * Instantiate a BinaryConsumer. - */ + /** Instantiate a BinaryConsumer. */ public BinaryConsumer(VarBinaryVector vector, int index) { super(vector, index); if (vector != null) { @@ -55,9 +50,7 @@ public BinaryConsumer(VarBinaryVector vector, int index) { } } - /** - * consume a InputStream. - */ + /** consume a InputStream. */ public void consume(InputStream is) throws IOException { if (is != null) { while (currentIndex >= vector.getValueCapacity()) { @@ -74,7 +67,8 @@ public void consume(InputStream is) throws IOException { vector.getDataBuffer().setBytes(startOffset + dataLength, reuseBytes, 0, read); dataLength += read; } - offsetBuffer.setInt((currentIndex + 1) * VarBinaryVector.OFFSET_WIDTH, startOffset + dataLength); + offsetBuffer.setInt( + (currentIndex + 1) * VarBinaryVector.OFFSET_WIDTH, startOffset + dataLength); BitVectorHelper.setBit(vector.getValidityBuffer(), currentIndex); vector.setLastSet(currentIndex); } @@ -91,14 +85,10 @@ public void resetValueVector(VarBinaryVector vector) { this.currentIndex = 0; } - /** - * Consumer for nullable binary data. - */ + /** Consumer for nullable binary data. */ static class NullableBinaryConsumer extends BinaryConsumer { - - /** - * Instantiate a BinaryConsumer. - */ + + /** Instantiate a BinaryConsumer. */ public NullableBinaryConsumer(VarBinaryVector vector, int index) { super(vector, index); } @@ -113,14 +103,10 @@ public void consume(ResultSet resultSet) throws SQLException, IOException { } } - /** - * Consumer for non-nullable binary data. - */ + /** Consumer for non-nullable binary data. */ static class NonNullableBinaryConsumer extends BinaryConsumer { - /** - * Instantiate a BinaryConsumer. - */ + /** Instantiate a BinaryConsumer. */ public NonNullableBinaryConsumer(VarBinaryVector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BitConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BitConsumer.java index d2d94d0a40e..18ce8fd9746 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BitConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BitConsumer.java @@ -19,19 +19,17 @@ import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.BitVector; /** - * Consumer which consume bit type values from {@link ResultSet}. - * Write the data to {@link BitVector}. + * Consumer which consume bit type values from {@link ResultSet}. Write the data to {@link + * BitVector}. */ public class BitConsumer { - /** - * Creates a consumer for {@link BitVector}. - */ - public static JdbcConsumer createConsumer(BitVector vector, int index, boolean nullable) { + /** Creates a consumer for {@link BitVector}. */ + public static JdbcConsumer createConsumer( + BitVector vector, int index, boolean nullable) { if (nullable) { return new NullableBitConsumer(vector, index); } else { @@ -39,14 +37,10 @@ public static JdbcConsumer createConsumer(BitVector vector, int index } } - /** - * Nullable consumer for {@link BitVector}. - */ + /** Nullable consumer for {@link BitVector}. */ static class NullableBitConsumer extends BaseConsumer { - /** - * Instantiate a BitConsumer. - */ + /** Instantiate a BitConsumer. */ public NullableBitConsumer(BitVector vector, int index) { super(vector, index); } @@ -63,14 +57,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for {@link BitVector}. - */ + /** Non-nullable consumer for {@link BitVector}. */ static class NonNullableBitConsumer extends BaseConsumer { - /** - * Instantiate a BitConsumer. - */ + /** Instantiate a BitConsumer. */ public NonNullableBitConsumer(BitVector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BlobConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BlobConsumer.java index e57ecdf9170..d2cf0c7f66c 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BlobConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/BlobConsumer.java @@ -21,12 +21,11 @@ import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.VarBinaryVector; /** - * Consumer which consume blob type values from {@link ResultSet}. - * Write the data to {@link VarBinaryVector}. + * Consumer which consume blob type values from {@link ResultSet}. Write the data to {@link + * VarBinaryVector}. */ public class BlobConsumer extends BaseConsumer { @@ -34,17 +33,12 @@ public class BlobConsumer extends BaseConsumer { private final boolean nullable; - /** - * Creates a consumer for {@link VarBinaryVector}. - */ - public static BlobConsumer createConsumer( - BinaryConsumer delegate, int index, boolean nullable) { + /** Creates a consumer for {@link VarBinaryVector}. */ + public static BlobConsumer createConsumer(BinaryConsumer delegate, int index, boolean nullable) { return new BlobConsumer(delegate, index, nullable); } - /** - * Instantiate a BlobConsumer. - */ + /** Instantiate a BlobConsumer. */ public BlobConsumer(BinaryConsumer delegate, int index, boolean nullable) { super(null, index); this.delegate = delegate; diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/ClobConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/ClobConsumer.java index a52d9b73b4d..454b25416b8 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/ClobConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/ClobConsumer.java @@ -21,21 +21,18 @@ import java.sql.Clob; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.util.MemoryUtil; import org.apache.arrow.vector.BitVectorHelper; import org.apache.arrow.vector.VarCharVector; /** - * Consumer which consume clob type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.VarCharVector}. + * Consumer which consume clob type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.VarCharVector}. */ public abstract class ClobConsumer extends BaseConsumer { - /** - * Creates a consumer for {@link VarCharVector}. - */ + /** Creates a consumer for {@link VarCharVector}. */ public static ClobConsumer createConsumer(VarCharVector vector, int index, boolean nullable) { if (nullable) { return new NullableClobConsumer(vector, index); @@ -46,9 +43,7 @@ public static ClobConsumer createConsumer(VarCharVector vector, int index, boole private static final int BUFFER_SIZE = 256; - /** - * Instantiate a ClobConsumer. - */ + /** Instantiate a ClobConsumer. */ public ClobConsumer(VarCharVector vector, int index) { super(vector, index); if (vector != null) { @@ -63,14 +58,10 @@ public void resetValueVector(VarCharVector vector) { this.currentIndex = 0; } - /** - * Nullable consumer for clob data. - */ + /** Nullable consumer for clob data. */ static class NullableClobConsumer extends ClobConsumer { - - /** - * Instantiate a ClobConsumer. - */ + + /** Instantiate a ClobConsumer. */ public NullableClobConsumer(VarCharVector vector, int index) { super(vector, index); } @@ -97,11 +88,11 @@ public void consume(ResultSet resultSet) throws SQLException { vector.reallocDataBuffer(); } MemoryUtil.UNSAFE.copyMemory( - bytes, - MemoryUtil.BYTE_ARRAY_BASE_OFFSET, - null, - dataBuffer.memoryAddress() + startIndex + totalBytes, - bytes.length); + bytes, + MemoryUtil.BYTE_ARRAY_BASE_OFFSET, + null, + dataBuffer.memoryAddress() + startIndex + totalBytes, + bytes.length); totalBytes += bytes.length; read += readSize; @@ -115,14 +106,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for clob data. - */ + /** Non-nullable consumer for clob data. */ static class NonNullableClobConsumer extends ClobConsumer { - /** - * Instantiate a ClobConsumer. - */ + /** Instantiate a ClobConsumer. */ public NonNullableClobConsumer(VarCharVector vector, int index) { super(vector, index); } @@ -148,11 +135,11 @@ public void consume(ResultSet resultSet) throws SQLException { vector.reallocDataBuffer(); } MemoryUtil.UNSAFE.copyMemory( - bytes, - MemoryUtil.BYTE_ARRAY_BASE_OFFSET, - null, - dataBuffer.memoryAddress() + startIndex + totalBytes, - bytes.length); + bytes, + MemoryUtil.BYTE_ARRAY_BASE_OFFSET, + null, + dataBuffer.memoryAddress() + startIndex + totalBytes, + bytes.length); totalBytes += bytes.length; read += readSize; @@ -161,7 +148,7 @@ public void consume(ResultSet resultSet) throws SQLException { BitVectorHelper.setBit(vector.getValidityBuffer(), currentIndex); vector.setLastSet(currentIndex); } - + currentIndex++; } } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/CompositeJdbcConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/CompositeJdbcConsumer.java index e6d780956d5..4e6049b9d83 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/CompositeJdbcConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/CompositeJdbcConsumer.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.adapter.jdbc.JdbcFieldInfo; import org.apache.arrow.adapter.jdbc.consumer.exceptions.JdbcConsumerException; import org.apache.arrow.util.AutoCloseables; @@ -28,17 +27,12 @@ import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.types.pojo.ArrowType; -/** - * Composite consumer which hold all consumers. - * It manages the consume and cleanup process. - */ +/** Composite consumer which hold all consumers. It manages the consume and cleanup process. */ public class CompositeJdbcConsumer implements JdbcConsumer { private final JdbcConsumer[] consumers; - /** - * Construct an instance. - */ + /** Construct an instance. */ public CompositeJdbcConsumer(JdbcConsumer[] consumers) { this.consumers = consumers; } @@ -51,9 +45,11 @@ public void consume(ResultSet rs) throws SQLException, IOException { } catch (Exception e) { if (consumers[i] instanceof BaseConsumer) { BaseConsumer consumer = (BaseConsumer) consumers[i]; - JdbcFieldInfo fieldInfo = new JdbcFieldInfo(rs.getMetaData(), consumer.columnIndexInResultSet); + JdbcFieldInfo fieldInfo = + new JdbcFieldInfo(rs.getMetaData(), consumer.columnIndexInResultSet); ArrowType arrowType = consumer.vector.getMinorType().getType(); - throw new JdbcConsumerException("Exception while consuming JDBC value", e, fieldInfo, arrowType); + throw new JdbcConsumerException( + "Exception while consuming JDBC value", e, fieldInfo, arrowType); } else { throw e; } @@ -70,17 +66,12 @@ public void close() { } catch (Exception e) { throw new RuntimeException("Error occurred while releasing resources.", e); } - } @Override - public void resetValueVector(ValueVector vector) { + public void resetValueVector(ValueVector vector) {} - } - - /** - * Reset inner consumers through vectors in the vector schema root. - */ + /** Reset inner consumers through vectors in the vector schema root. */ public void resetVectorSchemaRoot(VectorSchemaRoot root) { assert root.getFieldVectors().size() == consumers.length; for (int i = 0; i < consumers.length; i++) { @@ -88,4 +79,3 @@ public void resetVectorSchemaRoot(VectorSchemaRoot root) { } } } - diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DateConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DateConsumer.java index b9b83daccc2..aa69516526c 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DateConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DateConsumer.java @@ -22,19 +22,16 @@ import java.sql.SQLException; import java.util.Calendar; import java.util.concurrent.TimeUnit; - import org.apache.arrow.vector.DateDayVector; import org.apache.arrow.vector.DateMilliVector; /** - * Consumer which consume date type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.DateDayVector}. + * Consumer which consume date type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.DateDayVector}. */ public class DateConsumer { - /** - * Creates a consumer for {@link DateMilliVector}. - */ + /** Creates a consumer for {@link DateMilliVector}. */ public static JdbcConsumer createConsumer( DateDayVector vector, int index, boolean nullable, Calendar calendar) { if (nullable) { @@ -44,23 +41,17 @@ public static JdbcConsumer createConsumer( } } - /** - * Nullable consumer for date. - */ + /** Nullable consumer for date. */ static class NullableDateConsumer extends BaseConsumer { protected final Calendar calendar; - /** - * Instantiate a DateConsumer. - */ + /** Instantiate a DateConsumer. */ public NullableDateConsumer(DateDayVector vector, int index) { - this(vector, index, /* calendar */null); + this(vector, index, /* calendar */ null); } - /** - * Instantiate a DateConsumer. - */ + /** Instantiate a DateConsumer. */ public NullableDateConsumer(DateDayVector vector, int index, Calendar calendar) { super(vector, index); this.calendar = calendar; @@ -68,8 +59,10 @@ public NullableDateConsumer(DateDayVector vector, int index, Calendar calendar) @Override public void consume(ResultSet resultSet) throws SQLException { - Date date = calendar == null ? resultSet.getDate(columnIndexInResultSet) : - resultSet.getDate(columnIndexInResultSet, calendar); + Date date = + calendar == null + ? resultSet.getDate(columnIndexInResultSet) + : resultSet.getDate(columnIndexInResultSet, calendar); if (!resultSet.wasNull()) { // for fixed width vectors, we have allocated enough memory proactively, // so there is no need to call the setSafe method here. @@ -79,23 +72,17 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for date. - */ + /** Non-nullable consumer for date. */ static class NonNullableDateConsumer extends BaseConsumer { protected final Calendar calendar; - /** - * Instantiate a DateConsumer. - */ + /** Instantiate a DateConsumer. */ public NonNullableDateConsumer(DateDayVector vector, int index) { - this(vector, index, /* calendar */null); + this(vector, index, /* calendar */ null); } - /** - * Instantiate a DateConsumer. - */ + /** Instantiate a DateConsumer. */ public NonNullableDateConsumer(DateDayVector vector, int index, Calendar calendar) { super(vector, index); this.calendar = calendar; @@ -103,8 +90,10 @@ public NonNullableDateConsumer(DateDayVector vector, int index, Calendar calenda @Override public void consume(ResultSet resultSet) throws SQLException { - Date date = calendar == null ? resultSet.getDate(columnIndexInResultSet) : - resultSet.getDate(columnIndexInResultSet, calendar); + Date date = + calendar == null + ? resultSet.getDate(columnIndexInResultSet) + : resultSet.getDate(columnIndexInResultSet, calendar); // for fixed width vectors, we have allocated enough memory proactively, // so there is no need to call the setSafe method here. vector.set(currentIndex, Math.toIntExact(TimeUnit.MILLISECONDS.toDays(date.getTime()))); @@ -112,5 +101,3 @@ public void consume(ResultSet resultSet) throws SQLException { } } } - - diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/Decimal256Consumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/Decimal256Consumer.java index ad00d9b5a24..c670a4248b6 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/Decimal256Consumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/Decimal256Consumer.java @@ -21,12 +21,11 @@ import java.math.RoundingMode; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.Decimal256Vector; /** - * Consumer which consume decimal type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.Decimal256Vector}. + * Consumer which consume decimal type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.Decimal256Vector}. */ public abstract class Decimal256Consumer extends BaseConsumer { private final RoundingMode bigDecimalRoundingMode; @@ -36,7 +35,7 @@ public abstract class Decimal256Consumer extends BaseConsumer * Constructs a new consumer. * * @param vector the underlying vector for the consumer. - * @param index the column id for the consumer. + * @param index the column id for the consumer. */ public Decimal256Consumer(Decimal256Vector vector, int index) { this(vector, index, null); @@ -44,27 +43,23 @@ public Decimal256Consumer(Decimal256Vector vector, int index) { /** * Constructs a new consumer, with optional coercibility. + * * @param vector the underlying vector for the consumer. * @param index the column index for the consumer. - * @param bigDecimalRoundingMode java.math.RoundingMode to be applied if the BigDecimal scale does not match that - * of the target vector. Set to null to retain strict matching behavior (scale of - * source and target vector must match exactly). + * @param bigDecimalRoundingMode java.math.RoundingMode to be applied if the BigDecimal scale does + * not match that of the target vector. Set to null to retain strict matching behavior (scale + * of source and target vector must match exactly). */ - public Decimal256Consumer(Decimal256Vector vector, int index, RoundingMode bigDecimalRoundingMode) { + public Decimal256Consumer( + Decimal256Vector vector, int index, RoundingMode bigDecimalRoundingMode) { super(vector, index); this.bigDecimalRoundingMode = bigDecimalRoundingMode; this.scale = vector.getScale(); } - /** - * Creates a consumer for {@link Decimal256Vector}. - */ + /** Creates a consumer for {@link Decimal256Vector}. */ public static JdbcConsumer createConsumer( - Decimal256Vector vector, - int index, - boolean nullable, - RoundingMode bigDecimalRoundingMode - ) { + Decimal256Vector vector, int index, boolean nullable, RoundingMode bigDecimalRoundingMode) { if (nullable) { return new NullableDecimal256Consumer(vector, index, bigDecimalRoundingMode); } else { @@ -79,16 +74,12 @@ protected void set(BigDecimal value) { vector.set(currentIndex, value); } - - /** - * Consumer for nullable decimal. - */ + /** Consumer for nullable decimal. */ static class NullableDecimal256Consumer extends Decimal256Consumer { - /** - * Instantiate a Decimal256Consumer. - */ - public NullableDecimal256Consumer(Decimal256Vector vector, int index, RoundingMode bigDecimalRoundingMode) { + /** Instantiate a Decimal256Consumer. */ + public NullableDecimal256Consumer( + Decimal256Vector vector, int index, RoundingMode bigDecimalRoundingMode) { super(vector, index, bigDecimalRoundingMode); } @@ -104,15 +95,12 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Consumer for non-nullable decimal. - */ + /** Consumer for non-nullable decimal. */ static class NonNullableDecimal256Consumer extends Decimal256Consumer { - /** - * Instantiate a Decimal256Consumer. - */ - public NonNullableDecimal256Consumer(Decimal256Vector vector, int index, RoundingMode bigDecimalRoundingMode) { + /** Instantiate a Decimal256Consumer. */ + public NonNullableDecimal256Consumer( + Decimal256Vector vector, int index, RoundingMode bigDecimalRoundingMode) { super(vector, index, bigDecimalRoundingMode); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DecimalConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DecimalConsumer.java index bed96dda8b6..034cdf14ae6 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DecimalConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DecimalConsumer.java @@ -21,12 +21,11 @@ import java.math.RoundingMode; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.DecimalVector; /** - * Consumer which consume decimal type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.DecimalVector}. + * Consumer which consume decimal type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.DecimalVector}. */ public abstract class DecimalConsumer extends BaseConsumer { private final RoundingMode bigDecimalRoundingMode; @@ -36,7 +35,7 @@ public abstract class DecimalConsumer extends BaseConsumer { * Constructs a new consumer. * * @param vector the underlying vector for the consumer. - * @param index the column id for the consumer. + * @param index the column id for the consumer. */ public DecimalConsumer(DecimalVector vector, int index) { this(vector, index, null); @@ -44,11 +43,12 @@ public DecimalConsumer(DecimalVector vector, int index) { /** * Constructs a new consumer, with optional coercibility. + * * @param vector the underlying vector for the consumer. * @param index the column index for the consumer. - * @param bigDecimalRoundingMode java.math.RoundingMode to be applied if the BigDecimal scale does not match that - * of the target vector. Set to null to retain strict matching behavior (scale of - * source and target vector must match exactly). + * @param bigDecimalRoundingMode java.math.RoundingMode to be applied if the BigDecimal scale does + * not match that of the target vector. Set to null to retain strict matching behavior (scale + * of source and target vector must match exactly). */ public DecimalConsumer(DecimalVector vector, int index, RoundingMode bigDecimalRoundingMode) { super(vector, index); @@ -56,15 +56,9 @@ public DecimalConsumer(DecimalVector vector, int index, RoundingMode bigDecimalR this.scale = vector.getScale(); } - /** - * Creates a consumer for {@link DecimalVector}. - */ + /** Creates a consumer for {@link DecimalVector}. */ public static JdbcConsumer createConsumer( - DecimalVector vector, - int index, - boolean nullable, - RoundingMode bigDecimalRoundingMode - ) { + DecimalVector vector, int index, boolean nullable, RoundingMode bigDecimalRoundingMode) { if (nullable) { return new NullableDecimalConsumer(vector, index, bigDecimalRoundingMode); } else { @@ -79,16 +73,12 @@ protected void set(BigDecimal value) { vector.set(currentIndex, value); } - - /** - * Consumer for nullable decimal. - */ + /** Consumer for nullable decimal. */ static class NullableDecimalConsumer extends DecimalConsumer { - /** - * Instantiate a DecimalConsumer. - */ - public NullableDecimalConsumer(DecimalVector vector, int index, RoundingMode bigDecimalRoundingMode) { + /** Instantiate a DecimalConsumer. */ + public NullableDecimalConsumer( + DecimalVector vector, int index, RoundingMode bigDecimalRoundingMode) { super(vector, index, bigDecimalRoundingMode); } @@ -104,15 +94,12 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Consumer for non-nullable decimal. - */ + /** Consumer for non-nullable decimal. */ static class NonNullableDecimalConsumer extends DecimalConsumer { - /** - * Instantiate a DecimalConsumer. - */ - public NonNullableDecimalConsumer(DecimalVector vector, int index, RoundingMode bigDecimalRoundingMode) { + /** Instantiate a DecimalConsumer. */ + public NonNullableDecimalConsumer( + DecimalVector vector, int index, RoundingMode bigDecimalRoundingMode) { super(vector, index, bigDecimalRoundingMode); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DoubleConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DoubleConsumer.java index e3db95d1535..79cb4f65bb6 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DoubleConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DoubleConsumer.java @@ -19,19 +19,17 @@ import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.Float8Vector; /** - * Consumer which consume double type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.Float8Vector}. + * Consumer which consume double type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.Float8Vector}. */ public class DoubleConsumer { - /** - * Creates a consumer for {@link Float8Vector}. - */ - public static JdbcConsumer createConsumer(Float8Vector vector, int index, boolean nullable) { + /** Creates a consumer for {@link Float8Vector}. */ + public static JdbcConsumer createConsumer( + Float8Vector vector, int index, boolean nullable) { if (nullable) { return new NullableDoubleConsumer(vector, index); } else { @@ -39,14 +37,10 @@ public static JdbcConsumer createConsumer(Float8Vector vector, int } } - /** - * Nullable double consumer. - */ + /** Nullable double consumer. */ static class NullableDoubleConsumer extends BaseConsumer { - /** - * Instantiate a DoubleConsumer. - */ + /** Instantiate a DoubleConsumer. */ public NullableDoubleConsumer(Float8Vector vector, int index) { super(vector, index); } @@ -63,14 +57,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable double consumer. - */ + /** Non-nullable double consumer. */ static class NonNullableDoubleConsumer extends BaseConsumer { - /** - * Instantiate a DoubleConsumer. - */ + /** Instantiate a DoubleConsumer. */ public NonNullableDoubleConsumer(Float8Vector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/FloatConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/FloatConsumer.java index 830348fe94c..70b6e50e483 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/FloatConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/FloatConsumer.java @@ -19,19 +19,17 @@ import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.Float4Vector; /** - * Consumer which consume float type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.Float4Vector}. + * Consumer which consume float type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.Float4Vector}. */ public class FloatConsumer { - /** - * Creates a consumer for {@link Float4Vector}. - */ - public static JdbcConsumer createConsumer(Float4Vector vector, int index, boolean nullable) { + /** Creates a consumer for {@link Float4Vector}. */ + public static JdbcConsumer createConsumer( + Float4Vector vector, int index, boolean nullable) { if (nullable) { return new NullableFloatConsumer(vector, index); } else { @@ -39,14 +37,10 @@ public static JdbcConsumer createConsumer(Float4Vector vector, int } } - /** - * Nullable float consumer. - */ + /** Nullable float consumer. */ static class NullableFloatConsumer extends BaseConsumer { - /** - * Instantiate a FloatConsumer. - */ + /** Instantiate a FloatConsumer. */ public NullableFloatConsumer(Float4Vector vector, int index) { super(vector, index); } @@ -63,14 +57,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable float consumer. - */ + /** Non-nullable float consumer. */ static class NonNullableFloatConsumer extends BaseConsumer { - /** - * Instantiate a FloatConsumer. - */ + /** Instantiate a FloatConsumer. */ public NonNullableFloatConsumer(Float4Vector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/IntConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/IntConsumer.java index 4e537d682ff..883cc1b8ffa 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/IntConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/IntConsumer.java @@ -19,19 +19,17 @@ import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.IntVector; /** - * Consumer which consume int type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.IntVector}. + * Consumer which consume int type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.IntVector}. */ public class IntConsumer { - /** - * Creates a consumer for {@link IntVector}. - */ - public static JdbcConsumer createConsumer(IntVector vector, int index, boolean nullable) { + /** Creates a consumer for {@link IntVector}. */ + public static JdbcConsumer createConsumer( + IntVector vector, int index, boolean nullable) { if (nullable) { return new NullableIntConsumer(vector, index); } else { @@ -39,14 +37,10 @@ public static JdbcConsumer createConsumer(IntVector vector, int index } } - /** - * Nullable consumer for int. - */ + /** Nullable consumer for int. */ static class NullableIntConsumer extends BaseConsumer { - /** - * Instantiate a IntConsumer. - */ + /** Instantiate a IntConsumer. */ public NullableIntConsumer(IntVector vector, int index) { super(vector, index); } @@ -63,14 +57,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for int. - */ + /** Non-nullable consumer for int. */ static class NonNullableIntConsumer extends BaseConsumer { - /** - * Instantiate a IntConsumer. - */ + /** Instantiate a IntConsumer. */ public NonNullableIntConsumer(IntVector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/JdbcConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/JdbcConsumer.java index 480dfe3a1c5..4d20e27d1d6 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/JdbcConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/JdbcConsumer.java @@ -20,27 +20,21 @@ import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.ValueVector; /** * An abstraction that is used to consume values from {@link ResultSet}. + * * @param The vector within consumer or its delegate, used for partially consume purpose. */ public interface JdbcConsumer extends AutoCloseable { - /** - * Consume a specific type value from {@link ResultSet} and write it to vector. - */ + /** Consume a specific type value from {@link ResultSet} and write it to vector. */ void consume(ResultSet resultSet) throws SQLException, IOException; - /** - * Close this consumer, do some clean work such as clear reuse ArrowBuf. - */ + /** Close this consumer, do some clean work such as clear reuse ArrowBuf. */ void close() throws Exception; - /** - * Reset the vector within consumer for partial read purpose. - */ + /** Reset the vector within consumer for partial read purpose. */ void resetValueVector(T vector); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/MapConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/MapConsumer.java index 07a071bfc09..b556c14e9e6 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/MapConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/MapConsumer.java @@ -17,43 +17,37 @@ package org.apache.arrow.adapter.jdbc.consumer; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.MapVector; import org.apache.arrow.vector.complex.impl.UnionMapWriter; import org.apache.arrow.vector.util.ObjectMapperFactory; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - /** - * Consumer which consume map type values from {@link ResultSet}. - * Write the data into {@link org.apache.arrow.vector.complex.MapVector}. + * Consumer which consume map type values from {@link ResultSet}. Write the data into {@link + * org.apache.arrow.vector.complex.MapVector}. */ public class MapConsumer extends BaseConsumer { - private final UnionMapWriter writer; private final ObjectMapper objectMapper = ObjectMapperFactory.newObjectMapper(); - private final TypeReference> typeReference = new TypeReference>() {}; + private final TypeReference> typeReference = + new TypeReference>() {}; private int currentRow; - /** - * Creates a consumer for {@link MapVector}. - */ + /** Creates a consumer for {@link MapVector}. */ public static MapConsumer createConsumer(MapVector mapVector, int index, boolean nullable) { return new MapConsumer(mapVector, index); } - /** - * Instantiate a MapConsumer. - */ + /** Instantiate a MapConsumer. */ public MapConsumer(MapVector vector, int index) { super(vector, index); writer = vector.getWriter(); @@ -69,7 +63,8 @@ public void consume(ResultSet resultSet) throws SQLException, IOException { } else if (map instanceof Map) { writeJavaMapIntoVector((Map) map); } else { - throw new IllegalArgumentException("Unknown type of map type column from JDBC " + map.getClass().getName()); + throw new IllegalArgumentException( + "Unknown type of map type column from JDBC " + map.getClass().getName()); } } else { writer.writeNull(); @@ -79,26 +74,25 @@ public void consume(ResultSet resultSet) throws SQLException, IOException { private void writeJavaMapIntoVector(Map map) { BufferAllocator allocator = vector.getAllocator(); writer.startMap(); - map.forEach((key, value) -> { - byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); - byte[] valueBytes = value != null ? value.getBytes(StandardCharsets.UTF_8) : null; - try ( - ArrowBuf keyBuf = allocator.buffer(keyBytes.length); - ArrowBuf valueBuf = valueBytes != null ? allocator.buffer(valueBytes.length) : null; - ) { - writer.startEntry(); - keyBuf.writeBytes(keyBytes); - writer.key().varChar().writeVarChar(0, keyBytes.length, keyBuf); - if (valueBytes != null) { - valueBuf.writeBytes(valueBytes); - writer.value().varChar().writeVarChar(0, valueBytes.length, valueBuf); - } else { - writer.value().varChar().writeNull(); - } - writer.endEntry(); - } - }); + map.forEach( + (key, value) -> { + byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); + byte[] valueBytes = value != null ? value.getBytes(StandardCharsets.UTF_8) : null; + try (ArrowBuf keyBuf = allocator.buffer(keyBytes.length); + ArrowBuf valueBuf = + valueBytes != null ? allocator.buffer(valueBytes.length) : null; ) { + writer.startEntry(); + keyBuf.writeBytes(keyBytes); + writer.key().varChar().writeVarChar(0, keyBytes.length, keyBuf); + if (valueBytes != null) { + valueBuf.writeBytes(valueBytes); + writer.value().varChar().writeVarChar(0, valueBytes.length, valueBuf); + } else { + writer.value().varChar().writeNull(); + } + writer.endEntry(); + } + }); writer.endMap(); } } - diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/NullConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/NullConsumer.java index a79a029f45d..5b9aee84212 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/NullConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/NullConsumer.java @@ -19,12 +19,11 @@ import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.NullVector; /** - * Consumer which consume null type values from ResultSet. - * Corresponding to {@link org.apache.arrow.vector.NullVector}. + * Consumer which consume null type values from ResultSet. Corresponding to {@link + * org.apache.arrow.vector.NullVector}. */ public class NullConsumer extends BaseConsumer { @@ -33,6 +32,5 @@ public NullConsumer(NullVector vector) { } @Override - public void consume(ResultSet resultSet) throws SQLException { - } + public void consume(ResultSet resultSet) throws SQLException {} } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/SmallIntConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/SmallIntConsumer.java index 2edb3605b17..0fe3eb3d2df 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/SmallIntConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/SmallIntConsumer.java @@ -19,19 +19,17 @@ import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.SmallIntVector; /** - * Consumer which consume smallInt type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.SmallIntVector}. + * Consumer which consume smallInt type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.SmallIntVector}. */ public class SmallIntConsumer { - /** - * Creates a consumer for {@link SmallIntVector}. - */ - public static BaseConsumer createConsumer(SmallIntVector vector, int index, boolean nullable) { + /** Creates a consumer for {@link SmallIntVector}. */ + public static BaseConsumer createConsumer( + SmallIntVector vector, int index, boolean nullable) { if (nullable) { return new NullableSmallIntConsumer(vector, index); } else { @@ -39,14 +37,10 @@ public static BaseConsumer createConsumer(SmallIntVector vector, } } - /** - * Nullable consumer for small int. - */ + /** Nullable consumer for small int. */ static class NullableSmallIntConsumer extends BaseConsumer { - /** - * Instantiate a SmallIntConsumer. - */ + /** Instantiate a SmallIntConsumer. */ public NullableSmallIntConsumer(SmallIntVector vector, int index) { super(vector, index); } @@ -63,14 +57,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for small int. - */ + /** Non-nullable consumer for small int. */ static class NonNullableSmallIntConsumer extends BaseConsumer { - /** - * Instantiate a SmallIntConsumer. - */ + /** Instantiate a SmallIntConsumer. */ public NonNullableSmallIntConsumer(SmallIntVector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimeConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimeConsumer.java index 4fa15ad7903..d5b647a6189 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimeConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimeConsumer.java @@ -21,20 +21,17 @@ import java.sql.SQLException; import java.sql.Time; import java.util.Calendar; - import org.apache.arrow.vector.TimeMilliVector; /** - * Consumer which consume time type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.TimeMilliVector}. + * Consumer which consume time type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.TimeMilliVector}. */ public abstract class TimeConsumer { - /** - * Creates a consumer for {@link TimeMilliVector}. - */ + /** Creates a consumer for {@link TimeMilliVector}. */ public static JdbcConsumer createConsumer( - TimeMilliVector vector, int index, boolean nullable, Calendar calendar) { + TimeMilliVector vector, int index, boolean nullable, Calendar calendar) { if (nullable) { return new NullableTimeConsumer(vector, index, calendar); } else { @@ -42,23 +39,17 @@ public static JdbcConsumer createConsumer( } } - /** - * Nullable consumer for {@link TimeMilliVector}. - */ + /** Nullable consumer for {@link TimeMilliVector}. */ static class NullableTimeConsumer extends BaseConsumer { protected final Calendar calendar; - /** - * Instantiate a TimeConsumer. - */ + /** Instantiate a TimeConsumer. */ public NullableTimeConsumer(TimeMilliVector vector, int index) { - this(vector, index, /* calendar */null); + this(vector, index, /* calendar */ null); } - /** - * Instantiate a TimeConsumer. - */ + /** Instantiate a TimeConsumer. */ public NullableTimeConsumer(TimeMilliVector vector, int index, Calendar calendar) { super(vector, index); this.calendar = calendar; @@ -66,8 +57,10 @@ public NullableTimeConsumer(TimeMilliVector vector, int index, Calendar calendar @Override public void consume(ResultSet resultSet) throws SQLException { - Time time = calendar == null ? resultSet.getTime(columnIndexInResultSet) : - resultSet.getTime(columnIndexInResultSet, calendar); + Time time = + calendar == null + ? resultSet.getTime(columnIndexInResultSet) + : resultSet.getTime(columnIndexInResultSet, calendar); if (!resultSet.wasNull()) { // for fixed width vectors, we have allocated enough memory proactively, // so there is no need to call the setSafe method here. @@ -77,23 +70,17 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for {@link TimeMilliVector}. - */ + /** Non-nullable consumer for {@link TimeMilliVector}. */ static class NonNullableTimeConsumer extends BaseConsumer { protected final Calendar calendar; - /** - * Instantiate a TimeConsumer. - */ + /** Instantiate a TimeConsumer. */ public NonNullableTimeConsumer(TimeMilliVector vector, int index) { - this(vector, index, /* calendar */null); + this(vector, index, /* calendar */ null); } - /** - * Instantiate a TimeConsumer. - */ + /** Instantiate a TimeConsumer. */ public NonNullableTimeConsumer(TimeMilliVector vector, int index, Calendar calendar) { super(vector, index); this.calendar = calendar; @@ -101,8 +88,10 @@ public NonNullableTimeConsumer(TimeMilliVector vector, int index, Calendar calen @Override public void consume(ResultSet resultSet) throws SQLException { - Time time = calendar == null ? resultSet.getTime(columnIndexInResultSet) : - resultSet.getTime(columnIndexInResultSet, calendar); + Time time = + calendar == null + ? resultSet.getTime(columnIndexInResultSet) + : resultSet.getTime(columnIndexInResultSet, calendar); // for fixed width vectors, we have allocated enough memory proactively, // so there is no need to call the setSafe method here. vector.set(currentIndex, (int) time.getTime()); diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampConsumer.java index 3351e7e78a7..0b96092465c 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampConsumer.java @@ -20,20 +20,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; - import org.apache.arrow.vector.TimeStampMilliVector; /** - * Consumer which consume timestamp type values from {@link ResultSet}. - * Write the data to {@link TimeStampMilliVector}. + * Consumer which consume timestamp type values from {@link ResultSet}. Write the data to {@link + * TimeStampMilliVector}. */ public abstract class TimestampConsumer { - /** - * Creates a consumer for {@link TimeStampMilliVector}. - */ + /** Creates a consumer for {@link TimeStampMilliVector}. */ public static JdbcConsumer createConsumer( - TimeStampMilliVector vector, int index, boolean nullable) { + TimeStampMilliVector vector, int index, boolean nullable) { if (nullable) { return new NullableTimestampConsumer(vector, index); } else { @@ -41,14 +38,10 @@ public static JdbcConsumer createConsumer( } } - /** - * Nullable consumer for timestamp. - */ + /** Nullable consumer for timestamp. */ static class NullableTimestampConsumer extends BaseConsumer { - /** - * Instantiate a TimestampConsumer. - */ + /** Instantiate a TimestampConsumer. */ public NullableTimestampConsumer(TimeStampMilliVector vector, int index) { super(vector, index); } @@ -65,14 +58,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for timestamp. - */ + /** Non-nullable consumer for timestamp. */ static class NonNullableTimestampConsumer extends BaseConsumer { - /** - * Instantiate a TimestampConsumer. - */ + /** Instantiate a TimestampConsumer. */ public NonNullableTimestampConsumer(TimeStampMilliVector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampTZConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampTZConsumer.java index f08671f0be6..c55b6669326 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampTZConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TimestampTZConsumer.java @@ -21,18 +21,15 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.util.Calendar; - import org.apache.arrow.util.Preconditions; import org.apache.arrow.vector.TimeStampMilliTZVector; /** - * Consumer which consume timestamp (with time zone) type values from {@link ResultSet}. - * Write the data to {@link TimeStampMilliTZVector}. + * Consumer which consume timestamp (with time zone) type values from {@link ResultSet}. Write the + * data to {@link TimeStampMilliTZVector}. */ public class TimestampTZConsumer { - /** - * Creates a consumer for {@link TimeStampMilliTZVector}. - */ + /** Creates a consumer for {@link TimeStampMilliTZVector}. */ public static JdbcConsumer createConsumer( TimeStampMilliTZVector vector, int index, boolean nullable, Calendar calendar) { Preconditions.checkArgument(calendar != null, "Calendar cannot be null"); @@ -43,17 +40,14 @@ public static JdbcConsumer createConsumer( } } - /** - * Nullable consumer for timestamp (with time zone). - */ + /** Nullable consumer for timestamp (with time zone). */ static class NullableTimestampTZConsumer extends BaseConsumer { protected final Calendar calendar; - /** - * Instantiate a TimestampConsumer. - */ - public NullableTimestampTZConsumer(TimeStampMilliTZVector vector, int index, Calendar calendar) { + /** Instantiate a TimestampConsumer. */ + public NullableTimestampTZConsumer( + TimeStampMilliTZVector vector, int index, Calendar calendar) { super(vector, index); this.calendar = calendar; } @@ -70,17 +64,14 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for timestamp (with time zone). - */ + /** Non-nullable consumer for timestamp (with time zone). */ static class NonNullableTimestampConsumer extends BaseConsumer { protected final Calendar calendar; - /** - * Instantiate a TimestampConsumer. - */ - public NonNullableTimestampConsumer(TimeStampMilliTZVector vector, int index, Calendar calendar) { + /** Instantiate a TimestampConsumer. */ + public NonNullableTimestampConsumer( + TimeStampMilliTZVector vector, int index, Calendar calendar) { super(vector, index); this.calendar = calendar; } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TinyIntConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TinyIntConsumer.java index 40cf087a5ec..1191f6ac8e7 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TinyIntConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/TinyIntConsumer.java @@ -19,19 +19,17 @@ import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.TinyIntVector; /** - * Consumer which consume tinyInt type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.TinyIntVector}. + * Consumer which consume tinyInt type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.TinyIntVector}. */ public abstract class TinyIntConsumer { - /** - * Creates a consumer for {@link TinyIntVector}. - */ - public static JdbcConsumer createConsumer(TinyIntVector vector, int index, boolean nullable) { + /** Creates a consumer for {@link TinyIntVector}. */ + public static JdbcConsumer createConsumer( + TinyIntVector vector, int index, boolean nullable) { if (nullable) { return new NullableTinyIntConsumer(vector, index); } else { @@ -39,14 +37,10 @@ public static JdbcConsumer createConsumer(TinyIntVector vector, i } } - /** - * Nullable consumer for tiny int. - */ + /** Nullable consumer for tiny int. */ static class NullableTinyIntConsumer extends BaseConsumer { - /** - * Instantiate a TinyIntConsumer. - */ + /** Instantiate a TinyIntConsumer. */ public NullableTinyIntConsumer(TinyIntVector vector, int index) { super(vector, index); } @@ -63,14 +57,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for tiny int. - */ + /** Non-nullable consumer for tiny int. */ static class NonNullableTinyIntConsumer extends BaseConsumer { - /** - * Instantiate a TinyIntConsumer. - */ + /** Instantiate a TinyIntConsumer. */ public NonNullableTinyIntConsumer(TinyIntVector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/VarCharConsumer.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/VarCharConsumer.java index 05333715b8c..2a9f87b0cbe 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/VarCharConsumer.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/VarCharConsumer.java @@ -20,19 +20,17 @@ import java.nio.charset.StandardCharsets; import java.sql.ResultSet; import java.sql.SQLException; - import org.apache.arrow.vector.VarCharVector; /** - * Consumer which consume varchar type values from {@link ResultSet}. - * Write the data to {@link org.apache.arrow.vector.VarCharVector}. + * Consumer which consume varchar type values from {@link ResultSet}. Write the data to {@link + * org.apache.arrow.vector.VarCharVector}. */ public abstract class VarCharConsumer { - /** - * Creates a consumer for {@link VarCharVector}. - */ - public static JdbcConsumer createConsumer(VarCharVector vector, int index, boolean nullable) { + /** Creates a consumer for {@link VarCharVector}. */ + public static JdbcConsumer createConsumer( + VarCharVector vector, int index, boolean nullable) { if (nullable) { return new NullableVarCharConsumer(vector, index); } else { @@ -40,14 +38,10 @@ public static JdbcConsumer createConsumer(VarCharVector vector, i } } - /** - * Nullable consumer for var char. - */ + /** Nullable consumer for var char. */ static class NullableVarCharConsumer extends BaseConsumer { - /** - * Instantiate a VarCharConsumer. - */ + /** Instantiate a VarCharConsumer. */ public NullableVarCharConsumer(VarCharVector vector, int index) { super(vector, index); } @@ -63,14 +57,10 @@ public void consume(ResultSet resultSet) throws SQLException { } } - /** - * Non-nullable consumer for var char. - */ + /** Non-nullable consumer for var char. */ static class NonNullableVarCharConsumer extends BaseConsumer { - /** - * Instantiate a VarCharConsumer. - */ + /** Instantiate a VarCharConsumer. */ public NonNullableVarCharConsumer(VarCharVector vector, int index) { super(vector, index); } diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/exceptions/JdbcConsumerException.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/exceptions/JdbcConsumerException.java index b235be173cf..52b9a278b1f 100644 --- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/exceptions/JdbcConsumerException.java +++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/exceptions/JdbcConsumerException.java @@ -21,8 +21,8 @@ import org.apache.arrow.vector.types.pojo.ArrowType; /** - * Exception while consuming JDBC data. This exception stores the JdbcFieldInfo for the column and the - * ArrowType for the corresponding vector for easier debugging. + * Exception while consuming JDBC data. This exception stores the JdbcFieldInfo for the column and + * the ArrowType for the corresponding vector for easier debugging. */ public class JdbcConsumerException extends RuntimeException { final JdbcFieldInfo fieldInfo; @@ -31,12 +31,13 @@ public class JdbcConsumerException extends RuntimeException { /** * Construct JdbcConsumerException with all fields. * - * @param message error message - * @param cause original exception + * @param message error message + * @param cause original exception * @param fieldInfo JdbcFieldInfo for the column * @param arrowType ArrowType for the corresponding vector */ - public JdbcConsumerException(String message, Throwable cause, JdbcFieldInfo fieldInfo, ArrowType arrowType) { + public JdbcConsumerException( + String message, Throwable cause, JdbcFieldInfo fieldInfo, ArrowType arrowType) { super(message, cause); this.fieldInfo = fieldInfo; this.arrowType = arrowType; diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java index 88a66a31aa2..8811844bed9 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java @@ -17,6 +17,8 @@ package org.apache.arrow.adapter.jdbc; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; @@ -30,7 +32,6 @@ import java.util.Map; import java.util.TimeZone; import java.util.function.Function; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.util.Preconditions; @@ -41,12 +42,7 @@ import org.junit.Before; import org.junit.Test; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; - -/** - * Class to abstract out some common test functionality for testing JDBC to Arrow. - */ +/** Class to abstract out some common test functionality for testing JDBC to Arrow. */ public abstract class AbstractJdbcToArrowTest { protected static final String BIGINT = "BIGINT_FIELD5"; @@ -69,7 +65,8 @@ public abstract class AbstractJdbcToArrowTest { protected static final String TINYINT = "TINYINT_FIELD3"; protected static final String VARCHAR = "VARCHAR_FIELD13"; protected static final String NULL = "NULL_FIELD18"; - protected static final Map ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP = new HashMap<>(); + protected static final Map ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP = + new HashMap<>(); static { ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP.put(LIST, new JdbcFieldInfo(Types.INTEGER)); @@ -86,12 +83,12 @@ public abstract class AbstractJdbcToArrowTest { * @return Table object * @throws IOException on error */ - protected static Table getTable(String ymlFilePath, @SuppressWarnings("rawtypes") Class clss) throws IOException { - return new ObjectMapper(new YAMLFactory()).readValue( - clss.getClassLoader().getResourceAsStream(ymlFilePath), Table.class); + protected static Table getTable(String ymlFilePath, @SuppressWarnings("rawtypes") Class clss) + throws IOException { + return new ObjectMapper(new YAMLFactory()) + .readValue(clss.getClassLoader().getResourceAsStream(ymlFilePath), Table.class); } - /** * This method creates Connection object and DB table and also populate data into table for test. * @@ -105,7 +102,7 @@ public void setUp() throws SQLException, ClassNotFoundException { String driver = "org.h2.Driver"; Class.forName(driver); conn = DriverManager.getConnection(url); - try (Statement stmt = conn.createStatement();) { + try (Statement stmt = conn.createStatement(); ) { stmt.executeUpdate(table.getCreate()); for (String insert : table.getData()) { stmt.executeUpdate(insert); @@ -136,12 +133,13 @@ public void destroy() throws SQLException { * @throws ClassNotFoundException on error * @throws IOException on error */ - public static Object[][] prepareTestData(String[] testFiles, @SuppressWarnings("rawtypes") Class clss) + public static Object[][] prepareTestData( + String[] testFiles, @SuppressWarnings("rawtypes") Class clss) throws SQLException, ClassNotFoundException, IOException { Object[][] tableArr = new Object[testFiles.length][]; int i = 0; for (String testFile : testFiles) { - tableArr[i++] = new Object[]{getTable(testFile, clss)}; + tableArr[i++] = new Object[] {getTable(testFile, clss)}; } return tableArr; } @@ -159,86 +157,90 @@ public static Object[][] prepareTestData(String[] testFiles, @SuppressWarnings(" * Abstract method to implement logic to assert test various datatype values. * * @param root VectorSchemaRoot for test - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ public abstract void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector); /** - * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow objects. - * This method uses the default Calendar instance with default TimeZone and Locale as returned by the JVM. - * If you wish to use specific TimeZone or Locale for any Date, Time and Timestamp datasets, you may want use - * overloaded API that taken Calendar object instance. + * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow + * objects. This method uses the default Calendar instance with default TimeZone and Locale as + * returned by the JVM. If you wish to use specific TimeZone or Locale for any Date, Time and + * Timestamp datasets, you may want use overloaded API that taken Calendar object instance. * - * This method is for test only. + *

This method is for test only. * - * @param connection Database connection to be used. This method will not close the passed connection object. Since - * the caller has passed the connection object it's the responsibility of the caller to close or - * return the connection to the pool. - * @param query The DB Query to fetch the data. - * @param allocator Memory allocator + * @param connection Database connection to be used. This method will not close the passed + * connection object. Since the caller has passed the connection object it's the + * responsibility of the caller to close or return the connection to the pool. + * @param query The DB Query to fetch the data. + * @param allocator Memory allocator * @return Arrow Data Objects {@link VectorSchemaRoot} - * @throws SQLException Propagate any SQL Exceptions to the caller after closing any resources opened such as - * ResultSet and Statement objects. + * @throws SQLException Propagate any SQL Exceptions to the caller after closing any resources + * opened such as ResultSet and Statement objects. */ public VectorSchemaRoot sqlToArrow(Connection connection, String query, BufferAllocator allocator) throws SQLException, IOException { Preconditions.checkNotNull(allocator, "Memory allocator object cannot be null"); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(allocator, JdbcToArrowUtils.getUtcCalendar()) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(allocator, JdbcToArrowUtils.getUtcCalendar()) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); return sqlToArrow(connection, query, config); } /** - * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow objects. + * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow + * objects. * - * This method is for test only. + *

This method is for test only. * - * @param connection Database connection to be used. This method will not close the passed connection object. Since - * the caller has passed the connection object it's the responsibility of the caller to close or - * return the connection to the pool. - * @param query The DB Query to fetch the data. - * @param allocator Memory allocator - * @param calendar Calendar object to use to handle Date, Time and Timestamp datasets. + * @param connection Database connection to be used. This method will not close the passed + * connection object. Since the caller has passed the connection object it's the + * responsibility of the caller to close or return the connection to the pool. + * @param query The DB Query to fetch the data. + * @param allocator Memory allocator + * @param calendar Calendar object to use to handle Date, Time and Timestamp datasets. * @return Arrow Data Objects {@link VectorSchemaRoot} - * @throws SQLException Propagate any SQL Exceptions to the caller after closing any resources opened such as - * ResultSet and Statement objects. + * @throws SQLException Propagate any SQL Exceptions to the caller after closing any resources + * opened such as ResultSet and Statement objects. */ public VectorSchemaRoot sqlToArrow( - Connection connection, - String query, - BufferAllocator allocator, - Calendar calendar) throws SQLException, IOException { + Connection connection, String query, BufferAllocator allocator, Calendar calendar) + throws SQLException, IOException { Preconditions.checkNotNull(allocator, "Memory allocator object cannot be null"); Preconditions.checkNotNull(calendar, "Calendar object cannot be null"); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(allocator, calendar) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(allocator, calendar) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); return sqlToArrow(connection, query, config); } /** - * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow objects. + * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow + * objects. * - * This method is for test only. + *

This method is for test only. * - * @param connection Database connection to be used. This method will not close the passed connection object. - * Since the caller has passed the connection object it's the responsibility of the caller - * to close or return the connection to the pool. - * @param query The DB Query to fetch the data. - * @param config Configuration + * @param connection Database connection to be used. This method will not close the passed + * connection object. Since the caller has passed the connection object it's the + * responsibility of the caller to close or return the connection to the pool. + * @param query The DB Query to fetch the data. + * @param config Configuration * @return Arrow Data Objects {@link VectorSchemaRoot} - * @throws SQLException Propagate any SQL Exceptions to the caller after closing any resources opened such as - * ResultSet and Statement objects. + * @throws SQLException Propagate any SQL Exceptions to the caller after closing any resources + * opened such as ResultSet and Statement objects. */ - public static VectorSchemaRoot sqlToArrow(Connection connection, String query, JdbcToArrowConfig config) + public static VectorSchemaRoot sqlToArrow( + Connection connection, String query, JdbcToArrowConfig config) throws SQLException, IOException { Preconditions.checkNotNull(connection, "JDBC connection object cannot be null"); - Preconditions.checkArgument(query != null && query.length() > 0, "SQL query cannot be null or empty"); + Preconditions.checkArgument( + query != null && query.length() > 0, "SQL query cannot be null or empty"); try (Statement stmt = connection.createStatement()) { return sqlToArrow(stmt.executeQuery(query), config); @@ -246,10 +248,10 @@ public static VectorSchemaRoot sqlToArrow(Connection connection, String query, J } /** - * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects. This - * method uses the default RootAllocator and Calendar object. + * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow + * objects. This method uses the default RootAllocator and Calendar object. * - * This method is for test only. + *

This method is for test only. * * @param resultSet ResultSet to use to fetch the data from underlying database * @return Arrow Data Objects {@link VectorSchemaRoot} @@ -262,9 +264,10 @@ public static VectorSchemaRoot sqlToArrow(ResultSet resultSet) throws SQLExcepti } /** - * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects. + * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow + * objects. * - * This method is for test only. + *

This method is for test only. * * @param resultSet ResultSet to use to fetch the data from underlying database * @param allocator Memory allocator @@ -275,62 +278,69 @@ public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, BufferAllocator a throws SQLException, IOException { Preconditions.checkNotNull(allocator, "Memory Allocator object cannot be null"); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(allocator, JdbcToArrowUtils.getUtcCalendar()) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(allocator, JdbcToArrowUtils.getUtcCalendar()) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); return sqlToArrow(resultSet, config); } /** - * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects. + * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow + * objects. * - * This method is for test only. + *

This method is for test only. * * @param resultSet ResultSet to use to fetch the data from underlying database - * @param calendar Calendar instance to use for Date, Time and Timestamp datasets, or null if none. + * @param calendar Calendar instance to use for Date, Time and Timestamp datasets, or null + * if none. * @return Arrow Data Objects {@link VectorSchemaRoot} * @throws SQLException on error */ - public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, Calendar calendar) throws SQLException, IOException { + public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, Calendar calendar) + throws SQLException, IOException { Preconditions.checkNotNull(resultSet, "JDBC ResultSet object cannot be null"); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), calendar) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), calendar) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); return sqlToArrow(resultSet, config); } /** - * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects. + * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow + * objects. * - * This method is for test only. + *

This method is for test only. * * @param resultSet ResultSet to use to fetch the data from underlying database * @param allocator Memory allocator to use. - * @param calendar Calendar instance to use for Date, Time and Timestamp datasets, or null if none. + * @param calendar Calendar instance to use for Date, Time and Timestamp datasets, or null + * if none. * @return Arrow Data Objects {@link VectorSchemaRoot} * @throws SQLException on error */ public static VectorSchemaRoot sqlToArrow( - ResultSet resultSet, - BufferAllocator allocator, - Calendar calendar) + ResultSet resultSet, BufferAllocator allocator, Calendar calendar) throws SQLException, IOException { Preconditions.checkNotNull(allocator, "Memory Allocator object cannot be null"); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(allocator, calendar) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(allocator, calendar) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); return sqlToArrow(resultSet, config); } /** - * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects. + * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow + * objects. * - * This method is for test only. + *

This method is for test only. * * @param resultSet ResultSet to use to fetch the data from underlying database - * @param config Configuration of the conversion from JDBC to Arrow. + * @param config Configuration of the conversion from JDBC to Arrow. * @return Arrow Data Objects {@link VectorSchemaRoot} * @throws SQLException on error */ @@ -339,8 +349,10 @@ public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, JdbcToArrowConfig Preconditions.checkNotNull(resultSet, "JDBC ResultSet object cannot be null"); Preconditions.checkNotNull(config, "The configuration cannot be null"); - VectorSchemaRoot root = VectorSchemaRoot.create( - JdbcToArrowUtils.jdbcToArrowSchema(resultSet.getMetaData(), config), config.getAllocator()); + VectorSchemaRoot root = + VectorSchemaRoot.create( + JdbcToArrowUtils.jdbcToArrowSchema(resultSet.getMetaData(), config), + config.getAllocator()); if (config.getTargetBatchSize() != JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE) { ValueVectorUtility.preAllocate(root, config.getTargetBatchSize()); } @@ -350,12 +362,14 @@ public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, JdbcToArrowConfig /** * Register MAP_FIELD20 as ArrowType.Map - * @param calendar Calendar instance to use for Date, Time and Timestamp datasets, or null if none. + * + * @param calendar Calendar instance to use for Date, Time and Timestamp datasets, or null + * if none. * @param rsmd ResultSetMetaData to lookup column name from result set metadata * @return typeConverter instance with mapping column to Map type */ protected Function jdbcToArrowTypeConverter( - Calendar calendar, ResultSetMetaData rsmd) { + Calendar calendar, ResultSetMetaData rsmd) { return (jdbcFieldInfo) -> { String columnLabel = null; try { @@ -377,5 +391,4 @@ protected Function jdbcToArrowTypeConverter( protected ResultSetMetaData getQueryMetaData(String query) throws SQLException { return conn.createStatement().executeQuery(query).getMetaData(); } - } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfoTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfoTest.java index b1a8b8f2267..a5f8a5ccb78 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfoTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcFieldInfoTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.*; import java.sql.Types; - import org.junit.Test; public class JdbcFieldInfoTest { diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinderTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinderTest.java index 15b9ab03861..f1de99e28ac 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinderTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinderTest.java @@ -32,7 +32,6 @@ import java.util.List; import java.util.Map; import java.util.function.BiConsumer; - import org.apache.arrow.adapter.jdbc.binder.ColumnBinder; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; @@ -106,11 +105,11 @@ void bindOrder() throws SQLException { Field.nullable("ints1", new ArrowType.Int(32, true)), Field.nullable("ints2", new ArrowType.Int(32, true)))); try (final MockPreparedStatement statement = new MockPreparedStatement(); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final JdbcParameterBinder binder = JdbcParameterBinder.builder(statement, root) - .bind(/*paramIndex=*/ 1, /*colIndex=*/ 2) - .bind(/*paramIndex=*/ 2, /*colIndex=*/ 0) + .bind(/* paramIndex= */ 1, /* colIndex= */ 2) + .bind(/* paramIndex= */ 2, /* colIndex= */ 0) .build(); assertThat(binder.next()).isFalse(); @@ -161,17 +160,17 @@ void bindOrder() throws SQLException { @Test void customBinder() throws SQLException { final Schema schema = - new Schema(Collections.singletonList( - Field.nullable("ints0", new ArrowType.Int(32, true)))); + new Schema(Collections.singletonList(Field.nullable("ints0", new ArrowType.Int(32, true)))); try (final MockPreparedStatement statement = new MockPreparedStatement(); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final JdbcParameterBinder binder = JdbcParameterBinder.builder(statement, root) .bind( - /*paramIndex=*/ 1, + /* paramIndex= */ 1, new ColumnBinder() { private final IntVector vector = (IntVector) root.getVector(0); + @Override public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { @@ -212,7 +211,9 @@ public FieldVector getVector() { @Test void bool() throws SQLException { - testSimpleType(ArrowType.Bool.INSTANCE, Types.BOOLEAN, + testSimpleType( + ArrowType.Bool.INSTANCE, + Types.BOOLEAN, (BitVector vector, Integer index, Boolean value) -> vector.setSafe(index, value ? 1 : 0), BitVector::setNull, Arrays.asList(true, false, true)); @@ -220,53 +221,76 @@ void bool() throws SQLException { @Test void int8() throws SQLException { - testSimpleType(new ArrowType.Int(8, true), Types.TINYINT, - TinyIntVector::setSafe, TinyIntVector::setNull, + testSimpleType( + new ArrowType.Int(8, true), + Types.TINYINT, + TinyIntVector::setSafe, + TinyIntVector::setNull, Arrays.asList(Byte.MAX_VALUE, Byte.MIN_VALUE, (byte) 42)); } @Test void int16() throws SQLException { - testSimpleType(new ArrowType.Int(16, true), Types.SMALLINT, - SmallIntVector::setSafe, SmallIntVector::setNull, + testSimpleType( + new ArrowType.Int(16, true), + Types.SMALLINT, + SmallIntVector::setSafe, + SmallIntVector::setNull, Arrays.asList(Short.MAX_VALUE, Short.MIN_VALUE, (short) 42)); } @Test void int32() throws SQLException { - testSimpleType(new ArrowType.Int(32, true), Types.INTEGER, - IntVector::setSafe, IntVector::setNull, + testSimpleType( + new ArrowType.Int(32, true), + Types.INTEGER, + IntVector::setSafe, + IntVector::setNull, Arrays.asList(Integer.MAX_VALUE, Integer.MIN_VALUE, 42)); } @Test void int64() throws SQLException { - testSimpleType(new ArrowType.Int(64, true), Types.BIGINT, - BigIntVector::setSafe, BigIntVector::setNull, + testSimpleType( + new ArrowType.Int(64, true), + Types.BIGINT, + BigIntVector::setSafe, + BigIntVector::setNull, Arrays.asList(Long.MAX_VALUE, Long.MIN_VALUE, 42L)); } @Test void float32() throws SQLException { - testSimpleType(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), Types.REAL, - Float4Vector::setSafe, Float4Vector::setNull, + testSimpleType( + new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), + Types.REAL, + Float4Vector::setSafe, + Float4Vector::setNull, Arrays.asList(Float.MIN_VALUE, Float.MAX_VALUE, Float.POSITIVE_INFINITY)); } @Test void float64() throws SQLException { - testSimpleType(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), Types.DOUBLE, - Float8Vector::setSafe, Float8Vector::setNull, + testSimpleType( + new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), + Types.DOUBLE, + Float8Vector::setSafe, + Float8Vector::setNull, Arrays.asList(Double.MIN_VALUE, Double.MAX_VALUE, Double.POSITIVE_INFINITY)); } @Test void time32() throws SQLException { - testSimpleType(new ArrowType.Time(TimeUnit.SECOND, 32), Types.TIME, - (valueVectors, index, value) -> valueVectors.setSafe(index, (int) (value.getTime() / 1_000)), + testSimpleType( + new ArrowType.Time(TimeUnit.SECOND, 32), + Types.TIME, + (valueVectors, index, value) -> + valueVectors.setSafe(index, (int) (value.getTime() / 1_000)), TimeSecVector::setNull, Arrays.asList(new Time(-128_000), new Time(104_000), new Time(-42_000))); - testSimpleType(new ArrowType.Time(TimeUnit.MILLISECOND, 32), Types.TIME, + testSimpleType( + new ArrowType.Time(TimeUnit.MILLISECOND, 32), + Types.TIME, (valueVectors, index, value) -> valueVectors.setSafe(index, (int) value.getTime()), TimeMilliVector::setNull, Arrays.asList(new Time(-128_000), new Time(104_000), new Time(-42_000))); @@ -274,69 +298,110 @@ void time32() throws SQLException { @Test void time64() throws SQLException { - testSimpleType(new ArrowType.Time(TimeUnit.MICROSECOND, 64), Types.TIME, - (valueVectors, index, value) -> valueVectors.setSafe(index, (int) (value.getTime() * 1_000)), + testSimpleType( + new ArrowType.Time(TimeUnit.MICROSECOND, 64), + Types.TIME, + (valueVectors, index, value) -> + valueVectors.setSafe(index, (int) (value.getTime() * 1_000)), TimeMicroVector::setNull, Arrays.asList(new Time(-128_000), new Time(104_000), new Time(-42_000))); - testSimpleType(new ArrowType.Time(TimeUnit.NANOSECOND, 64), Types.TIME, - (valueVectors, index, value) -> valueVectors.setSafe(index, (int) (value.getTime() * 1_000_000)), + testSimpleType( + new ArrowType.Time(TimeUnit.NANOSECOND, 64), + Types.TIME, + (valueVectors, index, value) -> + valueVectors.setSafe(index, (int) (value.getTime() * 1_000_000)), TimeNanoVector::setNull, Arrays.asList(new Time(-128), new Time(104), new Time(-42))); } @Test void date32() throws SQLException { - testSimpleType(new ArrowType.Date(DateUnit.DAY), Types.DATE, - (valueVectors, index, value) -> valueVectors.setSafe(index, (int) (value.getTime() / MILLIS_PER_DAY)), + testSimpleType( + new ArrowType.Date(DateUnit.DAY), + Types.DATE, + (valueVectors, index, value) -> + valueVectors.setSafe(index, (int) (value.getTime() / MILLIS_PER_DAY)), DateDayVector::setNull, - Arrays.asList(new Date(-5 * MILLIS_PER_DAY), new Date(2 * MILLIS_PER_DAY), new Date(MILLIS_PER_DAY))); + Arrays.asList( + new Date(-5 * MILLIS_PER_DAY), new Date(2 * MILLIS_PER_DAY), new Date(MILLIS_PER_DAY))); } @Test void date64() throws SQLException { - testSimpleType(new ArrowType.Date(DateUnit.MILLISECOND), Types.DATE, + testSimpleType( + new ArrowType.Date(DateUnit.MILLISECOND), + Types.DATE, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime()), DateMilliVector::setNull, - Arrays.asList(new Date(-5 * MILLIS_PER_DAY), new Date(2 * MILLIS_PER_DAY), new Date(MILLIS_PER_DAY))); + Arrays.asList( + new Date(-5 * MILLIS_PER_DAY), new Date(2 * MILLIS_PER_DAY), new Date(MILLIS_PER_DAY))); } @Test void timestamp() throws SQLException { - List values = Arrays.asList(new Timestamp(-128_000), new Timestamp(104_000), new Timestamp(-42_000)); - testSimpleType(new ArrowType.Timestamp(TimeUnit.SECOND, null), Types.TIMESTAMP, + List values = + Arrays.asList(new Timestamp(-128_000), new Timestamp(104_000), new Timestamp(-42_000)); + testSimpleType( + new ArrowType.Timestamp(TimeUnit.SECOND, null), + Types.TIMESTAMP, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime() / 1_000), - TimeStampSecVector::setNull, values); - testSimpleType(new ArrowType.Timestamp(TimeUnit.MILLISECOND, null), Types.TIMESTAMP, + TimeStampSecVector::setNull, + values); + testSimpleType( + new ArrowType.Timestamp(TimeUnit.MILLISECOND, null), + Types.TIMESTAMP, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime()), - TimeStampMilliVector::setNull, values); - testSimpleType(new ArrowType.Timestamp(TimeUnit.MICROSECOND, null), Types.TIMESTAMP, + TimeStampMilliVector::setNull, + values); + testSimpleType( + new ArrowType.Timestamp(TimeUnit.MICROSECOND, null), + Types.TIMESTAMP, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime() * 1_000), - TimeStampMicroVector::setNull, values); - testSimpleType(new ArrowType.Timestamp(TimeUnit.NANOSECOND, null), Types.TIMESTAMP, + TimeStampMicroVector::setNull, + values); + testSimpleType( + new ArrowType.Timestamp(TimeUnit.NANOSECOND, null), + Types.TIMESTAMP, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime() * 1_000_000), - TimeStampNanoVector::setNull, values); + TimeStampNanoVector::setNull, + values); } @Test void timestampTz() throws SQLException { - List values = Arrays.asList(new Timestamp(-128_000), new Timestamp(104_000), new Timestamp(-42_000)); - testSimpleType(new ArrowType.Timestamp(TimeUnit.SECOND, "UTC"), Types.TIMESTAMP_WITH_TIMEZONE, + List values = + Arrays.asList(new Timestamp(-128_000), new Timestamp(104_000), new Timestamp(-42_000)); + testSimpleType( + new ArrowType.Timestamp(TimeUnit.SECOND, "UTC"), + Types.TIMESTAMP_WITH_TIMEZONE, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime() / 1_000), - TimeStampSecTZVector::setNull, values); - testSimpleType(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC"), Types.TIMESTAMP_WITH_TIMEZONE, + TimeStampSecTZVector::setNull, + values); + testSimpleType( + new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC"), + Types.TIMESTAMP_WITH_TIMEZONE, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime()), - TimeStampMilliTZVector::setNull, values); - testSimpleType(new ArrowType.Timestamp(TimeUnit.MICROSECOND, "UTC"), Types.TIMESTAMP_WITH_TIMEZONE, + TimeStampMilliTZVector::setNull, + values); + testSimpleType( + new ArrowType.Timestamp(TimeUnit.MICROSECOND, "UTC"), + Types.TIMESTAMP_WITH_TIMEZONE, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime() * 1_000), - TimeStampMicroTZVector::setNull, values); - testSimpleType(new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC"), Types.TIMESTAMP_WITH_TIMEZONE, + TimeStampMicroTZVector::setNull, + values); + testSimpleType( + new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC"), + Types.TIMESTAMP_WITH_TIMEZONE, (valueVectors, index, value) -> valueVectors.setSafe(index, value.getTime() * 1_000_000), - TimeStampNanoTZVector::setNull, values); + TimeStampNanoTZVector::setNull, + values); } @Test void utf8() throws SQLException { - testSimpleType(ArrowType.Utf8.INSTANCE, Types.VARCHAR, + testSimpleType( + ArrowType.Utf8.INSTANCE, + Types.VARCHAR, (VarCharVector vector, Integer index, String value) -> vector.setSafe(index, value.getBytes(StandardCharsets.UTF_8)), BaseVariableWidthVector::setNull, @@ -345,7 +410,9 @@ void utf8() throws SQLException { @Test void largeUtf8() throws SQLException { - testSimpleType(ArrowType.LargeUtf8.INSTANCE, Types.LONGVARCHAR, + testSimpleType( + ArrowType.LargeUtf8.INSTANCE, + Types.LONGVARCHAR, (LargeVarCharVector vector, Integer index, String value) -> vector.setSafe(index, value.getBytes(StandardCharsets.UTF_8)), BaseLargeVariableWidthVector::setNull, @@ -354,155 +421,200 @@ void largeUtf8() throws SQLException { @Test void binary() throws SQLException { - testSimpleType(ArrowType.Binary.INSTANCE, Types.VARBINARY, - (VarBinaryVector vector, Integer index, byte[] value) -> - vector.setSafe(index, value), + testSimpleType( + ArrowType.Binary.INSTANCE, + Types.VARBINARY, + (VarBinaryVector vector, Integer index, byte[] value) -> vector.setSafe(index, value), BaseVariableWidthVector::setNull, Arrays.asList(new byte[0], new byte[] {2, -4}, new byte[] {0, -1, 127, -128})); } @Test void largeBinary() throws SQLException { - testSimpleType(ArrowType.LargeBinary.INSTANCE, Types.LONGVARBINARY, - (LargeVarBinaryVector vector, Integer index, byte[] value) -> - vector.setSafe(index, value), + testSimpleType( + ArrowType.LargeBinary.INSTANCE, + Types.LONGVARBINARY, + (LargeVarBinaryVector vector, Integer index, byte[] value) -> vector.setSafe(index, value), BaseLargeVariableWidthVector::setNull, Arrays.asList(new byte[0], new byte[] {2, -4}, new byte[] {0, -1, 127, -128})); } @Test void fixedSizeBinary() throws SQLException { - testSimpleType(new ArrowType.FixedSizeBinary(3), Types.BINARY, - FixedSizeBinaryVector::setSafe, FixedSizeBinaryVector::setNull, + testSimpleType( + new ArrowType.FixedSizeBinary(3), + Types.BINARY, + FixedSizeBinaryVector::setSafe, + FixedSizeBinaryVector::setNull, Arrays.asList(new byte[3], new byte[] {1, 2, -4}, new byte[] {-1, 127, -128})); } @Test void decimal128() throws SQLException { - testSimpleType(new ArrowType.Decimal(/*precision*/ 12, /*scale*/3, 128), Types.DECIMAL, - DecimalVector::setSafe, DecimalVector::setNull, - Arrays.asList(new BigDecimal("120.429"), new BigDecimal("-10590.123"), new BigDecimal("0.000"))); + testSimpleType( + new ArrowType.Decimal(/*precision*/ 12, /*scale*/ 3, 128), + Types.DECIMAL, + DecimalVector::setSafe, + DecimalVector::setNull, + Arrays.asList( + new BigDecimal("120.429"), new BigDecimal("-10590.123"), new BigDecimal("0.000"))); } @Test void decimal256() throws SQLException { - testSimpleType(new ArrowType.Decimal(/*precision*/ 12, /*scale*/3, 256), Types.DECIMAL, - Decimal256Vector::setSafe, Decimal256Vector::setNull, - Arrays.asList(new BigDecimal("120.429"), new BigDecimal("-10590.123"), new BigDecimal("0.000"))); + testSimpleType( + new ArrowType.Decimal(/*precision*/ 12, /*scale*/ 3, 256), + Types.DECIMAL, + Decimal256Vector::setSafe, + Decimal256Vector::setNull, + Arrays.asList( + new BigDecimal("120.429"), new BigDecimal("-10590.123"), new BigDecimal("0.000"))); } @Test void listOfDouble() throws SQLException { - TriConsumer setValue = (listVector, index, values) -> { - org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); - writer.setPosition(index); - writer.startList(); - Arrays.stream(values).forEach(doubleValue -> writer.float8().writeFloat8(doubleValue)); - writer.endList(); - listVector.setLastSet(index); - }; - List values = Arrays.asList(new Double[]{0.0, Math.PI}, new Double[]{1.1, -352346.2, 2355.6}, - new Double[]{-1024.3}, new Double[]{}); - testListType(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), setValue, ListVector::setNull, values); + TriConsumer setValue = + (listVector, index, values) -> { + org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); + writer.setPosition(index); + writer.startList(); + Arrays.stream(values).forEach(doubleValue -> writer.float8().writeFloat8(doubleValue)); + writer.endList(); + listVector.setLastSet(index); + }; + List values = + Arrays.asList( + new Double[] {0.0, Math.PI}, new Double[] {1.1, -352346.2, 2355.6}, + new Double[] {-1024.3}, new Double[] {}); + testListType( + new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), + setValue, + ListVector::setNull, + values); } @Test void listOfInt64() throws SQLException { - TriConsumer setValue = (listVector, index, values) -> { - org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); - writer.setPosition(index); - writer.startList(); - Arrays.stream(values).forEach(longValue -> writer.bigInt().writeBigInt(longValue)); - writer.endList(); - listVector.setLastSet(index); - }; - List values = Arrays.asList(new Long[]{1L, 2L, 3L}, new Long[]{4L, 5L}, - new Long[]{512L, 1024L, 2048L, 4096L}, new Long[]{}); + TriConsumer setValue = + (listVector, index, values) -> { + org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); + writer.setPosition(index); + writer.startList(); + Arrays.stream(values).forEach(longValue -> writer.bigInt().writeBigInt(longValue)); + writer.endList(); + listVector.setLastSet(index); + }; + List values = + Arrays.asList( + new Long[] {1L, 2L, 3L}, + new Long[] {4L, 5L}, + new Long[] {512L, 1024L, 2048L, 4096L}, + new Long[] {}); testListType((ArrowType) new ArrowType.Int(64, true), setValue, ListVector::setNull, values); } @Test void listOfInt32() throws SQLException { - TriConsumer setValue = (listVector, index, values) -> { - org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); - writer.setPosition(index); - writer.startList(); - Arrays.stream(values).forEach(integerValue -> writer.integer().writeInt(integerValue)); - writer.endList(); - listVector.setLastSet(index); - }; - List values = Arrays.asList(new Integer[]{1, 2, 3}, new Integer[]{4, 5}, - new Integer[]{512, 1024, 2048, 4096}, new Integer[]{}); + TriConsumer setValue = + (listVector, index, values) -> { + org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); + writer.setPosition(index); + writer.startList(); + Arrays.stream(values).forEach(integerValue -> writer.integer().writeInt(integerValue)); + writer.endList(); + listVector.setLastSet(index); + }; + List values = + Arrays.asList( + new Integer[] {1, 2, 3}, + new Integer[] {4, 5}, + new Integer[] {512, 1024, 2048, 4096}, + new Integer[] {}); testListType((ArrowType) new ArrowType.Int(32, true), setValue, ListVector::setNull, values); } @Test void listOfBoolean() throws SQLException { - TriConsumer setValue = (listVector, index, values) -> { - org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); - writer.setPosition(index); - writer.startList(); - Arrays.stream(values).forEach(booleanValue -> writer.bit().writeBit(booleanValue ? 1 : 0)); - writer.endList(); - listVector.setLastSet(index); - }; - List values = Arrays.asList(new Boolean[]{true, false}, - new Boolean[]{false, false}, new Boolean[]{true, true, false, true}, new Boolean[]{}); + TriConsumer setValue = + (listVector, index, values) -> { + org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); + writer.setPosition(index); + writer.startList(); + Arrays.stream(values) + .forEach(booleanValue -> writer.bit().writeBit(booleanValue ? 1 : 0)); + writer.endList(); + listVector.setLastSet(index); + }; + List values = + Arrays.asList( + new Boolean[] {true, false}, + new Boolean[] {false, false}, + new Boolean[] {true, true, false, true}, + new Boolean[] {}); testListType((ArrowType) new ArrowType.Bool(), setValue, ListVector::setNull, values); } @Test void listOfString() throws SQLException { - TriConsumer setValue = (listVector, index, values) -> { - org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); - writer.setPosition(index); - writer.startList(); - Arrays.stream(values).forEach(stringValue -> { - if (stringValue != null) { - byte[] stringValueBytes = stringValue.getBytes(StandardCharsets.UTF_8); - try (ArrowBuf stringBuffer = allocator.buffer(stringValueBytes.length)) { - stringBuffer.writeBytes(stringValueBytes); - writer.varChar().writeVarChar(0, stringValueBytes.length, stringBuffer); - } - } else { - writer.varChar().writeNull(); - } - }); - writer.endList(); - listVector.setLastSet(index); - }; - List values = Arrays.asList(new String[]{"aaaa", "b1"}, - new String[]{"c", null, "d"}, new String[]{"e", "f", "g", "h"}, new String[]{}); + TriConsumer setValue = + (listVector, index, values) -> { + org.apache.arrow.vector.complex.impl.UnionListWriter writer = listVector.getWriter(); + writer.setPosition(index); + writer.startList(); + Arrays.stream(values) + .forEach( + stringValue -> { + if (stringValue != null) { + byte[] stringValueBytes = stringValue.getBytes(StandardCharsets.UTF_8); + try (ArrowBuf stringBuffer = allocator.buffer(stringValueBytes.length)) { + stringBuffer.writeBytes(stringValueBytes); + writer.varChar().writeVarChar(0, stringValueBytes.length, stringBuffer); + } + } else { + writer.varChar().writeNull(); + } + }); + writer.endList(); + listVector.setLastSet(index); + }; + List values = + Arrays.asList( + new String[] {"aaaa", "b1"}, + new String[] {"c", null, "d"}, + new String[] {"e", "f", "g", "h"}, + new String[] {}); testListType((ArrowType) new ArrowType.Utf8(), setValue, ListVector::setNull, values); } @Test void mapOfString() throws SQLException { - TriConsumer> setValue = (mapVector, index, values) -> { - org.apache.arrow.vector.complex.impl.UnionMapWriter mapWriter = mapVector.getWriter(); - mapWriter.setPosition(index); - mapWriter.startMap(); - values.entrySet().forEach(mapValue -> { - if (mapValue != null) { - byte[] keyBytes = mapValue.getKey().getBytes(StandardCharsets.UTF_8); - byte[] valueBytes = mapValue.getValue().getBytes(StandardCharsets.UTF_8); - try ( - ArrowBuf keyBuf = allocator.buffer(keyBytes.length); - ArrowBuf valueBuf = allocator.buffer(valueBytes.length); - ) { - mapWriter.startEntry(); - keyBuf.writeBytes(keyBytes); - valueBuf.writeBytes(valueBytes); - mapWriter.key().varChar().writeVarChar(0, keyBytes.length, keyBuf); - mapWriter.value().varChar().writeVarChar(0, valueBytes.length, valueBuf); - mapWriter.endEntry(); - } - } else { - mapWriter.writeNull(); - } - }); - mapWriter.endMap(); - }; + TriConsumer> setValue = + (mapVector, index, values) -> { + org.apache.arrow.vector.complex.impl.UnionMapWriter mapWriter = mapVector.getWriter(); + mapWriter.setPosition(index); + mapWriter.startMap(); + values + .entrySet() + .forEach( + mapValue -> { + if (mapValue != null) { + byte[] keyBytes = mapValue.getKey().getBytes(StandardCharsets.UTF_8); + byte[] valueBytes = mapValue.getValue().getBytes(StandardCharsets.UTF_8); + try (ArrowBuf keyBuf = allocator.buffer(keyBytes.length); + ArrowBuf valueBuf = allocator.buffer(valueBytes.length); ) { + mapWriter.startEntry(); + keyBuf.writeBytes(keyBytes); + valueBuf.writeBytes(valueBytes); + mapWriter.key().varChar().writeVarChar(0, keyBytes.length, keyBuf); + mapWriter.value().varChar().writeVarChar(0, valueBytes.length, valueBuf); + mapWriter.endEntry(); + } + } else { + mapWriter.writeNull(); + } + }); + mapWriter.endMap(); + }; JsonStringHashMap value1 = new JsonStringHashMap(); value1.put("a", "b"); @@ -514,28 +626,34 @@ void mapOfString() throws SQLException { JsonStringHashMap value3 = new JsonStringHashMap(); value3.put("y", "z"); value3.put("arrow", "cool"); - List> values = Arrays.asList(value1, value2, value3, Collections.emptyMap()); - testMapType(new ArrowType.Map(true), setValue, MapVector::setNull, values, new ArrowType.Utf8()); + List> values = + Arrays.asList(value1, value2, value3, Collections.emptyMap()); + testMapType( + new ArrowType.Map(true), setValue, MapVector::setNull, values, new ArrowType.Utf8()); } @Test void mapOfInteger() throws SQLException { - TriConsumer> setValue = (mapVector, index, values) -> { - org.apache.arrow.vector.complex.impl.UnionMapWriter mapWriter = mapVector.getWriter(); - mapWriter.setPosition(index); - mapWriter.startMap(); - values.entrySet().forEach(mapValue -> { - if (mapValue != null) { - mapWriter.startEntry(); - mapWriter.key().integer().writeInt(mapValue.getKey()); - mapWriter.value().integer().writeInt(mapValue.getValue()); - mapWriter.endEntry(); - } else { - mapWriter.writeNull(); - } - }); - mapWriter.endMap(); - }; + TriConsumer> setValue = + (mapVector, index, values) -> { + org.apache.arrow.vector.complex.impl.UnionMapWriter mapWriter = mapVector.getWriter(); + mapWriter.setPosition(index); + mapWriter.startMap(); + values + .entrySet() + .forEach( + mapValue -> { + if (mapValue != null) { + mapWriter.startEntry(); + mapWriter.key().integer().writeInt(mapValue.getKey()); + mapWriter.value().integer().writeInt(mapValue.getValue()); + mapWriter.endEntry(); + } else { + mapWriter.writeNull(); + } + }); + mapWriter.endMap(); + }; JsonStringHashMap value1 = new JsonStringHashMap(); value1.put(1, 2); @@ -547,8 +665,10 @@ void mapOfInteger() throws SQLException { JsonStringHashMap value3 = new JsonStringHashMap(); value3.put(Integer.MIN_VALUE, Integer.MAX_VALUE); value3.put(0, 4096); - List> values = Arrays.asList(value1, value2, value3, Collections.emptyMap()); - testMapType(new ArrowType.Map(true), setValue, MapVector::setNull, values, new ArrowType.Int(32, true)); + List> values = + Arrays.asList(value1, value2, value3, Collections.emptyMap()); + testMapType( + new ArrowType.Map(true), setValue, MapVector::setNull, values, new ArrowType.Int(32, true)); } @FunctionalInterface @@ -556,11 +676,16 @@ interface TriConsumer { void accept(T value1, U value2, V value3); } - void testSimpleType(ArrowType arrowType, int jdbcType, TriConsumer setValue, - BiConsumer setNull, List values) throws SQLException { + void testSimpleType( + ArrowType arrowType, + int jdbcType, + TriConsumer setValue, + BiConsumer setNull, + List values) + throws SQLException { Schema schema = new Schema(Collections.singletonList(Field.nullable("field", arrowType))); try (final MockPreparedStatement statement = new MockPreparedStatement(); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final JdbcParameterBinder binder = JdbcParameterBinder.builder(statement, root).bindAll().build(); assertThat(binder.next()).isFalse(); @@ -610,7 +735,7 @@ void testSimpleType(ArrowType arrowType, int jdbcType // Non-nullable (since some types have a specialized binder) schema = new Schema(Collections.singletonList(Field.notNullable("field", arrowType))); try (final MockPreparedStatement statement = new MockPreparedStatement(); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final JdbcParameterBinder binder = JdbcParameterBinder.builder(statement, root).bindAll().build(); assertThat(binder.next()).isFalse(); @@ -650,15 +775,23 @@ void testSimpleType(ArrowType arrowType, int jdbcType } } - void testListType(ArrowType arrowType, TriConsumer setValue, - BiConsumer setNull, List values) throws SQLException { + void testListType( + ArrowType arrowType, + TriConsumer setValue, + BiConsumer setNull, + List values) + throws SQLException { int jdbcType = Types.ARRAY; - Schema schema = new Schema(Collections.singletonList(new Field("field", FieldType.nullable( - new ArrowType.List()), Collections.singletonList( - new Field("element", FieldType.notNullable(arrowType), null) - )))); + Schema schema = + new Schema( + Collections.singletonList( + new Field( + "field", + FieldType.nullable(new ArrowType.List()), + Collections.singletonList( + new Field("element", FieldType.notNullable(arrowType), null))))); try (final MockPreparedStatement statement = new MockPreparedStatement(); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final JdbcParameterBinder binder = JdbcParameterBinder.builder(statement, root).bindAll().build(); assertThat(binder.next()).isFalse(); @@ -706,12 +839,16 @@ void testListType(ArrowType arrowType, TriConsumer void testListType(ArrowType arrowType, TriConsumer void testMapType(ArrowType arrowType, TriConsumer setValue, - BiConsumer setNull, List values, - ArrowType elementType) throws SQLException { + void testMapType( + ArrowType arrowType, + TriConsumer setValue, + BiConsumer setNull, + List values, + ArrowType elementType) + throws SQLException { int jdbcType = Types.VARCHAR; FieldType keyType = new FieldType(false, elementType, null, null); FieldType mapType = new FieldType(false, ArrowType.Struct.INSTANCE, null, null); - Schema schema = new Schema(Collections.singletonList(new Field("field", FieldType.nullable(arrowType), - Collections.singletonList(new Field(MapVector.KEY_NAME, mapType, - Arrays.asList(new Field(MapVector.KEY_NAME, keyType, null), - new Field(MapVector.VALUE_NAME, keyType, null))))))); + Schema schema = + new Schema( + Collections.singletonList( + new Field( + "field", + FieldType.nullable(arrowType), + Collections.singletonList( + new Field( + MapVector.KEY_NAME, + mapType, + Arrays.asList( + new Field(MapVector.KEY_NAME, keyType, null), + new Field(MapVector.VALUE_NAME, keyType, null))))))); try (final MockPreparedStatement statement = new MockPreparedStatement(); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final JdbcParameterBinder binder = JdbcParameterBinder.builder(statement, root).bindAll().build(); assertThat(binder.next()).isFalse(); @@ -810,18 +960,31 @@ void testMapType(ArrowType arrowType, TriConsumer metadata) { + private static Field field( + String name, boolean nullable, ArrowType type, Map metadata) { return new Field(name, new FieldType(nullable, type, null, metadata), Collections.emptyList()); } @@ -94,16 +96,26 @@ private static Map metadata(String... entries) { public void schemaComment() throws Exception { boolean includeMetadata = false; Schema schema = getSchemaWithCommentFromQuery(includeMetadata); - Schema expectedSchema = new Schema(Arrays.asList( - field("ID", false, Types.MinorType.BIGINT.getType(), - metadata("comment", "Record identifier")), - field("NAME", true, Types.MinorType.VARCHAR.getType(), - metadata("comment", "Name of record")), - field("COLUMN1", true, Types.MinorType.BIT.getType(), - metadata()), - field("COLUMNN", true, Types.MinorType.INT.getType(), - metadata("comment", "Informative description of columnN")) - ), metadata("comment", "This is super special table with valuable data")); + Schema expectedSchema = + new Schema( + Arrays.asList( + field( + "ID", + false, + Types.MinorType.BIGINT.getType(), + metadata("comment", "Record identifier")), + field( + "NAME", + true, + Types.MinorType.VARCHAR.getType(), + metadata("comment", "Name of record")), + field("COLUMN1", true, Types.MinorType.BIT.getType(), metadata()), + field( + "COLUMNN", + true, + Types.MinorType.INT.getType(), + metadata("comment", "Informative description of columnN"))), + metadata("comment", "This is super special table with valuable data")); assertThat(schema).isEqualTo(expectedSchema); } @@ -111,47 +123,60 @@ public void schemaComment() throws Exception { public void schemaCommentWithDatabaseMetadata() throws Exception { boolean includeMetadata = true; Schema schema = getSchemaWithCommentFromQuery(includeMetadata); - Schema expectedSchema = new Schema(Arrays.asList( - field("ID", false, Types.MinorType.BIGINT.getType(), - metadata( - "SQL_CATALOG_NAME", "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8", - "SQL_SCHEMA_NAME", "PUBLIC", - "SQL_TABLE_NAME", "TABLE1", - "SQL_COLUMN_NAME", "ID", - "SQL_TYPE", "BIGINT", - "comment", "Record identifier" - )), - field("NAME", true, Types.MinorType.VARCHAR.getType(), - metadata( - "SQL_CATALOG_NAME", "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8", - "SQL_SCHEMA_NAME", "PUBLIC", - "SQL_TABLE_NAME", "TABLE1", - "SQL_COLUMN_NAME", "NAME", - "SQL_TYPE", "CHARACTER VARYING", - "comment", "Name of record")), - field("COLUMN1", true, Types.MinorType.BIT.getType(), - metadata( - "SQL_CATALOG_NAME", "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8", - "SQL_SCHEMA_NAME", "PUBLIC", - "SQL_TABLE_NAME", "TABLE1", - "SQL_COLUMN_NAME", "COLUMN1", - "SQL_TYPE", "BOOLEAN")), - field("COLUMNN", true, Types.MinorType.INT.getType(), - metadata( - "SQL_CATALOG_NAME", "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8", - "SQL_SCHEMA_NAME", "PUBLIC", - "SQL_TABLE_NAME", "TABLE1", - "SQL_COLUMN_NAME", "COLUMNN", - "SQL_TYPE", "INTEGER", - "comment", "Informative description of columnN")) - ), metadata("comment", "This is super special table with valuable data")); + Schema expectedSchema = + new Schema( + Arrays.asList( + field( + "ID", + false, + Types.MinorType.BIGINT.getType(), + metadata( + "SQL_CATALOG_NAME", "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8", + "SQL_SCHEMA_NAME", "PUBLIC", + "SQL_TABLE_NAME", "TABLE1", + "SQL_COLUMN_NAME", "ID", + "SQL_TYPE", "BIGINT", + "comment", "Record identifier")), + field( + "NAME", + true, + Types.MinorType.VARCHAR.getType(), + metadata( + "SQL_CATALOG_NAME", "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8", + "SQL_SCHEMA_NAME", "PUBLIC", + "SQL_TABLE_NAME", "TABLE1", + "SQL_COLUMN_NAME", "NAME", + "SQL_TYPE", "CHARACTER VARYING", + "comment", "Name of record")), + field( + "COLUMN1", + true, + Types.MinorType.BIT.getType(), + metadata( + "SQL_CATALOG_NAME", "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8", + "SQL_SCHEMA_NAME", "PUBLIC", + "SQL_TABLE_NAME", "TABLE1", + "SQL_COLUMN_NAME", "COLUMN1", + "SQL_TYPE", "BOOLEAN")), + field( + "COLUMNN", + true, + Types.MinorType.INT.getType(), + metadata( + "SQL_CATALOG_NAME", "JDBCTOARROWTEST?CHARACTERENCODING=UTF-8", + "SQL_SCHEMA_NAME", "PUBLIC", + "SQL_TABLE_NAME", "TABLE1", + "SQL_COLUMN_NAME", "COLUMNN", + "SQL_TYPE", "INTEGER", + "comment", "Informative description of columnN"))), + metadata("comment", "This is super special table with valuable data")); assertThat(schema).isEqualTo(expectedSchema); /* corresponding Apache Spark DDL after conversion: - ID BIGINT NOT NULL COMMENT 'Record identifier', - NAME STRING COMMENT 'Name of record', - COLUMN1 BOOLEAN, - COLUMNN INT COMMENT 'Informative description of columnN' - */ + ID BIGINT NOT NULL COMMENT 'Record identifier', + NAME STRING COMMENT 'Name of record', + COLUMN1 BOOLEAN, + COLUMNN INT COMMENT 'Informative description of columnN' + */ assertThat(schema).isEqualTo(expectedSchema); } @@ -160,19 +185,25 @@ private Schema getSchemaWithCommentFromQuery(boolean includeMetadata) throws SQL try (Statement statement = conn.createStatement()) { try (ResultSet resultSet = statement.executeQuery("select * from table1")) { ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); - Map> columnCommentByColumnIndex = getColumnComments(metaData, resultSetMetaData); + Map> columnCommentByColumnIndex = + getColumnComments(metaData, resultSetMetaData); String tableName = getTableNameFromResultSetMetaData(resultSetMetaData); String tableComment = getTableComment(metaData, tableName); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder() - .setAllocator(new RootAllocator()).setSchemaMetadata(Collections.singletonMap(COMMENT, tableComment)) - .setColumnMetadataByColumnIndex(columnCommentByColumnIndex).setIncludeMetadata(includeMetadata).build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder() + .setAllocator(new RootAllocator()) + .setSchemaMetadata(Collections.singletonMap(COMMENT, tableComment)) + .setColumnMetadataByColumnIndex(columnCommentByColumnIndex) + .setIncludeMetadata(includeMetadata) + .build(); return JdbcToArrowUtils.jdbcToArrowSchema(resultSetMetaData, config); } } } - private String getTableNameFromResultSetMetaData(ResultSetMetaData resultSetMetaData) throws SQLException { + private String getTableNameFromResultSetMetaData(ResultSetMetaData resultSetMetaData) + throws SQLException { Set tablesFromQuery = new HashSet<>(); for (int idx = 1, columnCount = resultSetMetaData.getColumnCount(); idx <= columnCount; idx++) { String tableName = resultSetMetaData.getTableName(idx); @@ -186,11 +217,16 @@ private String getTableNameFromResultSetMetaData(ResultSetMetaData resultSetMeta throw new RuntimeException("Table metadata is absent or ambiguous"); } - private Map> getColumnComments(DatabaseMetaData metaData, - ResultSetMetaData resultSetMetaData) throws SQLException { + private Map> getColumnComments( + DatabaseMetaData metaData, ResultSetMetaData resultSetMetaData) throws SQLException { Map> columnCommentByColumnIndex = new HashMap<>(); - for (int columnIdx = 1, columnCount = resultSetMetaData.getColumnCount(); columnIdx <= columnCount; columnIdx++) { - String columnComment = getColumnComment(metaData, resultSetMetaData.getTableName(columnIdx), + for (int columnIdx = 1, columnCount = resultSetMetaData.getColumnCount(); + columnIdx <= columnCount; + columnIdx++) { + String columnComment = + getColumnComment( + metaData, + resultSetMetaData.getTableName(columnIdx), resultSetMetaData.getColumnName(columnIdx)); if (columnComment != null && !columnComment.isEmpty()) { columnCommentByColumnIndex.put(columnIdx, Collections.singletonMap(COMMENT, columnComment)); @@ -220,7 +256,8 @@ private String getTableComment(DatabaseMetaData metaData, String tableName) thro throw new RuntimeException("Table comment not found"); } - private String getColumnComment(DatabaseMetaData metaData, String tableName, String columnName) throws SQLException { + private String getColumnComment(DatabaseMetaData metaData, String tableName, String columnName) + throws SQLException { try (ResultSet tableMetadata = metaData.getColumns(null, null, tableName, columnName)) { if (tableMetadata.next()) { return tableMetadata.getString("REMARKS"); @@ -229,8 +266,14 @@ private String getColumnComment(DatabaseMetaData metaData, String tableName, Str return null; } - private String getExpectedSchema(String expectedResource) throws java.io.IOException, java.net.URISyntaxException { - return new String(Files.readAllBytes(Paths.get(Objects.requireNonNull( - JdbcToArrowCommentMetadataTest.class.getResource(expectedResource)).toURI())), StandardCharsets.UTF_8); + private String getExpectedSchema(String expectedResource) + throws java.io.IOException, java.net.URISyntaxException { + return new String( + Files.readAllBytes( + Paths.get( + Objects.requireNonNull( + JdbcToArrowCommentMetadataTest.class.getResource(expectedResource)) + .toURI())), + StandardCharsets.UTF_8); } } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java index 68a681b052c..c4dda5dc152 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java @@ -28,7 +28,6 @@ import java.util.HashMap; import java.util.Locale; import java.util.TimeZone; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.junit.Test; @@ -36,7 +35,8 @@ public class JdbcToArrowConfigTest { private static final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); - private static final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT); + private static final Calendar calendar = + Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT); @Test(expected = NullPointerException.class) public void testConfigNullArguments() { @@ -116,13 +116,29 @@ public void testIncludeMetadata() { config = new JdbcToArrowConfigBuilder(allocator, calendar, true).build(); assertTrue(config.shouldIncludeMetadata()); - config = new JdbcToArrowConfig(allocator, calendar, /* include metadata */ true, - /* reuse vector schema root */ true, null, null, JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE, null); + config = + new JdbcToArrowConfig( + allocator, + calendar, /* include metadata */ + true, + /* reuse vector schema root */ true, + null, + null, + JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE, + null); assertTrue(config.shouldIncludeMetadata()); assertTrue(config.isReuseVectorSchemaRoot()); - config = new JdbcToArrowConfig(allocator, calendar, /* include metadata */ false, - /* reuse vector schema root */ false, null, null, JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE, null); + config = + new JdbcToArrowConfig( + allocator, + calendar, /* include metadata */ + false, + /* reuse vector schema root */ false, + null, + null, + JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE, + null); assertFalse(config.shouldIncludeMetadata()); assertFalse(config.isReuseVectorSchemaRoot()); } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java index 91f2f465dd9..e16a39d3f49 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowTestHelper.java @@ -22,6 +22,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import java.math.BigDecimal; import java.nio.charset.Charset; import java.sql.ResultSetMetaData; @@ -31,7 +34,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.arrow.vector.BaseValueVector; import org.apache.arrow.vector.BigIntVector; import org.apache.arrow.vector.BitVector; @@ -57,12 +59,9 @@ import org.apache.arrow.vector.util.ObjectMapperFactory; import org.apache.arrow.vector.util.Text; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - /** - * This is a Helper class which has functionalities to read and assert the values from the given FieldVector object. + * This is a Helper class which has functionalities to read and assert the values from the given + * FieldVector object. */ public class JdbcToArrowTestHelper { @@ -78,7 +77,8 @@ public static void assertIntVectorValues(IntVector intVector, int rowCount, Inte } } - public static void assertBooleanVectorValues(BitVector bitVector, int rowCount, Boolean[] values) { + public static void assertBooleanVectorValues( + BitVector bitVector, int rowCount, Boolean[] values) { assertEquals(rowCount, bitVector.getValueCount()); for (int j = 0; j < bitVector.getValueCount(); j++) { @@ -102,7 +102,8 @@ public static void assertBitVectorValues(BitVector bitVector, int rowCount, Inte } } - public static void assertTinyIntVectorValues(TinyIntVector tinyIntVector, int rowCount, Integer[] values) { + public static void assertTinyIntVectorValues( + TinyIntVector tinyIntVector, int rowCount, Integer[] values) { assertEquals(rowCount, tinyIntVector.getValueCount()); for (int j = 0; j < tinyIntVector.getValueCount(); j++) { @@ -114,7 +115,8 @@ public static void assertTinyIntVectorValues(TinyIntVector tinyIntVector, int ro } } - public static void assertSmallIntVectorValues(SmallIntVector smallIntVector, int rowCount, Integer[] values) { + public static void assertSmallIntVectorValues( + SmallIntVector smallIntVector, int rowCount, Integer[] values) { assertEquals(rowCount, smallIntVector.getValueCount()); for (int j = 0; j < smallIntVector.getValueCount(); j++) { @@ -126,7 +128,8 @@ public static void assertSmallIntVectorValues(SmallIntVector smallIntVector, int } } - public static void assertBigIntVectorValues(BigIntVector bigIntVector, int rowCount, Long[] values) { + public static void assertBigIntVectorValues( + BigIntVector bigIntVector, int rowCount, Long[] values) { assertEquals(rowCount, bigIntVector.getValueCount()); for (int j = 0; j < bigIntVector.getValueCount(); j++) { @@ -138,7 +141,8 @@ public static void assertBigIntVectorValues(BigIntVector bigIntVector, int rowCo } } - public static void assertDecimalVectorValues(DecimalVector decimalVector, int rowCount, BigDecimal[] values) { + public static void assertDecimalVectorValues( + DecimalVector decimalVector, int rowCount, BigDecimal[] values) { assertEquals(rowCount, decimalVector.getValueCount()); for (int j = 0; j < decimalVector.getValueCount(); j++) { @@ -150,7 +154,8 @@ public static void assertDecimalVectorValues(DecimalVector decimalVector, int ro } } - public static void assertFloat8VectorValues(Float8Vector float8Vector, int rowCount, Double[] values) { + public static void assertFloat8VectorValues( + Float8Vector float8Vector, int rowCount, Double[] values) { assertEquals(rowCount, float8Vector.getValueCount()); for (int j = 0; j < float8Vector.getValueCount(); j++) { @@ -162,7 +167,8 @@ public static void assertFloat8VectorValues(Float8Vector float8Vector, int rowCo } } - public static void assertFloat4VectorValues(Float4Vector float4Vector, int rowCount, Float[] values) { + public static void assertFloat4VectorValues( + Float4Vector float4Vector, int rowCount, Float[] values) { assertEquals(rowCount, float4Vector.getValueCount()); for (int j = 0; j < float4Vector.getValueCount(); j++) { @@ -174,7 +180,8 @@ public static void assertFloat4VectorValues(Float4Vector float4Vector, int rowCo } } - public static void assertTimeVectorValues(TimeMilliVector timeMilliVector, int rowCount, Long[] values) { + public static void assertTimeVectorValues( + TimeMilliVector timeMilliVector, int rowCount, Long[] values) { assertEquals(rowCount, timeMilliVector.getValueCount()); for (int j = 0; j < timeMilliVector.getValueCount(); j++) { @@ -186,7 +193,8 @@ public static void assertTimeVectorValues(TimeMilliVector timeMilliVector, int r } } - public static void assertDateVectorValues(DateDayVector dateDayVector, int rowCount, Integer[] values) { + public static void assertDateVectorValues( + DateDayVector dateDayVector, int rowCount, Integer[] values) { assertEquals(rowCount, dateDayVector.getValueCount()); for (int j = 0; j < dateDayVector.getValueCount(); j++) { @@ -198,7 +206,8 @@ public static void assertDateVectorValues(DateDayVector dateDayVector, int rowCo } } - public static void assertTimeStampVectorValues(TimeStampVector timeStampVector, int rowCount, Long[] values) { + public static void assertTimeStampVectorValues( + TimeStampVector timeStampVector, int rowCount, Long[] values) { assertEquals(rowCount, timeStampVector.getValueCount()); for (int j = 0; j < timeStampVector.getValueCount(); j++) { @@ -210,7 +219,8 @@ public static void assertTimeStampVectorValues(TimeStampVector timeStampVector, } } - public static void assertVarBinaryVectorValues(VarBinaryVector varBinaryVector, int rowCount, byte[][] values) { + public static void assertVarBinaryVectorValues( + VarBinaryVector varBinaryVector, int rowCount, byte[][] values) { assertEquals(rowCount, varBinaryVector.getValueCount()); for (int j = 0; j < varBinaryVector.getValueCount(); j++) { @@ -222,7 +232,8 @@ public static void assertVarBinaryVectorValues(VarBinaryVector varBinaryVector, } } - public static void assertVarcharVectorValues(VarCharVector varCharVector, int rowCount, byte[][] values) { + public static void assertVarcharVectorValues( + VarCharVector varCharVector, int rowCount, byte[][] values) { assertEquals(rowCount, varCharVector.getValueCount()); for (int j = 0; j < varCharVector.getValueCount(); j++) { @@ -238,7 +249,8 @@ public static void assertNullVectorValues(NullVector vector, int rowCount) { assertEquals(rowCount, vector.getValueCount()); } - public static void assertListVectorValues(ListVector listVector, int rowCount, Integer[][] values) { + public static void assertListVectorValues( + ListVector listVector, int rowCount, Integer[][] values) { assertEquals(rowCount, listVector.getValueCount()); for (int j = 0; j < listVector.getValueCount(); j++) { @@ -251,7 +263,8 @@ public static void assertListVectorValues(ListVector listVector, int rowCount, I } } - public static void assertMapVectorValues(MapVector mapVector, int rowCount, Map[] values) { + public static void assertMapVectorValues( + MapVector mapVector, int rowCount, Map[] values) { assertEquals(rowCount, mapVector.getValueCount()); for (int j = 0; j < mapVector.getValueCount(); j++) { @@ -262,10 +275,17 @@ public static void assertMapVectorValues(MapVector mapVector, int rowCount, Map< (JsonStringArrayList>) mapVector.getObject(j); Map actualMap = null; if (actualSource != null && !actualSource.isEmpty()) { - actualMap = actualSource.stream().map(entry -> - new AbstractMap.SimpleEntry<>(entry.get("key").toString(), - entry.get("value") != null ? entry.get("value").toString() : null)) - .collect(HashMap::new, (collector, val) -> collector.put(val.getKey(), val.getValue()), HashMap::putAll); + actualMap = + actualSource.stream() + .map( + entry -> + new AbstractMap.SimpleEntry<>( + entry.get("key").toString(), + entry.get("value") != null ? entry.get("value").toString() : null)) + .collect( + HashMap::new, + (collector, val) -> collector.put(val.getKey(), val.getValue()), + HashMap::putAll); } assertEquals(values[j], actualMap); } @@ -309,8 +329,8 @@ public static void assertFieldMetadataIsEmpty(VectorSchemaRoot schema) { } } - public static void assertFieldMetadataMatchesResultSetMetadata(ResultSetMetaData rsmd, Schema schema) - throws SQLException { + public static void assertFieldMetadataMatchesResultSetMetadata( + ResultSetMetaData rsmd, Schema schema) throws SQLException { assertNotNull(schema); assertNotNull(schema.getFields()); assertNotNull(rsmd); @@ -404,7 +424,8 @@ public static byte[][] getCharArray(String[] values, String dataType) { return valueArr; } - public static byte[][] getCharArrayWithCharSet(String[] values, String dataType, Charset charSet) { + public static byte[][] getCharArrayWithCharSet( + String[] values, String dataType, Charset charSet) { String[] dataArr = getValues(values, dataType); byte[][] valueArr = new byte[dataArr.length][]; int i = 0; diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtility.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtility.java index c712741b51f..e2547fa8966 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtility.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtility.java @@ -48,13 +48,11 @@ public class ResultSetUtility { public static ResultSet generateEmptyResultSet() throws SQLException { MockDataElement element = new MockDataElement("string_example"); MockResultSetMetaData.MockColumnMetaData columnMetaData = - MockResultSetMetaData.MockColumnMetaData.fromDataElement(element, 1); + MockResultSetMetaData.MockColumnMetaData.fromDataElement(element, 1); ArrayList cols = new ArrayList<>(); cols.add(columnMetaData); ResultSetMetaData metadata = new MockResultSetMetaData(cols); - return MockResultSet.builder() - .setMetaData(metadata) - .build(); + return MockResultSet.builder().setMetaData(metadata).build(); } public static MockResultSet generateBasicResultSet(int rows) throws SQLException { @@ -319,15 +317,19 @@ public String getColumnTypeName(int column) throws SQLException { } public static MockResultSetMetaData fromRows(ArrayList rows) throws SQLException { - // Note: This attempts to dynamically construct ResultSetMetaData from the first row in a given result set. - // If there are now rows, or the result set contains no columns, this cannot be dynamically generated and + // Note: This attempts to dynamically construct ResultSetMetaData from the first row in a + // given result set. + // If there are now rows, or the result set contains no columns, this cannot be dynamically + // generated and // an exception will be thrown. if (rows.size() == 0) { - throw new SQLException("Unable to dynamically generate ResultSetMetaData because row count is zero!"); + throw new SQLException( + "Unable to dynamically generate ResultSetMetaData because row count is zero!"); } MockRow firstRow = rows.get(0); if (firstRow.dataElements.size() == 0) { - throw new SQLException("Unable to dynamically generate ResultSetMetaData because column count is zero!"); + throw new SQLException( + "Unable to dynamically generate ResultSetMetaData because column count is zero!"); } ArrayList columns = new ArrayList<>(); for (int i = 0; i < firstRow.dataElements.size(); i++) { @@ -347,7 +349,6 @@ public static class MockColumnMetaData { private String typeName; private int displaySize; - private MockColumnMetaData() {} private String getLabel() { @@ -382,17 +383,18 @@ private int getDisplaySize() { return displaySize; } - public static MockColumnMetaData fromDataElement(MockDataElement element, int i) throws SQLException { + public static MockColumnMetaData fromDataElement(MockDataElement element, int i) + throws SQLException { return MockColumnMetaData.builder() - .index(i) - .sqlType(element.getSqlType()) - .precision(element.getPrecision()) - .scale(element.getScale()) - .nullable(element.isNullable()) - .setTypeName("TYPE") - .setDisplaySize(420) - .label("col_" + i) - .build(); + .index(i) + .sqlType(element.getSqlType()) + .precision(element.getPrecision()) + .scale(element.getScale()) + .nullable(element.isNullable()) + .setTypeName("TYPE") + .setDisplaySize(420) + .label("col_" + i) + .build(); } public static Builder builder() { @@ -446,9 +448,7 @@ public MockColumnMetaData build() { return this.columnMetaData; } } - } - } public static class MockRow { @@ -641,7 +641,6 @@ public short getShort() throws SQLException { } } - public static class ThrowingResultSet implements ResultSet { @Override @@ -1145,17 +1144,20 @@ public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException } @Override - public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { + public void updateAsciiStream(String columnLabel, InputStream x, int length) + throws SQLException { throw getExceptionToThrow(); } @Override - public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { + public void updateBinaryStream(String columnLabel, InputStream x, int length) + throws SQLException { throw getExceptionToThrow(); } @Override - public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { + public void updateCharacterStream(String columnLabel, Reader reader, int length) + throws SQLException { throw getExceptionToThrow(); } @@ -1445,7 +1447,8 @@ public void updateNCharacterStream(int columnIndex, Reader x, long length) throw } @Override - public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + public void updateNCharacterStream(String columnLabel, Reader reader, long length) + throws SQLException { throw getExceptionToThrow(); } @@ -1455,7 +1458,8 @@ public void updateAsciiStream(int columnIndex, InputStream x, long length) throw } @Override - public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { + public void updateBinaryStream(int columnIndex, InputStream x, long length) + throws SQLException { throw getExceptionToThrow(); } @@ -1465,27 +1469,32 @@ public void updateCharacterStream(int columnIndex, Reader x, long length) throws } @Override - public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { + public void updateAsciiStream(String columnLabel, InputStream x, long length) + throws SQLException { throw getExceptionToThrow(); } @Override - public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { + public void updateBinaryStream(String columnLabel, InputStream x, long length) + throws SQLException { throw getExceptionToThrow(); } @Override - public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + public void updateCharacterStream(String columnLabel, Reader reader, long length) + throws SQLException { throw getExceptionToThrow(); } @Override - public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { + public void updateBlob(int columnIndex, InputStream inputStream, long length) + throws SQLException { throw getExceptionToThrow(); } @Override - public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { + public void updateBlob(String columnLabel, InputStream inputStream, long length) + throws SQLException { throw getExceptionToThrow(); } @@ -1590,13 +1599,14 @@ public T getObject(String columnLabel, Class type) throws SQLException { } @Override - public void updateObject(int columnIndex, Object x, SQLType targetSqlType, int scaleOrLength) throws SQLException { + public void updateObject(int columnIndex, Object x, SQLType targetSqlType, int scaleOrLength) + throws SQLException { throw getExceptionToThrow(); } @Override public void updateObject(String columnLabel, Object x, SQLType targetSqlType, int scaleOrLength) - throws SQLException { + throws SQLException { throw getExceptionToThrow(); } @@ -1606,7 +1616,8 @@ public void updateObject(int columnIndex, Object x, SQLType targetSqlType) throw } @Override - public void updateObject(String columnLabel, Object x, SQLType targetSqlType) throws SQLException { + public void updateObject(String columnLabel, Object x, SQLType targetSqlType) + throws SQLException { throw getExceptionToThrow(); } @@ -1629,7 +1640,6 @@ private static SQLException getExceptionToThrow(String message) { return new SQLException(message); } - public static class ThrowingResultSetMetaData implements ResultSetMetaData { @Override public int getColumnCount() throws SQLException { diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtilityTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtilityTest.java index 2424ed62524..4a505c48d28 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtilityTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/ResultSetUtilityTest.java @@ -26,7 +26,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.VectorSchemaRoot; @@ -36,20 +35,24 @@ public class ResultSetUtilityTest { @Test public void testZeroRowResultSet() throws Exception { - for (boolean reuseVectorSchemaRoot : new boolean[]{false, true}) { + for (boolean reuseVectorSchemaRoot : new boolean[] {false, true}) { try (BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE)) { ResultSet rs = ResultSetUtility.generateEmptyResultSet(); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .build(); ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config); assertTrue("Iterator on zero row ResultSet should haveNext() before use", iter.hasNext()); VectorSchemaRoot root = iter.next(); assertNotNull("VectorSchemaRoot from first next() result should never be null", root); - assertEquals("VectorSchemaRoot from empty ResultSet should have zero rows", 0, root.getRowCount()); - assertFalse("hasNext() should return false on empty ResultSets after initial next() call", iter.hasNext()); + assertEquals( + "VectorSchemaRoot from empty ResultSet should have zero rows", 0, root.getRowCount()); + assertFalse( + "hasNext() should return false on empty ResultSets after initial next() call", + iter.hasNext()); } } } @@ -99,7 +102,8 @@ public void testBasicResultSet() throws Exception { @Test public void testMockDataTypes() throws SQLException { - ResultSetUtility.MockDataElement element = new ResultSetUtility.MockDataElement(1L, Types.NUMERIC); + ResultSetUtility.MockDataElement element = + new ResultSetUtility.MockDataElement(1L, Types.NUMERIC); assertEquals(1L, element.getLong()); assertEquals(1, element.getInt()); assertEquals("1", element.getString()); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/Table.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/Table.java index 50c4fe6db2a..7c25af68cca 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/Table.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/Table.java @@ -17,14 +17,11 @@ package org.apache.arrow.adapter.jdbc; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -/** - * POJO to handle the YAML data from the test YAML file. - */ +/** POJO to handle the YAML data from the test YAML file. */ @JsonIgnoreProperties(ignoreUnknown = true) public class Table { private String name; @@ -39,8 +36,7 @@ public class Table { private String[] vectors; private int rowCount; - public Table() { - } + public Table() {} public String getName() { return name; diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/UnreliableMetaDataTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/UnreliableMetaDataTest.java index 3eb886faabc..ae2451d339e 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/UnreliableMetaDataTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/UnreliableMetaDataTest.java @@ -34,7 +34,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.IntVector; @@ -48,9 +47,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -/** - * Test options for dealing with unreliable ResultSetMetaData from JDBC drivers. - */ +/** Test options for dealing with unreliable ResultSetMetaData from JDBC drivers. */ @RunWith(Parameterized.class) public class UnreliableMetaDataTest { private final boolean reuseVectorSchemaRoot; @@ -72,7 +69,7 @@ public void afterEach() { @Parameterized.Parameters(name = "reuseVectorSchemaRoot = {0}") public static Collection getTestData() { - return Arrays.asList(new Object[][] { {false}, {true} }); + return Arrays.asList(new Object[][] {{false}, {true}}); } @Test @@ -91,13 +88,15 @@ public void testUnreliableMetaDataPrecisionAndScale() throws Exception { // reset the ResultSet: rs.beforeFirst(); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .build(); try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config)) { assertTrue(iter.hasNext()); - assertThrows(RuntimeException.class, iter::next, "Expected to fail due to mismatched metadata!"); + assertThrows( + RuntimeException.class, iter::next, "Expected to fail due to mismatched metadata!"); } // reset the ResultSet: @@ -105,11 +104,12 @@ public void testUnreliableMetaDataPrecisionAndScale() throws Exception { JdbcFieldInfo explicitMappingField = new JdbcFieldInfo(Types.DECIMAL, 18, 2); Map explicitMapping = new HashMap<>(); explicitMapping.put(1, explicitMappingField); - config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setExplicitTypesByColumnIndex(explicitMapping) - .build(); + config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setExplicitTypesByColumnIndex(explicitMapping) + .build(); try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config)) { while (iter.hasNext()) { @@ -133,7 +133,8 @@ public void testInconsistentPrecisionAndScale() throws Exception { assertEquals("Value precision should be 18", 18, bd1.precision()); rs.next(); BigDecimal bd2 = rs.getBigDecimal(1); - assertEquals("Value should be 1000000000300.0000001", new BigDecimal("1000000000300.0000001"), bd2); + assertEquals( + "Value should be 1000000000300.0000001", new BigDecimal("1000000000300.0000001"), bd2); assertEquals("Value scale should be 7", 7, bd2.scale()); assertEquals("Value precision should be 20", 20, bd2.precision()); rs.beforeFirst(); @@ -141,23 +142,27 @@ public void testInconsistentPrecisionAndScale() throws Exception { Map explicitMapping = new HashMap<>(); explicitMapping.put(1, explicitMappingField); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setExplicitTypesByColumnIndex(explicitMapping) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setExplicitTypesByColumnIndex(explicitMapping) + .build(); try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config)) { assertTrue(iter.hasNext()); - assertThrows(RuntimeException.class, iter::next, + assertThrows( + RuntimeException.class, + iter::next, "This is expected to fail due to inconsistent BigDecimal scales, while strict matching is enabled."); } // Reuse same ResultSet, with RoundingMode.UNNECESSARY set to coerce BigDecimal scale as needed: - config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setExplicitTypesByColumnIndex(explicitMapping) - .setBigDecimalRoundingMode(RoundingMode.UNNECESSARY) - .build(); + config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setExplicitTypesByColumnIndex(explicitMapping) + .setBigDecimalRoundingMode(RoundingMode.UNNECESSARY) + .build(); try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config)) { while (iter.hasNext()) { VectorSchemaRoot root = iter.next(); @@ -175,23 +180,30 @@ public void testIncorrectNullability() throws Exception { .sqlType(Types.INTEGER) .nullable(ResultSetMetaData.columnNoNulls) .build(); - ResultSetMetaData metadata = new ResultSetUtility.MockResultSetMetaData(Collections.singletonList(columnMetaData)); - final ResultSetUtility.MockResultSet.Builder resultSetBuilder = ResultSetUtility.MockResultSet.builder() - .setMetaData(metadata) - .addDataElement(new ResultSetUtility.MockDataElement(1024, Types.INTEGER)) - .finishRow() - .addDataElement(new ResultSetUtility.MockDataElement(null, Types.INTEGER)) - .finishRow(); - final Schema notNullSchema = new Schema( - Collections.singletonList(Field.notNullable(/*name=*/null, new ArrowType.Int(32, true)))); - final Schema nullSchema = new Schema( - Collections.singletonList(Field.nullable(/*name=*/null, new ArrowType.Int(32, true)))); + ResultSetMetaData metadata = + new ResultSetUtility.MockResultSetMetaData(Collections.singletonList(columnMetaData)); + final ResultSetUtility.MockResultSet.Builder resultSetBuilder = + ResultSetUtility.MockResultSet.builder() + .setMetaData(metadata) + .addDataElement(new ResultSetUtility.MockDataElement(1024, Types.INTEGER)) + .finishRow() + .addDataElement(new ResultSetUtility.MockDataElement(null, Types.INTEGER)) + .finishRow(); + final Schema notNullSchema = + new Schema( + Collections.singletonList( + Field.notNullable(/* name= */ null, new ArrowType.Int(32, true)))); + final Schema nullSchema = + new Schema( + Collections.singletonList( + Field.nullable(/* name= */ null, new ArrowType.Int(32, true)))); try (final ResultSet rs = resultSetBuilder.build()) { - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .build(); try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config)) { assertTrue(iter.hasNext()); final VectorSchemaRoot root = iter.next(); @@ -209,14 +221,16 @@ public void testIncorrectNullability() throws Exception { // Override the nullability to get the correct result final Map typeMapping = new HashMap<>(); - JdbcFieldInfo realFieldInfo = new JdbcFieldInfo( - Types.INTEGER, ResultSetMetaData.columnNullable, /*precision*/0, /*scale*/0); + JdbcFieldInfo realFieldInfo = + new JdbcFieldInfo( + Types.INTEGER, ResultSetMetaData.columnNullable, /*precision*/ 0, /*scale*/ 0); typeMapping.put(1, realFieldInfo); - config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setExplicitTypesByColumnIndex(typeMapping) - .build(); + config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setExplicitTypesByColumnIndex(typeMapping) + .build(); try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config)) { assertTrue(iter.hasNext()); final VectorSchemaRoot root = iter.next(); @@ -232,14 +246,16 @@ public void testIncorrectNullability() throws Exception { rs.beforeFirst(); // columnNullableUnknown won't override the metadata - realFieldInfo = new JdbcFieldInfo( - Types.INTEGER, ResultSetMetaData.columnNullableUnknown, /*precision*/0, /*scale*/0); + realFieldInfo = + new JdbcFieldInfo( + Types.INTEGER, ResultSetMetaData.columnNullableUnknown, /*precision*/ 0, /*scale*/ 0); typeMapping.put(1, realFieldInfo); - config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setExplicitTypesByColumnIndex(typeMapping) - .build(); + config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setExplicitTypesByColumnIndex(typeMapping) + .build(); try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config)) { assertTrue(iter.hasNext()); final VectorSchemaRoot root = iter.next(); @@ -268,8 +284,8 @@ private ResultSet buildIncorrectPrecisionAndScaleMetaDataResultSet() throws SQLE return ResultSetUtility.MockResultSet.builder() .setMetaData(metadata) .addDataElement( - new ResultSetUtility.MockDataElement(new BigDecimal("1000000000000000.01"), Types.DECIMAL) - ) + new ResultSetUtility.MockDataElement( + new BigDecimal("1000000000000000.01"), Types.DECIMAL)) .finishRow() .build(); } @@ -288,12 +304,12 @@ private ResultSet buildVaryingPrecisionAndScaleResultSet() throws SQLException { return ResultSetUtility.MockResultSet.builder() .setMetaData(metadata) .addDataElement( - new ResultSetUtility.MockDataElement(new BigDecimal("1000000000000000.01"), Types.DECIMAL) - ) + new ResultSetUtility.MockDataElement( + new BigDecimal("1000000000000000.01"), Types.DECIMAL)) .finishRow() .addDataElement( - new ResultSetUtility.MockDataElement(new BigDecimal("1000000000300.0000001"), Types.DECIMAL) - ) + new ResultSetUtility.MockDataElement( + new BigDecimal("1000000000300.0000001"), Types.DECIMAL)) .finishRow() .build(); } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java index 96bac42214c..d514780827f 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java @@ -35,5 +35,4 @@ public void setUp() { public void tearDown() { allocator.close(); } - } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java index a368023d490..1ba4112e5f4 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java @@ -23,7 +23,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; - import org.apache.arrow.vector.BaseValueVector; import org.apache.arrow.vector.VarBinaryVector; import org.junit.Test; @@ -37,7 +36,8 @@ interface InputStreamConsumer { void consume(BinaryConsumer consumer) throws IOException; } - protected void assertConsume(boolean nullable, InputStreamConsumer dataConsumer, byte[][] expect) throws IOException { + protected void assertConsume(boolean nullable, InputStreamConsumer dataConsumer, byte[][] expect) + throws IOException { try (final VarBinaryVector vector = new VarBinaryVector("binary", allocator)) { BinaryConsumer consumer = BinaryConsumer.createConsumer(vector, 0, nullable); dataConsumer.consume(consumer); @@ -61,51 +61,59 @@ private byte[] createBytes(int length) { return bytes; } - public void testConsumeInputStream(byte[][] values, boolean nullable) throws IOException { - assertConsume(nullable, binaryConsumer -> { - for (byte[] value : values) { - binaryConsumer.consume(new ByteArrayInputStream(value)); - binaryConsumer.moveWriterPosition(); - } - }, values); + assertConsume( + nullable, + binaryConsumer -> { + for (byte[] value : values) { + binaryConsumer.consume(new ByteArrayInputStream(value)); + binaryConsumer.moveWriterPosition(); + } + }, + values); } @Test public void testConsumeInputStream() throws IOException { - testConsumeInputStream(new byte[][]{ - createBytes(DEFAULT_RECORD_BYTE_COUNT) - }, false); - - testConsumeInputStream(new byte[][]{ - createBytes(DEFAULT_RECORD_BYTE_COUNT), - createBytes(DEFAULT_RECORD_BYTE_COUNT) - }, false); - - testConsumeInputStream(new byte[][]{ - createBytes(DEFAULT_RECORD_BYTE_COUNT * 2), - createBytes(DEFAULT_RECORD_BYTE_COUNT), - createBytes(DEFAULT_RECORD_BYTE_COUNT) - }, false); - - testConsumeInputStream(new byte[][]{ - createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT) - }, false); - - testConsumeInputStream(new byte[][]{ - createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT * 10), - }, false); - - testConsumeInputStream(new byte[][]{ - createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT), - createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT) - }, false); - - testConsumeInputStream(new byte[][]{ - createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT), - createBytes(DEFAULT_RECORD_BYTE_COUNT), - createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT) - }, false); + testConsumeInputStream(new byte[][] {createBytes(DEFAULT_RECORD_BYTE_COUNT)}, false); + + testConsumeInputStream( + new byte[][] { + createBytes(DEFAULT_RECORD_BYTE_COUNT), createBytes(DEFAULT_RECORD_BYTE_COUNT) + }, + false); + + testConsumeInputStream( + new byte[][] { + createBytes(DEFAULT_RECORD_BYTE_COUNT * 2), + createBytes(DEFAULT_RECORD_BYTE_COUNT), + createBytes(DEFAULT_RECORD_BYTE_COUNT) + }, + false); + + testConsumeInputStream( + new byte[][] {createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT)}, false); + + testConsumeInputStream( + new byte[][] { + createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT * 10), + }, + false); + + testConsumeInputStream( + new byte[][] { + createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT), + createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT) + }, + false); + + testConsumeInputStream( + new byte[][] { + createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT), + createBytes(DEFAULT_RECORD_BYTE_COUNT), + createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT) + }, + false); byte[][] testRecords = new byte[INITIAL_VALUE_ALLOCATION * 2][]; for (int i = 0; i < testRecords.length; i++) { @@ -113,5 +121,4 @@ public void testConsumeInputStream() throws IOException { } testConsumeInputStream(testRecords, false); } - } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcAliasToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcAliasToArrowTest.java index d9acfe88f4f..bc4ecf70f90 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcAliasToArrowTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcAliasToArrowTest.java @@ -28,7 +28,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.List; - import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.types.pojo.Field; @@ -40,10 +39,8 @@ public class JdbcAliasToArrowTest { private Connection conn = null; - private static final String CREATE_STATEMENT = - "CREATE TABLE example_table (id INTEGER);"; - private static final String INSERT_STATEMENT = - "INSERT INTO example_table (id) VALUES (?);"; + private static final String CREATE_STATEMENT = "CREATE TABLE example_table (id INTEGER);"; + private static final String INSERT_STATEMENT = "INSERT INTO example_table (id) VALUES (?);"; private static final String QUERY = "SELECT id as a, id as b FROM example_table;"; private static final String DROP_STATEMENT = "DROP TABLE example_table;"; private static final String ORIGINAL_COLUMN_NAME = "ID"; @@ -62,10 +59,9 @@ public void setUp() throws Exception { } /** - * Test h2 database query with alias for column name and column label. - * To verify reading field alias from an H2 database works as expected. - * If this test fails, something is either wrong with the setup, - * or the H2 SQL behavior changed. + * Test h2 database query with alias for column name and column label. To verify reading field + * alias from an H2 database works as expected. If this test fails, something is either wrong with + * the setup, or the H2 SQL behavior changed. */ @Test public void testReadH2Alias() throws Exception { @@ -96,8 +92,8 @@ public void testReadH2Alias() throws Exception { } /** - * Test jdbc query results with alias to arrow works expected. - * Arrow result schema name should be field alias name. + * Test jdbc query results with alias to arrow works expected. Arrow result schema name should be + * field alias name. */ @Test public void testJdbcAliasToArrow() throws Exception { @@ -105,8 +101,7 @@ public void testJdbcAliasToArrow() throws Exception { insertRows(rowCount); try (ResultSet resultSet = conn.createStatement().executeQuery(QUERY)) { - final VectorSchemaRoot vector = - sqlToArrow(resultSet, new RootAllocator(Integer.MAX_VALUE)); + final VectorSchemaRoot vector = sqlToArrow(resultSet, new RootAllocator(Integer.MAX_VALUE)); assertEquals(rowCount, vector.getRowCount()); Schema vectorSchema = vector.getSchema(); diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowArrayTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowArrayTest.java index 377e332b43a..075fee0ad47 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowArrayTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowArrayTest.java @@ -33,7 +33,6 @@ import java.sql.Types; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.adapter.jdbc.JdbcFieldInfo; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -53,11 +52,12 @@ public class JdbcToArrowArrayTest { private Connection conn = null; private static final String CREATE_STATEMENT = - "CREATE TABLE array_table (id INTEGER, int_array INTEGER ARRAY, float_array REAL ARRAY, " + - "string_array VARCHAR ARRAY);"; + "CREATE TABLE array_table (id INTEGER, int_array INTEGER ARRAY, float_array REAL ARRAY, " + + "string_array VARCHAR ARRAY);"; private static final String INSERT_STATEMENT = "INSERT INTO array_table (id, int_array, float_array, string_array) VALUES (?, ?, ?, ?);"; - private static final String QUERY = "SELECT int_array, float_array, string_array FROM array_table ORDER BY id;"; + private static final String QUERY = + "SELECT int_array, float_array, string_array FROM array_table ORDER BY id;"; private static final String DROP_STATEMENT = "DROP TABLE array_table;"; private static Map arrayFieldMapping; @@ -157,7 +157,8 @@ public void testJdbcToArrow() throws Exception { insertRows(rowCount, intArrays, floatArrays, strArrays); final JdbcToArrowConfigBuilder builder = - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), JdbcToArrowUtils.getUtcCalendar(), false); + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), JdbcToArrowUtils.getUtcCalendar(), false); builder.setArraySubTypeByColumnNameMap(arrayFieldMapping); final JdbcToArrowConfig config = builder.build(); @@ -167,9 +168,12 @@ public void testJdbcToArrow() throws Exception { assertEquals(rowCount, vector.getRowCount()); - assertIntegerVectorEquals((ListVector) vector.getVector(INT_ARRAY_FIELD_NAME), rowCount, intArrays); - assertFloatVectorEquals((ListVector) vector.getVector(FLOAT_ARRAY_FIELD_NAME), rowCount, floatArrays); - assertStringVectorEquals((ListVector) vector.getVector(STRING_ARRAY_FIELD_NAME), rowCount, strArrays); + assertIntegerVectorEquals( + (ListVector) vector.getVector(INT_ARRAY_FIELD_NAME), rowCount, intArrays); + assertFloatVectorEquals( + (ListVector) vector.getVector(FLOAT_ARRAY_FIELD_NAME), rowCount, floatArrays); + assertStringVectorEquals( + (ListVector) vector.getVector(STRING_ARRAY_FIELD_NAME), rowCount, strArrays); } } @@ -178,30 +182,22 @@ public void testJdbcToArrowWithNulls() throws Exception { int rowCount = 4; Integer[][] intArrays = { - null, - {0}, - {1}, - {}, + null, {0}, {1}, {}, }; Float[][] floatArrays = { - { 2.0f }, - null, - { 3.0f }, - {}, + {2.0f}, null, {3.0f}, {}, }; String[][] stringArrays = { - {"4"}, - null, - {"5"}, - {}, + {"4"}, null, {"5"}, {}, }; insertRows(rowCount, intArrays, floatArrays, stringArrays); final JdbcToArrowConfigBuilder builder = - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), JdbcToArrowUtils.getUtcCalendar(), false); + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), JdbcToArrowUtils.getUtcCalendar(), false); builder.setArraySubTypeByColumnNameMap(arrayFieldMapping); final JdbcToArrowConfig config = builder.build(); @@ -211,13 +207,17 @@ public void testJdbcToArrowWithNulls() throws Exception { assertEquals(rowCount, vector.getRowCount()); - assertIntegerVectorEquals((ListVector) vector.getVector(INT_ARRAY_FIELD_NAME), rowCount, intArrays); - assertFloatVectorEquals((ListVector) vector.getVector(FLOAT_ARRAY_FIELD_NAME), rowCount, floatArrays); - assertStringVectorEquals((ListVector) vector.getVector(STRING_ARRAY_FIELD_NAME), rowCount, stringArrays); + assertIntegerVectorEquals( + (ListVector) vector.getVector(INT_ARRAY_FIELD_NAME), rowCount, intArrays); + assertFloatVectorEquals( + (ListVector) vector.getVector(FLOAT_ARRAY_FIELD_NAME), rowCount, floatArrays); + assertStringVectorEquals( + (ListVector) vector.getVector(STRING_ARRAY_FIELD_NAME), rowCount, stringArrays); } } - private void assertIntegerVectorEquals(ListVector listVector, int rowCount, Integer[][] expectedValues) { + private void assertIntegerVectorEquals( + ListVector listVector, int rowCount, Integer[][] expectedValues) { IntVector vector = (IntVector) listVector.getDataVector(); ArrowBuf offsetBuffer = listVector.getOffsetBuffer(); @@ -242,7 +242,8 @@ private void assertIntegerVectorEquals(ListVector listVector, int rowCount, Inte } } - private void assertFloatVectorEquals(ListVector listVector, int rowCount, Float[][] expectedValues) { + private void assertFloatVectorEquals( + ListVector listVector, int rowCount, Float[][] expectedValues) { Float4Vector vector = (Float4Vector) listVector.getDataVector(); ArrowBuf offsetBuffer = listVector.getOffsetBuffer(); @@ -267,7 +268,8 @@ private void assertFloatVectorEquals(ListVector listVector, int rowCount, Float[ } } - private void assertStringVectorEquals(ListVector listVector, int rowCount, String[][] expectedValues) { + private void assertStringVectorEquals( + ListVector listVector, int rowCount, String[][] expectedValues) { VarCharVector vector = (VarCharVector) listVector.getDataVector(); ArrowBuf offsetBuffer = listVector.getOffsetBuffer(); @@ -308,7 +310,7 @@ private Integer[][] generateIntegerArrayField(int numRows) { for (int i = 0; i < numRows; ++i) { int val = i * 4; - result[i] = new Integer[]{val, val + 1, val + 2, val + 3}; + result[i] = new Integer[] {val, val + 1, val + 2, val + 3}; } return result; @@ -316,10 +318,10 @@ private Integer[][] generateIntegerArrayField(int numRows) { private Float[][] generateFloatArrayField(int numRows) { Float[][] result = new Float[numRows][]; - + for (int i = 0; i < numRows; ++i) { int val = i * 4; - result[i] = new Float[]{(float) val, (float) val + 1, (float) val + 2, (float) val + 3}; + result[i] = new Float[] {(float) val, (float) val + 1, (float) val + 2, (float) val + 3}; } return result; @@ -330,22 +332,21 @@ private String[][] generateStringArrayField(int numRows) { for (int i = 0; i < numRows; ++i) { int val = i * 4; - result[i] = new String[]{ - String.valueOf(val), - String.valueOf(val + 1), - String.valueOf(val + 2), - String.valueOf(val + 3) }; + result[i] = + new String[] { + String.valueOf(val), + String.valueOf(val + 1), + String.valueOf(val + 2), + String.valueOf(val + 3) + }; } return result; } private void insertRows( - int numRows, - Integer[][] integerArrays, - Float[][] floatArrays, - String[][] strArrays) - throws SQLException { + int numRows, Integer[][] integerArrays, Float[][] floatArrays, String[][] strArrays) + throws SQLException { // Insert 4 Rows try (PreparedStatement stmt = conn.prepareStatement(INSERT_STATEMENT)) { diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java index 422b55070aa..1f28d077f71 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java @@ -29,7 +29,6 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; - import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -47,8 +46,8 @@ import org.junit.runners.Parameterized.Parameters; /** - * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with UTF-8 Charset, - * including the multi-byte CJK characters for H2 database. + * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with + * UTF-8 Charset, including the multi-byte CJK characters for H2 database. */ @RunWith(Parameterized.class) public class JdbcToArrowCharSetTest extends AbstractJdbcToArrowTest { @@ -81,7 +80,7 @@ public void setUp() throws SQLException, ClassNotFoundException { String driver = "org.h2.Driver"; Class.forName(driver); conn = DriverManager.getConnection(url); - try (Statement stmt = conn.createStatement();) { + try (Statement stmt = conn.createStatement(); ) { stmt.executeUpdate(table.getCreate()); for (String insert : table.getData()) { stmt.executeUpdate(insert); @@ -98,38 +97,58 @@ public void setUp() throws SQLException, ClassNotFoundException { * @throws IOException on error */ @Parameters - public static Collection getTestData() throws SQLException, ClassNotFoundException, IOException { + public static Collection getTestData() + throws SQLException, ClassNotFoundException, IOException { return Arrays.asList(prepareTestData(testFiles, JdbcToArrowCharSetTest.class)); } /** - * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with UTF-8 Charset, including - * the multi-byte CJK characters. + * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with UTF-8 + * Charset, including the multi-byte CJK characters. */ @Test public void testJdbcToArrowValues() throws SQLException, IOException { - testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), + false); testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new RootAllocator(Integer.MAX_VALUE), + Calendar.getInstance()), + false); testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery())), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE)), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - Calendar.getInstance()), false); - testDataSets(sqlToArrow( - conn.createStatement().executeQuery(table.getQuery()), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()), false); - testDataSets(sqlToArrow( - conn, - table.getQuery(), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()), false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new RootAllocator(Integer.MAX_VALUE)), + false); + testDataSets( + sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()), + false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .build()), + false); + testDataSets( + sqlToArrow( + conn, + table.getQuery(), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .build()), + false); } @Test public void testJdbcSchemaMetadata() throws SQLException { - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build(); ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData(); Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config); JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema); @@ -139,19 +158,25 @@ public void testJdbcSchemaMetadata() throws SQLException { * This method calls the assert methods for various DataSets. * * @param root VectorSchemaRoot for test - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { JdbcToArrowTestHelper.assertFieldMetadataIsEmpty(root); - assertVarcharVectorValues((VarCharVector) root.getVector(CLOB), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(CLOB), + table.getRowCount(), getCharArrayWithCharSet(table.getValues(), CLOB, StandardCharsets.UTF_8)); - assertVarcharVectorValues((VarCharVector) root.getVector(VARCHAR), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(VARCHAR), + table.getRowCount(), getCharArrayWithCharSet(table.getValues(), VARCHAR, StandardCharsets.UTF_8)); - assertVarcharVectorValues((VarCharVector) root.getVector(CHAR), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(CHAR), + table.getRowCount(), getCharArrayWithCharSet(table.getValues(), CHAR, StandardCharsets.UTF_8)); } } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java index ae4fffd0f94..04f178cab28 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java @@ -40,7 +40,6 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; - import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -71,8 +70,8 @@ import org.junit.runners.Parameterized.Parameters; /** - * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with various data types - * for H2 database using multiple test data files. + * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with + * various data types for H2 database using multiple test data files. */ @RunWith(Parameterized.class) public class JdbcToArrowDataTypesTest extends AbstractJdbcToArrowTest { @@ -137,42 +136,59 @@ public JdbcToArrowDataTypesTest(Table table) { * @throws IOException on error */ @Parameters - public static Collection getTestData() throws SQLException, ClassNotFoundException, IOException { + public static Collection getTestData() + throws SQLException, ClassNotFoundException, IOException { return Arrays.asList(prepareTestData(testFiles, JdbcToArrowDataTypesTest.class)); } - /** - * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes. - */ + /** Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes. */ @Test public void testJdbcToArrowValues() throws SQLException, IOException { - testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), + false); testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new RootAllocator(Integer.MAX_VALUE), + Calendar.getInstance()), + false); testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery())), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE)), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()), false); - testDataSets(sqlToArrow( - conn.createStatement().executeQuery(table.getQuery()), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build()), false); - testDataSets(sqlToArrow( - conn, - table.getQuery(), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build()), false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new RootAllocator(Integer.MAX_VALUE)), + false); + testDataSets( + sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()), + false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build()), + false); + testDataSets( + sqlToArrow( + conn, + table.getQuery(), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build()), + false); } @Test public void testJdbcSchemaMetadata() throws SQLException { - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData(); Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config); JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema); @@ -182,77 +198,107 @@ public void testJdbcSchemaMetadata() throws SQLException { * This method calls the assert methods for various DataSets. * * @param root VectorSchemaRoot for test - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { JdbcToArrowTestHelper.assertFieldMetadataIsEmpty(root); switch (table.getType()) { case BIGINT: - assertBigIntVectorValues((BigIntVector) root.getVector(table.getVector()), table.getValues().length, + assertBigIntVectorValues( + (BigIntVector) root.getVector(table.getVector()), + table.getValues().length, table.getLongValues()); break; case BINARY: case BLOB: - assertVarBinaryVectorValues((VarBinaryVector) root.getVector(table.getVector()), table.getValues().length, + assertVarBinaryVectorValues( + (VarBinaryVector) root.getVector(table.getVector()), + table.getValues().length, table.getBinaryValues()); break; case BIT: - assertBitVectorValues((BitVector) root.getVector(table.getVector()), table.getValues().length, + assertBitVectorValues( + (BitVector) root.getVector(table.getVector()), + table.getValues().length, table.getIntValues()); break; case BOOL: - assertBooleanVectorValues((BitVector) root.getVector(table.getVector()), table.getValues().length, + assertBooleanVectorValues( + (BitVector) root.getVector(table.getVector()), + table.getValues().length, table.getBoolValues()); break; case CHAR: case VARCHAR: case CLOB: - assertVarcharVectorValues((VarCharVector) root.getVector(table.getVector()), table.getValues().length, + assertVarcharVectorValues( + (VarCharVector) root.getVector(table.getVector()), + table.getValues().length, table.getCharValues()); break; case DATE: - assertDateVectorValues((DateDayVector) root.getVector(table.getVector()), table.getValues().length, + assertDateVectorValues( + (DateDayVector) root.getVector(table.getVector()), + table.getValues().length, table.getIntValues()); break; case TIME: - assertTimeVectorValues((TimeMilliVector) root.getVector(table.getVector()), table.getValues().length, + assertTimeVectorValues( + (TimeMilliVector) root.getVector(table.getVector()), + table.getValues().length, table.getLongValues()); break; case TIMESTAMP: - assertTimeStampVectorValues((TimeStampVector) root.getVector(table.getVector()), table.getValues().length, + assertTimeStampVectorValues( + (TimeStampVector) root.getVector(table.getVector()), + table.getValues().length, table.getLongValues()); break; case DECIMAL: - assertDecimalVectorValues((DecimalVector) root.getVector(table.getVector()), table.getValues().length, + assertDecimalVectorValues( + (DecimalVector) root.getVector(table.getVector()), + table.getValues().length, table.getBigDecimalValues()); break; case DOUBLE: - assertFloat8VectorValues((Float8Vector) root.getVector(table.getVector()), table.getValues().length, + assertFloat8VectorValues( + (Float8Vector) root.getVector(table.getVector()), + table.getValues().length, table.getDoubleValues()); break; case INT: - assertIntVectorValues((IntVector) root.getVector(table.getVector()), table.getValues().length, + assertIntVectorValues( + (IntVector) root.getVector(table.getVector()), + table.getValues().length, table.getIntValues()); break; case SMALLINT: - assertSmallIntVectorValues((SmallIntVector) root.getVector(table.getVector()), table.getValues().length, + assertSmallIntVectorValues( + (SmallIntVector) root.getVector(table.getVector()), + table.getValues().length, table.getIntValues()); break; case TINYINT: - assertTinyIntVectorValues((TinyIntVector) root.getVector(table.getVector()), table.getValues().length, + assertTinyIntVectorValues( + (TinyIntVector) root.getVector(table.getVector()), + table.getValues().length, table.getIntValues()); break; case REAL: - assertFloat4VectorValues((Float4Vector) root.getVector(table.getVector()), table.getValues().length, + assertFloat4VectorValues( + (Float4Vector) root.getVector(table.getVector()), + table.getValues().length, table.getFloatValues()); break; case NULL: assertNullVectorValues((NullVector) root.getVector(table.getVector()), table.getRowCount()); break; case LIST: - assertListVectorValues((ListVector) root.getVector(table.getVector()), table.getValues().length, + assertListVectorValues( + (ListVector) root.getVector(table.getVector()), + table.getValues().length, table.getListValues()); break; default: @@ -261,4 +307,3 @@ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { } } } - diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowMapDataTypeTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowMapDataTypeTest.java index 43862a93c39..b516e2a19e9 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowMapDataTypeTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowMapDataTypeTest.java @@ -24,7 +24,6 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.Calendar; - import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; import org.apache.arrow.memory.RootAllocator; @@ -32,44 +31,46 @@ import org.apache.arrow.vector.complex.MapVector; import org.junit.Test; -/** - * Test MapConsumer with OTHER jdbc type. - */ +/** Test MapConsumer with OTHER jdbc type. */ public class JdbcToArrowMapDataTypeTest extends AbstractJdbcToArrowTest { public JdbcToArrowMapDataTypeTest() throws IOException { this.table = getTable("h2/test1_map_h2.yml", JdbcToArrowMapDataTypeTest.class); } - /** - * Test Method to test JdbcToArrow Functionality for Map form Types.OTHER column - */ + /** Test Method to test JdbcToArrow Functionality for Map form Types.OTHER column */ @Test public void testJdbcToArrowValues() throws SQLException, IOException { Calendar calendar = Calendar.getInstance(); ResultSetMetaData rsmd = getQueryMetaData(table.getQuery()); - testDataSets(sqlToArrow( + testDataSets( + sqlToArrow( conn.createStatement().executeQuery(table.getQuery()), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) - .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) - .build()), true); - testDataSets(sqlToArrow( + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) + .build()), + true); + testDataSets( + sqlToArrow( conn, table.getQuery(), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) - .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) - .build()), true); + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) + .build()), + true); } /** * This method calls the assert methods for various DataSets. * * @param root VectorSchemaRoot for test - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { - assertMapVectorValues((MapVector) root.getVector(MAP), table.getRowCount(), - getMapValues(table.getValues(), MAP)); + assertMapVectorValues( + (MapVector) root.getVector(MAP), table.getRowCount(), getMapValues(table.getValues(), MAP)); } } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java index 5731f27c5b3..cc4c8e5fa59 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java @@ -51,7 +51,6 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; - import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -82,8 +81,8 @@ import org.junit.runners.Parameterized.Parameters; /** - * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with null values for - * H2 database. + * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with + * null values for H2 database. */ @RunWith(Parameterized.class) public class JdbcToArrowNullTest extends AbstractJdbcToArrowTest { @@ -116,46 +115,66 @@ public JdbcToArrowNullTest(Table table) { * @throws IOException on error */ @Parameters - public static Collection getTestData() throws SQLException, ClassNotFoundException, IOException { + public static Collection getTestData() + throws SQLException, ClassNotFoundException, IOException { return Arrays.asList(prepareTestData(testFiles, JdbcToArrowNullTest.class)); } /** - * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with null values. + * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with null + * values. */ @Test public void testJdbcToArrowValues() throws SQLException, IOException { - testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), + false); testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new RootAllocator(Integer.MAX_VALUE), + Calendar.getInstance()), + false); testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery())), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE)), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new RootAllocator(Integer.MAX_VALUE)), + false); + testDataSets( + sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()), + false); Calendar calendar = Calendar.getInstance(); ResultSetMetaData rsmd = getQueryMetaData(table.getQuery()); - testDataSets(sqlToArrow( - conn.createStatement().executeQuery(table.getQuery()), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) - .build()), true); - testDataSets(sqlToArrow( - conn, - table.getQuery(), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) - .build()), true); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) + .build()), + true); + testDataSets( + sqlToArrow( + conn, + table.getQuery(), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) + .build()), + true); } @Test public void testJdbcSchemaMetadata() throws SQLException { - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData(); Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config); JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema); @@ -165,8 +184,8 @@ public void testJdbcSchemaMetadata() throws SQLException { * This method calls the assert methods for various DataSets. * * @param root VectorSchemaRoot for test - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { JdbcToArrowTestHelper.assertFieldMetadataIsEmpty(root); @@ -176,7 +195,8 @@ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { sqlToArrowTestNullValues(table.getVectors(), root, table.getRowCount()); break; case SELECTED_NULL_COLUMN: - sqlToArrowTestSelectedNullColumnsValues(table.getVectors(), root, table.getRowCount(), isIncludeMapVector); + sqlToArrowTestSelectedNullColumnsValues( + table.getVectors(), root, table.getRowCount(), isIncludeMapVector); break; case SELECTED_NULL_ROW: testAllVectorValues(root, isIncludeMapVector); @@ -190,62 +210,96 @@ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { private void testAllVectorValues(VectorSchemaRoot root, boolean isIncludeMapVector) { JdbcToArrowTestHelper.assertFieldMetadataIsEmpty(root); - assertBigIntVectorValues((BigIntVector) root.getVector(BIGINT), table.getRowCount(), + assertBigIntVectorValues( + (BigIntVector) root.getVector(BIGINT), + table.getRowCount(), getLongValues(table.getValues(), BIGINT)); - assertTinyIntVectorValues((TinyIntVector) root.getVector(TINYINT), table.getRowCount(), + assertTinyIntVectorValues( + (TinyIntVector) root.getVector(TINYINT), + table.getRowCount(), getIntValues(table.getValues(), TINYINT)); - assertSmallIntVectorValues((SmallIntVector) root.getVector(SMALLINT), table.getRowCount(), + assertSmallIntVectorValues( + (SmallIntVector) root.getVector(SMALLINT), + table.getRowCount(), getIntValues(table.getValues(), SMALLINT)); - assertVarBinaryVectorValues((VarBinaryVector) root.getVector(BINARY), table.getRowCount(), + assertVarBinaryVectorValues( + (VarBinaryVector) root.getVector(BINARY), + table.getRowCount(), getBinaryValues(table.getValues(), BINARY)); - assertVarBinaryVectorValues((VarBinaryVector) root.getVector(BLOB), table.getRowCount(), + assertVarBinaryVectorValues( + (VarBinaryVector) root.getVector(BLOB), + table.getRowCount(), getBinaryValues(table.getValues(), BLOB)); - assertVarcharVectorValues((VarCharVector) root.getVector(CLOB), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(CLOB), + table.getRowCount(), getCharArray(table.getValues(), CLOB)); - assertVarcharVectorValues((VarCharVector) root.getVector(VARCHAR), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(VARCHAR), + table.getRowCount(), getCharArray(table.getValues(), VARCHAR)); - assertVarcharVectorValues((VarCharVector) root.getVector(CHAR), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(CHAR), + table.getRowCount(), getCharArray(table.getValues(), CHAR)); - assertIntVectorValues((IntVector) root.getVector(INT), table.getRowCount(), - getIntValues(table.getValues(), INT)); + assertIntVectorValues( + (IntVector) root.getVector(INT), table.getRowCount(), getIntValues(table.getValues(), INT)); - assertBitVectorValues((BitVector) root.getVector(BIT), table.getRowCount(), - getIntValues(table.getValues(), BIT)); + assertBitVectorValues( + (BitVector) root.getVector(BIT), table.getRowCount(), getIntValues(table.getValues(), BIT)); - assertBooleanVectorValues((BitVector) root.getVector(BOOL), table.getRowCount(), + assertBooleanVectorValues( + (BitVector) root.getVector(BOOL), + table.getRowCount(), getBooleanValues(table.getValues(), BOOL)); - assertDateVectorValues((DateDayVector) root.getVector(DATE), table.getRowCount(), + assertDateVectorValues( + (DateDayVector) root.getVector(DATE), + table.getRowCount(), getIntValues(table.getValues(), DATE)); - assertTimeVectorValues((TimeMilliVector) root.getVector(TIME), table.getRowCount(), + assertTimeVectorValues( + (TimeMilliVector) root.getVector(TIME), + table.getRowCount(), getLongValues(table.getValues(), TIME)); - assertTimeStampVectorValues((TimeStampVector) root.getVector(TIMESTAMP), table.getRowCount(), + assertTimeStampVectorValues( + (TimeStampVector) root.getVector(TIMESTAMP), + table.getRowCount(), getLongValues(table.getValues(), TIMESTAMP)); - assertDecimalVectorValues((DecimalVector) root.getVector(DECIMAL), table.getRowCount(), + assertDecimalVectorValues( + (DecimalVector) root.getVector(DECIMAL), + table.getRowCount(), getDecimalValues(table.getValues(), DECIMAL)); - assertFloat8VectorValues((Float8Vector) root.getVector(DOUBLE), table.getRowCount(), + assertFloat8VectorValues( + (Float8Vector) root.getVector(DOUBLE), + table.getRowCount(), getDoubleValues(table.getValues(), DOUBLE)); - assertFloat4VectorValues((Float4Vector) root.getVector(REAL), table.getRowCount(), + assertFloat4VectorValues( + (Float4Vector) root.getVector(REAL), + table.getRowCount(), getFloatValues(table.getValues(), REAL)); - assertListVectorValues((ListVector) root.getVector(LIST), table.getRowCount(), + assertListVectorValues( + (ListVector) root.getVector(LIST), + table.getRowCount(), getListValues(table.getValues(), LIST)); if (isIncludeMapVector) { - assertMapVectorValues((MapVector) root.getVector(MAP), table.getRowCount(), - getMapValues(table.getValues(), MAP)); + assertMapVectorValues( + (MapVector) root.getVector(MAP), + table.getRowCount(), + getMapValues(table.getValues(), MAP)); } } @@ -283,11 +337,11 @@ public void sqlToArrowTestNullValues(String[] vectors, VectorSchemaRoot root, in * @param vectors Vectors to test * @param root VectorSchemaRoot for test * @param rowCount number of rows - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ - public void sqlToArrowTestSelectedNullColumnsValues(String[] vectors, VectorSchemaRoot root, int rowCount, - boolean isIncludeMapVector) { + public void sqlToArrowTestSelectedNullColumnsValues( + String[] vectors, VectorSchemaRoot root, int rowCount, boolean isIncludeMapVector) { assertNullValues((BigIntVector) root.getVector(vectors[0]), rowCount); assertNullValues((DecimalVector) root.getVector(vectors[1]), rowCount); assertNullValues((Float8Vector) root.getVector(vectors[2]), rowCount); @@ -306,5 +360,4 @@ public void sqlToArrowTestSelectedNullColumnsValues(String[] vectors, VectorSche assertNullValues((MapVector) root.getVector(vectors[14]), rowCount); } } - } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowOptionalColumnsTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowOptionalColumnsTest.java index eebcbe64c0e..0e11835c521 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowOptionalColumnsTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowOptionalColumnsTest.java @@ -24,7 +24,6 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Collection; - import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowTestHelper; import org.apache.arrow.adapter.jdbc.Table; @@ -40,9 +39,7 @@ */ @RunWith(Parameterized.class) public class JdbcToArrowOptionalColumnsTest extends AbstractJdbcToArrowTest { - private static final String[] testFiles = { - "h2/test1_null_and_notnull.yml" - }; + private static final String[] testFiles = {"h2/test1_null_and_notnull.yml"}; /** * Constructor which populates the table object for each test iteration. @@ -57,17 +54,19 @@ public JdbcToArrowOptionalColumnsTest(Table table) { * Get the test data as a collection of Table objects for each test iteration. * * @return Collection of Table objects - * @throws SQLException on error + * @throws SQLException on error * @throws ClassNotFoundException on error - * @throws IOException on error + * @throws IOException on error */ @Parameterized.Parameters - public static Collection getTestData() throws SQLException, ClassNotFoundException, IOException { + public static Collection getTestData() + throws SQLException, ClassNotFoundException, IOException { return Arrays.asList(prepareTestData(testFiles, JdbcToArrowOptionalColumnsTest.class)); } /** - * Test Method to test JdbcToArrow Functionality for dealing with nullable and non-nullable columns. + * Test Method to test JdbcToArrow Functionality for dealing with nullable and non-nullable + * columns. */ @Test public void testJdbcToArrowValues() throws SQLException, IOException { @@ -75,12 +74,13 @@ public void testJdbcToArrowValues() throws SQLException, IOException { } /** - * This method calls the assert methods for various DataSets. We verify that a SQL `NULL` column becomes - * nullable in the VectorSchemaRoot, and that a SQL `NOT NULL` column becomes non-nullable. + * This method calls the assert methods for various DataSets. We verify that a SQL `NULL` column + * becomes nullable in the VectorSchemaRoot, and that a SQL `NOT NULL` column becomes + * non-nullable. * * @param root VectorSchemaRoot for test - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { JdbcToArrowTestHelper.assertFieldMetadataIsEmpty(root); @@ -88,5 +88,4 @@ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { assertTrue(root.getSchema().getFields().get(0).isNullable()); assertFalse(root.getSchema().getFields().get(1).isNullable()); } - } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java index 7641fa7f165..16072c894a6 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java @@ -29,7 +29,6 @@ import java.util.Collection; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.ArrowVectorIterator; import org.apache.arrow.adapter.jdbc.JdbcToArrow; @@ -64,8 +63,8 @@ import org.junit.runners.Parameterized; /** - * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with various data types - * for H2 database using single test data file. + * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with + * various data types for H2 database using single test data file. */ @RunWith(Parameterized.class) public class JdbcToArrowTest extends AbstractJdbcToArrowTest { @@ -92,52 +91,71 @@ public JdbcToArrowTest(Table table, boolean reuseVectorSchemaRoot) { * @throws IOException on error */ @Parameterized.Parameters(name = "table = {0}, reuse batch = {1}") - public static Collection getTestData() throws SQLException, ClassNotFoundException, IOException { - return Arrays.stream(prepareTestData(testFiles, JdbcToArrowTest.class)).flatMap(row -> - Stream.of(new Object[] {row[0], true}, new Object[] {row[0], false})).collect(Collectors.toList()); + public static Collection getTestData() + throws SQLException, ClassNotFoundException, IOException { + return Arrays.stream(prepareTestData(testFiles, JdbcToArrowTest.class)) + .flatMap(row -> Stream.of(new Object[] {row[0], true}, new Object[] {row[0], false})) + .collect(Collectors.toList()); } /** - * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with only one test data file. + * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with only one + * test data file. */ @Test public void testJdbcToArrowValues() throws SQLException, IOException { - testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), + false); testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE)), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new RootAllocator(Integer.MAX_VALUE), + Calendar.getInstance()), + false); testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery())), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE)), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - Calendar.getInstance()), false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new RootAllocator(Integer.MAX_VALUE)), + false); + testDataSets( + sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()), + false); Calendar calendar = Calendar.getInstance(); ResultSetMetaData rsmd = getQueryMetaData(table.getQuery()); - testDataSets(sqlToArrow( - conn.createStatement().executeQuery(table.getQuery()), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) - .build()), true); - testDataSets(sqlToArrow( - conn, - table.getQuery(), - new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), calendar) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) - .build()), true); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) + .build()), + true); + testDataSets( + sqlToArrow( + conn, + table.getQuery(), + new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), calendar) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) + .build()), + true); } @Test public void testJdbcSchemaMetadata() throws SQLException { Calendar calendar = Calendar.getInstance(); ResultSetMetaData rsmd = getQueryMetaData(table.getQuery()); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar, true) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar, true) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setJdbcToArrowTypeConverter(jdbcToArrowTypeConverter(calendar, rsmd)) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config); JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema); } @@ -146,70 +164,104 @@ public void testJdbcSchemaMetadata() throws SQLException { * This method calls the assert methods for various DataSets. * * @param root VectorSchemaRoot for test - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { JdbcToArrowTestHelper.assertFieldMetadataIsEmpty(root); - assertBigIntVectorValues((BigIntVector) root.getVector(BIGINT), table.getRowCount(), + assertBigIntVectorValues( + (BigIntVector) root.getVector(BIGINT), + table.getRowCount(), getLongValues(table.getValues(), BIGINT)); - assertTinyIntVectorValues((TinyIntVector) root.getVector(TINYINT), table.getRowCount(), + assertTinyIntVectorValues( + (TinyIntVector) root.getVector(TINYINT), + table.getRowCount(), getIntValues(table.getValues(), TINYINT)); - assertSmallIntVectorValues((SmallIntVector) root.getVector(SMALLINT), table.getRowCount(), + assertSmallIntVectorValues( + (SmallIntVector) root.getVector(SMALLINT), + table.getRowCount(), getIntValues(table.getValues(), SMALLINT)); - assertVarBinaryVectorValues((VarBinaryVector) root.getVector(BINARY), table.getRowCount(), + assertVarBinaryVectorValues( + (VarBinaryVector) root.getVector(BINARY), + table.getRowCount(), getBinaryValues(table.getValues(), BINARY)); - assertVarBinaryVectorValues((VarBinaryVector) root.getVector(BLOB), table.getRowCount(), + assertVarBinaryVectorValues( + (VarBinaryVector) root.getVector(BLOB), + table.getRowCount(), getBinaryValues(table.getValues(), BLOB)); - assertVarcharVectorValues((VarCharVector) root.getVector(CLOB), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(CLOB), + table.getRowCount(), getCharArray(table.getValues(), CLOB)); - assertVarcharVectorValues((VarCharVector) root.getVector(VARCHAR), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(VARCHAR), + table.getRowCount(), getCharArray(table.getValues(), VARCHAR)); - assertVarcharVectorValues((VarCharVector) root.getVector(CHAR), table.getRowCount(), + assertVarcharVectorValues( + (VarCharVector) root.getVector(CHAR), + table.getRowCount(), getCharArray(table.getValues(), CHAR)); - assertIntVectorValues((IntVector) root.getVector(INT), table.getRowCount(), - getIntValues(table.getValues(), INT)); + assertIntVectorValues( + (IntVector) root.getVector(INT), table.getRowCount(), getIntValues(table.getValues(), INT)); - assertBitVectorValues((BitVector) root.getVector(BIT), table.getRowCount(), - getIntValues(table.getValues(), BIT)); + assertBitVectorValues( + (BitVector) root.getVector(BIT), table.getRowCount(), getIntValues(table.getValues(), BIT)); - assertBooleanVectorValues((BitVector) root.getVector(BOOL), table.getRowCount(), + assertBooleanVectorValues( + (BitVector) root.getVector(BOOL), + table.getRowCount(), getBooleanValues(table.getValues(), BOOL)); - assertDateVectorValues((DateDayVector) root.getVector(DATE), table.getRowCount(), + assertDateVectorValues( + (DateDayVector) root.getVector(DATE), + table.getRowCount(), getIntValues(table.getValues(), DATE)); - assertTimeVectorValues((TimeMilliVector) root.getVector(TIME), table.getRowCount(), + assertTimeVectorValues( + (TimeMilliVector) root.getVector(TIME), + table.getRowCount(), getLongValues(table.getValues(), TIME)); - assertTimeStampVectorValues((TimeStampVector) root.getVector(TIMESTAMP), table.getRowCount(), + assertTimeStampVectorValues( + (TimeStampVector) root.getVector(TIMESTAMP), + table.getRowCount(), getLongValues(table.getValues(), TIMESTAMP)); - assertDecimalVectorValues((DecimalVector) root.getVector(DECIMAL), table.getRowCount(), + assertDecimalVectorValues( + (DecimalVector) root.getVector(DECIMAL), + table.getRowCount(), getDecimalValues(table.getValues(), DECIMAL)); - assertFloat8VectorValues((Float8Vector) root.getVector(DOUBLE), table.getRowCount(), + assertFloat8VectorValues( + (Float8Vector) root.getVector(DOUBLE), + table.getRowCount(), getDoubleValues(table.getValues(), DOUBLE)); - assertFloat4VectorValues((Float4Vector) root.getVector(REAL), table.getRowCount(), + assertFloat4VectorValues( + (Float4Vector) root.getVector(REAL), + table.getRowCount(), getFloatValues(table.getValues(), REAL)); assertNullVectorValues((NullVector) root.getVector(NULL), table.getRowCount()); - assertListVectorValues((ListVector) root.getVector(LIST), table.getRowCount(), + assertListVectorValues( + (ListVector) root.getVector(LIST), + table.getRowCount(), getListValues(table.getValues(), LIST)); if (isIncludeMapVector) { - assertMapVectorValues((MapVector) root.getVector(MAP), table.getRowCount(), - getMapValues(table.getValues(), MAP)); + assertMapVectorValues( + (MapVector) root.getVector(MAP), + table.getRowCount(), + getMapValues(table.getValues(), MAP)); } } @@ -219,11 +271,12 @@ public void runLargeNumberOfRows() throws IOException, SQLException { int x = 0; final int targetRows = 600000; ResultSet rs = ResultSetUtility.generateBasicResultSet(targetRows); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder( - allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder( + allocator, JdbcToArrowUtils.getUtcCalendar(), /* include metadata */ false) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(rs, config)) { while (iter.hasNext()) { diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java index 462a75da514..44be281712a 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java @@ -28,7 +28,6 @@ import java.util.Calendar; import java.util.Collection; import java.util.TimeZone; - import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder; @@ -47,10 +46,9 @@ import org.junit.runners.Parameterized.Parameters; /** - * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with TimeZone based Date, - * Time and Timestamp datatypes for H2 database. + * JUnit Test Class which contains methods to test JDBC to Arrow data conversion functionality with + * TimeZone based Date, Time and Timestamp datatypes for H2 database. */ - @RunWith(Parameterized.class) public class JdbcToArrowTimeZoneTest extends AbstractJdbcToArrowTest { @@ -94,39 +92,59 @@ public JdbcToArrowTimeZoneTest(Table table) { * @throws IOException on error */ @Parameters - public static Collection getTestData() throws SQLException, ClassNotFoundException, IOException { + public static Collection getTestData() + throws SQLException, ClassNotFoundException, IOException { return Arrays.asList(prepareTestData(testFiles, JdbcToArrowTimeZoneTest.class)); } /** - * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with TimeZone based Date, - * Time and Timestamp datatype. + * Test Method to test JdbcToArrow Functionality for various H2 DB based datatypes with TimeZone + * based Date, Time and Timestamp datatype. */ @Test public void testJdbcToArrowValues() throws SQLException, IOException { - testDataSets(sqlToArrow(conn, table.getQuery(), new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))), false); - testDataSets(sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), - Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))), false); - testDataSets(sqlToArrow( - conn.createStatement().executeQuery(table.getQuery()), - new JdbcToArrowConfigBuilder( + testDataSets( + sqlToArrow( + conn, + table.getQuery(), new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))).build()), false); - testDataSets(sqlToArrow( - conn, - table.getQuery(), - new JdbcToArrowConfigBuilder( + Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))), + false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))).build()), false); + Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))), + false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))), + false); + testDataSets( + sqlToArrow( + conn.createStatement().executeQuery(table.getQuery()), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), + Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))) + .build()), + false); + testDataSets( + sqlToArrow( + conn, + table.getQuery(), + new JdbcToArrowConfigBuilder( + new RootAllocator(Integer.MAX_VALUE), + Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))) + .build()), + false); } @Test public void testJdbcSchemaMetadata() throws SQLException { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone())); - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar, true).build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar, true).build(); ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData(); Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config); JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema); @@ -136,8 +154,8 @@ public void testJdbcSchemaMetadata() throws SQLException { * This method calls the assert methods for various DataSets. * * @param root VectorSchemaRoot for test - * @param isIncludeMapVector is this dataset checks includes map column. - * Jdbc type to 'map' mapping declared in configuration only manually + * @param isIncludeMapVector is this dataset checks includes map column. Jdbc type to 'map' + * mapping declared in configuration only manually */ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { JdbcToArrowTestHelper.assertFieldMetadataIsEmpty(root); @@ -146,19 +164,25 @@ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { case EST_DATE: case GMT_DATE: case PST_DATE: - assertDateVectorValues((DateDayVector) root.getVector(table.getVector()), table.getValues().length, + assertDateVectorValues( + (DateDayVector) root.getVector(table.getVector()), + table.getValues().length, table.getIntValues()); break; case EST_TIME: case GMT_TIME: case PST_TIME: - assertTimeVectorValues((TimeMilliVector) root.getVector(table.getVector()), table.getValues().length, + assertTimeVectorValues( + (TimeMilliVector) root.getVector(table.getVector()), + table.getValues().length, table.getLongValues()); break; case EST_TIMESTAMP: case GMT_TIMESTAMP: case PST_TIMESTAMP: - assertTimeStampVectorValues((TimeStampVector) root.getVector(table.getVector()), table.getValues().length, + assertTimeStampVectorValues( + (TimeStampVector) root.getVector(table.getVector()), + table.getValues().length, table.getLongValues()); break; default: @@ -166,5 +190,4 @@ public void testDataSets(VectorSchemaRoot root, boolean isIncludeMapVector) { break; } } - } diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowVectorIteratorTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowVectorIteratorTest.java index 1d7e2760f84..3a3c781646a 100644 --- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowVectorIteratorTest.java +++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowVectorIteratorTest.java @@ -42,7 +42,6 @@ import java.util.Arrays; import java.util.Calendar; import java.util.List; - import org.apache.arrow.adapter.jdbc.ArrowVectorIterator; import org.apache.arrow.adapter.jdbc.JdbcToArrow; import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig; @@ -91,14 +90,15 @@ public JdbcToArrowVectorIteratorTest(Table table, boolean reuseVectorSchemaRoot) @Test @Override public void testJdbcToArrowValues() throws SQLException, IOException { - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()) - .setTargetBatchSize(3) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setTargetBatchSize(3) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); ArrowVectorIterator iterator = - JdbcToArrow.sqlToArrowVectorIterator(conn.createStatement().executeQuery(table.getQuery()), config); + JdbcToArrow.sqlToArrowVectorIterator( + conn.createStatement().executeQuery(table.getQuery()), config); validate(iterator); } @@ -106,27 +106,28 @@ public void testJdbcToArrowValues() throws SQLException, IOException { @Test public void testVectorSchemaRootReuse() throws SQLException, IOException { Integer[][] intValues = { - {101, 102, 103}, - {104, null, null}, - {107, 108, 109}, - {110} + {101, 102, 103}, + {104, null, null}, + {107, 108, 109}, + {110} }; Integer[][][] listValues = { - {{1, 2, 3}, {1, 2}, {1}}, - {{2, 3, 4}, {2, 3}, {2}}, - {{3, 4, 5}, {3, 4}, {3}}, - {{}} + {{1, 2, 3}, {1, 2}, {1}}, + {{2, 3, 4}, {2, 3}, {2}}, + {{3, 4, 5}, {3, 4}, {3}}, + {{}} }; - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()) - .setTargetBatchSize(3) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setTargetBatchSize(3) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); ArrowVectorIterator iterator = - JdbcToArrow.sqlToArrowVectorIterator(conn.createStatement().executeQuery(table.getQuery()), config); + JdbcToArrow.sqlToArrowVectorIterator( + conn.createStatement().executeQuery(table.getQuery()), config); int batchCount = 0; VectorSchemaRoot prev = null; @@ -178,14 +179,15 @@ public void testVectorSchemaRootReuse() throws SQLException, IOException { @Test public void testJdbcToArrowValuesNoLimit() throws SQLException, IOException { - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()) - .setTargetBatchSize(JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setTargetBatchSize(JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); ArrowVectorIterator iterator = - JdbcToArrow.sqlToArrowVectorIterator(conn.createStatement().executeQuery(table.getQuery()), config); + JdbcToArrow.sqlToArrowVectorIterator( + conn.createStatement().executeQuery(table.getQuery()), config); validate(iterator); } @@ -195,12 +197,12 @@ public void testTimeStampConsumer() throws SQLException, IOException { final String sql = "select timestamp_field11 from table1"; // first experiment, with calendar and time zone. - JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()) - .setTargetBatchSize(3) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + JdbcToArrowConfig config = + new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setTargetBatchSize(3) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); assertNotNull(config.getCalendar()); try (ArrowVectorIterator iterator = @@ -213,16 +215,16 @@ public void testTimeStampConsumer() throws SQLException, IOException { } // second experiment, without calendar and time zone. - config = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), - null) - .setTargetBatchSize(3) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) - .build(); + config = + new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), null) + .setTargetBatchSize(3) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP) + .build(); assertNull(config.getCalendar()); try (ArrowVectorIterator iterator = - JdbcToArrow.sqlToArrowVectorIterator(conn.createStatement().executeQuery(sql), config)) { + JdbcToArrow.sqlToArrowVectorIterator(conn.createStatement().executeQuery(sql), config)) { VectorSchemaRoot root = iterator.next(); assertEquals(1, root.getFieldVectors().size()); @@ -278,24 +280,40 @@ private void validate(ArrowVectorIterator iterator) throws SQLException, IOExcep float8Vectors.add((Float8Vector) root.getVector(DOUBLE)); listVectors.add((ListVector) root.getVector(LIST)); } - assertBigIntVectorValues(bigIntVectors, table.getRowCount(), getLongValues(table.getValues(), BIGINT)); - assertTinyIntVectorValues(tinyIntVectors, table.getRowCount(), getIntValues(table.getValues(), TINYINT)); + assertBigIntVectorValues( + bigIntVectors, table.getRowCount(), getLongValues(table.getValues(), BIGINT)); + assertTinyIntVectorValues( + tinyIntVectors, table.getRowCount(), getIntValues(table.getValues(), TINYINT)); assertIntVectorValues(intVectors, table.getRowCount(), getIntValues(table.getValues(), INT)); - assertSmallIntVectorValues(smallIntVectors, table.getRowCount(), getIntValues(table.getValues(), SMALLINT)); - assertBinaryVectorValues(vectorsForBinary, table.getRowCount(), getBinaryValues(table.getValues(), BINARY)); - assertBinaryVectorValues(vectorsForBlob, table.getRowCount(), getBinaryValues(table.getValues(), BLOB)); - assertVarCharVectorValues(vectorsForClob, table.getRowCount(), getCharArray(table.getValues(), CLOB)); - assertVarCharVectorValues(vectorsForVarChar, table.getRowCount(), getCharArray(table.getValues(), VARCHAR)); - assertVarCharVectorValues(vectorsForChar, table.getRowCount(), getCharArray(table.getValues(), CHAR)); + assertSmallIntVectorValues( + smallIntVectors, table.getRowCount(), getIntValues(table.getValues(), SMALLINT)); + assertBinaryVectorValues( + vectorsForBinary, table.getRowCount(), getBinaryValues(table.getValues(), BINARY)); + assertBinaryVectorValues( + vectorsForBlob, table.getRowCount(), getBinaryValues(table.getValues(), BLOB)); + assertVarCharVectorValues( + vectorsForClob, table.getRowCount(), getCharArray(table.getValues(), CLOB)); + assertVarCharVectorValues( + vectorsForVarChar, table.getRowCount(), getCharArray(table.getValues(), VARCHAR)); + assertVarCharVectorValues( + vectorsForChar, table.getRowCount(), getCharArray(table.getValues(), CHAR)); assertBitVectorValues(vectorsForBit, table.getRowCount(), getIntValues(table.getValues(), BIT)); - assertBooleanVectorValues(vectorsForBool, table.getRowCount(), getBooleanValues(table.getValues(), BOOL)); - assertDateDayVectorValues(dateDayVectors, table.getRowCount(), getLongValues(table.getValues(), DATE)); - assertTimeMilliVectorValues(timeMilliVectors, table.getRowCount(), getLongValues(table.getValues(), TIME)); - assertTimeStampVectorValues(timeStampVectors, table.getRowCount(), getLongValues(table.getValues(), TIMESTAMP)); - assertDecimalVectorValues(decimalVectors, table.getRowCount(), getDecimalValues(table.getValues(), DECIMAL)); - assertFloat4VectorValues(float4Vectors, table.getRowCount(), getFloatValues(table.getValues(), REAL)); - assertFloat8VectorValues(float8Vectors, table.getRowCount(), getDoubleValues(table.getValues(), DOUBLE)); - assertListVectorValues(listVectors, table.getRowCount(), getListValues(table.getValues(), LIST)); + assertBooleanVectorValues( + vectorsForBool, table.getRowCount(), getBooleanValues(table.getValues(), BOOL)); + assertDateDayVectorValues( + dateDayVectors, table.getRowCount(), getLongValues(table.getValues(), DATE)); + assertTimeMilliVectorValues( + timeMilliVectors, table.getRowCount(), getLongValues(table.getValues(), TIME)); + assertTimeStampVectorValues( + timeStampVectors, table.getRowCount(), getLongValues(table.getValues(), TIMESTAMP)); + assertDecimalVectorValues( + decimalVectors, table.getRowCount(), getDecimalValues(table.getValues(), DECIMAL)); + assertFloat4VectorValues( + float4Vectors, table.getRowCount(), getFloatValues(table.getValues(), REAL)); + assertFloat8VectorValues( + float8Vectors, table.getRowCount(), getDoubleValues(table.getValues(), DOUBLE)); + assertListVectorValues( + listVectors, table.getRowCount(), getListValues(table.getValues(), LIST)); roots.forEach(root -> root.close()); } @@ -324,7 +342,8 @@ private void assertFloat4VectorValues(List vectors, int rowCount, } } - private void assertDecimalVectorValues(List vectors, int rowCount, BigDecimal[] values) { + private void assertDecimalVectorValues( + List vectors, int rowCount, BigDecimal[] values) { int valueCount = vectors.stream().mapToInt(ValueVector::getValueCount).sum(); assertEquals(rowCount, valueCount); @@ -337,7 +356,8 @@ private void assertDecimalVectorValues(List vectors, int rowCount } } - private void assertTimeStampVectorValues(List vectors, int rowCount, Long[] values) { + private void assertTimeStampVectorValues( + List vectors, int rowCount, Long[] values) { int valueCount = vectors.stream().mapToInt(ValueVector::getValueCount).sum(); assertEquals(rowCount, valueCount); @@ -349,7 +369,8 @@ private void assertTimeStampVectorValues(List vectors, int rowC } } - private void assertTimeMilliVectorValues(List vectors, int rowCount, Long[] values) { + private void assertTimeMilliVectorValues( + List vectors, int rowCount, Long[] values) { int valueCount = vectors.stream().mapToInt(ValueVector::getValueCount).sum(); assertEquals(rowCount, valueCount); @@ -397,7 +418,8 @@ private void assertBooleanVectorValues(List vectors, int rowCount, Bo } } - private void assertVarCharVectorValues(List vectors, int rowCount, byte[][] values) { + private void assertVarCharVectorValues( + List vectors, int rowCount, byte[][] values) { int valueCount = vectors.stream().mapToInt(ValueVector::getValueCount).sum(); assertEquals(rowCount, valueCount); @@ -409,7 +431,8 @@ private void assertVarCharVectorValues(List vectors, int rowCount } } - private void assertBinaryVectorValues(List vectors, int rowCount, byte[][] values) { + private void assertBinaryVectorValues( + List vectors, int rowCount, byte[][] values) { int valueCount = vectors.stream().mapToInt(ValueVector::getValueCount).sum(); assertEquals(rowCount, valueCount); @@ -421,7 +444,8 @@ private void assertBinaryVectorValues(List vectors, int rowCoun } } - private void assertSmallIntVectorValues(List vectors, int rowCount, Integer[] values) { + private void assertSmallIntVectorValues( + List vectors, int rowCount, Integer[] values) { int valueCount = vectors.stream().mapToInt(ValueVector::getValueCount).sum(); assertEquals(rowCount, valueCount); @@ -433,7 +457,8 @@ private void assertSmallIntVectorValues(List vectors, int rowCou } } - private void assertTinyIntVectorValues(List vectors, int rowCount, Integer[] values) { + private void assertTinyIntVectorValues( + List vectors, int rowCount, Integer[] values) { int valueCount = vectors.stream().mapToInt(ValueVector::getValueCount).sum(); assertEquals(rowCount, valueCount); @@ -474,7 +499,8 @@ private void assertIntVectorValues(List vectors, int rowCount, Intege } } - public static void assertListVectorValues(List vectors, int rowCount, Integer[][] values) { + public static void assertListVectorValues( + List vectors, int rowCount, Integer[][] values) { int valueCount = vectors.stream().mapToInt(ValueVector::getValueCount).sum(); assertEquals(rowCount, valueCount); @@ -492,12 +518,11 @@ public static void assertListVectorValues(List vectors, int rowCount } } - /** - * Runs a simple query, and encapsulates the result into a field vector. - */ + /** Runs a simple query, and encapsulates the result into a field vector. */ private FieldVector getQueryResult(JdbcToArrowConfig config) throws SQLException, IOException { - ArrowVectorIterator iterator = JdbcToArrow.sqlToArrowVectorIterator( - conn.createStatement().executeQuery("select real_field8 from table1"), config); + ArrowVectorIterator iterator = + JdbcToArrow.sqlToArrowVectorIterator( + conn.createStatement().executeQuery("select real_field8 from table1"), config); VectorSchemaRoot root = iterator.next(); @@ -513,10 +538,11 @@ private FieldVector getQueryResult(JdbcToArrowConfig config) throws SQLException @Test public void testJdbcToArrowCustomTypeConversion() throws SQLException, IOException { - JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), - Calendar.getInstance()).setTargetBatchSize(JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE) - .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) - .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP); + JdbcToArrowConfigBuilder builder = + new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()) + .setTargetBatchSize(JdbcToArrowConfig.NO_LIMIT_BATCH_SIZE) + .setReuseVectorSchemaRoot(reuseVectorSchemaRoot) + .setArraySubTypeByColumnNameMap(ARRAY_SUB_TYPE_BY_COLUMN_NAME_MAP); // first experiment, using default type converter JdbcToArrowConfig config = builder.build(); @@ -527,15 +553,16 @@ public void testJdbcToArrowCustomTypeConversion() throws SQLException, IOExcepti } // second experiment, using customized type converter - builder.setJdbcToArrowTypeConverter((fieldInfo) -> { - switch (fieldInfo.getJdbcType()) { - case Types.REAL: - // this is different from the default type converter - return new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE); - default: - return null; - } - }); + builder.setJdbcToArrowTypeConverter( + (fieldInfo) -> { + switch (fieldInfo.getJdbcType()) { + case Types.REAL: + // this is different from the default type converter + return new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE); + default: + return null; + } + }); config = builder.build(); try (FieldVector vector = getQueryResult(config)) { diff --git a/java/adapter/jdbc/src/test/resources/logback.xml b/java/adapter/jdbc/src/test/resources/logback.xml index 4c54d18a210..9fa3f1e3b43 100644 --- a/java/adapter/jdbc/src/test/resources/logback.xml +++ b/java/adapter/jdbc/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/adapter/orc/pom.xml b/java/adapter/orc/pom.xml index 605b9871639..b14e9a0644d 100644 --- a/java/adapter/orc/pom.xml +++ b/java/adapter/orc/pom.xml @@ -1,15 +1,14 @@ - + 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. --> diff --git a/java/algorithm/pom.xml b/java/algorithm/pom.xml index 99740f20028..fcbd2c9f0b2 100644 --- a/java/algorithm/pom.xml +++ b/java/algorithm/pom.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/compression/pom.xml b/java/compression/pom.xml index e8008c97543..3087294ea94 100644 --- a/java/compression/pom.xml +++ b/java/compression/pom.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/flight/flight-core/pom.xml b/java/flight/flight-core/pom.xml index ec3034d14e2..4ef7db7a856 100644 --- a/java/flight/flight-core/pom.xml +++ b/java/flight/flight-core/pom.xml @@ -1,4 +1,4 @@ - + - endpoints = Collections.singletonList( - FlightEndpoint.builder( - new Ticket("".getBytes(StandardCharsets.UTF_8))).setAppMetadata(cmd).build()); + Schema schema = + new Schema( + Collections.singletonList( + Field.notNullable("number", Types.MinorType.UINT4.getType()))); + + List endpoints = + Collections.singletonList( + FlightEndpoint.builder(new Ticket("".getBytes(StandardCharsets.UTF_8))) + .setAppMetadata(cmd) + .build()); return FlightInfo.builder(schema, descriptor, endpoints).setAppMetadata(cmd).build(); } } } - - diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/AuthBasicProtoScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/AuthBasicProtoScenario.java index 1c95d4d5593..891bde3e40d 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/AuthBasicProtoScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/AuthBasicProtoScenario.java @@ -20,7 +20,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Optional; - import org.apache.arrow.flight.Action; import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.FlightClient; @@ -35,9 +34,7 @@ import org.apache.arrow.flight.auth.BasicServerAuthHandler; import org.apache.arrow.memory.BufferAllocator; -/** - * A scenario testing the built-in basic authentication Protobuf. - */ +/** A scenario testing the built-in basic authentication Protobuf. */ final class AuthBasicProtoScenario implements Scenario { static final String USERNAME = "arrow"; @@ -56,34 +53,40 @@ public void doAction(CallContext context, Action action, StreamListener @Override public void buildServer(FlightServer.Builder builder) { - builder.authHandler(new BasicServerAuthHandler(new BasicServerAuthHandler.BasicAuthValidator() { - @Override - public byte[] getToken(String username, String password) throws Exception { - if (!USERNAME.equals(username) || !PASSWORD.equals(password)) { - throw CallStatus.UNAUTHENTICATED.withDescription("Username or password is invalid.").toRuntimeException(); - } - return ("valid:" + username).getBytes(StandardCharsets.UTF_8); - } + builder.authHandler( + new BasicServerAuthHandler( + new BasicServerAuthHandler.BasicAuthValidator() { + @Override + public byte[] getToken(String username, String password) throws Exception { + if (!USERNAME.equals(username) || !PASSWORD.equals(password)) { + throw CallStatus.UNAUTHENTICATED + .withDescription("Username or password is invalid.") + .toRuntimeException(); + } + return ("valid:" + username).getBytes(StandardCharsets.UTF_8); + } - @Override - public Optional isValid(byte[] token) { - if (token != null) { - final String credential = new String(token, StandardCharsets.UTF_8); - if (credential.startsWith("valid:")) { - return Optional.of(credential.substring(6)); - } - } - return Optional.empty(); - } - })); + @Override + public Optional isValid(byte[] token) { + if (token != null) { + final String credential = new String(token, StandardCharsets.UTF_8); + if (credential.startsWith("valid:")) { + return Optional.of(credential.substring(6)); + } + } + return Optional.empty(); + } + })); } @Override public void client(BufferAllocator allocator, Location location, FlightClient client) { - final FlightRuntimeException e = IntegrationAssertions.assertThrows(FlightRuntimeException.class, () -> { - client.listActions().forEach(act -> { - }); - }); + final FlightRuntimeException e = + IntegrationAssertions.assertThrows( + FlightRuntimeException.class, + () -> { + client.listActions().forEach(act -> {}); + }); if (!FlightStatusCode.UNAUTHENTICATED.equals(e.status().code())) { throw new AssertionError("Expected UNAUTHENTICATED but found " + e.status().code(), e); } @@ -91,7 +94,8 @@ public void client(BufferAllocator allocator, Location location, FlightClient cl client.authenticate(new BasicClientAuthHandler(USERNAME, PASSWORD)); final Result result = client.doAction(new Action("")).next(); if (!USERNAME.equals(new String(result.getBody(), StandardCharsets.UTF_8))) { - throw new AssertionError("Expected " + USERNAME + " but got " + Arrays.toString(result.getBody())); + throw new AssertionError( + "Expected " + USERNAME + " but got " + Arrays.toString(result.getBody())); } } } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeCancelFlightInfoScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeCancelFlightInfoScenario.java index 244f4373b29..d6b128b1614 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeCancelFlightInfoScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeCancelFlightInfoScenario.java @@ -18,7 +18,6 @@ package org.apache.arrow.flight.integration.tests; import java.nio.charset.StandardCharsets; - import org.apache.arrow.flight.CancelFlightInfoRequest; import org.apache.arrow.flight.CancelFlightInfoResult; import org.apache.arrow.flight.CancelStatus; @@ -41,24 +40,26 @@ public FlightProducer producer(BufferAllocator allocator, Location location) thr } @Override - public void buildServer(FlightServer.Builder builder) { - } + public void buildServer(FlightServer.Builder builder) {} @Override - public void client(BufferAllocator allocator, Location location, FlightClient client) throws Exception { - FlightInfo info = client.getInfo(FlightDescriptor.command("expiration".getBytes(StandardCharsets.UTF_8))); + public void client(BufferAllocator allocator, Location location, FlightClient client) + throws Exception { + FlightInfo info = + client.getInfo(FlightDescriptor.command("expiration".getBytes(StandardCharsets.UTF_8))); CancelFlightInfoRequest request = new CancelFlightInfoRequest(info); CancelFlightInfoResult result = client.cancelFlightInfo(request); IntegrationAssertions.assertEquals(CancelStatus.CANCELLED, result.getStatus()); // All requests should fail for (FlightEndpoint endpoint : info.getEndpoints()) { - IntegrationAssertions.assertThrows(FlightRuntimeException.class, () -> { - try (FlightStream stream = client.getStream(endpoint.getTicket())) { - while (stream.next()) { - } - } - }); + IntegrationAssertions.assertThrows( + FlightRuntimeException.class, + () -> { + try (FlightStream stream = client.getStream(endpoint.getTicket())) { + while (stream.next()) {} + } + }); } } } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeDoGetScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeDoGetScenario.java index 504836b334e..9c7a781ce06 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeDoGetScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeDoGetScenario.java @@ -20,7 +20,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightDescriptor; import org.apache.arrow.flight.FlightEndpoint; @@ -45,22 +44,26 @@ public FlightProducer producer(BufferAllocator allocator, Location location) thr } @Override - public void buildServer(FlightServer.Builder builder) { - } + public void buildServer(FlightServer.Builder builder) {} @Override - public void client(BufferAllocator allocator, Location location, FlightClient client) throws Exception { - FlightInfo info = client.getInfo(FlightDescriptor.command("expiration_time".getBytes(StandardCharsets.UTF_8))); + public void client(BufferAllocator allocator, Location location, FlightClient client) + throws Exception { + FlightInfo info = + client.getInfo( + FlightDescriptor.command("expiration_time".getBytes(StandardCharsets.UTF_8))); List batches = new ArrayList<>(); try { for (FlightEndpoint endpoint : info.getEndpoints()) { if (batches.size() == 0) { - IntegrationAssertions.assertFalse("endpoints[0] must not have expiration time", + IntegrationAssertions.assertFalse( + "endpoints[0] must not have expiration time", endpoint.getExpirationTime().isPresent()); } else { - IntegrationAssertions.assertTrue("endpoints[" + batches.size() + "] must have expiration time", + IntegrationAssertions.assertTrue( + "endpoints[" + batches.size() + "] must have expiration time", endpoint.getExpirationTime().isPresent()); } try (FlightStream stream = client.getStream(endpoint.getTicket())) { @@ -72,7 +75,8 @@ public void client(BufferAllocator allocator, Location location, FlightClient cl // Check data IntegrationAssertions.assertEquals(3, batches.size()); - try (final VectorSchemaRoot root = VectorSchemaRoot.create(ExpirationTimeProducer.SCHEMA, allocator)) { + try (final VectorSchemaRoot root = + VectorSchemaRoot.create(ExpirationTimeProducer.SCHEMA, allocator)) { final VectorLoader loader = new VectorLoader(root); loader.load(batches.get(0)); diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeListActionsScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeListActionsScenario.java index 26c4e7b604d..c618d01f291 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeListActionsScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeListActionsScenario.java @@ -18,7 +18,6 @@ package org.apache.arrow.flight.integration.tests; import java.util.Iterator; - import org.apache.arrow.flight.ActionType; import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightConstants; @@ -35,19 +34,21 @@ public FlightProducer producer(BufferAllocator allocator, Location location) thr } @Override - public void buildServer(FlightServer.Builder builder) { - } + public void buildServer(FlightServer.Builder builder) {} @Override - public void client(BufferAllocator allocator, Location location, FlightClient client) throws Exception { + public void client(BufferAllocator allocator, Location location, FlightClient client) + throws Exception { Iterator actions = client.listActions().iterator(); IntegrationAssertions.assertTrue("Expected 2 actions", actions.hasNext()); ActionType action = actions.next(); - IntegrationAssertions.assertEquals(FlightConstants.CANCEL_FLIGHT_INFO.getType(), action.getType()); + IntegrationAssertions.assertEquals( + FlightConstants.CANCEL_FLIGHT_INFO.getType(), action.getType()); IntegrationAssertions.assertTrue("Expected 2 actions", actions.hasNext()); action = actions.next(); - IntegrationAssertions.assertEquals(FlightConstants.RENEW_FLIGHT_ENDPOINT.getType(), action.getType()); + IntegrationAssertions.assertEquals( + FlightConstants.RENEW_FLIGHT_ENDPOINT.getType(), action.getType()); IntegrationAssertions.assertFalse("Expected 2 actions", actions.hasNext()); } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeProducer.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeProducer.java index 7838667e4d2..b33a8a49193 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeProducer.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeProducer.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; - import org.apache.arrow.flight.Action; import org.apache.arrow.flight.ActionType; import org.apache.arrow.flight.CallStatus; @@ -49,35 +48,32 @@ import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.Schema; -/** The server used for testing FlightEndpoint.expiration_time. - *

- * GetFlightInfo() returns a FlightInfo that has the following - * three FlightEndpoints: +/** + * The server used for testing FlightEndpoint.expiration_time. + * + *

GetFlightInfo() returns a FlightInfo that has the following three FlightEndpoints: * *

    - *
  1. No expiration time
  2. - *
  3. 5 seconds expiration time
  4. - *
  5. 6 seconds expiration time
  6. + *
  7. No expiration time + *
  8. 5 seconds expiration time + *
  9. 6 seconds expiration time *
* - * The client can't read data from the first endpoint multiple times - * but can read data from the second and third endpoints. The client - * can't re-read data from the second endpoint 5 seconds later. The - * client can't re-read data from the third endpoint 6 seconds - * later. - *

- * The client can cancel a returned FlightInfo by pre-defined - * CancelFlightInfo action. The client can't read data from endpoints - * even within 6 seconds after the action. - *

- * The client can extend the expiration time of a FlightEndpoint in - * a returned FlightInfo by pre-defined RenewFlightEndpoint - * action. The client can read data from endpoints multiple times + * The client can't read data from the first endpoint multiple times but can read data from the + * second and third endpoints. The client can't re-read data from the second endpoint 5 seconds + * later. The client can't re-read data from the third endpoint 6 seconds later. + * + *

The client can cancel a returned FlightInfo by pre-defined CancelFlightInfo action. The client + * can't read data from endpoints even within 6 seconds after the action. + * + *

The client can extend the expiration time of a FlightEndpoint in a returned FlightInfo by + * pre-defined RenewFlightEndpoint action. The client can read data from endpoints multiple times * within more 10 seconds after the action. */ final class ExpirationTimeProducer extends NoOpFlightProducer { - public static final Schema SCHEMA = new Schema( - Collections.singletonList(Field.notNullable("number", Types.MinorType.UINT4.getType()))); + public static final Schema SCHEMA = + new Schema( + Collections.singletonList(Field.notNullable("number", Types.MinorType.UINT4.getType()))); private final BufferAllocator allocator; private final List statuses; @@ -104,22 +100,28 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener l int index = parseIndexFromTicket(ticket); EndpointStatus status = statuses.get(index); if (status.cancelled) { - listener.error(CallStatus.NOT_FOUND - .withDescription("Invalid flight: cancelled: " + - new String(ticket.getBytes(), StandardCharsets.UTF_8)) - .toRuntimeException()); + listener.error( + CallStatus.NOT_FOUND + .withDescription( + "Invalid flight: cancelled: " + + new String(ticket.getBytes(), StandardCharsets.UTF_8)) + .toRuntimeException()); return; } else if (status.expirationTime != null && Instant.now().isAfter(status.expirationTime)) { - listener.error(CallStatus.NOT_FOUND - .withDescription("Invalid flight: expired: " + - new String(ticket.getBytes(), StandardCharsets.UTF_8)) - .toRuntimeException()); + listener.error( + CallStatus.NOT_FOUND + .withDescription( + "Invalid flight: expired: " + + new String(ticket.getBytes(), StandardCharsets.UTF_8)) + .toRuntimeException()); return; } else if (status.expirationTime == null && status.numGets > 0) { - listener.error(CallStatus.NOT_FOUND - .withDescription("Invalid flight: can't read multiple times: " + - new String(ticket.getBytes(), StandardCharsets.UTF_8)) - .toRuntimeException()); + listener.error( + CallStatus.NOT_FOUND + .withDescription( + "Invalid flight: can't read multiple times: " + + new String(ticket.getBytes(), StandardCharsets.UTF_8)) + .toRuntimeException()); return; } status.numGets++; @@ -138,7 +140,8 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener l public void doAction(CallContext context, Action action, StreamListener listener) { try { if (action.getType().equals(FlightConstants.CANCEL_FLIGHT_INFO.getType())) { - CancelFlightInfoRequest request = CancelFlightInfoRequest.deserialize(ByteBuffer.wrap(action.getBody())); + CancelFlightInfoRequest request = + CancelFlightInfoRequest.deserialize(ByteBuffer.wrap(action.getBody())); CancelStatus cancelStatus = CancelStatus.UNSPECIFIED; for (FlightEndpoint endpoint : request.getInfo().getEndpoints()) { int index = parseIndexFromTicket(endpoint.getTicket()); @@ -154,14 +157,16 @@ public void doAction(CallContext context, Action action, StreamListener } listener.onNext(new Result(new CancelFlightInfoResult(cancelStatus).serialize().array())); } else if (action.getType().equals(FlightConstants.RENEW_FLIGHT_ENDPOINT.getType())) { - RenewFlightEndpointRequest request = RenewFlightEndpointRequest.deserialize(ByteBuffer.wrap(action.getBody())); + RenewFlightEndpointRequest request = + RenewFlightEndpointRequest.deserialize(ByteBuffer.wrap(action.getBody())); FlightEndpoint endpoint = request.getFlightEndpoint(); int index = parseIndexFromTicket(endpoint.getTicket()); EndpointStatus status = statuses.get(index); if (status.cancelled) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Invalid flight: cancelled: " + index) - .toRuntimeException()); + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Invalid flight: cancelled: " + index) + .toRuntimeException()); return; } @@ -170,17 +175,20 @@ public void doAction(CallContext context, Action action, StreamListener Ticket ticket = new Ticket(ticketBody.getBytes(StandardCharsets.UTF_8)); Instant expiration = Instant.now().plus(10, ChronoUnit.SECONDS); status.expirationTime = expiration; - FlightEndpoint newEndpoint = new FlightEndpoint( - ticket, expiration, endpoint.getLocations().toArray(new Location[0])); + FlightEndpoint newEndpoint = + new FlightEndpoint( + ticket, expiration, endpoint.getLocations().toArray(new Location[0])); listener.onNext(new Result(newEndpoint.serialize().array())); } else { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Unknown action: " + action.getType()) - .toRuntimeException()); + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Unknown action: " + action.getType()) + .toRuntimeException()); return; } } catch (IOException | URISyntaxException e) { - listener.onError(CallStatus.INTERNAL.withCause(e).withDescription(e.toString()).toRuntimeException()); + listener.onError( + CallStatus.INTERNAL.withCause(e).withDescription(e.toString()).toRuntimeException()); return; } listener.onCompleted(); @@ -194,7 +202,9 @@ public void listActions(CallContext context, StreamListener listener } private FlightEndpoint addEndpoint(String ticket, Instant expirationTime) { - Ticket flightTicket = new Ticket(String.format("%d: %s", statuses.size(), ticket).getBytes(StandardCharsets.UTF_8)); + Ticket flightTicket = + new Ticket( + String.format("%d: %s", statuses.size(), ticket).getBytes(StandardCharsets.UTF_8)); statuses.add(new EndpointStatus(expirationTime)); return new FlightEndpoint(flightTicket, expirationTime); } @@ -204,8 +214,8 @@ private int parseIndexFromTicket(Ticket ticket) { int index = contents.indexOf(':'); if (index == -1) { throw CallStatus.INVALID_ARGUMENT - .withDescription("Invalid ticket: " + - new String(ticket.getBytes(), StandardCharsets.UTF_8)) + .withDescription( + "Invalid ticket: " + new String(ticket.getBytes(), StandardCharsets.UTF_8)) .toRuntimeException(); } int endpointIndex = Integer.parseInt(contents.substring(0, index)); diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeRenewFlightEndpointScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeRenewFlightEndpointScenario.java index 6f47e2965a2..b2448fdfd99 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeRenewFlightEndpointScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/ExpirationTimeRenewFlightEndpointScenario.java @@ -19,7 +19,6 @@ import java.nio.charset.StandardCharsets; import java.time.Instant; - import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightDescriptor; import org.apache.arrow.flight.FlightEndpoint; @@ -38,12 +37,13 @@ public FlightProducer producer(BufferAllocator allocator, Location location) thr } @Override - public void buildServer(FlightServer.Builder builder) { - } + public void buildServer(FlightServer.Builder builder) {} @Override - public void client(BufferAllocator allocator, Location location, FlightClient client) throws Exception { - FlightInfo info = client.getInfo(FlightDescriptor.command("expiration".getBytes(StandardCharsets.UTF_8))); + public void client(BufferAllocator allocator, Location location, FlightClient client) + throws Exception { + FlightInfo info = + client.getInfo(FlightDescriptor.command("expiration".getBytes(StandardCharsets.UTF_8))); // Renew all endpoints with expiration time for (FlightEndpoint endpoint : info.getEndpoints()) { @@ -53,11 +53,12 @@ public void client(BufferAllocator allocator, Location location, FlightClient cl Instant expiration = endpoint.getExpirationTime().get(); FlightEndpoint renewed = client.renewFlightEndpoint(new RenewFlightEndpointRequest(endpoint)); - IntegrationAssertions.assertTrue("Renewed FlightEndpoint must have expiration time", + IntegrationAssertions.assertTrue( + "Renewed FlightEndpoint must have expiration time", renewed.getExpirationTime().isPresent()); - IntegrationAssertions.assertTrue("Renewed FlightEndpoint must have newer expiration time", + IntegrationAssertions.assertTrue( + "Renewed FlightEndpoint must have newer expiration time", renewed.getExpirationTime().get().isAfter(expiration)); - } } } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlExtensionScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlExtensionScenario.java index cd20ae4f46f..2abd49d8192 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlExtensionScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlExtensionScenario.java @@ -19,7 +19,6 @@ import java.util.HashMap; import java.util.Map; - import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightInfo; import org.apache.arrow.flight.FlightStream; @@ -38,9 +37,9 @@ import org.apache.arrow.vector.types.pojo.Schema; /** - * Integration test scenario for validating Flight SQL specs across multiple implementations. - * This should ensure that RPC objects are being built and parsed correctly for multiple languages - * and that the Arrow schemas are returned as expected. + * Integration test scenario for validating Flight SQL specs across multiple implementations. This + * should ensure that RPC objects are being built and parsed correctly for multiple languages and + * that the Arrow schemas are returned as expected. */ public class FlightSqlExtensionScenario extends FlightSqlScenario { @Override @@ -61,7 +60,8 @@ private void validateMetadataRetrieval(FlightSqlClient sqlClient) throws Excepti Map infoValues = new HashMap<>(); try (FlightStream stream = sqlClient.getStream(ticket)) { Schema actualSchema = stream.getSchema(); - IntegrationAssertions.assertEquals(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA, actualSchema); + IntegrationAssertions.assertEquals( + FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA, actualSchema); while (stream.next()) { UInt4Vector infoName = (UInt4Vector) stream.getRoot().getVector(0); @@ -76,9 +76,10 @@ private void validateMetadataRetrieval(FlightSqlClient sqlClient) throws Excepti byte typeId = value.getTypeId(i); switch (typeId) { case 0: // string - object = Preconditions.checkNotNull(value.getVarCharVector(typeId) - .getObject(value.getOffset(i))) - .toString(); + object = + Preconditions.checkNotNull( + value.getVarCharVector(typeId).getObject(value.getOffset(i))) + .toString(); break; case 1: // bool object = value.getBitVector(typeId).getObject(value.getOffset(i)); @@ -97,22 +98,25 @@ private void validateMetadataRetrieval(FlightSqlClient sqlClient) throws Excepti } } - IntegrationAssertions.assertEquals(Boolean.FALSE, - infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_SQL_VALUE)); - IntegrationAssertions.assertEquals(Boolean.TRUE, - infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_SUBSTRAIT_VALUE)); - IntegrationAssertions.assertEquals("min_version", + IntegrationAssertions.assertEquals( + Boolean.FALSE, infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_SQL_VALUE)); + IntegrationAssertions.assertEquals( + Boolean.TRUE, infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_SUBSTRAIT_VALUE)); + IntegrationAssertions.assertEquals( + "min_version", infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_SUBSTRAIT_MIN_VERSION_VALUE)); - IntegrationAssertions.assertEquals("max_version", + IntegrationAssertions.assertEquals( + "max_version", infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_SUBSTRAIT_MAX_VERSION_VALUE)); - IntegrationAssertions.assertEquals(FlightSql.SqlSupportedTransaction.SQL_SUPPORTED_TRANSACTION_SAVEPOINT_VALUE, + IntegrationAssertions.assertEquals( + FlightSql.SqlSupportedTransaction.SQL_SUPPORTED_TRANSACTION_SAVEPOINT_VALUE, infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_TRANSACTION_VALUE)); - IntegrationAssertions.assertEquals(Boolean.TRUE, - infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_CANCEL_VALUE)); - IntegrationAssertions.assertEquals(42, - infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_STATEMENT_TIMEOUT_VALUE)); - IntegrationAssertions.assertEquals(7, - infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_TRANSACTION_TIMEOUT_VALUE)); + IntegrationAssertions.assertEquals( + Boolean.TRUE, infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_CANCEL_VALUE)); + IntegrationAssertions.assertEquals( + 42, infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_STATEMENT_TIMEOUT_VALUE)); + IntegrationAssertions.assertEquals( + 7, infoValues.get(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_TRANSACTION_TIMEOUT_VALUE)); } private void validateStatementExecution(FlightSqlClient sqlClient) throws Exception { @@ -124,15 +128,15 @@ private void validateStatementExecution(FlightSqlClient sqlClient) throws Except IntegrationAssertions.assertEquals(CancelResult.CANCELLED, sqlClient.cancelQuery(info)); - IntegrationAssertions.assertEquals(sqlClient.executeSubstraitUpdate(SUBSTRAIT_PLAN), - UPDATE_STATEMENT_EXPECTED_ROWS); + IntegrationAssertions.assertEquals( + sqlClient.executeSubstraitUpdate(SUBSTRAIT_PLAN), UPDATE_STATEMENT_EXPECTED_ROWS); } - private void validatePreparedStatementExecution(BufferAllocator allocator, - FlightSqlClient sqlClient) throws Exception { + private void validatePreparedStatementExecution( + BufferAllocator allocator, FlightSqlClient sqlClient) throws Exception { try (FlightSqlClient.PreparedStatement preparedStatement = sqlClient.prepare(SUBSTRAIT_PLAN); - VectorSchemaRoot parameters = VectorSchemaRoot.create( - FlightSqlScenarioProducer.getQuerySchema(), allocator)) { + VectorSchemaRoot parameters = + VectorSchemaRoot.create(FlightSqlScenarioProducer.getQuerySchema(), allocator)) { parameters.setRowCount(1); preparedStatement.setParameters(parameters); validate(FlightSqlScenarioProducer.getQuerySchema(), preparedStatement.execute(), sqlClient); @@ -140,16 +144,18 @@ private void validatePreparedStatementExecution(BufferAllocator allocator, } try (FlightSqlClient.PreparedStatement preparedStatement = sqlClient.prepare(SUBSTRAIT_PLAN)) { - IntegrationAssertions.assertEquals(preparedStatement.executeUpdate(), - UPDATE_PREPARED_STATEMENT_EXPECTED_ROWS); + IntegrationAssertions.assertEquals( + preparedStatement.executeUpdate(), UPDATE_PREPARED_STATEMENT_EXPECTED_ROWS); } } - private void validateTransactions(BufferAllocator allocator, FlightSqlClient sqlClient) throws Exception { + private void validateTransactions(BufferAllocator allocator, FlightSqlClient sqlClient) + throws Exception { final FlightSqlClient.Transaction transaction = sqlClient.beginTransaction(); IntegrationAssertions.assertEquals(TRANSACTION_ID, transaction.getTransactionId()); - final FlightSqlClient.Savepoint savepoint = sqlClient.beginSavepoint(transaction, SAVEPOINT_NAME); + final FlightSqlClient.Savepoint savepoint = + sqlClient.beginSavepoint(transaction, SAVEPOINT_NAME); IntegrationAssertions.assertEquals(SAVEPOINT_ID, savepoint.getSavepointId()); FlightInfo info = sqlClient.execute("SELECT STATEMENT", transaction); @@ -164,47 +170,59 @@ private void validateTransactions(BufferAllocator allocator, FlightSqlClient sql schema = sqlClient.getExecuteSubstraitSchema(SUBSTRAIT_PLAN, transaction); validateSchema(FlightSqlScenarioProducer.getQueryWithTransactionSchema(), schema); - IntegrationAssertions.assertEquals(sqlClient.executeUpdate("UPDATE STATEMENT", transaction), + IntegrationAssertions.assertEquals( + sqlClient.executeUpdate("UPDATE STATEMENT", transaction), UPDATE_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); - IntegrationAssertions.assertEquals(sqlClient.executeSubstraitUpdate(SUBSTRAIT_PLAN, transaction), + IntegrationAssertions.assertEquals( + sqlClient.executeSubstraitUpdate(SUBSTRAIT_PLAN, transaction), UPDATE_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); - try (FlightSqlClient.PreparedStatement preparedStatement = sqlClient.prepare( - "SELECT PREPARED STATEMENT", transaction); - VectorSchemaRoot parameters = VectorSchemaRoot.create( - FlightSqlScenarioProducer.getQuerySchema(), allocator)) { + try (FlightSqlClient.PreparedStatement preparedStatement = + sqlClient.prepare("SELECT PREPARED STATEMENT", transaction); + VectorSchemaRoot parameters = + VectorSchemaRoot.create(FlightSqlScenarioProducer.getQuerySchema(), allocator)) { parameters.setRowCount(1); preparedStatement.setParameters(parameters); - validate(FlightSqlScenarioProducer.getQueryWithTransactionSchema(), preparedStatement.execute(), sqlClient); + validate( + FlightSqlScenarioProducer.getQueryWithTransactionSchema(), + preparedStatement.execute(), + sqlClient); schema = preparedStatement.fetchSchema(); validateSchema(FlightSqlScenarioProducer.getQueryWithTransactionSchema(), schema); } - try (FlightSqlClient.PreparedStatement preparedStatement = sqlClient.prepare(SUBSTRAIT_PLAN, transaction); - VectorSchemaRoot parameters = VectorSchemaRoot.create( - FlightSqlScenarioProducer.getQuerySchema(), allocator)) { + try (FlightSqlClient.PreparedStatement preparedStatement = + sqlClient.prepare(SUBSTRAIT_PLAN, transaction); + VectorSchemaRoot parameters = + VectorSchemaRoot.create(FlightSqlScenarioProducer.getQuerySchema(), allocator)) { parameters.setRowCount(1); preparedStatement.setParameters(parameters); - validate(FlightSqlScenarioProducer.getQueryWithTransactionSchema(), preparedStatement.execute(), sqlClient); + validate( + FlightSqlScenarioProducer.getQueryWithTransactionSchema(), + preparedStatement.execute(), + sqlClient); schema = preparedStatement.fetchSchema(); validateSchema(FlightSqlScenarioProducer.getQueryWithTransactionSchema(), schema); } try (FlightSqlClient.PreparedStatement preparedStatement = - sqlClient.prepare("UPDATE PREPARED STATEMENT", transaction)) { - IntegrationAssertions.assertEquals(preparedStatement.executeUpdate(), + sqlClient.prepare("UPDATE PREPARED STATEMENT", transaction)) { + IntegrationAssertions.assertEquals( + preparedStatement.executeUpdate(), UPDATE_PREPARED_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); } try (FlightSqlClient.PreparedStatement preparedStatement = - sqlClient.prepare(SUBSTRAIT_PLAN, transaction)) { - IntegrationAssertions.assertEquals(preparedStatement.executeUpdate(), + sqlClient.prepare(SUBSTRAIT_PLAN, transaction)) { + IntegrationAssertions.assertEquals( + preparedStatement.executeUpdate(), UPDATE_PREPARED_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); } sqlClient.rollback(savepoint); - final FlightSqlClient.Savepoint savepoint2 = sqlClient.beginSavepoint(transaction, SAVEPOINT_NAME); + final FlightSqlClient.Savepoint savepoint2 = + sqlClient.beginSavepoint(transaction, SAVEPOINT_NAME); IntegrationAssertions.assertEquals(SAVEPOINT_ID, savepoint2.getSavepointId()); sqlClient.release(savepoint); diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlScenario.java index 71f1f741d58..6332f7a484a 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlScenario.java @@ -19,7 +19,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; - import org.apache.arrow.flight.CallOption; import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightInfo; @@ -38,9 +37,9 @@ import org.apache.arrow.vector.types.pojo.Schema; /** - * Integration test scenario for validating Flight SQL specs across multiple implementations. - * This should ensure that RPC objects are being built and parsed correctly for multiple languages - * and that the Arrow schemas are returned as expected. + * Integration test scenario for validating Flight SQL specs across multiple implementations. This + * should ensure that RPC objects are being built and parsed correctly for multiple languages and + * that the Arrow schemas are returned as expected. */ public class FlightSqlScenario implements Scenario { public static final long UPDATE_STATEMENT_EXPECTED_ROWS = 10000L; @@ -61,9 +60,7 @@ public FlightProducer producer(BufferAllocator allocator, Location location) thr } @Override - public void buildServer(FlightServer.Builder builder) throws Exception { - - } + public void buildServer(FlightServer.Builder builder) throws Exception {} @Override public void client(BufferAllocator allocator, Location location, FlightClient client) @@ -78,72 +75,111 @@ public void client(BufferAllocator allocator, Location location, FlightClient cl private void validateMetadataRetrieval(FlightSqlClient sqlClient) throws Exception { final CallOption[] options = new CallOption[0]; - validate(FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA, sqlClient.getCatalogs(options), - sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA, sqlClient.getCatalogsSchema(options)); + validate( + FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA, sqlClient.getCatalogs(options), sqlClient); + validateSchema( + FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA, sqlClient.getCatalogsSchema(options)); - validate(FlightSqlProducer.Schemas.GET_SCHEMAS_SCHEMA, + validate( + FlightSqlProducer.Schemas.GET_SCHEMAS_SCHEMA, sqlClient.getSchemas("catalog", "db_schema_filter_pattern", options), sqlClient); validateSchema(FlightSqlProducer.Schemas.GET_SCHEMAS_SCHEMA, sqlClient.getSchemasSchema()); - validate(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA, - sqlClient.getTables("catalog", "db_schema_filter_pattern", "table_filter_pattern", - Arrays.asList("table", "view"), true, options), sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA, - sqlClient.getTablesSchema(/*includeSchema*/true, options)); - validateSchema(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, - sqlClient.getTablesSchema(/*includeSchema*/false, options)); - - validate(FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA, sqlClient.getTableTypes(options), sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA, sqlClient.getTableTypesSchema(options)); + validate( + FlightSqlProducer.Schemas.GET_TABLES_SCHEMA, + sqlClient.getTables( + "catalog", + "db_schema_filter_pattern", + "table_filter_pattern", + Arrays.asList("table", "view"), + true, + options), + sqlClient); + validateSchema( + FlightSqlProducer.Schemas.GET_TABLES_SCHEMA, + sqlClient.getTablesSchema(/*includeSchema*/ true, options)); + validateSchema( + FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, + sqlClient.getTablesSchema(/*includeSchema*/ false, options)); + + validate( + FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA, + sqlClient.getTableTypes(options), + sqlClient); + validateSchema( + FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA, sqlClient.getTableTypesSchema(options)); - validate(FlightSqlProducer.Schemas.GET_PRIMARY_KEYS_SCHEMA, + validate( + FlightSqlProducer.Schemas.GET_PRIMARY_KEYS_SCHEMA, sqlClient.getPrimaryKeys(TableRef.of("catalog", "db_schema", "table"), options), sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_PRIMARY_KEYS_SCHEMA, sqlClient.getPrimaryKeysSchema(options)); + validateSchema( + FlightSqlProducer.Schemas.GET_PRIMARY_KEYS_SCHEMA, sqlClient.getPrimaryKeysSchema(options)); - validate(FlightSqlProducer.Schemas.GET_EXPORTED_KEYS_SCHEMA, + validate( + FlightSqlProducer.Schemas.GET_EXPORTED_KEYS_SCHEMA, sqlClient.getExportedKeys(TableRef.of("catalog", "db_schema", "table"), options), sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_EXPORTED_KEYS_SCHEMA, sqlClient.getExportedKeysSchema(options)); + validateSchema( + FlightSqlProducer.Schemas.GET_EXPORTED_KEYS_SCHEMA, + sqlClient.getExportedKeysSchema(options)); - validate(FlightSqlProducer.Schemas.GET_IMPORTED_KEYS_SCHEMA, + validate( + FlightSqlProducer.Schemas.GET_IMPORTED_KEYS_SCHEMA, sqlClient.getImportedKeys(TableRef.of("catalog", "db_schema", "table"), options), sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_IMPORTED_KEYS_SCHEMA, sqlClient.getImportedKeysSchema(options)); - - validate(FlightSqlProducer.Schemas.GET_CROSS_REFERENCE_SCHEMA, - sqlClient.getCrossReference(TableRef.of("pk_catalog", "pk_db_schema", "pk_table"), - TableRef.of("fk_catalog", "fk_db_schema", "fk_table"), options), + validateSchema( + FlightSqlProducer.Schemas.GET_IMPORTED_KEYS_SCHEMA, + sqlClient.getImportedKeysSchema(options)); + + validate( + FlightSqlProducer.Schemas.GET_CROSS_REFERENCE_SCHEMA, + sqlClient.getCrossReference( + TableRef.of("pk_catalog", "pk_db_schema", "pk_table"), + TableRef.of("fk_catalog", "fk_db_schema", "fk_table"), + options), sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_CROSS_REFERENCE_SCHEMA, sqlClient.getCrossReferenceSchema(options)); - - validate(FlightSqlProducer.Schemas.GET_TYPE_INFO_SCHEMA, sqlClient.getXdbcTypeInfo(options), sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_TYPE_INFO_SCHEMA, sqlClient.getXdbcTypeInfoSchema(options)); + validateSchema( + FlightSqlProducer.Schemas.GET_CROSS_REFERENCE_SCHEMA, + sqlClient.getCrossReferenceSchema(options)); - validate(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA, - sqlClient.getSqlInfo(new FlightSql.SqlInfo[] {FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME, - FlightSql.SqlInfo.FLIGHT_SQL_SERVER_READ_ONLY}, options), sqlClient); - validateSchema(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA, sqlClient.getSqlInfoSchema(options)); + validate( + FlightSqlProducer.Schemas.GET_TYPE_INFO_SCHEMA, + sqlClient.getXdbcTypeInfo(options), + sqlClient); + validateSchema( + FlightSqlProducer.Schemas.GET_TYPE_INFO_SCHEMA, sqlClient.getXdbcTypeInfoSchema(options)); + + validate( + FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA, + sqlClient.getSqlInfo( + new FlightSql.SqlInfo[] { + FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME, + FlightSql.SqlInfo.FLIGHT_SQL_SERVER_READ_ONLY + }, + options), + sqlClient); + validateSchema( + FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA, sqlClient.getSqlInfoSchema(options)); } private void validateStatementExecution(FlightSqlClient sqlClient) throws Exception { FlightInfo info = sqlClient.execute("SELECT STATEMENT"); validate(FlightSqlScenarioProducer.getQuerySchema(), info, sqlClient); - validateSchema(FlightSqlScenarioProducer.getQuerySchema(), - sqlClient.getExecuteSchema("SELECT STATEMENT")); + validateSchema( + FlightSqlScenarioProducer.getQuerySchema(), sqlClient.getExecuteSchema("SELECT STATEMENT")); - IntegrationAssertions.assertEquals(sqlClient.executeUpdate("UPDATE STATEMENT"), - UPDATE_STATEMENT_EXPECTED_ROWS); + IntegrationAssertions.assertEquals( + sqlClient.executeUpdate("UPDATE STATEMENT"), UPDATE_STATEMENT_EXPECTED_ROWS); } - private void validatePreparedStatementExecution(BufferAllocator allocator, - FlightSqlClient sqlClient) throws Exception { - try (FlightSqlClient.PreparedStatement preparedStatement = sqlClient.prepare( - "SELECT PREPARED STATEMENT"); - VectorSchemaRoot parameters = VectorSchemaRoot.create( - FlightSqlScenarioProducer.getQuerySchema(), allocator)) { + private void validatePreparedStatementExecution( + BufferAllocator allocator, FlightSqlClient sqlClient) throws Exception { + try (FlightSqlClient.PreparedStatement preparedStatement = + sqlClient.prepare("SELECT PREPARED STATEMENT"); + VectorSchemaRoot parameters = + VectorSchemaRoot.create(FlightSqlScenarioProducer.getQuerySchema(), allocator)) { parameters.setRowCount(1); preparedStatement.setParameters(parameters); validate(FlightSqlScenarioProducer.getQuerySchema(), preparedStatement.execute(), sqlClient); @@ -151,14 +187,14 @@ private void validatePreparedStatementExecution(BufferAllocator allocator, } try (FlightSqlClient.PreparedStatement preparedStatement = - sqlClient.prepare("UPDATE PREPARED STATEMENT")) { - IntegrationAssertions.assertEquals(preparedStatement.executeUpdate(), - UPDATE_PREPARED_STATEMENT_EXPECTED_ROWS); + sqlClient.prepare("UPDATE PREPARED STATEMENT")) { + IntegrationAssertions.assertEquals( + preparedStatement.executeUpdate(), UPDATE_PREPARED_STATEMENT_EXPECTED_ROWS); } } - protected void validate(Schema expectedSchema, FlightInfo flightInfo, - FlightSqlClient sqlClient) throws Exception { + protected void validate(Schema expectedSchema, FlightInfo flightInfo, FlightSqlClient sqlClient) + throws Exception { Ticket ticket = flightInfo.getEndpoints().get(0).getTicket(); try (FlightStream stream = sqlClient.getStream(ticket)) { Schema actualSchema = stream.getSchema(); diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlScenarioProducer.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlScenarioProducer.java index 4ed9a3df0fc..5685ad6cacb 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlScenarioProducer.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/FlightSqlScenarioProducer.java @@ -17,10 +17,13 @@ package org.apache.arrow.flight.integration.tests; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.Message; import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.Criteria; import org.apache.arrow.flight.FlightDescriptor; @@ -44,14 +47,7 @@ import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.types.pojo.Schema; -import com.google.protobuf.Any; -import com.google.protobuf.ByteString; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.Message; - -/** - * Hardcoded Flight SQL producer used for cross-language integration tests. - */ +/** Hardcoded Flight SQL producer used for cross-language integration tests. */ public class FlightSqlScenarioProducer implements FlightSqlProducer { private final BufferAllocator allocator; @@ -60,157 +56,200 @@ public FlightSqlScenarioProducer(BufferAllocator allocator) { } /** - * Schema to be returned for mocking the statement/prepared statement results. - * Must be the same across all languages. + * Schema to be returned for mocking the statement/prepared statement results. Must be the same + * across all languages. */ static Schema getQuerySchema() { return new Schema( Collections.singletonList( - new Field("id", new FieldType(true, new ArrowType.Int(64, true), - null, new FlightSqlColumnMetadata.Builder() - .tableName("test") - .isAutoIncrement(true) - .isCaseSensitive(false) - .typeName("type_test") - .schemaName("schema_test") - .isSearchable(true) - .catalogName("catalog_test") - .precision(100) - .build().getMetadataMap()), null) - ) - ); + new Field( + "id", + new FieldType( + true, + new ArrowType.Int(64, true), + null, + new FlightSqlColumnMetadata.Builder() + .tableName("test") + .isAutoIncrement(true) + .isCaseSensitive(false) + .typeName("type_test") + .schemaName("schema_test") + .isSearchable(true) + .catalogName("catalog_test") + .precision(100) + .build() + .getMetadataMap()), + null))); } /** * The expected schema for queries with transactions. - *

- * Must be the same across all languages. + * + *

Must be the same across all languages. */ static Schema getQueryWithTransactionSchema() { return new Schema( Collections.singletonList( - new Field("pkey", new FieldType(true, new ArrowType.Int(32, true), - null, new FlightSqlColumnMetadata.Builder() - .tableName("test") - .isAutoIncrement(true) - .isCaseSensitive(false) - .typeName("type_test") - .schemaName("schema_test") - .isSearchable(true) - .catalogName("catalog_test") - .precision(100) - .build().getMetadataMap()), null) - ) - ); - } - - @Override - public void beginSavepoint(FlightSql.ActionBeginSavepointRequest request, CallContext context, - StreamListener listener) { + new Field( + "pkey", + new FieldType( + true, + new ArrowType.Int(32, true), + null, + new FlightSqlColumnMetadata.Builder() + .tableName("test") + .isAutoIncrement(true) + .isCaseSensitive(false) + .typeName("type_test") + .schemaName("schema_test") + .isSearchable(true) + .catalogName("catalog_test") + .precision(100) + .build() + .getMetadataMap()), + null))); + } + + @Override + public void beginSavepoint( + FlightSql.ActionBeginSavepointRequest request, + CallContext context, + StreamListener listener) { if (!request.getName().equals(FlightSqlScenario.SAVEPOINT_NAME)) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected name '%s', not '%s'", - FlightSqlScenario.SAVEPOINT_NAME, request.getName())) - .toRuntimeException()); + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + String.format( + "Expected name '%s', not '%s'", + FlightSqlScenario.SAVEPOINT_NAME, request.getName())) + .toRuntimeException()); return; } - if (!Arrays.equals(request.getTransactionId().toByteArray(), FlightSqlScenario.TRANSACTION_ID)) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected transaction ID '%s', not '%s'", - Arrays.toString(FlightSqlScenario.TRANSACTION_ID), - Arrays.toString(request.getTransactionId().toByteArray()))) - .toRuntimeException()); + if (!Arrays.equals( + request.getTransactionId().toByteArray(), FlightSqlScenario.TRANSACTION_ID)) { + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + String.format( + "Expected transaction ID '%s', not '%s'", + Arrays.toString(FlightSqlScenario.TRANSACTION_ID), + Arrays.toString(request.getTransactionId().toByteArray()))) + .toRuntimeException()); return; } - listener.onNext(FlightSql.ActionBeginSavepointResult.newBuilder() - .setSavepointId(ByteString.copyFrom(FlightSqlScenario.SAVEPOINT_ID)) - .build()); + listener.onNext( + FlightSql.ActionBeginSavepointResult.newBuilder() + .setSavepointId(ByteString.copyFrom(FlightSqlScenario.SAVEPOINT_ID)) + .build()); listener.onCompleted(); } @Override - public void beginTransaction(FlightSql.ActionBeginTransactionRequest request, CallContext context, - StreamListener listener) { - listener.onNext(FlightSql.ActionBeginTransactionResult.newBuilder() - .setTransactionId(ByteString.copyFrom(FlightSqlScenario.TRANSACTION_ID)) - .build()); + public void beginTransaction( + FlightSql.ActionBeginTransactionRequest request, + CallContext context, + StreamListener listener) { + listener.onNext( + FlightSql.ActionBeginTransactionResult.newBuilder() + .setTransactionId(ByteString.copyFrom(FlightSqlScenario.TRANSACTION_ID)) + .build()); listener.onCompleted(); } @Override - public void cancelQuery(FlightInfo info, CallContext context, StreamListener listener) { + public void cancelQuery( + FlightInfo info, CallContext context, StreamListener listener) { final String expectedTicket = "PLAN HANDLE"; if (info.getEndpoints().size() != 1) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected 1 endpoint, got %d", info.getEndpoints().size())) - .toRuntimeException()); + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + String.format("Expected 1 endpoint, got %d", info.getEndpoints().size())) + .toRuntimeException()); } final FlightEndpoint endpoint = info.getEndpoints().get(0); try { final Any any = Any.parseFrom(endpoint.getTicket().getBytes()); if (!any.is(FlightSql.TicketStatementQuery.class)) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected TicketStatementQuery, found '%s'", any.getTypeUrl())) - .toRuntimeException()); + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + String.format("Expected TicketStatementQuery, found '%s'", any.getTypeUrl())) + .toRuntimeException()); } - final FlightSql.TicketStatementQuery ticket = any.unpack(FlightSql.TicketStatementQuery.class); + final FlightSql.TicketStatementQuery ticket = + any.unpack(FlightSql.TicketStatementQuery.class); if (!ticket.getStatementHandle().toStringUtf8().equals(expectedTicket)) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected ticket '%s'", expectedTicket)) - .toRuntimeException()); + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription(String.format("Expected ticket '%s'", expectedTicket)) + .toRuntimeException()); } listener.onNext(CancelResult.CANCELLED); listener.onCompleted(); } catch (InvalidProtocolBufferException e) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Invalid Protobuf:" + e) - .withCause(e) - .toRuntimeException()); + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Invalid Protobuf:" + e) + .withCause(e) + .toRuntimeException()); } } @Override - public void createPreparedStatement(FlightSql.ActionCreatePreparedStatementRequest request, - CallContext context, StreamListener listener) { - IntegrationAssertions.assertTrue("Expect to be one of the two queries used on tests", - request.getQuery().equals("SELECT PREPARED STATEMENT") || - request.getQuery().equals("UPDATE PREPARED STATEMENT")); + public void createPreparedStatement( + FlightSql.ActionCreatePreparedStatementRequest request, + CallContext context, + StreamListener listener) { + IntegrationAssertions.assertTrue( + "Expect to be one of the two queries used on tests", + request.getQuery().equals("SELECT PREPARED STATEMENT") + || request.getQuery().equals("UPDATE PREPARED STATEMENT")); String text = request.getQuery(); if (!request.getTransactionId().isEmpty()) { text += " WITH TXN"; } text += " HANDLE"; - final FlightSql.ActionCreatePreparedStatementResult - result = FlightSql.ActionCreatePreparedStatementResult.newBuilder() - .setPreparedStatementHandle(ByteString.copyFromUtf8(text)) - .build(); + final FlightSql.ActionCreatePreparedStatementResult result = + FlightSql.ActionCreatePreparedStatementResult.newBuilder() + .setPreparedStatementHandle(ByteString.copyFromUtf8(text)) + .build(); listener.onNext(new Result(Any.pack(result).toByteArray())); listener.onCompleted(); } @Override - public void createPreparedSubstraitPlan(FlightSql.ActionCreatePreparedSubstraitPlanRequest request, - CallContext context, - StreamListener listener) { - if (!Arrays.equals(request.getPlan().getPlan().toByteArray(), FlightSqlScenario.SUBSTRAIT_PLAN_TEXT)) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected plan '%s', not '%s'", - Arrays.toString(FlightSqlScenario.SUBSTRAIT_PLAN_TEXT), - Arrays.toString(request.getPlan().getPlan().toByteArray()))) - .toRuntimeException()); + public void createPreparedSubstraitPlan( + FlightSql.ActionCreatePreparedSubstraitPlanRequest request, + CallContext context, + StreamListener listener) { + if (!Arrays.equals( + request.getPlan().getPlan().toByteArray(), FlightSqlScenario.SUBSTRAIT_PLAN_TEXT)) { + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + String.format( + "Expected plan '%s', not '%s'", + Arrays.toString(FlightSqlScenario.SUBSTRAIT_PLAN_TEXT), + Arrays.toString(request.getPlan().getPlan().toByteArray()))) + .toRuntimeException()); return; } if (!FlightSqlScenario.SUBSTRAIT_VERSION.equals(request.getPlan().getVersion())) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected version '%s', not '%s'", - FlightSqlScenario.SUBSTRAIT_VERSION, - request.getPlan().getVersion())) - .toRuntimeException()); + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + String.format( + "Expected version '%s', not '%s'", + FlightSqlScenario.SUBSTRAIT_VERSION, request.getPlan().getVersion())) + .toRuntimeException()); return; } - final String handle = request.getTransactionId().isEmpty() ? - "PREPARED PLAN HANDLE" : "PREPARED PLAN WITH TXN HANDLE"; + final String handle = + request.getTransactionId().isEmpty() + ? "PREPARED PLAN HANDLE" + : "PREPARED PLAN WITH TXN HANDLE"; final FlightSql.ActionCreatePreparedStatementResult result = FlightSql.ActionCreatePreparedStatementResult.newBuilder() .setPreparedStatementHandle(ByteString.copyFromUtf8(handle)) @@ -220,116 +259,141 @@ public void createPreparedSubstraitPlan(FlightSql.ActionCreatePreparedSubstraitP } @Override - public void closePreparedStatement(FlightSql.ActionClosePreparedStatementRequest request, - CallContext context, StreamListener listener) { + public void closePreparedStatement( + FlightSql.ActionClosePreparedStatementRequest request, + CallContext context, + StreamListener listener) { final String handle = request.getPreparedStatementHandle().toStringUtf8(); - IntegrationAssertions.assertTrue("Expect to be one of the queries used on tests", - handle.equals("SELECT PREPARED STATEMENT HANDLE") || - handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") || - handle.equals("UPDATE PREPARED STATEMENT HANDLE") || - handle.equals("UPDATE PREPARED STATEMENT WITH TXN HANDLE") || - handle.equals("PREPARED PLAN HANDLE") || - handle.equals("PREPARED PLAN WITH TXN HANDLE")); + IntegrationAssertions.assertTrue( + "Expect to be one of the queries used on tests", + handle.equals("SELECT PREPARED STATEMENT HANDLE") + || handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") + || handle.equals("UPDATE PREPARED STATEMENT HANDLE") + || handle.equals("UPDATE PREPARED STATEMENT WITH TXN HANDLE") + || handle.equals("PREPARED PLAN HANDLE") + || handle.equals("PREPARED PLAN WITH TXN HANDLE")); listener.onCompleted(); } @Override - public void endSavepoint(FlightSql.ActionEndSavepointRequest request, CallContext context, - StreamListener listener) { + public void endSavepoint( + FlightSql.ActionEndSavepointRequest request, + CallContext context, + StreamListener listener) { switch (request.getAction()) { case END_SAVEPOINT_RELEASE: case END_SAVEPOINT_ROLLBACK: - if (!Arrays.equals(request.getSavepointId().toByteArray(), FlightSqlScenario.SAVEPOINT_ID)) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Unexpected ID: " + Arrays.toString(request.getSavepointId().toByteArray())) - .toRuntimeException()); + if (!Arrays.equals( + request.getSavepointId().toByteArray(), FlightSqlScenario.SAVEPOINT_ID)) { + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + "Unexpected ID: " + Arrays.toString(request.getSavepointId().toByteArray())) + .toRuntimeException()); } break; case UNRECOGNIZED: - default: { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Unknown action: " + request.getAction()) - .toRuntimeException()); - return; - } + default: + { + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Unknown action: " + request.getAction()) + .toRuntimeException()); + return; + } } listener.onCompleted(); } @Override - public void endTransaction(FlightSql.ActionEndTransactionRequest request, CallContext context, - StreamListener listener) { + public void endTransaction( + FlightSql.ActionEndTransactionRequest request, + CallContext context, + StreamListener listener) { switch (request.getAction()) { case END_TRANSACTION_COMMIT: case END_TRANSACTION_ROLLBACK: - if (!Arrays.equals(request.getTransactionId().toByteArray(), FlightSqlScenario.TRANSACTION_ID)) { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Unexpected ID: " + Arrays.toString(request.getTransactionId().toByteArray())) - .toRuntimeException()); + if (!Arrays.equals( + request.getTransactionId().toByteArray(), FlightSqlScenario.TRANSACTION_ID)) { + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + "Unexpected ID: " + Arrays.toString(request.getTransactionId().toByteArray())) + .toRuntimeException()); } break; case UNRECOGNIZED: - default: { - listener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Unknown action: " + request.getAction()) - .toRuntimeException()); - return; - } + default: + { + listener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Unknown action: " + request.getAction()) + .toRuntimeException()); + return; + } } listener.onCompleted(); } @Override - public FlightInfo getFlightInfoStatement(FlightSql.CommandStatementQuery command, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoStatement( + FlightSql.CommandStatementQuery command, CallContext context, FlightDescriptor descriptor) { IntegrationAssertions.assertEquals(command.getQuery(), "SELECT STATEMENT"); if (command.getTransactionId().isEmpty()) { String handle = "SELECT STATEMENT HANDLE"; - FlightSql.TicketStatementQuery ticket = FlightSql.TicketStatementQuery.newBuilder() - .setStatementHandle(ByteString.copyFromUtf8(handle)) - .build(); + FlightSql.TicketStatementQuery ticket = + FlightSql.TicketStatementQuery.newBuilder() + .setStatementHandle(ByteString.copyFromUtf8(handle)) + .build(); return getFlightInfoForSchema(ticket, descriptor, getQuerySchema()); } else { String handle = "SELECT STATEMENT WITH TXN HANDLE"; - FlightSql.TicketStatementQuery ticket = FlightSql.TicketStatementQuery.newBuilder() - .setStatementHandle(ByteString.copyFromUtf8(handle)) - .build(); + FlightSql.TicketStatementQuery ticket = + FlightSql.TicketStatementQuery.newBuilder() + .setStatementHandle(ByteString.copyFromUtf8(handle)) + .build(); return getFlightInfoForSchema(ticket, descriptor, getQueryWithTransactionSchema()); } } @Override - public FlightInfo getFlightInfoSubstraitPlan(FlightSql.CommandStatementSubstraitPlan command, CallContext context, - FlightDescriptor descriptor) { - IntegrationAssertions.assertEquals(command.getPlan().getPlan().toByteArray(), - FlightSqlScenario.SUBSTRAIT_PLAN_TEXT); - IntegrationAssertions.assertEquals(command.getPlan().getVersion(), FlightSqlScenario.SUBSTRAIT_VERSION); - String handle = command.getTransactionId().isEmpty() ? - "PLAN HANDLE" : "PLAN WITH TXN HANDLE"; - FlightSql.TicketStatementQuery ticket = FlightSql.TicketStatementQuery.newBuilder() - .setStatementHandle(ByteString.copyFromUtf8(handle)) - .build(); + public FlightInfo getFlightInfoSubstraitPlan( + FlightSql.CommandStatementSubstraitPlan command, + CallContext context, + FlightDescriptor descriptor) { + IntegrationAssertions.assertEquals( + command.getPlan().getPlan().toByteArray(), FlightSqlScenario.SUBSTRAIT_PLAN_TEXT); + IntegrationAssertions.assertEquals( + command.getPlan().getVersion(), FlightSqlScenario.SUBSTRAIT_VERSION); + String handle = command.getTransactionId().isEmpty() ? "PLAN HANDLE" : "PLAN WITH TXN HANDLE"; + FlightSql.TicketStatementQuery ticket = + FlightSql.TicketStatementQuery.newBuilder() + .setStatementHandle(ByteString.copyFromUtf8(handle)) + .build(); return getFlightInfoForSchema(ticket, descriptor, getQuerySchema()); } @Override - public FlightInfo getFlightInfoPreparedStatement(FlightSql.CommandPreparedStatementQuery command, - CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoPreparedStatement( + FlightSql.CommandPreparedStatementQuery command, + CallContext context, + FlightDescriptor descriptor) { String handle = command.getPreparedStatementHandle().toStringUtf8(); - if (handle.equals("SELECT PREPARED STATEMENT HANDLE") || - handle.equals("PREPARED PLAN HANDLE")) { + if (handle.equals("SELECT PREPARED STATEMENT HANDLE") + || handle.equals("PREPARED PLAN HANDLE")) { return getFlightInfoForSchema(command, descriptor, getQuerySchema()); - } else if (handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") || - handle.equals("PREPARED PLAN WITH TXN HANDLE")) { + } else if (handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") + || handle.equals("PREPARED PLAN WITH TXN HANDLE")) { return getFlightInfoForSchema(command, descriptor, getQueryWithTransactionSchema()); } - throw CallStatus.INVALID_ARGUMENT.withDescription("Unknown handle: " + handle).toRuntimeException(); + throw CallStatus.INVALID_ARGUMENT + .withDescription("Unknown handle: " + handle) + .toRuntimeException(); } @Override - public SchemaResult getSchemaStatement(FlightSql.CommandStatementQuery command, - CallContext context, FlightDescriptor descriptor) { + public SchemaResult getSchemaStatement( + FlightSql.CommandStatementQuery command, CallContext context, FlightDescriptor descriptor) { IntegrationAssertions.assertEquals(command.getQuery(), "SELECT STATEMENT"); if (command.getTransactionId().isEmpty()) { return new SchemaResult(getQuerySchema()); @@ -338,34 +402,44 @@ public SchemaResult getSchemaStatement(FlightSql.CommandStatementQuery command, } @Override - public SchemaResult getSchemaPreparedStatement(FlightSql.CommandPreparedStatementQuery command, CallContext context, - FlightDescriptor descriptor) { + public SchemaResult getSchemaPreparedStatement( + FlightSql.CommandPreparedStatementQuery command, + CallContext context, + FlightDescriptor descriptor) { String handle = command.getPreparedStatementHandle().toStringUtf8(); - if (handle.equals("SELECT PREPARED STATEMENT HANDLE") || - handle.equals("PREPARED PLAN HANDLE")) { + if (handle.equals("SELECT PREPARED STATEMENT HANDLE") + || handle.equals("PREPARED PLAN HANDLE")) { return new SchemaResult(getQuerySchema()); - } else if (handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") || - handle.equals("PREPARED PLAN WITH TXN HANDLE")) { + } else if (handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") + || handle.equals("PREPARED PLAN WITH TXN HANDLE")) { return new SchemaResult(getQueryWithTransactionSchema()); } - throw CallStatus.INVALID_ARGUMENT.withDescription("Unknown handle: " + handle).toRuntimeException(); + throw CallStatus.INVALID_ARGUMENT + .withDescription("Unknown handle: " + handle) + .toRuntimeException(); } @Override - public SchemaResult getSchemaSubstraitPlan(FlightSql.CommandStatementSubstraitPlan command, CallContext context, - FlightDescriptor descriptor) { - if (!Arrays.equals(command.getPlan().getPlan().toByteArray(), FlightSqlScenario.SUBSTRAIT_PLAN_TEXT)) { + public SchemaResult getSchemaSubstraitPlan( + FlightSql.CommandStatementSubstraitPlan command, + CallContext context, + FlightDescriptor descriptor) { + if (!Arrays.equals( + command.getPlan().getPlan().toByteArray(), FlightSqlScenario.SUBSTRAIT_PLAN_TEXT)) { throw CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected plan '%s', not '%s'", - Arrays.toString(FlightSqlScenario.SUBSTRAIT_PLAN_TEXT), - Arrays.toString(command.getPlan().getPlan().toByteArray()))) + .withDescription( + String.format( + "Expected plan '%s', not '%s'", + Arrays.toString(FlightSqlScenario.SUBSTRAIT_PLAN_TEXT), + Arrays.toString(command.getPlan().getPlan().toByteArray()))) .toRuntimeException(); } if (!FlightSqlScenario.SUBSTRAIT_VERSION.equals(command.getPlan().getVersion())) { throw CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Expected version '%s', not '%s'", - FlightSqlScenario.SUBSTRAIT_VERSION, - command.getPlan().getVersion())) + .withDescription( + String.format( + "Expected version '%s', not '%s'", + FlightSqlScenario.SUBSTRAIT_VERSION, command.getPlan().getVersion())) .toRuntimeException(); } if (command.getTransactionId().isEmpty()) { @@ -375,31 +449,39 @@ public SchemaResult getSchemaSubstraitPlan(FlightSql.CommandStatementSubstraitPl } @Override - public void getStreamStatement(FlightSql.TicketStatementQuery ticket, CallContext context, - ServerStreamListener listener) { + public void getStreamStatement( + FlightSql.TicketStatementQuery ticket, CallContext context, ServerStreamListener listener) { final String handle = ticket.getStatementHandle().toStringUtf8(); if (handle.equals("SELECT STATEMENT HANDLE") || handle.equals("PLAN HANDLE")) { putEmptyBatchToStreamListener(listener, getQuerySchema()); - } else if (handle.equals("SELECT STATEMENT WITH TXN HANDLE") || handle.equals("PLAN WITH TXN HANDLE")) { + } else if (handle.equals("SELECT STATEMENT WITH TXN HANDLE") + || handle.equals("PLAN WITH TXN HANDLE")) { putEmptyBatchToStreamListener(listener, getQueryWithTransactionSchema()); } else { - listener.error(CallStatus.INVALID_ARGUMENT.withDescription("Unknown handle: " + handle).toRuntimeException()); + listener.error( + CallStatus.INVALID_ARGUMENT + .withDescription("Unknown handle: " + handle) + .toRuntimeException()); } } @Override - public void getStreamPreparedStatement(FlightSql.CommandPreparedStatementQuery command, - CallContext context, ServerStreamListener listener) { + public void getStreamPreparedStatement( + FlightSql.CommandPreparedStatementQuery command, + CallContext context, + ServerStreamListener listener) { String handle = command.getPreparedStatementHandle().toStringUtf8(); - if (handle.equals("SELECT PREPARED STATEMENT HANDLE") || handle.equals("PREPARED PLAN HANDLE")) { + if (handle.equals("SELECT PREPARED STATEMENT HANDLE") + || handle.equals("PREPARED PLAN HANDLE")) { putEmptyBatchToStreamListener(listener, getQuerySchema()); - } else if (handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") || - handle.equals("PREPARED PLAN WITH TXN HANDLE")) { + } else if (handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") + || handle.equals("PREPARED PLAN WITH TXN HANDLE")) { putEmptyBatchToStreamListener(listener, getQueryWithTransactionSchema()); } else { - listener.error(CallStatus.INVALID_ARGUMENT - .withDescription("Unknown handle: " + handle) - .toRuntimeException()); + listener.error( + CallStatus.INVALID_ARGUMENT + .withDescription("Unknown handle: " + handle) + .toRuntimeException()); } } @@ -417,113 +499,134 @@ private Runnable acceptPutReturnConstant(StreamListener ackStream, lo } @Override - public Runnable acceptPutStatement(FlightSql.CommandStatementUpdate command, CallContext context, - FlightStream flightStream, - StreamListener ackStream) { + public Runnable acceptPutStatement( + FlightSql.CommandStatementUpdate command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { IntegrationAssertions.assertEquals(command.getQuery(), "UPDATE STATEMENT"); - return acceptPutReturnConstant(ackStream, - command.getTransactionId().isEmpty() ? FlightSqlScenario.UPDATE_STATEMENT_EXPECTED_ROWS : - FlightSqlScenario.UPDATE_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); - } - - @Override - public Runnable acceptPutSubstraitPlan(FlightSql.CommandStatementSubstraitPlan command, CallContext context, - FlightStream flightStream, StreamListener ackStream) { - IntegrationAssertions.assertEquals(command.getPlan().getPlan().toByteArray(), - FlightSqlScenario.SUBSTRAIT_PLAN_TEXT); - IntegrationAssertions.assertEquals(command.getPlan().getVersion(), FlightSqlScenario.SUBSTRAIT_VERSION); - return acceptPutReturnConstant(ackStream, - command.getTransactionId().isEmpty() ? FlightSqlScenario.UPDATE_STATEMENT_EXPECTED_ROWS : - FlightSqlScenario.UPDATE_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); - } - - @Override - public Runnable acceptPutPreparedStatementUpdate(FlightSql.CommandPreparedStatementUpdate command, - CallContext context, FlightStream flightStream, - StreamListener ackStream) { + return acceptPutReturnConstant( + ackStream, + command.getTransactionId().isEmpty() + ? FlightSqlScenario.UPDATE_STATEMENT_EXPECTED_ROWS + : FlightSqlScenario.UPDATE_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); + } + + @Override + public Runnable acceptPutSubstraitPlan( + FlightSql.CommandStatementSubstraitPlan command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { + IntegrationAssertions.assertEquals( + command.getPlan().getPlan().toByteArray(), FlightSqlScenario.SUBSTRAIT_PLAN_TEXT); + IntegrationAssertions.assertEquals( + command.getPlan().getVersion(), FlightSqlScenario.SUBSTRAIT_VERSION); + return acceptPutReturnConstant( + ackStream, + command.getTransactionId().isEmpty() + ? FlightSqlScenario.UPDATE_STATEMENT_EXPECTED_ROWS + : FlightSqlScenario.UPDATE_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); + } + + @Override + public Runnable acceptPutPreparedStatementUpdate( + FlightSql.CommandPreparedStatementUpdate command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { final String handle = command.getPreparedStatementHandle().toStringUtf8(); - if (handle.equals("UPDATE PREPARED STATEMENT HANDLE") || - handle.equals("PREPARED PLAN HANDLE")) { - return acceptPutReturnConstant(ackStream, FlightSqlScenario.UPDATE_PREPARED_STATEMENT_EXPECTED_ROWS); - } else if (handle.equals("UPDATE PREPARED STATEMENT WITH TXN HANDLE") || - handle.equals("PREPARED PLAN WITH TXN HANDLE")) { + if (handle.equals("UPDATE PREPARED STATEMENT HANDLE") + || handle.equals("PREPARED PLAN HANDLE")) { + return acceptPutReturnConstant( + ackStream, FlightSqlScenario.UPDATE_PREPARED_STATEMENT_EXPECTED_ROWS); + } else if (handle.equals("UPDATE PREPARED STATEMENT WITH TXN HANDLE") + || handle.equals("PREPARED PLAN WITH TXN HANDLE")) { return acceptPutReturnConstant( ackStream, FlightSqlScenario.UPDATE_PREPARED_STATEMENT_WITH_TRANSACTION_EXPECTED_ROWS); } return () -> { - ackStream.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Unknown handle: " + handle) - .toRuntimeException()); + ackStream.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Unknown handle: " + handle) + .toRuntimeException()); }; } @Override - public Runnable acceptPutPreparedStatementQuery(FlightSql.CommandPreparedStatementQuery command, - CallContext context, FlightStream flightStream, - StreamListener ackStream) { + public Runnable acceptPutPreparedStatementQuery( + FlightSql.CommandPreparedStatementQuery command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { final String handle = command.getPreparedStatementHandle().toStringUtf8(); - if (handle.equals("SELECT PREPARED STATEMENT HANDLE") || - handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") || - handle.equals("PREPARED PLAN HANDLE") || - handle.equals("PREPARED PLAN WITH TXN HANDLE")) { + if (handle.equals("SELECT PREPARED STATEMENT HANDLE") + || handle.equals("SELECT PREPARED STATEMENT WITH TXN HANDLE") + || handle.equals("PREPARED PLAN HANDLE") + || handle.equals("PREPARED PLAN WITH TXN HANDLE")) { IntegrationAssertions.assertEquals(getQuerySchema(), flightStream.getSchema()); return ackStream::onCompleted; } return () -> { - ackStream.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Unknown handle: " + handle) - .toRuntimeException()); + ackStream.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Unknown handle: " + handle) + .toRuntimeException()); }; } @Override - public FlightInfo getFlightInfoSqlInfo(FlightSql.CommandGetSqlInfo request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoSqlInfo( + FlightSql.CommandGetSqlInfo request, CallContext context, FlightDescriptor descriptor) { if (request.getInfoCount() == 2) { // Integration test for the protocol messages - IntegrationAssertions.assertEquals(request.getInfo(0), - FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME_VALUE); - IntegrationAssertions.assertEquals(request.getInfo(1), - FlightSql.SqlInfo.FLIGHT_SQL_SERVER_READ_ONLY_VALUE); + IntegrationAssertions.assertEquals( + request.getInfo(0), FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME_VALUE); + IntegrationAssertions.assertEquals( + request.getInfo(1), FlightSql.SqlInfo.FLIGHT_SQL_SERVER_READ_ONLY_VALUE); } return getFlightInfoForSchema(request, descriptor, Schemas.GET_SQL_INFO_SCHEMA); } @Override - public void getStreamSqlInfo(FlightSql.CommandGetSqlInfo command, CallContext context, - ServerStreamListener listener) { + public void getStreamSqlInfo( + FlightSql.CommandGetSqlInfo command, CallContext context, ServerStreamListener listener) { if (command.getInfoCount() == 2) { // Integration test for the protocol messages putEmptyBatchToStreamListener(listener, Schemas.GET_SQL_INFO_SCHEMA); return; } - SqlInfoBuilder sqlInfoBuilder = new SqlInfoBuilder() - .withFlightSqlServerSql(false) - .withFlightSqlServerSubstrait(true) - .withFlightSqlServerSubstraitMinVersion("min_version") - .withFlightSqlServerSubstraitMaxVersion("max_version") - .withFlightSqlServerTransaction(FlightSql.SqlSupportedTransaction.SQL_SUPPORTED_TRANSACTION_SAVEPOINT) - .withFlightSqlServerCancel(true) - .withFlightSqlServerStatementTimeout(42) - .withFlightSqlServerTransactionTimeout(7); + SqlInfoBuilder sqlInfoBuilder = + new SqlInfoBuilder() + .withFlightSqlServerSql(false) + .withFlightSqlServerSubstrait(true) + .withFlightSqlServerSubstraitMinVersion("min_version") + .withFlightSqlServerSubstraitMaxVersion("max_version") + .withFlightSqlServerTransaction( + FlightSql.SqlSupportedTransaction.SQL_SUPPORTED_TRANSACTION_SAVEPOINT) + .withFlightSqlServerCancel(true) + .withFlightSqlServerStatementTimeout(42) + .withFlightSqlServerTransactionTimeout(7); sqlInfoBuilder.send(command.getInfoList(), listener); } @Override - public void getStreamTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, - CallContext context, ServerStreamListener listener) { + public void getStreamTypeInfo( + FlightSql.CommandGetXdbcTypeInfo request, + CallContext context, + ServerStreamListener listener) { putEmptyBatchToStreamListener(listener, Schemas.GET_TYPE_INFO_SCHEMA); } @Override - public FlightInfo getFlightInfoTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTypeInfo( + FlightSql.CommandGetXdbcTypeInfo request, CallContext context, FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_TYPE_INFO_SCHEMA); } @Override - public FlightInfo getFlightInfoCatalogs(FlightSql.CommandGetCatalogs request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoCatalogs( + FlightSql.CommandGetCatalogs request, CallContext context, FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_CATALOGS_SCHEMA); } @@ -541,27 +644,27 @@ public void getStreamCatalogs(CallContext context, ServerStreamListener listener } @Override - public FlightInfo getFlightInfoSchemas(FlightSql.CommandGetDbSchemas request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoSchemas( + FlightSql.CommandGetDbSchemas request, CallContext context, FlightDescriptor descriptor) { IntegrationAssertions.assertEquals(request.getCatalog(), "catalog"); - IntegrationAssertions.assertEquals(request.getDbSchemaFilterPattern(), - "db_schema_filter_pattern"); + IntegrationAssertions.assertEquals( + request.getDbSchemaFilterPattern(), "db_schema_filter_pattern"); return getFlightInfoForSchema(request, descriptor, Schemas.GET_SCHEMAS_SCHEMA); } @Override - public void getStreamSchemas(FlightSql.CommandGetDbSchemas command, CallContext context, - ServerStreamListener listener) { + public void getStreamSchemas( + FlightSql.CommandGetDbSchemas command, CallContext context, ServerStreamListener listener) { putEmptyBatchToStreamListener(listener, Schemas.GET_SCHEMAS_SCHEMA); } @Override - public FlightInfo getFlightInfoTables(FlightSql.CommandGetTables request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTables( + FlightSql.CommandGetTables request, CallContext context, FlightDescriptor descriptor) { IntegrationAssertions.assertEquals(request.getCatalog(), "catalog"); - IntegrationAssertions.assertEquals(request.getDbSchemaFilterPattern(), - "db_schema_filter_pattern"); + IntegrationAssertions.assertEquals( + request.getDbSchemaFilterPattern(), "db_schema_filter_pattern"); IntegrationAssertions.assertEquals(request.getTableNameFilterPattern(), "table_filter_pattern"); IntegrationAssertions.assertEquals(request.getTableTypesCount(), 2); IntegrationAssertions.assertEquals(request.getTableTypes(0), "table"); @@ -571,14 +674,14 @@ public FlightInfo getFlightInfoTables(FlightSql.CommandGetTables request, CallCo } @Override - public void getStreamTables(FlightSql.CommandGetTables command, CallContext context, - ServerStreamListener listener) { + public void getStreamTables( + FlightSql.CommandGetTables command, CallContext context, ServerStreamListener listener) { putEmptyBatchToStreamListener(listener, Schemas.GET_TABLES_SCHEMA); } @Override - public FlightInfo getFlightInfoTableTypes(FlightSql.CommandGetTableTypes request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTableTypes( + FlightSql.CommandGetTableTypes request, CallContext context, FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_TABLE_TYPES_SCHEMA); } @@ -588,8 +691,8 @@ public void getStreamTableTypes(CallContext context, ServerStreamListener listen } @Override - public FlightInfo getFlightInfoPrimaryKeys(FlightSql.CommandGetPrimaryKeys request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoPrimaryKeys( + FlightSql.CommandGetPrimaryKeys request, CallContext context, FlightDescriptor descriptor) { IntegrationAssertions.assertEquals(request.getCatalog(), "catalog"); IntegrationAssertions.assertEquals(request.getDbSchema(), "db_schema"); IntegrationAssertions.assertEquals(request.getTable(), "table"); @@ -598,14 +701,14 @@ public FlightInfo getFlightInfoPrimaryKeys(FlightSql.CommandGetPrimaryKeys reque } @Override - public void getStreamPrimaryKeys(FlightSql.CommandGetPrimaryKeys command, CallContext context, - ServerStreamListener listener) { + public void getStreamPrimaryKeys( + FlightSql.CommandGetPrimaryKeys command, CallContext context, ServerStreamListener listener) { putEmptyBatchToStreamListener(listener, Schemas.GET_PRIMARY_KEYS_SCHEMA); } @Override - public FlightInfo getFlightInfoExportedKeys(FlightSql.CommandGetExportedKeys request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoExportedKeys( + FlightSql.CommandGetExportedKeys request, CallContext context, FlightDescriptor descriptor) { IntegrationAssertions.assertEquals(request.getCatalog(), "catalog"); IntegrationAssertions.assertEquals(request.getDbSchema(), "db_schema"); IntegrationAssertions.assertEquals(request.getTable(), "table"); @@ -614,8 +717,8 @@ public FlightInfo getFlightInfoExportedKeys(FlightSql.CommandGetExportedKeys req } @Override - public FlightInfo getFlightInfoImportedKeys(FlightSql.CommandGetImportedKeys request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoImportedKeys( + FlightSql.CommandGetImportedKeys request, CallContext context, FlightDescriptor descriptor) { IntegrationAssertions.assertEquals(request.getCatalog(), "catalog"); IntegrationAssertions.assertEquals(request.getDbSchema(), "db_schema"); IntegrationAssertions.assertEquals(request.getTable(), "table"); @@ -624,8 +727,10 @@ public FlightInfo getFlightInfoImportedKeys(FlightSql.CommandGetImportedKeys req } @Override - public FlightInfo getFlightInfoCrossReference(FlightSql.CommandGetCrossReference request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoCrossReference( + FlightSql.CommandGetCrossReference request, + CallContext context, + FlightDescriptor descriptor) { IntegrationAssertions.assertEquals(request.getPkCatalog(), "pk_catalog"); IntegrationAssertions.assertEquals(request.getPkDbSchema(), "pk_db_schema"); IntegrationAssertions.assertEquals(request.getPkTable(), "pk_table"); @@ -637,37 +742,38 @@ public FlightInfo getFlightInfoCrossReference(FlightSql.CommandGetCrossReference } @Override - public void getStreamExportedKeys(FlightSql.CommandGetExportedKeys command, CallContext context, - ServerStreamListener listener) { + public void getStreamExportedKeys( + FlightSql.CommandGetExportedKeys command, + CallContext context, + ServerStreamListener listener) { putEmptyBatchToStreamListener(listener, Schemas.GET_EXPORTED_KEYS_SCHEMA); } @Override - public void getStreamImportedKeys(FlightSql.CommandGetImportedKeys command, CallContext context, - ServerStreamListener listener) { + public void getStreamImportedKeys( + FlightSql.CommandGetImportedKeys command, + CallContext context, + ServerStreamListener listener) { putEmptyBatchToStreamListener(listener, Schemas.GET_IMPORTED_KEYS_SCHEMA); } @Override - public void getStreamCrossReference(FlightSql.CommandGetCrossReference command, - CallContext context, ServerStreamListener listener) { + public void getStreamCrossReference( + FlightSql.CommandGetCrossReference command, + CallContext context, + ServerStreamListener listener) { putEmptyBatchToStreamListener(listener, Schemas.GET_CROSS_REFERENCE_SCHEMA); } @Override - public void close() throws Exception { - - } + public void close() throws Exception {} @Override - public void listFlights(CallContext context, Criteria criteria, - StreamListener listener) { - - } + public void listFlights( + CallContext context, Criteria criteria, StreamListener listener) {} - private FlightInfo getFlightInfoForSchema(final T request, - final FlightDescriptor descriptor, - final Schema schema) { + private FlightInfo getFlightInfoForSchema( + final T request, final FlightDescriptor descriptor, final Schema schema) { final Ticket ticket = new Ticket(Any.pack(request).toByteArray()); final List endpoints = Collections.singletonList(new FlightEndpoint(ticket)); diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationAssertions.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationAssertions.java index 036bcc3811b..8e97fd5057c 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationAssertions.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationAssertions.java @@ -21,13 +21,10 @@ import java.io.StringWriter; import java.util.Arrays; import java.util.Objects; - import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.FlightRuntimeException; -/** - * Utility methods to implement integration tests without using JUnit assertions. - */ +/** Utility methods to implement integration tests without using JUnit assertions. */ final class IntegrationAssertions { /** @@ -46,42 +43,36 @@ static T assertThrows(Class clazz, AssertThrows body) { if (clazz.isInstance(t)) { return (T) t; } - throw new AssertionError("Expected exception of class " + clazz + " but got " + t.getClass(), t); + throw new AssertionError( + "Expected exception of class " + clazz + " but got " + t.getClass(), t); } throw new AssertionError("Expected exception of class " + clazz + " but did not throw."); } - /** - * Assert that the two (non-array) objects are equal. - */ + /** Assert that the two (non-array) objects are equal. */ static void assertEquals(Object expected, Object actual) { if (!Objects.equals(expected, actual)) { throw new AssertionError("Expected:\n" + expected + "\nbut got:\n" + actual); } } - /** - * Assert that the two arrays are equal. - */ + /** Assert that the two arrays are equal. */ static void assertEquals(byte[] expected, byte[] actual) { if (!Arrays.equals(expected, actual)) { throw new AssertionError( - String.format("Expected:\n%s\nbut got:\n%s", Arrays.toString(expected), Arrays.toString(actual))); + String.format( + "Expected:\n%s\nbut got:\n%s", Arrays.toString(expected), Arrays.toString(actual))); } } - /** - * Assert that the value is false, using the given message as an error otherwise. - */ + /** Assert that the value is false, using the given message as an error otherwise. */ static void assertFalse(String message, boolean value) { if (value) { throw new AssertionError("Expected false: " + message); } } - /** - * Assert that the value is true, using the given message as an error otherwise. - */ + /** Assert that the value is true, using the given message as an error otherwise. */ static void assertTrue(String message, boolean value) { if (!value) { throw new AssertionError("Expected true: " + message); @@ -94,22 +85,18 @@ static void assertNotNull(Object actual) { } } - /** - * Convert a throwable into a FlightRuntimeException with error details, for debugging. - */ + /** Convert a throwable into a FlightRuntimeException with error details, for debugging. */ static FlightRuntimeException toFlightRuntimeException(Throwable t) { final StringWriter stringWriter = new StringWriter(); final PrintWriter writer = new PrintWriter(stringWriter); t.printStackTrace(writer); return CallStatus.UNKNOWN - .withCause(t) - .withDescription("Unknown error: " + t + "\n. Stack trace:\n" + stringWriter.toString()) - .toRuntimeException(); + .withCause(t) + .withDescription("Unknown error: " + t + "\n. Stack trace:\n" + stringWriter.toString()) + .toRuntimeException(); } - /** - * An interface used with {@link #assertThrows(Class, AssertThrows)}. - */ + /** An interface used with {@link #assertThrows(Class, AssertThrows)}. */ @FunctionalInterface interface AssertThrows { diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationProducer.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationProducer.java index aed3045accb..b2a3dedc197 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationProducer.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationProducer.java @@ -27,7 +27,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; - import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.FlightDescriptor; import org.apache.arrow.flight.FlightEndpoint; @@ -81,10 +80,14 @@ public void setLocation(Location location) { @Override public void getStream(CallContext context, Ticket ticket, ServerStreamListener listener) { try { - FlightDescriptor descriptor = FlightDescriptor.deserialize(ByteBuffer.wrap(ticket.getBytes())); + FlightDescriptor descriptor = + FlightDescriptor.deserialize(ByteBuffer.wrap(ticket.getBytes())); Dataset dataset = datasets.get(descriptor); if (dataset == null) { - listener.error(CallStatus.NOT_FOUND.withDescription("Unknown ticket: " + descriptor).toRuntimeException()); + listener.error( + CallStatus.NOT_FOUND + .withDescription("Unknown ticket: " + descriptor) + .toRuntimeException()); return; } dataset.streamTo(allocator, listener); @@ -97,14 +100,18 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener l public FlightInfo getFlightInfo(CallContext context, FlightDescriptor descriptor) { Dataset h = datasets.get(descriptor); if (h == null) { - throw CallStatus.NOT_FOUND.withDescription("Unknown descriptor: " + descriptor).toRuntimeException(); + throw CallStatus.NOT_FOUND + .withDescription("Unknown descriptor: " + descriptor) + .toRuntimeException(); } return h.getFlightInfo(location); } @Override - public Runnable acceptPut(CallContext context, - final FlightStream flightStream, final StreamListener ackStream) { + public Runnable acceptPut( + CallContext context, + final FlightStream flightStream, + final StreamListener ackStream) { return () -> { List batches = new ArrayList<>(); try { @@ -115,7 +122,8 @@ public Runnable acceptPut(CallContext context, batches.add(unloader.getRecordBatch()); } // Closing the stream will release the dictionaries, take ownership - final Dataset dataset = new Dataset( + final Dataset dataset = + new Dataset( flightStream.getDescriptor(), flightStream.getSchema(), flightStream.takeDictionaryOwnership(), @@ -143,10 +151,11 @@ private static final class Dataset implements AutoCloseable { private final DictionaryProvider dictionaryProvider; private final List batches; - private Dataset(FlightDescriptor descriptor, - Schema schema, - DictionaryProvider dictionaryProvider, - List batches) { + private Dataset( + FlightDescriptor descriptor, + Schema schema, + DictionaryProvider dictionaryProvider, + List batches) { this.descriptor = descriptor; this.schema = schema; this.dictionaryProvider = dictionaryProvider; @@ -157,20 +166,20 @@ public FlightInfo getFlightInfo(Location location) { ByteBuffer serializedDescriptor = descriptor.serialize(); byte[] descriptorBytes = new byte[serializedDescriptor.remaining()]; serializedDescriptor.get(descriptorBytes); - final List endpoints = Collections.singletonList( - new FlightEndpoint(new Ticket(descriptorBytes), location)); + final List endpoints = + Collections.singletonList(new FlightEndpoint(new Ticket(descriptorBytes), location)); return new FlightInfo( - messageFormatSchema(), - descriptor, - endpoints, - batches.stream().mapToLong(ArrowRecordBatch::computeBodyLength).sum(), - batches.stream().mapToInt(ArrowRecordBatch::getLength).sum()); + messageFormatSchema(), + descriptor, + endpoints, + batches.stream().mapToLong(ArrowRecordBatch::computeBodyLength).sum(), + batches.stream().mapToInt(ArrowRecordBatch::getLength).sum()); } private Schema messageFormatSchema() { final Set dictionaryIdsUsed = new HashSet<>(); - final List messageFormatFields = schema.getFields() - .stream() + final List messageFormatFields = + schema.getFields().stream() .map(f -> DictionaryUtility.toMessageFormat(f, dictionaryProvider, dictionaryIdsUsed)) .collect(Collectors.toList()); return new Schema(messageFormatFields, schema.getCustomMetadata()); diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestClient.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestClient.java index 2ea9874f3de..a693c02f193 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestClient.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestClient.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; - import org.apache.arrow.flight.AsyncPutListener; import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightDescriptor; @@ -49,11 +48,10 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -/** - * A Flight client for integration testing. - */ +/** A Flight client for integration testing. */ class IntegrationTestClient { - private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(IntegrationTestClient.class); + private static final org.slf4j.Logger LOGGER = + org.slf4j.LoggerFactory.getLogger(IntegrationTestClient.class); private final Options options; private IntegrationTestClient() { @@ -92,10 +90,11 @@ private void run(String[] args) throws Exception { final Location defaultLocation = Location.forGrpcInsecure(host, port); try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); - final FlightClient client = FlightClient.builder(allocator, defaultLocation).build()) { + final FlightClient client = FlightClient.builder(allocator, defaultLocation).build()) { if (cmd.hasOption("scenario")) { - Scenarios.getScenario(cmd.getOptionValue("scenario")).client(allocator, defaultLocation, client); + Scenarios.getScenario(cmd.getOptionValue("scenario")) + .client(allocator, defaultLocation, client); } else { final String inputPath = cmd.getOptionValue("j"); testStream(allocator, defaultLocation, client, inputPath); @@ -105,28 +104,36 @@ private void run(String[] args) throws Exception { } } - private static void testStream(BufferAllocator allocator, Location server, FlightClient client, String inputPath) + private static void testStream( + BufferAllocator allocator, Location server, FlightClient client, String inputPath) throws IOException { // 1. Read data from JSON and upload to server. FlightDescriptor descriptor = FlightDescriptor.path(inputPath); try (JsonFileReader reader = new JsonFileReader(new File(inputPath), allocator); - VectorSchemaRoot root = VectorSchemaRoot.create(reader.start(), allocator)) { - FlightClient.ClientStreamListener stream = client.startPut(descriptor, root, reader, - new AsyncPutListener() { - int counter = 0; - - @Override - public void onNext(PutResult val) { - final byte[] metadataRaw = new byte[checkedCastToInt(val.getApplicationMetadata().readableBytes())]; - val.getApplicationMetadata().readBytes(metadataRaw); - final String metadata = new String(metadataRaw, StandardCharsets.UTF_8); - if (!Integer.toString(counter).equals(metadata)) { - throw new RuntimeException( - String.format("Invalid ACK from server. Expected '%d' but got '%s'.", counter, metadata)); - } - counter++; - } - }); + VectorSchemaRoot root = VectorSchemaRoot.create(reader.start(), allocator)) { + FlightClient.ClientStreamListener stream = + client.startPut( + descriptor, + root, + reader, + new AsyncPutListener() { + int counter = 0; + + @Override + public void onNext(PutResult val) { + final byte[] metadataRaw = + new byte[checkedCastToInt(val.getApplicationMetadata().readableBytes())]; + val.getApplicationMetadata().readBytes(metadataRaw); + final String metadata = new String(metadataRaw, StandardCharsets.UTF_8); + if (!Integer.toString(counter).equals(metadata)) { + throw new RuntimeException( + String.format( + "Invalid ACK from server. Expected '%d' but got '%s'.", + counter, metadata)); + } + counter++; + } + }); int counter = 0; while (reader.read(root)) { final byte[] rawMetadata = Integer.toString(counter).getBytes(StandardCharsets.UTF_8); @@ -168,11 +175,12 @@ public void onNext(PutResult val) { } } - private static void testTicket(BufferAllocator allocator, FlightClient readClient, Ticket ticket, String inputPath) { + private static void testTicket( + BufferAllocator allocator, FlightClient readClient, Ticket ticket, String inputPath) { try (FlightStream stream = readClient.getStream(ticket); - VectorSchemaRoot root = stream.getRoot(); - VectorSchemaRoot downloadedRoot = VectorSchemaRoot.create(root.getSchema(), allocator); - JsonFileReader reader = new JsonFileReader(new File(inputPath), allocator)) { + VectorSchemaRoot root = stream.getRoot(); + VectorSchemaRoot downloadedRoot = VectorSchemaRoot.create(root.getSchema(), allocator); + JsonFileReader reader = new JsonFileReader(new File(inputPath), allocator)) { VectorLoader loader = new VectorLoader(downloadedRoot); VectorUnloader unloader = new VectorUnloader(root); diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestServer.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestServer.java index 6e22eb1ec31..673da423c96 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestServer.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/IntegrationTestServer.java @@ -28,11 +28,10 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -/** - * Flight server for integration testing. - */ +/** Flight server for integration testing. */ class IntegrationTestServer { - private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(IntegrationTestServer.class); + private static final org.slf4j.Logger LOGGER = + org.slf4j.LoggerFactory.getLogger(IntegrationTestServer.class); private final Options options; private IntegrationTestServer() { @@ -48,7 +47,8 @@ private void run(String[] args) throws Exception { final Location location = Location.forGrpcInsecure("localhost", port); final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - final FlightServer.Builder builder = FlightServer.builder().allocator(allocator).location(location); + final FlightServer.Builder builder = + FlightServer.builder().allocator(allocator).location(location); final FlightServer server; if (cmd.hasOption("scenario")) { @@ -64,14 +64,17 @@ private void run(String[] args) throws Exception { // Print out message for integration test script System.out.println("Server listening on localhost:" + server.getPort()); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - System.out.println("\nExiting..."); - AutoCloseables.close(server, allocator); - } catch (Exception e) { - e.printStackTrace(); - } - })); + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + try { + System.out.println("\nExiting..."); + AutoCloseables.close(server, allocator); + } catch (Exception e) { + e.printStackTrace(); + } + })); server.awaitTermination(); } @@ -92,5 +95,4 @@ private static void fatalError(String message, Throwable e) { LOGGER.error(message, e); System.exit(1); } - } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/MiddlewareScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/MiddlewareScenario.java index c284a577c08..9e4f751ed37 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/MiddlewareScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/MiddlewareScenario.java @@ -20,7 +20,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; - import org.apache.arrow.flight.CallHeaders; import org.apache.arrow.flight.CallInfo; import org.apache.arrow.flight.CallStatus; @@ -39,9 +38,9 @@ import org.apache.arrow.vector.types.pojo.Schema; /** - * Test an edge case in middleware: gRPC-Java consolidates headers and trailers if a call fails immediately. On the - * gRPC implementation side, we need to watch for this, or else we'll have a call with "no headers" if we only look - * for headers. + * Test an edge case in middleware: gRPC-Java consolidates headers and trailers if a call fails + * immediately. On the gRPC implementation side, we need to watch for this, or else we'll have a + * call with "no headers" if we only look for headers. */ final class MiddlewareScenario implements Scenario { @@ -56,7 +55,8 @@ public FlightProducer producer(BufferAllocator allocator, Location location) { public FlightInfo getFlightInfo(CallContext context, FlightDescriptor descriptor) { if (descriptor.isCommand()) { if (Arrays.equals(COMMAND_SUCCESS, descriptor.getCommand())) { - return new FlightInfo(new Schema(Collections.emptyList()), descriptor, Collections.emptyList(), -1, -1); + return new FlightInfo( + new Schema(Collections.emptyList()), descriptor, Collections.emptyList(), -1, -1); } } throw CallStatus.UNIMPLEMENTED.toRuntimeException(); @@ -66,22 +66,26 @@ public FlightInfo getFlightInfo(CallContext context, FlightDescriptor descriptor @Override public void buildServer(FlightServer.Builder builder) { - builder.middleware(FlightServerMiddleware.Key.of("test"), new InjectingServerMiddleware.Factory()); + builder.middleware( + FlightServerMiddleware.Key.of("test"), new InjectingServerMiddleware.Factory()); } @Override - public void client(BufferAllocator allocator, Location location, FlightClient ignored) throws Exception { + public void client(BufferAllocator allocator, Location location, FlightClient ignored) + throws Exception { final ExtractingClientMiddleware.Factory factory = new ExtractingClientMiddleware.Factory(); - try (final FlightClient client = FlightClient.builder(allocator, location).intercept(factory).build()) { + try (final FlightClient client = + FlightClient.builder(allocator, location).intercept(factory).build()) { // Should fail immediately - IntegrationAssertions.assertThrows(FlightRuntimeException.class, + IntegrationAssertions.assertThrows( + FlightRuntimeException.class, () -> client.getInfo(FlightDescriptor.command(new byte[0]))); if (!EXPECTED_HEADER_VALUE.equals(factory.extractedHeader)) { throw new AssertionError( - "Expected to extract the header value '" + - EXPECTED_HEADER_VALUE + - "', but found: " + - factory.extractedHeader); + "Expected to extract the header value '" + + EXPECTED_HEADER_VALUE + + "', but found: " + + factory.extractedHeader); } // Should not fail @@ -89,10 +93,10 @@ public void client(BufferAllocator allocator, Location location, FlightClient ig client.getInfo(FlightDescriptor.command(COMMAND_SUCCESS)); if (!EXPECTED_HEADER_VALUE.equals(factory.extractedHeader)) { throw new AssertionError( - "Expected to extract the header value '" + - EXPECTED_HEADER_VALUE + - "', but found: " + - factory.extractedHeader); + "Expected to extract the header value '" + + EXPECTED_HEADER_VALUE + + "', but found: " + + factory.extractedHeader); } } } @@ -112,19 +116,17 @@ public void onBeforeSendingHeaders(CallHeaders outgoingHeaders) { } @Override - public void onCallCompleted(CallStatus status) { - } + public void onCallCompleted(CallStatus status) {} @Override - public void onCallErrored(Throwable err) { - } + public void onCallErrored(Throwable err) {} /** The factory for the server middleware. */ static class Factory implements FlightServerMiddleware.Factory { @Override - public InjectingServerMiddleware onCallStarted(CallInfo info, CallHeaders incomingHeaders, - RequestContext context) { + public InjectingServerMiddleware onCallStarted( + CallInfo info, CallHeaders incomingHeaders, RequestContext context) { String incoming = incomingHeaders.get(HEADER); return new InjectingServerMiddleware(incoming == null ? "" : incoming); } @@ -151,8 +153,7 @@ public void onHeadersReceived(CallHeaders incomingHeaders) { } @Override - public void onCallCompleted(CallStatus status) { - } + public void onCallCompleted(CallStatus status) {} /** The factory for the client middleware. */ static class Factory implements FlightClientMiddleware.Factory { diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/OrderedScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/OrderedScenario.java index b8aa46fb567..711dbb93246 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/OrderedScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/OrderedScenario.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.List; import java.util.Objects; - import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightDescriptor; @@ -124,7 +123,8 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener l listener.error( CallStatus.INVALID_ARGUMENT .withDescription( - "Could not find flight: " + new String(ticket.getBytes(), StandardCharsets.UTF_8)) + "Could not find flight: " + + new String(ticket.getBytes(), StandardCharsets.UTF_8)) .toRuntimeException()); return; } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoProducer.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoProducer.java index 61312db56bc..6b3328e1bc7 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoProducer.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoProducer.java @@ -23,7 +23,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.flight.FlightDescriptor; import org.apache.arrow.flight.FlightEndpoint; import org.apache.arrow.flight.FlightInfo; @@ -40,17 +39,22 @@ class PollFlightInfoProducer extends NoOpFlightProducer { @Override public PollInfo pollFlightInfo(CallContext context, FlightDescriptor descriptor) { - Schema schema = new Schema( - Collections.singletonList(Field.notNullable("number", Types.MinorType.UINT4.getType()))); - List endpoints = Collections.singletonList( - new FlightEndpoint( - new Ticket("long-running query".getBytes(StandardCharsets.UTF_8)))); - FlightInfo info = new FlightInfo(schema, descriptor, endpoints, -1, -1 ); + Schema schema = + new Schema( + Collections.singletonList( + Field.notNullable("number", Types.MinorType.UINT4.getType()))); + List endpoints = + Collections.singletonList( + new FlightEndpoint(new Ticket("long-running query".getBytes(StandardCharsets.UTF_8)))); + FlightInfo info = new FlightInfo(schema, descriptor, endpoints, -1, -1); if (descriptor.isCommand() && Arrays.equals(descriptor.getCommand(), POLL_DESCRIPTOR)) { return new PollInfo(info, null, 1.0, null); } else { return new PollInfo( - info, FlightDescriptor.command(POLL_DESCRIPTOR), 0.1, Instant.now().plus(10, ChronoUnit.SECONDS)); + info, + FlightDescriptor.command(POLL_DESCRIPTOR), + 0.1, + Instant.now().plus(10, ChronoUnit.SECONDS)); } } } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoScenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoScenario.java index 1ffbe3c7262..107e881a73b 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoScenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/PollFlightInfoScenario.java @@ -19,7 +19,6 @@ import java.nio.charset.StandardCharsets; import java.util.Optional; - import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightDescriptor; import org.apache.arrow.flight.FlightProducer; @@ -36,27 +35,31 @@ public FlightProducer producer(BufferAllocator allocator, Location location) thr } @Override - public void buildServer(FlightServer.Builder builder) throws Exception { - } + public void buildServer(FlightServer.Builder builder) throws Exception {} @Override - public void client(BufferAllocator allocator, Location location, FlightClient client) throws Exception { - PollInfo info = client.pollInfo(FlightDescriptor.command("heavy query".getBytes(StandardCharsets.UTF_8))); + public void client(BufferAllocator allocator, Location location, FlightClient client) + throws Exception { + PollInfo info = + client.pollInfo(FlightDescriptor.command("heavy query".getBytes(StandardCharsets.UTF_8))); IntegrationAssertions.assertNotNull(info.getFlightInfo()); Optional progress = info.getProgress(); IntegrationAssertions.assertTrue("progress is missing", progress.isPresent()); - IntegrationAssertions.assertTrue("progress is invalid", progress.get() >= 0.0 && progress.get() <= 1.0); + IntegrationAssertions.assertTrue( + "progress is invalid", progress.get() >= 0.0 && progress.get() <= 1.0); IntegrationAssertions.assertTrue("expiration is missing", info.getExpirationTime().isPresent()); - IntegrationAssertions.assertTrue("descriptor is missing", - info.getFlightDescriptor().isPresent()); + IntegrationAssertions.assertTrue( + "descriptor is missing", info.getFlightDescriptor().isPresent()); info = client.pollInfo(info.getFlightDescriptor().get()); IntegrationAssertions.assertNotNull(info.getFlightInfo()); progress = info.getProgress(); IntegrationAssertions.assertTrue("progress is missing in finished query", progress.isPresent()); - IntegrationAssertions.assertTrue("progress isn't 1.0 in finished query", - Math.abs(progress.get() - 1.0) < Math.ulp(1.0)); - IntegrationAssertions.assertFalse("expiration is set in finished query", info.getExpirationTime().isPresent()); - IntegrationAssertions.assertFalse("descriptor is set in finished query", info.getFlightDescriptor().isPresent()); + IntegrationAssertions.assertTrue( + "progress isn't 1.0 in finished query", Math.abs(progress.get() - 1.0) < Math.ulp(1.0)); + IntegrationAssertions.assertFalse( + "expiration is set in finished query", info.getExpirationTime().isPresent()); + IntegrationAssertions.assertFalse( + "descriptor is set in finished query", info.getFlightDescriptor().isPresent()); } } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/Scenario.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/Scenario.java index bcc657b765c..e697038c1b5 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/Scenario.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/Scenario.java @@ -23,23 +23,15 @@ import org.apache.arrow.flight.Location; import org.apache.arrow.memory.BufferAllocator; -/** - * A particular scenario in integration testing. - */ +/** A particular scenario in integration testing. */ interface Scenario { - /** - * Construct the FlightProducer for a server in this scenario. - */ + /** Construct the FlightProducer for a server in this scenario. */ FlightProducer producer(BufferAllocator allocator, Location location) throws Exception; - /** - * Set any other server options. - */ + /** Set any other server options. */ void buildServer(FlightServer.Builder builder) throws Exception; - /** - * Run as the client in the scenario. - */ + /** Run as the client in the scenario. */ void client(BufferAllocator allocator, Location location, FlightClient client) throws Exception; } diff --git a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/Scenarios.java b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/Scenarios.java index c61fd94a4d2..fd0d33b4055 100644 --- a/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/Scenarios.java +++ b/java/flight/flight-integration-tests/src/main/java/org/apache/arrow/flight/integration/tests/Scenarios.java @@ -21,16 +21,13 @@ import java.util.TreeMap; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; - import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightServer; import org.apache.arrow.flight.Location; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; -/** - * Scenarios for integration testing. - */ +/** Scenarios for integration testing. */ final class Scenarios { private static Scenarios INSTANCE; @@ -40,8 +37,10 @@ final class Scenarios { private Scenarios() { scenarios = new TreeMap<>(); scenarios.put("auth:basic_proto", AuthBasicProtoScenario::new); - scenarios.put("expiration_time:cancel_flight_info", ExpirationTimeCancelFlightInfoScenario::new); - scenarios.put("expiration_time:renew_flight_endpoint", ExpirationTimeRenewFlightEndpointScenario::new); + scenarios.put( + "expiration_time:cancel_flight_info", ExpirationTimeCancelFlightInfoScenario::new); + scenarios.put( + "expiration_time:renew_flight_endpoint", ExpirationTimeRenewFlightEndpointScenario::new); scenarios.put("expiration_time:do_get", ExpirationTimeDoGetScenario::new); scenarios.put("expiration_time:list_actions", ExpirationTimeListActionsScenario::new); scenarios.put("middleware", MiddlewareScenario::new); @@ -76,8 +75,8 @@ public static void main(String[] args) { System.out.println("Running test scenario: " + entry.getKey()); final Scenario scenario = entry.getValue().get(); try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE)) { - final FlightServer.Builder builder = FlightServer - .builder(allocator, location, scenario.producer(allocator, location)); + final FlightServer.Builder builder = + FlightServer.builder(allocator, location, scenario.producer(allocator, location)); scenario.buildServer(builder); try (final FlightServer server = builder.build()) { server.start(); diff --git a/java/flight/flight-integration-tests/src/test/java/org/apache/arrow/flight/integration/tests/IntegrationTest.java b/java/flight/flight-integration-tests/src/test/java/org/apache/arrow/flight/integration/tests/IntegrationTest.java index 477a56055cb..ca198396bca 100644 --- a/java/flight/flight-integration-tests/src/test/java/org/apache/arrow/flight/integration/tests/IntegrationTest.java +++ b/java/flight/flight-integration-tests/src/test/java/org/apache/arrow/flight/integration/tests/IntegrationTest.java @@ -24,9 +24,7 @@ import org.apache.arrow.memory.RootAllocator; import org.junit.jupiter.api.Test; -/** - * Run the integration test scenarios in-process. - */ +/** Run the integration test scenarios in-process. */ class IntegrationTest { @Test void authBasicProto() throws Exception { @@ -85,9 +83,10 @@ void appMetadataFlightInfoEndpoint() throws Exception { void testScenario(String scenarioName) throws Exception { try (final BufferAllocator allocator = new RootAllocator()) { - final FlightServer.Builder builder = FlightServer.builder() - .allocator(allocator) - .location(Location.forGrpcInsecure("0.0.0.0", 0)); + final FlightServer.Builder builder = + FlightServer.builder() + .allocator(allocator) + .location(Location.forGrpcInsecure("0.0.0.0", 0)); final Scenario scenario = Scenarios.getScenario(scenarioName); scenario.buildServer(builder); builder.producer(scenario.producer(allocator, Location.forGrpcInsecure("0.0.0.0", 0))); diff --git a/java/flight/flight-integration-tests/src/test/resources/logback.xml b/java/flight/flight-integration-tests/src/test/resources/logback.xml index 95fb0b37dc5..df3ce59828e 100644 --- a/java/flight/flight-integration-tests/src/test/resources/logback.xml +++ b/java/flight/flight-integration-tests/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/flight/flight-sql-jdbc-core/pom.xml b/java/flight/flight-sql-jdbc-core/pom.xml index 1f20912b997..636c415725b 100644 --- a/java/flight/flight-sql-jdbc-core/pom.xml +++ b/java/flight/flight-sql-jdbc-core/pom.xml @@ -1,15 +1,14 @@ - + 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. --> diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadata.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadata.java index d68b8070e2b..d4f44c07b85 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadata.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadata.java @@ -35,6 +35,7 @@ import static java.sql.Types.VARCHAR; import static org.apache.arrow.flight.sql.util.SqlInfoOptionsUtils.doesBitmaskTranslateToEnum; +import com.google.protobuf.ProtocolMessageEnum; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.channels.Channels; @@ -52,7 +53,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; import java.util.stream.Collectors; - import org.apache.arrow.driver.jdbc.utils.SqlTypes; import org.apache.arrow.driver.jdbc.utils.VectorSchemaRootTransformer; import org.apache.arrow.flight.FlightInfo; @@ -85,11 +85,7 @@ import org.apache.calcite.avatica.AvaticaConnection; import org.apache.calcite.avatica.AvaticaDatabaseMetaData; -import com.google.protobuf.ProtocolMessageEnum; - -/** - * Arrow Flight JDBC's implementation of {@link DatabaseMetaData}. - */ +/** Arrow Flight JDBC's implementation of {@link DatabaseMetaData}. */ public class ArrowDatabaseMetadata extends AvaticaDatabaseMetaData { private static final String JAVA_REGEX_SPECIALS = "[]()|^-+*?{}$\\."; private static final Charset CHARSET = StandardCharsets.UTF_8; @@ -118,33 +114,33 @@ public class ArrowDatabaseMetadata extends AvaticaDatabaseMetaData { static final int DECIMAL_DIGITS_TIME_MILLISECONDS = 3; static final int DECIMAL_DIGITS_TIME_MICROSECONDS = 6; static final int DECIMAL_DIGITS_TIME_NANOSECONDS = 9; - private static final Schema GET_COLUMNS_SCHEMA = new Schema( - Arrays.asList( - Field.nullable("TABLE_CAT", Types.MinorType.VARCHAR.getType()), - Field.nullable("TABLE_SCHEM", Types.MinorType.VARCHAR.getType()), - Field.notNullable("TABLE_NAME", Types.MinorType.VARCHAR.getType()), - Field.notNullable("COLUMN_NAME", Types.MinorType.VARCHAR.getType()), - Field.nullable("DATA_TYPE", Types.MinorType.INT.getType()), - Field.nullable("TYPE_NAME", Types.MinorType.VARCHAR.getType()), - Field.nullable("COLUMN_SIZE", Types.MinorType.INT.getType()), - Field.nullable("BUFFER_LENGTH", Types.MinorType.INT.getType()), - Field.nullable("DECIMAL_DIGITS", Types.MinorType.INT.getType()), - Field.nullable("NUM_PREC_RADIX", Types.MinorType.INT.getType()), - Field.notNullable("NULLABLE", Types.MinorType.INT.getType()), - Field.nullable("REMARKS", Types.MinorType.VARCHAR.getType()), - Field.nullable("COLUMN_DEF", Types.MinorType.VARCHAR.getType()), - Field.nullable("SQL_DATA_TYPE", Types.MinorType.INT.getType()), - Field.nullable("SQL_DATETIME_SUB", Types.MinorType.INT.getType()), - Field.notNullable("CHAR_OCTET_LENGTH", Types.MinorType.INT.getType()), - Field.notNullable("ORDINAL_POSITION", Types.MinorType.INT.getType()), - Field.notNullable("IS_NULLABLE", Types.MinorType.VARCHAR.getType()), - Field.nullable("SCOPE_CATALOG", Types.MinorType.VARCHAR.getType()), - Field.nullable("SCOPE_SCHEMA", Types.MinorType.VARCHAR.getType()), - Field.nullable("SCOPE_TABLE", Types.MinorType.VARCHAR.getType()), - Field.nullable("SOURCE_DATA_TYPE", Types.MinorType.SMALLINT.getType()), - Field.notNullable("IS_AUTOINCREMENT", Types.MinorType.VARCHAR.getType()), - Field.notNullable("IS_GENERATEDCOLUMN", Types.MinorType.VARCHAR.getType()) - )); + private static final Schema GET_COLUMNS_SCHEMA = + new Schema( + Arrays.asList( + Field.nullable("TABLE_CAT", Types.MinorType.VARCHAR.getType()), + Field.nullable("TABLE_SCHEM", Types.MinorType.VARCHAR.getType()), + Field.notNullable("TABLE_NAME", Types.MinorType.VARCHAR.getType()), + Field.notNullable("COLUMN_NAME", Types.MinorType.VARCHAR.getType()), + Field.nullable("DATA_TYPE", Types.MinorType.INT.getType()), + Field.nullable("TYPE_NAME", Types.MinorType.VARCHAR.getType()), + Field.nullable("COLUMN_SIZE", Types.MinorType.INT.getType()), + Field.nullable("BUFFER_LENGTH", Types.MinorType.INT.getType()), + Field.nullable("DECIMAL_DIGITS", Types.MinorType.INT.getType()), + Field.nullable("NUM_PREC_RADIX", Types.MinorType.INT.getType()), + Field.notNullable("NULLABLE", Types.MinorType.INT.getType()), + Field.nullable("REMARKS", Types.MinorType.VARCHAR.getType()), + Field.nullable("COLUMN_DEF", Types.MinorType.VARCHAR.getType()), + Field.nullable("SQL_DATA_TYPE", Types.MinorType.INT.getType()), + Field.nullable("SQL_DATETIME_SUB", Types.MinorType.INT.getType()), + Field.notNullable("CHAR_OCTET_LENGTH", Types.MinorType.INT.getType()), + Field.notNullable("ORDINAL_POSITION", Types.MinorType.INT.getType()), + Field.notNullable("IS_NULLABLE", Types.MinorType.VARCHAR.getType()), + Field.nullable("SCOPE_CATALOG", Types.MinorType.VARCHAR.getType()), + Field.nullable("SCOPE_SCHEMA", Types.MinorType.VARCHAR.getType()), + Field.nullable("SCOPE_TABLE", Types.MinorType.VARCHAR.getType()), + Field.nullable("SOURCE_DATA_TYPE", Types.MinorType.SMALLINT.getType()), + Field.notNullable("IS_AUTOINCREMENT", Types.MinorType.VARCHAR.getType()), + Field.notNullable("IS_GENERATEDCOLUMN", Types.MinorType.VARCHAR.getType()))); private final AtomicBoolean isCachePopulated = new AtomicBoolean(false); private final Map cachedSqlInfo = new EnumMap<>(SqlInfo.class); private static final Map sqlTypesToFlightEnumConvertTypes = new HashMap<>(); @@ -160,12 +156,12 @@ public class ArrowDatabaseMetadata extends AvaticaDatabaseMetaData { sqlTypesToFlightEnumConvertTypes.put(REAL, SqlSupportsConvert.SQL_CONVERT_REAL_VALUE); sqlTypesToFlightEnumConvertTypes.put(DECIMAL, SqlSupportsConvert.SQL_CONVERT_DECIMAL_VALUE); sqlTypesToFlightEnumConvertTypes.put(BINARY, SqlSupportsConvert.SQL_CONVERT_BINARY_VALUE); - sqlTypesToFlightEnumConvertTypes.put(LONGVARBINARY, - SqlSupportsConvert.SQL_CONVERT_LONGVARBINARY_VALUE); + sqlTypesToFlightEnumConvertTypes.put( + LONGVARBINARY, SqlSupportsConvert.SQL_CONVERT_LONGVARBINARY_VALUE); sqlTypesToFlightEnumConvertTypes.put(CHAR, SqlSupportsConvert.SQL_CONVERT_CHAR_VALUE); sqlTypesToFlightEnumConvertTypes.put(VARCHAR, SqlSupportsConvert.SQL_CONVERT_VARCHAR_VALUE); - sqlTypesToFlightEnumConvertTypes.put(LONGNVARCHAR, - SqlSupportsConvert.SQL_CONVERT_LONGVARCHAR_VALUE); + sqlTypesToFlightEnumConvertTypes.put( + LONGNVARCHAR, SqlSupportsConvert.SQL_CONVERT_LONGVARCHAR_VALUE); sqlTypesToFlightEnumConvertTypes.put(DATE, SqlSupportsConvert.SQL_CONVERT_DATE_VALUE); sqlTypesToFlightEnumConvertTypes.put(TIMESTAMP, SqlSupportsConvert.SQL_CONVERT_TIMESTAMP_VALUE); } @@ -266,20 +262,20 @@ public boolean supportsConvert(final int fromType, final int toType) throws SQLE @Override public boolean supportsTableCorrelationNames() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTS_TABLE_CORRELATION_NAMES, - Boolean.class); + return getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTS_TABLE_CORRELATION_NAMES, Boolean.class); } @Override public boolean supportsDifferentTableCorrelationNames() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES, - Boolean.class); + return getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES, Boolean.class); } @Override public boolean supportsExpressionsInOrderBy() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTS_EXPRESSIONS_IN_ORDER_BY, - Boolean.class); + return getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTS_EXPRESSIONS_IN_ORDER_BY, Boolean.class); } @Override @@ -296,8 +292,8 @@ public boolean supportsGroupBy() throws SQLException { @Override public boolean supportsGroupByUnrelated() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_GROUP_BY, - SqlSupportedGroupBy.SQL_GROUP_BY_UNRELATED); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_GROUP_BY, SqlSupportedGroupBy.SQL_GROUP_BY_UNRELATED); } @Override @@ -307,66 +303,75 @@ public boolean supportsLikeEscapeClause() throws SQLException { @Override public boolean supportsNonNullableColumns() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTS_NON_NULLABLE_COLUMNS, - Boolean.class); + return getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTS_NON_NULLABLE_COLUMNS, Boolean.class); } @Override public boolean supportsMinimumSQLGrammar() throws SQLException { return checkEnumLevel( - Arrays.asList(getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_GRAMMAR, - SupportedSqlGrammar.SQL_EXTENDED_GRAMMAR), - getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_GRAMMAR, - SupportedSqlGrammar.SQL_CORE_GRAMMAR), - getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_GRAMMAR, - SupportedSqlGrammar.SQL_MINIMUM_GRAMMAR))); + Arrays.asList( + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_GRAMMAR, SupportedSqlGrammar.SQL_EXTENDED_GRAMMAR), + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_GRAMMAR, SupportedSqlGrammar.SQL_CORE_GRAMMAR), + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_GRAMMAR, SupportedSqlGrammar.SQL_MINIMUM_GRAMMAR))); } @Override public boolean supportsCoreSQLGrammar() throws SQLException { return checkEnumLevel( - Arrays.asList(getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_GRAMMAR, - SupportedSqlGrammar.SQL_EXTENDED_GRAMMAR), - getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_GRAMMAR, - SupportedSqlGrammar.SQL_CORE_GRAMMAR))); + Arrays.asList( + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_GRAMMAR, SupportedSqlGrammar.SQL_EXTENDED_GRAMMAR), + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_GRAMMAR, SupportedSqlGrammar.SQL_CORE_GRAMMAR))); } @Override public boolean supportsExtendedSQLGrammar() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_GRAMMAR, - SupportedSqlGrammar.SQL_EXTENDED_GRAMMAR); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_GRAMMAR, SupportedSqlGrammar.SQL_EXTENDED_GRAMMAR); } @Override public boolean supportsANSI92EntryLevelSQL() throws SQLException { return checkEnumLevel( - Arrays.asList(getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, + Arrays.asList( + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, SupportedAnsi92SqlGrammarLevel.ANSI92_ENTRY_SQL), - getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, SupportedAnsi92SqlGrammarLevel.ANSI92_INTERMEDIATE_SQL), - getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, SupportedAnsi92SqlGrammarLevel.ANSI92_FULL_SQL))); } @Override public boolean supportsANSI92IntermediateSQL() throws SQLException { return checkEnumLevel( - Arrays.asList(getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, + Arrays.asList( + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, SupportedAnsi92SqlGrammarLevel.ANSI92_ENTRY_SQL), - getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, + getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, SupportedAnsi92SqlGrammarLevel.ANSI92_INTERMEDIATE_SQL))); } @Override public boolean supportsANSI92FullSQL() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, - SupportedAnsi92SqlGrammarLevel.ANSI92_FULL_SQL); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL, SupportedAnsi92SqlGrammarLevel.ANSI92_FULL_SQL); } @Override public boolean supportsIntegrityEnhancementFacility() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY, - Boolean.class); + return getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY, Boolean.class); } @Override @@ -378,14 +383,14 @@ public boolean supportsOuterJoins() throws SQLException { @Override public boolean supportsFullOuterJoins() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_OUTER_JOINS_SUPPORT_LEVEL, - SqlOuterJoinsSupportLevel.SQL_FULL_OUTER_JOINS); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_OUTER_JOINS_SUPPORT_LEVEL, SqlOuterJoinsSupportLevel.SQL_FULL_OUTER_JOINS); } @Override public boolean supportsLimitedOuterJoins() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_OUTER_JOINS_SUPPORT_LEVEL, - SqlOuterJoinsSupportLevel.SQL_LIMITED_OUTER_JOINS); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_OUTER_JOINS_SUPPORT_LEVEL, SqlOuterJoinsSupportLevel.SQL_LIMITED_OUTER_JOINS); } @Override @@ -410,43 +415,50 @@ public boolean isCatalogAtStart() throws SQLException { @Override public boolean supportsSchemasInProcedureCalls() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SCHEMAS_SUPPORTED_ACTIONS, + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SCHEMAS_SUPPORTED_ACTIONS, SqlSupportedElementActions.SQL_ELEMENT_IN_PROCEDURE_CALLS); } @Override public boolean supportsSchemasInIndexDefinitions() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SCHEMAS_SUPPORTED_ACTIONS, + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SCHEMAS_SUPPORTED_ACTIONS, SqlSupportedElementActions.SQL_ELEMENT_IN_INDEX_DEFINITIONS); } @Override public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SCHEMAS_SUPPORTED_ACTIONS, + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SCHEMAS_SUPPORTED_ACTIONS, SqlSupportedElementActions.SQL_ELEMENT_IN_PRIVILEGE_DEFINITIONS); } @Override public boolean supportsCatalogsInIndexDefinitions() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_CATALOGS_SUPPORTED_ACTIONS, + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_CATALOGS_SUPPORTED_ACTIONS, SqlSupportedElementActions.SQL_ELEMENT_IN_INDEX_DEFINITIONS); } @Override public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_CATALOGS_SUPPORTED_ACTIONS, + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_CATALOGS_SUPPORTED_ACTIONS, SqlSupportedElementActions.SQL_ELEMENT_IN_PRIVILEGE_DEFINITIONS); } @Override public boolean supportsPositionedDelete() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_POSITIONED_COMMANDS, + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_POSITIONED_COMMANDS, SqlSupportedPositionedCommands.SQL_POSITIONED_DELETE); } @Override public boolean supportsPositionedUpdate() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_POSITIONED_COMMANDS, + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_POSITIONED_COMMANDS, SqlSupportedPositionedCommands.SQL_POSITIONED_UPDATE); } @@ -457,14 +469,14 @@ public boolean supportsResultSetType(final int type) throws SQLException { switch (type) { case ResultSet.TYPE_FORWARD_ONLY: - return doesBitmaskTranslateToEnum(SqlSupportedResultSetType.SQL_RESULT_SET_TYPE_FORWARD_ONLY, - bitmask); + return doesBitmaskTranslateToEnum( + SqlSupportedResultSetType.SQL_RESULT_SET_TYPE_FORWARD_ONLY, bitmask); case ResultSet.TYPE_SCROLL_INSENSITIVE: - return doesBitmaskTranslateToEnum(SqlSupportedResultSetType.SQL_RESULT_SET_TYPE_SCROLL_INSENSITIVE, - bitmask); + return doesBitmaskTranslateToEnum( + SqlSupportedResultSetType.SQL_RESULT_SET_TYPE_SCROLL_INSENSITIVE, bitmask); case ResultSet.TYPE_SCROLL_SENSITIVE: - return doesBitmaskTranslateToEnum(SqlSupportedResultSetType.SQL_RESULT_SET_TYPE_SCROLL_SENSITIVE, - bitmask); + return doesBitmaskTranslateToEnum( + SqlSupportedResultSetType.SQL_RESULT_SET_TYPE_SCROLL_SENSITIVE, bitmask); default: throw new SQLException( "Invalid result set type argument. The informed type is not defined in java.sql.ResultSet."); @@ -483,32 +495,32 @@ public boolean supportsStoredProcedures() throws SQLException { @Override public boolean supportsSubqueriesInComparisons() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_SUBQUERIES, - SqlSupportedSubqueries.SQL_SUBQUERIES_IN_COMPARISONS); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_SUBQUERIES, SqlSupportedSubqueries.SQL_SUBQUERIES_IN_COMPARISONS); } @Override public boolean supportsSubqueriesInExists() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_SUBQUERIES, - SqlSupportedSubqueries.SQL_SUBQUERIES_IN_EXISTS); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_SUBQUERIES, SqlSupportedSubqueries.SQL_SUBQUERIES_IN_EXISTS); } @Override public boolean supportsSubqueriesInIns() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_SUBQUERIES, - SqlSupportedSubqueries.SQL_SUBQUERIES_IN_INS); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_SUBQUERIES, SqlSupportedSubqueries.SQL_SUBQUERIES_IN_INS); } @Override public boolean supportsSubqueriesInQuantifieds() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_SUBQUERIES, - SqlSupportedSubqueries.SQL_SUBQUERIES_IN_QUANTIFIEDS); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_SUBQUERIES, SqlSupportedSubqueries.SQL_SUBQUERIES_IN_QUANTIFIEDS); } @Override public boolean supportsCorrelatedSubqueries() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_CORRELATED_SUBQUERIES_SUPPORTED, - Boolean.class); + return getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_CORRELATED_SUBQUERIES_SUPPORTED, Boolean.class); } @Override @@ -520,56 +532,56 @@ public boolean supportsUnion() throws SQLException { @Override public boolean supportsUnionAll() throws SQLException { - return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_UNIONS, - SqlSupportedUnions.SQL_UNION_ALL); + return getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_UNIONS, SqlSupportedUnions.SQL_UNION_ALL); } @Override public int getMaxBinaryLiteralLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_BINARY_LITERAL_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_BINARY_LITERAL_LENGTH, Long.class) + .intValue(); } @Override public int getMaxCharLiteralLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_CHAR_LITERAL_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_CHAR_LITERAL_LENGTH, Long.class) + .intValue(); } @Override public int getMaxColumnNameLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMN_NAME_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMN_NAME_LENGTH, Long.class) + .intValue(); } @Override public int getMaxColumnsInGroupBy() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_GROUP_BY, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_GROUP_BY, Long.class) + .intValue(); } @Override public int getMaxColumnsInIndex() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_INDEX, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_INDEX, Long.class) + .intValue(); } @Override public int getMaxColumnsInOrderBy() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_ORDER_BY, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_ORDER_BY, Long.class) + .intValue(); } @Override public int getMaxColumnsInSelect() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_SELECT, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_SELECT, Long.class) + .intValue(); } @Override public int getMaxColumnsInTable() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_TABLE, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_COLUMNS_IN_TABLE, Long.class) + .intValue(); } @Override @@ -579,8 +591,8 @@ public int getMaxConnections() throws SQLException { @Override public int getMaxCursorNameLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_CURSOR_NAME_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_CURSOR_NAME_LENGTH, Long.class) + .intValue(); } @Override @@ -590,20 +602,20 @@ public int getMaxIndexLength() throws SQLException { @Override public int getMaxSchemaNameLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_DB_SCHEMA_NAME_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_DB_SCHEMA_NAME_LENGTH, Long.class) + .intValue(); } @Override public int getMaxProcedureNameLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_PROCEDURE_NAME_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_PROCEDURE_NAME_LENGTH, Long.class) + .intValue(); } @Override public int getMaxCatalogNameLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_CATALOG_NAME_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_CATALOG_NAME_LENGTH, Long.class) + .intValue(); } @Override @@ -618,8 +630,8 @@ public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { @Override public int getMaxStatementLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_STATEMENT_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_STATEMENT_LENGTH, Long.class) + .intValue(); } @Override @@ -629,14 +641,14 @@ public int getMaxStatements() throws SQLException { @Override public int getMaxTableNameLength() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_TABLE_NAME_LENGTH, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_TABLE_NAME_LENGTH, Long.class) + .intValue(); } @Override public int getMaxTablesInSelect() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_TABLES_IN_SELECT, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_MAX_TABLES_IN_SELECT, Long.class) + .intValue(); } @Override @@ -646,8 +658,8 @@ public int getMaxUserNameLength() throws SQLException { @Override public int getDefaultTransactionIsolation() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_DEFAULT_TRANSACTION_ISOLATION, - Long.class).intValue(); + return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_DEFAULT_TRANSACTION_ISOLATION, Long.class) + .intValue(); } @Override @@ -658,24 +670,25 @@ public boolean supportsTransactions() throws SQLException { @Override public boolean supportsTransactionIsolationLevel(final int level) throws SQLException { final int bitmask = - getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_SUPPORTED_TRANSACTIONS_ISOLATION_LEVELS, - Integer.class); + getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_SUPPORTED_TRANSACTIONS_ISOLATION_LEVELS, Integer.class); switch (level) { case Connection.TRANSACTION_NONE: - return doesBitmaskTranslateToEnum(SqlTransactionIsolationLevel.SQL_TRANSACTION_NONE, bitmask); + return doesBitmaskTranslateToEnum( + SqlTransactionIsolationLevel.SQL_TRANSACTION_NONE, bitmask); case Connection.TRANSACTION_READ_COMMITTED: - return doesBitmaskTranslateToEnum(SqlTransactionIsolationLevel.SQL_TRANSACTION_READ_COMMITTED, - bitmask); + return doesBitmaskTranslateToEnum( + SqlTransactionIsolationLevel.SQL_TRANSACTION_READ_COMMITTED, bitmask); case Connection.TRANSACTION_READ_UNCOMMITTED: - return doesBitmaskTranslateToEnum(SqlTransactionIsolationLevel.SQL_TRANSACTION_READ_UNCOMMITTED, - bitmask); + return doesBitmaskTranslateToEnum( + SqlTransactionIsolationLevel.SQL_TRANSACTION_READ_UNCOMMITTED, bitmask); case Connection.TRANSACTION_REPEATABLE_READ: - return doesBitmaskTranslateToEnum(SqlTransactionIsolationLevel.SQL_TRANSACTION_REPEATABLE_READ, - bitmask); + return doesBitmaskTranslateToEnum( + SqlTransactionIsolationLevel.SQL_TRANSACTION_REPEATABLE_READ, bitmask); case Connection.TRANSACTION_SERIALIZABLE: - return doesBitmaskTranslateToEnum(SqlTransactionIsolationLevel.SQL_TRANSACTION_SERIALIZABLE, - bitmask); + return doesBitmaskTranslateToEnum( + SqlTransactionIsolationLevel.SQL_TRANSACTION_SERIALIZABLE, bitmask); default: throw new SQLException( "Invalid transaction isolation level argument. The informed level is not defined in java.sql.Connection."); @@ -684,14 +697,14 @@ public boolean supportsTransactionIsolationLevel(final int level) throws SQLExce @Override public boolean dataDefinitionCausesTransactionCommit() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT, - Boolean.class); + return getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT, Boolean.class); } @Override public boolean dataDefinitionIgnoredInTransactions() throws SQLException { - return getSqlInfoAndCacheIfCacheIsEmpty(SqlInfo.SQL_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED, - Boolean.class); + return getSqlInfoAndCacheIfCacheIsEmpty( + SqlInfo.SQL_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED, Boolean.class); } @Override @@ -725,24 +738,25 @@ public ArrowFlightConnection getConnection() throws SQLException { return (ArrowFlightConnection) super.getConnection(); } - private T getSqlInfoAndCacheIfCacheIsEmpty(final SqlInfo sqlInfoCommand, - final Class desiredType) - throws SQLException { + private T getSqlInfoAndCacheIfCacheIsEmpty( + final SqlInfo sqlInfoCommand, final Class desiredType) throws SQLException { final ArrowFlightConnection connection = getConnection(); if (!isCachePopulated.get()) { // Lock-and-populate the cache. Only issue the call to getSqlInfo() once, // populate the cache, then mark it as populated. - // Note that multiple callers from separate threads can see that the cache is not populated, but only - // one thread will try to populate the cache. Other threads will see the cache is non-empty when acquiring + // Note that multiple callers from separate threads can see that the cache is not populated, + // but only + // one thread will try to populate the cache. Other threads will see the cache is non-empty + // when acquiring // the lock on the cache and skip population. synchronized (cachedSqlInfo) { if (cachedSqlInfo.isEmpty()) { final FlightInfo sqlInfo = connection.getClientHandler().getSqlInfo(); try (final ResultSet resultSet = - ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( - connection, sqlInfo, null)) { + ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, sqlInfo, null)) { while (resultSet.next()) { - cachedSqlInfo.put(SqlInfo.forNumber((Integer) resultSet.getObject("info_name")), + cachedSqlInfo.put( + SqlInfo.forNumber((Integer) resultSet.getObject("info_name")), resultSet.getObject("value")); } } @@ -758,9 +772,7 @@ private String convertListSqlInfoToString(final List sqlInfoList) { } private boolean getSqlInfoEnumOptionAndCacheIfCacheIsEmpty( - final SqlInfo sqlInfoCommand, - final ProtocolMessageEnum enumInstance - ) throws SQLException { + final SqlInfo sqlInfoCommand, final ProtocolMessageEnum enumInstance) throws SQLException { final int bitmask = getSqlInfoAndCacheIfCacheIsEmpty(sqlInfoCommand, Integer.class); return doesBitmaskTranslateToEnum(enumInstance, bitmask); } @@ -779,8 +791,8 @@ public ResultSet getCatalogs() throws SQLException { new VectorSchemaRootTransformer.Builder(Schemas.GET_CATALOGS_SCHEMA, allocator) .renameFieldVector("catalog_name", "TABLE_CAT") .build(); - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoCatalogs, - transformer); + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, flightInfoCatalogs, transformer); } @Override @@ -792,8 +804,8 @@ public ResultSet getImportedKeys(final String catalog, final String schema, fina final BufferAllocator allocator = connection.getBufferAllocator(); final VectorSchemaRootTransformer transformer = getForeignKeysTransformer(allocator); - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoImportedKeys, - transformer); + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, flightInfoImportedKeys, transformer); } @Override @@ -805,33 +817,43 @@ public ResultSet getExportedKeys(final String catalog, final String schema, fina final BufferAllocator allocator = connection.getBufferAllocator(); final VectorSchemaRootTransformer transformer = getForeignKeysTransformer(allocator); - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoExportedKeys, - transformer); + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, flightInfoExportedKeys, transformer); } @Override - public ResultSet getCrossReference(final String parentCatalog, final String parentSchema, - final String parentTable, - final String foreignCatalog, final String foreignSchema, - final String foreignTable) + public ResultSet getCrossReference( + final String parentCatalog, + final String parentSchema, + final String parentTable, + final String foreignCatalog, + final String foreignSchema, + final String foreignTable) throws SQLException { final ArrowFlightConnection connection = getConnection(); - final FlightInfo flightInfoCrossReference = connection.getClientHandler().getCrossReference( - parentCatalog, parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable); + final FlightInfo flightInfoCrossReference = + connection + .getClientHandler() + .getCrossReference( + parentCatalog, + parentSchema, + parentTable, + foreignCatalog, + foreignSchema, + foreignTable); final BufferAllocator allocator = connection.getBufferAllocator(); final VectorSchemaRootTransformer transformer = getForeignKeysTransformer(allocator); - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoCrossReference, - transformer); + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, flightInfoCrossReference, transformer); } /** - * Transformer used on getImportedKeys, getExportedKeys and getCrossReference methods, since - * all three share the same schema. + * Transformer used on getImportedKeys, getExportedKeys and getCrossReference methods, since all + * three share the same schema. */ private VectorSchemaRootTransformer getForeignKeysTransformer(final BufferAllocator allocator) { - return new VectorSchemaRootTransformer.Builder(Schemas.GET_IMPORTED_KEYS_SCHEMA, - allocator) + return new VectorSchemaRootTransformer.Builder(Schemas.GET_IMPORTED_KEYS_SCHEMA, allocator) .renameFieldVector("pk_catalog_name", "PKTABLE_CAT") .renameFieldVector("pk_db_schema_name", "PKTABLE_SCHEM") .renameFieldVector("pk_table_name", "PKTABLE_NAME") @@ -862,8 +884,8 @@ public ResultSet getSchemas(final String catalog, final String schemaPattern) .renameFieldVector("db_schema_name", "TABLE_SCHEM") .renameFieldVector("catalog_name", "TABLE_CATALOG") .build(); - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoSchemas, - transformer); + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, flightInfoSchemas, transformer); } @Override @@ -876,19 +898,22 @@ public ResultSet getTableTypes() throws SQLException { new VectorSchemaRootTransformer.Builder(Schemas.GET_TABLE_TYPES_SCHEMA, allocator) .renameFieldVector("table_type", "TABLE_TYPE") .build(); - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoTableTypes, - transformer); + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, flightInfoTableTypes, transformer); } @Override - public ResultSet getTables(final String catalog, final String schemaPattern, - final String tableNamePattern, - final String[] types) + public ResultSet getTables( + final String catalog, + final String schemaPattern, + final String tableNamePattern, + final String[] types) throws SQLException { final ArrowFlightConnection connection = getConnection(); final List typesList = types == null ? null : Arrays.asList(types); final FlightInfo flightInfoTables = - connection.getClientHandler() + connection + .getClientHandler() .getTables(catalog, schemaPattern, tableNamePattern, typesList, false); final BufferAllocator allocator = connection.getBufferAllocator(); @@ -905,8 +930,8 @@ public ResultSet getTables(final String catalog, final String schemaPattern, .addEmptyField("SELF_REFERENCING_COL_NAME", Types.MinorType.VARBINARY) .addEmptyField("REF_GENERATION", Types.MinorType.VARBINARY) .build(); - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoTables, - transformer); + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, flightInfoTables, transformer); } @Override @@ -926,18 +951,21 @@ public ResultSet getPrimaryKeys(final String catalog, final String schema, final .renameFieldVector("key_sequence", "KEY_SEQ") .renameFieldVector("key_name", "PK_NAME") .build(); - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoPrimaryKeys, - transformer); + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, flightInfoPrimaryKeys, transformer); } @Override - public ResultSet getColumns(final String catalog, final String schemaPattern, - final String tableNamePattern, - final String columnNamePattern) + public ResultSet getColumns( + final String catalog, + final String schemaPattern, + final String tableNamePattern, + final String columnNamePattern) throws SQLException { final ArrowFlightConnection connection = getConnection(); final FlightInfo flightInfoTables = - connection.getClientHandler() + connection + .getClientHandler() .getTables(catalog, schemaPattern, tableNamePattern, null, true); final BufferAllocator allocator = connection.getBufferAllocator(); @@ -945,7 +973,9 @@ public ResultSet getColumns(final String catalog, final String schemaPattern, final Pattern columnNamePat = columnNamePattern != null ? Pattern.compile(sqlToRegexLike(columnNamePattern)) : null; - return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(connection, flightInfoTables, + return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo( + connection, + flightInfoTables, (originalRoot, transformedRoot) -> { int columnCounter = 0; if (transformedRoot == null) { @@ -971,18 +1001,25 @@ public ResultSet getColumns(final String catalog, final String schemaPattern, final Schema currentSchema; try { - currentSchema = MessageSerializer.deserializeSchema( - new ReadChannel(Channels.newChannel( - new ByteArrayInputStream(schemaVector.get(i))))); + currentSchema = + MessageSerializer.deserializeSchema( + new ReadChannel( + Channels.newChannel(new ByteArrayInputStream(schemaVector.get(i))))); } catch (final IOException e) { throw new IOException( String.format("Failed to deserialize schema for table %s", tableName), e); } final List tableColumns = currentSchema.getFields(); - columnCounter = setGetColumnsVectorSchemaRootFromFields(transformedRoot, columnCounter, - tableColumns, - catalogName, tableName, schemaName, columnNamePat); + columnCounter = + setGetColumnsVectorSchemaRootFromFields( + transformedRoot, + columnCounter, + tableColumns, + catalogName, + tableName, + schemaName, + columnNamePat); } transformedRoot.setRowCount(columnCounter); @@ -992,12 +1029,14 @@ public ResultSet getColumns(final String catalog, final String schemaPattern, }); } - private int setGetColumnsVectorSchemaRootFromFields(final VectorSchemaRoot currentRoot, - int insertIndex, - final List tableColumns, - final Text catalogName, - final Text tableName, final Text schemaName, - final Pattern columnNamePattern) { + private int setGetColumnsVectorSchemaRootFromFields( + final VectorSchemaRoot currentRoot, + int insertIndex, + final List tableColumns, + final Text catalogName, + final Text tableName, + final Text schemaName, + final Pattern columnNamePattern) { int ordinalIndex = 1; final int tableColumnsSize = tableColumns.size(); @@ -1013,12 +1052,15 @@ private int setGetColumnsVectorSchemaRootFromFields(final VectorSchemaRoot curre final IntVector nullableVector = (IntVector) currentRoot.getVector("NULLABLE"); final IntVector ordinalPositionVector = (IntVector) currentRoot.getVector("ORDINAL_POSITION"); final VarCharVector isNullableVector = (VarCharVector) currentRoot.getVector("IS_NULLABLE"); - final VarCharVector isAutoincrementVector = (VarCharVector) currentRoot.getVector("IS_AUTOINCREMENT"); - final VarCharVector isGeneratedColumnVector = (VarCharVector) currentRoot.getVector("IS_GENERATEDCOLUMN"); + final VarCharVector isAutoincrementVector = + (VarCharVector) currentRoot.getVector("IS_AUTOINCREMENT"); + final VarCharVector isGeneratedColumnVector = + (VarCharVector) currentRoot.getVector("IS_GENERATEDCOLUMN"); for (int i = 0; i < tableColumnsSize; i++, ordinalIndex++) { final Field field = tableColumns.get(i); - final FlightSqlColumnMetadata columnMetadata = new FlightSqlColumnMetadata(field.getMetadata()); + final FlightSqlColumnMetadata columnMetadata = + new FlightSqlColumnMetadata(field.getMetadata()); final String columnName = field.getName(); if (columnNamePattern != null && !columnNamePattern.matcher(columnName).matches()) { @@ -1043,13 +1085,15 @@ private int setGetColumnsVectorSchemaRootFromFields(final VectorSchemaRoot curre } dataTypeVector.setSafe(insertIndex, SqlTypes.getSqlTypeIdFromArrowType(fieldType)); - byte[] typeName = columnMetadata.getTypeName() != null ? - columnMetadata.getTypeName().getBytes(CHARSET) : - SqlTypes.getSqlTypeNameFromArrowType(fieldType).getBytes(CHARSET); + byte[] typeName = + columnMetadata.getTypeName() != null + ? columnMetadata.getTypeName().getBytes(CHARSET) + : SqlTypes.getSqlTypeNameFromArrowType(fieldType).getBytes(CHARSET); typeNameVector.setSafe(insertIndex, typeName); // We aren't setting COLUMN_SIZE for ROWID SQL Types, as there's no such Arrow type. - // We aren't setting COLUMN_SIZE nor DECIMAL_DIGITS for Float/Double as their precision and scale are variable. + // We aren't setting COLUMN_SIZE nor DECIMAL_DIGITS for Float/Double as their precision and + // scale are variable. if (fieldType instanceof ArrowType.Decimal) { numPrecRadixVector.setSafe(insertIndex, BASE10_RADIX); } else if (fieldType instanceof ArrowType.Int) { @@ -1142,7 +1186,8 @@ static Integer getDecimalDigits(final ArrowType fieldType) { static Integer getColumnSize(final ArrowType fieldType) { // We aren't setting COLUMN_SIZE for ROWID SQL Types, as there's no such Arrow type. - // We aren't setting COLUMN_SIZE nor DECIMAL_DIGITS for Float/Double as their precision and scale are variable. + // We aren't setting COLUMN_SIZE nor DECIMAL_DIGITS for Float/Double as their precision and + // scale are variable. if (fieldType instanceof ArrowType.Decimal) { final ArrowType.Decimal thisDecimal = (ArrowType.Decimal) fieldType; return thisDecimal.getPrecision(); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightConnection.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightConnection.java index ad19c616ff2..a70e7899d84 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightConnection.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightConnection.java @@ -19,11 +19,11 @@ import static org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty.replaceSemiColons; +import io.netty.util.concurrent.DefaultThreadFactory; import java.sql.SQLException; import java.util.Properties; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; - import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl; import org.apache.arrow.flight.FlightClient; @@ -33,11 +33,7 @@ import org.apache.calcite.avatica.AvaticaConnection; import org.apache.calcite.avatica.AvaticaFactory; -import io.netty.util.concurrent.DefaultThreadFactory; - -/** - * Connection to the Arrow Flight server. - */ +/** Connection to the Arrow Flight server. */ public final class ArrowFlightConnection extends AvaticaConnection { private final BufferAllocator allocator; @@ -48,19 +44,22 @@ public final class ArrowFlightConnection extends AvaticaConnection { /** * Creates a new {@link ArrowFlightConnection}. * - * @param driver the {@link ArrowFlightJdbcDriver} to use. - * @param factory the {@link AvaticaFactory} to use. - * @param url the URL to use. - * @param properties the {@link Properties} to use. - * @param config the {@link ArrowFlightConnectionConfigImpl} to use. - * @param allocator the {@link BufferAllocator} to use. + * @param driver the {@link ArrowFlightJdbcDriver} to use. + * @param factory the {@link AvaticaFactory} to use. + * @param url the URL to use. + * @param properties the {@link Properties} to use. + * @param config the {@link ArrowFlightConnectionConfigImpl} to use. + * @param allocator the {@link BufferAllocator} to use. * @param clientHandler the {@link ArrowFlightSqlClientHandler} to use. */ - private ArrowFlightConnection(final ArrowFlightJdbcDriver driver, final AvaticaFactory factory, - final String url, final Properties properties, - final ArrowFlightConnectionConfigImpl config, - final BufferAllocator allocator, - final ArrowFlightSqlClientHandler clientHandler) { + private ArrowFlightConnection( + final ArrowFlightJdbcDriver driver, + final AvaticaFactory factory, + final String url, + final Properties properties, + final ArrowFlightConnectionConfigImpl config, + final BufferAllocator allocator, + final ArrowFlightSqlClientHandler clientHandler) { super(driver, factory, url, properties); this.config = Preconditions.checkNotNull(config, "Config cannot be null."); this.allocator = Preconditions.checkNotNull(allocator, "Allocator cannot be null."); @@ -70,28 +69,31 @@ private ArrowFlightConnection(final ArrowFlightJdbcDriver driver, final AvaticaF /** * Creates a new {@link ArrowFlightConnection} to a {@link FlightClient}. * - * @param driver the {@link ArrowFlightJdbcDriver} to use. - * @param factory the {@link AvaticaFactory} to use. - * @param url the URL to establish the connection to. + * @param driver the {@link ArrowFlightJdbcDriver} to use. + * @param factory the {@link AvaticaFactory} to use. + * @param url the URL to establish the connection to. * @param properties the {@link Properties} to use for this session. - * @param allocator the {@link BufferAllocator} to use. + * @param allocator the {@link BufferAllocator} to use. * @return a new {@link ArrowFlightConnection}. * @throws SQLException on error. */ - static ArrowFlightConnection createNewConnection(final ArrowFlightJdbcDriver driver, - final AvaticaFactory factory, - String url, final Properties properties, - final BufferAllocator allocator) + static ArrowFlightConnection createNewConnection( + final ArrowFlightJdbcDriver driver, + final AvaticaFactory factory, + String url, + final Properties properties, + final BufferAllocator allocator) throws SQLException { url = replaceSemiColons(url); final ArrowFlightConnectionConfigImpl config = new ArrowFlightConnectionConfigImpl(properties); final ArrowFlightSqlClientHandler clientHandler = createNewClientHandler(config, allocator); - return new ArrowFlightConnection(driver, factory, url, properties, config, allocator, clientHandler); + return new ArrowFlightConnection( + driver, factory, url, properties, config, allocator, clientHandler); } private static ArrowFlightSqlClientHandler createNewClientHandler( - final ArrowFlightConnectionConfigImpl config, - final BufferAllocator allocator) throws SQLException { + final ArrowFlightConnectionConfigImpl config, final BufferAllocator allocator) + throws SQLException { try { return new ArrowFlightSqlClientHandler.Builder() .withHost(config.getHost()) @@ -154,10 +156,11 @@ ArrowFlightSqlClientHandler getClientHandler() { * @return the {@link #executorService}. */ synchronized ExecutorService getExecutorService() { - return executorService = executorService == null ? - Executors.newFixedThreadPool(config.threadPoolSize(), - new DefaultThreadFactory(getClass().getSimpleName())) : - executorService; + return executorService = + executorService == null + ? Executors.newFixedThreadPool( + config.threadPoolSize(), new DefaultThreadFactory(getClass().getSimpleName())) + : executorService; } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightInfoStatement.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightInfoStatement.java index 8365c7bb57a..4f4cb6c9b12 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightInfoStatement.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightInfoStatement.java @@ -19,12 +19,9 @@ import java.sql.SQLException; import java.sql.Statement; - import org.apache.arrow.flight.FlightInfo; -/** - * A {@link Statement} that deals with {@link FlightInfo}. - */ +/** A {@link Statement} that deals with {@link FlightInfo}. */ public interface ArrowFlightInfoStatement extends Statement { @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java index ed67c97cf69..3d8f0ca56dd 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java @@ -23,7 +23,6 @@ import java.sql.SQLFeatureNotSupportedException; import java.util.Arrays; import java.util.Map; - import org.apache.arrow.driver.jdbc.accessor.impl.complex.AbstractArrowFlightJdbcListVectorAccessor; import org.apache.arrow.driver.jdbc.utils.SqlTypes; import org.apache.arrow.memory.util.LargeMemoryUtil; @@ -46,9 +45,10 @@ public class ArrowFlightJdbcArray implements Array { private final long valuesCount; /** - * Instantiate an {@link Array} backed up by given {@link FieldVector}, limited by a start offset and values count. + * Instantiate an {@link Array} backed up by given {@link FieldVector}, limited by a start offset + * and values count. * - * @param dataVector underlying FieldVector, containing the Array items. + * @param dataVector underlying FieldVector, containing the Array items. * @param startOffset offset from FieldVector pointing to this Array's first value. * @param valuesCount how many items this Array contains. */ @@ -111,8 +111,8 @@ public Object getArray(long index, int count, Map> map) throws } checkBoundaries(index, count); - return getArrayNoBoundCheck(this.dataVector, - LargeMemoryUtil.checkedCastToInt(this.startOffset + index), count); + return getArrayNoBoundCheck( + this.dataVector, LargeMemoryUtil.checkedCastToInt(this.startOffset + index), count); } @Override @@ -134,12 +134,11 @@ public ResultSet getResultSet(long index, int count) throws SQLException { return getResultSet(index, count, null); } - private static ResultSet getResultSetNoBoundariesCheck(ValueVector dataVector, long start, - long count) - throws SQLException { + private static ResultSet getResultSetNoBoundariesCheck( + ValueVector dataVector, long start, long count) throws SQLException { TransferPair transferPair = dataVector.getTransferPair(dataVector.getAllocator()); - transferPair.splitAndTransfer(LargeMemoryUtil.checkedCastToInt(start), - LargeMemoryUtil.checkedCastToInt(count)); + transferPair.splitAndTransfer( + LargeMemoryUtil.checkedCastToInt(start), LargeMemoryUtil.checkedCastToInt(count)); FieldVector vectorSlice = (FieldVector) transferPair.getTo(); VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.of(vectorSlice); @@ -154,14 +153,12 @@ public ResultSet getResultSet(long index, int count, Map> map) } checkBoundaries(index, count); - return getResultSetNoBoundariesCheck(this.dataVector, - LargeMemoryUtil.checkedCastToInt(this.startOffset + index), count); + return getResultSetNoBoundariesCheck( + this.dataVector, LargeMemoryUtil.checkedCastToInt(this.startOffset + index), count); } @Override - public void free() { - - } + public void free() {} @Override public String toString() { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSource.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSource.java index 46a1d3ff87c..3307d8d23d6 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSource.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSource.java @@ -23,17 +23,13 @@ import java.util.Queue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; - import javax.sql.ConnectionEvent; import javax.sql.ConnectionEventListener; import javax.sql.ConnectionPoolDataSource; import javax.sql.PooledConnection; - import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl; -/** - * {@link ConnectionPoolDataSource} implementation for Arrow Flight JDBC Driver. - */ +/** {@link ConnectionPoolDataSource} implementation for Arrow Flight JDBC Driver. */ public class ArrowFlightJdbcConnectionPoolDataSource extends ArrowFlightJdbcDataSource implements ConnectionPoolDataSource, ConnectionEventListener, AutoCloseable { private final Map> pool = @@ -43,10 +39,10 @@ public class ArrowFlightJdbcConnectionPoolDataSource extends ArrowFlightJdbcData * Instantiates a new DataSource. * * @param properties the properties - * @param config the config. + * @param config the config. */ - protected ArrowFlightJdbcConnectionPoolDataSource(final Properties properties, - final ArrowFlightConnectionConfigImpl config) { + protected ArrowFlightJdbcConnectionPoolDataSource( + final Properties properties, final ArrowFlightConnectionConfigImpl config) { super(properties, config); } @@ -58,8 +54,8 @@ protected ArrowFlightJdbcConnectionPoolDataSource(final Properties properties, */ public static ArrowFlightJdbcConnectionPoolDataSource createNewDataSource( final Properties properties) { - return new ArrowFlightJdbcConnectionPoolDataSource(properties, - new ArrowFlightConnectionConfigImpl(properties)); + return new ArrowFlightJdbcConnectionPoolDataSource( + properties, new ArrowFlightConnectionConfigImpl(properties)); } @Override @@ -84,8 +80,7 @@ public PooledConnection getPooledConnection(final String username, final String } private ArrowFlightJdbcPooledConnection createPooledConnection( - final ArrowFlightConnectionConfigImpl config) - throws SQLException { + final ArrowFlightConnectionConfigImpl config) throws SQLException { ArrowFlightJdbcPooledConnection pooledConnection = new ArrowFlightJdbcPooledConnection(getConnection(config.getUser(), config.getPassword())); pooledConnection.addConnectionEventListener(this); @@ -102,9 +97,7 @@ public void connectionClosed(ConnectionEvent connectionEvent) { } @Override - public void connectionErrorOccurred(ConnectionEvent connectionEvent) { - - } + public void connectionErrorOccurred(ConnectionEvent connectionEvent) {} @Override public void close() throws Exception { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcCursor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcCursor.java index 45c23e4d529..0982746b4d5 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcCursor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcCursor.java @@ -17,13 +17,11 @@ package org.apache.arrow.driver.jdbc; - import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.util.AutoCloseables; import org.apache.arrow.vector.FieldVector; @@ -34,9 +32,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Arrow Flight Jdbc's Cursor class. - */ +/** Arrow Flight Jdbc's Cursor class. */ public class ArrowFlightJdbcCursor extends AbstractCursor { private static final Logger LOGGER; @@ -54,18 +50,20 @@ public ArrowFlightJdbcCursor(VectorSchemaRoot root) { } @Override - public List createAccessors(List columns, - Calendar localCalendar, - ArrayImpl.Factory factory) { + public List createAccessors( + List columns, Calendar localCalendar, ArrayImpl.Factory factory) { final List fieldVectors = root.getFieldVectors(); - return IntStream.range(0, fieldVectors.size()).mapToObj(root::getVector) + return IntStream.range(0, fieldVectors.size()) + .mapToObj(root::getVector) .map(this::createAccessor) .collect(Collectors.toCollection(() -> new ArrayList<>(fieldVectors.size()))); } private Accessor createAccessor(FieldVector vector) { - return ArrowFlightJdbcAccessorFactory.createAccessor(vector, this::getCurrentRow, + return ArrowFlightJdbcAccessorFactory.createAccessor( + vector, + this::getCurrentRow, (boolean wasNull) -> { // AbstractCursor creates a boolean array of length 1 to hold the wasNull value this.wasNull[0] = wasNull; @@ -73,8 +71,9 @@ private Accessor createAccessor(FieldVector vector) { } /** - * ArrowFlightJdbcAccessors do not use {@link AbstractCursor.Getter}, as it would box primitive types and cause - * performance issues. Each Accessor implementation works directly on Arrow Vectors. + * ArrowFlightJdbcAccessors do not use {@link AbstractCursor.Getter}, as it would box primitive + * types and cause performance issues. Each Accessor implementation works directly on Arrow + * Vectors. */ @Override protected Getter createGetter(int column) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDataSource.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDataSource.java index a57eeaa8304..3ba150ff630 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDataSource.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDataSource.java @@ -24,25 +24,19 @@ import java.sql.SQLFeatureNotSupportedException; import java.util.Properties; import java.util.logging.Logger; - import javax.sql.DataSource; - import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl; import org.apache.arrow.util.Preconditions; -/** - * {@link DataSource} implementation for Arrow Flight JDBC Driver. - */ +/** {@link DataSource} implementation for Arrow Flight JDBC Driver. */ public class ArrowFlightJdbcDataSource implements DataSource { private final Properties properties; private final ArrowFlightConnectionConfigImpl config; private PrintWriter logWriter; - /** - * Instantiates a new DataSource. - */ - protected ArrowFlightJdbcDataSource(final Properties properties, - final ArrowFlightConnectionConfigImpl config) { + /** Instantiates a new DataSource. */ + protected ArrowFlightJdbcDataSource( + final Properties properties, final ArrowFlightConnectionConfigImpl config) { this.properties = Preconditions.checkNotNull(properties); this.config = Preconditions.checkNotNull(config); } @@ -57,8 +51,8 @@ protected final ArrowFlightConnectionConfigImpl getConfig() { } /** - * Gets a copy of the {@link #properties} for this {@link ArrowFlightJdbcDataSource} with - * the provided {@code username} and {@code password}. + * Gets a copy of the {@link #properties} for this {@link ArrowFlightJdbcDataSource} with the + * provided {@code username} and {@code password}. * * @return the {@link Properties} for this data source. */ @@ -81,8 +75,8 @@ protected final Properties getProperties(final String username, final String pas * @return a new data source. */ public static ArrowFlightJdbcDataSource createNewDataSource(final Properties properties) { - return new ArrowFlightJdbcDataSource(properties, - new ArrowFlightConnectionConfigImpl(properties)); + return new ArrowFlightJdbcDataSource( + properties, new ArrowFlightConnectionConfigImpl(properties)); } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java index aa1b460fc13..8807a9b3146 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.java @@ -31,7 +31,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Properties; - import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; import org.apache.arrow.driver.jdbc.utils.UrlParser; import org.apache.arrow.flight.FlightRuntimeException; @@ -43,13 +42,12 @@ import org.apache.calcite.avatica.Meta; import org.apache.calcite.avatica.UnregisteredDriver; -/** - * JDBC driver for querying data from an Apache Arrow Flight server. - */ +/** JDBC driver for querying data from an Apache Arrow Flight server. */ public class ArrowFlightJdbcDriver extends UnregisteredDriver { private static final String CONNECT_STRING_PREFIX = "jdbc:arrow-flight-sql://"; private static final String CONNECT_STRING_PREFIX_DEPRECATED = "jdbc:arrow-flight://"; - private static final String CONNECTION_STRING_EXPECTED = "jdbc:arrow-flight-sql://[host][:port][?param1=value&...]"; + private static final String CONNECTION_STRING_EXPECTED = + "jdbc:arrow-flight-sql://[host][:port][?param1=value&...]"; private static DriverVersion version; static { @@ -83,11 +81,7 @@ public ArrowFlightConnection connect(final String url, final Properties info) try { return ArrowFlightConnection.createNewConnection( - this, - factory, - url, - lowerCasePropertyKeys(properties), - new RootAllocator(Long.MAX_VALUE)); + this, factory, url, lowerCasePropertyKeys(properties), new RootAllocator(Long.MAX_VALUE)); } catch (final FlightRuntimeException e) { throw new SQLException("Failed to connect.", e); } @@ -101,11 +95,14 @@ protected String getFactoryClassName(final JdbcVersion jdbcVersion) { @Override protected DriverVersion createDriverVersion() { if (version == null) { - final InputStream flightProperties = this.getClass().getResourceAsStream("/properties/flight.properties"); + final InputStream flightProperties = + this.getClass().getResourceAsStream("/properties/flight.properties"); if (flightProperties == null) { - throw new RuntimeException("Flight Properties not found. Ensure the JAR was built properly."); + throw new RuntimeException( + "Flight Properties not found. Ensure the JAR was built properly."); } - try (final Reader reader = new BufferedReader(new InputStreamReader(flightProperties, StandardCharsets.UTF_8))) { + try (final Reader reader = + new BufferedReader(new InputStreamReader(flightProperties, StandardCharsets.UTF_8))) { final Properties properties = new Properties(); properties.load(reader); @@ -117,22 +114,24 @@ protected DriverVersion createDriverVersion() { final int parentMinorVersion = Integer.parseInt(pVersion[1]); final String childName = properties.getProperty("org.apache.arrow.flight.jdbc-driver.name"); - final String childVersion = properties.getProperty("org.apache.arrow.flight.jdbc-driver.version"); + final String childVersion = + properties.getProperty("org.apache.arrow.flight.jdbc-driver.version"); final String[] cVersion = childVersion.split("\\."); final int childMajorVersion = Integer.parseInt(cVersion[0]); final int childMinorVersion = Integer.parseInt(cVersion[1]); - version = new DriverVersion( - childName, - childVersion, - parentName, - parentVersion, - true, - childMajorVersion, - childMinorVersion, - parentMajorVersion, - parentMinorVersion); + version = + new DriverVersion( + childName, + childVersion, + parentName, + parentVersion, + true, + childMajorVersion, + childMinorVersion, + parentMajorVersion, + parentMinorVersion); } catch (final IOException e) { throw new RuntimeException("Failed to load driver version.", e); } @@ -154,15 +153,16 @@ protected String getConnectStringPrefix() { @Override public boolean acceptsURL(final String url) { Preconditions.checkNotNull(url); - return url.startsWith(CONNECT_STRING_PREFIX) || url.startsWith(CONNECT_STRING_PREFIX_DEPRECATED); + return url.startsWith(CONNECT_STRING_PREFIX) + || url.startsWith(CONNECT_STRING_PREFIX_DEPRECATED); } /** - * Parses the provided url based on the format this driver accepts, retrieving - * arguments after the {@link #CONNECT_STRING_PREFIX}. - *

- * This method gets the args if the provided URL follows this pattern: - * {@code jdbc:arrow-flight-sql://:[/?key1=val1&key2=val2&(...)]} + * Parses the provided url based on the format this driver accepts, retrieving arguments after the + * {@link #CONNECT_STRING_PREFIX}. + * + *

This method gets the args if the provided URL follows this pattern: {@code + * jdbc:arrow-flight-sql://:[/?key1=val1&key2=val2&(...)]} * * * @@ -208,8 +208,7 @@ public boolean acceptsURL(final String url) { * @throws SQLException If an error occurs while trying to parse the URL. */ @VisibleForTesting // ArrowFlightJdbcDriverTest - Optional> getUrlsArgs(String url) - throws SQLException { + Optional> getUrlsArgs(String url) throws SQLException { /* * @@ -228,8 +227,9 @@ Optional> getUrlsArgs(String url) url = replaceSemiColons(url); if (!url.startsWith("jdbc:")) { - throw new SQLException("Connection string must start with 'jdbc:'. Expected format: " + - CONNECTION_STRING_EXPECTED); + throw new SQLException( + "Connection string must start with 'jdbc:'. Expected format: " + + CONNECTION_STRING_EXPECTED); } // It's necessary to use a string without "jdbc:" at the beginning to be parsed as a valid URL. @@ -243,15 +243,17 @@ Optional> getUrlsArgs(String url) throw new SQLException("Malformed/invalid URL!", e); } - if (!Objects.equals(uri.getScheme(), "arrow-flight") && - !Objects.equals(uri.getScheme(), "arrow-flight-sql")) { + if (!Objects.equals(uri.getScheme(), "arrow-flight") + && !Objects.equals(uri.getScheme(), "arrow-flight-sql")) { return Optional.empty(); } if (uri.getHost() == null) { - throw new SQLException("URL must have a host. Expected format: " + CONNECTION_STRING_EXPECTED); + throw new SQLException( + "URL must have a host. Expected format: " + CONNECTION_STRING_EXPECTED); } else if (uri.getPort() < 0) { - throw new SQLException("URL must have a port. Expected format: " + CONNECTION_STRING_EXPECTED); + throw new SQLException( + "URL must have a port. Expected format: " + CONNECTION_STRING_EXPECTED); } resultMap.put(ArrowFlightConnectionProperty.HOST.camelName(), uri.getHost()); // host resultMap.put(ArrowFlightConnectionProperty.PORT.camelName(), uri.getPort()); // port diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactory.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactory.java index 16bdede02d0..7e2352abeb1 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactory.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactory.java @@ -21,7 +21,6 @@ import java.sql.SQLException; import java.util.Properties; import java.util.TimeZone; - import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.memory.RootAllocator; import org.apache.calcite.avatica.AvaticaConnection; @@ -33,9 +32,7 @@ import org.apache.calcite.avatica.QueryState; import org.apache.calcite.avatica.UnregisteredDriver; -/** - * Factory for the Arrow Flight JDBC Driver. - */ +/** Factory for the Arrow Flight JDBC Driver. */ public class ArrowFlightJdbcFactory implements AvaticaFactory { private final int major; private final int minor; @@ -51,16 +48,14 @@ private ArrowFlightJdbcFactory(final int major, final int minor) { } @Override - public AvaticaConnection newConnection(final UnregisteredDriver driver, - final AvaticaFactory factory, - final String url, - final Properties info) throws SQLException { + public AvaticaConnection newConnection( + final UnregisteredDriver driver, + final AvaticaFactory factory, + final String url, + final Properties info) + throws SQLException { return ArrowFlightConnection.createNewConnection( - (ArrowFlightJdbcDriver) driver, - factory, - url, - info, - new RootAllocator(Long.MAX_VALUE)); + (ArrowFlightJdbcDriver) driver, factory, url, info, new RootAllocator(Long.MAX_VALUE)); } @Override @@ -70,8 +65,12 @@ public AvaticaStatement newStatement( final int resultType, final int resultSetConcurrency, final int resultSetHoldability) { - return new ArrowFlightStatement((ArrowFlightConnection) connection, - handle, resultType, resultSetConcurrency, resultSetHoldability); + return new ArrowFlightStatement( + (ArrowFlightConnection) connection, + handle, + resultType, + resultSetConcurrency, + resultSetHoldability); } @Override @@ -81,27 +80,34 @@ public ArrowFlightPreparedStatement newPreparedStatement( final Meta.Signature signature, final int resultType, final int resultSetConcurrency, - final int resultSetHoldability) throws SQLException { + final int resultSetHoldability) + throws SQLException { final ArrowFlightConnection flightConnection = (ArrowFlightConnection) connection; ArrowFlightSqlClientHandler.PreparedStatement preparedStatement = flightConnection.getMeta().getPreparedStatement(statementHandle); return ArrowFlightPreparedStatement.newPreparedStatement( - flightConnection, preparedStatement, statementHandle, - signature, resultType, resultSetConcurrency, resultSetHoldability); + flightConnection, + preparedStatement, + statementHandle, + signature, + resultType, + resultSetConcurrency, + resultSetHoldability); } @Override - public ArrowFlightJdbcVectorSchemaRootResultSet newResultSet(final AvaticaStatement statement, - final QueryState state, - final Meta.Signature signature, - final TimeZone timeZone, - final Meta.Frame frame) + public ArrowFlightJdbcVectorSchemaRootResultSet newResultSet( + final AvaticaStatement statement, + final QueryState state, + final Meta.Signature signature, + final TimeZone timeZone, + final Meta.Frame frame) throws SQLException { final ResultSetMetaData metaData = newResultSetMetaData(statement, signature); - return new ArrowFlightJdbcFlightStreamResultSet(statement, state, signature, metaData, timeZone, - frame); + return new ArrowFlightJdbcFlightStreamResultSet( + statement, state, signature, metaData, timeZone, frame); } @Override @@ -111,10 +117,8 @@ public AvaticaSpecificDatabaseMetaData newDatabaseMetaData(final AvaticaConnecti @Override public ResultSetMetaData newResultSetMetaData( - final AvaticaStatement avaticaStatement, - final Meta.Signature signature) { - return new AvaticaResultSetMetaData(avaticaStatement, - null, signature); + final AvaticaStatement avaticaStatement, final Meta.Signature signature) { + return new AvaticaResultSetMetaData(avaticaStatement, null, signature); } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFlightStreamResultSet.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFlightStreamResultSet.java index f69681d77a5..f22e61a1e68 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFlightStreamResultSet.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFlightStreamResultSet.java @@ -25,7 +25,6 @@ import java.util.Optional; import java.util.TimeZone; import java.util.concurrent.TimeUnit; - import org.apache.arrow.driver.jdbc.client.CloseableEndpointStreamPair; import org.apache.arrow.driver.jdbc.utils.FlightEndpointDataQueue; import org.apache.arrow.driver.jdbc.utils.VectorSchemaRootTransformer; @@ -41,8 +40,8 @@ import org.apache.calcite.avatica.QueryState; /** - * {@link ResultSet} implementation for Arrow Flight used to access the results of multiple {@link FlightStream} - * objects. + * {@link ResultSet} implementation for Arrow Flight used to access the results of multiple {@link + * FlightStream} objects. */ public final class ArrowFlightJdbcFlightStreamResultSet extends ArrowFlightJdbcVectorSchemaRootResultSet { @@ -57,49 +56,50 @@ public final class ArrowFlightJdbcFlightStreamResultSet private Schema schema; - /** - * Public constructor used by ArrowFlightJdbcFactory. - */ - ArrowFlightJdbcFlightStreamResultSet(final AvaticaStatement statement, - final QueryState state, - final Meta.Signature signature, - final ResultSetMetaData resultSetMetaData, - final TimeZone timeZone, - final Meta.Frame firstFrame) throws SQLException { + /** Public constructor used by ArrowFlightJdbcFactory. */ + ArrowFlightJdbcFlightStreamResultSet( + final AvaticaStatement statement, + final QueryState state, + final Meta.Signature signature, + final ResultSetMetaData resultSetMetaData, + final TimeZone timeZone, + final Meta.Frame firstFrame) + throws SQLException { super(statement, state, signature, resultSetMetaData, timeZone, firstFrame); this.connection = (ArrowFlightConnection) statement.connection; this.flightInfo = ((ArrowFlightInfoStatement) statement).executeFlightInfoQuery(); } - /** - * Private constructor for fromFlightInfo. - */ - private ArrowFlightJdbcFlightStreamResultSet(final ArrowFlightConnection connection, - final QueryState state, - final Meta.Signature signature, - final ResultSetMetaData resultSetMetaData, - final TimeZone timeZone, - final Meta.Frame firstFrame, - final FlightInfo flightInfo - ) throws SQLException { + /** Private constructor for fromFlightInfo. */ + private ArrowFlightJdbcFlightStreamResultSet( + final ArrowFlightConnection connection, + final QueryState state, + final Meta.Signature signature, + final ResultSetMetaData resultSetMetaData, + final TimeZone timeZone, + final Meta.Frame firstFrame, + final FlightInfo flightInfo) + throws SQLException { super(null, state, signature, resultSetMetaData, timeZone, firstFrame); this.connection = connection; this.flightInfo = flightInfo; } /** - * Create a {@link ResultSet} which pulls data from given {@link FlightInfo}. This is used to fetch result sets - * from DatabaseMetadata calls and skips the Avatica factory. + * Create a {@link ResultSet} which pulls data from given {@link FlightInfo}. This is used to + * fetch result sets from DatabaseMetadata calls and skips the Avatica factory. * - * @param connection The connection linked to the returned ResultSet. - * @param flightInfo The FlightInfo from which data will be iterated by the returned ResultSet. - * @param transformer Optional transformer for processing VectorSchemaRoot before access from ResultSet + * @param connection The connection linked to the returned ResultSet. + * @param flightInfo The FlightInfo from which data will be iterated by the returned ResultSet. + * @param transformer Optional transformer for processing VectorSchemaRoot before access from + * ResultSet * @return A ResultSet which pulls data from given FlightInfo. */ static ArrowFlightJdbcFlightStreamResultSet fromFlightInfo( final ArrowFlightConnection connection, final FlightInfo flightInfo, - final VectorSchemaRootTransformer transformer) throws SQLException { + final VectorSchemaRootTransformer transformer) + throws SQLException { // Similar to how org.apache.calcite.avatica.util.ArrayFactoryImpl does final TimeZone timeZone = TimeZone.getDefault(); @@ -110,8 +110,8 @@ static ArrowFlightJdbcFlightStreamResultSet fromFlightInfo( final AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(null, null, signature); final ArrowFlightJdbcFlightStreamResultSet resultSet = - new ArrowFlightJdbcFlightStreamResultSet(connection, state, signature, resultSetMetaData, - timeZone, null, flightInfo); + new ArrowFlightJdbcFlightStreamResultSet( + connection, state, signature, resultSetMetaData, timeZone, null, flightInfo); resultSet.transformer = transformer; @@ -167,9 +167,7 @@ private void populateDataForCurrentFlightStream() throws SQLException { populateData(currentVectorSchemaRoot, schema); } - /** - * Expose appMetadata associated with the underlying FlightInfo for this ResultSet. - */ + /** Expose appMetadata associated with the underlying FlightInfo for this ResultSet. */ public byte[] getAppMetadata() { return flightInfo.getAppMetadata(); } @@ -253,11 +251,13 @@ public synchronized void close() { } } - private CloseableEndpointStreamPair getNextEndpointStream(final boolean canTimeout) throws SQLException { + private CloseableEndpointStreamPair getNextEndpointStream(final boolean canTimeout) + throws SQLException { if (canTimeout) { final int statementTimeout = statement != null ? statement.getQueryTimeout() : 0; - return statementTimeout != 0 ? - flightEndpointDataQueue.next(statementTimeout, TimeUnit.SECONDS) : flightEndpointDataQueue.next(); + return statementTimeout != 0 + ? flightEndpointDataQueue.next(statementTimeout, TimeUnit.SECONDS) + : flightEndpointDataQueue.next(); } else { return flightEndpointDataQueue.next(); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcPooledConnection.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcPooledConnection.java index 96a2d9dda1d..ad8846e218c 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcPooledConnection.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcPooledConnection.java @@ -23,17 +23,13 @@ import java.util.HashSet; import java.util.Properties; import java.util.Set; - import javax.sql.ConnectionEvent; import javax.sql.ConnectionEventListener; import javax.sql.PooledConnection; import javax.sql.StatementEventListener; - import org.apache.arrow.driver.jdbc.utils.ConnectionWrapper; -/** - * {@link PooledConnection} implementation for Arrow Flight JDBC Driver. - */ +/** {@link PooledConnection} implementation for Arrow Flight JDBC Driver. */ public class ArrowFlightJdbcPooledConnection implements PooledConnection { private final ArrowFlightConnection connection; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTime.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTime.java index 109048bc05c..7fd9747b3a9 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTime.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTime.java @@ -19,19 +19,18 @@ import static org.apache.calcite.avatica.util.DateTimeUtils.MILLIS_PER_DAY; +import com.google.common.collect.ImmutableList; import java.sql.Time; import java.time.LocalTime; import java.time.temporal.ChronoField; import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; - import org.apache.arrow.util.VisibleForTesting; -import com.google.common.collect.ImmutableList; - /** - * Wrapper class for Time objects to include the milliseconds part in ISO 8601 format in this#toString. + * Wrapper class for Time objects to include the milliseconds part in ISO 8601 format in + * this#toString. */ public class ArrowFlightJdbcTime extends Time { private static final List LEADING_ZEROES = ImmutableList.of("", "0", "00"); @@ -54,7 +53,8 @@ public ArrowFlightJdbcTime(final long milliseconds) { @VisibleForTesting ArrowFlightJdbcTime(final LocalTime time) { - // Although the constructor is deprecated, this is the exact same code as Time#valueOf(LocalTime) + // Although the constructor is deprecated, this is the exact same code as + // Time#valueOf(LocalTime) super(time.getHour(), time.getMinute(), time.getSecond()); millisReprValue = time.get(ChronoField.MILLI_OF_SECOND); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcVectorSchemaRootResultSet.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcVectorSchemaRootResultSet.java index 626ae95bc5b..a8155adcc96 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcVectorSchemaRootResultSet.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcVectorSchemaRootResultSet.java @@ -25,7 +25,6 @@ import java.util.Objects; import java.util.Set; import java.util.TimeZone; - import org.apache.arrow.driver.jdbc.utils.ConvertUtils; import org.apache.arrow.util.AutoCloseables; import org.apache.arrow.vector.VectorSchemaRoot; @@ -41,19 +40,20 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * {@link ResultSet} implementation used to access a {@link VectorSchemaRoot}. - */ +/** {@link ResultSet} implementation used to access a {@link VectorSchemaRoot}. */ public class ArrowFlightJdbcVectorSchemaRootResultSet extends AvaticaResultSet { private static final Logger LOGGER = LoggerFactory.getLogger(ArrowFlightJdbcVectorSchemaRootResultSet.class); VectorSchemaRoot vectorSchemaRoot; - ArrowFlightJdbcVectorSchemaRootResultSet(final AvaticaStatement statement, final QueryState state, - final Signature signature, - final ResultSetMetaData resultSetMetaData, - final TimeZone timeZone, final Frame firstFrame) + ArrowFlightJdbcVectorSchemaRootResultSet( + final AvaticaStatement statement, + final QueryState state, + final Signature signature, + final ResultSetMetaData resultSetMetaData, + final TimeZone timeZone, + final Frame firstFrame) throws SQLException { super(statement, state, signature, resultSetMetaData, timeZone, firstFrame); } @@ -65,8 +65,7 @@ public class ArrowFlightJdbcVectorSchemaRootResultSet extends AvaticaResultSet { * @return a ResultSet which accesses the given VectorSchemaRoot */ public static ArrowFlightJdbcVectorSchemaRootResultSet fromVectorSchemaRoot( - final VectorSchemaRoot vectorSchemaRoot) - throws SQLException { + final VectorSchemaRoot vectorSchemaRoot) throws SQLException { // Similar to how org.apache.calcite.avatica.util.ArrayFactoryImpl does final TimeZone timeZone = TimeZone.getDefault(); @@ -76,10 +75,9 @@ public static ArrowFlightJdbcVectorSchemaRootResultSet fromVectorSchemaRoot( final AvaticaResultSetMetaData resultSetMetaData = new AvaticaResultSetMetaData(null, null, signature); - final ArrowFlightJdbcVectorSchemaRootResultSet - resultSet = - new ArrowFlightJdbcVectorSchemaRootResultSet(null, state, signature, resultSetMetaData, - timeZone, null); + final ArrowFlightJdbcVectorSchemaRootResultSet resultSet = + new ArrowFlightJdbcVectorSchemaRootResultSet( + null, state, signature, resultSetMetaData, timeZone, null); resultSet.populateData(vectorSchemaRoot); return resultSet; @@ -96,7 +94,8 @@ void populateData(final VectorSchemaRoot vectorSchemaRoot) { void populateData(final VectorSchemaRoot vectorSchemaRoot, final Schema schema) { Schema currentSchema = schema == null ? vectorSchemaRoot.getSchema() : schema; - final List columns = ConvertUtils.convertArrowFieldsToColumnMetaDataList(currentSchema.getFields()); + final List columns = + ConvertUtils.convertArrowFieldsToColumnMetaDataList(currentSchema.getFields()); signature.columns.clear(); signature.columns.addAll(columns); @@ -138,9 +137,11 @@ public void close() { } } exceptions.parallelStream().forEach(e -> LOGGER.error(e.getMessage(), e)); - exceptions.stream().findAny().ifPresent(e -> { - throw new RuntimeException(e); - }); + exceptions.stream() + .findAny() + .ifPresent( + e -> { + throw new RuntimeException(e); + }); } - } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java index 38275091499..b2eb8520626 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightMetaImpl.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler.PreparedStatement; import org.apache.arrow.driver.jdbc.utils.AvaticaParameterBinder; import org.apache.arrow.driver.jdbc.utils.ConvertUtils; @@ -39,14 +38,13 @@ import org.apache.calcite.avatica.QueryState; import org.apache.calcite.avatica.remote.TypedValue; -/** - * Metadata handler for Arrow Flight. - */ +/** Metadata handler for Arrow Flight. */ public class ArrowFlightMetaImpl extends MetaImpl { private final Map statementHandlePreparedStatementMap; /** * Constructs a {@link MetaImpl} object specific for Arrow Flight. + * * @param connection A {@link AvaticaConnection}. */ public ArrowFlightMetaImpl(final AvaticaConnection connection) { @@ -55,14 +53,16 @@ public ArrowFlightMetaImpl(final AvaticaConnection connection) { setDefaultConnectionProperties(); } - /** - * Construct a signature. - */ + /** Construct a signature. */ static Signature newSignature(final String sql, Schema resultSetSchema, Schema parameterSchema) { - List columnMetaData = resultSetSchema == null ? - new ArrayList<>() : ConvertUtils.convertArrowFieldsToColumnMetaDataList(resultSetSchema.getFields()); - List parameters = parameterSchema == null ? - new ArrayList<>() : ConvertUtils.convertArrowFieldsToAvaticaParameters(parameterSchema.getFields()); + List columnMetaData = + resultSetSchema == null + ? new ArrayList<>() + : ConvertUtils.convertArrowFieldsToColumnMetaDataList(resultSetSchema.getFields()); + List parameters = + parameterSchema == null + ? new ArrayList<>() + : ConvertUtils.convertArrowFieldsToAvaticaParameters(parameterSchema.getFields()); return new Signature( columnMetaData, @@ -70,15 +70,15 @@ static Signature newSignature(final String sql, Schema resultSetSchema, Schema p parameters, Collections.emptyMap(), null, // unnecessary, as SQL requests use ArrowFlightJdbcCursor - StatementType.SELECT - ); + StatementType.SELECT); } @Override public void closeStatement(final StatementHandle statementHandle) { PreparedStatement preparedStatement = statementHandlePreparedStatementMap.remove(new StatementHandleKey(statementHandle)); - // Testing if the prepared statement was created because the statement can be not created until this moment + // Testing if the prepared statement was created because the statement can be not created until + // this moment if (preparedStatement != null) { preparedStatement.close(); } @@ -90,54 +90,64 @@ public void commit(final ConnectionHandle connectionHandle) { } @Override - public ExecuteResult execute(final StatementHandle statementHandle, - final List typedValues, final long maxRowCount) { - Preconditions.checkArgument(connection.id.equals(statementHandle.connectionId), - "Connection IDs are not consistent"); + public ExecuteResult execute( + final StatementHandle statementHandle, + final List typedValues, + final long maxRowCount) { + Preconditions.checkArgument( + connection.id.equals(statementHandle.connectionId), "Connection IDs are not consistent"); PreparedStatement preparedStatement = getPreparedStatement(statementHandle); if (preparedStatement == null) { throw new IllegalStateException("Prepared statement not found: " + statementHandle); } - - new AvaticaParameterBinder(preparedStatement, ((ArrowFlightConnection) connection).getBufferAllocator()) - .bind(typedValues); + new AvaticaParameterBinder( + preparedStatement, ((ArrowFlightConnection) connection).getBufferAllocator()) + .bind(typedValues); if (statementHandle.signature == null) { // Update query long updatedCount = preparedStatement.executeUpdate(); - return new ExecuteResult(Collections.singletonList(MetaResultSet.count(statementHandle.connectionId, - statementHandle.id, updatedCount))); + return new ExecuteResult( + Collections.singletonList( + MetaResultSet.count(statementHandle.connectionId, statementHandle.id, updatedCount))); } else { // TODO Why is maxRowCount ignored? return new ExecuteResult( - Collections.singletonList(MetaResultSet.create( - statementHandle.connectionId, statementHandle.id, - true, statementHandle.signature, null))); + Collections.singletonList( + MetaResultSet.create( + statementHandle.connectionId, + statementHandle.id, + true, + statementHandle.signature, + null))); } } @Override - public ExecuteResult execute(final StatementHandle statementHandle, - final List typedValues, final int maxRowsInFirstFrame) { + public ExecuteResult execute( + final StatementHandle statementHandle, + final List typedValues, + final int maxRowsInFirstFrame) { return execute(statementHandle, typedValues, (long) maxRowsInFirstFrame); } @Override - public ExecuteBatchResult executeBatch(final StatementHandle statementHandle, - final List> parameterValuesList) + public ExecuteBatchResult executeBatch( + final StatementHandle statementHandle, final List> parameterValuesList) throws IllegalStateException { - Preconditions.checkArgument(connection.id.equals(statementHandle.connectionId), - "Connection IDs are not consistent"); + Preconditions.checkArgument( + connection.id.equals(statementHandle.connectionId), "Connection IDs are not consistent"); PreparedStatement preparedStatement = getPreparedStatement(statementHandle); if (preparedStatement == null) { throw new IllegalStateException("Prepared statement not found: " + statementHandle); } - final AvaticaParameterBinder binder = new AvaticaParameterBinder(preparedStatement, - ((ArrowFlightConnection) connection).getBufferAllocator()); + final AvaticaParameterBinder binder = + new AvaticaParameterBinder( + preparedStatement, ((ArrowFlightConnection) connection).getBufferAllocator()); for (int i = 0; i < parameterValuesList.size(); i++) { binder.bind(parameterValuesList.get(i), i); } @@ -148,49 +158,53 @@ public ExecuteBatchResult executeBatch(final StatementHandle statementHandle, } @Override - public Frame fetch(final StatementHandle statementHandle, final long offset, - final int fetchMaxRowCount) { + public Frame fetch( + final StatementHandle statementHandle, final long offset, final int fetchMaxRowCount) { /* * ArrowFlightMetaImpl does not use frames. * Instead, we have accessors that contain a VectorSchemaRoot with * the results. */ throw AvaticaConnection.HELPER.wrap( - String.format("%s does not use frames.", this), - AvaticaConnection.HELPER.unsupported()); + String.format("%s does not use frames.", this), AvaticaConnection.HELPER.unsupported()); } private PreparedStatement prepareForHandle(final String query, StatementHandle handle) { final PreparedStatement preparedStatement = ((ArrowFlightConnection) connection).getClientHandler().prepare(query); - handle.signature = newSignature(query, preparedStatement.getDataSetSchema(), - preparedStatement.getParameterSchema()); + handle.signature = + newSignature( + query, preparedStatement.getDataSetSchema(), preparedStatement.getParameterSchema()); statementHandlePreparedStatementMap.put(new StatementHandleKey(handle), preparedStatement); return preparedStatement; } @Override - public StatementHandle prepare(final ConnectionHandle connectionHandle, - final String query, final long maxRowCount) { + public StatementHandle prepare( + final ConnectionHandle connectionHandle, final String query, final long maxRowCount) { final StatementHandle handle = super.createStatement(connectionHandle); prepareForHandle(query, handle); return handle; } @Override - public ExecuteResult prepareAndExecute(final StatementHandle statementHandle, - final String query, final long maxRowCount, - final PrepareCallback prepareCallback) + public ExecuteResult prepareAndExecute( + final StatementHandle statementHandle, + final String query, + final long maxRowCount, + final PrepareCallback prepareCallback) throws NoSuchStatementException { return prepareAndExecute( statementHandle, query, maxRowCount, -1 /* Not used */, prepareCallback); } @Override - public ExecuteResult prepareAndExecute(final StatementHandle handle, - final String query, final long maxRowCount, - final int maxRowsInFirstFrame, - final PrepareCallback callback) + public ExecuteResult prepareAndExecute( + final StatementHandle handle, + final String query, + final long maxRowCount, + final int maxRowsInFirstFrame, + final PrepareCallback callback) throws NoSuchStatementException { try { PreparedStatement preparedStatement = prepareForHandle(query, handle); @@ -203,11 +217,12 @@ public ExecuteResult prepareAndExecute(final StatementHandle handle, callback.assign(handle.signature, null, updateCount); } callback.execute(); - final MetaResultSet metaResultSet = MetaResultSet.create(handle.connectionId, handle.id, - false, handle.signature, null); + final MetaResultSet metaResultSet = + MetaResultSet.create(handle.connectionId, handle.id, false, handle.signature, null); return new ExecuteResult(Collections.singletonList(metaResultSet)); } catch (SQLTimeoutException e) { - // So far AvaticaStatement(executeInternal) only handles NoSuchStatement and Runtime Exceptions. + // So far AvaticaStatement(executeInternal) only handles NoSuchStatement and Runtime + // Exceptions. throw new RuntimeException(e); } catch (SQLException e) { throw new NoSuchStatementException(handle); @@ -228,8 +243,8 @@ public void rollback(final ConnectionHandle connectionHandle) { } @Override - public boolean syncResults(final StatementHandle statementHandle, - final QueryState queryState, final long offset) + public boolean syncResults( + final StatementHandle statementHandle, final QueryState queryState, final long offset) throws NoSuchStatementException { // TODO Fill this stub. return false; @@ -237,7 +252,8 @@ public boolean syncResults(final StatementHandle statementHandle, void setDefaultConnectionProperties() { // TODO Double-check this. - connProps.setDirty(false) + connProps + .setDirty(false) .setAutoCommit(true) .setReadOnly(true) .setCatalog(null) @@ -249,7 +265,8 @@ PreparedStatement getPreparedStatement(StatementHandle statementHandle) { return statementHandlePreparedStatementMap.get(new StatementHandleKey(statementHandle)); } - // Helper used to look up prepared statement instances later. Avatica doesn't give us the signature in + // Helper used to look up prepared statement instances later. Avatica doesn't give us the + // signature in // an UPDATE code path so we can't directly use StatementHandle as a map key. private static final class StatementHandleKey { public final String connectionId; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatement.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatement.java index 7203f02daa9..6d823934eb0 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatement.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatement.java @@ -19,7 +19,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; - import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.flight.FlightInfo; import org.apache.arrow.util.Preconditions; @@ -27,36 +26,42 @@ import org.apache.calcite.avatica.Meta.Signature; import org.apache.calcite.avatica.Meta.StatementHandle; - -/** - * Arrow Flight JBCS's implementation {@link PreparedStatement}. - */ +/** Arrow Flight JBCS's implementation {@link PreparedStatement}. */ public class ArrowFlightPreparedStatement extends AvaticaPreparedStatement implements ArrowFlightInfoStatement { private final ArrowFlightSqlClientHandler.PreparedStatement preparedStatement; - private ArrowFlightPreparedStatement(final ArrowFlightConnection connection, - final ArrowFlightSqlClientHandler.PreparedStatement preparedStatement, - final StatementHandle handle, - final Signature signature, final int resultSetType, - final int resultSetConcurrency, - final int resultSetHoldability) + private ArrowFlightPreparedStatement( + final ArrowFlightConnection connection, + final ArrowFlightSqlClientHandler.PreparedStatement preparedStatement, + final StatementHandle handle, + final Signature signature, + final int resultSetType, + final int resultSetConcurrency, + final int resultSetHoldability) throws SQLException { super(connection, handle, signature, resultSetType, resultSetConcurrency, resultSetHoldability); this.preparedStatement = Preconditions.checkNotNull(preparedStatement); } - static ArrowFlightPreparedStatement newPreparedStatement(final ArrowFlightConnection connection, + static ArrowFlightPreparedStatement newPreparedStatement( + final ArrowFlightConnection connection, final ArrowFlightSqlClientHandler.PreparedStatement preparedStmt, final StatementHandle statementHandle, final Signature signature, final int resultSetType, final int resultSetConcurrency, - final int resultSetHoldability) throws SQLException { + final int resultSetHoldability) + throws SQLException { return new ArrowFlightPreparedStatement( - connection, preparedStmt, statementHandle, - signature, resultSetType, resultSetConcurrency, resultSetHoldability); + connection, + preparedStmt, + statementHandle, + signature, + resultSetType, + resultSetConcurrency, + resultSetHoldability); } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightStatement.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightStatement.java index 5bc7c2ab9b4..4a267fd3a77 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightStatement.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightStatement.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc; import java.sql.SQLException; - import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler.PreparedStatement; import org.apache.arrow.driver.jdbc.utils.ConvertUtils; import org.apache.arrow.flight.FlightInfo; @@ -27,14 +26,15 @@ import org.apache.calcite.avatica.Meta; import org.apache.calcite.avatica.Meta.StatementHandle; -/** - * A SQL statement for querying data from an Arrow Flight server. - */ +/** A SQL statement for querying data from an Arrow Flight server. */ public class ArrowFlightStatement extends AvaticaStatement implements ArrowFlightInfoStatement { - ArrowFlightStatement(final ArrowFlightConnection connection, - final StatementHandle handle, final int resultSetType, - final int resultSetConcurrency, final int resultSetHoldability) { + ArrowFlightStatement( + final ArrowFlightConnection connection, + final StatementHandle handle, + final int resultSetType, + final int resultSetConcurrency, + final int resultSetHoldability) { super(connection, handle, resultSetType, resultSetConcurrency, resultSetHoldability); } @@ -45,14 +45,16 @@ public ArrowFlightConnection getConnection() throws SQLException { @Override public FlightInfo executeFlightInfoQuery() throws SQLException { - final PreparedStatement preparedStatement = getConnection().getMeta().getPreparedStatement(handle); + final PreparedStatement preparedStatement = + getConnection().getMeta().getPreparedStatement(handle); final Meta.Signature signature = getSignature(); if (signature == null) { return null; } final Schema resultSetSchema = preparedStatement.getDataSetSchema(); - signature.columns.addAll(ConvertUtils.convertArrowFieldsToColumnMetaDataList(resultSetSchema.getFields())); + signature.columns.addAll( + ConvertUtils.convertArrowFieldsToColumnMetaDataList(resultSetSchema.getFields())); setSignature(signature); return preparedStatement.executeQuery(); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessor.java index 3821ee1dc87..47dcb3375dd 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessor.java @@ -38,9 +38,7 @@ import java.util.Map; import java.util.function.IntSupplier; -/** - * Base Jdbc Accessor. - */ +/** Base Jdbc Accessor. */ public abstract class ArrowFlightJdbcAccessor implements Accessor { private final IntSupplier currentRowSupplier; @@ -48,8 +46,9 @@ public abstract class ArrowFlightJdbcAccessor implements Accessor { protected boolean wasNull; protected ArrowFlightJdbcAccessorFactory.WasNullConsumer wasNullConsumer; - protected ArrowFlightJdbcAccessor(final IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer wasNullConsumer) { + protected ArrowFlightJdbcAccessor( + final IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer wasNullConsumer) { this.currentRowSupplier = currentRowSupplier; this.wasNullConsumer = wasNullConsumer; } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorFactory.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorFactory.java index 813b40a8070..0cb9e5b7d3c 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorFactory.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorFactory.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc.accessor; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.impl.ArrowFlightJdbcNullVectorAccessor; import org.apache.arrow.driver.jdbc.accessor.impl.binary.ArrowFlightJdbcBinaryVectorAccessor; import org.apache.arrow.driver.jdbc.accessor.impl.calendar.ArrowFlightJdbcDateVectorAccessor; @@ -77,136 +76,132 @@ import org.apache.arrow.vector.complex.StructVector; import org.apache.arrow.vector.complex.UnionVector; -/** - * Factory to instantiate the accessors. - */ +/** Factory to instantiate the accessors. */ public class ArrowFlightJdbcAccessorFactory { /** * Create an accessor according to its type. * - * @param vector an instance of an arrow vector. + * @param vector an instance of an arrow vector. * @param getCurrentRow a supplier to check which row is being accessed. * @return an instance of one of the accessors. */ - public static ArrowFlightJdbcAccessor createAccessor(ValueVector vector, - IntSupplier getCurrentRow, - WasNullConsumer setCursorWasNull) { + public static ArrowFlightJdbcAccessor createAccessor( + ValueVector vector, IntSupplier getCurrentRow, WasNullConsumer setCursorWasNull) { if (vector instanceof UInt1Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt1Vector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt1Vector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof UInt2Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt2Vector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt2Vector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof UInt4Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt4Vector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt4Vector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof UInt8Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt8Vector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt8Vector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof TinyIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((TinyIntVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBaseIntVectorAccessor( + (TinyIntVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof SmallIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((SmallIntVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBaseIntVectorAccessor( + (SmallIntVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof IntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((IntVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBaseIntVectorAccessor( + (IntVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof BigIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((BigIntVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBaseIntVectorAccessor( + (BigIntVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof Float4Vector) { - return new ArrowFlightJdbcFloat4VectorAccessor((Float4Vector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcFloat4VectorAccessor( + (Float4Vector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof Float8Vector) { - return new ArrowFlightJdbcFloat8VectorAccessor((Float8Vector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcFloat8VectorAccessor( + (Float8Vector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof BitVector) { - return new ArrowFlightJdbcBitVectorAccessor((BitVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBitVectorAccessor( + (BitVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof DecimalVector) { - return new ArrowFlightJdbcDecimalVectorAccessor((DecimalVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcDecimalVectorAccessor( + (DecimalVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof Decimal256Vector) { - return new ArrowFlightJdbcDecimalVectorAccessor((Decimal256Vector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcDecimalVectorAccessor( + (Decimal256Vector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof VarBinaryVector) { - return new ArrowFlightJdbcBinaryVectorAccessor((VarBinaryVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBinaryVectorAccessor( + (VarBinaryVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof LargeVarBinaryVector) { - return new ArrowFlightJdbcBinaryVectorAccessor((LargeVarBinaryVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBinaryVectorAccessor( + (LargeVarBinaryVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof FixedSizeBinaryVector) { - return new ArrowFlightJdbcBinaryVectorAccessor((FixedSizeBinaryVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcBinaryVectorAccessor( + (FixedSizeBinaryVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof TimeStampVector) { - return new ArrowFlightJdbcTimeStampVectorAccessor((TimeStampVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcTimeStampVectorAccessor( + (TimeStampVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof TimeNanoVector) { - return new ArrowFlightJdbcTimeVectorAccessor((TimeNanoVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcTimeVectorAccessor( + (TimeNanoVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof TimeMicroVector) { - return new ArrowFlightJdbcTimeVectorAccessor((TimeMicroVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcTimeVectorAccessor( + (TimeMicroVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof TimeMilliVector) { - return new ArrowFlightJdbcTimeVectorAccessor((TimeMilliVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcTimeVectorAccessor( + (TimeMilliVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof TimeSecVector) { - return new ArrowFlightJdbcTimeVectorAccessor((TimeSecVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcTimeVectorAccessor( + (TimeSecVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof DateDayVector) { - return new ArrowFlightJdbcDateVectorAccessor(((DateDayVector) vector), getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcDateVectorAccessor( + ((DateDayVector) vector), getCurrentRow, setCursorWasNull); } else if (vector instanceof DateMilliVector) { - return new ArrowFlightJdbcDateVectorAccessor(((DateMilliVector) vector), getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcDateVectorAccessor( + ((DateMilliVector) vector), getCurrentRow, setCursorWasNull); } else if (vector instanceof VarCharVector) { - return new ArrowFlightJdbcVarCharVectorAccessor((VarCharVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcVarCharVectorAccessor( + (VarCharVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof LargeVarCharVector) { - return new ArrowFlightJdbcVarCharVectorAccessor((LargeVarCharVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcVarCharVectorAccessor( + (LargeVarCharVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof DurationVector) { - return new ArrowFlightJdbcDurationVectorAccessor((DurationVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcDurationVectorAccessor( + (DurationVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof IntervalDayVector) { - return new ArrowFlightJdbcIntervalVectorAccessor(((IntervalDayVector) vector), getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcIntervalVectorAccessor( + ((IntervalDayVector) vector), getCurrentRow, setCursorWasNull); } else if (vector instanceof IntervalYearVector) { - return new ArrowFlightJdbcIntervalVectorAccessor(((IntervalYearVector) vector), getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcIntervalVectorAccessor( + ((IntervalYearVector) vector), getCurrentRow, setCursorWasNull); } else if (vector instanceof StructVector) { - return new ArrowFlightJdbcStructVectorAccessor((StructVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcStructVectorAccessor( + (StructVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof MapVector) { - return new ArrowFlightJdbcMapVectorAccessor((MapVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcMapVectorAccessor( + (MapVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof ListVector) { - return new ArrowFlightJdbcListVectorAccessor((ListVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcListVectorAccessor( + (ListVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof LargeListVector) { - return new ArrowFlightJdbcLargeListVectorAccessor((LargeListVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcLargeListVectorAccessor( + (LargeListVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof FixedSizeListVector) { - return new ArrowFlightJdbcFixedSizeListVectorAccessor((FixedSizeListVector) vector, - getCurrentRow, setCursorWasNull); + return new ArrowFlightJdbcFixedSizeListVectorAccessor( + (FixedSizeListVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof UnionVector) { - return new ArrowFlightJdbcUnionVectorAccessor((UnionVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcUnionVectorAccessor( + (UnionVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof DenseUnionVector) { - return new ArrowFlightJdbcDenseUnionVectorAccessor((DenseUnionVector) vector, getCurrentRow, - setCursorWasNull); + return new ArrowFlightJdbcDenseUnionVectorAccessor( + (DenseUnionVector) vector, getCurrentRow, setCursorWasNull); } else if (vector instanceof NullVector || vector == null) { return new ArrowFlightJdbcNullVectorAccessor(setCursorWasNull); } - throw new UnsupportedOperationException("Unsupported vector type: " + vector.getClass().getName()); + throw new UnsupportedOperationException( + "Unsupported vector type: " + vector.getClass().getName()); } - /** - * Functional interface used to propagate that the value accessed was null or not. - */ + /** Functional interface used to propagate that the value accessed was null or not. */ @FunctionalInterface public interface WasNullConsumer { void setWasNull(boolean wasNull); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/ArrowFlightJdbcNullVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/ArrowFlightJdbcNullVectorAccessor.java index f40a5797293..b1ef1d4d02b 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/ArrowFlightJdbcNullVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/ArrowFlightJdbcNullVectorAccessor.java @@ -21,9 +21,7 @@ import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.NullVector; -/** - * Accessor for the Arrow type {@link NullVector}. - */ +/** Accessor for the Arrow type {@link NullVector}. */ public class ArrowFlightJdbcNullVectorAccessor extends ArrowFlightJdbcAccessor { public ArrowFlightJdbcNullVectorAccessor( ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/binary/ArrowFlightJdbcBinaryVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/binary/ArrowFlightJdbcBinaryVectorAccessor.java index c50d7349721..df7854575bf 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/binary/ArrowFlightJdbcBinaryVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/binary/ArrowFlightJdbcBinaryVectorAccessor.java @@ -23,7 +23,6 @@ import java.io.Reader; import java.nio.charset.StandardCharsets; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.FixedSizeBinaryVector; @@ -31,8 +30,8 @@ import org.apache.arrow.vector.VarBinaryVector; /** - * Accessor for the Arrow types: {@link FixedSizeBinaryVector}, {@link VarBinaryVector} - * and {@link LargeVarBinaryVector}. + * Accessor for the Arrow types: {@link FixedSizeBinaryVector}, {@link VarBinaryVector} and {@link + * LargeVarBinaryVector}. */ public class ArrowFlightJdbcBinaryVectorAccessor extends ArrowFlightJdbcAccessor { @@ -42,26 +41,31 @@ private interface ByteArrayGetter { private final ByteArrayGetter getter; - public ArrowFlightJdbcBinaryVectorAccessor(FixedSizeBinaryVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBinaryVectorAccessor( + FixedSizeBinaryVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector::get, currentRowSupplier, setCursorWasNull); } - public ArrowFlightJdbcBinaryVectorAccessor(VarBinaryVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBinaryVectorAccessor( + VarBinaryVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector::get, currentRowSupplier, setCursorWasNull); } - public ArrowFlightJdbcBinaryVectorAccessor(LargeVarBinaryVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBinaryVectorAccessor( + LargeVarBinaryVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector::get, currentRowSupplier, setCursorWasNull); } - private ArrowFlightJdbcBinaryVectorAccessor(ByteArrayGetter getter, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + private ArrowFlightJdbcBinaryVectorAccessor( + ByteArrayGetter getter, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.getter = getter; } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessor.java index f6c14a47f52..f5a2ae93316 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessor.java @@ -29,7 +29,6 @@ import java.util.Calendar; import java.util.concurrent.TimeUnit; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.utils.DateTimeUtils; @@ -37,9 +36,7 @@ import org.apache.arrow.vector.DateMilliVector; import org.apache.arrow.vector.ValueVector; -/** - * Accessor for the Arrow types: {@link DateDayVector} and {@link DateMilliVector}. - */ +/** Accessor for the Arrow types: {@link DateDayVector} and {@link DateMilliVector}. */ public class ArrowFlightJdbcDateVectorAccessor extends ArrowFlightJdbcAccessor { private final Getter getter; @@ -49,12 +46,14 @@ public class ArrowFlightJdbcDateVectorAccessor extends ArrowFlightJdbcAccessor { /** * Instantiate an accessor for a {@link DateDayVector}. * - * @param vector an instance of a DateDayVector. + * @param vector an instance of a DateDayVector. * @param currentRowSupplier the supplier to track the lines. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcDateVectorAccessor(DateDayVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcDateVectorAccessor( + DateDayVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new Holder(); this.getter = createGetter(vector); @@ -64,11 +63,13 @@ public ArrowFlightJdbcDateVectorAccessor(DateDayVector vector, IntSupplier curre /** * Instantiate an accessor for a {@link DateMilliVector}. * - * @param vector an instance of a DateMilliVector. + * @param vector an instance of a DateMilliVector. * @param currentRowSupplier the supplier to track the lines. */ - public ArrowFlightJdbcDateVectorAccessor(DateMilliVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcDateVectorAccessor( + DateMilliVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new Holder(); this.getter = createGetter(vector); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorGetter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorGetter.java index ea545851a3a..0c97605e9be 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorGetter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorGetter.java @@ -22,9 +22,7 @@ import org.apache.arrow.vector.holders.NullableDateDayHolder; import org.apache.arrow.vector.holders.NullableDateMilliHolder; -/** - * Auxiliary class used to unify data access on TimeStampVectors. - */ +/** Auxiliary class used to unify data access on TimeStampVectors. */ final class ArrowFlightJdbcDateVectorGetter { private ArrowFlightJdbcDateVectorGetter() { @@ -32,16 +30,15 @@ private ArrowFlightJdbcDateVectorGetter() { } /** - * Auxiliary class meant to unify Date*Vector#get implementations with different classes of ValueHolders. + * Auxiliary class meant to unify Date*Vector#get implementations with different classes of + * ValueHolders. */ static class Holder { int isSet; // Tells if value is set; 0 = not set, 1 = set long value; // Holds actual value in its respective timeunit } - /** - * Functional interface used to unify Date*Vector#get implementations. - */ + /** Functional interface used to unify Date*Vector#get implementations. */ @FunctionalInterface interface Getter { void get(int index, Holder holder); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDurationVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDurationVectorAccessor.java index 22a0e6f8923..0690afb0e00 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDurationVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDurationVectorAccessor.java @@ -19,21 +19,19 @@ import java.time.Duration; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.DurationVector; -/** - * Accessor for the Arrow type {@link DurationVector}. - */ +/** Accessor for the Arrow type {@link DurationVector}. */ public class ArrowFlightJdbcDurationVectorAccessor extends ArrowFlightJdbcAccessor { private final DurationVector vector; - public ArrowFlightJdbcDurationVectorAccessor(DurationVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcDurationVectorAccessor( + DurationVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessor.java index 21d1c15712c..27c08f333bb 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessor.java @@ -25,7 +25,6 @@ import java.time.Duration; import java.time.Period; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.BaseFixedWidthVector; @@ -34,9 +33,7 @@ import org.apache.arrow.vector.holders.NullableIntervalDayHolder; import org.apache.arrow.vector.holders.NullableIntervalYearHolder; -/** - * Accessor for the Arrow type {@link IntervalDayVector}. - */ +/** Accessor for the Arrow type {@link IntervalDayVector}. */ public class ArrowFlightJdbcIntervalVectorAccessor extends ArrowFlightJdbcAccessor { private final BaseFixedWidthVector vector; @@ -46,53 +43,57 @@ public class ArrowFlightJdbcIntervalVectorAccessor extends ArrowFlightJdbcAccess /** * Instantiate an accessor for a {@link IntervalDayVector}. * - * @param vector an instance of a IntervalDayVector. + * @param vector an instance of a IntervalDayVector. * @param currentRowSupplier the supplier to track the rows. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcIntervalVectorAccessor(IntervalDayVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcIntervalVectorAccessor( + IntervalDayVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; - stringGetter = (index) -> { - final NullableIntervalDayHolder holder = new NullableIntervalDayHolder(); - vector.get(index, holder); - if (holder.isSet == 0) { - return null; - } else { - final int days = holder.days; - final int millis = holder.milliseconds; - return formatIntervalDay(Duration.ofDays(days).plusMillis(millis)); - } - }; + stringGetter = + (index) -> { + final NullableIntervalDayHolder holder = new NullableIntervalDayHolder(); + vector.get(index, holder); + if (holder.isSet == 0) { + return null; + } else { + final int days = holder.days; + final int millis = holder.milliseconds; + return formatIntervalDay(Duration.ofDays(days).plusMillis(millis)); + } + }; objectClass = java.time.Duration.class; } /** * Instantiate an accessor for a {@link IntervalYearVector}. * - * @param vector an instance of a IntervalYearVector. + * @param vector an instance of a IntervalYearVector. * @param currentRowSupplier the supplier to track the rows. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcIntervalVectorAccessor(IntervalYearVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcIntervalVectorAccessor( + IntervalYearVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; - stringGetter = (index) -> { - final NullableIntervalYearHolder holder = new NullableIntervalYearHolder(); - vector.get(index, holder); - if (holder.isSet == 0) { - return null; - } else { - final int interval = holder.value; - final int years = (interval / yearsToMonths); - final int months = (interval % yearsToMonths); - return formatIntervalYear(Period.ofYears(years).plusMonths(months)); - } - }; + stringGetter = + (index) -> { + final NullableIntervalYearHolder holder = new NullableIntervalYearHolder(); + vector.get(index, holder); + if (holder.isSet == 0) { + return null; + } else { + final int interval = holder.value; + final int years = (interval / yearsToMonths); + final int months = (interval % yearsToMonths); + return formatIntervalYear(Period.ofYears(years).plusMonths(months)); + } + }; objectClass = java.time.Period.class; } @@ -117,9 +118,7 @@ public Object getObject() { return object; } - /** - * Functional interface used to unify Interval*Vector#getAsStringBuilder implementations. - */ + /** Functional interface used to unify Interval*Vector#getAsStringBuilder implementations. */ @FunctionalInterface interface StringGetter { String get(int index); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessor.java index a23883baf1e..d60d320e4b2 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessor.java @@ -30,16 +30,13 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.TimeStampVector; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.util.DateUtility; -/** - * Accessor for the Arrow types extending from {@link TimeStampVector}. - */ +/** Accessor for the Arrow types extending from {@link TimeStampVector}. */ public class ArrowFlightJdbcTimeStampVectorAccessor extends ArrowFlightJdbcAccessor { private final TimeZone timeZone; @@ -48,19 +45,16 @@ public class ArrowFlightJdbcTimeStampVectorAccessor extends ArrowFlightJdbcAcces private final LongToLocalDateTime longToLocalDateTime; private final Holder holder; - /** - * Functional interface used to convert a number (in any time resolution) to LocalDateTime. - */ + /** Functional interface used to convert a number (in any time resolution) to LocalDateTime. */ interface LongToLocalDateTime { LocalDateTime fromLong(long value); } - /** - * Instantiate a ArrowFlightJdbcTimeStampVectorAccessor for given vector. - */ - public ArrowFlightJdbcTimeStampVectorAccessor(TimeStampVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + /** Instantiate a ArrowFlightJdbcTimeStampVectorAccessor for given vector. */ + public ArrowFlightJdbcTimeStampVectorAccessor( + TimeStampVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new Holder(); this.getter = createGetter(vector); @@ -95,8 +89,9 @@ private LocalDateTime getLocalDateTime(Calendar calendar) { if (calendar != null) { TimeZone timeZone = calendar.getTimeZone(); long millis = this.timeUnit.toMillis(value); - localDateTime = localDateTime - .minus(timeZone.getOffset(millis) - this.timeZone.getOffset(millis), ChronoUnit.MILLIS); + localDateTime = + localDateTime.minus( + timeZone.getOffset(millis) - this.timeZone.getOffset(millis), ChronoUnit.MILLIS); } return localDateTime; } @@ -149,8 +144,8 @@ protected static TimeUnit getTimeUnitForVector(TimeStampVector vector) { } } - protected static LongToLocalDateTime getLongToLocalDateTimeForVector(TimeStampVector vector, - TimeZone timeZone) { + protected static LongToLocalDateTime getLongToLocalDateTimeForVector( + TimeStampVector vector, TimeZone timeZone) { String timeZoneID = timeZone.getID(); ArrowType.Timestamp arrowType = @@ -164,8 +159,9 @@ protected static LongToLocalDateTime getLongToLocalDateTimeForVector(TimeStampVe case MILLISECOND: return milliseconds -> DateUtility.getLocalDateTimeFromEpochMilli(milliseconds, timeZoneID); case SECOND: - return seconds -> DateUtility.getLocalDateTimeFromEpochMilli( - TimeUnit.SECONDS.toMillis(seconds), timeZoneID); + return seconds -> + DateUtility.getLocalDateTimeFromEpochMilli( + TimeUnit.SECONDS.toMillis(seconds), timeZoneID); default: throw new UnsupportedOperationException("Invalid Arrow time unit"); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorGetter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorGetter.java index 03fb35face7..8bdc5856bc9 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorGetter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorGetter.java @@ -35,9 +35,7 @@ import org.apache.arrow.vector.holders.NullableTimeStampSecHolder; import org.apache.arrow.vector.holders.NullableTimeStampSecTZHolder; -/** - * Auxiliary class used to unify data access on TimeStampVectors. - */ +/** Auxiliary class used to unify data access on TimeStampVectors. */ final class ArrowFlightJdbcTimeStampVectorGetter { private ArrowFlightJdbcTimeStampVectorGetter() { @@ -45,16 +43,15 @@ private ArrowFlightJdbcTimeStampVectorGetter() { } /** - * Auxiliary class meant to unify TimeStamp*Vector#get implementations with different classes of ValueHolders. + * Auxiliary class meant to unify TimeStamp*Vector#get implementations with different classes of + * ValueHolders. */ static class Holder { int isSet; // Tells if value is set; 0 = not set, 1 = set long value; // Holds actual value in its respective timeunit } - /** - * Functional interface used to unify TimeStamp*Vector#get implementations. - */ + /** Functional interface used to unify TimeStamp*Vector#get implementations. */ @FunctionalInterface interface Getter { void get(int index, Holder holder); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessor.java index 6c2173d5e56..81fecfaf184 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessor.java @@ -26,7 +26,6 @@ import java.util.Calendar; import java.util.concurrent.TimeUnit; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.ArrowFlightJdbcTime; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; @@ -38,8 +37,8 @@ import org.apache.arrow.vector.ValueVector; /** - * Accessor for the Arrow types: {@link TimeNanoVector}, {@link TimeMicroVector}, {@link TimeMilliVector} - * and {@link TimeSecVector}. + * Accessor for the Arrow types: {@link TimeNanoVector}, {@link TimeMicroVector}, {@link + * TimeMilliVector} and {@link TimeSecVector}. */ public class ArrowFlightJdbcTimeVectorAccessor extends ArrowFlightJdbcAccessor { @@ -50,12 +49,14 @@ public class ArrowFlightJdbcTimeVectorAccessor extends ArrowFlightJdbcAccessor { /** * Instantiate an accessor for a {@link TimeNanoVector}. * - * @param vector an instance of a TimeNanoVector. + * @param vector an instance of a TimeNanoVector. * @param currentRowSupplier the supplier to track the lines. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcTimeVectorAccessor(TimeNanoVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcTimeVectorAccessor( + TimeNanoVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new Holder(); this.getter = createGetter(vector); @@ -65,12 +66,14 @@ public ArrowFlightJdbcTimeVectorAccessor(TimeNanoVector vector, IntSupplier curr /** * Instantiate an accessor for a {@link TimeMicroVector}. * - * @param vector an instance of a TimeMicroVector. + * @param vector an instance of a TimeMicroVector. * @param currentRowSupplier the supplier to track the lines. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcTimeVectorAccessor(TimeMicroVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcTimeVectorAccessor( + TimeMicroVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new Holder(); this.getter = createGetter(vector); @@ -80,11 +83,13 @@ public ArrowFlightJdbcTimeVectorAccessor(TimeMicroVector vector, IntSupplier cur /** * Instantiate an accessor for a {@link TimeMilliVector}. * - * @param vector an instance of a TimeMilliVector. + * @param vector an instance of a TimeMilliVector. * @param currentRowSupplier the supplier to track the lines. */ - public ArrowFlightJdbcTimeVectorAccessor(TimeMilliVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcTimeVectorAccessor( + TimeMilliVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new Holder(); this.getter = createGetter(vector); @@ -94,11 +99,13 @@ public ArrowFlightJdbcTimeVectorAccessor(TimeMilliVector vector, IntSupplier cur /** * Instantiate an accessor for a {@link TimeSecVector}. * - * @param vector an instance of a TimeSecVector. + * @param vector an instance of a TimeSecVector. * @param currentRowSupplier the supplier to track the lines. */ - public ArrowFlightJdbcTimeVectorAccessor(TimeSecVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcTimeVectorAccessor( + TimeSecVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new Holder(); this.getter = createGetter(vector); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorGetter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorGetter.java index fb254c69401..754749369c2 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorGetter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorGetter.java @@ -26,9 +26,7 @@ import org.apache.arrow.vector.holders.NullableTimeNanoHolder; import org.apache.arrow.vector.holders.NullableTimeSecHolder; -/** - * Auxiliary class used to unify data access on Time*Vectors. - */ +/** Auxiliary class used to unify data access on Time*Vectors. */ final class ArrowFlightJdbcTimeVectorGetter { private ArrowFlightJdbcTimeVectorGetter() { @@ -36,16 +34,15 @@ private ArrowFlightJdbcTimeVectorGetter() { } /** - * Auxiliary class meant to unify TimeStamp*Vector#get implementations with different classes of ValueHolders. + * Auxiliary class meant to unify TimeStamp*Vector#get implementations with different classes of + * ValueHolders. */ static class Holder { int isSet; // Tells if value is set; 0 = not set, 1 = set long value; // Holds actual value in its respective timeunit } - /** - * Functional interface used to unify TimeStamp*Vector#get implementations. - */ + /** Functional interface used to unify TimeStamp*Vector#get implementations. */ @FunctionalInterface interface Getter { void get(int index, Holder holder); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListVectorAccessor.java index d3338608f83..dd9e2fc5d93 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListVectorAccessor.java @@ -20,7 +20,6 @@ import java.sql.Array; import java.util.List; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.ArrowFlightJdbcArray; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; @@ -30,12 +29,14 @@ import org.apache.arrow.vector.complex.ListVector; /** - * Base Accessor for the Arrow types {@link ListVector}, {@link LargeListVector} and {@link FixedSizeListVector}. + * Base Accessor for the Arrow types {@link ListVector}, {@link LargeListVector} and {@link + * FixedSizeListVector}. */ public abstract class AbstractArrowFlightJdbcListVectorAccessor extends ArrowFlightJdbcAccessor { - protected AbstractArrowFlightJdbcListVectorAccessor(IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + protected AbstractArrowFlightJdbcListVectorAccessor( + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); } @@ -70,4 +71,3 @@ public final Array getArray() { return new ArrowFlightJdbcArray(dataVector, startOffset, valuesCount); } } - diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessor.java index 0465765f183..62980af3239 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessor.java @@ -35,7 +35,6 @@ import java.util.Calendar; import java.util.Map; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.accessor.impl.ArrowFlightJdbcNullVectorAccessor; @@ -43,22 +42,20 @@ import org.apache.arrow.vector.complex.DenseUnionVector; import org.apache.arrow.vector.complex.UnionVector; -/** - * Base accessor for {@link UnionVector} and {@link DenseUnionVector}. - */ +/** Base accessor for {@link UnionVector} and {@link DenseUnionVector}. */ public abstract class AbstractArrowFlightJdbcUnionVectorAccessor extends ArrowFlightJdbcAccessor { /** - * Array of accessors for each type contained in UnionVector. - * Index corresponds to UnionVector and DenseUnionVector typeIds which are both limited to 128. + * Array of accessors for each type contained in UnionVector. Index corresponds to UnionVector and + * DenseUnionVector typeIds which are both limited to 128. */ private final ArrowFlightJdbcAccessor[] accessors = new ArrowFlightJdbcAccessor[128]; private final ArrowFlightJdbcNullVectorAccessor nullAccessor = - new ArrowFlightJdbcNullVectorAccessor((boolean wasNull) -> { - }); + new ArrowFlightJdbcNullVectorAccessor((boolean wasNull) -> {}); - protected AbstractArrowFlightJdbcUnionVectorAccessor(IntSupplier currentRowSupplier, + protected AbstractArrowFlightJdbcUnionVectorAccessor( + IntSupplier currentRowSupplier, ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcDenseUnionVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcDenseUnionVectorAccessor.java index ba5b83ade63..74c1754cfbf 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcDenseUnionVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcDenseUnionVectorAccessor.java @@ -18,15 +18,12 @@ package org.apache.arrow.driver.jdbc.accessor.impl.complex; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.ValueVector; import org.apache.arrow.vector.complex.DenseUnionVector; -/** - * Accessor for the Arrow type {@link DenseUnionVector}. - */ +/** Accessor for the Arrow type {@link DenseUnionVector}. */ public class ArrowFlightJdbcDenseUnionVectorAccessor extends AbstractArrowFlightJdbcUnionVectorAccessor { @@ -35,22 +32,22 @@ public class ArrowFlightJdbcDenseUnionVectorAccessor /** * Instantiate an accessor for a {@link DenseUnionVector}. * - * @param vector an instance of a DenseUnionVector. + * @param vector an instance of a DenseUnionVector. * @param currentRowSupplier the supplier to track the rows. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcDenseUnionVectorAccessor(DenseUnionVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcDenseUnionVectorAccessor( + DenseUnionVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; } @Override protected ArrowFlightJdbcAccessor createAccessorForVector(ValueVector vector) { - return ArrowFlightJdbcAccessorFactory.createAccessor(vector, - () -> this.vector.getOffset(this.getCurrentRow()), (boolean wasNull) -> { - }); + return ArrowFlightJdbcAccessorFactory.createAccessor( + vector, () -> this.vector.getOffset(this.getCurrentRow()), (boolean wasNull) -> {}); } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcFixedSizeListVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcFixedSizeListVectorAccessor.java index 7bdd3abfd0c..b55cc3bec19 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcFixedSizeListVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcFixedSizeListVectorAccessor.java @@ -19,22 +19,20 @@ import java.util.List; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.FixedSizeListVector; -/** - * Accessor for the Arrow type {@link FixedSizeListVector}. - */ +/** Accessor for the Arrow type {@link FixedSizeListVector}. */ public class ArrowFlightJdbcFixedSizeListVectorAccessor extends AbstractArrowFlightJdbcListVectorAccessor { private final FixedSizeListVector vector; - public ArrowFlightJdbcFixedSizeListVectorAccessor(FixedSizeListVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcFixedSizeListVectorAccessor( + FixedSizeListVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcLargeListVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcLargeListVectorAccessor.java index f7608bb06e5..f88ccf35465 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcLargeListVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcLargeListVectorAccessor.java @@ -19,22 +19,20 @@ import java.util.List; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.LargeListVector; -/** - * Accessor for the Arrow type {@link LargeListVector}. - */ +/** Accessor for the Arrow type {@link LargeListVector}. */ public class ArrowFlightJdbcLargeListVectorAccessor extends AbstractArrowFlightJdbcListVectorAccessor { private final LargeListVector vector; - public ArrowFlightJdbcLargeListVectorAccessor(LargeListVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcLargeListVectorAccessor( + LargeListVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcListVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcListVectorAccessor.java index a329a344073..daa7ed82767 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcListVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcListVectorAccessor.java @@ -19,21 +19,20 @@ import java.util.List; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.BaseRepeatedValueVector; import org.apache.arrow.vector.complex.ListVector; -/** - * Accessor for the Arrow type {@link ListVector}. - */ +/** Accessor for the Arrow type {@link ListVector}. */ public class ArrowFlightJdbcListVectorAccessor extends AbstractArrowFlightJdbcListVectorAccessor { private final ListVector vector; - public ArrowFlightJdbcListVectorAccessor(ListVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcListVectorAccessor( + ListVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; } @@ -45,7 +44,8 @@ protected long getStartOffset(int index) { @Override protected long getEndOffset(int index) { - return vector.getOffsetBuffer() + return vector + .getOffsetBuffer() .getInt((long) (index + 1) * BaseRepeatedValueVector.OFFSET_WIDTH); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcMapVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcMapVectorAccessor.java index bf1225b33de..b2476cbc021 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcMapVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcMapVectorAccessor.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.BaseRepeatedValueVector; @@ -27,15 +26,15 @@ import org.apache.arrow.vector.complex.impl.UnionMapReader; import org.apache.arrow.vector.util.JsonStringHashMap; -/** - * Accessor for the Arrow type {@link MapVector}. - */ +/** Accessor for the Arrow type {@link MapVector}. */ public class ArrowFlightJdbcMapVectorAccessor extends AbstractArrowFlightJdbcListVectorAccessor { private final MapVector vector; - public ArrowFlightJdbcMapVectorAccessor(MapVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcMapVectorAccessor( + MapVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; } @@ -76,7 +75,8 @@ protected long getStartOffset(int index) { @Override protected long getEndOffset(int index) { - return vector.getOffsetBuffer() + return vector + .getOffsetBuffer() .getInt((long) (index + 1) * BaseRepeatedValueVector.OFFSET_WIDTH); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessor.java index 8a7ac117113..755d927a95b 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessor.java @@ -22,21 +22,20 @@ import java.util.Map; import java.util.function.IntSupplier; import java.util.stream.Collectors; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.complex.StructVector; import org.apache.calcite.avatica.util.StructImpl; -/** - * Accessor for the Arrow type {@link StructVector}. - */ +/** Accessor for the Arrow type {@link StructVector}. */ public class ArrowFlightJdbcStructVectorAccessor extends ArrowFlightJdbcAccessor { private final StructVector vector; - public ArrowFlightJdbcStructVectorAccessor(StructVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcStructVectorAccessor( + StructVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; } @@ -65,10 +64,10 @@ public Struct getStruct() { return null; } - List attributes = vector.getChildrenFromFields() - .stream() - .map(vector -> vector.getObject(currentRow)) - .collect(Collectors.toList()); + List attributes = + vector.getChildrenFromFields().stream() + .map(vector -> vector.getObject(currentRow)) + .collect(Collectors.toList()); return new StructImpl(attributes); } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcUnionVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcUnionVectorAccessor.java index 5b5a0a472d5..39fb232b525 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcUnionVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcUnionVectorAccessor.java @@ -18,15 +18,12 @@ package org.apache.arrow.driver.jdbc.accessor.impl.complex; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.ValueVector; import org.apache.arrow.vector.complex.UnionVector; -/** - * Accessor for the Arrow type {@link UnionVector}. - */ +/** Accessor for the Arrow type {@link UnionVector}. */ public class ArrowFlightJdbcUnionVectorAccessor extends AbstractArrowFlightJdbcUnionVectorAccessor { private final UnionVector vector; @@ -34,21 +31,22 @@ public class ArrowFlightJdbcUnionVectorAccessor extends AbstractArrowFlightJdbcU /** * Instantiate an accessor for a {@link UnionVector}. * - * @param vector an instance of a UnionVector. + * @param vector an instance of a UnionVector. * @param currentRowSupplier the supplier to track the rows. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcUnionVectorAccessor(UnionVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcUnionVectorAccessor( + UnionVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; } @Override protected ArrowFlightJdbcAccessor createAccessorForVector(ValueVector vector) { - return ArrowFlightJdbcAccessorFactory.createAccessor(vector, this::getCurrentRow, - (boolean wasNull) -> { - }); + return ArrowFlightJdbcAccessorFactory.createAccessor( + vector, this::getCurrentRow, (boolean wasNull) -> {}); } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessor.java index aea9b75fa6c..439f1b00591 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessor.java @@ -23,7 +23,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.accessor.impl.numeric.ArrowFlightJdbcNumericGetter.NumericHolder; @@ -50,49 +49,68 @@ public class ArrowFlightJdbcBaseIntVectorAccessor extends ArrowFlightJdbcAccesso private final Getter getter; private final NumericHolder holder; - public ArrowFlightJdbcBaseIntVectorAccessor(UInt1Vector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBaseIntVectorAccessor( + UInt1Vector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector, currentRowSupplier, true, UInt1Vector.TYPE_WIDTH, setCursorWasNull); } - public ArrowFlightJdbcBaseIntVectorAccessor(UInt2Vector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBaseIntVectorAccessor( + UInt2Vector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector, currentRowSupplier, true, UInt2Vector.TYPE_WIDTH, setCursorWasNull); } - public ArrowFlightJdbcBaseIntVectorAccessor(UInt4Vector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBaseIntVectorAccessor( + UInt4Vector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector, currentRowSupplier, true, UInt4Vector.TYPE_WIDTH, setCursorWasNull); } - public ArrowFlightJdbcBaseIntVectorAccessor(UInt8Vector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBaseIntVectorAccessor( + UInt8Vector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector, currentRowSupplier, true, UInt8Vector.TYPE_WIDTH, setCursorWasNull); } - public ArrowFlightJdbcBaseIntVectorAccessor(TinyIntVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBaseIntVectorAccessor( + TinyIntVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector, currentRowSupplier, false, TinyIntVector.TYPE_WIDTH, setCursorWasNull); } - public ArrowFlightJdbcBaseIntVectorAccessor(SmallIntVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBaseIntVectorAccessor( + SmallIntVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector, currentRowSupplier, false, SmallIntVector.TYPE_WIDTH, setCursorWasNull); } - public ArrowFlightJdbcBaseIntVectorAccessor(IntVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBaseIntVectorAccessor( + IntVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector, currentRowSupplier, false, IntVector.TYPE_WIDTH, setCursorWasNull); } - public ArrowFlightJdbcBaseIntVectorAccessor(BigIntVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBaseIntVectorAccessor( + BigIntVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector, currentRowSupplier, false, BigIntVector.TYPE_WIDTH, setCursorWasNull); } - private ArrowFlightJdbcBaseIntVectorAccessor(BaseIntVector vector, IntSupplier currentRowSupplier, - boolean isUnsigned, int bytesToAllocate, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + private ArrowFlightJdbcBaseIntVectorAccessor( + BaseIntVector vector, + IntSupplier currentRowSupplier, + boolean isUnsigned, + int bytesToAllocate, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.type = vector.getMinorType(); this.holder = new NumericHolder(); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessor.java index f55fd12f9a5..fed164df081 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessor.java @@ -19,15 +19,12 @@ import java.math.BigDecimal; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.BitVector; import org.apache.arrow.vector.holders.NullableBitHolder; -/** - * Accessor for the arrow {@link BitVector}. - */ +/** Accessor for the arrow {@link BitVector}. */ public class ArrowFlightJdbcBitVectorAccessor extends ArrowFlightJdbcAccessor { private final BitVector vector; @@ -37,12 +34,14 @@ public class ArrowFlightJdbcBitVectorAccessor extends ArrowFlightJdbcAccessor { /** * Constructor for the BitVectorAccessor. * - * @param vector an instance of a {@link BitVector}. + * @param vector an instance of a {@link BitVector}. * @param currentRowSupplier a supplier to check which row is being accessed. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcBitVectorAccessor(BitVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcBitVectorAccessor( + BitVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.vector = vector; this.holder = new NullableBitHolder(); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcDecimalVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcDecimalVectorAccessor.java index 0f7d618a609..5e1e17ad9b5 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcDecimalVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcDecimalVectorAccessor.java @@ -20,36 +20,34 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.Decimal256Vector; import org.apache.arrow.vector.DecimalVector; -/** - * Accessor for {@link DecimalVector} and {@link Decimal256Vector}. - */ +/** Accessor for {@link DecimalVector} and {@link Decimal256Vector}. */ public class ArrowFlightJdbcDecimalVectorAccessor extends ArrowFlightJdbcAccessor { private final Getter getter; - /** - * Functional interface used to unify Decimal*Vector#getObject implementations. - */ + /** Functional interface used to unify Decimal*Vector#getObject implementations. */ @FunctionalInterface interface Getter { BigDecimal getObject(int index); } - public ArrowFlightJdbcDecimalVectorAccessor(DecimalVector vector, IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcDecimalVectorAccessor( + DecimalVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.getter = vector::getObject; } - public ArrowFlightJdbcDecimalVectorAccessor(Decimal256Vector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcDecimalVectorAccessor( + Decimal256Vector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.getter = vector::getObject; } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat4VectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat4VectorAccessor.java index cbf2d36ff80..4dd9065af86 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat4VectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat4VectorAccessor.java @@ -21,15 +21,12 @@ import java.math.RoundingMode; import java.sql.SQLException; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.Float4Vector; import org.apache.arrow.vector.holders.NullableFloat4Holder; -/** - * Accessor for the Float4Vector. - */ +/** Accessor for the Float4Vector. */ public class ArrowFlightJdbcFloat4VectorAccessor extends ArrowFlightJdbcAccessor { private final Float4Vector vector; @@ -38,13 +35,14 @@ public class ArrowFlightJdbcFloat4VectorAccessor extends ArrowFlightJdbcAccessor /** * Instantiate a accessor for the {@link Float4Vector}. * - * @param vector an instance of a Float4Vector. + * @param vector an instance of a Float4Vector. * @param currentRowSupplier the supplier to track the lines. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcFloat4VectorAccessor(Float4Vector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcFloat4VectorAccessor( + Float4Vector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new NullableFloat4Holder(); this.vector = vector; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat8VectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat8VectorAccessor.java index dc5542ffc58..44538f011d4 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat8VectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat8VectorAccessor.java @@ -21,15 +21,12 @@ import java.math.RoundingMode; import java.sql.SQLException; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.vector.Float8Vector; import org.apache.arrow.vector.holders.NullableFloat8Holder; -/** - * Accessor for the Float8Vector. - */ +/** Accessor for the Float8Vector. */ public class ArrowFlightJdbcFloat8VectorAccessor extends ArrowFlightJdbcAccessor { private final Float8Vector vector; @@ -38,13 +35,14 @@ public class ArrowFlightJdbcFloat8VectorAccessor extends ArrowFlightJdbcAccessor /** * Instantiate a accessor for the {@link Float8Vector}. * - * @param vector an instance of a Float8Vector. + * @param vector an instance of a Float8Vector. * @param currentRowSupplier the supplier to track the lines. - * @param setCursorWasNull the consumer to set if value was null. + * @param setCursorWasNull the consumer to set if value was null. */ - public ArrowFlightJdbcFloat8VectorAccessor(Float8Vector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcFloat8VectorAccessor( + Float8Vector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.holder = new NullableFloat8Holder(); this.vector = vector; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcNumericGetter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcNumericGetter.java index cc802a0089d..4052d1efad3 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcNumericGetter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcNumericGetter.java @@ -15,7 +15,6 @@ * limitations under the License. */ - package org.apache.arrow.driver.jdbc.accessor.impl.numeric; import org.apache.arrow.vector.BaseIntVector; @@ -36,29 +35,22 @@ import org.apache.arrow.vector.holders.NullableUInt4Holder; import org.apache.arrow.vector.holders.NullableUInt8Holder; -/** - * A custom getter for values from the {@link BaseIntVector}. - */ +/** A custom getter for values from the {@link BaseIntVector}. */ class ArrowFlightJdbcNumericGetter { - /** - * A holder for values from the {@link BaseIntVector}. - */ + /** A holder for values from the {@link BaseIntVector}. */ static class NumericHolder { int isSet; // Tells if value is set; 0 = not set, 1 = set long value; // Holds actual value } - /** - * Functional interface for a getter to baseInt values. - */ + /** Functional interface for a getter to baseInt values. */ @FunctionalInterface interface Getter { void get(int index, NumericHolder holder); } /** - * Main class that will check the type of the vector to create - * a specific getter. + * Main class that will check the type of the vector to create a specific getter. * * @param vector an instance of the {@link BaseIntVector} * @return a getter. diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessor.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessor.java index d4075bbb75e..7eef1078196 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessor.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessor.java @@ -31,7 +31,6 @@ import java.sql.Timestamp; import java.util.Calendar; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.utils.DateTimeUtils; @@ -39,14 +38,10 @@ import org.apache.arrow.vector.VarCharVector; import org.apache.arrow.vector.util.Text; -/** - * Accessor for the Arrow types: {@link VarCharVector} and {@link LargeVarCharVector}. - */ +/** Accessor for the Arrow types: {@link VarCharVector} and {@link LargeVarCharVector}. */ public class ArrowFlightJdbcVarCharVectorAccessor extends ArrowFlightJdbcAccessor { - /** - * Functional interface to help integrating VarCharVector and LargeVarCharVector. - */ + /** Functional interface to help integrating VarCharVector and LargeVarCharVector. */ @FunctionalInterface interface Getter { byte[] get(int index); @@ -54,21 +49,24 @@ interface Getter { private final Getter getter; - public ArrowFlightJdbcVarCharVectorAccessor(VarCharVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcVarCharVectorAccessor( + VarCharVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector::get, currentRowSupplier, setCursorWasNull); } - public ArrowFlightJdbcVarCharVectorAccessor(LargeVarCharVector vector, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + public ArrowFlightJdbcVarCharVectorAccessor( + LargeVarCharVector vector, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { this(vector::get, currentRowSupplier, setCursorWasNull); } - ArrowFlightJdbcVarCharVectorAccessor(Getter getter, - IntSupplier currentRowSupplier, - ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { + ArrowFlightJdbcVarCharVectorAccessor( + Getter getter, + IntSupplier currentRowSupplier, + ArrowFlightJdbcAccessorFactory.WasNullConsumer setCursorWasNull) { super(currentRowSupplier, setCursorWasNull); this.getter = getter; } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java index 234820bd418..5ca14c8dc4f 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java @@ -27,7 +27,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; - import org.apache.arrow.driver.jdbc.client.utils.ClientAuthenticationUtils; import org.apache.arrow.flight.CallOption; import org.apache.arrow.flight.FlightClient; @@ -56,9 +55,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * A {@link FlightSqlClient} handler. - */ +/** A {@link FlightSqlClient} handler. */ public final class ArrowFlightSqlClientHandler implements AutoCloseable { private static final Logger LOGGER = LoggerFactory.getLogger(ArrowFlightSqlClientHandler.class); @@ -66,9 +63,10 @@ public final class ArrowFlightSqlClientHandler implements AutoCloseable { private final Set options = new HashSet<>(); private final Builder builder; - ArrowFlightSqlClientHandler(final FlightSqlClient sqlClient, - final Builder builder, - final Collection credentialOptions) { + ArrowFlightSqlClientHandler( + final FlightSqlClient sqlClient, + final Builder builder, + final Collection credentialOptions) { this.options.addAll(builder.options); this.options.addAll(credentialOptions); this.sqlClient = Preconditions.checkNotNull(sqlClient); @@ -76,15 +74,15 @@ public final class ArrowFlightSqlClientHandler implements AutoCloseable { } /** - * Creates a new {@link ArrowFlightSqlClientHandler} from the provided {@code client} and {@code options}. + * Creates a new {@link ArrowFlightSqlClientHandler} from the provided {@code client} and {@code + * options}. * - * @param client the {@link FlightClient} to manage under a {@link FlightSqlClient} wrapper. + * @param client the {@link FlightClient} to manage under a {@link FlightSqlClient} wrapper. * @param options the {@link CallOption}s to persist in between subsequent client calls. * @return a new {@link ArrowFlightSqlClientHandler}. */ - public static ArrowFlightSqlClientHandler createNewHandler(final FlightClient client, - final Builder builder, - final Collection options) { + public static ArrowFlightSqlClientHandler createNewHandler( + final FlightClient client, final Builder builder, final Collection options) { return new ArrowFlightSqlClientHandler(new FlightSqlClient(client), builder, options); } @@ -98,13 +96,14 @@ private CallOption[] getOptions() { } /** - * Makes an RPC "getStream" request based on the provided {@link FlightInfo} - * object. Retrieves the result of the query previously prepared with "getInfo." + * Makes an RPC "getStream" request based on the provided {@link FlightInfo} object. Retrieves the + * result of the query previously prepared with "getInfo." * * @param flightInfo The {@link FlightInfo} instance from which to fetch results. * @return a {@code FlightStream} of results. */ - public List getStreams(final FlightInfo flightInfo) throws SQLException { + public List getStreams(final FlightInfo flightInfo) + throws SQLException { final ArrayList endpoints = new ArrayList<>(flightInfo.getEndpoints().size()); @@ -112,28 +111,36 @@ public List getStreams(final FlightInfo flightInfo) for (FlightEndpoint endpoint : flightInfo.getEndpoints()) { if (endpoint.getLocations().isEmpty()) { // Create a stream using the current client only and do not close the client at the end. - endpoints.add(new CloseableEndpointStreamPair( - sqlClient.getStream(endpoint.getTicket(), getOptions()), null)); + endpoints.add( + new CloseableEndpointStreamPair( + sqlClient.getStream(endpoint.getTicket(), getOptions()), null)); } else { // Clone the builder and then set the new endpoint on it. - // GH-38573: This code currently only tries the first Location and treats a failure as fatal. + // GH-38573: This code currently only tries the first Location and treats a failure as + // fatal. // This should be changed to try other Locations that are available. - - // GH-38574: Currently a new FlightClient will be made for each partition that returns a non-empty Location - // then disposed of. It may be better to cache clients because a server may report the same Locations. - // It would also be good to identify when the reported location is the same as the original connection's + + // GH-38574: Currently a new FlightClient will be made for each partition that returns a + // non-empty Location + // then disposed of. It may be better to cache clients because a server may report the + // same Locations. + // It would also be good to identify when the reported location is the same as the + // original connection's // Location and skip creating a FlightClient in that scenario. final URI endpointUri = endpoint.getLocations().get(0).getUri(); - final Builder builderForEndpoint = new Builder(ArrowFlightSqlClientHandler.this.builder) - .withHost(endpointUri.getHost()) - .withPort(endpointUri.getPort()) - .withEncryption(endpointUri.getScheme().equals(LocationSchemes.GRPC_TLS)); + final Builder builderForEndpoint = + new Builder(ArrowFlightSqlClientHandler.this.builder) + .withHost(endpointUri.getHost()) + .withPort(endpointUri.getPort()) + .withEncryption(endpointUri.getScheme().equals(LocationSchemes.GRPC_TLS)); final ArrowFlightSqlClientHandler endpointHandler = builderForEndpoint.build(); try { - endpoints.add(new CloseableEndpointStreamPair( - endpointHandler.sqlClient.getStream(endpoint.getTicket(), - endpointHandler.getOptions()), endpointHandler.sqlClient)); + endpoints.add( + new CloseableEndpointStreamPair( + endpointHandler.sqlClient.getStream( + endpoint.getTicket(), endpointHandler.getOptions()), + endpointHandler.sqlClient)); } catch (Exception ex) { AutoCloseables.close(endpointHandler); throw ex; @@ -156,8 +163,7 @@ public List getStreams(final FlightInfo flightInfo) } /** - * Makes an RPC "getInfo" request based on the provided {@code query} - * object. + * Makes an RPC "getInfo" request based on the provided {@code query} object. * * @param query The query. * @return a {@code FlightStream} of results. @@ -175,9 +181,7 @@ public void close() throws SQLException { } } - /** - * A prepared statement handler. - */ + /** A prepared statement handler. */ public interface PreparedStatement extends AutoCloseable { /** * Executes this {@link PreparedStatement}. @@ -268,9 +272,9 @@ public void close() { preparedStatement.close(getOptions()); } catch (FlightRuntimeException fre) { // ARROW-17785: suppress exceptions caused by flaky gRPC layer - if (fre.status().code().equals(FlightStatusCode.UNAVAILABLE) || - (fre.status().code().equals(FlightStatusCode.INTERNAL) && - fre.getMessage().contains("Connection closed after GOAWAY"))) { + if (fre.status().code().equals(FlightStatusCode.UNAVAILABLE) + || (fre.status().code().equals(FlightStatusCode.INTERNAL) + && fre.getMessage().contains("Connection closed after GOAWAY"))) { LOGGER.warn("Supressed error closing PreparedStatement", fre); return; } @@ -293,12 +297,12 @@ public FlightInfo getCatalogs() { * Makes an RPC "getImportedKeys" request based on the provided info. * * @param catalog The catalog name. Must match the catalog name as it is stored in the database. - * Retrieves those without a catalog. Null means that the catalog name should not be used to - * narrow the search. - * @param schema The schema name. Must match the schema name as it is stored in the database. - * "" retrieves those without a schema. Null means that the schema name should not be used to narrow - * the search. - * @param table The table name. Must match the table name as it is stored in the database. + * Retrieves those without a catalog. Null means that the catalog name should not be used to + * narrow the search. + * @param schema The schema name. Must match the schema name as it is stored in the database. "" + * retrieves those without a schema. Null means that the schema name should not be used to + * narrow the search. + * @param table The table name. Must match the table name as it is stored in the database. * @return a {@code FlightStream} of results. */ public FlightInfo getImportedKeys(final String catalog, final String schema, final String table) { @@ -309,12 +313,12 @@ public FlightInfo getImportedKeys(final String catalog, final String schema, fin * Makes an RPC "getExportedKeys" request based on the provided info. * * @param catalog The catalog name. Must match the catalog name as it is stored in the database. - * Retrieves those without a catalog. Null means that the catalog name should not be used to - * narrow the search. - * @param schema The schema name. Must match the schema name as it is stored in the database. - * "" retrieves those without a schema. Null means that the schema name should not be used to narrow - * the search. - * @param table The table name. Must match the table name as it is stored in the database. + * Retrieves those without a catalog. Null means that the catalog name should not be used to + * narrow the search. + * @param schema The schema name. Must match the schema name as it is stored in the database. "" + * retrieves those without a schema. Null means that the schema name should not be used to + * narrow the search. + * @param table The table name. Must match the table name as it is stored in the database. * @return a {@code FlightStream} of results. */ public FlightInfo getExportedKeys(final String catalog, final String schema, final String table) { @@ -324,11 +328,11 @@ public FlightInfo getExportedKeys(final String catalog, final String schema, fin /** * Makes an RPC "getSchemas" request based on the provided info. * - * @param catalog The catalog name. Must match the catalog name as it is stored in the database. - * Retrieves those without a catalog. Null means that the catalog name should not be used to - * narrow the search. - * @param schemaPattern The schema name pattern. Must match the schema name as it is stored in the database. - * Null means that schema name should not be used to narrow down the search. + * @param catalog The catalog name. Must match the catalog name as it is stored in the database. + * Retrieves those without a catalog. Null means that the catalog name should not be used to + * narrow the search. + * @param schemaPattern The schema name pattern. Must match the schema name as it is stored in the + * database. Null means that schema name should not be used to narrow down the search. * @return a {@code FlightStream} of results. */ public FlightInfo getSchemas(final String catalog, final String schemaPattern) { @@ -347,24 +351,28 @@ public FlightInfo getTableTypes() { /** * Makes an RPC "getTables" request based on the provided info. * - * @param catalog The catalog name. Must match the catalog name as it is stored in the database. - * Retrieves those without a catalog. Null means that the catalog name should not be used to - * narrow the search. - * @param schemaPattern The schema name pattern. Must match the schema name as it is stored in the database. - * "" retrieves those without a schema. Null means that the schema name should not be used to - * narrow the search. - * @param tableNamePattern The table name pattern. Must match the table name as it is stored in the database. - * @param types The list of table types, which must be from the list of table types to include. - * Null returns all types. - * @param includeSchema Whether to include schema. + * @param catalog The catalog name. Must match the catalog name as it is stored in the database. + * Retrieves those without a catalog. Null means that the catalog name should not be used to + * narrow the search. + * @param schemaPattern The schema name pattern. Must match the schema name as it is stored in the + * database. "" retrieves those without a schema. Null means that the schema name should not + * be used to narrow the search. + * @param tableNamePattern The table name pattern. Must match the table name as it is stored in + * the database. + * @param types The list of table types, which must be from the list of table types to include. + * Null returns all types. + * @param includeSchema Whether to include schema. * @return a {@code FlightStream} of results. */ - public FlightInfo getTables(final String catalog, final String schemaPattern, - final String tableNamePattern, - final List types, final boolean includeSchema) { - - return sqlClient.getTables(catalog, schemaPattern, tableNamePattern, types, includeSchema, - getOptions()); + public FlightInfo getTables( + final String catalog, + final String schemaPattern, + final String tableNamePattern, + final List types, + final boolean includeSchema) { + + return sqlClient.getTables( + catalog, schemaPattern, tableNamePattern, types, includeSchema, getOptions()); } /** @@ -380,12 +388,12 @@ public FlightInfo getSqlInfo(SqlInfo... info) { * Makes an RPC "getPrimaryKeys" request based on the provided info. * * @param catalog The catalog name; must match the catalog name as it is stored in the database. - * "" retrieves those without a catalog. - * Null means that the catalog name should not be used to narrow the search. - * @param schema The schema name; must match the schema name as it is stored in the database. - * "" retrieves those without a schema. Null means that the schema name should not be used to narrow - * the search. - * @param table The table name. Must match the table name as it is stored in the database. + * "" retrieves those without a catalog. Null means that the catalog name should not be used + * to narrow the search. + * @param schema The schema name; must match the schema name as it is stored in the database. "" + * retrieves those without a schema. Null means that the schema name should not be used to + * narrow the search. + * @param table The table name. Must match the table name as it is stored in the database. * @return a {@code FlightStream} of results. */ public FlightInfo getPrimaryKeys(final String catalog, final String schema, final String table) { @@ -396,90 +404,80 @@ public FlightInfo getPrimaryKeys(final String catalog, final String schema, fina * Makes an RPC "getCrossReference" request based on the provided info. * * @param pkCatalog The catalog name. Must match the catalog name as it is stored in the database. - * Retrieves those without a catalog. Null means that the catalog name should not be used to - * narrow the search. - * @param pkSchema The schema name. Must match the schema name as it is stored in the database. - * "" retrieves those without a schema. Null means that the schema name should not be used to narrow - * the search. - * @param pkTable The table name. Must match the table name as it is stored in the database. + * Retrieves those without a catalog. Null means that the catalog name should not be used to + * narrow the search. + * @param pkSchema The schema name. Must match the schema name as it is stored in the database. "" + * retrieves those without a schema. Null means that the schema name should not be used to + * narrow the search. + * @param pkTable The table name. Must match the table name as it is stored in the database. * @param fkCatalog The catalog name. Must match the catalog name as it is stored in the database. - * Retrieves those without a catalog. Null means that the catalog name should not be used to - * narrow the search. - * @param fkSchema The schema name. Must match the schema name as it is stored in the database. - * "" retrieves those without a schema. Null means that the schema name should not be used to narrow - * the search. - * @param fkTable The table name. Must match the table name as it is stored in the database. + * Retrieves those without a catalog. Null means that the catalog name should not be used to + * narrow the search. + * @param fkSchema The schema name. Must match the schema name as it is stored in the database. "" + * retrieves those without a schema. Null means that the schema name should not be used to + * narrow the search. + * @param fkTable The table name. Must match the table name as it is stored in the database. * @return a {@code FlightStream} of results. */ - public FlightInfo getCrossReference(String pkCatalog, String pkSchema, String pkTable, - String fkCatalog, String fkSchema, String fkTable) { - return sqlClient.getCrossReference(TableRef.of(pkCatalog, pkSchema, pkTable), + public FlightInfo getCrossReference( + String pkCatalog, + String pkSchema, + String pkTable, + String fkCatalog, + String fkSchema, + String fkTable) { + return sqlClient.getCrossReference( + TableRef.of(pkCatalog, pkSchema, pkTable), TableRef.of(fkCatalog, fkSchema, fkTable), getOptions()); } - /** - * Builder for {@link ArrowFlightSqlClientHandler}. - */ + /** Builder for {@link ArrowFlightSqlClientHandler}. */ public static final class Builder { private final Set middlewareFactories = new HashSet<>(); private final Set options = new HashSet<>(); private String host; private int port; - @VisibleForTesting - String username; + @VisibleForTesting String username; - @VisibleForTesting - String password; + @VisibleForTesting String password; - @VisibleForTesting - String trustStorePath; + @VisibleForTesting String trustStorePath; - @VisibleForTesting - String trustStorePassword; + @VisibleForTesting String trustStorePassword; - @VisibleForTesting - String token; + @VisibleForTesting String token; - @VisibleForTesting - boolean useEncryption = true; + @VisibleForTesting boolean useEncryption = true; - @VisibleForTesting - boolean disableCertificateVerification; + @VisibleForTesting boolean disableCertificateVerification; - @VisibleForTesting - boolean useSystemTrustStore = true; + @VisibleForTesting boolean useSystemTrustStore = true; - @VisibleForTesting - String tlsRootCertificatesPath; + @VisibleForTesting String tlsRootCertificatesPath; - @VisibleForTesting - String clientCertificatePath; + @VisibleForTesting String clientCertificatePath; - @VisibleForTesting - String clientKeyPath; + @VisibleForTesting String clientKeyPath; - @VisibleForTesting - private BufferAllocator allocator; + @VisibleForTesting private BufferAllocator allocator; - @VisibleForTesting - boolean retainCookies = true; + @VisibleForTesting boolean retainCookies = true; - @VisibleForTesting - boolean retainAuth = true; + @VisibleForTesting boolean retainAuth = true; - // These two middleware are for internal use within build() and should not be exposed by builder APIs. + // These two middleware are for internal use within build() and should not be exposed by builder + // APIs. // Note that these middleware may not necessarily be registered. @VisibleForTesting - ClientIncomingAuthHeaderMiddleware.Factory authFactory - = new ClientIncomingAuthHeaderMiddleware.Factory(new ClientBearerHeaderHandler()); + ClientIncomingAuthHeaderMiddleware.Factory authFactory = + new ClientIncomingAuthHeaderMiddleware.Factory(new ClientBearerHeaderHandler()); @VisibleForTesting ClientCookieMiddleware.Factory cookieFactory = new ClientCookieMiddleware.Factory(); - public Builder() { - } + public Builder() {} /** * Copies the builder. @@ -597,7 +595,8 @@ public Builder withEncryption(final boolean useEncryption) { * @param disableCertificateVerification whether to disable certificate verification. * @return this instance. */ - public Builder withDisableCertificateVerification(final boolean disableCertificateVerification) { + public Builder withDisableCertificateVerification( + final boolean disableCertificateVerification) { this.disableCertificateVerification = disableCertificateVerification; return this; } @@ -614,8 +613,8 @@ public Builder withSystemTrustStore(final boolean useSystemTrustStore) { } /** - * Sets the TLS root certificate path as an alternative to using the System - * or other Trust Store. The path must contain a valid PEM file. + * Sets the TLS root certificate path as an alternative to using the System or other Trust + * Store. The path must contain a valid PEM file. * * @param tlsRootCertificatesPath the TLS root certificate path (if TLS is required). * @return this instance. @@ -646,12 +645,12 @@ public Builder withClientKey(final String clientKeyPath) { this.clientKeyPath = clientKeyPath; return this; } - + /** * Sets the token used in the token authentication. * * @param token the token value. - * @return this builder instance. + * @return this builder instance. */ public Builder withToken(final String token) { this.token = token; @@ -665,15 +664,16 @@ public Builder withToken(final String token) { * @return this instance. */ public Builder withBufferAllocator(final BufferAllocator allocator) { - this.allocator = allocator - .newChildAllocator("ArrowFlightSqlClientHandler", 0, allocator.getLimit()); + this.allocator = + allocator.newChildAllocator("ArrowFlightSqlClientHandler", 0, allocator.getLimit()); return this; } /** * Indicates if cookies should be re-used by connections spawned for getStreams() calls. + * * @param retainCookies The flag indicating if cookies should be re-used. - * @return this builder instance. + * @return this builder instance. */ public Builder withRetainCookies(boolean retainCookies) { this.retainCookies = retainCookies; @@ -681,11 +681,11 @@ public Builder withRetainCookies(boolean retainCookies) { } /** - * Indicates if bearer tokens negotiated should be re-used by connections - * spawned for getStreams() calls. + * Indicates if bearer tokens negotiated should be re-used by connections spawned for + * getStreams() calls. * * @param retainAuth The flag indicating if auth tokens should be re-used. - * @return this builder instance. + * @return this builder instance. */ public Builder withRetainAuth(boolean retainAuth) { this.retainAuth = retainAuth; @@ -693,7 +693,8 @@ public Builder withRetainAuth(boolean retainAuth) { } /** - * Adds the provided {@code factories} to the list of {@link #middlewareFactories} of this handler. + * Adds the provided {@code factories} to the list of {@link #middlewareFactories} of this + * handler. * * @param factories the factories to add. * @return this instance. @@ -703,7 +704,8 @@ public Builder withMiddlewareFactories(final FlightClientMiddleware.Factory... f } /** - * Adds the provided {@code factories} to the list of {@link #middlewareFactories} of this handler. + * Adds the provided {@code factories} to the list of {@link #middlewareFactories} of this + * handler. * * @param factories the factories to add. * @return this instance. @@ -742,13 +744,16 @@ public Builder withCallOptions(final Collection options) { * @throws SQLException on error. */ public ArrowFlightSqlClientHandler build() throws SQLException { - // Copy middleware so that the build method doesn't change the state of the builder fields itself. - Set buildTimeMiddlewareFactories = new HashSet<>(this.middlewareFactories); + // Copy middleware so that the build method doesn't change the state of the builder fields + // itself. + Set buildTimeMiddlewareFactories = + new HashSet<>(this.middlewareFactories); FlightClient client = null; boolean isUsingUserPasswordAuth = username != null && token == null; try { - // Token should take priority since some apps pass in a username/password even when a token is provided + // Token should take priority since some apps pass in a username/password even when a token + // is provided if (isUsingUserPasswordAuth) { buildTimeMiddlewareFactories.add(authFactory); } @@ -771,13 +776,15 @@ public ArrowFlightSqlClientHandler build() throws SQLException { } else { if (tlsRootCertificatesPath != null) { clientBuilder.trustedCertificates( - ClientAuthenticationUtils.getTlsRootCertificatesStream(tlsRootCertificatesPath)); + ClientAuthenticationUtils.getTlsRootCertificatesStream(tlsRootCertificatesPath)); } else if (useSystemTrustStore) { clientBuilder.trustedCertificates( - ClientAuthenticationUtils.getCertificateInputStreamFromSystem(trustStorePassword)); + ClientAuthenticationUtils.getCertificateInputStreamFromSystem( + trustStorePassword)); } else if (trustStorePath != null) { clientBuilder.trustedCertificates( - ClientAuthenticationUtils.getCertificateStream(trustStorePath, trustStorePassword)); + ClientAuthenticationUtils.getCertificateStream( + trustStorePath, trustStorePassword)); } } @@ -792,7 +799,8 @@ public ArrowFlightSqlClientHandler build() throws SQLException { final ArrayList credentialOptions = new ArrayList<>(); if (isUsingUserPasswordAuth) { // If the authFactory has already been used for a handshake, use the existing token. - // This can occur if the authFactory is being re-used for a new connection spawned for getStream(). + // This can occur if the authFactory is being re-used for a new connection spawned for + // getStream(). if (authFactory.getCredentialCallOption() != null) { credentialOptions.add(authFactory.getCredentialCallOption()); } else { @@ -804,12 +812,16 @@ public ArrowFlightSqlClientHandler build() throws SQLException { } else if (token != null) { credentialOptions.add( ClientAuthenticationUtils.getAuthenticate( - client, new CredentialCallOption(new BearerCredentialWriter(token)), options.toArray( - new CallOption[0]))); + client, + new CredentialCallOption(new BearerCredentialWriter(token)), + options.toArray(new CallOption[0]))); } return ArrowFlightSqlClientHandler.createNewHandler(client, this, credentialOptions); - } catch (final IllegalArgumentException | GeneralSecurityException | IOException | FlightRuntimeException e) { + } catch (final IllegalArgumentException + | GeneralSecurityException + | IOException + | FlightRuntimeException e) { final SQLException originalException = new SQLException(e); if (client != null) { try { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/CloseableEndpointStreamPair.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/CloseableEndpointStreamPair.java index 6c37a5b0c62..85fc6299fa8 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/CloseableEndpointStreamPair.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/CloseableEndpointStreamPair.java @@ -22,9 +22,7 @@ import org.apache.arrow.util.AutoCloseables; import org.apache.arrow.util.Preconditions; -/** - * Represents a connection to a {@link org.apache.arrow.flight.FlightEndpoint}. - */ +/** Represents a connection to a {@link org.apache.arrow.flight.FlightEndpoint}. */ public class CloseableEndpointStreamPair implements AutoCloseable { private final FlightStream stream; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtils.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtils.java index ffb0048181c..dd84aa1f274 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtils.java @@ -36,7 +36,6 @@ import java.util.Collection; import java.util.Enumeration; import java.util.List; - import org.apache.arrow.flight.CallOption; import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.auth2.BasicAuthCredentialWriter; @@ -46,9 +45,7 @@ import org.apache.arrow.util.VisibleForTesting; import org.bouncycastle.openssl.jcajce.JcaPEMWriter; -/** - * Utils for {@link FlightClientHandler} authentication. - */ +/** Utils for {@link FlightClientHandler} authentication. */ public final class ClientAuthenticationUtils { private ClientAuthenticationUtils() { @@ -58,14 +55,15 @@ private ClientAuthenticationUtils() { /** * Gets the {@link CredentialCallOption} for the provided authentication info. * - * @param client the client. - * @param credential the credential as CallOptions. - * @param options the {@link CallOption}s to use. + * @param client the client. + * @param credential the credential as CallOptions. + * @param options the {@link CallOption}s to use. * @return the credential call option. */ - public static CredentialCallOption getAuthenticate(final FlightClient client, - final CredentialCallOption credential, - final CallOption... options) { + public static CredentialCallOption getAuthenticate( + final FlightClient client, + final CredentialCallOption credential, + final CallOption... options) { final List theseOptions = new ArrayList<>(); theseOptions.add(credential); @@ -78,27 +76,32 @@ public static CredentialCallOption getAuthenticate(final FlightClient client, /** * Gets the {@link CredentialCallOption} for the provided authentication info. * - * @param client the client. + * @param client the client. * @param username the username. * @param password the password. - * @param factory the {@link ClientIncomingAuthHeaderMiddleware.Factory} to use. - * @param options the {@link CallOption}s to use. + * @param factory the {@link ClientIncomingAuthHeaderMiddleware.Factory} to use. + * @param options the {@link CallOption}s to use. * @return the credential call option. */ - public static CredentialCallOption getAuthenticate(final FlightClient client, - final String username, final String password, - final ClientIncomingAuthHeaderMiddleware.Factory factory, - final CallOption... options) { - - return getAuthenticate(client, + public static CredentialCallOption getAuthenticate( + final FlightClient client, + final String username, + final String password, + final ClientIncomingAuthHeaderMiddleware.Factory factory, + final CallOption... options) { + + return getAuthenticate( + client, new CredentialCallOption(new BasicAuthCredentialWriter(username, password)), - factory, options); + factory, + options); } - private static CredentialCallOption getAuthenticate(final FlightClient client, - final CredentialCallOption token, - final ClientIncomingAuthHeaderMiddleware.Factory factory, - final CallOption... options) { + private static CredentialCallOption getAuthenticate( + final FlightClient client, + final CredentialCallOption token, + final ClientIncomingAuthHeaderMiddleware.Factory factory, + final CallOption... options) { final List theseOptions = new ArrayList<>(); theseOptions.add(token); theseOptions.addAll(Arrays.asList(options)); @@ -148,17 +151,16 @@ public static boolean isMac() { } /** - * It gets the trusted certificate based on the operating system and loads all the certificate into a - * {@link InputStream}. + * It gets the trusted certificate based on the operating system and loads all the certificate + * into a {@link InputStream}. * * @return An input stream with all the certificates. - * - * @throws KeyStoreException if a key store could not be loaded. - * @throws CertificateException if a certificate could not be found. - * @throws IOException if it fails reading the file. + * @throws KeyStoreException if a key store could not be loaded. + * @throws CertificateException if a certificate could not be found. + * @throws IOException if it fails reading the file. */ - public static InputStream getCertificateInputStreamFromSystem(String password) throws KeyStoreException, - CertificateException, IOException, NoSuchAlgorithmException { + public static InputStream getCertificateInputStreamFromSystem(String password) + throws KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException { List keyStoreList = new ArrayList<>(); if (isWindows()) { @@ -201,36 +203,33 @@ static void getCertificatesInputStream(KeyStore keyStore, JcaPEMWriter pemWriter static InputStream getCertificatesInputStream(Collection keyStores) throws IOException, KeyStoreException { try (final StringWriter writer = new StringWriter(); - final JcaPEMWriter pemWriter = new JcaPEMWriter(writer)) { + final JcaPEMWriter pemWriter = new JcaPEMWriter(writer)) { for (KeyStore keyStore : keyStores) { getCertificatesInputStream(keyStore, pemWriter); } - return new ByteArrayInputStream( - writer.toString().getBytes(StandardCharsets.UTF_8)); + return new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8)); } } /** - * Generates an {@link InputStream} that contains certificates for a private - * key. + * Generates an {@link InputStream} that contains certificates for a private key. * * @param keyStorePath The path of the KeyStore. * @param keyStorePass The password of the KeyStore. * @return a new {code InputStream} containing the certificates. * @throws GeneralSecurityException on error. - * @throws IOException on error. + * @throws IOException on error. */ - public static InputStream getCertificateStream(final String keyStorePath, - final String keyStorePass) + public static InputStream getCertificateStream( + final String keyStorePath, final String keyStorePass) throws GeneralSecurityException, IOException { Preconditions.checkNotNull(keyStorePath, "KeyStore path cannot be null!"); Preconditions.checkNotNull(keyStorePass, "KeyStorePass cannot be null!"); final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); - try (final InputStream keyStoreStream = Files - .newInputStream(Paths.get(keyStorePath))) { + try (final InputStream keyStoreStream = Files.newInputStream(Paths.get(keyStorePath))) { keyStore.load(keyStoreStream, keyStorePass.toCharArray()); } @@ -238,54 +237,51 @@ public static InputStream getCertificateStream(final String keyStorePath, } /** - * Generates an {@link InputStream} that contains certificates for path-based - * TLS Root Certificates. + * Generates an {@link InputStream} that contains certificates for path-based TLS Root + * Certificates. * * @param tlsRootsCertificatesPath The path of the TLS Root Certificates. * @return a new {code InputStream} containing the certificates. * @throws GeneralSecurityException on error. - * @throws IOException on error. + * @throws IOException on error. */ public static InputStream getTlsRootCertificatesStream(final String tlsRootsCertificatesPath) - throws GeneralSecurityException, IOException { - Preconditions.checkNotNull(tlsRootsCertificatesPath, "TLS Root certificates path cannot be null!"); + throws GeneralSecurityException, IOException { + Preconditions.checkNotNull( + tlsRootsCertificatesPath, "TLS Root certificates path cannot be null!"); - return Files - .newInputStream(Paths.get(tlsRootsCertificatesPath)); + return Files.newInputStream(Paths.get(tlsRootsCertificatesPath)); } /** - * Generates an {@link InputStream} that contains certificates for a path-based - * mTLS Client Certificate. + * Generates an {@link InputStream} that contains certificates for a path-based mTLS Client + * Certificate. * * @param clientCertificatePath The path of the mTLS Client Certificate. * @return a new {code InputStream} containing the certificates. * @throws GeneralSecurityException on error. - * @throws IOException on error. + * @throws IOException on error. */ public static InputStream getClientCertificateStream(final String clientCertificatePath) throws GeneralSecurityException, IOException { Preconditions.checkNotNull(clientCertificatePath, "Client certificate path cannot be null!"); - return Files - .newInputStream(Paths.get(clientCertificatePath)); + return Files.newInputStream(Paths.get(clientCertificatePath)); } /** - * Generates an {@link InputStream} that contains certificates for a path-based - * mTLS Client Key. + * Generates an {@link InputStream} that contains certificates for a path-based mTLS Client Key. * * @param clientKeyPath The path of the mTLS Client Key. * @return a new {code InputStream} containing the certificates. * @throws GeneralSecurityException on error. - * @throws IOException on error. + * @throws IOException on error. */ public static InputStream getClientKeyStream(final String clientKeyPath) - throws GeneralSecurityException, IOException { + throws GeneralSecurityException, IOException { Preconditions.checkNotNull(clientKeyPath, "Client key path cannot be null!"); - return Files - .newInputStream(Paths.get(clientKeyPath)); + return Files.newInputStream(Paths.get(clientKeyPath)); } private static InputStream getSingleCertificateInputStream(KeyStore keyStore) @@ -302,16 +298,14 @@ private static InputStream getSingleCertificateInputStream(KeyStore keyStore) throw new CertificateException("Keystore did not have a certificate."); } - private static InputStream toInputStream(final Certificate certificate) - throws IOException { + private static InputStream toInputStream(final Certificate certificate) throws IOException { try (final StringWriter writer = new StringWriter(); - final JcaPEMWriter pemWriter = new JcaPEMWriter(writer)) { + final JcaPEMWriter pemWriter = new JcaPEMWriter(writer)) { pemWriter.writeObject(certificate); pemWriter.flush(); - return new ByteArrayInputStream( - writer.toString().getBytes(StandardCharsets.UTF_8)); + return new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8)); } } } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BaseAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BaseAvaticaParameterConverter.java index f5cf8358b7a..8b5b1460a38 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BaseAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BaseAvaticaParameterConverter.java @@ -34,7 +34,8 @@ protected AvaticaParameter createParameter(Field field, boolean signed) { final ArrowType arrowType = field.getType(); final String typeName = arrowType.toString(); final int precision = 0; // Would have to know about the actual number - final int scale = 0; // According to https://www.postgresql.org/docs/current/datatype-numeric.html + final int scale = + 0; // According to https://www.postgresql.org/docs/current/datatype-numeric.html final int jdbcType = SqlTypes.getSqlTypeIdFromArrowType(arrowType); final String className = SqlType.valueOf(jdbcType).clazz.getCanonicalName(); return new AvaticaParameter(signed, precision, scale, jdbcType, typeName, className, name); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BinaryAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BinaryAvaticaParameterConverter.java index d244848955e..0da0d6f69d9 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BinaryAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BinaryAvaticaParameterConverter.java @@ -24,13 +24,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Binary Arrow types. - */ +/** AvaticaParameterConverter for Binary Arrow types. */ public class BinaryAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public BinaryAvaticaParameterConverter(ArrowType.Binary type) { - } + public BinaryAvaticaParameterConverter(ArrowType.Binary type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BoolAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BoolAvaticaParameterConverter.java index 6725154d03c..7df7f7e68f6 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BoolAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/BoolAvaticaParameterConverter.java @@ -24,13 +24,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Bool Arrow types. - */ +/** AvaticaParameterConverter for Bool Arrow types. */ public class BoolAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public BoolAvaticaParameterConverter(ArrowType.Bool type) { - } + public BoolAvaticaParameterConverter(ArrowType.Bool type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DateAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DateAvaticaParameterConverter.java index 0da1dabe437..d51f66b8efa 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DateAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DateAvaticaParameterConverter.java @@ -25,13 +25,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Date Arrow types. - */ +/** AvaticaParameterConverter for Date Arrow types. */ public class DateAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public DateAvaticaParameterConverter(ArrowType.Date type) { - } + public DateAvaticaParameterConverter(ArrowType.Date type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverter.java index fad43e2e06a..7e10fe13b67 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DecimalAvaticaParameterConverter.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc.converter.impl; import java.math.BigDecimal; - import org.apache.arrow.vector.DecimalVector; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.types.pojo.ArrowType; @@ -26,13 +25,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Decimal Arrow types. - */ +/** AvaticaParameterConverter for Decimal Arrow types. */ public class DecimalAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public DecimalAvaticaParameterConverter(ArrowType.Decimal type) { - } + public DecimalAvaticaParameterConverter(ArrowType.Decimal type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DurationAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DurationAvaticaParameterConverter.java index 89f2fc1d5c1..0b42899e1ba 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DurationAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/DurationAvaticaParameterConverter.java @@ -23,13 +23,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Duration Arrow types. - */ +/** AvaticaParameterConverter for Duration Arrow types. */ public class DurationAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public DurationAvaticaParameterConverter(ArrowType.Duration type) { - } + public DurationAvaticaParameterConverter(ArrowType.Duration type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FixedSizeBinaryAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FixedSizeBinaryAvaticaParameterConverter.java index a90434f695a..08e6804d4a8 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FixedSizeBinaryAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FixedSizeBinaryAvaticaParameterConverter.java @@ -24,13 +24,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for FixedSizeBinary Arrow types. - */ +/** AvaticaParameterConverter for FixedSizeBinary Arrow types. */ public class FixedSizeBinaryAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public FixedSizeBinaryAvaticaParameterConverter(ArrowType.FixedSizeBinary type) { - } + public FixedSizeBinaryAvaticaParameterConverter(ArrowType.FixedSizeBinary type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FixedSizeListAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FixedSizeListAvaticaParameterConverter.java index 1525bcaaf51..ca774d68551 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FixedSizeListAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FixedSizeListAvaticaParameterConverter.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc.converter.impl; import java.util.List; - import org.apache.arrow.driver.jdbc.utils.AvaticaParameterBinder; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.FixedSizeListVector; @@ -27,13 +26,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for FixedSizeList Arrow types. - */ +/** AvaticaParameterConverter for FixedSizeList Arrow types. */ public class FixedSizeListAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public FixedSizeListAvaticaParameterConverter(ArrowType.FixedSizeList type) { - } + public FixedSizeListAvaticaParameterConverter(ArrowType.FixedSizeList type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { @@ -47,9 +43,11 @@ public boolean bindParameter(FieldVector vector, TypedValue typedValue, int inde if (arraySize != maxArraySize) { if (!childVector.getField().isNullable()) { - throw new UnsupportedOperationException("Each array must contain " + maxArraySize + " elements"); + throw new UnsupportedOperationException( + "Each array must contain " + maxArraySize + " elements"); } else if (arraySize > maxArraySize) { - throw new UnsupportedOperationException("Each array must contain at most " + maxArraySize + " elements"); + throw new UnsupportedOperationException( + "Each array must contain at most " + maxArraySize + " elements"); } } @@ -64,9 +62,12 @@ public boolean bindParameter(FieldVector vector, TypedValue typedValue, int inde throw new UnsupportedOperationException("Can't set null on non-nullable child list"); } } else { - childVector.getField().getType().accept( + childVector + .getField() + .getType() + .accept( new AvaticaParameterBinder.BinderVisitor( - childVector, TypedValue.ofSerial(typedValue.componentType, val), childIndex)); + childVector, TypedValue.ofSerial(typedValue.componentType, val), childIndex)); } } listVector.setValueCount(index + 1); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FloatingPointAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FloatingPointAvaticaParameterConverter.java index 9f305a2b6f2..2113c3058d0 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FloatingPointAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/FloatingPointAvaticaParameterConverter.java @@ -25,13 +25,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for FloatingPoint Arrow types. - */ +/** AvaticaParameterConverter for FloatingPoint Arrow types. */ public class FloatingPointAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public FloatingPointAvaticaParameterConverter(ArrowType.FloatingPoint type) { - } + public FloatingPointAvaticaParameterConverter(ArrowType.FloatingPoint type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/IntAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/IntAvaticaParameterConverter.java index 6684e8d32c9..96b8aa87265 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/IntAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/IntAvaticaParameterConverter.java @@ -31,9 +31,7 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Int Arrow types. - */ +/** AvaticaParameterConverter for Int Arrow types. */ public class IntAvaticaParameterConverter extends BaseAvaticaParameterConverter { private final ArrowType.Int type; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/IntervalAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/IntervalAvaticaParameterConverter.java index 724275d5109..a9e2db955e4 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/IntervalAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/IntervalAvaticaParameterConverter.java @@ -23,13 +23,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Interval Arrow types. - */ +/** AvaticaParameterConverter for Interval Arrow types. */ public class IntervalAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public IntervalAvaticaParameterConverter(ArrowType.Interval type) { - } + public IntervalAvaticaParameterConverter(ArrowType.Interval type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeBinaryAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeBinaryAvaticaParameterConverter.java index 133ec2072d5..8648aa6e0ca 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeBinaryAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeBinaryAvaticaParameterConverter.java @@ -24,13 +24,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for LargeBinary Arrow types. - */ +/** AvaticaParameterConverter for LargeBinary Arrow types. */ public class LargeBinaryAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public LargeBinaryAvaticaParameterConverter(ArrowType.LargeBinary type) { - } + public LargeBinaryAvaticaParameterConverter(ArrowType.LargeBinary type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeListAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeListAvaticaParameterConverter.java index a20747693e3..bb3ab674483 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeListAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeListAvaticaParameterConverter.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc.converter.impl; import java.util.List; - import org.apache.arrow.driver.jdbc.utils.AvaticaParameterBinder; import org.apache.arrow.memory.util.LargeMemoryUtil; import org.apache.arrow.vector.FieldVector; @@ -28,13 +27,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for LargeList Arrow types. - */ +/** AvaticaParameterConverter for LargeList Arrow types. */ public class LargeListAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public LargeListAvaticaParameterConverter(ArrowType.LargeList type) { - } + public LargeListAvaticaParameterConverter(ArrowType.LargeList type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { @@ -55,9 +51,12 @@ public boolean bindParameter(FieldVector vector, TypedValue typedValue, int inde throw new UnsupportedOperationException("Can't set null on non-nullable child list"); } } else { - childVector.getField().getType().accept( + childVector + .getField() + .getType() + .accept( new AvaticaParameterBinder.BinderVisitor( - childVector, TypedValue.ofSerial(typedValue.componentType, val), childIndex)); + childVector, TypedValue.ofSerial(typedValue.componentType, val), childIndex)); } } listVector.endValue(index, values.size()); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeUtf8AvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeUtf8AvaticaParameterConverter.java index d412ab007ac..e4050c16b97 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeUtf8AvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/LargeUtf8AvaticaParameterConverter.java @@ -25,13 +25,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for LargeUtf8 Arrow types. - */ +/** AvaticaParameterConverter for LargeUtf8 Arrow types. */ public class LargeUtf8AvaticaParameterConverter extends BaseAvaticaParameterConverter { - public LargeUtf8AvaticaParameterConverter(ArrowType.LargeUtf8 type) { - } + public LargeUtf8AvaticaParameterConverter(ArrowType.LargeUtf8 type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/ListAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/ListAvaticaParameterConverter.java index f6cb9f3be2a..6645fdcfd3c 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/ListAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/ListAvaticaParameterConverter.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc.converter.impl; import java.util.List; - import org.apache.arrow.driver.jdbc.utils.AvaticaParameterBinder; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.complex.ListVector; @@ -27,13 +26,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for List Arrow types. - */ +/** AvaticaParameterConverter for List Arrow types. */ public class ListAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public ListAvaticaParameterConverter(ArrowType.List type) { - } + public ListAvaticaParameterConverter(ArrowType.List type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { @@ -54,9 +50,12 @@ public boolean bindParameter(FieldVector vector, TypedValue typedValue, int inde throw new UnsupportedOperationException("Can't set null on non-nullable child list"); } } else { - childVector.getField().getType().accept( + childVector + .getField() + .getType() + .accept( new AvaticaParameterBinder.BinderVisitor( - childVector, TypedValue.ofSerial(typedValue.componentType, val), childIndex)); + childVector, TypedValue.ofSerial(typedValue.componentType, val), childIndex)); } } listVector.endValue(index, values.size()); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/MapAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/MapAvaticaParameterConverter.java index feac3794d22..c0e1d984606 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/MapAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/MapAvaticaParameterConverter.java @@ -23,13 +23,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Map Arrow types. - */ +/** AvaticaParameterConverter for Map Arrow types. */ public class MapAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public MapAvaticaParameterConverter(ArrowType.Map type) { - } + public MapAvaticaParameterConverter(ArrowType.Map type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/NullAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/NullAvaticaParameterConverter.java index e2c184fb11a..f41ac055752 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/NullAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/NullAvaticaParameterConverter.java @@ -24,19 +24,18 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Null Arrow types. - */ +/** AvaticaParameterConverter for Null Arrow types. */ public class NullAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public NullAvaticaParameterConverter(ArrowType.Null type) { - } + public NullAvaticaParameterConverter(ArrowType.Null type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { Object value = typedValue.toLocal(); if (vector instanceof NullVector) { - if (value != null) { throw new RuntimeException("Can't set non-null value on NullVector"); } + if (value != null) { + throw new RuntimeException("Can't set non-null value on NullVector"); + } vector.setNull(index); } return false; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/StructAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/StructAvaticaParameterConverter.java index 5dfe923cb51..8bcc365d493 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/StructAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/StructAvaticaParameterConverter.java @@ -23,13 +23,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Struct Arrow types. - */ +/** AvaticaParameterConverter for Struct Arrow types. */ public class StructAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public StructAvaticaParameterConverter(ArrowType.Struct type) { - } + public StructAvaticaParameterConverter(ArrowType.Struct type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimeAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimeAvaticaParameterConverter.java index c6b79537fd4..80887d2f897 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimeAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimeAvaticaParameterConverter.java @@ -27,13 +27,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Time Arrow types. - */ +/** AvaticaParameterConverter for Time Arrow types. */ public class TimeAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public TimeAvaticaParameterConverter(ArrowType.Time type) { - } + public TimeAvaticaParameterConverter(ArrowType.Time type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimestampAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimestampAvaticaParameterConverter.java index eb3316a1bdb..7e0edb27023 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimestampAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/TimestampAvaticaParameterConverter.java @@ -31,13 +31,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Timestamp Arrow types. - */ +/** AvaticaParameterConverter for Timestamp Arrow types. */ public class TimestampAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public TimestampAvaticaParameterConverter(ArrowType.Timestamp type) { - } + public TimestampAvaticaParameterConverter(ArrowType.Timestamp type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/UnionAvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/UnionAvaticaParameterConverter.java index 6b171e68557..eefd42216d7 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/UnionAvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/UnionAvaticaParameterConverter.java @@ -23,13 +23,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Union Arrow types. - */ +/** AvaticaParameterConverter for Union Arrow types. */ public class UnionAvaticaParameterConverter extends BaseAvaticaParameterConverter { - public UnionAvaticaParameterConverter(ArrowType.Union type) { - } + public UnionAvaticaParameterConverter(ArrowType.Union type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/Utf8AvaticaParameterConverter.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/Utf8AvaticaParameterConverter.java index 9223e5361d2..4ef67ea5e89 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/Utf8AvaticaParameterConverter.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/converter/impl/Utf8AvaticaParameterConverter.java @@ -25,13 +25,10 @@ import org.apache.calcite.avatica.AvaticaParameter; import org.apache.calcite.avatica.remote.TypedValue; -/** - * AvaticaParameterConverter for Utf8 Arrow types. - */ +/** AvaticaParameterConverter for Utf8 Arrow types. */ public class Utf8AvaticaParameterConverter extends BaseAvaticaParameterConverter { - public Utf8AvaticaParameterConverter(ArrowType.Utf8 type) { - } + public Utf8AvaticaParameterConverter(ArrowType.Utf8 type) {} @Override public boolean bindParameter(FieldVector vector, TypedValue typedValue, int index) { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java index 6237a8b58d6..aca7da0e144 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImpl.java @@ -22,7 +22,6 @@ import java.util.Map; import java.util.Objects; import java.util.Properties; - import org.apache.arrow.driver.jdbc.ArrowFlightConnection; import org.apache.arrow.flight.CallHeaders; import org.apache.arrow.flight.CallOption; @@ -33,9 +32,7 @@ import org.apache.calcite.avatica.ConnectionConfigImpl; import org.apache.calcite.avatica.ConnectionProperty; -/** - * A {@link ConnectionConfig} for the {@link ArrowFlightConnection}. - */ +/** A {@link ConnectionConfig} for the {@link ArrowFlightConnection}. */ public final class ArrowFlightConnectionConfigImpl extends ConnectionConfigImpl { public ArrowFlightConnectionConfigImpl(final Properties properties) { super(properties); @@ -77,7 +74,6 @@ public String getPassword() { return ArrowFlightConnectionProperty.PASSWORD.getString(properties); } - public String getToken() { return ArrowFlightConnectionProperty.TOKEN.getString(properties); } @@ -144,16 +140,16 @@ public int threadPoolSize() { } /** - * Indicates if sub-connections created for stream retrieval - * should reuse cookies from the main connection. + * Indicates if sub-connections created for stream retrieval should reuse cookies from the main + * connection. */ public boolean retainCookies() { return ArrowFlightConnectionProperty.RETAIN_COOKIES.getBoolean(properties); } /** - * Indicates if sub-connections created for stream retrieval - * should reuse bearer tokens created from the main connection. + * Indicates if sub-connections created for stream retrieval should reuse bearer tokens created + * from the main connection. */ public boolean retainAuth() { return ArrowFlightConnectionProperty.RETAIN_AUTH.getBoolean(properties); @@ -183,16 +179,15 @@ public Map getHeaderAttributes() { (key, val) -> { // For built-in properties before adding new headers if (Arrays.stream(builtInProperties) - .noneMatch(builtInProperty -> builtInProperty.camelName.equalsIgnoreCase(key.toString()))) { + .noneMatch( + builtInProperty -> builtInProperty.camelName.equalsIgnoreCase(key.toString()))) { headers.put(key.toString(), val.toString()); } }); return headers; } - /** - * Custom {@link ConnectionProperty} for the {@link ArrowFlightConnectionConfigImpl}. - */ + /** Custom {@link ConnectionProperty} for the {@link ArrowFlightConnectionConfigImpl}. */ public enum ArrowFlightConnectionProperty implements ConnectionProperty { HOST("host", null, Type.STRING, true), PORT("port", null, Type.NUMBER, true), @@ -216,8 +211,11 @@ public enum ArrowFlightConnectionProperty implements ConnectionProperty { private final Type type; private final boolean required; - ArrowFlightConnectionProperty(final String camelName, final Object defaultValue, - final Type type, final boolean required) { + ArrowFlightConnectionProperty( + final String camelName, + final Object defaultValue, + final Type type, + final boolean required) { this.camelName = Preconditions.checkNotNull(camelName); this.defaultValue = defaultValue; this.type = Preconditions.checkNotNull(type); @@ -238,7 +236,8 @@ public Object get(final Properties properties) { } if (required) { if (value == null) { - throw new IllegalStateException(String.format("Required property not provided: <%s>.", this)); + throw new IllegalStateException( + String.format("Required property not provided: <%s>.", this)); } return value; } else { diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/AvaticaParameterBinder.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/AvaticaParameterBinder.java index b2bd8e745ec..313be75566f 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/AvaticaParameterBinder.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/AvaticaParameterBinder.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc.utils; import java.util.List; - import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler.PreparedStatement; import org.apache.arrow.driver.jdbc.converter.impl.BinaryAvaticaParameterConverter; import org.apache.arrow.driver.jdbc.converter.impl.BoolAvaticaParameterConverter; @@ -48,22 +47,25 @@ import org.apache.calcite.avatica.remote.TypedValue; /** - * Convert Avatica PreparedStatement parameters from a list of TypedValue to Arrow and bind them to the - * VectorSchemaRoot representing the PreparedStatement parameters. - *

- * NOTE: Make sure to close the parameters VectorSchemaRoot once we're done with them. + * Convert Avatica PreparedStatement parameters from a list of TypedValue to Arrow and bind them to + * the VectorSchemaRoot representing the PreparedStatement parameters. + * + *

NOTE: Make sure to close the parameters VectorSchemaRoot once we're done with them. */ public class AvaticaParameterBinder { private final PreparedStatement preparedStatement; private final VectorSchemaRoot parameters; - public AvaticaParameterBinder(PreparedStatement preparedStatement, BufferAllocator bufferAllocator) { - this.parameters = VectorSchemaRoot.create(preparedStatement.getParameterSchema(), bufferAllocator); + public AvaticaParameterBinder( + PreparedStatement preparedStatement, BufferAllocator bufferAllocator) { + this.parameters = + VectorSchemaRoot.create(preparedStatement.getParameterSchema(), bufferAllocator); this.preparedStatement = preparedStatement; } /** * Bind the given Avatica values to the prepared statement. + * * @param typedValues The parameter values. */ public void bind(List typedValues) { @@ -72,15 +74,16 @@ public void bind(List typedValues) { /** * Bind the given Avatica values to the prepared statement at the given index. + * * @param typedValues The parameter values. * @param index index for parameter. */ public void bind(List typedValues, int index) { if (preparedStatement.getParameterSchema().getFields().size() != typedValues.size()) { throw new IllegalStateException( - String.format("Prepared statement has %s parameters, but only received %s", - preparedStatement.getParameterSchema().getFields().size(), - typedValues.size())); + String.format( + "Prepared statement has %s parameters, but only received %s", + preparedStatement.getParameterSchema().getFields().size(), typedValues.size())); } for (int i = 0; i < typedValues.size(); i++) { @@ -96,9 +99,9 @@ public void bind(List typedValues, int index) { /** * Bind a TypedValue to the given index on the FieldVector. * - * @param vector FieldVector to bind to. + * @param vector FieldVector to bind to. * @param typedValue TypedValue to bind to the vector. - * @param index Vector index to bind the value at. + * @param index Vector index to bind the value at. */ private void bind(FieldVector vector, TypedValue typedValue, int index) { try { @@ -108,19 +111,24 @@ private void bind(FieldVector vector, TypedValue typedValue, int index) { } else { throw new UnsupportedOperationException("Can't set null on non-nullable parameter"); } - } else if (!vector.getField().getType().accept(new BinderVisitor(vector, typedValue, index))) { + } else if (!vector + .getField() + .getType() + .accept(new BinderVisitor(vector, typedValue, index))) { throw new UnsupportedOperationException( - String.format("Binding to vector type %s is not yet supported", vector.getClass())); + String.format("Binding to vector type %s is not yet supported", vector.getClass())); } } catch (ClassCastException e) { throw new UnsupportedOperationException( - String.format("Binding value of type %s is not yet supported for expected Arrow type %s", - typedValue.type, vector.getField().getType())); + String.format( + "Binding value of type %s is not yet supported for expected Arrow type %s", + typedValue.type, vector.getField().getType())); } } /** - * ArrowTypeVisitor that binds Avatica TypedValues to the given FieldVector at the specified index. + * ArrowTypeVisitor that binds Avatica TypedValues to the given FieldVector at the specified + * index. */ public static class BinderVisitor implements ArrowType.ArrowTypeVisitor { private final FieldVector vector; @@ -162,7 +170,8 @@ public Boolean visit(ArrowType.LargeList type) { @Override public Boolean visit(ArrowType.FixedSizeList type) { - return new FixedSizeListAvaticaParameterConverter(type).bindParameter(vector, typedValue, index); + return new FixedSizeListAvaticaParameterConverter(type) + .bindParameter(vector, typedValue, index); } @Override @@ -182,7 +191,8 @@ public Boolean visit(ArrowType.Int type) { @Override public Boolean visit(ArrowType.FloatingPoint type) { - return new FloatingPointAvaticaParameterConverter(type).bindParameter(vector, typedValue, index); + return new FloatingPointAvaticaParameterConverter(type) + .bindParameter(vector, typedValue, index); } @Override @@ -202,12 +212,14 @@ public Boolean visit(ArrowType.Binary type) { @Override public Boolean visit(ArrowType.LargeBinary type) { - return new LargeBinaryAvaticaParameterConverter(type).bindParameter(vector, typedValue, index); + return new LargeBinaryAvaticaParameterConverter(type) + .bindParameter(vector, typedValue, index); } @Override public Boolean visit(ArrowType.FixedSizeBinary type) { - return new FixedSizeBinaryAvaticaParameterConverter(type).bindParameter(vector, typedValue, index); + return new FixedSizeBinaryAvaticaParameterConverter(type) + .bindParameter(vector, typedValue, index); } @Override @@ -245,5 +257,4 @@ public Boolean visit(ArrowType.Duration type) { return new DurationAvaticaParameterConverter(type).bindParameter(vector, typedValue, index); } } - } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapper.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapper.java index 5ee43ce012e..eba34cc5b27 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapper.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapper.java @@ -37,7 +37,6 @@ import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; - import org.apache.arrow.driver.jdbc.ArrowFlightJdbcPooledConnection; /** @@ -162,15 +161,15 @@ public Statement createStatement(final int resultSetTypeId, final int resultSetC } @Override - public PreparedStatement prepareStatement(final String sqlQuery, final int resultSetTypeId, - final int resultSetConcurrencyId) + public PreparedStatement prepareStatement( + final String sqlQuery, final int resultSetTypeId, final int resultSetConcurrencyId) throws SQLException { return realConnection.prepareStatement(sqlQuery, resultSetTypeId, resultSetConcurrencyId); } @Override - public CallableStatement prepareCall(final String query, final int resultSetTypeId, - final int resultSetConcurrencyId) + public CallableStatement prepareCall( + final String query, final int resultSetTypeId, final int resultSetConcurrencyId) throws SQLException { return realConnection.prepareCall(query, resultSetTypeId, resultSetConcurrencyId); } @@ -216,29 +215,33 @@ public void releaseSavepoint(final Savepoint savepoint) throws SQLException { } @Override - public Statement createStatement(final int resultSetType, - final int resultSetConcurrency, - final int resultSetHoldability) throws SQLException { - return realConnection.createStatement(resultSetType, resultSetConcurrency, - resultSetHoldability); + public Statement createStatement( + final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) + throws SQLException { + return realConnection.createStatement( + resultSetType, resultSetConcurrency, resultSetHoldability); } @Override - public PreparedStatement prepareStatement(final String sqlQuery, - final int resultSetType, - final int resultSetConcurrency, - final int resultSetHoldability) throws SQLException { - return realConnection.prepareStatement(sqlQuery, resultSetType, resultSetConcurrency, - resultSetHoldability); + public PreparedStatement prepareStatement( + final String sqlQuery, + final int resultSetType, + final int resultSetConcurrency, + final int resultSetHoldability) + throws SQLException { + return realConnection.prepareStatement( + sqlQuery, resultSetType, resultSetConcurrency, resultSetHoldability); } @Override - public CallableStatement prepareCall(final String sqlQuery, - final int resultSetType, - final int resultSetConcurrency, - final int resultSetHoldability) throws SQLException { - return realConnection.prepareCall(sqlQuery, resultSetType, resultSetConcurrency, - resultSetHoldability); + public CallableStatement prepareCall( + final String sqlQuery, + final int resultSetType, + final int resultSetConcurrency, + final int resultSetHoldability) + throws SQLException { + return realConnection.prepareCall( + sqlQuery, resultSetType, resultSetConcurrency, resultSetHoldability); } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConvertUtils.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConvertUtils.java index b21b03340e9..73396714ecb 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConvertUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ConvertUtils.java @@ -21,7 +21,6 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.apache.arrow.driver.jdbc.converter.impl.BinaryAvaticaParameterConverter; import org.apache.arrow.driver.jdbc.converter.impl.BoolAvaticaParameterConverter; import org.apache.arrow.driver.jdbc.converter.impl.DateAvaticaParameterConverter; @@ -51,13 +50,10 @@ import org.apache.calcite.avatica.proto.Common; import org.apache.calcite.avatica.proto.Common.ColumnMetaData.Builder; -/** - * Convert objects between Arrow and Avatica. - */ +/** Convert objects between Arrow and Avatica. */ public final class ConvertUtils { - private ConvertUtils() { - } + private ConvertUtils() {} /** * Convert Fields To Column MetaData List functions. @@ -65,36 +61,42 @@ private ConvertUtils() { * @param fields list of {@link Field}. * @return list of {@link ColumnMetaData}. */ - public static List convertArrowFieldsToColumnMetaDataList(final List fields) { - return Stream.iterate(0, Math::incrementExact).limit(fields.size()) - .map(index -> { - final Field field = fields.get(index); - final ArrowType fieldType = field.getType(); - - final Builder builder = Common.ColumnMetaData.newBuilder() - .setOrdinal(index) - .setColumnName(field.getName()) - .setLabel(field.getName()); - - setOnColumnMetaDataBuilder(builder, field.getMetadata()); - - builder.setType(Common.AvaticaType.newBuilder() - .setId(SqlTypes.getSqlTypeIdFromArrowType(fieldType)) - .setName(SqlTypes.getSqlTypeNameFromArrowType(fieldType)) - .build()); - - return ColumnMetaData.fromProto(builder.build()); - }).collect(Collectors.toList()); + public static List convertArrowFieldsToColumnMetaDataList( + final List fields) { + return Stream.iterate(0, Math::incrementExact) + .limit(fields.size()) + .map( + index -> { + final Field field = fields.get(index); + final ArrowType fieldType = field.getType(); + + final Builder builder = + Common.ColumnMetaData.newBuilder() + .setOrdinal(index) + .setColumnName(field.getName()) + .setLabel(field.getName()); + + setOnColumnMetaDataBuilder(builder, field.getMetadata()); + + builder.setType( + Common.AvaticaType.newBuilder() + .setId(SqlTypes.getSqlTypeIdFromArrowType(fieldType)) + .setName(SqlTypes.getSqlTypeNameFromArrowType(fieldType)) + .build()); + + return ColumnMetaData.fromProto(builder.build()); + }) + .collect(Collectors.toList()); } /** * Set on Column MetaData Builder. * - * @param builder {@link Builder} + * @param builder {@link Builder} * @param metadataMap {@link Map} */ - public static void setOnColumnMetaDataBuilder(final Builder builder, - final Map metadataMap) { + public static void setOnColumnMetaDataBuilder( + final Builder builder, final Map metadataMap) { final FlightSqlColumnMetadata columnMetadata = new FlightSqlColumnMetadata(metadataMap); final String catalogName = columnMetadata.getCatalogName(); if (catalogName != null) { @@ -142,10 +144,11 @@ public static void setOnColumnMetaDataBuilder(final Builder builder, * @param fields list of {@link Field}. * @return list of {@link AvaticaParameter}. */ - public static List convertArrowFieldsToAvaticaParameters(final List fields) { + public static List convertArrowFieldsToAvaticaParameters( + final List fields) { return fields.stream() - .map(field -> field.getType().accept(new ConverterVisitor(field))) - .collect(Collectors.toList()); + .map(field -> field.getType().accept(new ConverterVisitor(field))) + .collect(Collectors.toList()); } private static class ConverterVisitor implements ArrowType.ArrowTypeVisitor { @@ -168,25 +171,21 @@ public AvaticaParameter visit(ArrowType.Struct type) { @Override public AvaticaParameter visit(ArrowType.List type) { return new ListAvaticaParameterConverter(type).createParameter(field); - } @Override public AvaticaParameter visit(ArrowType.LargeList type) { return new LargeListAvaticaParameterConverter(type).createParameter(field); - } @Override public AvaticaParameter visit(ArrowType.FixedSizeList type) { return new FixedSizeListAvaticaParameterConverter(type).createParameter(field); - } @Override public AvaticaParameter visit(ArrowType.Union type) { return new UnionAvaticaParameterConverter(type).createParameter(field); - } @Override @@ -264,5 +263,4 @@ public AvaticaParameter visit(ArrowType.Duration type) { return new DurationAvaticaParameterConverter(type).createParameter(field); } } - } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/DateTimeUtils.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/DateTimeUtils.java index dd94a09256d..fe2f6ca788b 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/DateTimeUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/DateTimeUtils.java @@ -27,17 +27,13 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; -/** - * Datetime utility functions. - */ +/** Datetime utility functions. */ public class DateTimeUtils { private DateTimeUtils() { // Prevent instantiation. } - /** - * Subtracts given Calendar's TimeZone offset from epoch milliseconds. - */ + /** Subtracts given Calendar's TimeZone offset from epoch milliseconds. */ public static long applyCalendarOffset(long milliseconds, Calendar calendar) { if (calendar == null) { calendar = Calendar.getInstance(); @@ -53,7 +49,6 @@ public static long applyCalendarOffset(long milliseconds, Calendar calendar) { return milliseconds; } - /** * Converts Epoch millis to a {@link Timestamp} object. * @@ -70,7 +65,6 @@ public static Timestamp getTimestampValue(long millisWithCalendar) { return Timestamp.valueOf( LocalDateTime.of( LocalDate.ofEpochDay(millisWithCalendar / MILLIS_PER_DAY), - LocalTime.ofNanoOfDay(TimeUnit.MILLISECONDS.toNanos(milliseconds % MILLIS_PER_DAY))) - ); + LocalTime.ofNanoOfDay(TimeUnit.MILLISECONDS.toNanos(milliseconds % MILLIS_PER_DAY)))); } } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueue.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueue.java index 1198d89c40a..8d066e65ca2 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueue.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueue.java @@ -35,7 +35,6 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; - import org.apache.arrow.driver.jdbc.client.CloseableEndpointStreamPair; import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.FlightRuntimeException; @@ -46,27 +45,29 @@ /** * Auxiliary class used to handle consuming of multiple {@link FlightStream}. - *

- * The usage follows this routine: + * + *

The usage follows this routine: + * *

    - *
  1. Create a FlightStreamQueue;
  2. - *
  3. Call enqueue(FlightStream) for all streams to be consumed;
  4. - *
  5. Call next() to get a FlightStream that is ready to consume
  6. - *
  7. Consume the given FlightStream and add it back to the queue - call enqueue(FlightStream)
  8. - *
  9. Repeat from (3) until next() returns null.
  10. + *
  11. Create a FlightStreamQueue; + *
  12. Call enqueue(FlightStream) for all streams to be consumed; + *
  13. Call next() to get a FlightStream that is ready to consume + *
  14. Consume the given FlightStream and add it back to the queue - call + * enqueue(FlightStream) + *
  15. Repeat from (3) until next() returns null. *
*/ public class FlightEndpointDataQueue implements AutoCloseable { private static final Logger LOGGER = LoggerFactory.getLogger(FlightEndpointDataQueue.class); private final CompletionService completionService; private final Set> futures = synchronizedSet(new HashSet<>()); - private final Set endpointsToClose = synchronizedSet(new HashSet<>()); + private final Set endpointsToClose = + synchronizedSet(new HashSet<>()); private final AtomicBoolean closed = new AtomicBoolean(); - /** - * Instantiate a new FlightStreamQueue. - */ - protected FlightEndpointDataQueue(final CompletionService executorService) { + /** Instantiate a new FlightStreamQueue. */ + protected FlightEndpointDataQueue( + final CompletionService executorService) { completionService = checkNotNull(executorService); } @@ -89,15 +90,14 @@ public boolean isClosed() { return closed.get(); } - /** - * Auxiliary functional interface for getting ready-to-consume FlightStreams. - */ + /** Auxiliary functional interface for getting ready-to-consume FlightStreams. */ @FunctionalInterface interface EndpointStreamSupplier { Future get() throws SQLException; } - private CloseableEndpointStreamPair next(final EndpointStreamSupplier endpointStreamSupplier) throws SQLException { + private CloseableEndpointStreamPair next(final EndpointStreamSupplier endpointStreamSupplier) + throws SQLException { checkOpen(); while (!futures.isEmpty()) { final Future future = endpointStreamSupplier.get(); @@ -119,24 +119,26 @@ private CloseableEndpointStreamPair next(final EndpointStreamSupplier endpointSt * Blocking request with timeout to get the next ready FlightStream in queue. * * @param timeoutValue the amount of time to be waited - * @param timeoutUnit the timeoutValue time unit + * @param timeoutUnit the timeoutValue time unit * @return a FlightStream that is ready to consume or null if all FlightStreams are ended. */ public CloseableEndpointStreamPair next(final long timeoutValue, final TimeUnit timeoutUnit) throws SQLException { - return next(() -> { - try { - final Future future = completionService.poll(timeoutValue, timeoutUnit); - if (future != null) { - return future; - } - } catch (final InterruptedException e) { - throw new SQLTimeoutException("Query was interrupted", e); - } + return next( + () -> { + try { + final Future future = + completionService.poll(timeoutValue, timeoutUnit); + if (future != null) { + return future; + } + } catch (final InterruptedException e) { + throw new SQLTimeoutException("Query was interrupted", e); + } - throw new SQLTimeoutException( - String.format("Query timed out after %d %s", timeoutValue, timeoutUnit)); - }); + throw new SQLTimeoutException( + String.format("Query timed out after %d %s", timeoutValue, timeoutUnit)); + }); } /** @@ -145,50 +147,47 @@ public CloseableEndpointStreamPair next(final long timeoutValue, final TimeUnit * @return a FlightStream that is ready to consume or null if all FlightStreams are ended. */ public CloseableEndpointStreamPair next() throws SQLException { - return next(() -> { - try { - return completionService.take(); - } catch (final InterruptedException e) { - throw AvaticaConnection.HELPER.wrap(e.getMessage(), e); - } - }); + return next( + () -> { + try { + return completionService.take(); + } catch (final InterruptedException e) { + throw AvaticaConnection.HELPER.wrap(e.getMessage(), e); + } + }); } - /** - * Checks if this queue is open. - */ + /** Checks if this queue is open. */ public synchronized void checkOpen() { checkState(!isClosed(), format("%s closed", this.getClass().getSimpleName())); } - /** - * Readily adds given {@link FlightStream}s to the queue. - */ + /** Readily adds given {@link FlightStream}s to the queue. */ public void enqueue(final Collection endpointRequests) { endpointRequests.forEach(this::enqueue); } - /** - * Adds given {@link FlightStream} to the queue. - */ + /** Adds given {@link FlightStream} to the queue. */ public synchronized void enqueue(final CloseableEndpointStreamPair endpointRequest) { checkNotNull(endpointRequest); checkOpen(); endpointsToClose.add(endpointRequest); - futures.add(completionService.submit(() -> { - // `FlightStream#next` will block until new data can be read or stream is over. - while (endpointRequest.getStream().next()) { - if (endpointRequest.getStream().getRoot().getRowCount() > 0) { - return endpointRequest; - } - } - return null; - })); + futures.add( + completionService.submit( + () -> { + // `FlightStream#next` will block until new data can be read or stream is over. + while (endpointRequest.getStream().next()) { + if (endpointRequest.getStream().getRoot().getRowCount() > 0) { + return endpointRequest; + } + } + return null; + })); } private static boolean isCallStatusCancelled(final Exception e) { - return e.getCause() instanceof FlightRuntimeException && - ((FlightRuntimeException) e.getCause()).status().code() == CallStatus.CANCELLED.code(); + return e.getCause() instanceof FlightRuntimeException + && ((FlightRuntimeException) e.getCause()).status().code() == CallStatus.CANCELLED.code(); } @Override @@ -208,19 +207,20 @@ public synchronized void close() throws SQLException { exceptions.add(new SQLException(errorMsg, e)); } } - futures.forEach(future -> { - try { - // TODO: Consider adding a hardcoded timeout? - future.get(); - } catch (final InterruptedException | ExecutionException e) { - // Ignore if future is already cancelled - if (!isCallStatusCancelled(e)) { - final String errorMsg = "Failed consuming a future during close."; - LOGGER.error(errorMsg, e); - exceptions.add(new SQLException(errorMsg, e)); - } - } - }); + futures.forEach( + future -> { + try { + // TODO: Consider adding a hardcoded timeout? + future.get(); + } catch (final InterruptedException | ExecutionException e) { + // Ignore if future is already cancelled + if (!isCallStatusCancelled(e)) { + final String errorMsg = "Failed consuming a future during close."; + LOGGER.error(errorMsg, e); + exceptions.add(new SQLException(errorMsg, e)); + } + } + }); for (final CloseableEndpointStreamPair endpointToClose : endpointsToClose) { try { endpointToClose.close(); diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/IntervalStringUtils.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/IntervalStringUtils.java index fdf6c508d93..3757bb4eb48 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/IntervalStringUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/IntervalStringUtils.java @@ -19,23 +19,20 @@ import java.time.Duration; import java.time.Period; - import org.apache.arrow.vector.util.DateUtility; /** - * Utility class to format periods similar to Oracle's representation - * of "INTERVAL * to *" data type. + * Utility class to format periods similar to Oracle's representation of "INTERVAL * to *" data + * type. */ public final class IntervalStringUtils { - /** - * Constructor Method of class. - */ - private IntervalStringUtils( ) {} + /** Constructor Method of class. */ + private IntervalStringUtils() {} /** - * Formats a period similar to Oracle INTERVAL YEAR TO MONTH data type
. - * For example, the string "+21-02" defines an interval of 21 years and 2 months. + * Formats a period similar to Oracle INTERVAL YEAR TO MONTH data type
+ * . For example, the string "+21-02" defines an interval of 21 years and 2 months. */ public static String formatIntervalYear(final Period p) { long months = p.toTotalMonths(); @@ -51,9 +48,9 @@ public static String formatIntervalYear(final Period p) { } /** - * Formats a period similar to Oracle INTERVAL DAY TO SECOND data type.
. - * For example, the string "-001 18:25:16.766" defines an interval of - * - 1 day 18 hours 25 minutes 16 seconds and 766 milliseconds. + * Formats a period similar to Oracle INTERVAL DAY TO SECOND data type.
+ * . For example, the string "-001 18:25:16.766" defines an interval of - 1 day 18 hours 25 + * minutes 16 seconds and 766 milliseconds. */ public static String formatIntervalDay(final Duration d) { long millis = d.toMillis(); @@ -76,6 +73,7 @@ public static String formatIntervalDay(final Duration d) { final int seconds = (int) (millis / DateUtility.secondsToMillis); millis = millis % DateUtility.secondsToMillis; - return String.format("%c%03d %02d:%02d:%02d.%03d", neg ? '-' : '+', days, hours, minutes, seconds, millis); + return String.format( + "%c%03d %02d:%02d:%02d.%03d", neg ? '-' : '+', days, hours, minutes, seconds, millis); } } diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/SqlTypes.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/SqlTypes.java index 85c3964303c..3af95b13973 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/SqlTypes.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/SqlTypes.java @@ -20,13 +20,10 @@ import java.sql.Types; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.vector.types.FloatingPointPrecision; import org.apache.arrow.vector.types.pojo.ArrowType; -/** - * SQL Types utility functions. - */ +/** SQL Types utility functions. */ public class SqlTypes { private static final Map typeIdToName = new HashMap<>(); @@ -84,7 +81,6 @@ public static String getSqlTypeNameFromArrowType(ArrowType arrowType) { return typeIdToName.get(typeId); } - /** * Convert given {@link ArrowType} to its corresponding SQL type ID. * diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java index e52251f5391..44c13881d41 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/UrlParser.java @@ -22,12 +22,9 @@ import java.util.HashMap; import java.util.Map; -/** - * URL Parser for extracting key values from a connection string. - */ +/** URL Parser for extracting key values from a connection string. */ public final class UrlParser { - private UrlParser() { - } + private UrlParser() {} /** * Parse URL key value parameters. @@ -44,8 +41,10 @@ public static Map parse(String url, String separator) { for (String keyValue : keyValues) { try { - int separatorKey = keyValue.indexOf("="); // Find the first equal sign to split key and value. - if (separatorKey != -1) { // Avoid crashes when not finding an equal sign in the property value. + int separatorKey = + keyValue.indexOf("="); // Find the first equal sign to split key and value. + if (separatorKey + != -1) { // Avoid crashes when not finding an equal sign in the property value. String key = keyValue.substring(0, separatorKey); key = URLDecoder.decode(key, "UTF-8"); String value = ""; diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformer.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformer.java index 52a1d7db791..e24bf9f50a4 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformer.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformer.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.BaseFixedWidthVector; import org.apache.arrow.vector.BaseVariableWidthVector; @@ -32,17 +31,13 @@ import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.types.pojo.Schema; -/** - * Converts Arrow's {@link VectorSchemaRoot} format to one JDBC would expect. - */ +/** Converts Arrow's {@link VectorSchemaRoot} format to one JDBC would expect. */ @FunctionalInterface public interface VectorSchemaRootTransformer { VectorSchemaRoot transform(VectorSchemaRoot originalRoot, VectorSchemaRoot transformedRoot) throws Exception; - /** - * Transformer's helper class; builds a new {@link VectorSchemaRoot}. - */ + /** Transformer's helper class; builds a new {@link VectorSchemaRoot}. */ class Builder { private final Schema schema; @@ -52,50 +47,57 @@ class Builder { public Builder(final Schema schema, final BufferAllocator bufferAllocator) { this.schema = schema; - this.bufferAllocator = bufferAllocator - .newChildAllocator("VectorSchemaRootTransformer", 0, bufferAllocator.getLimit()); + this.bufferAllocator = + bufferAllocator.newChildAllocator( + "VectorSchemaRootTransformer", 0, bufferAllocator.getLimit()); } /** - * Add task to transform a vector to a new vector renaming it. - * This also adds transformedVectorName to the transformed {@link VectorSchemaRoot} schema. + * Add task to transform a vector to a new vector renaming it. This also adds + * transformedVectorName to the transformed {@link VectorSchemaRoot} schema. * - * @param originalVectorName Name of the original vector to be transformed. + * @param originalVectorName Name of the original vector to be transformed. * @param transformedVectorName Name of the vector that is the result of the transformation. * @return a VectorSchemaRoot instance with a task to rename a field vector. */ - public Builder renameFieldVector(final String originalVectorName, - final String transformedVectorName) { - tasks.add((originalRoot, transformedRoot) -> { - final FieldVector originalVector = originalRoot.getVector(originalVectorName); - final FieldVector transformedVector = transformedRoot.getVector(transformedVectorName); - - final ArrowType originalType = originalVector.getField().getType(); - final ArrowType transformedType = transformedVector.getField().getType(); - if (!originalType.equals(transformedType)) { - throw new IllegalArgumentException(String.format( - "Cannot transfer vector with field type %s to %s", originalType, transformedType)); - } - - if (originalVector instanceof BaseVariableWidthVector) { - ((BaseVariableWidthVector) originalVector).transferTo( - ((BaseVariableWidthVector) transformedVector)); - } else if (originalVector instanceof BaseFixedWidthVector) { - ((BaseFixedWidthVector) originalVector).transferTo( - ((BaseFixedWidthVector) transformedVector)); - } else { - throw new IllegalStateException(String.format( - "Cannot transfer vector of type %s", originalVector.getClass())); - } - }); + public Builder renameFieldVector( + final String originalVectorName, final String transformedVectorName) { + tasks.add( + (originalRoot, transformedRoot) -> { + final FieldVector originalVector = originalRoot.getVector(originalVectorName); + final FieldVector transformedVector = transformedRoot.getVector(transformedVectorName); + + final ArrowType originalType = originalVector.getField().getType(); + final ArrowType transformedType = transformedVector.getField().getType(); + if (!originalType.equals(transformedType)) { + throw new IllegalArgumentException( + String.format( + "Cannot transfer vector with field type %s to %s", + originalType, transformedType)); + } + + if (originalVector instanceof BaseVariableWidthVector) { + ((BaseVariableWidthVector) originalVector) + .transferTo(((BaseVariableWidthVector) transformedVector)); + } else if (originalVector instanceof BaseFixedWidthVector) { + ((BaseFixedWidthVector) originalVector) + .transferTo(((BaseFixedWidthVector) transformedVector)); + } else { + throw new IllegalStateException( + String.format("Cannot transfer vector of type %s", originalVector.getClass())); + } + }); final Field originalField = schema.findField(originalVectorName); - newFields.add(new Field( - transformedVectorName, - new FieldType(originalField.isNullable(), originalField.getType(), - originalField.getDictionary(), originalField.getMetadata()), - originalField.getChildren()) - ); + newFields.add( + new Field( + transformedVectorName, + new FieldType( + originalField.isNullable(), + originalField.getType(), + originalField.getDictionary(), + originalField.getMetadata()), + originalField.getChildren())); return this; } @@ -144,7 +146,8 @@ public VectorSchemaRootTransformer build() { } /** - * Functional interface used to a task to transform a VectorSchemaRoot into a new VectorSchemaRoot. + * Functional interface used to a task to transform a VectorSchemaRoot into a new + * VectorSchemaRoot. */ @FunctionalInterface interface Task { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadataTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadataTest.java index 0d930f4c44e..46bfe71975e 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadataTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadataTest.java @@ -33,6 +33,9 @@ import static org.apache.arrow.flight.sql.impl.FlightSql.SqlSupportsConvert.SQL_CONVERT_INTEGER_VALUE; import static org.hamcrest.CoreMatchers.is; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.protobuf.Message; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; @@ -45,7 +48,6 @@ import java.util.Map; import java.util.Objects; import java.util.function.Consumer; - import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; import org.apache.arrow.driver.jdbc.utils.ResultSetTestUtils; import org.apache.arrow.driver.jdbc.utils.ThrowableAssertionUtils; @@ -84,20 +86,16 @@ import org.junit.Test; import org.junit.rules.ErrorCollector; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.protobuf.Message; - -/** - * Class containing the tests from the {@link ArrowDatabaseMetadata}. - */ +/** Class containing the tests from the {@link ArrowDatabaseMetadata}. */ @SuppressWarnings("DoubleBraceInitialization") public class ArrowDatabaseMetadataTest { public static final boolean EXPECTED_MAX_ROW_SIZE_INCLUDES_BLOBS = false; private static final MockFlightSqlProducer FLIGHT_SQL_PRODUCER = new MockFlightSqlProducer(); + @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = FlightServerTestRule - .createStandardTestRule(FLIGHT_SQL_PRODUCER); + public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = + FlightServerTestRule.createStandardTestRule(FLIGHT_SQL_PRODUCER); + private static final int ROW_COUNT = 10; private static final List> EXPECTED_GET_CATALOGS_RESULTS = range(0, ROW_COUNT) @@ -113,61 +111,85 @@ public class ArrowDatabaseMetadataTest { .collect(toList()); private static final List> EXPECTED_GET_TABLES_RESULTS = range(0, ROW_COUNT) - .mapToObj(i -> new Object[] { - format("catalog_name #%d", i), - format("db_schema_name #%d", i), - format("table_name #%d", i), - format("table_type #%d", i), - // TODO Add these fields to FlightSQL, as it's currently not possible to fetch them. - null, null, null, null, null, null}) + .mapToObj( + i -> + new Object[] { + format("catalog_name #%d", i), + format("db_schema_name #%d", i), + format("table_name #%d", i), + format("table_type #%d", i), + // TODO Add these fields to FlightSQL, as it's currently not possible to fetch + // them. + null, + null, + null, + null, + null, + null + }) .map(Arrays::asList) .collect(toList()); private static final List> EXPECTED_GET_SCHEMAS_RESULTS = range(0, ROW_COUNT) - .mapToObj(i -> new Object[] { - format("db_schema_name #%d", i), - format("catalog_name #%d", i)}) + .mapToObj( + i -> new Object[] {format("db_schema_name #%d", i), format("catalog_name #%d", i)}) .map(Arrays::asList) .collect(toList()); private static final List> EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS = range(0, ROW_COUNT) - .mapToObj(i -> new Object[] { - format("pk_catalog_name #%d", i), - format("pk_db_schema_name #%d", i), - format("pk_table_name #%d", i), - format("pk_column_name #%d", i), - format("fk_catalog_name #%d", i), - format("fk_db_schema_name #%d", i), - format("fk_table_name #%d", i), - format("fk_column_name #%d", i), - i, - format("fk_key_name #%d", i), - format("pk_key_name #%d", i), - (byte) i, - (byte) i, - // TODO Add this field to FlightSQL, as it's currently not possible to fetch it. - null}) + .mapToObj( + i -> + new Object[] { + format("pk_catalog_name #%d", i), + format("pk_db_schema_name #%d", i), + format("pk_table_name #%d", i), + format("pk_column_name #%d", i), + format("fk_catalog_name #%d", i), + format("fk_db_schema_name #%d", i), + format("fk_table_name #%d", i), + format("fk_column_name #%d", i), + i, + format("fk_key_name #%d", i), + format("pk_key_name #%d", i), + (byte) i, + (byte) i, + // TODO Add this field to FlightSQL, as it's currently not possible to fetch it. + null + }) .map(Arrays::asList) .collect(toList()); private static final List> EXPECTED_CROSS_REFERENCE_RESULTS = EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS; private static final List> EXPECTED_PRIMARY_KEYS_RESULTS = range(0, ROW_COUNT) - .mapToObj(i -> new Object[] { - format("catalog_name #%d", i), - format("db_schema_name #%d", i), - format("table_name #%d", i), - format("column_name #%d", i), - i, - format("key_name #%d", i)}) + .mapToObj( + i -> + new Object[] { + format("catalog_name #%d", i), + format("db_schema_name #%d", i), + format("table_name #%d", i), + format("column_name #%d", i), + i, + format("key_name #%d", i) + }) .map(Arrays::asList) .collect(toList()); - private static final List FIELDS_GET_IMPORTED_EXPORTED_KEYS = ImmutableList.of( - "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME", - "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM", - "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ", - "FK_NAME", "PK_NAME", "UPDATE_RULE", "DELETE_RULE", - "DEFERRABILITY"); + private static final List FIELDS_GET_IMPORTED_EXPORTED_KEYS = + ImmutableList.of( + "PKTABLE_CAT", + "PKTABLE_SCHEM", + "PKTABLE_NAME", + "PKCOLUMN_NAME", + "FKTABLE_CAT", + "FKTABLE_SCHEM", + "FKTABLE_NAME", + "FKCOLUMN_NAME", + "KEY_SEQ", + "FK_NAME", + "PK_NAME", + "UPDATE_RULE", + "DELETE_RULE", + "DEFERRABILITY"); private static final List FIELDS_GET_CROSS_REFERENCE = FIELDS_GET_IMPORTED_EXPORTED_KEYS; private static final String TARGET_TABLE = "TARGET_TABLE"; private static final String TARGET_FOREIGN_TABLE = "FOREIGN_TABLE"; @@ -229,8 +251,8 @@ public class ArrowDatabaseMetadataTest { private static final boolean EXPECTED_SUBQUERIES_IN_EXISTS = false; private static final boolean EXPECTED_SUBQUERIES_IN_INS = false; private static final boolean EXPECTED_SUBQUERIES_IN_QUANTIFIEDS = false; - private static final SqlSupportedSubqueries[] EXPECTED_SUPPORTED_SUBQUERIES = new SqlSupportedSubqueries[] - {SqlSupportedSubqueries.SQL_SUBQUERIES_IN_COMPARISONS}; + private static final SqlSupportedSubqueries[] EXPECTED_SUPPORTED_SUBQUERIES = + new SqlSupportedSubqueries[] {SqlSupportedSubqueries.SQL_SUBQUERIES_IN_COMPARISONS}; private static final boolean EXPECTED_CORRELATED_SUBQUERIES_SUPPORTED = true; private static final boolean EXPECTED_SUPPORTS_UNION = true; private static final boolean EXPECTED_SUPPORTS_UNION_ALL = true; @@ -277,30 +299,41 @@ public class ArrowDatabaseMetadataTest { List expectedGetColumnsColumnSize = Arrays.asList(5, 29, 10); List expectedGetColumnsDecimalDigits = Arrays.asList(2, 9, 0); List expectedGetColumnsIsNullable = Arrays.asList("YES", "YES", "NO"); - EXPECTED_GET_COLUMNS_RESULTS = range(0, ROW_COUNT * 3) - .mapToObj(i -> new Object[] { - format("catalog_name #%d", i / 3), - format("db_schema_name #%d", i / 3), - format("table_name%d", i / 3), - format("column_%d", (i % 3) + 1), - expectedGetColumnsDataTypes.get(i % 3), - expectedGetColumnsTypeName.get(i % 3), - expectedGetColumnsColumnSize.get(i % 3), - null, - expectedGetColumnsDecimalDigits.get(i % 3), - expectedGetColumnsRadix.get(i % 3), - !Objects.equals(expectedGetColumnsIsNullable.get(i % 3), "NO") ? 1 : 0, - null, null, null, null, null, - (i % 3) + 1, - expectedGetColumnsIsNullable.get(i % 3), - null, null, null, null, - "", ""}) - .map(Arrays::asList) - .collect(toList()); + EXPECTED_GET_COLUMNS_RESULTS = + range(0, ROW_COUNT * 3) + .mapToObj( + i -> + new Object[] { + format("catalog_name #%d", i / 3), + format("db_schema_name #%d", i / 3), + format("table_name%d", i / 3), + format("column_%d", (i % 3) + 1), + expectedGetColumnsDataTypes.get(i % 3), + expectedGetColumnsTypeName.get(i % 3), + expectedGetColumnsColumnSize.get(i % 3), + null, + expectedGetColumnsDecimalDigits.get(i % 3), + expectedGetColumnsRadix.get(i % 3), + !Objects.equals(expectedGetColumnsIsNullable.get(i % 3), "NO") ? 1 : 0, + null, + null, + null, + null, + null, + (i % 3) + 1, + expectedGetColumnsIsNullable.get(i % 3), + null, + null, + null, + null, + "", + "" + }) + .map(Arrays::asList) + .collect(toList()); } - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); public final ResultSetTestUtils resultSetTestUtils = new ResultSetTestUtils(collector); @BeforeClass @@ -308,140 +341,149 @@ public static void setUpBeforeClass() throws SQLException { connection = FLIGHT_SERVER_TEST_RULE.getConnection(false); final Message commandGetCatalogs = CommandGetCatalogs.getDefaultInstance(); - final Consumer commandGetCatalogsResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_CATALOGS_SCHEMA, - allocator)) { - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - range(0, ROW_COUNT).forEach( - i -> catalogName.setSafe(i, new Text(format("catalog #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetCatalogsResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_CATALOGS_SCHEMA, allocator)) { + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + range(0, ROW_COUNT) + .forEach(i -> catalogName.setSafe(i, new Text(format("catalog #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetCatalogs, commandGetCatalogsResultProducer); final Message commandGetTableTypes = CommandGetTableTypes.getDefaultInstance(); - final Consumer commandGetTableTypesResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_TABLE_TYPES_SCHEMA, - allocator)) { - final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); - range(0, ROW_COUNT).forEach( - i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetTableTypesResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TABLE_TYPES_SCHEMA, allocator)) { + final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); + range(0, ROW_COUNT) + .forEach(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetTableTypes, commandGetTableTypesResultProducer); final Message commandGetTables = CommandGetTables.getDefaultInstance(); - final Consumer commandGetTablesResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create( - Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, allocator)) { - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); - final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); - final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); - range(0, ROW_COUNT) - .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) - .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) - .peek(i -> tableName.setSafe(i, new Text(format("table_name #%d", i)))) - .forEach(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetTablesResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, allocator)) { + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); + final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); + final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); + range(0, ROW_COUNT) + .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) + .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) + .peek(i -> tableName.setSafe(i, new Text(format("table_name #%d", i)))) + .forEach(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetTables, commandGetTablesResultProducer); - final Message commandGetTablesWithSchema = CommandGetTables.newBuilder() - .setIncludeSchema(true) - .build(); - final Consumer commandGetTablesWithSchemaResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_TABLES_SCHEMA, - allocator)) { - final byte[] filledTableSchemaBytes = - copyFrom( - serializeSchema(new Schema(Arrays.asList( - Field.nullable("column_1", ArrowType.Decimal.createDecimal(5, 2, 128)), - Field.nullable("column_2", new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC")), - Field.notNullable("column_3", Types.MinorType.INT.getType()))))) - .toByteArray(); - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); - final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); - final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); - final VarBinaryVector tableSchema = (VarBinaryVector) root.getVector("table_schema"); - range(0, ROW_COUNT) - .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) - .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) - .peek(i -> tableName.setSafe(i, new Text(format("table_name%d", i)))) - .peek(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))) - .forEach(i -> tableSchema.setSafe(i, filledTableSchemaBytes)); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; - FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetTablesWithSchema, - commandGetTablesWithSchemaResultProducer); + final Message commandGetTablesWithSchema = + CommandGetTables.newBuilder().setIncludeSchema(true).build(); + final Consumer commandGetTablesWithSchemaResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TABLES_SCHEMA, allocator)) { + final byte[] filledTableSchemaBytes = + copyFrom( + serializeSchema( + new Schema( + Arrays.asList( + Field.nullable( + "column_1", ArrowType.Decimal.createDecimal(5, 2, 128)), + Field.nullable( + "column_2", + new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC")), + Field.notNullable("column_3", Types.MinorType.INT.getType()))))) + .toByteArray(); + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); + final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); + final VarCharVector tableType = (VarCharVector) root.getVector("table_type"); + final VarBinaryVector tableSchema = (VarBinaryVector) root.getVector("table_schema"); + range(0, ROW_COUNT) + .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) + .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) + .peek(i -> tableName.setSafe(i, new Text(format("table_name%d", i)))) + .peek(i -> tableType.setSafe(i, new Text(format("table_type #%d", i)))) + .forEach(i -> tableSchema.setSafe(i, filledTableSchemaBytes)); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; + FLIGHT_SQL_PRODUCER.addCatalogQuery( + commandGetTablesWithSchema, commandGetTablesWithSchemaResultProducer); final Message commandGetDbSchemas = CommandGetDbSchemas.getDefaultInstance(); - final Consumer commandGetSchemasResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_SCHEMAS_SCHEMA, - allocator)) { - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); - range(0, ROW_COUNT) - .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) - .forEach(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetSchemasResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_SCHEMAS_SCHEMA, allocator)) { + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); + range(0, ROW_COUNT) + .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) + .forEach(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetDbSchemas, commandGetSchemasResultProducer); final Message commandGetExportedKeys = CommandGetExportedKeys.newBuilder().setTable(TARGET_TABLE).build(); final Message commandGetImportedKeys = CommandGetImportedKeys.newBuilder().setTable(TARGET_TABLE).build(); - final Message commandGetCrossReference = CommandGetCrossReference.newBuilder() - .setPkTable(TARGET_TABLE) - .setFkTable(TARGET_FOREIGN_TABLE) - .build(); + final Message commandGetCrossReference = + CommandGetCrossReference.newBuilder() + .setPkTable(TARGET_TABLE) + .setFkTable(TARGET_FOREIGN_TABLE) + .build(); final Consumer commandGetExportedAndImportedKeysResultProducer = listener -> { try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create( - Schemas.GET_IMPORTED_KEYS_SCHEMA, - allocator)) { + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_IMPORTED_KEYS_SCHEMA, allocator)) { final VarCharVector pkCatalogName = (VarCharVector) root.getVector("pk_catalog_name"); final VarCharVector pkSchemaName = (VarCharVector) root.getVector("pk_db_schema_name"); final VarCharVector pkTableName = (VarCharVector) root.getVector("pk_table_name"); @@ -478,44 +520,46 @@ public static void setUpBeforeClass() throws SQLException { listener.completed(); } }; - FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetExportedKeys, - commandGetExportedAndImportedKeysResultProducer); - FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetImportedKeys, - commandGetExportedAndImportedKeysResultProducer); - FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetCrossReference, - commandGetExportedAndImportedKeysResultProducer); + FLIGHT_SQL_PRODUCER.addCatalogQuery( + commandGetExportedKeys, commandGetExportedAndImportedKeysResultProducer); + FLIGHT_SQL_PRODUCER.addCatalogQuery( + commandGetImportedKeys, commandGetExportedAndImportedKeysResultProducer); + FLIGHT_SQL_PRODUCER.addCatalogQuery( + commandGetCrossReference, commandGetExportedAndImportedKeysResultProducer); final Message commandGetPrimaryKeys = CommandGetPrimaryKeys.newBuilder().setTable(TARGET_TABLE).build(); - final Consumer commandGetPrimaryKeysResultProducer = listener -> { - try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_PRIMARY_KEYS_SCHEMA, - allocator)) { - final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); - final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); - final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); - final VarCharVector columnName = (VarCharVector) root.getVector("column_name"); - final IntVector keySequence = (IntVector) root.getVector("key_sequence"); - final VarCharVector keyName = (VarCharVector) root.getVector("key_name"); - range(0, ROW_COUNT) - .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) - .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) - .peek(i -> tableName.setSafe(i, new Text(format("table_name #%d", i)))) - .peek(i -> columnName.setSafe(i, new Text(format("column_name #%d", i)))) - .peek(i -> keySequence.setSafe(i, i)) - .forEach(i -> keyName.setSafe(i, new Text(format("key_name #%d", i)))); - root.setRowCount(ROW_COUNT); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - }; + final Consumer commandGetPrimaryKeysResultProducer = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(); + final VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_PRIMARY_KEYS_SCHEMA, allocator)) { + final VarCharVector catalogName = (VarCharVector) root.getVector("catalog_name"); + final VarCharVector schemaName = (VarCharVector) root.getVector("db_schema_name"); + final VarCharVector tableName = (VarCharVector) root.getVector("table_name"); + final VarCharVector columnName = (VarCharVector) root.getVector("column_name"); + final IntVector keySequence = (IntVector) root.getVector("key_sequence"); + final VarCharVector keyName = (VarCharVector) root.getVector("key_name"); + range(0, ROW_COUNT) + .peek(i -> catalogName.setSafe(i, new Text(format("catalog_name #%d", i)))) + .peek(i -> schemaName.setSafe(i, new Text(format("db_schema_name #%d", i)))) + .peek(i -> tableName.setSafe(i, new Text(format("table_name #%d", i)))) + .peek(i -> columnName.setSafe(i, new Text(format("column_name #%d", i)))) + .peek(i -> keySequence.setSafe(i, i)) + .forEach(i -> keyName.setSafe(i, new Text(format("key_name #%d", i)))); + root.setRowCount(ROW_COUNT); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + }; FLIGHT_SQL_PRODUCER.addCatalogQuery(commandGetPrimaryKeys, commandGetPrimaryKeysResultProducer); - FLIGHT_SQL_PRODUCER.getSqlInfoBuilder() + FLIGHT_SQL_PRODUCER + .getSqlInfoBuilder() .withSqlOuterJoinSupportLevel(FlightSql.SqlOuterJoinsSupportLevel.SQL_FULL_OUTER_JOINS) .withFlightSqlServerName(EXPECTED_DATABASE_PRODUCT_NAME) .withFlightSqlServerVersion(EXPECTED_DATABASE_PRODUCT_VERSION) @@ -530,8 +574,10 @@ public static void setUpBeforeClass() throws SQLException { .withSqlExtraNameCharacters(EXPECTED_EXTRA_NAME_CHARACTERS) .withSqlSupportsColumnAliasing(EXPECTED_SUPPORTS_COLUMN_ALIASING) .withSqlNullPlusNullIsNull(EXPECTED_NULL_PLUS_NULL_IS_NULL) - .withSqlSupportsConvert(ImmutableMap.of(SQL_CONVERT_BIT_VALUE, - Arrays.asList(SQL_CONVERT_INTEGER_VALUE, SQL_CONVERT_BIGINT_VALUE))) + .withSqlSupportsConvert( + ImmutableMap.of( + SQL_CONVERT_BIT_VALUE, + Arrays.asList(SQL_CONVERT_INTEGER_VALUE, SQL_CONVERT_BIGINT_VALUE))) .withSqlSupportsTableCorrelationNames(EXPECTED_SUPPORTS_TABLE_CORRELATION_NAMES) .withSqlSupportsDifferentTableCorrelationNames( EXPECTED_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES) @@ -540,9 +586,11 @@ public static void setUpBeforeClass() throws SQLException { .withSqlSupportedGroupBy(FlightSql.SqlSupportedGroupBy.SQL_GROUP_BY_UNRELATED) .withSqlSupportsLikeEscapeClause(EXPECTED_SUPPORTS_LIKE_ESCAPE_CLAUSE) .withSqlSupportsNonNullableColumns(EXPECTED_NON_NULLABLE_COLUMNS) - .withSqlSupportedGrammar(FlightSql.SupportedSqlGrammar.SQL_CORE_GRAMMAR, + .withSqlSupportedGrammar( + FlightSql.SupportedSqlGrammar.SQL_CORE_GRAMMAR, FlightSql.SupportedSqlGrammar.SQL_MINIMUM_GRAMMAR) - .withSqlAnsi92SupportedLevel(FlightSql.SupportedAnsi92SqlGrammarLevel.ANSI92_ENTRY_SQL, + .withSqlAnsi92SupportedLevel( + FlightSql.SupportedAnsi92SqlGrammarLevel.ANSI92_ENTRY_SQL, FlightSql.SupportedAnsi92SqlGrammarLevel.ANSI92_INTERMEDIATE_SQL) .withSqlSupportsIntegrityEnhancementFacility( EXPECTED_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY) @@ -607,7 +655,6 @@ public static void tearDown() throws Exception { AutoCloseables.close(connection, FLIGHT_SQL_PRODUCER); } - @Test public void testGetCatalogsCanBeAccessedByIndices() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getCatalogs()) { @@ -618,8 +665,8 @@ public void testGetCatalogsCanBeAccessedByIndices() throws SQLException { @Test public void testGetCatalogsCanBeAccessedByNames() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getCatalogs()) { - resultSetTestUtils.testData(resultSet, singletonList("TABLE_CAT"), - EXPECTED_GET_CATALOGS_RESULTS); + resultSetTestUtils.testData( + resultSet, singletonList("TABLE_CAT"), EXPECTED_GET_CATALOGS_RESULTS); } } @@ -633,8 +680,8 @@ public void testTableTypesCanBeAccessedByIndices() throws SQLException { @Test public void testTableTypesCanBeAccessedByNames() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getTableTypes()) { - resultSetTestUtils.testData(resultSet, singletonList("TABLE_TYPE"), - EXPECTED_GET_TABLE_TYPES_RESULTS); + resultSetTestUtils.testData( + resultSet, singletonList("TABLE_TYPE"), EXPECTED_GET_TABLE_TYPES_RESULTS); } } @@ -661,8 +708,7 @@ public void testGetTablesCanBeAccessedByNames() throws SQLException { "TYPE_NAME", "SELF_REFERENCING_COL_NAME", "REF_GENERATION"), - EXPECTED_GET_TABLES_RESULTS - ); + EXPECTED_GET_TABLES_RESULTS); } } @@ -676,59 +722,67 @@ public void testGetSchemasCanBeAccessedByIndices() throws SQLException { @Test public void testGetSchemasCanBeAccessedByNames() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getSchemas()) { - resultSetTestUtils.testData(resultSet, ImmutableList.of("TABLE_SCHEM", "TABLE_CATALOG"), + resultSetTestUtils.testData( + resultSet, + ImmutableList.of("TABLE_SCHEM", "TABLE_CATALOG"), EXPECTED_GET_SCHEMAS_RESULTS); } } @Test public void testGetExportedKeysCanBeAccessedByIndices() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getExportedKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getExportedKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData(resultSet, EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS); } } @Test public void testGetExportedKeysCanBeAccessedByNames() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getExportedKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getExportedKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData( - resultSet, FIELDS_GET_IMPORTED_EXPORTED_KEYS, + resultSet, + FIELDS_GET_IMPORTED_EXPORTED_KEYS, EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS); } } @Test public void testGetImportedKeysCanBeAccessedByIndices() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getImportedKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getImportedKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData(resultSet, EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS); } } @Test public void testGetImportedKeysCanBeAccessedByNames() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getImportedKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getImportedKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData( - resultSet, FIELDS_GET_IMPORTED_EXPORTED_KEYS, + resultSet, + FIELDS_GET_IMPORTED_EXPORTED_KEYS, EXPECTED_GET_EXPORTED_AND_IMPORTED_KEYS_RESULTS); } } @Test public void testGetCrossReferenceCanBeAccessedByIndices() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData().getCrossReference(null, null, - TARGET_TABLE, null, null, TARGET_FOREIGN_TABLE)) { + try (final ResultSet resultSet = + connection + .getMetaData() + .getCrossReference(null, null, TARGET_TABLE, null, null, TARGET_FOREIGN_TABLE)) { resultSetTestUtils.testData(resultSet, EXPECTED_CROSS_REFERENCE_RESULTS); } } @Test public void testGetGetCrossReferenceCanBeAccessedByNames() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData().getCrossReference(null, null, - TARGET_TABLE, null, null, TARGET_FOREIGN_TABLE)) { + try (final ResultSet resultSet = + connection + .getMetaData() + .getCrossReference(null, null, TARGET_TABLE, null, null, TARGET_FOREIGN_TABLE)) { resultSetTestUtils.testData( resultSet, FIELDS_GET_CROSS_REFERENCE, EXPECTED_CROSS_REFERENCE_RESULTS); } @@ -736,27 +790,21 @@ public void testGetGetCrossReferenceCanBeAccessedByNames() throws SQLException { @Test public void testPrimaryKeysCanBeAccessedByIndices() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getPrimaryKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getPrimaryKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData(resultSet, EXPECTED_PRIMARY_KEYS_RESULTS); } } @Test public void testPrimaryKeysCanBeAccessedByNames() throws SQLException { - try (final ResultSet resultSet = connection.getMetaData() - .getPrimaryKeys(null, null, TARGET_TABLE)) { + try (final ResultSet resultSet = + connection.getMetaData().getPrimaryKeys(null, null, TARGET_TABLE)) { resultSetTestUtils.testData( resultSet, ImmutableList.of( - "TABLE_CAT", - "TABLE_SCHEM", - "TABLE_NAME", - "COLUMN_NAME", - "KEY_SEQ", - "PK_NAME"), - EXPECTED_PRIMARY_KEYS_RESULTS - ); + "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "KEY_SEQ", "PK_NAME"), + EXPECTED_PRIMARY_KEYS_RESULTS); } } @@ -769,14 +817,13 @@ public void testGetColumnsCanBeAccessedByIndices() throws SQLException { @Test public void testGetColumnsCanByIndicesFilteringColumnNames() throws SQLException { - try ( - final ResultSet resultSet = connection.getMetaData() - .getColumns(null, null, null, "column_1")) { - resultSetTestUtils.testData(resultSet, EXPECTED_GET_COLUMNS_RESULTS - .stream() - .filter(insideList -> Objects.equals(insideList.get(3), "column_1")) - .collect(toList()) - ); + try (final ResultSet resultSet = + connection.getMetaData().getColumns(null, null, null, "column_1")) { + resultSetTestUtils.testData( + resultSet, + EXPECTED_GET_COLUMNS_RESULTS.stream() + .filter(insideList -> Objects.equals(insideList.get(3), "column_1")) + .collect(toList())); } } @@ -784,8 +831,8 @@ public void testGetColumnsCanByIndicesFilteringColumnNames() throws SQLException public void testGetSqlInfo() throws SQLException { final DatabaseMetaData metaData = connection.getMetaData(); collector.checkThat(metaData.getDatabaseProductName(), is(EXPECTED_DATABASE_PRODUCT_NAME)); - collector.checkThat(metaData.getDatabaseProductVersion(), - is(EXPECTED_DATABASE_PRODUCT_VERSION)); + collector.checkThat( + metaData.getDatabaseProductVersion(), is(EXPECTED_DATABASE_PRODUCT_VERSION)); collector.checkThat(metaData.getIdentifierQuoteString(), is(EXPECTED_IDENTIFIER_QUOTE_STRING)); collector.checkThat(metaData.isReadOnly(), is(EXPECTED_IS_READ_ONLY)); collector.checkThat(metaData.getSQLKeywords(), is(EXPECTED_SQL_KEYWORDS)); @@ -798,29 +845,29 @@ public void testGetSqlInfo() throws SQLException { collector.checkThat(metaData.supportsConvert(), is(EXPECTED_SQL_SUPPORTS_CONVERT)); collector.checkThat(metaData.supportsConvert(BIT, INTEGER), is(EXPECTED_SQL_SUPPORTS_CONVERT)); collector.checkThat(metaData.supportsConvert(BIT, BIGINT), is(EXPECTED_SQL_SUPPORTS_CONVERT)); - collector.checkThat(metaData.supportsConvert(BIGINT, INTEGER), - is(EXPECTED_INVALID_SQL_SUPPORTS_CONVERT)); - collector.checkThat(metaData.supportsConvert(JAVA_OBJECT, INTEGER), - is(EXPECTED_INVALID_SQL_SUPPORTS_CONVERT)); - collector.checkThat(metaData.supportsTableCorrelationNames(), - is(EXPECTED_SUPPORTS_TABLE_CORRELATION_NAMES)); - collector.checkThat(metaData.supportsExpressionsInOrderBy(), - is(EXPECTED_EXPRESSIONS_IN_ORDER_BY)); - collector.checkThat(metaData.supportsOrderByUnrelated(), - is(EXPECTED_SUPPORTS_ORDER_BY_UNRELATED)); + collector.checkThat( + metaData.supportsConvert(BIGINT, INTEGER), is(EXPECTED_INVALID_SQL_SUPPORTS_CONVERT)); + collector.checkThat( + metaData.supportsConvert(JAVA_OBJECT, INTEGER), is(EXPECTED_INVALID_SQL_SUPPORTS_CONVERT)); + collector.checkThat( + metaData.supportsTableCorrelationNames(), is(EXPECTED_SUPPORTS_TABLE_CORRELATION_NAMES)); + collector.checkThat( + metaData.supportsExpressionsInOrderBy(), is(EXPECTED_EXPRESSIONS_IN_ORDER_BY)); + collector.checkThat( + metaData.supportsOrderByUnrelated(), is(EXPECTED_SUPPORTS_ORDER_BY_UNRELATED)); collector.checkThat(metaData.supportsGroupBy(), is(EXPECTED_SUPPORTS_GROUP_BY)); - collector.checkThat(metaData.supportsGroupByUnrelated(), - is(EXPECTED_SUPPORTS_GROUP_BY_UNRELATED)); - collector.checkThat(metaData.supportsLikeEscapeClause(), - is(EXPECTED_SUPPORTS_LIKE_ESCAPE_CLAUSE)); + collector.checkThat( + metaData.supportsGroupByUnrelated(), is(EXPECTED_SUPPORTS_GROUP_BY_UNRELATED)); + collector.checkThat( + metaData.supportsLikeEscapeClause(), is(EXPECTED_SUPPORTS_LIKE_ESCAPE_CLAUSE)); collector.checkThat(metaData.supportsNonNullableColumns(), is(EXPECTED_NON_NULLABLE_COLUMNS)); collector.checkThat(metaData.supportsMinimumSQLGrammar(), is(EXPECTED_MINIMUM_SQL_GRAMMAR)); collector.checkThat(metaData.supportsCoreSQLGrammar(), is(EXPECTED_CORE_SQL_GRAMMAR)); collector.checkThat(metaData.supportsExtendedSQLGrammar(), is(EXPECTED_EXTEND_SQL_GRAMMAR)); - collector.checkThat(metaData.supportsANSI92EntryLevelSQL(), - is(EXPECTED_ANSI92_ENTRY_LEVEL_SQL)); - collector.checkThat(metaData.supportsANSI92IntermediateSQL(), - is(EXPECTED_ANSI92_INTERMEDIATE_SQL)); + collector.checkThat( + metaData.supportsANSI92EntryLevelSQL(), is(EXPECTED_ANSI92_ENTRY_LEVEL_SQL)); + collector.checkThat( + metaData.supportsANSI92IntermediateSQL(), is(EXPECTED_ANSI92_INTERMEDIATE_SQL)); collector.checkThat(metaData.supportsANSI92FullSQL(), is(EXPECTED_ANSI92_FULL_SQL)); collector.checkThat(metaData.supportsOuterJoins(), is(EXPECTED_SUPPORTS_OUTER_JOINS)); collector.checkThat(metaData.supportsFullOuterJoins(), is(EXPECTED_SUPPORTS_FULL_OUTER_JOINS)); @@ -829,32 +876,33 @@ public void testGetSqlInfo() throws SQLException { collector.checkThat(metaData.getProcedureTerm(), is(EXPECTED_PROCEDURE_TERM)); collector.checkThat(metaData.getCatalogTerm(), is(EXPECTED_CATALOG_TERM)); collector.checkThat(metaData.isCatalogAtStart(), is(EXPECTED_CATALOG_AT_START)); - collector.checkThat(metaData.supportsSchemasInProcedureCalls(), - is(EXPECTED_SCHEMAS_IN_PROCEDURE_CALLS)); - collector.checkThat(metaData.supportsSchemasInIndexDefinitions(), - is(EXPECTED_SCHEMAS_IN_INDEX_DEFINITIONS)); - collector.checkThat(metaData.supportsCatalogsInIndexDefinitions(), - is(EXPECTED_CATALOGS_IN_INDEX_DEFINITIONS)); + collector.checkThat( + metaData.supportsSchemasInProcedureCalls(), is(EXPECTED_SCHEMAS_IN_PROCEDURE_CALLS)); + collector.checkThat( + metaData.supportsSchemasInIndexDefinitions(), is(EXPECTED_SCHEMAS_IN_INDEX_DEFINITIONS)); + collector.checkThat( + metaData.supportsCatalogsInIndexDefinitions(), is(EXPECTED_CATALOGS_IN_INDEX_DEFINITIONS)); collector.checkThat(metaData.supportsPositionedDelete(), is(EXPECTED_POSITIONED_DELETE)); collector.checkThat(metaData.supportsPositionedUpdate(), is(EXPECTED_POSITIONED_UPDATE)); - collector.checkThat(metaData.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY), + collector.checkThat( + metaData.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY), is(EXPECTED_TYPE_FORWARD_ONLY)); - collector.checkThat(metaData.supportsSelectForUpdate(), - is(EXPECTED_SELECT_FOR_UPDATE_SUPPORTED)); - collector.checkThat(metaData.supportsStoredProcedures(), - is(EXPECTED_STORED_PROCEDURES_SUPPORTED)); - collector.checkThat(metaData.supportsSubqueriesInComparisons(), - is(EXPECTED_SUBQUERIES_IN_COMPARISON)); + collector.checkThat( + metaData.supportsSelectForUpdate(), is(EXPECTED_SELECT_FOR_UPDATE_SUPPORTED)); + collector.checkThat( + metaData.supportsStoredProcedures(), is(EXPECTED_STORED_PROCEDURES_SUPPORTED)); + collector.checkThat( + metaData.supportsSubqueriesInComparisons(), is(EXPECTED_SUBQUERIES_IN_COMPARISON)); collector.checkThat(metaData.supportsSubqueriesInExists(), is(EXPECTED_SUBQUERIES_IN_EXISTS)); collector.checkThat(metaData.supportsSubqueriesInIns(), is(EXPECTED_SUBQUERIES_IN_INS)); - collector.checkThat(metaData.supportsSubqueriesInQuantifieds(), - is(EXPECTED_SUBQUERIES_IN_QUANTIFIEDS)); - collector.checkThat(metaData.supportsCorrelatedSubqueries(), - is(EXPECTED_CORRELATED_SUBQUERIES_SUPPORTED)); + collector.checkThat( + metaData.supportsSubqueriesInQuantifieds(), is(EXPECTED_SUBQUERIES_IN_QUANTIFIEDS)); + collector.checkThat( + metaData.supportsCorrelatedSubqueries(), is(EXPECTED_CORRELATED_SUBQUERIES_SUPPORTED)); collector.checkThat(metaData.supportsUnion(), is(EXPECTED_SUPPORTS_UNION)); collector.checkThat(metaData.supportsUnionAll(), is(EXPECTED_SUPPORTS_UNION_ALL)); - collector.checkThat(metaData.getMaxBinaryLiteralLength(), - is(EXPECTED_MAX_BINARY_LITERAL_LENGTH)); + collector.checkThat( + metaData.getMaxBinaryLiteralLength(), is(EXPECTED_MAX_BINARY_LITERAL_LENGTH)); collector.checkThat(metaData.getMaxCharLiteralLength(), is(EXPECTED_MAX_CHAR_LITERAL_LENGTH)); collector.checkThat(metaData.getMaxColumnsInGroupBy(), is(EXPECTED_MAX_COLUMNS_IN_GROUP_BY)); collector.checkThat(metaData.getMaxColumnsInIndex(), is(EXPECTED_MAX_COLUMNS_IN_INDEX)); @@ -864,35 +912,40 @@ public void testGetSqlInfo() throws SQLException { collector.checkThat(metaData.getMaxCursorNameLength(), is(EXPECTED_MAX_CURSOR_NAME_LENGTH)); collector.checkThat(metaData.getMaxIndexLength(), is(EXPECTED_MAX_INDEX_LENGTH)); collector.checkThat(metaData.getMaxSchemaNameLength(), is(EXPECTED_SCHEMA_NAME_LENGTH)); - collector.checkThat(metaData.getMaxProcedureNameLength(), - is(EXPECTED_MAX_PROCEDURE_NAME_LENGTH)); + collector.checkThat( + metaData.getMaxProcedureNameLength(), is(EXPECTED_MAX_PROCEDURE_NAME_LENGTH)); collector.checkThat(metaData.getMaxCatalogNameLength(), is(EXPECTED_MAX_CATALOG_NAME_LENGTH)); collector.checkThat(metaData.getMaxRowSize(), is(EXPECTED_MAX_ROW_SIZE)); - collector.checkThat(metaData.doesMaxRowSizeIncludeBlobs(), - is(EXPECTED_MAX_ROW_SIZE_INCLUDES_BLOBS)); + collector.checkThat( + metaData.doesMaxRowSizeIncludeBlobs(), is(EXPECTED_MAX_ROW_SIZE_INCLUDES_BLOBS)); collector.checkThat(metaData.getMaxStatementLength(), is(EXPECTED_MAX_STATEMENT_LENGTH)); collector.checkThat(metaData.getMaxStatements(), is(EXPECTED_MAX_STATEMENTS)); collector.checkThat(metaData.getMaxTableNameLength(), is(EXPECTED_MAX_TABLE_NAME_LENGTH)); collector.checkThat(metaData.getMaxTablesInSelect(), is(EXPECTED_MAX_TABLES_IN_SELECT)); collector.checkThat(metaData.getMaxUserNameLength(), is(EXPECTED_MAX_USERNAME_LENGTH)); - collector.checkThat(metaData.getDefaultTransactionIsolation(), - is(EXPECTED_DEFAULT_TRANSACTION_ISOLATION)); + collector.checkThat( + metaData.getDefaultTransactionIsolation(), is(EXPECTED_DEFAULT_TRANSACTION_ISOLATION)); collector.checkThat(metaData.supportsTransactions(), is(EXPECTED_TRANSACTIONS_SUPPORTED)); collector.checkThat(metaData.supportsBatchUpdates(), is(EXPECTED_BATCH_UPDATES_SUPPORTED)); collector.checkThat(metaData.supportsSavepoints(), is(EXPECTED_SAVEPOINTS_SUPPORTED)); - collector.checkThat(metaData.supportsNamedParameters(), - is(EXPECTED_NAMED_PARAMETERS_SUPPORTED)); + collector.checkThat( + metaData.supportsNamedParameters(), is(EXPECTED_NAMED_PARAMETERS_SUPPORTED)); collector.checkThat(metaData.locatorsUpdateCopy(), is(EXPECTED_LOCATORS_UPDATE_COPY)); - collector.checkThat(metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE), + collector.checkThat( + metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE), is(EXPECTED_TYPE_SCROLL_INSENSITIVE)); - collector.checkThat(metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE), + collector.checkThat( + metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE), is(EXPECTED_TYPE_SCROLL_SENSITIVE)); - collector.checkThat(metaData.supportsSchemasInPrivilegeDefinitions(), + collector.checkThat( + metaData.supportsSchemasInPrivilegeDefinitions(), is(EXPECTED_SCHEMAS_IN_PRIVILEGE_DEFINITIONS)); - collector.checkThat(metaData.supportsCatalogsInPrivilegeDefinitions(), + collector.checkThat( + metaData.supportsCatalogsInPrivilegeDefinitions(), is(EXPECTED_CATALOGS_IN_PRIVILEGE_DEFINITIONS)); - collector.checkThat(metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE), + collector.checkThat( + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE), is(EXPECTED_TRANSACTION_NONE)); collector.checkThat( metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED), @@ -906,27 +959,35 @@ public void testGetSqlInfo() throws SQLException { collector.checkThat( metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE), is(EXPECTED_TRANSACTION_SERIALIZABLE)); - collector.checkThat(metaData.dataDefinitionCausesTransactionCommit(), + collector.checkThat( + metaData.dataDefinitionCausesTransactionCommit(), is(EXPECTED_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT)); - collector.checkThat(metaData.dataDefinitionIgnoredInTransactions(), + collector.checkThat( + metaData.dataDefinitionIgnoredInTransactions(), is(EXPECTED_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED)); - collector.checkThat(metaData.supportsStoredFunctionsUsingCallSyntax(), + collector.checkThat( + metaData.supportsStoredFunctionsUsingCallSyntax(), is(EXPECTED_STORED_FUNCTIONS_USING_CALL_SYNTAX_SUPPORTED)); - collector.checkThat(metaData.supportsIntegrityEnhancementFacility(), + collector.checkThat( + metaData.supportsIntegrityEnhancementFacility(), is(EXPECTED_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY)); - collector.checkThat(metaData.supportsDifferentTableCorrelationNames(), + collector.checkThat( + metaData.supportsDifferentTableCorrelationNames(), is(EXPECTED_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES)); - ThrowableAssertionUtils.simpleAssertThrowableClass(SQLException.class, + ThrowableAssertionUtils.simpleAssertThrowableClass( + SQLException.class, () -> metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE + 1)); - ThrowableAssertionUtils.simpleAssertThrowableClass(SQLException.class, + ThrowableAssertionUtils.simpleAssertThrowableClass( + SQLException.class, () -> metaData.supportsResultSetType(ResultSet.HOLD_CURSORS_OVER_COMMIT)); } @Test public void testGetColumnsCanBeAccessedByNames() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getColumns(null, null, null, null)) { - resultSetTestUtils.testData(resultSet, + resultSetTestUtils.testData( + resultSet, ImmutableList.of( "TABLE_CAT", "TABLE_SCHEM", @@ -952,8 +1013,7 @@ public void testGetColumnsCanBeAccessedByNames() throws SQLException { "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN"), - EXPECTED_GET_COLUMNS_RESULTS - ); + EXPECTED_GET_COLUMNS_RESULTS); } } @@ -961,27 +1021,28 @@ public void testGetColumnsCanBeAccessedByNames() throws SQLException { public void testGetProcedures() throws SQLException { try (final ResultSet resultSet = connection.getMetaData().getProcedures(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetProceduresSchema = new HashMap() { - { - put(1, "PROCEDURE_CAT"); - put(2, "PROCEDURE_SCHEM"); - put(3, "PROCEDURE_NAME"); - put(4, "FUTURE_USE1"); - put(5, "FUTURE_USE2"); - put(6, "FUTURE_USE3"); - put(7, "REMARKS"); - put(8, "PROCEDURE_TYPE"); - put(9, "SPECIFIC_NAME"); - } - }; + final Map expectedGetProceduresSchema = + new HashMap() { + { + put(1, "PROCEDURE_CAT"); + put(2, "PROCEDURE_SCHEM"); + put(3, "PROCEDURE_NAME"); + put(4, "FUTURE_USE1"); + put(5, "FUTURE_USE2"); + put(6, "FUTURE_USE3"); + put(7, "REMARKS"); + put(8, "PROCEDURE_TYPE"); + put(9, "SPECIFIC_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetProceduresSchema); } } @Test public void testGetProcedureColumns() throws SQLException { - try (ResultSet resultSet = connection.getMetaData() - .getProcedureColumns(null, null, null, null)) { + try (ResultSet resultSet = + connection.getMetaData().getProcedureColumns(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation final Map expectedGetProcedureColumnsSchema = new HashMap() { @@ -1014,8 +1075,8 @@ public void testGetProcedureColumns() throws SQLException { @Test public void testGetColumnPrivileges() throws SQLException { - try (ResultSet resultSet = connection.getMetaData() - .getColumnPrivileges(null, null, null, null)) { + try (ResultSet resultSet = + connection.getMetaData().getColumnPrivileges(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation final Map expectedGetColumnPrivilegesSchema = new HashMap() { @@ -1038,25 +1099,26 @@ public void testGetColumnPrivileges() throws SQLException { public void testGetTablePrivileges() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getTablePrivileges(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetTablePrivilegesSchema = new HashMap() { - { - put(1, "TABLE_CAT"); - put(2, "TABLE_SCHEM"); - put(3, "TABLE_NAME"); - put(4, "GRANTOR"); - put(5, "GRANTEE"); - put(6, "PRIVILEGE"); - put(7, "IS_GRANTABLE"); - } - }; + final Map expectedGetTablePrivilegesSchema = + new HashMap() { + { + put(1, "TABLE_CAT"); + put(2, "TABLE_SCHEM"); + put(3, "TABLE_NAME"); + put(4, "GRANTOR"); + put(5, "GRANTEE"); + put(6, "PRIVILEGE"); + put(7, "IS_GRANTABLE"); + } + }; testEmptyResultSet(resultSet, expectedGetTablePrivilegesSchema); } } @Test public void testGetBestRowIdentifier() throws SQLException { - try (ResultSet resultSet = connection.getMetaData() - .getBestRowIdentifier(null, null, null, 0, true)) { + try (ResultSet resultSet = + connection.getMetaData().getBestRowIdentifier(null, null, null, 0, true)) { // Maps ordinal index to column name according to JDBC documentation final Map expectedGetBestRowIdentifierSchema = new HashMap() { @@ -1079,18 +1141,19 @@ public void testGetBestRowIdentifier() throws SQLException { public void testGetVersionColumns() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getVersionColumns(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetVersionColumnsSchema = new HashMap() { - { - put(1, "SCOPE"); - put(2, "COLUMN_NAME"); - put(3, "DATA_TYPE"); - put(4, "TYPE_NAME"); - put(5, "COLUMN_SIZE"); - put(6, "BUFFER_LENGTH"); - put(7, "DECIMAL_DIGITS"); - put(8, "PSEUDO_COLUMN"); - } - }; + final Map expectedGetVersionColumnsSchema = + new HashMap() { + { + put(1, "SCOPE"); + put(2, "COLUMN_NAME"); + put(3, "DATA_TYPE"); + put(4, "TYPE_NAME"); + put(5, "COLUMN_SIZE"); + put(6, "BUFFER_LENGTH"); + put(7, "DECIMAL_DIGITS"); + put(8, "PSEUDO_COLUMN"); + } + }; testEmptyResultSet(resultSet, expectedGetVersionColumnsSchema); } } @@ -1099,54 +1162,56 @@ public void testGetVersionColumns() throws SQLException { public void testGetTypeInfo() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getTypeInfo()) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetTypeInfoSchema = new HashMap() { - { - put(1, "TYPE_NAME"); - put(2, "DATA_TYPE"); - put(3, "PRECISION"); - put(4, "LITERAL_PREFIX"); - put(5, "LITERAL_SUFFIX"); - put(6, "CREATE_PARAMS"); - put(7, "NULLABLE"); - put(8, "CASE_SENSITIVE"); - put(9, "SEARCHABLE"); - put(10, "UNSIGNED_ATTRIBUTE"); - put(11, "FIXED_PREC_SCALE"); - put(12, "AUTO_INCREMENT"); - put(13, "LOCAL_TYPE_NAME"); - put(14, "MINIMUM_SCALE"); - put(15, "MAXIMUM_SCALE"); - put(16, "SQL_DATA_TYPE"); - put(17, "SQL_DATETIME_SUB"); - put(18, "NUM_PREC_RADIX"); - } - }; + final Map expectedGetTypeInfoSchema = + new HashMap() { + { + put(1, "TYPE_NAME"); + put(2, "DATA_TYPE"); + put(3, "PRECISION"); + put(4, "LITERAL_PREFIX"); + put(5, "LITERAL_SUFFIX"); + put(6, "CREATE_PARAMS"); + put(7, "NULLABLE"); + put(8, "CASE_SENSITIVE"); + put(9, "SEARCHABLE"); + put(10, "UNSIGNED_ATTRIBUTE"); + put(11, "FIXED_PREC_SCALE"); + put(12, "AUTO_INCREMENT"); + put(13, "LOCAL_TYPE_NAME"); + put(14, "MINIMUM_SCALE"); + put(15, "MAXIMUM_SCALE"); + put(16, "SQL_DATA_TYPE"); + put(17, "SQL_DATETIME_SUB"); + put(18, "NUM_PREC_RADIX"); + } + }; testEmptyResultSet(resultSet, expectedGetTypeInfoSchema); } } @Test public void testGetIndexInfo() throws SQLException { - try (ResultSet resultSet = connection.getMetaData() - .getIndexInfo(null, null, null, false, true)) { + try (ResultSet resultSet = + connection.getMetaData().getIndexInfo(null, null, null, false, true)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetIndexInfoSchema = new HashMap() { - { - put(1, "TABLE_CAT"); - put(2, "TABLE_SCHEM"); - put(3, "TABLE_NAME"); - put(4, "NON_UNIQUE"); - put(5, "INDEX_QUALIFIER"); - put(6, "INDEX_NAME"); - put(7, "TYPE"); - put(8, "ORDINAL_POSITION"); - put(9, "COLUMN_NAME"); - put(10, "ASC_OR_DESC"); - put(11, "CARDINALITY"); - put(12, "PAGES"); - put(13, "FILTER_CONDITION"); - } - }; + final Map expectedGetIndexInfoSchema = + new HashMap() { + { + put(1, "TABLE_CAT"); + put(2, "TABLE_SCHEM"); + put(3, "TABLE_NAME"); + put(4, "NON_UNIQUE"); + put(5, "INDEX_QUALIFIER"); + put(6, "INDEX_NAME"); + put(7, "TYPE"); + put(8, "ORDINAL_POSITION"); + put(9, "COLUMN_NAME"); + put(10, "ASC_OR_DESC"); + put(11, "CARDINALITY"); + put(12, "PAGES"); + put(13, "FILTER_CONDITION"); + } + }; testEmptyResultSet(resultSet, expectedGetIndexInfoSchema); } } @@ -1155,17 +1220,18 @@ public void testGetIndexInfo() throws SQLException { public void testGetUDTs() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getUDTs(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetUDTsSchema = new HashMap() { - { - put(1, "TYPE_CAT"); - put(2, "TYPE_SCHEM"); - put(3, "TYPE_NAME"); - put(4, "CLASS_NAME"); - put(5, "DATA_TYPE"); - put(6, "REMARKS"); - put(7, "BASE_TYPE"); - } - }; + final Map expectedGetUDTsSchema = + new HashMap() { + { + put(1, "TYPE_CAT"); + put(2, "TYPE_SCHEM"); + put(3, "TYPE_NAME"); + put(4, "CLASS_NAME"); + put(5, "DATA_TYPE"); + put(6, "REMARKS"); + put(7, "BASE_TYPE"); + } + }; testEmptyResultSet(resultSet, expectedGetUDTsSchema); } } @@ -1174,16 +1240,17 @@ public void testGetUDTs() throws SQLException { public void testGetSuperTypes() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getSuperTypes(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetSuperTypesSchema = new HashMap() { - { - put(1, "TYPE_CAT"); - put(2, "TYPE_SCHEM"); - put(3, "TYPE_NAME"); - put(4, "SUPERTYPE_CAT"); - put(5, "SUPERTYPE_SCHEM"); - put(6, "SUPERTYPE_NAME"); - } - }; + final Map expectedGetSuperTypesSchema = + new HashMap() { + { + put(1, "TYPE_CAT"); + put(2, "TYPE_SCHEM"); + put(3, "TYPE_NAME"); + put(4, "SUPERTYPE_CAT"); + put(5, "SUPERTYPE_SCHEM"); + put(6, "SUPERTYPE_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetSuperTypesSchema); } } @@ -1192,14 +1259,15 @@ public void testGetSuperTypes() throws SQLException { public void testGetSuperTables() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getSuperTables(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetSuperTablesSchema = new HashMap() { - { - put(1, "TABLE_CAT"); - put(2, "TABLE_SCHEM"); - put(3, "TABLE_NAME"); - put(4, "SUPERTABLE_NAME"); - } - }; + final Map expectedGetSuperTablesSchema = + new HashMap() { + { + put(1, "TABLE_CAT"); + put(2, "TABLE_SCHEM"); + put(3, "TABLE_NAME"); + put(4, "SUPERTABLE_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetSuperTablesSchema); } } @@ -1208,31 +1276,32 @@ public void testGetSuperTables() throws SQLException { public void testGetAttributes() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getAttributes(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetAttributesSchema = new HashMap() { - { - put(1, "TYPE_CAT"); - put(2, "TYPE_SCHEM"); - put(3, "TYPE_NAME"); - put(4, "ATTR_NAME"); - put(5, "DATA_TYPE"); - put(6, "ATTR_TYPE_NAME"); - put(7, "ATTR_SIZE"); - put(8, "DECIMAL_DIGITS"); - put(9, "NUM_PREC_RADIX"); - put(10, "NULLABLE"); - put(11, "REMARKS"); - put(12, "ATTR_DEF"); - put(13, "SQL_DATA_TYPE"); - put(14, "SQL_DATETIME_SUB"); - put(15, "CHAR_OCTET_LENGTH"); - put(16, "ORDINAL_POSITION"); - put(17, "IS_NULLABLE"); - put(18, "SCOPE_CATALOG"); - put(19, "SCOPE_SCHEMA"); - put(20, "SCOPE_TABLE"); - put(21, "SOURCE_DATA_TYPE"); - } - }; + final Map expectedGetAttributesSchema = + new HashMap() { + { + put(1, "TYPE_CAT"); + put(2, "TYPE_SCHEM"); + put(3, "TYPE_NAME"); + put(4, "ATTR_NAME"); + put(5, "DATA_TYPE"); + put(6, "ATTR_TYPE_NAME"); + put(7, "ATTR_SIZE"); + put(8, "DECIMAL_DIGITS"); + put(9, "NUM_PREC_RADIX"); + put(10, "NULLABLE"); + put(11, "REMARKS"); + put(12, "ATTR_DEF"); + put(13, "SQL_DATA_TYPE"); + put(14, "SQL_DATETIME_SUB"); + put(15, "CHAR_OCTET_LENGTH"); + put(16, "ORDINAL_POSITION"); + put(17, "IS_NULLABLE"); + put(18, "SCOPE_CATALOG"); + put(19, "SCOPE_SCHEMA"); + put(20, "SCOPE_TABLE"); + put(21, "SOURCE_DATA_TYPE"); + } + }; testEmptyResultSet(resultSet, expectedGetAttributesSchema); } } @@ -1258,46 +1327,48 @@ public void testGetClientInfoProperties() throws SQLException { public void testGetFunctions() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getFunctions(null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetFunctionsSchema = new HashMap() { - { - put(1, "FUNCTION_CAT"); - put(2, "FUNCTION_SCHEM"); - put(3, "FUNCTION_NAME"); - put(4, "REMARKS"); - put(5, "FUNCTION_TYPE"); - put(6, "SPECIFIC_NAME"); - } - }; + final Map expectedGetFunctionsSchema = + new HashMap() { + { + put(1, "FUNCTION_CAT"); + put(2, "FUNCTION_SCHEM"); + put(3, "FUNCTION_NAME"); + put(4, "REMARKS"); + put(5, "FUNCTION_TYPE"); + put(6, "SPECIFIC_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetFunctionsSchema); } } @Test public void testGetFunctionColumns() throws SQLException { - try ( - ResultSet resultSet = connection.getMetaData().getFunctionColumns(null, null, null, null)) { + try (ResultSet resultSet = + connection.getMetaData().getFunctionColumns(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetFunctionColumnsSchema = new HashMap() { - { - put(1, "FUNCTION_CAT"); - put(2, "FUNCTION_SCHEM"); - put(3, "FUNCTION_NAME"); - put(4, "COLUMN_NAME"); - put(5, "COLUMN_TYPE"); - put(6, "DATA_TYPE"); - put(7, "TYPE_NAME"); - put(8, "PRECISION"); - put(9, "LENGTH"); - put(10, "SCALE"); - put(11, "RADIX"); - put(12, "NULLABLE"); - put(13, "REMARKS"); - put(14, "CHAR_OCTET_LENGTH"); - put(15, "ORDINAL_POSITION"); - put(16, "IS_NULLABLE"); - put(17, "SPECIFIC_NAME"); - } - }; + final Map expectedGetFunctionColumnsSchema = + new HashMap() { + { + put(1, "FUNCTION_CAT"); + put(2, "FUNCTION_SCHEM"); + put(3, "FUNCTION_NAME"); + put(4, "COLUMN_NAME"); + put(5, "COLUMN_TYPE"); + put(6, "DATA_TYPE"); + put(7, "TYPE_NAME"); + put(8, "PRECISION"); + put(9, "LENGTH"); + put(10, "SCALE"); + put(11, "RADIX"); + put(12, "NULLABLE"); + put(13, "REMARKS"); + put(14, "CHAR_OCTET_LENGTH"); + put(15, "ORDINAL_POSITION"); + put(16, "IS_NULLABLE"); + put(17, "SPECIFIC_NAME"); + } + }; testEmptyResultSet(resultSet, expectedGetFunctionColumnsSchema); } } @@ -1306,28 +1377,29 @@ public void testGetFunctionColumns() throws SQLException { public void testGetPseudoColumns() throws SQLException { try (ResultSet resultSet = connection.getMetaData().getPseudoColumns(null, null, null, null)) { // Maps ordinal index to column name according to JDBC documentation - final Map expectedGetPseudoColumnsSchema = new HashMap() { - { - put(1, "TABLE_CAT"); - put(2, "TABLE_SCHEM"); - put(3, "TABLE_NAME"); - put(4, "COLUMN_NAME"); - put(5, "DATA_TYPE"); - put(6, "COLUMN_SIZE"); - put(7, "DECIMAL_DIGITS"); - put(8, "NUM_PREC_RADIX"); - put(9, "COLUMN_USAGE"); - put(10, "REMARKS"); - put(11, "CHAR_OCTET_LENGTH"); - put(12, "IS_NULLABLE"); - } - }; + final Map expectedGetPseudoColumnsSchema = + new HashMap() { + { + put(1, "TABLE_CAT"); + put(2, "TABLE_SCHEM"); + put(3, "TABLE_NAME"); + put(4, "COLUMN_NAME"); + put(5, "DATA_TYPE"); + put(6, "COLUMN_SIZE"); + put(7, "DECIMAL_DIGITS"); + put(8, "NUM_PREC_RADIX"); + put(9, "COLUMN_USAGE"); + put(10, "REMARKS"); + put(11, "CHAR_OCTET_LENGTH"); + put(12, "IS_NULLABLE"); + } + }; testEmptyResultSet(resultSet, expectedGetPseudoColumnsSchema); } } - private void testEmptyResultSet(final ResultSet resultSet, - final Map expectedResultSetSchema) + private void testEmptyResultSet( + final ResultSet resultSet, final Map expectedResultSetSchema) throws SQLException { Assert.assertFalse(resultSet.next()); final ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); @@ -1338,76 +1410,102 @@ private void testEmptyResultSet(final ResultSet resultSet, @Test public void testGetColumnSize() { - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_BYTE), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_BYTE), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Int(Byte.SIZE, true))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_SHORT), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_SHORT), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Int(Short.SIZE, true))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_INT), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_INT), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Int(Integer.SIZE, true))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_LONG), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_LONG), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Int(Long.SIZE, true))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_VARCHAR_AND_BINARY), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_VARCHAR_AND_BINARY), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Utf8())); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_VARCHAR_AND_BINARY), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_VARCHAR_AND_BINARY), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Binary())); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_SECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_SECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Timestamp(TimeUnit.SECOND, null))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_MILLISECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_MILLISECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Timestamp(TimeUnit.MILLISECOND, null))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_MICROSECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_MICROSECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Timestamp(TimeUnit.MICROSECOND, null))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_NANOSECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIMESTAMP_NANOSECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Timestamp(TimeUnit.NANOSECOND, null))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Time(TimeUnit.SECOND, Integer.SIZE))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_MILLISECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_MILLISECONDS), ArrowDatabaseMetadata.getColumnSize( new ArrowType.Time(TimeUnit.MILLISECOND, Integer.SIZE))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_MICROSECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_MICROSECONDS), ArrowDatabaseMetadata.getColumnSize( new ArrowType.Time(TimeUnit.MICROSECOND, Integer.SIZE))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_NANOSECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_TIME_NANOSECONDS), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Time(TimeUnit.NANOSECOND, Integer.SIZE))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_DATE), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.COLUMN_SIZE_DATE), ArrowDatabaseMetadata.getColumnSize(new ArrowType.Date(DateUnit.DAY))); - Assert.assertNull(ArrowDatabaseMetadata.getColumnSize(new ArrowType.FloatingPoint( - FloatingPointPrecision.DOUBLE))); + Assert.assertNull( + ArrowDatabaseMetadata.getColumnSize( + new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE))); } @Test public void testGetDecimalDigits() { - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Int(Byte.SIZE, true))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Timestamp(TimeUnit.SECOND, null))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MILLISECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MILLISECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Timestamp(TimeUnit.MILLISECOND, null))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MICROSECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MICROSECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Timestamp(TimeUnit.MICROSECOND, null))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_NANOSECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_NANOSECONDS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Timestamp(TimeUnit.NANOSECOND, null))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Time(TimeUnit.SECOND, Integer.SIZE))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MILLISECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MILLISECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Time(TimeUnit.MILLISECOND, Integer.SIZE))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MICROSECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_MICROSECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Time(TimeUnit.MICROSECOND, Integer.SIZE))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_NANOSECONDS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.DECIMAL_DIGITS_TIME_NANOSECONDS), ArrowDatabaseMetadata.getDecimalDigits( new ArrowType.Time(TimeUnit.NANOSECOND, Integer.SIZE))); - Assert.assertEquals(Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), + Assert.assertEquals( + Integer.valueOf(ArrowDatabaseMetadata.NO_DECIMAL_DIGITS), ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Date(DateUnit.DAY))); Assert.assertNull(ArrowDatabaseMetadata.getDecimalDigits(new ArrowType.Utf8())); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java index 90c926612f1..c2b061ab54b 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java @@ -23,7 +23,6 @@ import java.sql.Types; import java.util.Arrays; import java.util.HashMap; - import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; import org.apache.arrow.vector.IntVector; import org.apache.arrow.vector.util.JsonStringArrayList; @@ -38,8 +37,7 @@ @RunWith(MockitoJUnitRunner.class) public class ArrowFlightJdbcArrayTest { - @Rule - public RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); + @Rule public RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); IntVector dataVector; diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionCookieTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionCookieTest.java index c7268e0594e..a5224eeb13d 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionCookieTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionCookieTest.java @@ -20,7 +20,6 @@ import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; - import org.apache.arrow.driver.jdbc.utils.CoreMockedSqlProducers; import org.junit.Assert; import org.junit.ClassRule; @@ -30,8 +29,7 @@ public class ArrowFlightJdbcConnectionCookieTest { - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = @@ -40,7 +38,7 @@ public class ArrowFlightJdbcConnectionCookieTest { @Test public void testCookies() throws SQLException { try (Connection connection = FLIGHT_SERVER_TEST_RULE.getConnection(false); - Statement statement = connection.createStatement()) { + Statement statement = connection.createStatement()) { // Expect client didn't receive cookies before any operation Assert.assertNull(FLIGHT_SERVER_TEST_RULE.getMiddlewareCookieFactory().getCookie()); @@ -51,4 +49,3 @@ public void testCookies() throws SQLException { } } } - diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSourceTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSourceTest.java index bdf2826c41e..f558e13a1fe 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSourceTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcConnectionPoolDataSourceTest.java @@ -18,9 +18,7 @@ package org.apache.arrow.driver.jdbc; import java.sql.Connection; - import javax.sql.PooledConnection; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.utils.ConnectionWrapper; import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; @@ -31,8 +29,7 @@ import org.junit.Test; public class ArrowFlightJdbcConnectionPoolDataSourceTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); @@ -43,10 +40,11 @@ public class ArrowFlightJdbcConnectionPoolDataSourceTest { .user("user2", "pass2") .build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .producer(PRODUCER) + .build(); } private ArrowFlightJdbcConnectionPoolDataSource dataSource; @@ -107,7 +105,8 @@ public void testShouldReuseConnectionsOnPool() throws Exception { Assert.assertSame(pooledConnection, pooledConnection2); Assert.assertNotSame(connection, connection2); - Assert.assertSame(connection.unwrap(ArrowFlightConnection.class), + Assert.assertSame( + connection.unwrap(ArrowFlightConnection.class), connection2.unwrap(ArrowFlightConnection.class)); } @@ -129,7 +128,8 @@ public void testShouldNotMixConnectionsForDifferentUsers() throws Exception { Assert.assertNotSame(pooledConnection, pooledConnection2); Assert.assertNotSame(connection, connection2); - Assert.assertNotSame(connection.unwrap(ArrowFlightConnection.class), + Assert.assertNotSame( + connection.unwrap(ArrowFlightConnection.class), connection2.unwrap(ArrowFlightConnection.class)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcCursorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcCursorTest.java index b818f7115b7..ffb08ce3fac 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcCursorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcCursorTest.java @@ -19,10 +19,10 @@ import static org.junit.Assert.assertTrue; +import com.google.common.collect.ImmutableList; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BitVector; @@ -55,11 +55,7 @@ import org.junit.After; import org.junit.Test; -import com.google.common.collect.ImmutableList; - -/** - * Tests for {@link ArrowFlightJdbcCursor}. - */ +/** Tests for {@link ArrowFlightJdbcCursor}. */ public class ArrowFlightJdbcCursorTest { ArrowFlightJdbcCursor cursor; @@ -88,44 +84,42 @@ public void testDateVectorNullTrue() throws SQLException { @Test public void testDurationVectorNullTrue() throws SQLException { - final VectorSchemaRoot root = getVectorSchemaRoot("Duration", - new ArrowType.Duration(TimeUnit.MILLISECOND), null); + final VectorSchemaRoot root = + getVectorSchemaRoot("Duration", new ArrowType.Duration(TimeUnit.MILLISECOND), null); ((DurationVector) root.getVector("Duration")).setNull(0); testCursorWasNull(root); } @Test public void testDateInternalNullTrue() throws SQLException { - final VectorSchemaRoot root = getVectorSchemaRoot("Interval", - new ArrowType.Interval(IntervalUnit.DAY_TIME), null); + final VectorSchemaRoot root = + getVectorSchemaRoot("Interval", new ArrowType.Interval(IntervalUnit.DAY_TIME), null); ((IntervalDayVector) root.getVector("Interval")).setNull(0); testCursorWasNull(root); } @Test public void testTimeStampVectorNullTrue() throws SQLException { - final VectorSchemaRoot root = getVectorSchemaRoot("TimeStamp", - new ArrowType.Timestamp(TimeUnit.MILLISECOND, null), null); + final VectorSchemaRoot root = + getVectorSchemaRoot("TimeStamp", new ArrowType.Timestamp(TimeUnit.MILLISECOND, null), null); ((TimeStampMilliVector) root.getVector("TimeStamp")).setNull(0); testCursorWasNull(root); } @Test public void testTimeVectorNullTrue() throws SQLException { - final VectorSchemaRoot root = getVectorSchemaRoot("Time", - new ArrowType.Time(TimeUnit.MILLISECOND, 32), null); + final VectorSchemaRoot root = + getVectorSchemaRoot("Time", new ArrowType.Time(TimeUnit.MILLISECOND, 32), null); ((TimeMilliVector) root.getVector("Time")).setNull(0); testCursorWasNull(root); - } @Test public void testFixedSizeListVectorNullTrue() throws SQLException { List fieldList = new ArrayList<>(); - fieldList.add(new Field("Null", new FieldType(true, new ArrowType.Null(), null), - null)); - final VectorSchemaRoot root = getVectorSchemaRoot("FixedSizeList", - new ArrowType.FixedSizeList(10), fieldList); + fieldList.add(new Field("Null", new FieldType(true, new ArrowType.Null(), null), null)); + final VectorSchemaRoot root = + getVectorSchemaRoot("FixedSizeList", new ArrowType.FixedSizeList(10), fieldList); ((FixedSizeListVector) root.getVector("FixedSizeList")).setNull(0); testCursorWasNull(root); } @@ -133,8 +127,7 @@ public void testFixedSizeListVectorNullTrue() throws SQLException { @Test public void testLargeListVectorNullTrue() throws SQLException { List fieldList = new ArrayList<>(); - fieldList.add(new Field("Null", new FieldType(true, new ArrowType.Null(), null), - null)); + fieldList.add(new Field("Null", new FieldType(true, new ArrowType.Null(), null), null)); final VectorSchemaRoot root = getVectorSchemaRoot("LargeList", new ArrowType.LargeList(), fieldList); ((LargeListVector) root.getVector("LargeList")).setNull(0); @@ -144,8 +137,7 @@ public void testLargeListVectorNullTrue() throws SQLException { @Test public void testListVectorNullTrue() throws SQLException { List fieldList = new ArrayList<>(); - fieldList.add(new Field("Null", new FieldType(true, new ArrowType.Null(), null), - null)); + fieldList.add(new Field("Null", new FieldType(true, new ArrowType.Null(), null), null)); final VectorSchemaRoot root = getVectorSchemaRoot("List", new ArrowType.List(), fieldList); ((ListVector) root.getVector("List")).setNull(0); testCursorWasNull(root); @@ -154,13 +146,11 @@ public void testListVectorNullTrue() throws SQLException { @Test public void testMapVectorNullTrue() throws SQLException { List structChildren = new ArrayList<>(); - structChildren.add(new Field("Key", new FieldType(false, new ArrowType.Utf8(), null), - null)); - structChildren.add(new Field("Value", new FieldType(false, new ArrowType.Utf8(), null), - null)); + structChildren.add(new Field("Key", new FieldType(false, new ArrowType.Utf8(), null), null)); + structChildren.add(new Field("Value", new FieldType(false, new ArrowType.Utf8(), null), null)); List fieldList = new ArrayList<>(); - fieldList.add(new Field("Struct", new FieldType(false, new ArrowType.Struct(), null), - structChildren)); + fieldList.add( + new Field("Struct", new FieldType(false, new ArrowType.Struct(), null), structChildren)); final VectorSchemaRoot root = getVectorSchemaRoot("Map", new ArrowType.Map(false), fieldList); ((MapVector) root.getVector("Map")).setNull(0); testCursorWasNull(root); @@ -175,8 +165,8 @@ public void testStructVectorNullTrue() throws SQLException { @Test public void testBaseIntVectorNullTrue() throws SQLException { - final VectorSchemaRoot root = getVectorSchemaRoot("BaseInt", - new ArrowType.Int(32, false), null); + final VectorSchemaRoot root = + getVectorSchemaRoot("BaseInt", new ArrowType.Int(32, false), null); ((UInt4Vector) root.getVector("BaseInt")).setNull(0); testCursorWasNull(root); } @@ -190,24 +180,26 @@ public void testBitVectorNullTrue() throws SQLException { @Test public void testDecimalVectorNullTrue() throws SQLException { - final VectorSchemaRoot root = getVectorSchemaRoot("Decimal", - new ArrowType.Decimal(2, 2, 128), null); + final VectorSchemaRoot root = + getVectorSchemaRoot("Decimal", new ArrowType.Decimal(2, 2, 128), null); ((DecimalVector) root.getVector("Decimal")).setNull(0); testCursorWasNull(root); } @Test public void testFloat4VectorNullTrue() throws SQLException { - final VectorSchemaRoot root = getVectorSchemaRoot("Float4", - new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), null); + final VectorSchemaRoot root = + getVectorSchemaRoot( + "Float4", new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), null); ((Float4Vector) root.getVector("Float4")).setNull(0); testCursorWasNull(root); } @Test public void testFloat8VectorNullTrue() throws SQLException { - final VectorSchemaRoot root = getVectorSchemaRoot("Float8", - new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), null); + final VectorSchemaRoot root = + getVectorSchemaRoot( + "Float8", new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), null); ((Float8Vector) root.getVector("Float8")).setNull(0); testCursorWasNull(root); } @@ -225,14 +217,11 @@ public void testNullVectorNullTrue() throws SQLException { testCursorWasNull(root); } - private VectorSchemaRoot getVectorSchemaRoot(String name, ArrowType arrowType, - List children) { - final Schema schema = new Schema(ImmutableList.of( - new Field( - name, - new FieldType(true, arrowType, - null), - children))); + private VectorSchemaRoot getVectorSchemaRoot( + String name, ArrowType arrowType, List children) { + final Schema schema = + new Schema( + ImmutableList.of(new Field(name, new FieldType(true, arrowType, null), children))); allocator = new RootAllocator(Long.MAX_VALUE); final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator); root.allocateNew(); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriverTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriverTest.java index 784fd5b292b..589b75c87b8 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriverTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriverTest.java @@ -30,7 +30,6 @@ import java.util.Collection; import java.util.Map; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; @@ -42,24 +41,24 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Tests for {@link ArrowFlightJdbcDriver}. - */ +/** Tests for {@link ArrowFlightJdbcDriver}. */ public class ArrowFlightJdbcDriverTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); static { UserPasswordAuthentication authentication = - new UserPasswordAuthentication.Builder().user("user1", "pass1").user("user2", "pass2") + new UserPasswordAuthentication.Builder() + .user("user1", "pass1") + .user("user2", "pass2") .build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .producer(PRODUCER) + .build(); } private BufferAllocator allocator; @@ -79,34 +78,36 @@ public void tearDown() throws Exception { } /** - * Tests whether the {@link ArrowFlightJdbcDriver} is registered in the - * {@link DriverManager}. + * Tests whether the {@link ArrowFlightJdbcDriver} is registered in the {@link DriverManager}. * * @throws SQLException If an error occurs. (This is not supposed to happen.) */ @Test public void testDriverIsRegisteredInDriverManager() throws Exception { - assertTrue(DriverManager.getDriver("jdbc:arrow-flight://localhost:32010") instanceof - ArrowFlightJdbcDriver); - assertTrue(DriverManager.getDriver("jdbc:arrow-flight-sql://localhost:32010") instanceof - ArrowFlightJdbcDriver); + assertTrue( + DriverManager.getDriver("jdbc:arrow-flight://localhost:32010") + instanceof ArrowFlightJdbcDriver); + assertTrue( + DriverManager.getDriver("jdbc:arrow-flight-sql://localhost:32010") + instanceof ArrowFlightJdbcDriver); } /** - * Tests whether the {@link ArrowFlightJdbcDriver} returns null when provided with an - * unsupported URL prefix. + * Tests whether the {@link ArrowFlightJdbcDriver} returns null when provided with an unsupported + * URL prefix. */ @Test public void testShouldDeclineUrlWithUnsupportedPrefix() throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); - assertNull(driver.connect("jdbc:mysql://localhost:32010", - dataSource.getProperties("flight", "flight123"))); + assertNull( + driver.connect( + "jdbc:mysql://localhost:32010", dataSource.getProperties("flight", "flight123"))); } /** - * Tests whether the {@link ArrowFlightJdbcDriver} can establish a successful - * connection to the Arrow Flight client. + * Tests whether the {@link ArrowFlightJdbcDriver} can establish a successful connection to the + * Arrow Flight client. * * @throws Exception If the connection fails to be established. */ @@ -116,19 +117,27 @@ public void testShouldConnectWhenProvidedWithValidUrl() throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); try (Connection connection = - driver.connect("jdbc:arrow-flight://" + - dataSource.getConfig().getHost() + ":" + - dataSource.getConfig().getPort() + "?" + - "useEncryption=false", - dataSource.getProperties(dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) { + driver.connect( + "jdbc:arrow-flight://" + + dataSource.getConfig().getHost() + + ":" + + dataSource.getConfig().getPort() + + "?" + + "useEncryption=false", + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) { assertTrue(connection.isValid(300)); } try (Connection connection = - driver.connect("jdbc:arrow-flight-sql://" + - dataSource.getConfig().getHost() + ":" + - dataSource.getConfig().getPort() + "?" + - "useEncryption=false", - dataSource.getProperties(dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) { + driver.connect( + "jdbc:arrow-flight-sql://" + + dataSource.getConfig().getHost() + + ":" + + dataSource.getConfig().getPort() + + "?" + + "useEncryption=false", + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) { assertTrue(connection.isValid(300)); } } @@ -139,19 +148,27 @@ public void testConnectWithInsensitiveCasePropertyKeys() throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); try (Connection connection = - driver.connect("jdbc:arrow-flight://" + - dataSource.getConfig().getHost() + ":" + - dataSource.getConfig().getPort() + "?" + - "UseEncryptIon=false", - dataSource.getProperties(dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) { + driver.connect( + "jdbc:arrow-flight://" + + dataSource.getConfig().getHost() + + ":" + + dataSource.getConfig().getPort() + + "?" + + "UseEncryptIon=false", + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) { assertTrue(connection.isValid(300)); } try (Connection connection = - driver.connect("jdbc:arrow-flight-sql://" + - dataSource.getConfig().getHost() + ":" + - dataSource.getConfig().getPort() + "?" + - "UseEncryptIon=false", - dataSource.getProperties(dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) { + driver.connect( + "jdbc:arrow-flight-sql://" + + dataSource.getConfig().getHost() + + ":" + + dataSource.getConfig().getPort() + + "?" + + "UseEncryptIon=false", + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()))) { assertTrue(connection.isValid(300)); } } @@ -161,27 +178,31 @@ public void testConnectWithInsensitiveCasePropertyKeys2() throws Exception { // Get the Arrow Flight JDBC driver by providing a property object with insensitive case keys. final Driver driver = new ArrowFlightJdbcDriver(); Properties properties = - dataSource.getProperties(dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()); + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()); properties.put("UseEncryptIon", "false"); try (Connection connection = - driver.connect("jdbc:arrow-flight://" + - dataSource.getConfig().getHost() + ":" + - dataSource.getConfig().getPort(), properties)) { + driver.connect( + "jdbc:arrow-flight://" + + dataSource.getConfig().getHost() + + ":" + + dataSource.getConfig().getPort(), + properties)) { assertTrue(connection.isValid(300)); } try (Connection connection = - driver.connect("jdbc:arrow-flight-sql://" + - dataSource.getConfig().getHost() + ":" + - dataSource.getConfig().getPort(), properties)) { + driver.connect( + "jdbc:arrow-flight-sql://" + + dataSource.getConfig().getHost() + + ":" + + dataSource.getConfig().getPort(), + properties)) { assertTrue(connection.isValid(300)); } } - /** - * Tests whether an exception is thrown upon attempting to connect to a - * malformed URI. - */ + /** Tests whether an exception is thrown upon attempting to connect to a malformed URI. */ @Test(expected = SQLException.class) public void testShouldThrowExceptionWhenAttemptingToConnectToMalformedUrl() throws SQLException { final Driver driver = new ArrowFlightJdbcDriver(); @@ -191,8 +212,7 @@ public void testShouldThrowExceptionWhenAttemptingToConnectToMalformedUrl() thro } /** - * Tests whether an exception is thrown upon attempting to connect to a - * malformed URI. + * Tests whether an exception is thrown upon attempting to connect to a malformed URI. * * @throws Exception If an error occurs. */ @@ -201,60 +221,72 @@ public void testShouldThrowExceptionWhenAttemptingToConnectToUrlNoPrefix() throw final Driver driver = new ArrowFlightJdbcDriver(); final String malformedUri = "localhost:32010"; - driver.connect(malformedUri, dataSource.getProperties(dataSource.getConfig().getUser(), - dataSource.getConfig().getPassword())); + driver.connect( + malformedUri, + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword())); } - /** - * Tests whether an exception is thrown upon attempting to connect to a - * malformed URI. - */ + /** Tests whether an exception is thrown upon attempting to connect to a malformed URI. */ @Test public void testShouldThrowExceptionWhenAttemptingToConnectToUrlNoPort() { final Driver driver = new ArrowFlightJdbcDriver(); - SQLException e = assertThrows(SQLException.class, () -> { - Properties properties = dataSource.getProperties(dataSource.getConfig().getUser(), - dataSource.getConfig().getPassword()); - Connection conn = driver.connect("jdbc:arrow-flight://localhost", properties); - conn.close(); - }); + SQLException e = + assertThrows( + SQLException.class, + () -> { + Properties properties = + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()); + Connection conn = driver.connect("jdbc:arrow-flight://localhost", properties); + conn.close(); + }); assertTrue(e.getMessage().contains("URL must have a port")); - e = assertThrows(SQLException.class, () -> { - Properties properties = dataSource.getProperties(dataSource.getConfig().getUser(), - dataSource.getConfig().getPassword()); - Connection conn = driver.connect("jdbc:arrow-flight-sql://localhost", properties); - conn.close(); - }); + e = + assertThrows( + SQLException.class, + () -> { + Properties properties = + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()); + Connection conn = driver.connect("jdbc:arrow-flight-sql://localhost", properties); + conn.close(); + }); assertTrue(e.getMessage().contains("URL must have a port")); } - /** - * Tests whether an exception is thrown upon attempting to connect to a - * malformed URI. - */ + /** Tests whether an exception is thrown upon attempting to connect to a malformed URI. */ @Test public void testShouldThrowExceptionWhenAttemptingToConnectToUrlNoHost() { final Driver driver = new ArrowFlightJdbcDriver(); - SQLException e = assertThrows(SQLException.class, () -> { - Properties properties = dataSource.getProperties(dataSource.getConfig().getUser(), - dataSource.getConfig().getPassword()); - Connection conn = driver.connect("jdbc:arrow-flight://32010:localhost", properties); - conn.close(); - }); + SQLException e = + assertThrows( + SQLException.class, + () -> { + Properties properties = + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()); + Connection conn = driver.connect("jdbc:arrow-flight://32010:localhost", properties); + conn.close(); + }); assertTrue(e.getMessage().contains("URL must have a host")); - e = assertThrows(SQLException.class, () -> { - Properties properties = dataSource.getProperties(dataSource.getConfig().getUser(), - dataSource.getConfig().getPassword()); - Connection conn = driver.connect("jdbc:arrow-flight-sql://32010:localhost", properties); - conn.close(); - }); + e = + assertThrows( + SQLException.class, + () -> { + Properties properties = + dataSource.getProperties( + dataSource.getConfig().getUser(), dataSource.getConfig().getPassword()); + Connection conn = + driver.connect("jdbc:arrow-flight-sql://32010:localhost", properties); + conn.close(); + }); assertTrue(e.getMessage().contains("URL must have a host")); } /** - * Tests whether {@link ArrowFlightJdbcDriver#getUrlsArgs} returns the - * correct URL parameters. + * Tests whether {@link ArrowFlightJdbcDriver#getUrlsArgs} returns the correct URL parameters. * * @throws Exception If an error occurs. */ @@ -262,9 +294,10 @@ public void testShouldThrowExceptionWhenAttemptingToConnectToUrlNoHost() { public void testDriverUrlParsingMechanismShouldReturnTheDesiredArgsFromUrl() throws Exception { final ArrowFlightJdbcDriver driver = new ArrowFlightJdbcDriver(); - final Map parsedArgs = driver.getUrlsArgs( - "jdbc:arrow-flight-sql://localhost:2222/?key1=value1&key2=value2&a=b") - .orElseThrow(() -> new RuntimeException("URL was rejected")); + final Map parsedArgs = + driver + .getUrlsArgs("jdbc:arrow-flight-sql://localhost:2222/?key1=value1&key2=value2&a=b") + .orElseThrow(() -> new RuntimeException("URL was rejected")); // Check size == the amount of args provided (scheme not included) assertEquals(5, parsedArgs.size()); @@ -282,11 +315,13 @@ public void testDriverUrlParsingMechanismShouldReturnTheDesiredArgsFromUrl() thr } @Test - public void testDriverUrlParsingMechanismShouldReturnTheDesiredArgsFromUrlWithSemicolon() throws Exception { + public void testDriverUrlParsingMechanismShouldReturnTheDesiredArgsFromUrlWithSemicolon() + throws Exception { final ArrowFlightJdbcDriver driver = new ArrowFlightJdbcDriver(); - final Map parsedArgs = driver.getUrlsArgs( - "jdbc:arrow-flight-sql://localhost:2222/;key1=value1;key2=value2;a=b") - .orElseThrow(() -> new RuntimeException("URL was rejected")); + final Map parsedArgs = + driver + .getUrlsArgs("jdbc:arrow-flight-sql://localhost:2222/;key1=value1;key2=value2;a=b") + .orElseThrow(() -> new RuntimeException("URL was rejected")); // Check size == the amount of args provided (scheme not included) assertEquals(5, parsedArgs.size()); @@ -304,11 +339,13 @@ public void testDriverUrlParsingMechanismShouldReturnTheDesiredArgsFromUrlWithSe } @Test - public void testDriverUrlParsingMechanismShouldReturnTheDesiredArgsFromUrlWithOneSemicolon() throws Exception { + public void testDriverUrlParsingMechanismShouldReturnTheDesiredArgsFromUrlWithOneSemicolon() + throws Exception { final ArrowFlightJdbcDriver driver = new ArrowFlightJdbcDriver(); - final Map parsedArgs = driver.getUrlsArgs( - "jdbc:arrow-flight-sql://localhost:2222/;key1=value1") - .orElseThrow(() -> new RuntimeException("URL was rejected")); + final Map parsedArgs = + driver + .getUrlsArgs("jdbc:arrow-flight-sql://localhost:2222/;key1=value1") + .orElseThrow(() -> new RuntimeException("URL was rejected")); // Check size == the amount of args provided (scheme not included) assertEquals(3, parsedArgs.size()); @@ -324,22 +361,25 @@ public void testDriverUrlParsingMechanismShouldReturnTheDesiredArgsFromUrlWithOn } @Test - public void testDriverUrlParsingMechanismShouldReturnEmptyOptionalForUnknownScheme() throws SQLException { + public void testDriverUrlParsingMechanismShouldReturnEmptyOptionalForUnknownScheme() + throws SQLException { final ArrowFlightJdbcDriver driver = new ArrowFlightJdbcDriver(); assertFalse(driver.getUrlsArgs("jdbc:malformed-url-flight://localhost:2222").isPresent()); } /** - * Tests whether {@code ArrowFlightJdbcDriverTest#getUrlsArgs} returns the - * correct URL parameters when the host is an IP Address. + * Tests whether {@code ArrowFlightJdbcDriverTest#getUrlsArgs} returns the correct URL parameters + * when the host is an IP Address. * * @throws Exception If an error occurs. */ @Test public void testDriverUrlParsingMechanismShouldWorkWithIPAddress() throws Exception { final ArrowFlightJdbcDriver driver = new ArrowFlightJdbcDriver(); - final Map parsedArgs = driver.getUrlsArgs("jdbc:arrow-flight-sql://0.0.0.0:2222") - .orElseThrow(() -> new RuntimeException("URL was rejected")); + final Map parsedArgs = + driver + .getUrlsArgs("jdbc:arrow-flight-sql://0.0.0.0:2222") + .orElseThrow(() -> new RuntimeException("URL was rejected")); // Check size == the amount of args provided (scheme not included) assertEquals(2, parsedArgs.size()); @@ -352,8 +392,9 @@ public void testDriverUrlParsingMechanismShouldWorkWithIPAddress() throws Except } /** - * Tests whether {@code ArrowFlightJdbcDriverTest#getUrlsArgs} escape especial characters and returns the - * correct URL parameters when the especial character '&' is embedded in the query parameters values. + * Tests whether {@code ArrowFlightJdbcDriverTest#getUrlsArgs} escape especial characters and + * returns the correct URL parameters when the especial character '&' is embedded in the query + * parameters values. * * @throws Exception If an error occurs. */ @@ -361,9 +402,11 @@ public void testDriverUrlParsingMechanismShouldWorkWithIPAddress() throws Except public void testDriverUrlParsingMechanismShouldWorkWithEmbeddedEspecialCharacter() throws Exception { final ArrowFlightJdbcDriver driver = new ArrowFlightJdbcDriver(); - final Map parsedArgs = driver.getUrlsArgs( - "jdbc:arrow-flight-sql://0.0.0.0:2222?test1=test1value&test2%26continue=test2value&test3=test3value") - .orElseThrow(() -> new RuntimeException("URL was rejected")); + final Map parsedArgs = + driver + .getUrlsArgs( + "jdbc:arrow-flight-sql://0.0.0.0:2222?test1=test1value&test2%26continue=test2value&test3=test3value") + .orElseThrow(() -> new RuntimeException("URL was rejected")); // Check size == the amount of args provided (scheme not included) assertEquals(5, parsedArgs.size()); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactoryTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactoryTest.java index a355e7156f7..2b9c77ff83d 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactoryTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactoryTest.java @@ -17,10 +17,10 @@ package org.apache.arrow.driver.jdbc; +import com.google.common.collect.ImmutableMap; import java.lang.reflect.Constructor; import java.sql.Connection; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; @@ -33,26 +33,24 @@ import org.junit.ClassRule; import org.junit.Test; -import com.google.common.collect.ImmutableMap; - -/** - * Tests for {@link ArrowFlightJdbcDriver}. - */ +/** Tests for {@link ArrowFlightJdbcDriver}. */ public class ArrowFlightJdbcFactoryTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); static { UserPasswordAuthentication authentication = - new UserPasswordAuthentication.Builder().user("user1", "pass1").user("user2", "pass2") + new UserPasswordAuthentication.Builder() + .user("user1", "pass1") + .user("user2", "pass2") .build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .producer(PRODUCER) + .build(); } private BufferAllocator allocator; @@ -77,13 +75,21 @@ public void testShouldBeAbleToEstablishAConnectionSuccessfully() throws Exceptio ArrowFlightJdbcFactory factory = constructor.newInstance(); final Properties properties = new Properties(); - properties.putAll(ImmutableMap.of( - ArrowFlightConnectionProperty.HOST.camelName(), "localhost", - ArrowFlightConnectionProperty.PORT.camelName(), 32010, - ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false)); + properties.putAll( + ImmutableMap.of( + ArrowFlightConnectionProperty.HOST.camelName(), + "localhost", + ArrowFlightConnectionProperty.PORT.camelName(), + 32010, + ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), + false)); - try (Connection connection = factory.newConnection(driver, constructor.newInstance(), - "jdbc:arrow-flight-sql://localhost:32010", properties)) { + try (Connection connection = + factory.newConnection( + driver, + constructor.newInstance(), + "jdbc:arrow-flight-sql://localhost:32010", + properties)) { assert connection.isValid(300); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTimeTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTimeTest.java index 104794b3ad1..044b3e1ec5e 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTimeTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTimeTest.java @@ -22,15 +22,13 @@ import java.time.LocalTime; import java.util.concurrent.TimeUnit; - import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.ErrorCollector; public class ArrowFlightJdbcTimeTest { - @ClassRule - public static final ErrorCollector collector = new ErrorCollector(); + @ClassRule public static final ErrorCollector collector = new ErrorCollector(); final int hour = 5; final int minute = 6; final int second = 7; @@ -38,7 +36,8 @@ public class ArrowFlightJdbcTimeTest { @Test public void testPrintingMillisNoLeadingZeroes() { // testing the regular case where the precision of the millisecond is 3 - LocalTime dateTime = LocalTime.of(hour, minute, second, (int) TimeUnit.MILLISECONDS.toNanos(999)); + LocalTime dateTime = + LocalTime.of(hour, minute, second, (int) TimeUnit.MILLISECONDS.toNanos(999)); ArrowFlightJdbcTime time = new ArrowFlightJdbcTime(dateTime); collector.checkThat(time.toString(), endsWith(".999")); collector.checkThat(time.getHours(), is(hour)); @@ -49,7 +48,8 @@ public void testPrintingMillisNoLeadingZeroes() { @Test public void testPrintingMillisOneLeadingZeroes() { // test case where one leading zero needs to be added - LocalTime dateTime = LocalTime.of(hour, minute, second, (int) TimeUnit.MILLISECONDS.toNanos(99)); + LocalTime dateTime = + LocalTime.of(hour, minute, second, (int) TimeUnit.MILLISECONDS.toNanos(99)); ArrowFlightJdbcTime time = new ArrowFlightJdbcTime(dateTime); collector.checkThat(time.toString(), endsWith(".099")); collector.checkThat(time.getHours(), is(hour)); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatementTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatementTest.java index 0b521a704bb..ef82bf751aa 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatementTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatementTest.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.driver.jdbc.utils.CoreMockedSqlProducers; import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; import org.apache.arrow.flight.sql.FlightSqlUtils; @@ -54,14 +53,14 @@ public class ArrowFlightPreparedStatementTest { public static final MockFlightSqlProducer PRODUCER = CoreMockedSqlProducers.getLegacyProducer(); + @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = FlightServerTestRule - .createStandardTestRule(PRODUCER); + public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = + FlightServerTestRule.createStandardTestRule(PRODUCER); private static Connection connection; - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); @BeforeClass public static void setup() throws SQLException { @@ -82,7 +81,7 @@ public void before() { public void testSimpleQueryNoParameterBinding() throws SQLException { final String query = CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD; try (final PreparedStatement preparedStatement = connection.prepareStatement(query); - final ResultSet resultSet = preparedStatement.executeQuery()) { + final ResultSet resultSet = preparedStatement.executeQuery()) { CoreMockedSqlProducers.assertLegacyRegularSqlResultSet(resultSet, collector); } } @@ -90,20 +89,26 @@ public void testSimpleQueryNoParameterBinding() throws SQLException { @Test public void testQueryWithParameterBinding() throws SQLException { final String query = "Fake query with parameters"; - final Schema schema = new Schema(Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType()))); - final Schema parameterSchema = new Schema(Arrays.asList( - Field.nullable("", ArrowType.Utf8.INSTANCE), - new Field("", FieldType.nullable(ArrowType.List.INSTANCE), + final Schema schema = + new Schema(Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType()))); + final Schema parameterSchema = + new Schema( + Arrays.asList( + Field.nullable("", ArrowType.Utf8.INSTANCE), + new Field( + "", + FieldType.nullable(ArrowType.List.INSTANCE), Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType()))))); - final List> expected = Collections.singletonList(Arrays.asList( - new Text("foo"), - new Integer[]{1, 2, null})); - - PRODUCER.addSelectQuery(query, schema, - Collections.singletonList(listener -> { + final List> expected = + Collections.singletonList(Arrays.asList(new Text("foo"), new Integer[] {1, 2, null})); + + PRODUCER.addSelectQuery( + query, + schema, + Collections.singletonList( + listener -> { try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, - allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { ((IntVector) root.getVector(0)).setSafe(0, 10); root.setRowCount(1); listener.start(root); @@ -119,7 +124,8 @@ public void testQueryWithParameterBinding() throws SQLException { try (final PreparedStatement preparedStatement = connection.prepareStatement(query)) { preparedStatement.setString(1, "foo"); - preparedStatement.setArray(2, connection.createArrayOf("INTEGER", new Integer[]{1, 2, null})); + preparedStatement.setArray( + 2, connection.createArrayOf("INTEGER", new Integer[] {1, 2, null})); try (final ResultSet resultSet = preparedStatement.executeQuery()) { resultSet.next(); @@ -128,15 +134,20 @@ public void testQueryWithParameterBinding() throws SQLException { } } - @Test @Ignore("https://github.com/apache/arrow/issues/34741: flaky test") public void testPreparedStatementExecutionOnce() throws SQLException { - final PreparedStatement statement = connection.prepareStatement(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD); - // Expect that there is one entry in the map -- {prepared statement action type, invocation count}. + final PreparedStatement statement = + connection.prepareStatement(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD); + // Expect that there is one entry in the map -- {prepared statement action type, invocation + // count}. assertEquals(PRODUCER.getActionTypeCounter().size(), 1); // Expect that the prepared statement was executed exactly once. - assertEquals(PRODUCER.getActionTypeCounter().get(FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT.getType()), 1); + assertEquals( + PRODUCER + .getActionTypeCounter() + .get(FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT.getType()), + 1); statement.close(); } @@ -157,7 +168,7 @@ public void testReturnColumnCount() throws SQLException { @Test public void testUpdateQuery() throws SQLException { String query = "Fake update"; - PRODUCER.addUpdateQuery(query, /*updatedRows*/42); + PRODUCER.addUpdateQuery(query, /*updatedRows*/ 42); try (final PreparedStatement stmt = connection.prepareStatement(query)) { int updated = stmt.executeUpdate(); assertEquals(42, updated); @@ -167,10 +178,12 @@ public void testUpdateQuery() throws SQLException { @Test public void testUpdateQueryWithParameters() throws SQLException { String query = "Fake update with parameters"; - PRODUCER.addUpdateQuery(query, /*updatedRows*/42); - PRODUCER.addExpectedParameters(query, + PRODUCER.addUpdateQuery(query, /*updatedRows*/ 42); + PRODUCER.addExpectedParameters( + query, new Schema(Collections.singletonList(Field.nullable("", ArrowType.Utf8.INSTANCE))), - Collections.singletonList(Collections.singletonList(new Text("foo".getBytes(StandardCharsets.UTF_8))))); + Collections.singletonList( + Collections.singletonList(new Text("foo".getBytes(StandardCharsets.UTF_8))))); try (final PreparedStatement stmt = connection.prepareStatement(query)) { // TODO: make sure this is validated on the server too stmt.setString(1, "foo"); @@ -182,29 +195,29 @@ public void testUpdateQueryWithParameters() throws SQLException { @Test public void testUpdateQueryWithBatchedParameters() throws SQLException { String query = "Fake update with batched parameters"; - Schema parameterSchema = new Schema(Arrays.asList( - Field.nullable("", ArrowType.Utf8.INSTANCE), - new Field("", FieldType.nullable(ArrowType.List.INSTANCE), - Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType()))))); - List> expected = Arrays.asList( + Schema parameterSchema = + new Schema( Arrays.asList( - new Text("foo"), - new Integer[]{1, 2, null}), - Arrays.asList( - new Text("bar"), - new Integer[]{0, -1, 100000}) - ); + Field.nullable("", ArrowType.Utf8.INSTANCE), + new Field( + "", + FieldType.nullable(ArrowType.List.INSTANCE), + Collections.singletonList(Field.nullable("", Types.MinorType.INT.getType()))))); + List> expected = + Arrays.asList( + Arrays.asList(new Text("foo"), new Integer[] {1, 2, null}), + Arrays.asList(new Text("bar"), new Integer[] {0, -1, 100000})); - PRODUCER.addUpdateQuery(query, /*updatedRows*/42); + PRODUCER.addUpdateQuery(query, /*updatedRows*/ 42); PRODUCER.addExpectedParameters(query, parameterSchema, expected); try (final PreparedStatement stmt = connection.prepareStatement(query)) { // TODO: make sure this is validated on the server too stmt.setString(1, "foo"); - stmt.setArray(2, connection.createArrayOf("INTEGER", new Integer[]{1, 2, null})); + stmt.setArray(2, connection.createArrayOf("INTEGER", new Integer[] {1, 2, null})); stmt.addBatch(); stmt.setString(1, "bar"); - stmt.setArray(2, connection.createArrayOf("INTEGER", new Integer[]{0, -1, 100000})); + stmt.setArray(2, connection.createArrayOf("INTEGER", new Integer[] {0, -1, 100000})); stmt.addBatch(); int[] updated = stmt.executeBatch(); assertEquals(42, updated[0]); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteTest.java index 155fcc50827..95644775e8f 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteTest.java @@ -32,7 +32,6 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; - import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -52,9 +51,7 @@ import org.junit.Test; import org.junit.rules.ErrorCollector; -/** - * Tests for {@link ArrowFlightStatement#execute}. - */ +/** Tests for {@link ArrowFlightStatement#execute}. */ public class ArrowFlightStatementExecuteTest { private static final String SAMPLE_QUERY_CMD = "SELECT * FROM this_test"; private static final int SAMPLE_QUERY_ROWS = Byte.MAX_VALUE; @@ -68,11 +65,12 @@ public class ArrowFlightStatementExecuteTest { "UPDATE this_large_table SET this_large_field = that_large_field FROM this_large_test WHERE this_large_condition"; private static final long SAMPLE_LARGE_UPDATE_COUNT = Long.MAX_VALUE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); + @ClassRule - public static final FlightServerTestRule SERVER_TEST_RULE = FlightServerTestRule.createStandardTestRule(PRODUCER); + public static final FlightServerTestRule SERVER_TEST_RULE = + FlightServerTestRule.createStandardTestRule(PRODUCER); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private Connection connection; private Statement statement; @@ -81,22 +79,24 @@ public static void setUpBeforeClass() { PRODUCER.addSelectQuery( SAMPLE_QUERY_CMD, SAMPLE_QUERY_SCHEMA, - Collections.singletonList(listener -> { - try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - final VectorSchemaRoot root = VectorSchemaRoot.create(SAMPLE_QUERY_SCHEMA, - allocator)) { - final UInt1Vector vector = (UInt1Vector) root.getVector(VECTOR_NAME); - IntStream.range(0, SAMPLE_QUERY_ROWS).forEach(index -> vector.setSafe(index, index)); - vector.setValueCount(SAMPLE_QUERY_ROWS); - root.setRowCount(SAMPLE_QUERY_ROWS); - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - })); + Collections.singletonList( + listener -> { + try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); + final VectorSchemaRoot root = + VectorSchemaRoot.create(SAMPLE_QUERY_SCHEMA, allocator)) { + final UInt1Vector vector = (UInt1Vector) root.getVector(VECTOR_NAME); + IntStream.range(0, SAMPLE_QUERY_ROWS) + .forEach(index -> vector.setSafe(index, index)); + vector.setValueCount(SAMPLE_QUERY_ROWS); + root.setRowCount(SAMPLE_QUERY_ROWS); + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + })); PRODUCER.addUpdateQuery(SAMPLE_UPDATE_QUERY, SAMPLE_UPDATE_COUNT); PRODUCER.addUpdateQuery(SAMPLE_LARGE_UPDATE_QUERY, SAMPLE_LARGE_UPDATE_COUNT); } @@ -119,10 +119,11 @@ public static void tearDownAfterClass() throws Exception { @Test public void testExecuteShouldRunSelectQuery() throws SQLException { - collector.checkThat(statement.execute(SAMPLE_QUERY_CMD), - is(true)); // Means this is a SELECT query. + collector.checkThat( + statement.execute(SAMPLE_QUERY_CMD), is(true)); // Means this is a SELECT query. final Set numbers = - IntStream.range(0, SAMPLE_QUERY_ROWS).boxed() + IntStream.range(0, SAMPLE_QUERY_ROWS) + .boxed() .map(Integer::byteValue) .collect(Collectors.toCollection(HashSet::new)); try (final ResultSet resultSet = statement.getResultSet()) { @@ -142,8 +143,8 @@ public void testExecuteShouldRunSelectQuery() throws SQLException { @Test public void testExecuteShouldRunUpdateQueryForSmallUpdate() throws SQLException { - collector.checkThat(statement.execute(SAMPLE_UPDATE_QUERY), - is(false)); // Means this is an UPDATE query. + collector.checkThat( + statement.execute(SAMPLE_UPDATE_QUERY), is(false)); // Means this is an UPDATE query. collector.checkThat( (long) statement.getUpdateCount(), is(allOf(equalTo(statement.getLargeUpdateCount()), equalTo(SAMPLE_UPDATE_COUNT)))); @@ -158,8 +159,10 @@ public void testExecuteShouldRunUpdateQueryForLargeUpdate() throws SQLException collector.checkThat(updateCountLarge, is(equalTo(SAMPLE_LARGE_UPDATE_COUNT))); collector.checkThat( updateCountSmall, - is(allOf(equalTo((long) AvaticaUtils.toSaturatedInt(updateCountLarge)), - not(equalTo(updateCountLarge))))); + is( + allOf( + equalTo((long) AvaticaUtils.toSaturatedInt(updateCountLarge)), + not(equalTo(updateCountLarge))))); collector.checkThat(statement.getResultSet(), is(nullValue())); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java index 43209d8913e..ad2c4d9eb96 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightStatementExecuteUpdateTest.java @@ -29,7 +29,6 @@ import java.sql.SQLFeatureNotSupportedException; import java.sql.Statement; import java.util.Collections; - import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -48,9 +47,7 @@ import org.junit.Test; import org.junit.rules.ErrorCollector; -/** - * Tests for {@link ArrowFlightStatement#executeUpdate}. - */ +/** Tests for {@link ArrowFlightStatement#executeUpdate}. */ public class ArrowFlightStatementExecuteUpdateTest { private static final String UPDATE_SAMPLE_QUERY = "UPDATE sample_table SET sample_col = sample_val WHERE sample_condition"; @@ -63,11 +60,12 @@ public class ArrowFlightStatementExecuteUpdateTest { new Schema( Collections.singletonList(Field.nullable("placeholder", MinorType.VARCHAR.getType()))); private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); + @ClassRule - public static final FlightServerTestRule SERVER_TEST_RULE = FlightServerTestRule.createStandardTestRule(PRODUCER); + public static final FlightServerTestRule SERVER_TEST_RULE = + FlightServerTestRule.createStandardTestRule(PRODUCER); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); public Connection connection; public Statement statement; @@ -78,18 +76,19 @@ public static void setUpBeforeClass() { PRODUCER.addSelectQuery( REGULAR_QUERY_SAMPLE, REGULAR_QUERY_SCHEMA, - Collections.singletonList(listener -> { - try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - final VectorSchemaRoot root = VectorSchemaRoot.create(REGULAR_QUERY_SCHEMA, - allocator)) { - listener.start(root); - listener.putNext(); - } catch (final Throwable throwable) { - listener.error(throwable); - } finally { - listener.completed(); - } - })); + Collections.singletonList( + listener -> { + try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); + final VectorSchemaRoot root = + VectorSchemaRoot.create(REGULAR_QUERY_SCHEMA, allocator)) { + listener.start(root); + listener.putNext(); + } catch (final Throwable throwable) { + listener.error(throwable); + } finally { + listener.completed(); + } + })); } @Before @@ -111,8 +110,8 @@ public static void tearDownAfterClass() throws Exception { @Test public void testExecuteUpdateShouldReturnNumColsAffectedForNumRowsFittingInt() throws SQLException { - collector.checkThat(statement.executeUpdate(UPDATE_SAMPLE_QUERY), - is(UPDATE_SAMPLE_QUERY_AFFECTED_COLS)); + collector.checkThat( + statement.executeUpdate(UPDATE_SAMPLE_QUERY), is(UPDATE_SAMPLE_QUERY_AFFECTED_COLS)); } @Test @@ -122,10 +121,13 @@ public void testExecuteUpdateShouldReturnSaturatedNumColsAffectedIfDoesNotFitInI final long expectedRowCountRaw = LARGE_UPDATE_SAMPLE_QUERY_AFFECTED_COLS; collector.checkThat( result, - is(allOf( - not(equalTo(expectedRowCountRaw)), - equalTo((long) AvaticaUtils.toSaturatedInt( - expectedRowCountRaw))))); // Because of long-to-integer overflow. + is( + allOf( + not(equalTo(expectedRowCountRaw)), + equalTo( + (long) + AvaticaUtils.toSaturatedInt( + expectedRowCountRaw))))); // Because of long-to-integer overflow. } @Test @@ -161,10 +163,10 @@ public void testExecuteUpdateUnsupportedWithArraysOfStrings() throws SQLExceptio @Test public void testExecuteShouldExecuteUpdateQueryAutomatically() throws SQLException { - collector.checkThat(statement.execute(UPDATE_SAMPLE_QUERY), - is(false)); // Meaning there was an update query. - collector.checkThat(statement.execute(REGULAR_QUERY_SAMPLE), - is(true)); // Meaning there was a select query. + collector.checkThat( + statement.execute(UPDATE_SAMPLE_QUERY), is(false)); // Meaning there was an update query. + collector.checkThat( + statement.execute(REGULAR_QUERY_SAMPLE), is(true)); // Meaning there was a select query. } @Test diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java index cc44cc57be9..1a4a23fd693 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionMutualTlsTest.java @@ -27,7 +27,6 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; @@ -42,13 +41,10 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Tests encrypted connections. - */ +/** Tests encrypted connections. */ public class ConnectionMutualTlsTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final String tlsRootCertsPath; private static final String serverMTlsCACertPath; @@ -61,8 +57,8 @@ public class ConnectionMutualTlsTest { private static final String passTest = "pass1"; static { - final FlightSqlTestCertificates.CertKeyPair - certKey = FlightSqlTestCertificates.exampleTlsCerts().get(0); + final FlightSqlTestCertificates.CertKeyPair certKey = + FlightSqlTestCertificates.exampleTlsCerts().get(0); tlsRootCertsPath = certKey.cert.getPath(); @@ -70,8 +66,8 @@ public class ConnectionMutualTlsTest { serverMTlsCACertPath = serverMTlsCACert.getPath(); - final FlightSqlTestCertificates.CertKeyPair - clientMTlsCertKey = FlightSqlTestCertificates.exampleTlsCerts().get(1); + final FlightSqlTestCertificates.CertKeyPair clientMTlsCertKey = + FlightSqlTestCertificates.exampleTlsCerts().get(1); clientMTlsCertPath = clientMTlsCertKey.cert.getPath(); clientMTlsKeyPath = clientMTlsCertKey.key.getPath(); @@ -79,16 +75,16 @@ public class ConnectionMutualTlsTest { badClientMTlsCertPath = clientMTlsCertPath + ".bad"; badClientMTlsKeyPath = clientMTlsKeyPath + ".bad"; - UserPasswordAuthentication authentication = new UserPasswordAuthentication.Builder() - .user(userTest, passTest) - .build(); + UserPasswordAuthentication authentication = + new UserPasswordAuthentication.Builder().user(userTest, passTest).build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .useEncryption(certKey.cert, certKey.key) - .useMTlsClientVerification(serverMTlsCACert) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .useEncryption(certKey.cert, certKey.key) + .useMTlsClientVerification(serverMTlsCACert) + .producer(PRODUCER) + .build(); } private BufferAllocator allocator; @@ -113,17 +109,17 @@ public void tearDown() throws Exception { public void testGetEncryptedClientAuthenticated() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withTlsRootCertificates(tlsRootCertsPath) - .withClientCertificate(clientMTlsCertPath) - .withClientKey(clientMTlsKeyPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withTlsRootCertificates(tlsRootCertsPath) + .withClientCertificate(clientMTlsCertPath) + .withClientKey(clientMTlsKeyPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } @@ -135,21 +131,24 @@ public void testGetEncryptedClientAuthenticated() throws Exception { @Test public void testGetEncryptedClientWithBadMTlsCertPath() { - assertThrows(SQLException.class, () -> { - try (ArrowFlightSqlClientHandler handler = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withTlsRootCertificates(tlsRootCertsPath) - .withClientCertificate(badClientMTlsCertPath) - .withClientKey(clientMTlsKeyPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { - Assert.fail(); - } - }); + assertThrows( + SQLException.class, + () -> { + try (ArrowFlightSqlClientHandler handler = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withTlsRootCertificates(tlsRootCertsPath) + .withClientCertificate(badClientMTlsCertPath) + .withClientKey(clientMTlsKeyPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { + Assert.fail(); + } + }); } /** @@ -159,21 +158,24 @@ public void testGetEncryptedClientWithBadMTlsCertPath() { @Test public void testGetEncryptedClientWithBadMTlsKeyPath() { - assertThrows(SQLException.class, () -> { - try (ArrowFlightSqlClientHandler handler = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withTlsRootCertificates(tlsRootCertsPath) - .withClientCertificate(clientMTlsCertPath) - .withClientKey(badClientMTlsKeyPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { - Assert.fail(); - } - }); + assertThrows( + SQLException.class, + () -> { + try (ArrowFlightSqlClientHandler handler = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withTlsRootCertificates(tlsRootCertsPath) + .withClientCertificate(clientMTlsCertPath) + .withClientKey(badClientMTlsKeyPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { + Assert.fail(); + } + }); } /** @@ -184,21 +186,21 @@ public void testGetEncryptedClientWithBadMTlsKeyPath() { @Test public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withTlsRootCertificates(tlsRootCertsPath) - .withClientCertificate(clientMTlsCertPath) - .withClientKey(clientMTlsKeyPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withTlsRootCertificates(tlsRootCertsPath) + .withClientCertificate(clientMTlsCertPath) + .withClientKey(clientMTlsKeyPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } /** - * Check if an encrypted connection can be established successfully when the - * provided valid credentials and a valid TLS Root Certs path. + * Check if an encrypted connection can be established successfully when the provided valid + * credentials and a valid TLS Root Certs path. * * @throws Exception on error. */ @@ -207,18 +209,14 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); - properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), - tlsRootCertsPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), - clientMTlsCertPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), - clientMTlsKeyPath); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); + properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.put( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); @@ -228,8 +226,8 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro } /** - * Check if an encrypted connection can be established successfully when not - * providing authentication. + * Check if an encrypted connection can be established successfully when not providing + * authentication. * * @throws Exception on error. */ @@ -237,22 +235,26 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro public void testGetNonAuthenticatedEncryptedConnection() throws Exception { final Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.put( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); + final ArrowFlightJdbcDataSource dataSource = + ArrowFlightJdbcDataSource.createNewDataSource(properties); try (final Connection connection = dataSource.getConnection()) { Assert.assertTrue(connection.isValid(300)); } } /** - * Check if an encrypted connection can be established successfully when connecting through - * the DriverManager using just a connection url. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url. * * @throws Exception on error. */ @@ -261,9 +263,10 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - final String jdbcUrl = String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=true&%s=%s&%s=%s&%s=%s", + final String jdbcUrl = + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=true&%s=%s&%s=%s&%s=%s", FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest, @@ -280,14 +283,15 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -295,14 +299,15 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); - properties.setProperty(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.setProperty( + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "true"); - properties.setProperty(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.setProperty( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.setProperty(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final String jdbcUrl = String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()); + final String jdbcUrl = + String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) { Assert.assertTrue(connection.isValid(0)); @@ -310,8 +315,8 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs. * * @throws Exception on error. */ @@ -327,12 +332,12 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.put( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final String jdbcUrl = String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()); + final String jdbcUrl = + String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) { Assert.assertTrue(connection.isValid(0)); @@ -340,8 +345,8 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * just a connection url and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url and using 0 and 1 as ssl values. * * @throws Exception on error. */ @@ -351,9 +356,10 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager( final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - final String jdbcUrl = String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s&%s=%s", + final String jdbcUrl = + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s&%s=%s", FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest, @@ -370,14 +376,16 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager( } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -385,12 +393,15 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); - properties.setProperty(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.setProperty( + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "1"); - properties.setProperty(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.setProperty( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.setProperty(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final String jdbcUrl = String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); + final String jdbcUrl = + String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) { Assert.assertTrue(connection.isValid(0)); @@ -398,14 +409,16 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -415,11 +428,12 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), 1); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - properties.put(ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); + properties.put( + ArrowFlightConnectionProperty.CLIENT_CERTIFICATE.camelName(), clientMTlsCertPath); properties.put(ArrowFlightConnectionProperty.CLIENT_KEY.camelName(), clientMTlsKeyPath); - final String jdbcUrl = String.format("jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()); + final String jdbcUrl = + String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()); try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) { Assert.assertTrue(connection.isValid(0)); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java index 357506b3d17..2bc29a7df82 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java @@ -28,7 +28,6 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; @@ -42,27 +41,23 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Tests for {@link Connection}. - */ +/** Tests for {@link Connection}. */ public class ConnectionTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); private static final String userTest = "user1"; private static final String passTest = "pass1"; static { UserPasswordAuthentication authentication = - new UserPasswordAuthentication.Builder() - .user(userTest, passTest) - .build(); + new UserPasswordAuthentication.Builder().user(userTest, passTest).build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .producer(PRODUCER) + .build(); } private BufferAllocator allocator; @@ -79,8 +74,8 @@ public void tearDown() throws Exception { } /** - * Checks if an unencrypted connection can be established successfully when - * the provided valid credentials. + * Checks if an unencrypted connection can be established successfully when the provided valid + * credentials. * * @throws SQLException on error. */ @@ -90,58 +85,64 @@ public void testUnencryptedConnectionShouldOpenSuccessfullyWhenProvidedValidCred final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - "jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_RULE.getHost() + ":" + - FLIGHT_SERVER_TEST_RULE.getPort(), properties)) { + try (Connection connection = + DriverManager.getConnection( + "jdbc:arrow-flight-sql://" + + FLIGHT_SERVER_TEST_RULE.getHost() + + ":" + + FLIGHT_SERVER_TEST_RULE.getPort(), + properties)) { Assert.assertTrue(connection.isValid(300)); } } /** - * Checks if a token is provided it takes precedence over username/pass. In this case, - * the connection should fail if a token is passed in. + * Checks if a token is provided it takes precedence over username/pass. In this case, the + * connection should fail if a token is passed in. */ @Test public void testTokenOverridesUsernameAndPasswordAuth() { final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.TOKEN.camelName(), "token"); properties.put("useEncryption", false); - SQLException e = assertThrows(SQLException.class, () -> { - try (Connection conn = DriverManager.getConnection( - "jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_RULE.getHost() + ":" + FLIGHT_SERVER_TEST_RULE.getPort(), - properties)) { - Assert.fail(); - } - }); + SQLException e = + assertThrows( + SQLException.class, + () -> { + try (Connection conn = + DriverManager.getConnection( + "jdbc:arrow-flight-sql://" + + FLIGHT_SERVER_TEST_RULE.getHost() + + ":" + + FLIGHT_SERVER_TEST_RULE.getPort(), + properties)) { + Assert.fail(); + } + }); assertTrue(e.getMessage().contains("UNAUTHENTICATED")); } - /** - * Checks if the exception SQLException is thrown when trying to establish a connection without a host. + * Checks if the exception SQLException is thrown when trying to establish a connection without a + * host. * * @throws SQLException on error. */ @Test(expected = SQLException.class) - public void testUnencryptedConnectionWithEmptyHost() - throws Exception { + public void testUnencryptedConnectionWithEmptyHost() throws Exception { final Properties properties = new Properties(); properties.put("user", userTest); @@ -159,43 +160,38 @@ public void testUnencryptedConnectionWithEmptyHost() * @throws URISyntaxException on error. */ @Test - public void testGetBasicClientAuthenticatedShouldOpenConnection() - throws Exception { + public void testGetBasicClientAuthenticatedShouldOpenConnection() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withEncryption(false) - .withUsername(userTest) - .withPassword(passTest) - .withBufferAllocator(allocator) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withEncryption(false) + .withUsername(userTest) + .withPassword(passTest) + .withBufferAllocator(allocator) + .build()) { assertNotNull(client); } } /** - * Checks if the exception IllegalArgumentException is thrown when trying to establish an unencrypted - * connection providing with an invalid port. + * Checks if the exception IllegalArgumentException is thrown when trying to establish an + * unencrypted connection providing with an invalid port. * * @throws SQLException on error. */ @Test(expected = SQLException.class) - public void testUnencryptedConnectionProvidingInvalidPort() - throws Exception { + public void testUnencryptedConnectionProvidingInvalidPort() throws Exception { final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); - properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), - false); - final String invalidUrl = "jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_RULE.getHost() + - ":" + 65537; + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); + properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false); + final String invalidUrl = + "jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_RULE.getHost() + ":" + 65537; try (Connection conn = DriverManager.getConnection(invalidUrl, properties)) { fail("Expected SQLException"); @@ -211,18 +207,18 @@ public void testUnencryptedConnectionProvidingInvalidPort() public void testGetBasicClientNoAuthShouldOpenConnection() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withBufferAllocator(allocator) - .withEncryption(false) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withBufferAllocator(allocator) + .withEncryption(false) + .build()) { assertNotNull(client); } } /** - * Checks if an unencrypted connection can be established successfully when - * not providing credentials. + * Checks if an unencrypted connection can be established successfully when not providing + * credentials. * * @throws SQLException on error. */ @@ -231,19 +227,17 @@ public void testUnencryptedConnectionShouldOpenSuccessfullyWithoutAuthentication throws Exception { final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), - false); - try (Connection connection = DriverManager - .getConnection("jdbc:arrow-flight-sql://localhost:32010", properties)) { + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false); + try (Connection connection = + DriverManager.getConnection("jdbc:arrow-flight-sql://localhost:32010", properties)) { Assert.assertTrue(connection.isValid(300)); } } /** - * Check if an unencrypted connection throws an exception when provided with - * invalid credentials. + * Check if an unencrypted connection throws an exception when provided with invalid credentials. * * @throws SQLException The exception expected to be thrown. */ @@ -254,17 +248,14 @@ public void testUnencryptedConnectionShouldThrowExceptionWhenProvidedWithInvalid final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - "invalidUser"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), - false); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - "invalidPassword"); - - try (Connection ignored = DriverManager.getConnection("jdbc:arrow-flight-sql://localhost:32010", - properties)) { + properties.put(ArrowFlightConnectionProperty.USER.camelName(), "invalidUser"); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), "invalidPassword"); + + try (Connection ignored = + DriverManager.getConnection("jdbc:arrow-flight-sql://localhost:32010", properties)) { Assert.fail(); } } @@ -280,12 +271,11 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlWithDriverManager() thro final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=false", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest))) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=false", + FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest))) { Assert.assertTrue(connection.isValid(0)); } } @@ -297,24 +287,23 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlWithDriverManager() thro * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyFalseCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyFalseCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "false"); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } @@ -332,17 +321,15 @@ public void testTLSConnectionPropertyFalseCorrectCastUrlAndPropertiesUsingPutWit DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } @@ -359,70 +346,67 @@ public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlWithDriverManager final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=0", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest))) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=0", + FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest))) { Assert.assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with String K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "0"); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with Object K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyFalseIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), 0); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } @@ -439,73 +423,69 @@ public void testThreadPoolSizeConnectionPropertyCorrectCastUrlWithDriverManager( final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&threadPoolSize=1&useEncryption=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - false))) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&threadPoolSize=1&useEncryption=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest, false))) { Assert.assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with String K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.THREAD_POOL_SIZE.camelName(), "1"); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with Object K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testThreadPoolSizeConnectionPropertyCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.THREAD_POOL_SIZE.camelName(), 1); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } @@ -522,71 +502,67 @@ public void testPasswordConnectionPropertyIntegerCorrectCastUrlWithDriverManager final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - false))) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s&useEncryption=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), userTest, passTest, false))) { Assert.assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with String K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** * Check if an non-encrypted connection can be established successfully when connecting through - * the DriverManager using a connection url and properties with Object K-V pairs and using - * 0 and 1 as ssl values. + * the DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 + * as ssl values. * * @throws Exception on error. */ @Test - public void testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testPasswordConnectionPropertyIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put("useEncryption", false); - try (Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsRootCertsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsRootCertsTest.java index e5ffc2bcf79..8a142ba2646 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsRootCertsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsRootCertsTest.java @@ -26,7 +26,6 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; @@ -41,14 +40,10 @@ import org.junit.ClassRule; import org.junit.Test; - -/** - * Tests encrypted connections. - */ +/** Tests encrypted connections. */ public class ConnectionTlsRootCertsTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final String tlsRootCertsPath; private static final String badTlsRootCertsPath; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); @@ -56,22 +51,22 @@ public class ConnectionTlsRootCertsTest { private static final String passTest = "pass1"; static { - final FlightSqlTestCertificates.CertKeyPair - certKey = FlightSqlTestCertificates.exampleTlsCerts().get(0); + final FlightSqlTestCertificates.CertKeyPair certKey = + FlightSqlTestCertificates.exampleTlsCerts().get(0); tlsRootCertsPath = certKey.cert.getPath(); badTlsRootCertsPath = certKey.cert.getPath() + ".bad"; - UserPasswordAuthentication authentication = new UserPasswordAuthentication.Builder() - .user(userTest, passTest) - .build(); + UserPasswordAuthentication authentication = + new UserPasswordAuthentication.Builder().user(userTest, passTest).build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .useEncryption(certKey.cert, certKey.key) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .useEncryption(certKey.cert, certKey.key) + .producer(PRODUCER) + .build(); } private BufferAllocator allocator; @@ -96,35 +91,38 @@ public void tearDown() throws Exception { public void testGetEncryptedClientAuthenticated() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withTlsRootCertificates(tlsRootCertsPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withTlsRootCertificates(tlsRootCertsPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } /** - * Try to instantiate an encrypted FlightClient providing a bad TLS Root Certs Path. It's expected to - * receive the SQLException. + * Try to instantiate an encrypted FlightClient providing a bad TLS Root Certs Path. It's expected + * to receive the SQLException. */ @Test public void testGetEncryptedClientWithNoCertificateOnKeyStore() { - assertThrows(SQLException.class, () -> { - try (ArrowFlightSqlClientHandler handler = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withTlsRootCertificates(badTlsRootCertsPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { - Assert.fail(); - } - }); + assertThrows( + SQLException.class, + () -> { + try (ArrowFlightSqlClientHandler handler = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withTlsRootCertificates(badTlsRootCertsPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { + Assert.fail(); + } + }); } /** @@ -135,19 +133,19 @@ public void testGetEncryptedClientWithNoCertificateOnKeyStore() { @Test public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withTlsRootCertificates(tlsRootCertsPath) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withTlsRootCertificates(tlsRootCertsPath) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } /** - * Check if an encrypted connection can be established successfully when the - * provided valid credentials and a valid TLS Root Certs path. + * Check if an encrypted connection can be established successfully when the provided valid + * credentials and a valid TLS Root Certs path. * * @throws Exception on error. */ @@ -156,14 +154,11 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); - properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), - tlsRootCertsPath); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); + properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); @@ -173,8 +168,8 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro } /** - * Check if an encrypted connection can be established successfully when not - * providing authentication. + * Check if an encrypted connection can be established successfully when not providing + * authentication. * * @throws Exception on error. */ @@ -182,20 +177,23 @@ public void testGetEncryptedConnectionWithValidCredentialsAndTlsRootsPath() thro public void testGetNonAuthenticatedEncryptedConnection() throws Exception { final Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); + final ArrowFlightJdbcDataSource dataSource = + ArrowFlightJdbcDataSource.createNewDataSource(properties); try (final Connection connection = dataSource.getConnection()) { Assert.assertTrue(connection.isValid(300)); } } /** - * Check if an encrypted connection can be established successfully when connecting through - * the DriverManager using just a connection url. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url. * * @throws Exception on error. */ @@ -204,28 +202,30 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=true&%s=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), - URLEncoder.encode(tlsRootCertsPath, "UTF-8")))) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=true&%s=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), + userTest, + passTest, + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), + URLEncoder.encode(tlsRootCertsPath, "UTF-8")))) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -233,21 +233,22 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); - properties.setProperty(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.setProperty( + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "true"); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs. * * @throws Exception on error. */ @@ -264,18 +265,18 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * just a connection url and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url and using 0 and 1 as ssl values. * * @throws Exception on error. */ @@ -285,28 +286,31 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager( final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=1&useSystemTrustStore=0&%s=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), - URLEncoder.encode(tlsRootCertsPath, "UTF-8")))) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=1&useSystemTrustStore=0&%s=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), + userTest, + passTest, + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), + URLEncoder.encode(tlsRootCertsPath, "UTF-8")))) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -314,25 +318,30 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); - properties.setProperty(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); + properties.setProperty( + ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "1"); - try (final Connection connection = DriverManager.getConnection( - String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -343,10 +352,11 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), 1); properties.put(ArrowFlightConnectionProperty.TLS_ROOT_CERTS.camelName(), tlsRootCertsPath); - try (final Connection connection = DriverManager.getConnection( - String.format("jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java index f5a7b68e06c..0d6adee2d46 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTlsTest.java @@ -26,7 +26,6 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler; import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; @@ -42,30 +41,27 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Tests encrypted connections. - */ +/** Tests encrypted connections. */ public class ConnectionTlsTest { - @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE; private static final MockFlightSqlProducer PRODUCER = new MockFlightSqlProducer(); private static final String userTest = "user1"; private static final String passTest = "pass1"; static { - final FlightSqlTestCertificates.CertKeyPair - certKey = FlightSqlTestCertificates.exampleTlsCerts().get(0); + final FlightSqlTestCertificates.CertKeyPair certKey = + FlightSqlTestCertificates.exampleTlsCerts().get(0); - UserPasswordAuthentication authentication = new UserPasswordAuthentication.Builder() - .user(userTest, passTest) - .build(); + UserPasswordAuthentication authentication = + new UserPasswordAuthentication.Builder().user(userTest, passTest).build(); - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(authentication) - .useEncryption(certKey.cert, certKey.key) - .producer(PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(authentication) + .useEncryption(certKey.cert, certKey.key) + .producer(PRODUCER) + .build(); } private String trustStorePath; @@ -75,10 +71,14 @@ public class ConnectionTlsTest { @Before public void setUp() throws Exception { - trustStorePath = Paths.get( - Preconditions.checkNotNull(getClass().getResource("/keys/keyStore.jks")).toURI()).toString(); - noCertificateKeyStorePath = Paths.get( - Preconditions.checkNotNull(getClass().getResource("/keys/noCertificate.jks")).toURI()).toString(); + trustStorePath = + Paths.get(Preconditions.checkNotNull(getClass().getResource("/keys/keyStore.jks")).toURI()) + .toString(); + noCertificateKeyStorePath = + Paths.get( + Preconditions.checkNotNull(getClass().getResource("/keys/noCertificate.jks")) + .toURI()) + .toString(); allocator = new RootAllocator(Long.MAX_VALUE); } @@ -97,15 +97,15 @@ public void tearDown() throws Exception { public void testGetEncryptedClientAuthenticatedWithDisableCertVerification() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withUsername(userTest) - .withPassword(passTest) - .withDisableCertificateVerification(true) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withUsername(userTest) + .withPassword(passTest) + .withDisableCertificateVerification(true) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } @@ -119,24 +119,24 @@ public void testGetEncryptedClientAuthenticatedWithDisableCertVerification() thr public void testGetEncryptedClientAuthenticated() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withSystemTrustStore(false) - .withUsername(userTest) - .withPassword(passTest) - .withTrustStorePath(trustStorePath) - .withTrustStorePassword(trustStorePass) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withSystemTrustStore(false) + .withUsername(userTest) + .withPassword(passTest) + .withTrustStorePath(trustStorePath) + .withTrustStorePassword(trustStorePass) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } /** - * Try to instantiate an encrypted FlightClient providing a keystore without certificate. It's expected to - * receive the SQLException. + * Try to instantiate an encrypted FlightClient providing a keystore without certificate. It's + * expected to receive the SQLException. * * @throws Exception on error. */ @@ -145,14 +145,14 @@ public void testGetEncryptedClientWithNoCertificateOnKeyStore() throws Exception final String noCertificateKeyStorePassword = "flight1"; try (ArrowFlightSqlClientHandler ignored = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withTrustStorePath(noCertificateKeyStorePath) - .withTrustStorePassword(noCertificateKeyStorePassword) - .withSystemTrustStore(false) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withTrustStorePath(noCertificateKeyStorePath) + .withTrustStorePassword(noCertificateKeyStorePassword) + .withSystemTrustStore(false) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { Assert.fail(); } } @@ -165,14 +165,14 @@ public void testGetEncryptedClientWithNoCertificateOnKeyStore() throws Exception @Test public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception { try (ArrowFlightSqlClientHandler client = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withSystemTrustStore(false) - .withTrustStorePath(trustStorePath) - .withTrustStorePassword(trustStorePass) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withSystemTrustStore(false) + .withTrustStorePath(trustStorePath) + .withTrustStorePassword(trustStorePass) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { assertNotNull(client); } } @@ -188,21 +188,21 @@ public void testGetEncryptedClientWithKeyStoreBadPasswordAndNoAuth() throws Exce String keyStoreBadPassword = "badPassword"; try (ArrowFlightSqlClientHandler ignored = - new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withSystemTrustStore(false) - .withTrustStorePath(trustStorePath) - .withTrustStorePassword(keyStoreBadPassword) - .withBufferAllocator(allocator) - .withEncryption(true) - .build()) { + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withSystemTrustStore(false) + .withTrustStorePath(trustStorePath) + .withTrustStorePassword(keyStoreBadPassword) + .withBufferAllocator(allocator) + .withEncryption(true) + .build()) { Assert.fail(); } } /** - * Check if an encrypted connection can be established successfully when the - * provided valid credentials and a valid Keystore. + * Check if an encrypted connection can be established successfully when the provided valid + * credentials and a valid Keystore. * * @throws Exception on error. */ @@ -211,12 +211,10 @@ public void testGetEncryptedConnectionWithValidCredentialsAndKeyStore() throws E final Properties properties = new Properties(); properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost"); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), false); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); @@ -229,8 +227,8 @@ public void testGetEncryptedConnectionWithValidCredentialsAndKeyStore() throws E } /** - * Check if the SQLException is thrown when trying to establish an encrypted connection - * providing valid credentials but invalid password to the Keystore. + * Check if the SQLException is thrown when trying to establish an encrypted connection providing + * valid credentials but invalid password to the Keystore. * * @throws SQLException on error. */ @@ -238,14 +236,12 @@ public void testGetEncryptedConnectionWithValidCredentialsAndKeyStore() throws E public void testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword() throws Exception { final Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.HOST.camelName(), - FLIGHT_SERVER_TEST_RULE.getHost()); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), - FLIGHT_SERVER_TEST_RULE.getPort()); - properties.put(ArrowFlightConnectionProperty.USER.camelName(), - userTest); - properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), - passTest); + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest); + properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), "badpassword"); @@ -258,7 +254,8 @@ public void testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword() thr } /** - * Check if an encrypted connection can be established successfully when not providing authentication. + * Check if an encrypted connection can be established successfully when not providing + * authentication. * * @throws Exception on error. */ @@ -266,22 +263,25 @@ public void testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword() thr public void testGetNonAuthenticatedEncryptedConnection() throws Exception { final Properties properties = new Properties(); - properties.put(ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); - properties.put(ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); + properties.put( + ArrowFlightConnectionProperty.HOST.camelName(), FLIGHT_SERVER_TEST_RULE.getHost()); + properties.put( + ArrowFlightConnectionProperty.PORT.camelName(), FLIGHT_SERVER_TEST_RULE.getPort()); properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), true); properties.put(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), false); properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); - final ArrowFlightJdbcDataSource dataSource = ArrowFlightJdbcDataSource.createNewDataSource(properties); + final ArrowFlightJdbcDataSource dataSource = + ArrowFlightJdbcDataSource.createNewDataSource(properties); try (final Connection connection = dataSource.getConnection()) { Assert.assertTrue(connection.isValid(300)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * just a connection url. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url. * * @throws Exception on error. */ @@ -290,30 +290,32 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlWithDriverManager() throw final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=true&useSystemTrustStore=false&%s=%s&%s=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - ArrowFlightConnectionProperty.TRUST_STORE.camelName(), - URLEncoder.encode(trustStorePath, "UTF-8"), - ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), - URLEncoder.encode(trustStorePass, "UTF-8")))) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=true&useSystemTrustStore=false&%s=%s&%s=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), + userTest, + passTest, + ArrowFlightConnectionProperty.TRUST_STORE.camelName(), + URLEncoder.encode(trustStorePath, "UTF-8"), + ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), + URLEncoder.encode(trustStorePass, "UTF-8")))) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -322,22 +324,24 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingSetProp properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); - properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); + properties.setProperty( + ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "true"); - properties.setProperty(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), "false"); - - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + properties.setProperty( + ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), "false"); + + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs. * * @throws Exception on error. */ @@ -356,18 +360,18 @@ public void testTLSConnectionPropertyTrueCorrectCastUrlAndPropertiesUsingPutWith properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * just a connection url and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using just a connection url and using 0 and 1 as ssl values. * * @throws Exception on error. */ @@ -377,30 +381,33 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlWithDriverManager( final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); - try (final Connection connection = DriverManager.getConnection( - String.format( - "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + - "&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s", - FLIGHT_SERVER_TEST_RULE.getPort(), - userTest, - passTest, - ArrowFlightConnectionProperty.TRUST_STORE.camelName(), - URLEncoder.encode(trustStorePath, "UTF-8"), - ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), - URLEncoder.encode(trustStorePass, "UTF-8")))) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s?user=%s&password=%s" + + "&useEncryption=1&useSystemTrustStore=0&%s=%s&%s=%s", + FLIGHT_SERVER_TEST_RULE.getPort(), + userTest, + passTest, + ArrowFlightConnectionProperty.TRUST_STORE.camelName(), + URLEncoder.encode(trustStorePath, "UTF-8"), + ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), + URLEncoder.encode(trustStorePass, "UTF-8")))) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with String K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with String K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingSetPropertyWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -409,26 +416,31 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.setProperty(ArrowFlightConnectionProperty.USER.camelName(), userTest); properties.setProperty(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest); properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); - properties.setProperty(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); + properties.setProperty( + ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); properties.setProperty(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), "1"); properties.setProperty(ArrowFlightConnectionProperty.USE_SYSTEM_TRUST_STORE.camelName(), "0"); - try (final Connection connection = DriverManager.getConnection( - String.format("jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } /** - * Check if an encrypted connection can be established successfully when connecting through the DriverManager using - * a connection url and properties with Object K-V pairs and using 0 and 1 as ssl values. + * Check if an encrypted connection can be established successfully when connecting through the + * DriverManager using a connection url and properties with Object K-V pairs and using 0 and 1 as + * ssl values. * * @throws Exception on error. */ @Test - public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() - throws Exception { + public void + testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsingPutWithDriverManager() + throws Exception { final Driver driver = new ArrowFlightJdbcDriver(); DriverManager.registerDriver(driver); @@ -441,10 +453,11 @@ public void testTLSConnectionPropertyTrueIntegerCorrectCastUrlAndPropertiesUsing properties.put(ArrowFlightConnectionProperty.TRUST_STORE.camelName(), trustStorePath); properties.put(ArrowFlightConnectionProperty.TRUST_STORE_PASSWORD.camelName(), trustStorePass); - try (final Connection connection = DriverManager.getConnection( - String.format("jdbc:arrow-flight-sql://localhost:%s", - FLIGHT_SERVER_TEST_RULE.getPort()), - properties)) { + try (final Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://localhost:%s", FLIGHT_SERVER_TEST_RULE.getPort()), + properties)) { Assert.assertTrue(connection.isValid(0)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/FlightServerTestRule.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/FlightServerTestRule.java index 39eb0a29866..e794250c344 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/FlightServerTestRule.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/FlightServerTestRule.java @@ -27,7 +27,6 @@ import java.util.ArrayDeque; import java.util.Deque; import java.util.Properties; - import org.apache.arrow.driver.jdbc.authentication.Authentication; import org.apache.arrow.driver.jdbc.authentication.TokenAuthentication; import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication; @@ -51,8 +50,8 @@ import org.slf4j.LoggerFactory; /** - * Utility class for unit tests that need to instantiate a {@link FlightServer} - * and interact with it. + * Utility class for unit tests that need to instantiate a {@link FlightServer} and interact with + * it. */ public class FlightServerTestRule implements TestRule, AutoCloseable { public static final String DEFAULT_USER = "flight-test-user"; @@ -70,13 +69,14 @@ public class FlightServerTestRule implements TestRule, AutoCloseable { private final MiddlewareCookie.Factory middlewareCookieFactory = new MiddlewareCookie.Factory(); - private FlightServerTestRule(final Properties properties, - final ArrowFlightConnectionConfigImpl config, - final BufferAllocator allocator, - final FlightSqlProducer producer, - final Authentication authentication, - final CertKeyPair certKeyPair, - final File mTlsCACert) { + private FlightServerTestRule( + final Properties properties, + final ArrowFlightConnectionConfigImpl config, + final BufferAllocator allocator, + final FlightSqlProducer producer, + final Authentication authentication, + final CertKeyPair certKeyPair, + final File mTlsCACert) { this.properties = Preconditions.checkNotNull(properties); this.config = Preconditions.checkNotNull(config); this.allocator = Preconditions.checkNotNull(allocator); @@ -94,14 +94,9 @@ private FlightServerTestRule(final Properties properties, */ public static FlightServerTestRule createStandardTestRule(final FlightSqlProducer producer) { UserPasswordAuthentication authentication = - new UserPasswordAuthentication.Builder() - .user(DEFAULT_USER, DEFAULT_PASSWORD) - .build(); - - return new Builder() - .authentication(authentication) - .producer(producer) - .build(); + new UserPasswordAuthentication.Builder().user(DEFAULT_USER, DEFAULT_PASSWORD).build(); + + return new Builder().authentication(authentication).producer(producer).build(); } ArrowFlightJdbcDataSource createDataSource() { @@ -112,7 +107,8 @@ public ArrowFlightJdbcConnectionPoolDataSource createConnectionPoolDataSource() return ArrowFlightJdbcConnectionPoolDataSource.createNewDataSource(properties); } - public ArrowFlightJdbcConnectionPoolDataSource createConnectionPoolDataSource(boolean useEncryption) { + public ArrowFlightJdbcConnectionPoolDataSource createConnectionPoolDataSource( + boolean useEncryption) { setUseEncryption(useEncryption); return ArrowFlightJdbcConnectionPoolDataSource.createNewDataSource(properties); } @@ -142,9 +138,10 @@ public interface CheckedFunction { } private FlightServer initiateServer(Location location) throws IOException { - FlightServer.Builder builder = FlightServer.builder(allocator, location, producer) - .headerAuthenticator(authentication.authenticate()) - .middleware(FlightServerMiddleware.Key.of("KEY"), middlewareCookieFactory); + FlightServer.Builder builder = + FlightServer.builder(allocator, location, producer) + .headerAuthenticator(authentication.authenticate()) + .middleware(FlightServerMiddleware.Key.of("KEY"), middlewareCookieFactory); if (certKeyPair != null) { builder.useTls(certKeyPair.cert, certKeyPair.key); } @@ -170,12 +167,13 @@ public void evaluate() throws Throwable { }; } - private FlightServer getStartServer(CheckedFunction newServerFromLocation, - int retries) + private FlightServer getStartServer( + CheckedFunction newServerFromLocation, int retries) throws IOException { final Deque exceptions = new ArrayDeque<>(); for (; retries > 0; retries--) { - final FlightServer server = newServerFromLocation.apply(Location.forGrpcInsecure("localhost", 0)); + final FlightServer server = + newServerFromLocation.apply(Location.forGrpcInsecure("localhost", 0)); try { Method start = server.getClass().getMethod("start"); start.setAccessible(true); @@ -213,9 +211,7 @@ public void close() throws Exception { AutoCloseables.close(allocator); } - /** - * Builder for {@link FlightServerTestRule}. - */ + /** Builder for {@link FlightServerTestRule}. */ public static final class Builder { private final Properties properties; private FlightSqlProducer producer; @@ -240,9 +236,8 @@ public Builder producer(final FlightSqlProducer producer) { } /** - * Sets the type of the authentication that will be used in the server rules. - * There are two types of authentication: {@link UserPasswordAuthentication} and - * {@link TokenAuthentication}. + * Sets the type of the authentication that will be used in the server rules. There are two + * types of authentication: {@link UserPasswordAuthentication} and {@link TokenAuthentication}. * * @param authentication the type of authentication. * @return the Builder. @@ -256,7 +251,7 @@ public Builder authentication(final Authentication authentication) { * Enable TLS on the server. * * @param certChain The certificate chain to use. - * @param key The private key to use. + * @param key The private key to use. * @return the Builder. */ public Builder useEncryption(final File certChain, final File key) { @@ -282,14 +277,20 @@ public Builder useMTlsClientVerification(final File mTlsCACert) { */ public FlightServerTestRule build() { authentication.populateProperties(properties); - return new FlightServerTestRule(properties, new ArrowFlightConnectionConfigImpl(properties), - new RootAllocator(Long.MAX_VALUE), producer, authentication, certKeyPair, mTlsCACert); + return new FlightServerTestRule( + properties, + new ArrowFlightConnectionConfigImpl(properties), + new RootAllocator(Long.MAX_VALUE), + producer, + authentication, + certKeyPair, + mTlsCACert); } } /** - * A middleware to handle with the cookies in the server. It is used to test if cookies are - * being sent properly. + * A middleware to handle with the cookies in the server. It is used to test if cookies are being + * sent properly. */ static class MiddlewareCookie implements FlightServerMiddleware { @@ -307,26 +308,20 @@ public void onBeforeSendingHeaders(CallHeaders callHeaders) { } @Override - public void onCallCompleted(CallStatus callStatus) { - - } + public void onCallCompleted(CallStatus callStatus) {} @Override - public void onCallErrored(Throwable throwable) { + public void onCallErrored(Throwable throwable) {} - } - - /** - * A factory for the MiddlewareCookie. - */ + /** A factory for the MiddlewareCookie. */ static class Factory implements FlightServerMiddleware.Factory { private boolean receivedCookieHeader = false; private String cookie; @Override - public MiddlewareCookie onCallStarted(CallInfo callInfo, CallHeaders callHeaders, - RequestContext requestContext) { + public MiddlewareCookie onCallStarted( + CallInfo callInfo, CallHeaders callHeaders, RequestContext requestContext) { cookie = callHeaders.get("Cookie"); receivedCookieHeader = null != cookie; return new MiddlewareCookie(this); @@ -337,5 +332,4 @@ public String getCookie() { } } } - } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetMetadataTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetMetadataTest.java index 64ec7f7d9e1..a20d4457c1e 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetMetadataTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetMetadataTest.java @@ -26,7 +26,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; - import org.apache.arrow.driver.jdbc.utils.CoreMockedSqlProducers; import org.hamcrest.CoreMatchers; import org.junit.AfterClass; @@ -42,20 +41,19 @@ public class ResultSetMetadataTest { private static Connection connection; - @Rule - public ErrorCollector collector = new ErrorCollector(); + @Rule public ErrorCollector collector = new ErrorCollector(); @ClassRule - public static final FlightServerTestRule SERVER_TEST_RULE = FlightServerTestRule - .createStandardTestRule(CoreMockedSqlProducers.getLegacyProducer()); + public static final FlightServerTestRule SERVER_TEST_RULE = + FlightServerTestRule.createStandardTestRule(CoreMockedSqlProducers.getLegacyProducer()); @BeforeClass public static void setup() throws SQLException { connection = SERVER_TEST_RULE.getConnection(false); try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_METADATA_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_METADATA_SQL_CMD)) { metadata = resultSet.getMetaData(); } } @@ -65,9 +63,7 @@ public static void teardown() throws SQLException { connection.close(); } - /** - * Test if {@link ResultSetMetaData} object is not null. - */ + /** Test if {@link ResultSetMetaData} object is not null. */ @Test public void testShouldGetResultSetMetadata() { collector.checkThat(metadata, CoreMatchers.is(notNullValue())); @@ -86,7 +82,7 @@ public void testShouldGetColumnCount() throws SQLException { } /** - * Test if {@link ResultSetMetaData#getColumnTypeName(int)} returns the correct type name for each + * Test if {@link ResultSetMetaData#getColumnTypeName(int)} returns the correct type name for each * column. * * @throws SQLException in case of error. @@ -103,7 +99,8 @@ public void testShouldGetColumnTypesName() throws SQLException { } /** - * Test if {@link ResultSetMetaData#getColumnTypeName(int)} passing an column index that does not exist. + * Test if {@link ResultSetMetaData#getColumnTypeName(int)} passing an column index that does not + * exist. * * @throws SQLException in case of error. */ @@ -130,9 +127,9 @@ public void testShouldGetColumnNames() throws SQLException { collector.checkThat(thirdColumn, equalTo("float2")); } - /** - * Test {@link ResultSetMetaData#getColumnTypeName(int)} passing an column index that does not exist. + * Test {@link ResultSetMetaData#getColumnTypeName(int)} passing an column index that does not + * exist. * * @throws SQLException in case of error. */ @@ -223,7 +220,8 @@ public void testShouldIsSearchable() throws SQLException { } /** - * Test if {@link ResultSetMetaData#getColumnTypeName(int)} passing an column index that does not exist. + * Test if {@link ResultSetMetaData#getColumnTypeName(int)} passing an column index that does not + * exist. * * @throws SQLException in case of error. */ diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java index 231371a923a..873058d0118 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ResultSetTest.java @@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.google.common.collect.ImmutableSet; import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; @@ -44,7 +45,6 @@ import java.util.Random; import java.util.Set; import java.util.concurrent.CountDownLatch; - import org.apache.arrow.driver.jdbc.utils.CoreMockedSqlProducers; import org.apache.arrow.driver.jdbc.utils.PartitionedFlightSqlProducer; import org.apache.arrow.flight.FlightEndpoint; @@ -65,17 +65,16 @@ import org.junit.Test; import org.junit.rules.ErrorCollector; -import com.google.common.collect.ImmutableSet; - public class ResultSetTest { private static final Random RANDOM = new Random(10); + @ClassRule - public static final FlightServerTestRule SERVER_TEST_RULE = FlightServerTestRule - .createStandardTestRule(CoreMockedSqlProducers.getLegacyProducer()); + public static final FlightServerTestRule SERVER_TEST_RULE = + FlightServerTestRule.createStandardTestRule(CoreMockedSqlProducers.getLegacyProducer()); + private static Connection connection; - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); @BeforeClass public static void setup() throws SQLException { @@ -106,8 +105,8 @@ private static void setMaxRowsLimit(int maxRowsLimit, Statement statement) throw @Test public void testShouldRunSelectQuery() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { CoreMockedSqlProducers.assertLegacyRegularSqlResultSet(resultSet, collector); } } @@ -115,8 +114,8 @@ public void testShouldRunSelectQuery() throws Exception { @Test public void testShouldExecuteQueryNotBlockIfClosedBeforeEnd() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { for (int i = 0; i < 7500; i++) { assertTrue(resultSet.next()); @@ -125,16 +124,16 @@ public void testShouldExecuteQueryNotBlockIfClosedBeforeEnd() throws Exception { } /** - * Tests whether the {@link ArrowFlightJdbcDriver} query only returns only the - * amount of value set by {@link org.apache.calcite.avatica.AvaticaStatement#setMaxRows(int)}. + * Tests whether the {@link ArrowFlightJdbcDriver} query only returns only the amount of value set + * by {@link org.apache.calcite.avatica.AvaticaStatement#setMaxRows(int)}. * * @throws Exception If the connection fails to be established. */ @Test public void testShouldRunSelectQuerySettingMaxRowLimit() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { final int maxRowsLimit = 3; statement.setMaxRows(maxRowsLimit); @@ -155,8 +154,7 @@ public void testShouldRunSelectQuerySettingMaxRowLimit() throws Exception { } /** - * Tests whether the {@link ArrowFlightJdbcDriver} fails upon attempting - * to run an invalid query. + * Tests whether the {@link ArrowFlightJdbcDriver} fails upon attempting to run an invalid query. * * @throws Exception If the connection fails to be established. */ @@ -164,22 +162,22 @@ public void testShouldRunSelectQuerySettingMaxRowLimit() throws Exception { public void testShouldThrowExceptionUponAttemptingToExecuteAnInvalidSelectQuery() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet result = statement.executeQuery("SELECT * FROM SHOULD-FAIL")) { + ResultSet result = statement.executeQuery("SELECT * FROM SHOULD-FAIL")) { fail(); } } /** - * Tests whether the {@link ArrowFlightJdbcDriver} query only returns only the - * amount of value set by {@link org.apache.calcite.avatica.AvaticaStatement#setLargeMaxRows(long)} (int)}. + * Tests whether the {@link ArrowFlightJdbcDriver} query only returns only the amount of value set + * by {@link org.apache.calcite.avatica.AvaticaStatement#setLargeMaxRows(long)} (int)}. * * @throws Exception If the connection fails to be established. */ @Test public void testShouldRunSelectQuerySettingLargeMaxRowLimit() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { final long maxRowsLimit = 3; statement.setLargeMaxRows(maxRowsLimit); @@ -203,8 +201,8 @@ public void testColumnCountShouldRemainConsistentForResultSetThroughoutEntireDur throws SQLException { final Set counts = new HashSet<>(); try (final Statement statement = connection.createStatement(); - final ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + final ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { while (resultSet.next()) { counts.add(resultSet.getMetaData().getColumnCount()); } @@ -221,7 +219,8 @@ public void testColumnCountShouldRemainConsistentForResultSetThroughoutEntireDur @Test public void testShouldCloseStatementWhenIsCloseOnCompletion() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { statement.closeOnCompletion(); @@ -232,15 +231,17 @@ public void testShouldCloseStatementWhenIsCloseOnCompletion() throws Exception { } /** - * Tests whether the {@link ArrowFlightJdbcDriver} close the statement after complete ResultSet with max rows limit - * when call {@link org.apache.calcite.avatica.AvaticaStatement#closeOnCompletion()}. + * Tests whether the {@link ArrowFlightJdbcDriver} close the statement after complete ResultSet + * with max rows limit when call {@link + * org.apache.calcite.avatica.AvaticaStatement#closeOnCompletion()}. * * @throws Exception If the connection fails to be established. */ @Test public void testShouldCloseStatementWhenIsCloseOnCompletionWithMaxRowsLimit() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { final long maxRowsLimit = 3; statement.setLargeMaxRows(maxRowsLimit); @@ -253,8 +254,9 @@ public void testShouldCloseStatementWhenIsCloseOnCompletionWithMaxRowsLimit() th } /** - * Tests whether the {@link ArrowFlightJdbcDriver} not close the statement after complete ResultSet with max rows - * limit when call {@link org.apache.calcite.avatica.AvaticaStatement#closeOnCompletion()}. + * Tests whether the {@link ArrowFlightJdbcDriver} not close the statement after complete + * ResultSet with max rows limit when call {@link + * org.apache.calcite.avatica.AvaticaStatement#closeOnCompletion()}. * * @throws Exception If the connection fails to be established. */ @@ -262,8 +264,8 @@ public void testShouldCloseStatementWhenIsCloseOnCompletionWithMaxRowsLimit() th public void testShouldNotCloseStatementWhenIsNotCloseOnCompletionWithMaxRowsLimit() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { final long maxRowsLimit = 3; statement.setLargeMaxRows(maxRowsLimit); @@ -278,8 +280,8 @@ public void testShouldNotCloseStatementWhenIsNotCloseOnCompletionWithMaxRowsLimi @Test public void testShouldCancelQueryUponCancelAfterQueryingResultSet() throws SQLException { try (final Statement statement = connection.createStatement(); - final ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + final ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { final int column = RANDOM.nextInt(resultSet.getMetaData().getColumnCount()) + 1; collector.checkThat(resultSet.isClosed(), is(false)); collector.checkThat(resultSet.next(), is(true)); @@ -298,20 +300,22 @@ public void testShouldInterruptFlightStreamsIfQueryIsCancelledMidQuerying() try (final Statement statement = connection.createStatement()) { final CountDownLatch latch = new CountDownLatch(1); final Set exceptions = synchronizedSet(new HashSet<>(1)); - final Thread thread = new Thread(() -> { - try (final ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { - final int cachedColumnCount = resultSet.getMetaData().getColumnCount(); - Thread.sleep(300); - while (resultSet.next()) { - resultSet.getObject(RANDOM.nextInt(cachedColumnCount) + 1); - } - } catch (final SQLException | InterruptedException e) { - exceptions.add(e); - } finally { - latch.countDown(); - } - }); + final Thread thread = + new Thread( + () -> { + try (final ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + final int cachedColumnCount = resultSet.getMetaData().getColumnCount(); + Thread.sleep(300); + while (resultSet.next()) { + resultSet.getObject(RANDOM.nextInt(cachedColumnCount) + 1); + } + } catch (final SQLException | InterruptedException e) { + exceptions.add(e); + } finally { + latch.countDown(); + } + }); thread.setName("Test Case: interrupt query execution before first retrieval"); thread.start(); statement.cancel(); @@ -328,18 +332,21 @@ public void testShouldInterruptFlightStreamsIfQueryIsCancelledMidQuerying() } @Test - public void testShouldInterruptFlightStreamsIfQueryIsCancelledMidProcessingForTimeConsumingQueries() - throws SQLException, InterruptedException { + public void + testShouldInterruptFlightStreamsIfQueryIsCancelledMidProcessingForTimeConsumingQueries() + throws SQLException, InterruptedException { final String query = CoreMockedSqlProducers.LEGACY_CANCELLATION_SQL_CMD; try (final Statement statement = connection.createStatement()) { final Set exceptions = synchronizedSet(new HashSet<>(1)); - final Thread thread = new Thread(() -> { - try (final ResultSet ignored = statement.executeQuery(query)) { - fail(); - } catch (final SQLException e) { - exceptions.add(e); - } - }); + final Thread thread = + new Thread( + () -> { + try (final ResultSet ignored = statement.executeQuery(query)) { + fail(); + } catch (final SQLException e) { + exceptions.add(e); + } + }); thread.setName("Test Case: interrupt query execution mid-process"); thread.setPriority(Thread.MAX_PRIORITY); thread.start(); @@ -353,8 +360,10 @@ public void testShouldInterruptFlightStreamsIfQueryIsCancelledMidProcessingForTi .reduce(StringBuilder::append) .orElseThrow(IllegalStateException::new) .toString(), - anyOf(is(format("Error while executing SQL \"%s\": Query canceled", query)), - allOf(containsString(format("Error while executing SQL \"%s\"", query)), + anyOf( + is(format("Error while executing SQL \"%s\": Query canceled", query)), + allOf( + containsString(format("Error while executing SQL \"%s\"", query)), containsString("CANCELLED")))); } } @@ -372,14 +381,11 @@ public void testShouldInterruptFlightStreamsIfQueryTimeoutIsOver() throws SQLExc } catch (final Exception e) { exceptions.add(e); } - final Throwable comparisonCause = exceptions.stream() - .findFirst() - .orElseThrow(RuntimeException::new) - .getCause() - .getCause(); - collector.checkThat(comparisonCause, - is(instanceOf(SQLTimeoutException.class))); - collector.checkThat(comparisonCause.getMessage(), + final Throwable comparisonCause = + exceptions.stream().findFirst().orElseThrow(RuntimeException::new).getCause().getCause(); + collector.checkThat(comparisonCause, is(instanceOf(SQLTimeoutException.class))); + collector.checkThat( + comparisonCause.getMessage(), is(format("Query timed out after %d %s", timeoutValue, timeoutUnit))); } } @@ -399,8 +405,9 @@ public void testFlightStreamsQueryShouldNotTimeout() throws SQLException { @Test public void testPartitionedFlightServer() throws Exception { // Arrange - final Schema schema = new Schema( - Arrays.asList(Field.nullablePrimitive("int_column", new ArrowType.Int(32, true)))); + final Schema schema = + new Schema( + Arrays.asList(Field.nullablePrimitive("int_column", new ArrowType.Int(32, true)))); try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); VectorSchemaRoot firstPartition = VectorSchemaRoot.create(schema, allocator); VectorSchemaRoot secondPartition = VectorSchemaRoot.create(schema, allocator)) { @@ -410,20 +417,22 @@ public void testPartitionedFlightServer() throws Exception { ((IntVector) secondPartition.getVector(0)).set(0, 2); // Construct the data-only nodes first. - FlightProducer firstProducer = new PartitionedFlightSqlProducer.DataOnlyFlightSqlProducer( - new Ticket("first".getBytes()), firstPartition); - FlightProducer secondProducer = new PartitionedFlightSqlProducer.DataOnlyFlightSqlProducer( - new Ticket("second".getBytes()), secondPartition); + FlightProducer firstProducer = + new PartitionedFlightSqlProducer.DataOnlyFlightSqlProducer( + new Ticket("first".getBytes()), firstPartition); + FlightProducer secondProducer = + new PartitionedFlightSqlProducer.DataOnlyFlightSqlProducer( + new Ticket("second".getBytes()), secondPartition); - final FlightServer.Builder firstBuilder = FlightServer.builder( - allocator, forGrpcInsecure("localhost", 0), firstProducer); + final FlightServer.Builder firstBuilder = + FlightServer.builder(allocator, forGrpcInsecure("localhost", 0), firstProducer); - final FlightServer.Builder secondBuilder = FlightServer.builder( - allocator, forGrpcInsecure("localhost", 0), secondProducer); + final FlightServer.Builder secondBuilder = + FlightServer.builder(allocator, forGrpcInsecure("localhost", 0), secondProducer); // Run the data-only nodes so that we can get the Locations they are running at. try (FlightServer firstServer = firstBuilder.build(); - FlightServer secondServer = secondBuilder.build()) { + FlightServer secondServer = secondBuilder.build()) { firstServer.start(); secondServer.start(); final FlightEndpoint firstEndpoint = @@ -433,25 +442,28 @@ public void testPartitionedFlightServer() throws Exception { new FlightEndpoint(new Ticket("second".getBytes()), secondServer.getLocation()); // Finally start the root node. - try (final PartitionedFlightSqlProducer rootProducer = new PartitionedFlightSqlProducer( - schema, firstEndpoint, secondEndpoint); - FlightServer rootServer = FlightServer.builder( - allocator, forGrpcInsecure("localhost", 0), rootProducer) - .build() - .start(); - Connection newConnection = DriverManager.getConnection(String.format( - "jdbc:arrow-flight-sql://%s:%d/?useEncryption=false", - rootServer.getLocation().getUri().getHost(), rootServer.getPort())); - Statement newStatement = newConnection.createStatement(); - // Act - ResultSet result = newStatement.executeQuery("Select partitioned_data")) { + try (final PartitionedFlightSqlProducer rootProducer = + new PartitionedFlightSqlProducer(schema, firstEndpoint, secondEndpoint); + FlightServer rootServer = + FlightServer.builder(allocator, forGrpcInsecure("localhost", 0), rootProducer) + .build() + .start(); + Connection newConnection = + DriverManager.getConnection( + String.format( + "jdbc:arrow-flight-sql://%s:%d/?useEncryption=false", + rootServer.getLocation().getUri().getHost(), rootServer.getPort())); + Statement newStatement = newConnection.createStatement(); + // Act + ResultSet result = newStatement.executeQuery("Select partitioned_data")) { List resultData = new ArrayList<>(); while (result.next()) { resultData.add(result.getInt(1)); } // Assert - assertEquals(firstPartition.getRowCount() + secondPartition.getRowCount(), resultData.size()); + assertEquals( + firstPartition.getRowCount() + secondPartition.getRowCount(), resultData.size()); assertTrue(resultData.contains(((IntVector) firstPartition.getVector(0)).get(0))); assertTrue(resultData.contains(((IntVector) secondPartition.getVector(0)).get(0))); } @@ -462,8 +474,8 @@ allocator, forGrpcInsecure("localhost", 0), rootProducer) @Test public void testShouldRunSelectQueryWithEmptyVectorsEmbedded() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_WITH_EMPTY_SQL_CMD)) { + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_WITH_EMPTY_SQL_CMD)) { long rowCount = 0; while (resultSet.next()) { ++rowCount; @@ -475,10 +487,11 @@ public void testShouldRunSelectQueryWithEmptyVectorsEmbedded() throws Exception @Test public void testResultSetAppMetadata() throws Exception { try (Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( - CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { - assertArrayEquals(((ArrowFlightJdbcFlightStreamResultSet) resultSet).getAppMetadata(), - "foo".getBytes(StandardCharsets.UTF_8)); + ResultSet resultSet = + statement.executeQuery(CoreMockedSqlProducers.LEGACY_REGULAR_SQL_CMD)) { + assertArrayEquals( + ((ArrowFlightJdbcFlightStreamResultSet) resultSet).getAppMetadata(), + "foo".getBytes(StandardCharsets.UTF_8)); } } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/TokenAuthenticationTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/TokenAuthenticationTest.java index 9fe506231ec..7525cf14670 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/TokenAuthenticationTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/TokenAuthenticationTest.java @@ -19,7 +19,6 @@ import java.sql.Connection; import java.sql.SQLException; - import org.apache.arrow.driver.jdbc.authentication.TokenAuthentication; import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer; import org.apache.arrow.util.AutoCloseables; @@ -31,16 +30,14 @@ public class TokenAuthenticationTest { private static final MockFlightSqlProducer FLIGHT_SQL_PRODUCER = new MockFlightSqlProducer(); - @ClassRule - public static FlightServerTestRule FLIGHT_SERVER_TEST_RULE; + @ClassRule public static FlightServerTestRule FLIGHT_SERVER_TEST_RULE; static { - FLIGHT_SERVER_TEST_RULE = new FlightServerTestRule.Builder() - .authentication(new TokenAuthentication.Builder() - .token("1234") - .build()) - .producer(FLIGHT_SQL_PRODUCER) - .build(); + FLIGHT_SERVER_TEST_RULE = + new FlightServerTestRule.Builder() + .authentication(new TokenAuthentication.Builder().token("1234").build()) + .producer(FLIGHT_SQL_PRODUCER) + .build(); } @AfterClass diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorFactoryTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorFactoryTest.java index 4b3744372c0..6c222bdeead 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorFactoryTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorFactoryTest.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc.accessor; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.impl.binary.ArrowFlightJdbcBinaryVectorAccessor; import org.apache.arrow.driver.jdbc.accessor.impl.calendar.ArrowFlightJdbcDateVectorAccessor; import org.apache.arrow.driver.jdbc.accessor.impl.calendar.ArrowFlightJdbcDurationVectorAccessor; @@ -66,9 +65,8 @@ public class ArrowFlightJdbcAccessorFactoryTest { public void createAccessorForUInt1Vector() { try (ValueVector valueVector = rootAllocatorTestRule.createUInt1Vector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBaseIntVectorAccessor); } @@ -78,9 +76,8 @@ public void createAccessorForUInt1Vector() { public void createAccessorForUInt2Vector() { try (ValueVector valueVector = rootAllocatorTestRule.createUInt2Vector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBaseIntVectorAccessor); } @@ -90,9 +87,8 @@ public void createAccessorForUInt2Vector() { public void createAccessorForUInt4Vector() { try (ValueVector valueVector = rootAllocatorTestRule.createUInt4Vector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBaseIntVectorAccessor); } @@ -102,9 +98,8 @@ public void createAccessorForUInt4Vector() { public void createAccessorForUInt8Vector() { try (ValueVector valueVector = rootAllocatorTestRule.createUInt8Vector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBaseIntVectorAccessor); } @@ -114,9 +109,8 @@ public void createAccessorForUInt8Vector() { public void createAccessorForTinyIntVector() { try (ValueVector valueVector = rootAllocatorTestRule.createTinyIntVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBaseIntVectorAccessor); } @@ -126,9 +120,8 @@ public void createAccessorForTinyIntVector() { public void createAccessorForSmallIntVector() { try (ValueVector valueVector = rootAllocatorTestRule.createSmallIntVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBaseIntVectorAccessor); } @@ -138,9 +131,8 @@ public void createAccessorForSmallIntVector() { public void createAccessorForIntVector() { try (ValueVector valueVector = rootAllocatorTestRule.createIntVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBaseIntVectorAccessor); } @@ -150,9 +142,8 @@ public void createAccessorForIntVector() { public void createAccessorForBigIntVector() { try (ValueVector valueVector = rootAllocatorTestRule.createBigIntVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBaseIntVectorAccessor); } @@ -162,9 +153,8 @@ public void createAccessorForBigIntVector() { public void createAccessorForFloat4Vector() { try (ValueVector valueVector = rootAllocatorTestRule.createFloat4Vector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcFloat4VectorAccessor); } @@ -174,9 +164,8 @@ public void createAccessorForFloat4Vector() { public void createAccessorForFloat8Vector() { try (ValueVector valueVector = rootAllocatorTestRule.createFloat8Vector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcFloat8VectorAccessor); } @@ -186,9 +175,8 @@ public void createAccessorForFloat8Vector() { public void createAccessorForBitVector() { try (ValueVector valueVector = rootAllocatorTestRule.createBitVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBitVectorAccessor); } @@ -198,9 +186,8 @@ public void createAccessorForBitVector() { public void createAccessorForDecimalVector() { try (ValueVector valueVector = rootAllocatorTestRule.createDecimalVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcDecimalVectorAccessor); } @@ -210,9 +197,8 @@ public void createAccessorForDecimalVector() { public void createAccessorForDecimal256Vector() { try (ValueVector valueVector = rootAllocatorTestRule.createDecimal256Vector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcDecimalVectorAccessor); } @@ -222,9 +208,8 @@ public void createAccessorForDecimal256Vector() { public void createAccessorForVarBinaryVector() { try (ValueVector valueVector = rootAllocatorTestRule.createVarBinaryVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBinaryVectorAccessor); } @@ -234,9 +219,8 @@ public void createAccessorForVarBinaryVector() { public void createAccessorForLargeVarBinaryVector() { try (ValueVector valueVector = rootAllocatorTestRule.createLargeVarBinaryVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBinaryVectorAccessor); } @@ -246,9 +230,8 @@ public void createAccessorForLargeVarBinaryVector() { public void createAccessorForFixedSizeBinaryVector() { try (ValueVector valueVector = rootAllocatorTestRule.createFixedSizeBinaryVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcBinaryVectorAccessor); } @@ -258,9 +241,8 @@ public void createAccessorForFixedSizeBinaryVector() { public void createAccessorForTimeStampVector() { try (ValueVector valueVector = rootAllocatorTestRule.createTimeStampMilliVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcTimeStampVectorAccessor); } @@ -270,9 +252,8 @@ public void createAccessorForTimeStampVector() { public void createAccessorForTimeNanoVector() { try (ValueVector valueVector = rootAllocatorTestRule.createTimeNanoVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcTimeVectorAccessor); } @@ -282,9 +263,8 @@ public void createAccessorForTimeNanoVector() { public void createAccessorForTimeMicroVector() { try (ValueVector valueVector = rootAllocatorTestRule.createTimeMicroVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcTimeVectorAccessor); } @@ -294,9 +274,8 @@ public void createAccessorForTimeMicroVector() { public void createAccessorForTimeMilliVector() { try (ValueVector valueVector = rootAllocatorTestRule.createTimeMilliVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcTimeVectorAccessor); } @@ -306,9 +285,8 @@ public void createAccessorForTimeMilliVector() { public void createAccessorForTimeSecVector() { try (ValueVector valueVector = rootAllocatorTestRule.createTimeSecVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcTimeVectorAccessor); } @@ -318,9 +296,8 @@ public void createAccessorForTimeSecVector() { public void createAccessorForDateDayVector() { try (ValueVector valueVector = rootAllocatorTestRule.createDateDayVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcDateVectorAccessor); } @@ -330,9 +307,8 @@ public void createAccessorForDateDayVector() { public void createAccessorForDateMilliVector() { try (ValueVector valueVector = rootAllocatorTestRule.createDateMilliVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcDateVectorAccessor); } @@ -340,12 +316,11 @@ public void createAccessorForDateMilliVector() { @Test public void createAccessorForVarCharVector() { - try ( - ValueVector valueVector = new VarCharVector("", rootAllocatorTestRule.getRootAllocator())) { + try (ValueVector valueVector = + new VarCharVector("", rootAllocatorTestRule.getRootAllocator())) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcVarCharVectorAccessor); } @@ -353,12 +328,11 @@ public void createAccessorForVarCharVector() { @Test public void createAccessorForLargeVarCharVector() { - try (ValueVector valueVector = new LargeVarCharVector("", - rootAllocatorTestRule.getRootAllocator())) { + try (ValueVector valueVector = + new LargeVarCharVector("", rootAllocatorTestRule.getRootAllocator())) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcVarCharVectorAccessor); } @@ -367,13 +341,13 @@ public void createAccessorForLargeVarCharVector() { @Test public void createAccessorForDurationVector() { try (ValueVector valueVector = - new DurationVector("", - new FieldType(true, new ArrowType.Duration(TimeUnit.MILLISECOND), null), - rootAllocatorTestRule.getRootAllocator())) { + new DurationVector( + "", + new FieldType(true, new ArrowType.Duration(TimeUnit.MILLISECOND), null), + rootAllocatorTestRule.getRootAllocator())) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcDurationVectorAccessor); } @@ -381,12 +355,11 @@ public void createAccessorForDurationVector() { @Test public void createAccessorForIntervalDayVector() { - try (ValueVector valueVector = new IntervalDayVector("", - rootAllocatorTestRule.getRootAllocator())) { + try (ValueVector valueVector = + new IntervalDayVector("", rootAllocatorTestRule.getRootAllocator())) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcIntervalVectorAccessor); } @@ -394,12 +367,11 @@ public void createAccessorForIntervalDayVector() { @Test public void createAccessorForIntervalYearVector() { - try (ValueVector valueVector = new IntervalYearVector("", - rootAllocatorTestRule.getRootAllocator())) { + try (ValueVector valueVector = + new IntervalYearVector("", rootAllocatorTestRule.getRootAllocator())) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcIntervalVectorAccessor); } @@ -407,12 +379,11 @@ public void createAccessorForIntervalYearVector() { @Test public void createAccessorForUnionVector() { - try (ValueVector valueVector = new UnionVector("", rootAllocatorTestRule.getRootAllocator(), - null, null)) { + try (ValueVector valueVector = + new UnionVector("", rootAllocatorTestRule.getRootAllocator(), null, null)) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcUnionVectorAccessor); } @@ -420,13 +391,11 @@ public void createAccessorForUnionVector() { @Test public void createAccessorForDenseUnionVector() { - try ( - ValueVector valueVector = new DenseUnionVector("", rootAllocatorTestRule.getRootAllocator(), - null, null)) { + try (ValueVector valueVector = + new DenseUnionVector("", rootAllocatorTestRule.getRootAllocator(), null, null)) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcDenseUnionVectorAccessor); } @@ -434,12 +403,11 @@ public void createAccessorForDenseUnionVector() { @Test public void createAccessorForStructVector() { - try (ValueVector valueVector = StructVector.empty("", - rootAllocatorTestRule.getRootAllocator())) { + try (ValueVector valueVector = + StructVector.empty("", rootAllocatorTestRule.getRootAllocator())) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcStructVectorAccessor); } @@ -449,9 +417,8 @@ public void createAccessorForStructVector() { public void createAccessorForListVector() { try (ValueVector valueVector = rootAllocatorTestRule.createListVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcListVectorAccessor); } @@ -461,9 +428,8 @@ public void createAccessorForListVector() { public void createAccessorForLargeListVector() { try (ValueVector valueVector = rootAllocatorTestRule.createLargeListVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcLargeListVectorAccessor); } @@ -473,9 +439,8 @@ public void createAccessorForLargeListVector() { public void createAccessorForFixedSizeListVector() { try (ValueVector valueVector = rootAllocatorTestRule.createFixedSizeListVector()) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcFixedSizeListVectorAccessor); } @@ -483,12 +448,11 @@ public void createAccessorForFixedSizeListVector() { @Test public void createAccessorForMapVector() { - try (ValueVector valueVector = MapVector.empty("", rootAllocatorTestRule.getRootAllocator(), - true)) { + try (ValueVector valueVector = + MapVector.empty("", rootAllocatorTestRule.getRootAllocator(), true)) { ArrowFlightJdbcAccessor accessor = - ArrowFlightJdbcAccessorFactory.createAccessor(valueVector, GET_CURRENT_ROW, - (boolean wasNull) -> { - }); + ArrowFlightJdbcAccessorFactory.createAccessor( + valueVector, GET_CURRENT_ROW, (boolean wasNull) -> {}); Assert.assertTrue(accessor instanceof ArrowFlightJdbcMapVectorAccessor); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java index 099b0122179..491226d1776 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java @@ -25,7 +25,6 @@ import java.sql.SQLException; import java.util.HashMap; import java.util.Map; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -38,8 +37,7 @@ public class ArrowFlightJdbcAccessorTest { static class MockedArrowFlightJdbcAccessor extends ArrowFlightJdbcAccessor { protected MockedArrowFlightJdbcAccessor() { - super(() -> 0, (boolean wasNull) -> { - }); + super(() -> 0, (boolean wasNull) -> {}); } @Override @@ -48,8 +46,7 @@ public Class getObjectClass() { } } - @Mock - MockedArrowFlightJdbcAccessor accessor; + @Mock MockedArrowFlightJdbcAccessor accessor; @Test public void testShouldGetObjectWithByteClassReturnGetByte() throws SQLException { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/ArrowFlightJdbcNullVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/ArrowFlightJdbcNullVectorAccessorTest.java index 57e7ecfe025..56f8adf704c 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/ArrowFlightJdbcNullVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/ArrowFlightJdbcNullVectorAccessorTest.java @@ -23,8 +23,7 @@ public class ArrowFlightJdbcNullVectorAccessorTest { ArrowFlightJdbcNullVectorAccessor accessor = - new ArrowFlightJdbcNullVectorAccessor((boolean wasNull) -> { - }); + new ArrowFlightJdbcNullVectorAccessor((boolean wasNull) -> {}); @Test public void testShouldWasNullReturnTrue() { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/binary/ArrowFlightJdbcBinaryVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/binary/ArrowFlightJdbcBinaryVectorAccessorTest.java index f4d256c4cf8..43132071047 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/binary/ArrowFlightJdbcBinaryVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/binary/ArrowFlightJdbcBinaryVectorAccessorTest.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -51,47 +50,53 @@ public class ArrowFlightJdbcBinaryVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private ValueVector vector; private final Supplier vectorSupplier; private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = (boolean wasNull) -> { - }; - if (vector instanceof VarBinaryVector) { - return new ArrowFlightJdbcBinaryVectorAccessor(((VarBinaryVector) vector), getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof LargeVarBinaryVector) { - return new ArrowFlightJdbcBinaryVectorAccessor(((LargeVarBinaryVector) vector), - getCurrentRow, noOpWasNullConsumer); - } else if (vector instanceof FixedSizeBinaryVector) { - return new ArrowFlightJdbcBinaryVectorAccessor(((FixedSizeBinaryVector) vector), - getCurrentRow, noOpWasNullConsumer); - } - return null; - }; + accessorSupplier = + (vector, getCurrentRow) -> { + ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = + (boolean wasNull) -> {}; + if (vector instanceof VarBinaryVector) { + return new ArrowFlightJdbcBinaryVectorAccessor( + ((VarBinaryVector) vector), getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof LargeVarBinaryVector) { + return new ArrowFlightJdbcBinaryVectorAccessor( + ((LargeVarBinaryVector) vector), getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof FixedSizeBinaryVector) { + return new ArrowFlightJdbcBinaryVectorAccessor( + ((FixedSizeBinaryVector) vector), getCurrentRow, noOpWasNullConsumer); + } + return null; + }; private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> rootAllocatorTestRule.createVarBinaryVector(), - "VarBinaryVector"}, - {(Supplier) () -> rootAllocatorTestRule.createLargeVarBinaryVector(), - "LargeVarBinaryVector"}, - {(Supplier) () -> rootAllocatorTestRule.createFixedSizeBinaryVector(), - "FixedSizeBinaryVector"}, - }); - } - - public ArrowFlightJdbcBinaryVectorAccessorTest(Supplier vectorSupplier, - String vectorType) { + return Arrays.asList( + new Object[][] { + { + (Supplier) () -> rootAllocatorTestRule.createVarBinaryVector(), + "VarBinaryVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createLargeVarBinaryVector(), + "LargeVarBinaryVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createFixedSizeBinaryVector(), + "FixedSizeBinaryVector" + }, + }); + } + + public ArrowFlightJdbcBinaryVectorAccessorTest( + Supplier vectorSupplier, String vectorType) { this.vectorSupplier = vectorSupplier; } @@ -107,7 +112,9 @@ public void tearDown() { @Test public void testShouldGetStringReturnExpectedString() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBinaryVectorAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBinaryVectorAccessor::getString, (accessor) -> is(new String(accessor.getBytes(), UTF_8))); } @@ -116,14 +123,15 @@ public void testShouldGetStringReturnNull() throws Exception { vector.reset(); vector.setValueCount(5); - accessorIterator - .assertAccessorGetter(vector, ArrowFlightJdbcBinaryVectorAccessor::getString, - CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcBinaryVectorAccessor::getString, CoreMatchers.nullValue()); } @Test public void testShouldGetBytesReturnExpectedByteArray() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBinaryVectorAccessor::getBytes, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBinaryVectorAccessor::getBytes, (accessor, currentRow) -> { if (vector instanceof VarBinaryVector) { return is(((VarBinaryVector) vector).get(currentRow)); @@ -148,7 +156,9 @@ public void testShouldGetBytesReturnNull() throws Exception { @Test public void testShouldGetObjectReturnAsGetBytes() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBinaryVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBinaryVectorAccessor::getObject, (accessor) -> is(accessor.getBytes())); } @@ -164,12 +174,14 @@ public void testShouldGetObjectReturnNull() { @Test public void testShouldGetUnicodeStreamReturnCorrectInputStream() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - InputStream inputStream = accessor.getUnicodeStream(); - String actualString = IOUtils.toString(inputStream, UTF_8); - collector.checkThat(accessor.wasNull(), is(false)); - collector.checkThat(actualString, is(accessor.getString())); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + InputStream inputStream = accessor.getUnicodeStream(); + String actualString = IOUtils.toString(inputStream, UTF_8); + collector.checkThat(accessor.wasNull(), is(false)); + collector.checkThat(actualString, is(accessor.getString())); + }); } @Test @@ -184,12 +196,14 @@ public void testShouldGetUnicodeStreamReturnNull() throws Exception { @Test public void testShouldGetAsciiStreamReturnCorrectInputStream() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - InputStream inputStream = accessor.getAsciiStream(); - String actualString = IOUtils.toString(inputStream, US_ASCII); - collector.checkThat(accessor.wasNull(), is(false)); - collector.checkThat(actualString, is(accessor.getString())); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + InputStream inputStream = accessor.getAsciiStream(); + String actualString = IOUtils.toString(inputStream, US_ASCII); + collector.checkThat(accessor.wasNull(), is(false)); + collector.checkThat(actualString, is(accessor.getString())); + }); } @Test @@ -204,12 +218,14 @@ public void testShouldGetAsciiStreamReturnNull() throws Exception { @Test public void testShouldGetBinaryStreamReturnCurrentInputStream() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - InputStream inputStream = accessor.getBinaryStream(); - String actualString = IOUtils.toString(inputStream, UTF_8); - collector.checkThat(accessor.wasNull(), is(false)); - collector.checkThat(actualString, is(accessor.getString())); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + InputStream inputStream = accessor.getBinaryStream(); + String actualString = IOUtils.toString(inputStream, UTF_8); + collector.checkThat(accessor.wasNull(), is(false)); + collector.checkThat(actualString, is(accessor.getString())); + }); } @Test @@ -224,12 +240,14 @@ public void testShouldGetBinaryStreamReturnNull() throws Exception { @Test public void testShouldGetCharacterStreamReturnCorrectReader() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - Reader characterStream = accessor.getCharacterStream(); - String actualString = IOUtils.toString(characterStream); - collector.checkThat(accessor.wasNull(), is(false)); - collector.checkThat(actualString, is(accessor.getString())); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + Reader characterStream = accessor.getCharacterStream(); + String actualString = IOUtils.toString(characterStream); + collector.checkThat(accessor.wasNull(), is(false)); + collector.checkThat(actualString, is(accessor.getString())); + }); } @Test diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessorTest.java index 36af5134626..54e8ecc3569 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDateVectorAccessorTest.java @@ -31,7 +31,6 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.impl.text.ArrowFlightJdbcVarCharVectorAccessor; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -58,42 +57,44 @@ public class ArrowFlightJdbcDateVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private BaseFixedWidthVector vector; private final Supplier vectorSupplier; private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - if (vector instanceof DateDayVector) { - return new ArrowFlightJdbcDateVectorAccessor((DateDayVector) vector, getCurrentRow, - (boolean wasNull) -> { - }); - } else if (vector instanceof DateMilliVector) { - return new ArrowFlightJdbcDateVectorAccessor((DateMilliVector) vector, getCurrentRow, - (boolean wasNull) -> { - }); - } - return null; - }; + accessorSupplier = + (vector, getCurrentRow) -> { + if (vector instanceof DateDayVector) { + return new ArrowFlightJdbcDateVectorAccessor( + (DateDayVector) vector, getCurrentRow, (boolean wasNull) -> {}); + } else if (vector instanceof DateMilliVector) { + return new ArrowFlightJdbcDateVectorAccessor( + (DateMilliVector) vector, getCurrentRow, (boolean wasNull) -> {}); + } + return null; + }; private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> rootAllocatorTestRule.createDateDayVector(), - "DateDayVector"}, - {(Supplier) () -> rootAllocatorTestRule.createDateMilliVector(), - "DateMilliVector"}, - }); + return Arrays.asList( + new Object[][] { + { + (Supplier) () -> rootAllocatorTestRule.createDateDayVector(), + "DateDayVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createDateMilliVector(), + "DateMilliVector" + }, + }); } - public ArrowFlightJdbcDateVectorAccessorTest(Supplier vectorSupplier, - String vectorType) { + public ArrowFlightJdbcDateVectorAccessorTest( + Supplier vectorSupplier, String vectorType) { this.vectorSupplier = vectorSupplier; } @@ -109,13 +110,17 @@ public void tearDown() { @Test public void testShouldGetTimestampReturnValidTimestampWithoutCalendar() throws Exception { - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getTimestamp(null), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getTimestamp(null), (accessor, currentRow) -> is(getTimestampForVector(currentRow))); } @Test public void testShouldGetObjectWithDateClassReturnValidDateWithoutCalendar() throws Exception { - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getObject(Date.class), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getObject(Date.class), (accessor, currentRow) -> is(new Date(getTimestampForVector(currentRow).getTime()))); } @@ -124,15 +129,17 @@ public void testShouldGetTimestampReturnValidTimestampWithCalendar() throws Exce TimeZone timeZone = TimeZone.getTimeZone(AMERICA_VANCOUVER); Calendar calendar = Calendar.getInstance(timeZone); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final Timestamp resultWithoutCalendar = accessor.getTimestamp(null); - final Timestamp result = accessor.getTimestamp(calendar); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final Timestamp resultWithoutCalendar = accessor.getTimestamp(null); + final Timestamp result = accessor.getTimestamp(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()); + long offset = timeZone.getOffset(resultWithoutCalendar.getTime()); - collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } @Test @@ -145,7 +152,9 @@ public void testShouldGetTimestampReturnNull() { @Test public void testShouldGetDateReturnValidDateWithoutCalendar() throws Exception { - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getDate(null), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getDate(null), (accessor, currentRow) -> is(new Date(getTimestampForVector(currentRow).getTime()))); } @@ -154,15 +163,17 @@ public void testShouldGetDateReturnValidDateWithCalendar() throws Exception { TimeZone timeZone = TimeZone.getTimeZone(AMERICA_VANCOUVER); Calendar calendar = Calendar.getInstance(timeZone); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final Date resultWithoutCalendar = accessor.getDate(null); - final Date result = accessor.getDate(calendar); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final Date resultWithoutCalendar = accessor.getDate(null); + final Date result = accessor.getDate(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()); + long offset = timeZone.getOffset(resultWithoutCalendar.getTime()); - collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } @Test @@ -190,9 +201,8 @@ private Timestamp getTimestampForVector(int currentRow) { @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator - .assertAccessorGetter(vector, ArrowFlightJdbcDateVectorAccessor::getObjectClass, - equalTo(Date.class)); + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcDateVectorAccessor::getObjectClass, equalTo(Date.class)); } @Test @@ -208,47 +218,51 @@ public void testShouldGetStringBeConsistentWithVarCharAccessorWithCalendar() thr @Test public void testValidateGetStringTimeZoneConsistency() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final TimeZone defaultTz = TimeZone.getDefault(); - try { - final String string = accessor.getString(); // Should always be UTC as no calendar is provided - - // Validate with UTC - Date date = accessor.getDate(null); - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - collector.checkThat(date.toString(), is(string)); - - // Validate with different TZ - TimeZone.setDefault(TimeZone.getTimeZone(AMERICA_VANCOUVER)); - collector.checkThat(date.toString(), not(string)); - - collector.checkThat(accessor.wasNull(), is(false)); - } finally { - // Set default Tz back - TimeZone.setDefault(defaultTz); - } - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final TimeZone defaultTz = TimeZone.getDefault(); + try { + final String string = + accessor.getString(); // Should always be UTC as no calendar is provided + + // Validate with UTC + Date date = accessor.getDate(null); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + collector.checkThat(date.toString(), is(string)); + + // Validate with different TZ + TimeZone.setDefault(TimeZone.getTimeZone(AMERICA_VANCOUVER)); + collector.checkThat(date.toString(), not(string)); + + collector.checkThat(accessor.wasNull(), is(false)); + } finally { + // Set default Tz back + TimeZone.setDefault(defaultTz); + } + }); } private void assertGetStringIsConsistentWithVarCharAccessor(Calendar calendar) throws Exception { - try (VarCharVector varCharVector = new VarCharVector("", - rootAllocatorTestRule.getRootAllocator())) { + try (VarCharVector varCharVector = + new VarCharVector("", rootAllocatorTestRule.getRootAllocator())) { varCharVector.allocateNew(1); ArrowFlightJdbcVarCharVectorAccessor varCharVectorAccessor = - new ArrowFlightJdbcVarCharVectorAccessor(varCharVector, () -> 0, (boolean wasNull) -> { - }); + new ArrowFlightJdbcVarCharVectorAccessor(varCharVector, () -> 0, (boolean wasNull) -> {}); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final String string = accessor.getString(); - varCharVector.set(0, new Text(string)); - varCharVector.setValueCount(1); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final String string = accessor.getString(); + varCharVector.set(0, new Text(string)); + varCharVector.setValueCount(1); - Date dateFromVarChar = varCharVectorAccessor.getDate(calendar); - Date date = accessor.getDate(calendar); + Date dateFromVarChar = varCharVectorAccessor.getDate(calendar); + Date date = accessor.getDate(calendar); - collector.checkThat(date, is(dateFromVarChar)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(date, is(dateFromVarChar)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDurationVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDurationVectorAccessorTest.java index 64ddb573f1b..b2895bc4679 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDurationVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcDurationVectorAccessorTest.java @@ -21,7 +21,6 @@ import static org.hamcrest.CoreMatchers.is; import java.time.Duration; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -41,20 +40,18 @@ public class ArrowFlightJdbcDurationVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private DurationVector vector; private final AccessorTestUtils.AccessorSupplier accessorSupplier = - (vector, getCurrentRow) -> new ArrowFlightJdbcDurationVectorAccessor((DurationVector) vector, - getCurrentRow, (boolean wasNull) -> { - }); + (vector, getCurrentRow) -> + new ArrowFlightJdbcDurationVectorAccessor( + (DurationVector) vector, getCurrentRow, (boolean wasNull) -> {}); private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Before public void setup() { @@ -75,7 +72,9 @@ public void tearDown() { @Test public void getObject() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDurationVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDurationVectorAccessor::getObject, (accessor, currentRow) -> is(Duration.ofDays(currentRow + 1))); } @@ -86,13 +85,17 @@ public void getObjectForNull() throws Exception { vector.setNull(i); } - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDurationVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDurationVectorAccessor::getObject, (accessor, currentRow) -> equalTo(null)); } @Test public void getString() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcAccessor::getString, (accessor, currentRow) -> is(Duration.ofDays(currentRow + 1).toString())); } @@ -103,13 +106,15 @@ public void getStringForNull() throws Exception { vector.setNull(i); } - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcAccessor::getString, - (accessor, currentRow) -> equalTo(null)); + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcAccessor::getString, (accessor, currentRow) -> equalTo(null)); } @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcAccessor::getObjectClass, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcAccessor::getObjectClass, (accessor, currentRow) -> equalTo(Duration.class)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessorTest.java index 322b7d40bd6..48f9539df1d 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcIntervalVectorAccessorTest.java @@ -27,7 +27,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -50,59 +49,68 @@ public class ArrowFlightJdbcIntervalVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private final Supplier vectorSupplier; private ValueVector vector; private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = (boolean wasNull) -> { - }; - if (vector instanceof IntervalDayVector) { - return new ArrowFlightJdbcIntervalVectorAccessor((IntervalDayVector) vector, - getCurrentRow, noOpWasNullConsumer); - } else if (vector instanceof IntervalYearVector) { - return new ArrowFlightJdbcIntervalVectorAccessor((IntervalYearVector) vector, - getCurrentRow, noOpWasNullConsumer); - } - return null; - }; + accessorSupplier = + (vector, getCurrentRow) -> { + ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = + (boolean wasNull) -> {}; + if (vector instanceof IntervalDayVector) { + return new ArrowFlightJdbcIntervalVectorAccessor( + (IntervalDayVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof IntervalYearVector) { + return new ArrowFlightJdbcIntervalVectorAccessor( + (IntervalYearVector) vector, getCurrentRow, noOpWasNullConsumer); + } + return null; + }; final AccessorTestUtils.AccessorIterator accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> { - IntervalDayVector vector = - new IntervalDayVector("", rootAllocatorTestRule.getRootAllocator()); - - int valueCount = 10; - vector.setValueCount(valueCount); - for (int i = 0; i < valueCount; i++) { - vector.set(i, i + 1, (i + 1) * 1000); - } - return vector; - }, "IntervalDayVector"}, - {(Supplier) () -> { - IntervalYearVector vector = - new IntervalYearVector("", rootAllocatorTestRule.getRootAllocator()); - - int valueCount = 10; - vector.setValueCount(valueCount); - for (int i = 0; i < valueCount; i++) { - vector.set(i, i + 1); - } - return vector; - }, "IntervalYearVector"}, - }); - } - - public ArrowFlightJdbcIntervalVectorAccessorTest(Supplier vectorSupplier, - String vectorType) { + return Arrays.asList( + new Object[][] { + { + (Supplier) + () -> { + IntervalDayVector vector = + new IntervalDayVector("", rootAllocatorTestRule.getRootAllocator()); + + int valueCount = 10; + vector.setValueCount(valueCount); + for (int i = 0; i < valueCount; i++) { + vector.set(i, i + 1, (i + 1) * 1000); + } + return vector; + }, + "IntervalDayVector" + }, + { + (Supplier) + () -> { + IntervalYearVector vector = + new IntervalYearVector("", rootAllocatorTestRule.getRootAllocator()); + + int valueCount = 10; + vector.setValueCount(valueCount); + for (int i = 0; i < valueCount; i++) { + vector.set(i, i + 1); + } + return vector; + }, + "IntervalYearVector" + }, + }); + } + + public ArrowFlightJdbcIntervalVectorAccessorTest( + Supplier vectorSupplier, String vectorType) { this.vectorSupplier = vectorSupplier; } @@ -118,21 +126,27 @@ public void tearDown() { @Test public void testShouldGetObjectReturnValidObject() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcIntervalVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcIntervalVectorAccessor::getObject, (accessor, currentRow) -> is(getExpectedObject(vector, currentRow))); } @Test public void testShouldGetObjectPassingObjectClassAsParameterReturnValidObject() throws Exception { Class objectClass = getExpectedObjectClassForVector(vector); - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getObject(objectClass), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getObject(objectClass), (accessor, currentRow) -> is(getExpectedObject(vector, currentRow))); } @Test public void testShouldGetObjectReturnNull() throws Exception { setAllNullOnVector(vector); - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcIntervalVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcIntervalVectorAccessor::getObject, (accessor, currentRow) -> equalTo(null)); } @@ -149,7 +163,7 @@ private String getStringOnVector(ValueVector vector, int index) { } @Test - public void testShouldGetIntervalYear( ) { + public void testShouldGetIntervalYear() { Assert.assertEquals("-002-00", formatIntervalYear(Period.parse("P-2Y"))); Assert.assertEquals("-001-01", formatIntervalYear(Period.parse("P-1Y-1M"))); Assert.assertEquals("-001-02", formatIntervalYear(Period.parse("P-1Y-2M"))); @@ -165,22 +179,30 @@ public void testShouldGetIntervalYear( ) { } @Test - public void testShouldGetIntervalDay( ) { + public void testShouldGetIntervalDay() { Assert.assertEquals("-001 00:00:00.000", formatIntervalDay(Duration.parse("PT-24H"))); Assert.assertEquals("+001 00:00:00.000", formatIntervalDay(Duration.parse("PT+24H"))); Assert.assertEquals("-000 01:00:00.000", formatIntervalDay(Duration.parse("PT-1H"))); - // "JDK-8054978: java.time.Duration.parse() fails for negative duration with 0 seconds and nanos" not fixed on JDK8 - //Assert.assertEquals("-000 01:00:00.001", formatIntervalDay(Duration.parse("PT-1H-0M-00.001S"))); - Assert.assertEquals("-000 01:00:00.001", formatIntervalDay(Duration.ofHours(-1).minusMillis(1))); + // "JDK-8054978: java.time.Duration.parse() fails for negative duration with 0 seconds and + // nanos" not fixed on JDK8 + // Assert.assertEquals("-000 01:00:00.001", + // formatIntervalDay(Duration.parse("PT-1H-0M-00.001S"))); + Assert.assertEquals( + "-000 01:00:00.001", formatIntervalDay(Duration.ofHours(-1).minusMillis(1))); Assert.assertEquals("-000 01:01:01.000", formatIntervalDay(Duration.parse("PT-1H-1M-1S"))); Assert.assertEquals("-000 02:02:02.002", formatIntervalDay(Duration.parse("PT-2H-2M-02.002S"))); - Assert.assertEquals("-000 23:59:59.999", formatIntervalDay(Duration.parse("PT-23H-59M-59.999S"))); - // "JDK-8054978: java.time.Duration.parse() fails for negative duration with 0 seconds and nanos" not fixed on JDK8 - //Assert.assertEquals("-000 11:59:00.100", formatIntervalDay(Duration.parse("PT-11H-59M-00.100S"))); - Assert.assertEquals("-000 11:59:00.100", + Assert.assertEquals( + "-000 23:59:59.999", formatIntervalDay(Duration.parse("PT-23H-59M-59.999S"))); + // "JDK-8054978: java.time.Duration.parse() fails for negative duration with 0 seconds and + // nanos" not fixed on JDK8 + // Assert.assertEquals("-000 11:59:00.100", + // formatIntervalDay(Duration.parse("PT-11H-59M-00.100S"))); + Assert.assertEquals( + "-000 11:59:00.100", formatIntervalDay(Duration.ofHours(-11).minusMinutes(59).minusMillis(100))); Assert.assertEquals("-000 05:02:03.000", formatIntervalDay(Duration.parse("PT-5H-2M-3S"))); - Assert.assertEquals("-000 22:22:22.222", formatIntervalDay(Duration.parse("PT-22H-22M-22.222S"))); + Assert.assertEquals( + "-000 22:22:22.222", formatIntervalDay(Duration.parse("PT-22H-22M-22.222S"))); Assert.assertEquals("+000 01:00:00.000", formatIntervalDay(Duration.parse("PT+1H"))); Assert.assertEquals("+000 01:00:00.001", formatIntervalDay(Duration.parse("PT+1H0M00.001S"))); Assert.assertEquals("+000 01:01:01.000", formatIntervalDay(Duration.parse("PT+1H1M1S"))); @@ -193,29 +215,32 @@ public void testShouldGetIntervalDay( ) { @Test public void testIntervalDayWithJodaPeriodObject() { - Assert.assertEquals("+1567 00:00:00.000", - formatIntervalDay(Duration.ofDays(1567))); - Assert.assertEquals("-1567 00:00:00.000", - formatIntervalDay(Duration.ofDays(-1567))); + Assert.assertEquals("+1567 00:00:00.000", formatIntervalDay(Duration.ofDays(1567))); + Assert.assertEquals("-1567 00:00:00.000", formatIntervalDay(Duration.ofDays(-1567))); } @Test public void testShouldGetStringReturnCorrectString() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcIntervalVectorAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcIntervalVectorAccessor::getString, (accessor, currentRow) -> is(getStringOnVector(vector, currentRow))); } @Test public void testShouldGetStringReturnNull() throws Exception { setAllNullOnVector(vector); - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcIntervalVectorAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcIntervalVectorAccessor::getString, (accessor, currentRow) -> equalTo(null)); } @Test public void testShouldGetObjectClassReturnCorrectClass() throws Exception { Class expectedObjectClass = getExpectedObjectClassForVector(vector); - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcIntervalVectorAccessor::getObjectClass, (accessor, currentRow) -> equalTo(expectedObjectClass)); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessorTest.java index 38d842724b9..495d0451bac 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessorTest.java @@ -32,7 +32,6 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.impl.text.ArrowFlightJdbcVarCharVectorAccessor; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -64,8 +63,7 @@ public class ArrowFlightJdbcTimeStampVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private final String timeZone; private TimeStampVector vector; @@ -73,81 +71,114 @@ public class ArrowFlightJdbcTimeStampVectorAccessorTest { private final AccessorTestUtils.AccessorSupplier accessorSupplier = - (vector, getCurrentRow) -> new ArrowFlightJdbcTimeStampVectorAccessor( - (TimeStampVector) vector, getCurrentRow, (boolean wasNull) -> { - }); + (vector, getCurrentRow) -> + new ArrowFlightJdbcTimeStampVectorAccessor( + (TimeStampVector) vector, getCurrentRow, (boolean wasNull) -> {}); private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1} - TimeZone: {2}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> rootAllocatorTestRule.createTimeStampNanoVector(), + return Arrays.asList( + new Object[][] { + { + (Supplier) () -> rootAllocatorTestRule.createTimeStampNanoVector(), "TimeStampNanoVector", - null}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampNanoTZVector("UTC"), + null + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampNanoTZVector("UTC"), "TimeStampNanoTZVector", - "UTC"}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampNanoTZVector( - AMERICA_VANCOUVER), + "UTC" + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampNanoTZVector(AMERICA_VANCOUVER), "TimeStampNanoTZVector", - AMERICA_VANCOUVER}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampNanoTZVector( - ASIA_BANGKOK), + AMERICA_VANCOUVER + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampNanoTZVector(ASIA_BANGKOK), "TimeStampNanoTZVector", - ASIA_BANGKOK}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampMicroVector(), + ASIA_BANGKOK + }, + { + (Supplier) () -> rootAllocatorTestRule.createTimeStampMicroVector(), "TimeStampMicroVector", - null}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampMicroTZVector( - "UTC"), + null + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampMicroTZVector("UTC"), "TimeStampMicroTZVector", - "UTC"}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampMicroTZVector( - AMERICA_VANCOUVER), + "UTC" + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampMicroTZVector(AMERICA_VANCOUVER), "TimeStampMicroTZVector", - AMERICA_VANCOUVER}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampMicroTZVector( - ASIA_BANGKOK), + AMERICA_VANCOUVER + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampMicroTZVector(ASIA_BANGKOK), "TimeStampMicroTZVector", - ASIA_BANGKOK}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampMilliVector(), + ASIA_BANGKOK + }, + { + (Supplier) () -> rootAllocatorTestRule.createTimeStampMilliVector(), "TimeStampMilliVector", - null}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampMilliTZVector( - "UTC"), + null + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampMilliTZVector("UTC"), "TimeStampMilliTZVector", - "UTC"}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampMilliTZVector( - AMERICA_VANCOUVER), + "UTC" + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampMilliTZVector(AMERICA_VANCOUVER), "TimeStampMilliTZVector", - AMERICA_VANCOUVER}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampMilliTZVector( - ASIA_BANGKOK), + AMERICA_VANCOUVER + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampMilliTZVector(ASIA_BANGKOK), "TimeStampMilliTZVector", - ASIA_BANGKOK}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampSecVector(), + ASIA_BANGKOK + }, + { + (Supplier) () -> rootAllocatorTestRule.createTimeStampSecVector(), "TimeStampSecVector", - null}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampSecTZVector("UTC"), + null + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampSecTZVector("UTC"), "TimeStampSecTZVector", - "UTC"}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampSecTZVector( - AMERICA_VANCOUVER), + "UTC" + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampSecTZVector(AMERICA_VANCOUVER), "TimeStampSecTZVector", - AMERICA_VANCOUVER}, - {(Supplier) () -> rootAllocatorTestRule.createTimeStampSecTZVector( - ASIA_BANGKOK), + AMERICA_VANCOUVER + }, + { + (Supplier) + () -> rootAllocatorTestRule.createTimeStampSecTZVector(ASIA_BANGKOK), "TimeStampSecTZVector", - ASIA_BANGKOK} - }); + ASIA_BANGKOK + } + }); } - public ArrowFlightJdbcTimeStampVectorAccessorTest(Supplier vectorSupplier, - String vectorType, - String timeZone) { + public ArrowFlightJdbcTimeStampVectorAccessorTest( + Supplier vectorSupplier, String vectorType, String timeZone) { this.vectorSupplier = vectorSupplier; this.timeZone = timeZone; } @@ -164,7 +195,9 @@ public void tearDown() { @Test public void testShouldGetTimestampReturnValidTimestampWithoutCalendar() throws Exception { - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getTimestamp(null), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getTimestamp(null), (accessor, currentRow) -> is(getTimestampForVector(currentRow))); } @@ -175,16 +208,19 @@ public void testShouldGetTimestampReturnValidTimestampWithCalendar() throws Exce TimeZone timeZoneForVector = getTimeZoneForVector(vector); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final Timestamp resultWithoutCalendar = accessor.getTimestamp(null); - final Timestamp result = accessor.getTimestamp(calendar); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final Timestamp resultWithoutCalendar = accessor.getTimestamp(null); + final Timestamp result = accessor.getTimestamp(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()) - - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); + long offset = + timeZone.getOffset(resultWithoutCalendar.getTime()) + - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); - collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } @Test @@ -197,7 +233,9 @@ public void testShouldGetTimestampReturnNull() { @Test public void testShouldGetDateReturnValidDateWithoutCalendar() throws Exception { - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getDate(null), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getDate(null), (accessor, currentRow) -> is(new Date(getTimestampForVector(currentRow).getTime()))); } @@ -208,16 +246,19 @@ public void testShouldGetDateReturnValidDateWithCalendar() throws Exception { TimeZone timeZoneForVector = getTimeZoneForVector(vector); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final Date resultWithoutCalendar = accessor.getDate(null); - final Date result = accessor.getDate(calendar); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final Date resultWithoutCalendar = accessor.getDate(null); + final Date result = accessor.getDate(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()) - - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); + long offset = + timeZone.getOffset(resultWithoutCalendar.getTime()) + - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); - collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } @Test @@ -230,7 +271,9 @@ public void testShouldGetDateReturnNull() { @Test public void testShouldGetTimeReturnValidTimeWithoutCalendar() throws Exception { - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getTime(null), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getTime(null), (accessor, currentRow) -> is(new Time(getTimestampForVector(currentRow).getTime()))); } @@ -241,16 +284,19 @@ public void testShouldGetTimeReturnValidTimeWithCalendar() throws Exception { TimeZone timeZoneForVector = getTimeZoneForVector(vector); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final Time resultWithoutCalendar = accessor.getTime(null); - final Time result = accessor.getTime(calendar); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final Time resultWithoutCalendar = accessor.getTime(null); + final Time result = accessor.getTime(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()) - - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); + long offset = + timeZone.getOffset(resultWithoutCalendar.getTime()) + - timeZoneForVector.getOffset(resultWithoutCalendar.getTime()); - collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } @Test @@ -278,9 +324,8 @@ private Timestamp getTimestampForVector(int currentRow) { @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, - ArrowFlightJdbcTimeStampVectorAccessor::getObjectClass, - equalTo(Timestamp.class)); + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcTimeStampVectorAccessor::getObjectClass, equalTo(Timestamp.class)); } @Test @@ -292,31 +337,34 @@ public void testShouldGetStringBeConsistentWithVarCharAccessorWithoutCalendar() public void testShouldGetStringBeConsistentWithVarCharAccessorWithCalendar() throws Exception { // Ignore for TimeStamp vectors with TZ, as VarChar accessor won't consider their TZ Assume.assumeTrue( - vector instanceof TimeStampNanoVector || vector instanceof TimeStampMicroVector || - vector instanceof TimeStampMilliVector || vector instanceof TimeStampSecVector); + vector instanceof TimeStampNanoVector + || vector instanceof TimeStampMicroVector + || vector instanceof TimeStampMilliVector + || vector instanceof TimeStampSecVector); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(AMERICA_VANCOUVER)); assertGetStringIsConsistentWithVarCharAccessor(calendar); } private void assertGetStringIsConsistentWithVarCharAccessor(Calendar calendar) throws Exception { - try (VarCharVector varCharVector = new VarCharVector("", - rootAllocatorTestRule.getRootAllocator())) { + try (VarCharVector varCharVector = + new VarCharVector("", rootAllocatorTestRule.getRootAllocator())) { varCharVector.allocateNew(1); ArrowFlightJdbcVarCharVectorAccessor varCharVectorAccessor = - new ArrowFlightJdbcVarCharVectorAccessor(varCharVector, () -> 0, (boolean wasNull) -> { - }); + new ArrowFlightJdbcVarCharVectorAccessor(varCharVector, () -> 0, (boolean wasNull) -> {}); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final String string = accessor.getString(); - varCharVector.set(0, new Text(string)); - varCharVector.setValueCount(1); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final String string = accessor.getString(); + varCharVector.set(0, new Text(string)); + varCharVector.setValueCount(1); - Timestamp timestampFromVarChar = varCharVectorAccessor.getTimestamp(calendar); - Timestamp timestamp = accessor.getTimestamp(calendar); + Timestamp timestampFromVarChar = varCharVectorAccessor.getTimestamp(calendar); + Timestamp timestamp = accessor.getTimestamp(calendar); - collector.checkThat(timestamp, is(timestampFromVarChar)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(timestamp, is(timestampFromVarChar)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessorTest.java index d2f7eb336af..d08a3a6bf6a 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessorTest.java @@ -31,7 +31,6 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.accessor.impl.text.ArrowFlightJdbcVarCharVectorAccessor; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; @@ -61,52 +60,60 @@ public class ArrowFlightJdbcTimeVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private BaseFixedWidthVector vector; private final Supplier vectorSupplier; private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = (boolean wasNull) -> { - }; - if (vector instanceof TimeNanoVector) { - return new ArrowFlightJdbcTimeVectorAccessor((TimeNanoVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof TimeMicroVector) { - return new ArrowFlightJdbcTimeVectorAccessor((TimeMicroVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof TimeMilliVector) { - return new ArrowFlightJdbcTimeVectorAccessor((TimeMilliVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof TimeSecVector) { - return new ArrowFlightJdbcTimeVectorAccessor((TimeSecVector) vector, getCurrentRow, - noOpWasNullConsumer); - } - return null; - }; + accessorSupplier = + (vector, getCurrentRow) -> { + ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = + (boolean wasNull) -> {}; + if (vector instanceof TimeNanoVector) { + return new ArrowFlightJdbcTimeVectorAccessor( + (TimeNanoVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof TimeMicroVector) { + return new ArrowFlightJdbcTimeVectorAccessor( + (TimeMicroVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof TimeMilliVector) { + return new ArrowFlightJdbcTimeVectorAccessor( + (TimeMilliVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof TimeSecVector) { + return new ArrowFlightJdbcTimeVectorAccessor( + (TimeSecVector) vector, getCurrentRow, noOpWasNullConsumer); + } + return null; + }; private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> rootAllocatorTestRule.createTimeNanoVector(), - "TimeNanoVector"}, - {(Supplier) () -> rootAllocatorTestRule.createTimeMicroVector(), - "TimeMicroVector"}, - {(Supplier) () -> rootAllocatorTestRule.createTimeMilliVector(), - "TimeMilliVector"}, - {(Supplier) () -> rootAllocatorTestRule.createTimeSecVector(), - "TimeSecVector"} - }); + return Arrays.asList( + new Object[][] { + { + (Supplier) () -> rootAllocatorTestRule.createTimeNanoVector(), + "TimeNanoVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createTimeMicroVector(), + "TimeMicroVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createTimeMilliVector(), + "TimeMilliVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createTimeSecVector(), + "TimeSecVector" + } + }); } - public ArrowFlightJdbcTimeVectorAccessorTest(Supplier vectorSupplier, - String vectorType) { + public ArrowFlightJdbcTimeVectorAccessorTest( + Supplier vectorSupplier, String vectorType) { this.vectorSupplier = vectorSupplier; } @@ -122,7 +129,9 @@ public void tearDown() { @Test public void testShouldGetTimestampReturnValidTimestampWithoutCalendar() throws Exception { - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getTimestamp(null), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getTimestamp(null), (accessor, currentRow) -> is(getTimestampForVector(currentRow))); } @@ -131,15 +140,17 @@ public void testShouldGetTimestampReturnValidTimestampWithCalendar() throws Exce TimeZone timeZone = TimeZone.getTimeZone(AMERICA_VANCOUVER); Calendar calendar = Calendar.getInstance(timeZone); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final Timestamp resultWithoutCalendar = accessor.getTimestamp(null); - final Timestamp result = accessor.getTimestamp(calendar); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final Timestamp resultWithoutCalendar = accessor.getTimestamp(null); + final Timestamp result = accessor.getTimestamp(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()); + long offset = timeZone.getOffset(resultWithoutCalendar.getTime()); - collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } @Test @@ -152,7 +163,9 @@ public void testShouldGetTimestampReturnNull() { @Test public void testShouldGetTimeReturnValidTimeWithoutCalendar() throws Exception { - accessorIterator.assertAccessorGetter(vector, accessor -> accessor.getTime(null), + accessorIterator.assertAccessorGetter( + vector, + accessor -> accessor.getTime(null), (accessor, currentRow) -> { Timestamp expectedTimestamp = getTimestampForVector(currentRow); return is(new Time(expectedTimestamp.getTime())); @@ -164,15 +177,17 @@ public void testShouldGetTimeReturnValidTimeWithCalendar() throws Exception { TimeZone timeZone = TimeZone.getTimeZone(AMERICA_VANCOUVER); Calendar calendar = Calendar.getInstance(timeZone); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final Time resultWithoutCalendar = accessor.getTime(null); - final Time result = accessor.getTime(calendar); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final Time resultWithoutCalendar = accessor.getTime(null); + final Time result = accessor.getTime(calendar); - long offset = timeZone.getOffset(resultWithoutCalendar.getTime()); + long offset = timeZone.getOffset(resultWithoutCalendar.getTime()); - collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(resultWithoutCalendar.getTime() - result.getTime(), is(offset)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } @Test @@ -200,8 +215,8 @@ private Timestamp getTimestampForVector(int currentRow) { @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcTimeVectorAccessor::getObjectClass, - equalTo(Time.class)); + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcTimeVectorAccessor::getObjectClass, equalTo(Time.class)); } @Test @@ -217,47 +232,51 @@ public void testShouldGetStringBeConsistentWithVarCharAccessorWithCalendar() thr @Test public void testValidateGetStringTimeZoneConsistency() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final TimeZone defaultTz = TimeZone.getDefault(); - try { - final String string = accessor.getString(); // Should always be UTC as no calendar is provided - - // Validate with UTC - Time time = accessor.getTime(null); - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - collector.checkThat(time.toString(), is(string)); - - // Validate with different TZ - TimeZone.setDefault(TimeZone.getTimeZone(AMERICA_VANCOUVER)); - collector.checkThat(time.toString(), not(string)); - - collector.checkThat(accessor.wasNull(), is(false)); - } finally { - // Set default Tz back - TimeZone.setDefault(defaultTz); - } - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final TimeZone defaultTz = TimeZone.getDefault(); + try { + final String string = + accessor.getString(); // Should always be UTC as no calendar is provided + + // Validate with UTC + Time time = accessor.getTime(null); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + collector.checkThat(time.toString(), is(string)); + + // Validate with different TZ + TimeZone.setDefault(TimeZone.getTimeZone(AMERICA_VANCOUVER)); + collector.checkThat(time.toString(), not(string)); + + collector.checkThat(accessor.wasNull(), is(false)); + } finally { + // Set default Tz back + TimeZone.setDefault(defaultTz); + } + }); } private void assertGetStringIsConsistentWithVarCharAccessor(Calendar calendar) throws Exception { - try (VarCharVector varCharVector = new VarCharVector("", - rootAllocatorTestRule.getRootAllocator())) { + try (VarCharVector varCharVector = + new VarCharVector("", rootAllocatorTestRule.getRootAllocator())) { varCharVector.allocateNew(1); ArrowFlightJdbcVarCharVectorAccessor varCharVectorAccessor = - new ArrowFlightJdbcVarCharVectorAccessor(varCharVector, () -> 0, (boolean wasNull) -> { - }); + new ArrowFlightJdbcVarCharVectorAccessor(varCharVector, () -> 0, (boolean wasNull) -> {}); - accessorIterator.iterate(vector, (accessor, currentRow) -> { - final String string = accessor.getString(); - varCharVector.set(0, new Text(string)); - varCharVector.setValueCount(1); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + final String string = accessor.getString(); + varCharVector.set(0, new Text(string)); + varCharVector.setValueCount(1); - Time timeFromVarChar = varCharVectorAccessor.getTime(calendar); - Time time = accessor.getTime(calendar); + Time timeFromVarChar = varCharVectorAccessor.getTime(calendar); + Time time = accessor.getTime(calendar); - collector.checkThat(time, is(timeFromVarChar)); - collector.checkThat(accessor.wasNull(), is(false)); - }); + collector.checkThat(time, is(timeFromVarChar)); + collector.checkThat(accessor.wasNull(), is(false)); + }); } } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListAccessorTest.java index b2eb8f1dbee..de6c03123f6 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcListAccessorTest.java @@ -25,7 +25,6 @@ import java.util.Collection; import java.util.List; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -49,46 +48,50 @@ public class AbstractArrowFlightJdbcListAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private final Supplier vectorSupplier; private ValueVector vector; private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = (boolean wasNull) -> { - }; - if (vector instanceof ListVector) { - return new ArrowFlightJdbcListVectorAccessor((ListVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof LargeListVector) { - return new ArrowFlightJdbcLargeListVectorAccessor((LargeListVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof FixedSizeListVector) { - return new ArrowFlightJdbcFixedSizeListVectorAccessor((FixedSizeListVector) vector, - getCurrentRow, noOpWasNullConsumer); - } - return null; - }; + accessorSupplier = + (vector, getCurrentRow) -> { + ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = + (boolean wasNull) -> {}; + if (vector instanceof ListVector) { + return new ArrowFlightJdbcListVectorAccessor( + (ListVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof LargeListVector) { + return new ArrowFlightJdbcLargeListVectorAccessor( + (LargeListVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof FixedSizeListVector) { + return new ArrowFlightJdbcFixedSizeListVectorAccessor( + (FixedSizeListVector) vector, getCurrentRow, noOpWasNullConsumer); + } + return null; + }; final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> rootAllocatorTestRule.createListVector(), "ListVector"}, - {(Supplier) () -> rootAllocatorTestRule.createLargeListVector(), - "LargeListVector"}, - {(Supplier) () -> rootAllocatorTestRule.createFixedSizeListVector(), - "FixedSizeListVector"}, - }); + return Arrays.asList( + new Object[][] { + {(Supplier) () -> rootAllocatorTestRule.createListVector(), "ListVector"}, + { + (Supplier) () -> rootAllocatorTestRule.createLargeListVector(), + "LargeListVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createFixedSizeListVector(), + "FixedSizeListVector" + }, + }); } - public AbstractArrowFlightJdbcListAccessorTest(Supplier vectorSupplier, - String vectorType) { + public AbstractArrowFlightJdbcListAccessorTest( + Supplier vectorSupplier, String vectorType) { this.vectorSupplier = vectorSupplier; } @@ -104,17 +107,21 @@ public void tearDown() { @Test public void testShouldGetObjectClassReturnCorrectClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, AbstractArrowFlightJdbcListVectorAccessor::getObjectClass, (accessor, currentRow) -> equalTo(List.class)); } @Test public void testShouldGetObjectReturnValidList() throws Exception { - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, AbstractArrowFlightJdbcListVectorAccessor::getObject, - (accessor, currentRow) -> equalTo( - Arrays.asList(0, (currentRow), (currentRow) * 2, (currentRow) * 3, (currentRow) * 4))); + (accessor, currentRow) -> + equalTo( + Arrays.asList( + 0, (currentRow), (currentRow) * 2, (currentRow) * 3, (currentRow) * 4))); } @Test @@ -123,22 +130,29 @@ public void testShouldGetObjectReturnNull() throws Exception { vector.allocateNewSafe(); vector.setValueCount(5); - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, AbstractArrowFlightJdbcListVectorAccessor::getObject, (accessor, currentRow) -> CoreMatchers.nullValue()); } @Test public void testShouldGetArrayReturnValidArray() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - Array array = accessor.getArray(); - assert array != null; - - Object[] arrayObject = (Object[]) array.getArray(); - - collector.checkThat(arrayObject, equalTo( - new Object[] {0, currentRow, (currentRow) * 2, (currentRow) * 3, (currentRow) * 4})); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + Array array = accessor.getArray(); + assert array != null; + + Object[] arrayObject = (Object[]) array.getArray(); + + collector.checkThat( + arrayObject, + equalTo( + new Object[] { + 0, currentRow, (currentRow) * 2, (currentRow) * 3, (currentRow) * 4 + })); + }); } @Test @@ -147,39 +161,42 @@ public void testShouldGetArrayReturnNull() throws Exception { vector.allocateNewSafe(); vector.setValueCount(5); - accessorIterator.assertAccessorGetter(vector, - AbstractArrowFlightJdbcListVectorAccessor::getArray, - CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + vector, AbstractArrowFlightJdbcListVectorAccessor::getArray, CoreMatchers.nullValue()); } @Test public void testShouldGetArrayReturnValidArrayPassingOffsets() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - Array array = accessor.getArray(); - assert array != null; + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + Array array = accessor.getArray(); + assert array != null; - Object[] arrayObject = (Object[]) array.getArray(1, 3); + Object[] arrayObject = (Object[]) array.getArray(1, 3); - collector.checkThat(arrayObject, equalTo( - new Object[] {currentRow, (currentRow) * 2, (currentRow) * 3})); - }); + collector.checkThat( + arrayObject, equalTo(new Object[] {currentRow, (currentRow) * 2, (currentRow) * 3})); + }); } @Test public void testShouldGetArrayGetResultSetReturnValidResultSet() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - Array array = accessor.getArray(); - assert array != null; - - try (ResultSet rs = array.getResultSet()) { - int count = 0; - while (rs.next()) { - final int value = rs.getInt(1); - collector.checkThat(value, equalTo(currentRow * count)); - count++; - } - collector.checkThat(count, equalTo(5)); - } - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + Array array = accessor.getArray(); + assert array != null; + + try (ResultSet rs = array.getResultSet()) { + int count = 0; + while (rs.next()) { + final int value = rs.getInt(1); + collector.checkThat(value, equalTo(currentRow * count)); + count++; + } + collector.checkThat(count, equalTo(5)); + } + }); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessorTest.java index 2b53b27dc9e..486af288321 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessorTest.java @@ -24,7 +24,6 @@ import java.sql.SQLException; import java.util.Calendar; import java.util.Map; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.driver.jdbc.accessor.impl.ArrowFlightJdbcNullVectorAccessor; import org.apache.arrow.vector.NullVector; @@ -39,10 +38,8 @@ @RunWith(MockitoJUnitRunner.class) public class AbstractArrowFlightJdbcUnionVectorAccessorTest { - @Mock - ArrowFlightJdbcAccessor innerAccessor; - @Spy - AbstractArrowFlightJdbcUnionVectorAccessorMock accessor; + @Mock ArrowFlightJdbcAccessor innerAccessor; + @Spy AbstractArrowFlightJdbcUnionVectorAccessorMock accessor; @Before public void setup() { @@ -242,14 +239,12 @@ public void testGetBigDecimalWithScaleUsesSpecificAccessor() throws SQLException private static class AbstractArrowFlightJdbcUnionVectorAccessorMock extends AbstractArrowFlightJdbcUnionVectorAccessor { protected AbstractArrowFlightJdbcUnionVectorAccessorMock() { - super(() -> 0, (boolean wasNull) -> { - }); + super(() -> 0, (boolean wasNull) -> {}); } @Override protected ArrowFlightJdbcAccessor createAccessorForVector(ValueVector vector) { - return new ArrowFlightJdbcNullVectorAccessor((boolean wasNull) -> { - }); + return new ArrowFlightJdbcNullVectorAccessor((boolean wasNull) -> {}); } @Override diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcDenseUnionVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcDenseUnionVectorAccessorTest.java index 41d5eb97e85..0bb36253a92 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcDenseUnionVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcDenseUnionVectorAccessorTest.java @@ -23,7 +23,6 @@ import java.sql.Timestamp; import java.util.Arrays; import java.util.List; - import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; import org.apache.arrow.vector.complex.DenseUnionVector; @@ -44,21 +43,22 @@ public class ArrowFlightJdbcDenseUnionVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private DenseUnionVector vector; private final AccessorTestUtils.AccessorSupplier accessorSupplier = - (vector, getCurrentRow) -> new ArrowFlightJdbcDenseUnionVectorAccessor( - (DenseUnionVector) vector, getCurrentRow, (boolean wasNull) -> { - //No Operation - }); + (vector, getCurrentRow) -> + new ArrowFlightJdbcDenseUnionVectorAccessor( + (DenseUnionVector) vector, + getCurrentRow, + (boolean wasNull) -> { + // No Operation + }); private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Before public void setup() throws Exception { @@ -106,12 +106,8 @@ public void tearDown() { @Test public void getObject() throws Exception { List result = accessorIterator.toList(vector); - List expected = Arrays.asList( - Long.MAX_VALUE, - Math.PI, - new Timestamp(1625702400000L), - null, - null); + List expected = + Arrays.asList(Long.MAX_VALUE, Math.PI, new Timestamp(1625702400000L), null, null); collector.checkThat(result, is(expected)); } @@ -120,7 +116,7 @@ public void getObject() throws Exception { public void getObjectForNull() throws Exception { vector.reset(); vector.setValueCount(5); - accessorIterator.assertAccessorGetter(vector, - AbstractArrowFlightJdbcUnionVectorAccessor::getObject, equalTo(null)); + accessorIterator.assertAccessorGetter( + vector, AbstractArrowFlightJdbcUnionVectorAccessor::getObject, equalTo(null)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcMapVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcMapVectorAccessorTest.java index 7a81da4240b..eab19f083f8 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcMapVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcMapVectorAccessorTest.java @@ -21,7 +21,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; - import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; import org.apache.arrow.vector.complex.MapVector; @@ -40,8 +39,7 @@ public class ArrowFlightJdbcMapVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private MapVector vector; @@ -105,8 +103,8 @@ public void tearDown() { public void testShouldGetObjectReturnValidMap() { AccessorTestUtils.Cursor cursor = new AccessorTestUtils.Cursor(vector.getValueCount()); ArrowFlightJdbcMapVectorAccessor accessor = - new ArrowFlightJdbcMapVectorAccessor(vector, cursor::getCurrentRow, (boolean wasNull) -> { - }); + new ArrowFlightJdbcMapVectorAccessor( + vector, cursor::getCurrentRow, (boolean wasNull) -> {}); Map expected = new JsonStringHashMap<>(); expected.put(1, 11); @@ -135,8 +133,7 @@ public void testShouldGetObjectReturnValidMap() { public void testShouldGetObjectReturnNull() { vector.setNull(0); ArrowFlightJdbcMapVectorAccessor accessor = - new ArrowFlightJdbcMapVectorAccessor(vector, () -> 0, (boolean wasNull) -> { - }); + new ArrowFlightJdbcMapVectorAccessor(vector, () -> 0, (boolean wasNull) -> {}); Assert.assertNull(accessor.getObject()); Assert.assertTrue(accessor.wasNull()); @@ -146,8 +143,8 @@ public void testShouldGetObjectReturnNull() { public void testShouldGetArrayReturnValidArray() throws SQLException { AccessorTestUtils.Cursor cursor = new AccessorTestUtils.Cursor(vector.getValueCount()); ArrowFlightJdbcMapVectorAccessor accessor = - new ArrowFlightJdbcMapVectorAccessor(vector, cursor::getCurrentRow, (boolean wasNull) -> { - }); + new ArrowFlightJdbcMapVectorAccessor( + vector, cursor::getCurrentRow, (boolean wasNull) -> {}); Array array = accessor.getArray(); Assert.assertNotNull(array); @@ -212,8 +209,7 @@ public void testShouldGetArrayReturnNull() { ((StructVector) vector.getDataVector()).setNull(0); ArrowFlightJdbcMapVectorAccessor accessor = - new ArrowFlightJdbcMapVectorAccessor(vector, () -> 0, (boolean wasNull) -> { - }); + new ArrowFlightJdbcMapVectorAccessor(vector, () -> 0, (boolean wasNull) -> {}); Assert.assertNull(accessor.getArray()); Assert.assertTrue(accessor.wasNull()); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java index b3c85fc0ab1..ddc810e67e8 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java @@ -24,7 +24,6 @@ import java.sql.Struct; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; import org.apache.arrow.vector.Float8Vector; @@ -52,20 +51,18 @@ public class ArrowFlightJdbcStructVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private StructVector vector; private final AccessorTestUtils.AccessorSupplier accessorSupplier = - (vector, getCurrentRow) -> new ArrowFlightJdbcStructVectorAccessor((StructVector) vector, - getCurrentRow, (boolean wasNull) -> { - }); + (vector, getCurrentRow) -> + new ArrowFlightJdbcStructVectorAccessor( + (StructVector) vector, getCurrentRow, (boolean wasNull) -> {}); private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Before public void setUp() throws Exception { @@ -78,8 +75,8 @@ public void setUp() throws Exception { IntVector intVector = vector.addOrGet("int", FieldType.nullable(Types.MinorType.INT.getType()), IntVector.class); Float8Vector float8Vector = - vector.addOrGet("float8", FieldType.nullable(Types.MinorType.FLOAT8.getType()), - Float8Vector.class); + vector.addOrGet( + "float8", FieldType.nullable(Types.MinorType.FLOAT8.getType()), Float8Vector.class); intVector.setSafe(0, 100); float8Vector.setSafe(0, 100.05); @@ -98,14 +95,17 @@ public void tearDown() throws Exception { @Test public void testShouldGetObjectClassReturnMapClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcStructVectorAccessor::getObjectClass, (accessor, currentRow) -> equalTo(Map.class)); } @Test public void testShouldGetObjectReturnValidMap() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcStructVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcStructVectorAccessor::getObject, (accessor, currentRow) -> { Map expected = new HashMap<>(); expected.put("int", 100 * (currentRow + 1)); @@ -119,37 +119,40 @@ public void testShouldGetObjectReturnValidMap() throws Exception { public void testShouldGetObjectReturnNull() throws Exception { vector.setNull(0); vector.setNull(1); - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcStructVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcStructVectorAccessor::getObject, (accessor, currentRow) -> nullValue()); } @Test public void testShouldGetStructReturnValidStruct() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - Struct struct = accessor.getStruct(); - assert struct != null; + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + Struct struct = accessor.getStruct(); + assert struct != null; - Object[] expected = new Object[] { - 100 * (currentRow + 1), - 100.05 * (currentRow + 1) - }; + Object[] expected = new Object[] {100 * (currentRow + 1), 100.05 * (currentRow + 1)}; - collector.checkThat(struct.getAttributes(), equalTo(expected)); - }); + collector.checkThat(struct.getAttributes(), equalTo(expected)); + }); } @Test public void testShouldGetStructReturnNull() throws Exception { vector.setNull(0); vector.setNull(1); - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcStructVectorAccessor::getStruct, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcStructVectorAccessor::getStruct, (accessor, currentRow) -> nullValue()); } @Test public void testShouldGetObjectWorkWithNestedComplexData() throws SQLException { - try (StructVector rootVector = StructVector.empty("", - rootAllocatorTestRule.getRootAllocator())) { + try (StructVector rootVector = + StructVector.empty("", rootAllocatorTestRule.getRootAllocator())) { StructVector structVector = rootVector.addOrGetStruct("struct"); FieldType intFieldType = FieldType.nullable(Types.MinorType.INT.getType()); @@ -199,8 +202,7 @@ public void testShouldGetObjectWorkWithNestedComplexData() throws SQLException { expected.put("union", true); ArrowFlightJdbcStructVectorAccessor accessor = - new ArrowFlightJdbcStructVectorAccessor(rootVector, () -> 0, (boolean wasNull) -> { - }); + new ArrowFlightJdbcStructVectorAccessor(rootVector, () -> 0, (boolean wasNull) -> {}); Assert.assertEquals(accessor.getObject(), expected); Assert.assertEquals(accessor.getString(), expected.toString()); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcUnionVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcUnionVectorAccessorTest.java index 9ec9388ff87..32139b24404 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcUnionVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcUnionVectorAccessorTest.java @@ -23,7 +23,6 @@ import java.sql.Timestamp; import java.util.Arrays; import java.util.List; - import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; import org.apache.arrow.vector.complex.UnionVector; @@ -43,20 +42,18 @@ public class ArrowFlightJdbcUnionVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private UnionVector vector; private final AccessorTestUtils.AccessorSupplier accessorSupplier = - (vector, getCurrentRow) -> new ArrowFlightJdbcUnionVectorAccessor((UnionVector) vector, - getCurrentRow, (boolean wasNull) -> { - }); + (vector, getCurrentRow) -> + new ArrowFlightJdbcUnionVectorAccessor( + (UnionVector) vector, getCurrentRow, (boolean wasNull) -> {}); private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Before public void setup() { @@ -96,12 +93,8 @@ public void tearDown() { @Test public void getObject() throws Exception { List result = accessorIterator.toList(vector); - List expected = Arrays.asList( - Long.MAX_VALUE, - Math.PI, - new Timestamp(1625702400000L), - null, - null); + List expected = + Arrays.asList(Long.MAX_VALUE, Math.PI, new Timestamp(1625702400000L), null, null); collector.checkThat(result, is(expected)); } @@ -111,8 +104,7 @@ public void getObjectForNull() throws Exception { vector.reset(); vector.setValueCount(5); - accessorIterator.assertAccessorGetter(vector, - AbstractArrowFlightJdbcUnionVectorAccessor::getObject, - equalTo(null)); + accessorIterator.assertAccessorGetter( + vector, AbstractArrowFlightJdbcUnionVectorAccessor::getObject, equalTo(null)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessorTest.java index 5e54b545a85..b2cb7476393 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessorTest.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -44,75 +43,87 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - @RunWith(Parameterized.class) public class ArrowFlightJdbcBaseIntVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private BaseIntVector vector; private final Supplier vectorSupplier; private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = (boolean wasNull) -> { - }; - if (vector instanceof UInt1Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt1Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof UInt2Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt2Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } else { - if (vector instanceof UInt4Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt4Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof UInt8Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt8Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof TinyIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((TinyIntVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof SmallIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((SmallIntVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof IntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((IntVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof BigIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((BigIntVector) vector, getCurrentRow, - noOpWasNullConsumer); - } - } - throw new UnsupportedOperationException(); - }; + accessorSupplier = + (vector, getCurrentRow) -> { + ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = + (boolean wasNull) -> {}; + if (vector instanceof UInt1Vector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt1Vector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof UInt2Vector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt2Vector) vector, getCurrentRow, noOpWasNullConsumer); + } else { + if (vector instanceof UInt4Vector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt4Vector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof UInt8Vector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt8Vector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof TinyIntVector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (TinyIntVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof SmallIntVector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (SmallIntVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof IntVector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (IntVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof BigIntVector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (BigIntVector) vector, getCurrentRow, noOpWasNullConsumer); + } + } + throw new UnsupportedOperationException(); + }; private final AccessorTestUtils.AccessorIterator accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> rootAllocatorTestRule.createIntVector(), "IntVector"}, - {(Supplier) () -> rootAllocatorTestRule.createSmallIntVector(), - "SmallIntVector"}, - {(Supplier) () -> rootAllocatorTestRule.createTinyIntVector(), - "TinyIntVector"}, - {(Supplier) () -> rootAllocatorTestRule.createBigIntVector(), - "BigIntVector"}, - {(Supplier) () -> rootAllocatorTestRule.createUInt1Vector(), "UInt1Vector"}, - {(Supplier) () -> rootAllocatorTestRule.createUInt2Vector(), "UInt2Vector"}, - {(Supplier) () -> rootAllocatorTestRule.createUInt4Vector(), "UInt4Vector"}, - {(Supplier) () -> rootAllocatorTestRule.createUInt8Vector(), "UInt8Vector"} - }); + return Arrays.asList( + new Object[][] { + {(Supplier) () -> rootAllocatorTestRule.createIntVector(), "IntVector"}, + { + (Supplier) () -> rootAllocatorTestRule.createSmallIntVector(), + "SmallIntVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createTinyIntVector(), + "TinyIntVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createBigIntVector(), + "BigIntVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createUInt1Vector(), "UInt1Vector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createUInt2Vector(), "UInt2Vector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createUInt4Vector(), "UInt4Vector" + }, + {(Supplier) () -> rootAllocatorTestRule.createUInt8Vector(), "UInt8Vector"} + }); } - public ArrowFlightJdbcBaseIntVectorAccessorTest(Supplier vectorSupplier, - String vectorType) { + public ArrowFlightJdbcBaseIntVectorAccessorTest( + Supplier vectorSupplier, String vectorType) { this.vectorSupplier = vectorSupplier; } @@ -128,44 +139,55 @@ public void tearDown() { @Test public void testShouldConvertToByteMethodFromBaseIntVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBaseIntVectorAccessor::getByte, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBaseIntVectorAccessor::getByte, (accessor, currentRow) -> equalTo((byte) accessor.getLong())); } @Test public void testShouldConvertToShortMethodFromBaseIntVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBaseIntVectorAccessor::getShort, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBaseIntVectorAccessor::getShort, (accessor, currentRow) -> equalTo((short) accessor.getLong())); } @Test public void testShouldConvertToIntegerMethodFromBaseIntVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBaseIntVectorAccessor::getInt, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBaseIntVectorAccessor::getInt, (accessor, currentRow) -> equalTo((int) accessor.getLong())); } @Test public void testShouldConvertToFloatMethodFromBaseIntVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBaseIntVectorAccessor::getFloat, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBaseIntVectorAccessor::getFloat, (accessor, currentRow) -> equalTo((float) accessor.getLong())); } @Test public void testShouldConvertToDoubleMethodFromBaseIntVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBaseIntVectorAccessor::getDouble, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBaseIntVectorAccessor::getDouble, (accessor, currentRow) -> equalTo((double) accessor.getLong())); } @Test public void testShouldConvertToBooleanMethodFromBaseIntVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBaseIntVectorAccessor::getBoolean, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcBaseIntVectorAccessor::getBoolean, (accessor, currentRow) -> equalTo(accessor.getLong() != 0L)); } @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, - ArrowFlightJdbcBaseIntVectorAccessor::getObjectClass, - equalTo(Long.class)); + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcBaseIntVectorAccessor::getObjectClass, equalTo(Long.class)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessorUnitTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessorUnitTest.java index 2e64b6fb402..513800d769a 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessorUnitTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBaseIntVectorAccessorUnitTest.java @@ -44,8 +44,7 @@ @RunWith(MockitoJUnitRunner.class) public class ArrowFlightJdbcBaseIntVectorAccessorUnitTest { - @ClassRule - public static RootAllocatorTestRule rule = new RootAllocatorTestRule(); + @ClassRule public static RootAllocatorTestRule rule = new RootAllocatorTestRule(); private static UInt4Vector int4Vector; private static UInt8Vector int8Vector; private static IntVector intVectorWithNull; @@ -53,40 +52,40 @@ public class ArrowFlightJdbcBaseIntVectorAccessorUnitTest { private static SmallIntVector smallIntVector; private static IntVector intVector; private static BigIntVector bigIntVector; - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = (boolean wasNull) -> { - }; - if (vector instanceof UInt1Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt1Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof UInt2Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt2Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof UInt4Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt4Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof UInt8Vector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((UInt8Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof TinyIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((TinyIntVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof SmallIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((SmallIntVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof IntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((IntVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof BigIntVector) { - return new ArrowFlightJdbcBaseIntVectorAccessor((BigIntVector) vector, getCurrentRow, - noOpWasNullConsumer); - } - return null; - }; + accessorSupplier = + (vector, getCurrentRow) -> { + ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = + (boolean wasNull) -> {}; + if (vector instanceof UInt1Vector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt1Vector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof UInt2Vector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt2Vector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof UInt4Vector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt4Vector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof UInt8Vector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (UInt8Vector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof TinyIntVector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (TinyIntVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof SmallIntVector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (SmallIntVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof IntVector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (IntVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof BigIntVector) { + return new ArrowFlightJdbcBaseIntVectorAccessor( + (BigIntVector) vector, getCurrentRow, noOpWasNullConsumer); + } + return null; + }; private final AccessorTestUtils.AccessorIterator accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @@ -124,90 +123,108 @@ public static void setup() { @AfterClass public static void tearDown() throws Exception { - AutoCloseables.close(bigIntVector, intVector, smallIntVector, tinyIntVector, int4Vector, - int8Vector, intVectorWithNull, rule); + AutoCloseables.close( + bigIntVector, + intVector, + smallIntVector, + tinyIntVector, + int4Vector, + int8Vector, + intVectorWithNull, + rule); } @Test public void testShouldGetStringFromUnsignedValue() throws Exception { - accessorIterator.assertAccessorGetter(int8Vector, - ArrowFlightJdbcBaseIntVectorAccessor::getString, equalTo("18446744073709551615")); + accessorIterator.assertAccessorGetter( + int8Vector, + ArrowFlightJdbcBaseIntVectorAccessor::getString, + equalTo("18446744073709551615")); } @Test public void testShouldGetBytesFromIntVectorThrowsSqlException() throws Exception { - accessorIterator.assertAccessorGetterThrowingException(intVector, ArrowFlightJdbcBaseIntVectorAccessor::getBytes); + accessorIterator.assertAccessorGetterThrowingException( + intVector, ArrowFlightJdbcBaseIntVectorAccessor::getBytes); } @Test public void testShouldGetStringFromIntVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(intVectorWithNull, - ArrowFlightJdbcBaseIntVectorAccessor::getString, CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + intVectorWithNull, + ArrowFlightJdbcBaseIntVectorAccessor::getString, + CoreMatchers.nullValue()); } @Test public void testShouldGetObjectFromInt() throws Exception { - accessorIterator.assertAccessorGetter(intVector, - ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo(0xAABBCCDD)); + accessorIterator.assertAccessorGetter( + intVector, ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo(0xAABBCCDD)); } @Test public void testShouldGetObjectFromTinyInt() throws Exception { - accessorIterator.assertAccessorGetter(tinyIntVector, - ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo((byte) 0xAA)); + accessorIterator.assertAccessorGetter( + tinyIntVector, ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo((byte) 0xAA)); } @Test public void testShouldGetObjectFromSmallInt() throws Exception { - accessorIterator.assertAccessorGetter(smallIntVector, - ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo((short) 0xAABB)); + accessorIterator.assertAccessorGetter( + smallIntVector, ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo((short) 0xAABB)); } @Test public void testShouldGetObjectFromBigInt() throws Exception { - accessorIterator.assertAccessorGetter(bigIntVector, - ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo(0xAABBCCDDEEFFAABBL)); + accessorIterator.assertAccessorGetter( + bigIntVector, + ArrowFlightJdbcBaseIntVectorAccessor::getObject, + equalTo(0xAABBCCDDEEFFAABBL)); } @Test public void testShouldGetObjectFromUnsignedInt() throws Exception { - accessorIterator.assertAccessorGetter(int4Vector, - ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo(0x80000001)); + accessorIterator.assertAccessorGetter( + int4Vector, ArrowFlightJdbcBaseIntVectorAccessor::getObject, equalTo(0x80000001)); } @Test public void testShouldGetObjectFromIntVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(intVectorWithNull, - ArrowFlightJdbcBaseIntVectorAccessor::getObject, CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + intVectorWithNull, + ArrowFlightJdbcBaseIntVectorAccessor::getObject, + CoreMatchers.nullValue()); } @Test public void testShouldGetBigDecimalFromIntVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(intVectorWithNull, - ArrowFlightJdbcBaseIntVectorAccessor::getBigDecimal, CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + intVectorWithNull, + ArrowFlightJdbcBaseIntVectorAccessor::getBigDecimal, + CoreMatchers.nullValue()); } @Test public void testShouldGetBigDecimalWithScaleFromIntVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(intVectorWithNull, accessor -> accessor.getBigDecimal(2), - CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + intVectorWithNull, accessor -> accessor.getBigDecimal(2), CoreMatchers.nullValue()); } @Test public void testShouldGetBytesFromSmallVectorThrowsSqlException() throws Exception { - accessorIterator.assertAccessorGetterThrowingException(smallIntVector, - ArrowFlightJdbcBaseIntVectorAccessor::getBytes); + accessorIterator.assertAccessorGetterThrowingException( + smallIntVector, ArrowFlightJdbcBaseIntVectorAccessor::getBytes); } @Test public void testShouldGetBytesFromTinyIntVectorThrowsSqlException() throws Exception { - accessorIterator.assertAccessorGetterThrowingException(tinyIntVector, - ArrowFlightJdbcBaseIntVectorAccessor::getBytes); + accessorIterator.assertAccessorGetterThrowingException( + tinyIntVector, ArrowFlightJdbcBaseIntVectorAccessor::getBytes); } @Test public void testShouldGetBytesFromBigIntVectorThrowsSqlException() throws Exception { - accessorIterator.assertAccessorGetterThrowingException(bigIntVector, - ArrowFlightJdbcBaseIntVectorAccessor::getBytes); + accessorIterator.assertAccessorGetterThrowingException( + bigIntVector, ArrowFlightJdbcBaseIntVectorAccessor::getBytes); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java index 809d6e8d353..2c66d712be1 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java @@ -21,7 +21,6 @@ import static org.hamcrest.CoreMatchers.is; import java.math.BigDecimal; - import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils.AccessorIterator; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils.CheckedFunction; @@ -38,14 +37,13 @@ public class ArrowFlightJdbcBitVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> new ArrowFlightJdbcBitVectorAccessor((BitVector) vector, - getCurrentRow, (boolean wasNull) -> { - }); - private final AccessorIterator - accessorIterator = + accessorSupplier = + (vector, getCurrentRow) -> + new ArrowFlightJdbcBitVectorAccessor( + (BitVector) vector, getCurrentRow, (boolean wasNull) -> {}); + private final AccessorIterator accessorIterator = new AccessorIterator<>(collector, accessorSupplier); private BitVector vector; private BitVector vectorWithNull; @@ -64,12 +62,16 @@ public void tearDown() { this.vectorWithNull.close(); } - private void iterate(final CheckedFunction function, - final T result, - final T resultIfFalse, final BitVector vector) throws Exception { - accessorIterator.assertAccessorGetter(vector, function, - ((accessor, currentRow) -> is(arrayToAssert[currentRow] ? result : resultIfFalse)) - ); + private void iterate( + final CheckedFunction function, + final T result, + final T resultIfFalse, + final BitVector vector) + throws Exception { + accessorIterator.assertAccessorGetter( + vector, + function, + ((accessor, currentRow) -> is(arrayToAssert[currentRow] ? result : resultIfFalse))); } @Test @@ -90,66 +92,57 @@ public void testShouldGetShortMethodFromBitVector() throws Exception { @Test public void testShouldGetIntMethodFromBitVector() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getInt, 1, 0, vector); - } @Test public void testShouldGetLongMethodFromBitVector() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getLong, (long) 1, (long) 0, vector); - } @Test public void testShouldGetFloatMethodFromBitVector() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getFloat, (float) 1, (float) 0, vector); - } @Test public void testShouldGetDoubleMethodFromBitVector() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getDouble, (double) 1, (double) 0, vector); - } @Test public void testShouldGetBigDecimalMethodFromBitVector() throws Exception { - iterate(ArrowFlightJdbcBitVectorAccessor::getBigDecimal, BigDecimal.ONE, BigDecimal.ZERO, - vector); + iterate( + ArrowFlightJdbcBitVectorAccessor::getBigDecimal, BigDecimal.ONE, BigDecimal.ZERO, vector); } @Test public void testShouldGetBigDecimalMethodFromBitVectorFromNull() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getBigDecimal, null, null, vectorWithNull); - } @Test public void testShouldGetObjectMethodFromBitVector() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getObject, true, false, vector); - } @Test public void testShouldGetObjectMethodFromBitVectorFromNull() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getObject, null, null, vectorWithNull); - } @Test public void testShouldGetStringMethodFromBitVector() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getString, "true", "false", vector); - } @Test public void testShouldGetStringMethodFromBitVectorFromNull() throws Exception { iterate(ArrowFlightJdbcBitVectorAccessor::getString, null, null, vectorWithNull); - } @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcBitVectorAccessor::getObjectClass, - equalTo(Boolean.class)); + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcBitVectorAccessor::getObjectClass, equalTo(Boolean.class)); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcDecimalVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcDecimalVectorAccessorTest.java index b7bd7c40fef..de933feb574 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcDecimalVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcDecimalVectorAccessorTest.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessorFactory; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -47,43 +46,47 @@ public class ArrowFlightJdbcDecimalVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); private final Supplier vectorSupplier; private ValueVector vector; private ValueVector vectorWithNull; private final AccessorTestUtils.AccessorSupplier - accessorSupplier = (vector, getCurrentRow) -> { - ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = (boolean wasNull) -> { - }; - if (vector instanceof DecimalVector) { - return new ArrowFlightJdbcDecimalVectorAccessor((DecimalVector) vector, getCurrentRow, - noOpWasNullConsumer); - } else if (vector instanceof Decimal256Vector) { - return new ArrowFlightJdbcDecimalVectorAccessor((Decimal256Vector) vector, getCurrentRow, - noOpWasNullConsumer); - } - return null; - }; + accessorSupplier = + (vector, getCurrentRow) -> { + ArrowFlightJdbcAccessorFactory.WasNullConsumer noOpWasNullConsumer = + (boolean wasNull) -> {}; + if (vector instanceof DecimalVector) { + return new ArrowFlightJdbcDecimalVectorAccessor( + (DecimalVector) vector, getCurrentRow, noOpWasNullConsumer); + } else if (vector instanceof Decimal256Vector) { + return new ArrowFlightJdbcDecimalVectorAccessor( + (Decimal256Vector) vector, getCurrentRow, noOpWasNullConsumer); + } + return null; + }; private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Parameterized.Parameters(name = "{1}") public static Collection data() { - return Arrays.asList(new Object[][] { - {(Supplier) () -> rootAllocatorTestRule.createDecimalVector(), - "DecimalVector"}, - {(Supplier) () -> rootAllocatorTestRule.createDecimal256Vector(), - "Decimal256Vector"}, - }); + return Arrays.asList( + new Object[][] { + { + (Supplier) () -> rootAllocatorTestRule.createDecimalVector(), + "DecimalVector" + }, + { + (Supplier) () -> rootAllocatorTestRule.createDecimal256Vector(), + "Decimal256Vector" + }, + }); } - public ArrowFlightJdbcDecimalVectorAccessorTest(Supplier vectorSupplier, - String vectorType) { + public ArrowFlightJdbcDecimalVectorAccessorTest( + Supplier vectorSupplier, String vectorType) { this.vectorSupplier = vectorSupplier; } @@ -104,145 +107,177 @@ public void tearDown() { @Test public void testShouldGetBigDecimalFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcDecimalVectorAccessor::getBigDecimal, (accessor, currentRow) -> CoreMatchers.notNullValue()); } @Test public void testShouldGetDoubleMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getDouble, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getDouble, (accessor, currentRow) -> equalTo(accessor.getBigDecimal().doubleValue())); } @Test public void testShouldGetFloatMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getFloat, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getFloat, (accessor, currentRow) -> equalTo(accessor.getBigDecimal().floatValue())); } @Test public void testShouldGetLongMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getLong, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getLong, (accessor, currentRow) -> equalTo(accessor.getBigDecimal().longValue())); } @Test public void testShouldGetIntMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getInt, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getInt, (accessor, currentRow) -> equalTo(accessor.getBigDecimal().intValue())); } @Test public void testShouldGetShortMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getShort, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getShort, (accessor, currentRow) -> equalTo(accessor.getBigDecimal().shortValue())); } @Test public void testShouldGetByteMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getByte, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getByte, (accessor, currentRow) -> equalTo(accessor.getBigDecimal().byteValue())); } @Test public void testShouldGetStringMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getString, (accessor, currentRow) -> equalTo(accessor.getBigDecimal().toString())); } @Test public void testShouldGetBooleanMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getBoolean, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getBoolean, (accessor, currentRow) -> equalTo(!accessor.getBigDecimal().equals(BigDecimal.ZERO))); } @Test public void testShouldGetObjectMethodFromDecimalVector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcDecimalVectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcDecimalVectorAccessor::getObject, (accessor, currentRow) -> equalTo(accessor.getBigDecimal())); } @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcDecimalVectorAccessor::getObjectClass, (accessor, currentRow) -> equalTo(BigDecimal.class)); } @Test public void testShouldGetBigDecimalMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getBigDecimal, (accessor, currentRow) -> CoreMatchers.nullValue()); } @Test public void testShouldGetObjectMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getObject, (accessor, currentRow) -> CoreMatchers.nullValue()); } @Test public void testShouldGetStringMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getString, (accessor, currentRow) -> CoreMatchers.nullValue()); } @Test public void testShouldGetByteMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getByte, (accessor, currentRow) -> is((byte) 0)); } @Test public void testShouldGetShortMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getShort, (accessor, currentRow) -> is((short) 0)); } @Test public void testShouldGetIntMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getInt, (accessor, currentRow) -> is(0)); } @Test public void testShouldGetLongMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getLong, (accessor, currentRow) -> is((long) 0)); } @Test public void testShouldGetFloatMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getFloat, (accessor, currentRow) -> is(0.0f)); } @Test public void testShouldGetDoubleMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getDouble, (accessor, currentRow) -> is(0.0D)); } @Test public void testShouldGetBooleanMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcDecimalVectorAccessor::getBoolean, (accessor, currentRow) -> is(false)); } @Test public void testShouldGetBigDecimalWithScaleMethodFromDecimalVectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, accessor -> accessor.getBigDecimal(2), + accessorIterator.assertAccessorGetter( + vectorWithNull, + accessor -> accessor.getBigDecimal(2), (accessor, currentRow) -> CoreMatchers.nullValue()); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat4VectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat4VectorAccessorTest.java index 74a65715ec0..b92c7fc12f1 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat4VectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat4VectorAccessorTest.java @@ -23,7 +23,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.SQLException; - import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; import org.apache.arrow.vector.Float4Vector; @@ -41,23 +40,20 @@ public class ArrowFlightJdbcFloat4VectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); - @Rule - public ExpectedException exceptionCollector = ExpectedException.none(); + @Rule public ExpectedException exceptionCollector = ExpectedException.none(); private Float4Vector vector; private final AccessorTestUtils.AccessorSupplier accessorSupplier = - (vector, getCurrentRow) -> new ArrowFlightJdbcFloat4VectorAccessor((Float4Vector) vector, - getCurrentRow, (boolean wasNull) -> { - }); + (vector, getCurrentRow) -> + new ArrowFlightJdbcFloat4VectorAccessor( + (Float4Vector) vector, getCurrentRow, (boolean wasNull) -> {}); private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Before public void setup() { @@ -71,55 +67,61 @@ public void tearDown() { @Test public void testShouldGetFloatMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getFloat, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getFloat, (accessor, currentRow) -> is(vector.get(currentRow))); } @Test public void testShouldGetObjectMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getObject, (accessor) -> is(accessor.getFloat())); } @Test public void testShouldGetStringMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getString, accessor -> is(Float.toString(accessor.getFloat()))); } @Test public void testShouldGetStringMethodFromFloat4VectorWithNull() throws Exception { - try (final Float4Vector float4Vector = new Float4Vector("ID", - rootAllocatorTestRule.getRootAllocator())) { + try (final Float4Vector float4Vector = + new Float4Vector("ID", rootAllocatorTestRule.getRootAllocator())) { float4Vector.setNull(0); float4Vector.setValueCount(1); - accessorIterator.assertAccessorGetter(float4Vector, - ArrowFlightJdbcFloat4VectorAccessor::getString, - CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + float4Vector, ArrowFlightJdbcFloat4VectorAccessor::getString, CoreMatchers.nullValue()); } } @Test public void testShouldGetFloatMethodFromFloat4VectorWithNull() throws Exception { - try (final Float4Vector float4Vector = new Float4Vector("ID", - rootAllocatorTestRule.getRootAllocator())) { + try (final Float4Vector float4Vector = + new Float4Vector("ID", rootAllocatorTestRule.getRootAllocator())) { float4Vector.setNull(0); float4Vector.setValueCount(1); - accessorIterator.assertAccessorGetter(float4Vector, - ArrowFlightJdbcFloat4VectorAccessor::getFloat, is(0.0f)); + accessorIterator.assertAccessorGetter( + float4Vector, ArrowFlightJdbcFloat4VectorAccessor::getFloat, is(0.0f)); } } @Test public void testShouldGetBigDecimalMethodFromFloat4VectorWithNull() throws Exception { - try (final Float4Vector float4Vector = new Float4Vector("ID", - rootAllocatorTestRule.getRootAllocator())) { + try (final Float4Vector float4Vector = + new Float4Vector("ID", rootAllocatorTestRule.getRootAllocator())) { float4Vector.setNull(0); float4Vector.setValueCount(1); - accessorIterator.assertAccessorGetter(float4Vector, + accessorIterator.assertAccessorGetter( + float4Vector, ArrowFlightJdbcFloat4VectorAccessor::getBigDecimal, CoreMatchers.nullValue()); } @@ -127,79 +129,96 @@ public void testShouldGetBigDecimalMethodFromFloat4VectorWithNull() throws Excep @Test public void testShouldGetObjectMethodFromFloat4VectorWithNull() throws Exception { - try (final Float4Vector float4Vector = new Float4Vector("ID", - rootAllocatorTestRule.getRootAllocator())) { + try (final Float4Vector float4Vector = + new Float4Vector("ID", rootAllocatorTestRule.getRootAllocator())) { float4Vector.setNull(0); float4Vector.setValueCount(1); - accessorIterator.assertAccessorGetter(float4Vector, - ArrowFlightJdbcFloat4VectorAccessor::getObject, - CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + float4Vector, ArrowFlightJdbcFloat4VectorAccessor::getObject, CoreMatchers.nullValue()); } } @Test public void testShouldGetBooleanMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getBoolean, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getBoolean, accessor -> is(accessor.getFloat() != 0.0f)); } @Test public void testShouldGetByteMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getByte, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getByte, accessor -> is((byte) accessor.getFloat())); } @Test public void testShouldGetShortMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getShort, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getShort, accessor -> is((short) accessor.getFloat())); } @Test public void testShouldGetIntMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getInt, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getInt, accessor -> is((int) accessor.getFloat())); } @Test public void testShouldGetLongMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getLong, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getLong, accessor -> is((long) accessor.getFloat())); } @Test public void testShouldGetDoubleMethodFromFloat4Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat4VectorAccessor::getDouble, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat4VectorAccessor::getDouble, accessor -> is((double) accessor.getFloat())); } @Test public void testShouldGetBigDecimalMethodFromFloat4Vector() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - float value = accessor.getFloat(); - if (Float.isInfinite(value) || Float.isNaN(value)) { - exceptionCollector.expect(SQLException.class); - } - collector.checkThat(accessor.getBigDecimal(), is(BigDecimal.valueOf(value))); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + float value = accessor.getFloat(); + if (Float.isInfinite(value) || Float.isNaN(value)) { + exceptionCollector.expect(SQLException.class); + } + collector.checkThat(accessor.getBigDecimal(), is(BigDecimal.valueOf(value))); + }); } @Test public void testShouldGetBigDecimalWithScaleMethodFromFloat4Vector() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - float value = accessor.getFloat(); - if (Float.isInfinite(value) || Float.isNaN(value)) { - exceptionCollector.expect(SQLException.class); - } - collector.checkThat(accessor.getBigDecimal(9), - is(BigDecimal.valueOf(value).setScale(9, RoundingMode.HALF_UP))); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + float value = accessor.getFloat(); + if (Float.isInfinite(value) || Float.isNaN(value)) { + exceptionCollector.expect(SQLException.class); + } + collector.checkThat( + accessor.getBigDecimal(9), + is(BigDecimal.valueOf(value).setScale(9, RoundingMode.HALF_UP))); + }); } @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator.assertAccessorGetter(vector, + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcFloat4VectorAccessor::getObjectClass, accessor -> equalTo(Float.class)); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat8VectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat8VectorAccessorTest.java index 26758287a96..27a01ab31e0 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat8VectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcFloat8VectorAccessorTest.java @@ -23,7 +23,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.SQLException; - import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; import org.apache.arrow.vector.Float8Vector; @@ -41,25 +40,21 @@ public class ArrowFlightJdbcFloat8VectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Rule - public final ErrorCollector collector = new ErrorCollector(); - - @Rule - public ExpectedException exceptionCollector = ExpectedException.none(); + @Rule public final ErrorCollector collector = new ErrorCollector(); + @Rule public ExpectedException exceptionCollector = ExpectedException.none(); private Float8Vector vector; private Float8Vector vectorWithNull; private final AccessorTestUtils.AccessorSupplier accessorSupplier = - (vector, getCurrentRow) -> new ArrowFlightJdbcFloat8VectorAccessor((Float8Vector) vector, - getCurrentRow, (boolean wasNull) -> { - }); + (vector, getCurrentRow) -> + new ArrowFlightJdbcFloat8VectorAccessor( + (Float8Vector) vector, getCurrentRow, (boolean wasNull) -> {}); private final AccessorTestUtils.AccessorIterator - accessorIterator = - new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); + accessorIterator = new AccessorTestUtils.AccessorIterator<>(collector, accessorSupplier); @Before public void setup() { @@ -75,113 +70,133 @@ public void tearDown() { @Test public void testShouldGetDoubleMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getDouble, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getDouble, (accessor, currentRow) -> is(vector.getValueAsDouble(currentRow))); } @Test public void testShouldGetObjectMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getObject, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getObject, (accessor) -> is(accessor.getDouble())); } @Test public void testShouldGetStringMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getString, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getString, (accessor) -> is(Double.toString(accessor.getDouble()))); } @Test public void testShouldGetBooleanMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getBoolean, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getBoolean, (accessor) -> is(accessor.getDouble() != 0.0)); } @Test public void testShouldGetByteMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getByte, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getByte, (accessor) -> is((byte) accessor.getDouble())); } @Test public void testShouldGetShortMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getShort, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getShort, (accessor) -> is((short) accessor.getDouble())); } @Test public void testShouldGetIntMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getInt, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getInt, (accessor) -> is((int) accessor.getDouble())); } @Test public void testShouldGetLongMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getLong, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getLong, (accessor) -> is((long) accessor.getDouble())); } @Test public void testShouldGetFloatMethodFromFloat8Vector() throws Exception { - accessorIterator.assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getFloat, + accessorIterator.assertAccessorGetter( + vector, + ArrowFlightJdbcFloat8VectorAccessor::getFloat, (accessor) -> is((float) accessor.getDouble())); } @Test public void testShouldGetBigDecimalMethodFromFloat8Vector() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - double value = accessor.getDouble(); - if (Double.isInfinite(value) || Double.isNaN(value)) { - exceptionCollector.expect(SQLException.class); - } - collector.checkThat(accessor.getBigDecimal(), is(BigDecimal.valueOf(value))); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + double value = accessor.getDouble(); + if (Double.isInfinite(value) || Double.isNaN(value)) { + exceptionCollector.expect(SQLException.class); + } + collector.checkThat(accessor.getBigDecimal(), is(BigDecimal.valueOf(value))); + }); } @Test public void testShouldGetObjectClass() throws Exception { - accessorIterator - .assertAccessorGetter(vector, ArrowFlightJdbcFloat8VectorAccessor::getObjectClass, - equalTo(Double.class)); + accessorIterator.assertAccessorGetter( + vector, ArrowFlightJdbcFloat8VectorAccessor::getObjectClass, equalTo(Double.class)); } @Test public void testShouldGetStringMethodFromFloat8VectorWithNull() throws Exception { - accessorIterator - .assertAccessorGetter(vectorWithNull, ArrowFlightJdbcFloat8VectorAccessor::getString, - CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcFloat8VectorAccessor::getString, CoreMatchers.nullValue()); } @Test public void testShouldGetFloatMethodFromFloat8VectorWithNull() throws Exception { - accessorIterator - .assertAccessorGetter(vectorWithNull, ArrowFlightJdbcFloat8VectorAccessor::getFloat, - is(0.0f)); + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcFloat8VectorAccessor::getFloat, is(0.0f)); } @Test public void testShouldGetBigDecimalMethodFromFloat8VectorWithNull() throws Exception { - accessorIterator.assertAccessorGetter(vectorWithNull, + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcFloat8VectorAccessor::getBigDecimal, CoreMatchers.nullValue()); } @Test public void testShouldGetBigDecimalWithScaleMethodFromFloat4Vector() throws Exception { - accessorIterator.iterate(vector, (accessor, currentRow) -> { - double value = accessor.getDouble(); - if (Double.isInfinite(value) || Double.isNaN(value)) { - exceptionCollector.expect(SQLException.class); - } - collector.checkThat(accessor.getBigDecimal(9), - is(BigDecimal.valueOf(value).setScale(9, RoundingMode.HALF_UP))); - }); + accessorIterator.iterate( + vector, + (accessor, currentRow) -> { + double value = accessor.getDouble(); + if (Double.isInfinite(value) || Double.isNaN(value)) { + exceptionCollector.expect(SQLException.class); + } + collector.checkThat( + accessor.getBigDecimal(9), + is(BigDecimal.valueOf(value).setScale(9, RoundingMode.HALF_UP))); + }); } @Test public void testShouldGetObjectMethodFromFloat8VectorWithNull() throws Exception { - accessorIterator - .assertAccessorGetter(vectorWithNull, ArrowFlightJdbcFloat8VectorAccessor::getObject, - CoreMatchers.nullValue()); + accessorIterator.assertAccessorGetter( + vectorWithNull, ArrowFlightJdbcFloat8VectorAccessor::getObject, CoreMatchers.nullValue()); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessorTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessorTest.java index 799c517dd56..12237beb83f 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessorTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessorTest.java @@ -36,7 +36,6 @@ import java.util.Calendar; import java.util.TimeZone; import java.util.function.IntSupplier; - import org.apache.arrow.driver.jdbc.accessor.impl.calendar.ArrowFlightJdbcDateVectorAccessor; import org.apache.arrow.driver.jdbc.accessor.impl.calendar.ArrowFlightJdbcTimeStampVectorAccessor; import org.apache.arrow.driver.jdbc.accessor.impl.calendar.ArrowFlightJdbcTimeVectorAccessor; @@ -57,7 +56,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - @RunWith(MockitoJUnitRunner.class) public class ArrowFlightJdbcVarCharVectorAccessorTest { @@ -69,21 +67,18 @@ public class ArrowFlightJdbcVarCharVectorAccessorTest { @ClassRule public static RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); - @Mock - private ArrowFlightJdbcVarCharVectorAccessor.Getter getter; + @Mock private ArrowFlightJdbcVarCharVectorAccessor.Getter getter; - @Rule - public ErrorCollector collector = new ErrorCollector(); + @Rule public ErrorCollector collector = new ErrorCollector(); - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); @Before public void setUp() { IntSupplier currentRowSupplier = () -> 0; accessor = - new ArrowFlightJdbcVarCharVectorAccessor(getter, currentRowSupplier, (boolean wasNull) -> { - }); + new ArrowFlightJdbcVarCharVectorAccessor( + getter, currentRowSupplier, (boolean wasNull) -> {}); } @Test @@ -313,7 +308,8 @@ public void testShouldGetLongReturnValidNegativeLong() throws Exception { } @Test - public void testShouldBigDecimalWithParametersThrowsExceptionForNonNumericValue() throws Exception { + public void testShouldBigDecimalWithParametersThrowsExceptionForNonNumericValue() + throws Exception { Text value = new Text("Invalid value for BigDecimal."); when(getter.get(0)).thenReturn(value.copyBytes()); @@ -501,8 +497,8 @@ public void testShouldGetDateReturnValidDateWithoutCalendar() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.setTime(result); - collector.checkThat(dateTimeFormat.format(calendar.getTime()), - equalTo("2021-07-02T00:00:00.000Z")); + collector.checkThat( + dateTimeFormat.format(calendar.getTime()), equalTo("2021-07-02T00:00:00.000Z")); } @Test @@ -516,8 +512,8 @@ public void testShouldGetDateReturnValidDateWithCalendar() throws Exception { calendar = Calendar.getInstance(TimeZone.getTimeZone("Etc/UTC")); calendar.setTime(result); - collector.checkThat(dateTimeFormat.format(calendar.getTime()), - equalTo("2021-07-02T03:00:00.000Z")); + collector.checkThat( + dateTimeFormat.format(calendar.getTime()), equalTo("2021-07-02T03:00:00.000Z")); } @Test @@ -575,8 +571,8 @@ public void testShouldGetTimestampReturnValidDateWithoutCalendar() throws Except Calendar calendar = Calendar.getInstance(); calendar.setTime(result); - collector.checkThat(dateTimeFormat.format(calendar.getTime()), - equalTo("2021-07-02T02:30:00.000Z")); + collector.checkThat( + dateTimeFormat.format(calendar.getTime()), equalTo("2021-07-02T02:30:00.000Z")); } @Test @@ -590,8 +586,8 @@ public void testShouldGetTimestampReturnValidDateWithCalendar() throws Exception calendar = Calendar.getInstance(TimeZone.getTimeZone("Etc/UTC")); calendar.setTime(result); - collector.checkThat(dateTimeFormat.format(calendar.getTime()), - equalTo("2021-07-02T05:30:00.000Z")); + collector.checkThat( + dateTimeFormat.format(calendar.getTime()), equalTo("2021-07-02T05:30:00.000Z")); } private void assertGetBoolean(Text value, boolean expectedResult) throws SQLException { @@ -602,7 +598,8 @@ private void assertGetBoolean(Text value, boolean expectedResult) throws SQLExce private void assertGetBooleanForSQLException(Text value) { when(getter.get(0)).thenReturn(value == null ? null : value.copyBytes()); - ThrowableAssertionUtils.simpleAssertThrowableClass(SQLException.class, () -> accessor.getBoolean()); + ThrowableAssertionUtils.simpleAssertThrowableClass( + SQLException.class, () -> accessor.getBoolean()); } @Test @@ -649,8 +646,7 @@ public void testShouldGetUnicodeStreamReturnValidInputStream() throws Exception try (final InputStream result = accessor.getUnicodeStream()) { byte[] resultBytes = toByteArray(result); - collector.checkThat(new String(resultBytes, UTF_8), - equalTo(value.toString())); + collector.checkThat(new String(resultBytes, UTF_8), equalTo(value.toString())); } } @@ -683,9 +679,8 @@ public void testShouldGetCharacterStreamReturnValidReader() throws Exception { public void testShouldGetTimeStampBeConsistentWithTimeStampAccessor() throws Exception { try (TimeStampVector timeStampVector = rootAllocatorTestRule.createTimeStampMilliVector()) { ArrowFlightJdbcTimeStampVectorAccessor timeStampVectorAccessor = - new ArrowFlightJdbcTimeStampVectorAccessor(timeStampVector, () -> 0, - (boolean wasNull) -> { - }); + new ArrowFlightJdbcTimeStampVectorAccessor( + timeStampVector, () -> 0, (boolean wasNull) -> {}); Text value = new Text(timeStampVectorAccessor.getString()); when(getter.get(0)).thenReturn(value.copyBytes()); @@ -699,8 +694,7 @@ public void testShouldGetTimeStampBeConsistentWithTimeStampAccessor() throws Exc public void testShouldGetTimeBeConsistentWithTimeAccessor() throws Exception { try (TimeMilliVector timeVector = rootAllocatorTestRule.createTimeMilliVector()) { ArrowFlightJdbcTimeVectorAccessor timeVectorAccessor = - new ArrowFlightJdbcTimeVectorAccessor(timeVector, () -> 0, (boolean wasNull) -> { - }); + new ArrowFlightJdbcTimeVectorAccessor(timeVector, () -> 0, (boolean wasNull) -> {}); Text value = new Text(timeVectorAccessor.getString()); when(getter.get(0)).thenReturn(value.copyBytes()); @@ -714,8 +708,7 @@ public void testShouldGetTimeBeConsistentWithTimeAccessor() throws Exception { public void testShouldGetDateBeConsistentWithDateAccessor() throws Exception { try (DateMilliVector dateVector = rootAllocatorTestRule.createDateMilliVector()) { ArrowFlightJdbcDateVectorAccessor dateVectorAccessor = - new ArrowFlightJdbcDateVectorAccessor(dateVector, () -> 0, (boolean wasNull) -> { - }); + new ArrowFlightJdbcDateVectorAccessor(dateVector, () -> 0, (boolean wasNull) -> {}); Text value = new Text(dateVectorAccessor.getString()); when(getter.get(0)).thenReturn(value.copyBytes()); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/Authentication.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/Authentication.java index 5fe2b0dc057..6e53c933f2c 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/Authentication.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/Authentication.java @@ -18,7 +18,6 @@ package org.apache.arrow.driver.jdbc.authentication; import java.util.Properties; - import org.apache.arrow.flight.auth2.CallHeaderAuthenticator; public interface Authentication { @@ -31,6 +30,7 @@ public interface Authentication { /** * Uses the validCredentials variable and populate the Properties object. + * * @param properties the Properties object that will be populated. */ void populateProperties(Properties properties); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/TokenAuthentication.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/TokenAuthentication.java index 605705d1ca9..a8825ccf15a 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/TokenAuthentication.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/TokenAuthentication.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; - import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl; import org.apache.arrow.flight.CallHeaders; import org.apache.arrow.flight.CallStatus; @@ -40,7 +39,9 @@ public CallHeaderAuthenticator authenticate() { public AuthResult authenticate(CallHeaders incomingHeaders) { String authorization = incomingHeaders.get("authorization"); if (!validCredentials.contains(authorization)) { - throw CallStatus.UNAUTHENTICATED.withDescription("Invalid credentials.").toRuntimeException(); + throw CallStatus.UNAUTHENTICATED + .withDescription("Invalid credentials.") + .toRuntimeException(); } return new AuthResult() { @Override @@ -54,8 +55,11 @@ public String getPeerIdentity() { @Override public void populateProperties(Properties properties) { - this.validCredentials.forEach(value -> properties.put( - ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty.TOKEN.camelName(), value)); + this.validCredentials.forEach( + value -> + properties.put( + ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty.TOKEN.camelName(), + value)); } public static final class Builder { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/UserPasswordAuthentication.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/UserPasswordAuthentication.java index 5dc97c858f3..a7008781754 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/UserPasswordAuthentication.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/authentication/UserPasswordAuthentication.java @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; - import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl; import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.auth2.BasicCallHeaderAuthenticator; @@ -42,20 +41,28 @@ private String getCredentials(String key) { @Override public CallHeaderAuthenticator authenticate() { return new GeneratedBearerTokenAuthenticator( - new BasicCallHeaderAuthenticator((username, password) -> { - if (validCredentials.containsKey(username) && getCredentials(username).equals(password)) { - return () -> username; - } - throw CallStatus.UNAUTHENTICATED.withDescription("Invalid credentials.").toRuntimeException(); - })); + new BasicCallHeaderAuthenticator( + (username, password) -> { + if (validCredentials.containsKey(username) + && getCredentials(username).equals(password)) { + return () -> username; + } + throw CallStatus.UNAUTHENTICATED + .withDescription("Invalid credentials.") + .toRuntimeException(); + })); } @Override public void populateProperties(Properties properties) { - validCredentials.forEach((key, value) -> { - properties.put(ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty.USER.camelName(), key); - properties.put(ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty.PASSWORD.camelName(), value); - }); + validCredentials.forEach( + (key, value) -> { + properties.put( + ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty.USER.camelName(), key); + properties.put( + ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty.PASSWORD.camelName(), + value); + }); } public static class Builder { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerBuilderTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerBuilderTest.java index 6565a85ddf9..5e6470de12a 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerBuilderTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerBuilderTest.java @@ -32,13 +32,11 @@ import org.junit.ClassRule; import org.junit.Test; -/** - * Test the behavior of ArrowFlightSqlClientHandler.Builder - */ +/** Test the behavior of ArrowFlightSqlClientHandler.Builder */ public class ArrowFlightSqlClientHandlerBuilderTest { @ClassRule - public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = FlightServerTestRule - .createStandardTestRule(CoreMockedSqlProducers.getLegacyProducer()); + public static final FlightServerTestRule FLIGHT_SERVER_TEST_RULE = + FlightServerTestRule.createStandardTestRule(CoreMockedSqlProducers.getLegacyProducer()); private static BufferAllocator allocator; @@ -55,19 +53,21 @@ public static void tearDown() { @Test public void testRetainCookiesOnAuthOff() throws Exception { // Arrange - final ArrowFlightSqlClientHandler.Builder rootBuilder = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withBufferAllocator(allocator) - .withUsername(FlightServerTestRule.DEFAULT_USER) - .withPassword(FlightServerTestRule.DEFAULT_PASSWORD) - .withEncryption(false) - .withRetainCookies(true) - .withRetainAuth(false); + final ArrowFlightSqlClientHandler.Builder rootBuilder = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withBufferAllocator(allocator) + .withUsername(FlightServerTestRule.DEFAULT_USER) + .withPassword(FlightServerTestRule.DEFAULT_PASSWORD) + .withEncryption(false) + .withRetainCookies(true) + .withRetainAuth(false); try (ArrowFlightSqlClientHandler rootHandler = rootBuilder.build()) { // Act - final ArrowFlightSqlClientHandler.Builder testBuilder = new ArrowFlightSqlClientHandler.Builder(rootBuilder); + final ArrowFlightSqlClientHandler.Builder testBuilder = + new ArrowFlightSqlClientHandler.Builder(rootBuilder); // Assert assertSame(rootBuilder.cookieFactory, testBuilder.cookieFactory); @@ -78,19 +78,21 @@ public void testRetainCookiesOnAuthOff() throws Exception { @Test public void testRetainCookiesOffAuthOff() throws Exception { // Arrange - final ArrowFlightSqlClientHandler.Builder rootBuilder = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withBufferAllocator(allocator) - .withUsername(FlightServerTestRule.DEFAULT_USER) - .withPassword(FlightServerTestRule.DEFAULT_PASSWORD) - .withEncryption(false) - .withRetainCookies(false) - .withRetainAuth(false); + final ArrowFlightSqlClientHandler.Builder rootBuilder = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withBufferAllocator(allocator) + .withUsername(FlightServerTestRule.DEFAULT_USER) + .withPassword(FlightServerTestRule.DEFAULT_PASSWORD) + .withEncryption(false) + .withRetainCookies(false) + .withRetainAuth(false); try (ArrowFlightSqlClientHandler rootHandler = rootBuilder.build()) { // Act - final ArrowFlightSqlClientHandler.Builder testBuilder = new ArrowFlightSqlClientHandler.Builder(rootBuilder); + final ArrowFlightSqlClientHandler.Builder testBuilder = + new ArrowFlightSqlClientHandler.Builder(rootBuilder); // Assert assertNotSame(rootBuilder.cookieFactory, testBuilder.cookieFactory); @@ -101,19 +103,21 @@ public void testRetainCookiesOffAuthOff() throws Exception { @Test public void testRetainCookiesOnAuthOn() throws Exception { // Arrange - final ArrowFlightSqlClientHandler.Builder rootBuilder = new ArrowFlightSqlClientHandler.Builder() - .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) - .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) - .withBufferAllocator(allocator) - .withUsername(FlightServerTestRule.DEFAULT_USER) - .withPassword(FlightServerTestRule.DEFAULT_PASSWORD) - .withEncryption(false) - .withRetainCookies(true) - .withRetainAuth(true); + final ArrowFlightSqlClientHandler.Builder rootBuilder = + new ArrowFlightSqlClientHandler.Builder() + .withHost(FLIGHT_SERVER_TEST_RULE.getHost()) + .withPort(FLIGHT_SERVER_TEST_RULE.getPort()) + .withBufferAllocator(allocator) + .withUsername(FlightServerTestRule.DEFAULT_USER) + .withPassword(FlightServerTestRule.DEFAULT_PASSWORD) + .withEncryption(false) + .withRetainCookies(true) + .withRetainAuth(true); try (ArrowFlightSqlClientHandler rootHandler = rootBuilder.build()) { // Act - final ArrowFlightSqlClientHandler.Builder testBuilder = new ArrowFlightSqlClientHandler.Builder(rootBuilder); + final ArrowFlightSqlClientHandler.Builder testBuilder = + new ArrowFlightSqlClientHandler.Builder(rootBuilder); // Assert assertSame(rootBuilder.cookieFactory, testBuilder.cookieFactory); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtilsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtilsTest.java index b7977462e9c..923dc2dd652 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtilsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/utils/ClientAuthenticationUtilsTest.java @@ -30,7 +30,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; - import org.bouncycastle.openssl.jcajce.JcaPEMWriter; import org.junit.Assert; import org.junit.Test; @@ -42,8 +41,7 @@ @RunWith(MockitoJUnitRunner.class) public class ClientAuthenticationUtilsTest { - @Mock - KeyStore keyStoreMock; + @Mock KeyStore keyStoreMock; @Test public void testGetCertificatesInputStream() throws IOException, KeyStoreException { @@ -61,38 +59,36 @@ public void testGetCertificatesInputStream() throws IOException, KeyStoreExcepti } @Test - public void testGetKeyStoreInstance() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetKeyStoreInstance() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { try (MockedStatic keyStoreMockedStatic = Mockito.mockStatic(KeyStore.class)) { keyStoreMockedStatic .when(() -> ClientAuthenticationUtils.getKeyStoreInstance(Mockito.any())) .thenReturn(keyStoreMock); KeyStore receiveKeyStore = ClientAuthenticationUtils.getKeyStoreInstance("test1"); - Mockito - .verify(keyStoreMock) - .load(null, null); + Mockito.verify(keyStoreMock).load(null, null); Assert.assertEquals(receiveKeyStore, keyStoreMock); } } @Test - public void testGetDefaultKeyStoreInstancePassword() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetDefaultKeyStoreInstancePassword() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { try (MockedStatic keyStoreMockedStatic = Mockito.mockStatic(KeyStore.class)) { keyStoreMockedStatic - .when(() -> ClientAuthenticationUtils.getDefaultKeyStoreInstance("changeit")) - .thenReturn(keyStoreMock); + .when(() -> ClientAuthenticationUtils.getDefaultKeyStoreInstance("changeit")) + .thenReturn(keyStoreMock); KeyStore receiveKeyStore = ClientAuthenticationUtils.getDefaultKeyStoreInstance("changeit"); Assert.assertEquals(receiveKeyStore, keyStoreMock); } } @Test - public void testGetDefaultKeyStoreInstanceNoPassword() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetDefaultKeyStoreInstanceNoPassword() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { try (MockedStatic keyStoreMockedStatic = Mockito.mockStatic(KeyStore.class)) { keyStoreMockedStatic @@ -103,44 +99,44 @@ public void testGetDefaultKeyStoreInstanceNoPassword() throws IOException, } } - @Test - public void testGetCertificateInputStreamFromMacSystem() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetCertificateInputStreamFromMacSystem() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { InputStream mock = mock(InputStream.class); try (MockedStatic keyStoreMockedStatic = createKeyStoreStaticMock(); - MockedStatic - clientAuthenticationUtilsMockedStatic = createClientAuthenticationUtilsStaticMock()) { + MockedStatic clientAuthenticationUtilsMockedStatic = + createClientAuthenticationUtilsStaticMock()) { setOperatingSystemMock(clientAuthenticationUtilsMockedStatic, false, true); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getKeyStoreInstance("KeychainStore")) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getKeyStoreInstance("KeychainStore")) .thenReturn(keyStoreMock); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getDefaultKeyStoreInstance("changeit")) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getDefaultKeyStoreInstance("changeit")) .thenReturn(keyStoreMock); clientAuthenticationUtilsMockedStatic .when(ClientAuthenticationUtils::getKeystoreInputStream) .thenCallRealMethod(); keyStoreMockedStatic.when(KeyStore::getDefaultType).thenCallRealMethod(); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getCertificatesInputStream(Mockito.any())) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getCertificatesInputStream(Mockito.any())) .thenReturn(mock); - InputStream inputStream = ClientAuthenticationUtils.getCertificateInputStreamFromSystem("changeit"); + InputStream inputStream = + ClientAuthenticationUtils.getCertificateInputStreamFromSystem("changeit"); Assert.assertEquals(inputStream, mock); } } @Test - public void testGetCertificateInputStreamFromWindowsSystem() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetCertificateInputStreamFromWindowsSystem() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { InputStream mock = mock(InputStream.class); try (MockedStatic keyStoreMockedStatic = createKeyStoreStaticMock(); - MockedStatic - clientAuthenticationUtilsMockedStatic = createClientAuthenticationUtilsStaticMock()) { + MockedStatic clientAuthenticationUtilsMockedStatic = + createClientAuthenticationUtilsStaticMock()) { setOperatingSystemMock(clientAuthenticationUtilsMockedStatic, true, false); keyStoreMockedStatic @@ -153,67 +149,74 @@ public void testGetCertificateInputStreamFromWindowsSystem() throws IOException, .when(() -> ClientAuthenticationUtils.getCertificatesInputStream(Mockito.any())) .thenReturn(mock); - InputStream inputStream = ClientAuthenticationUtils.getCertificateInputStreamFromSystem("test"); + InputStream inputStream = + ClientAuthenticationUtils.getCertificateInputStreamFromSystem("test"); Assert.assertEquals(inputStream, mock); } } @Test - public void testGetCertificateInputStreamFromLinuxSystem() throws IOException, - KeyStoreException, CertificateException, NoSuchAlgorithmException { + public void testGetCertificateInputStreamFromLinuxSystem() + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { InputStream mock = mock(InputStream.class); - try ( - MockedStatic keyStoreMockedStatic = createKeyStoreStaticMock(); - MockedStatic - clientAuthenticationUtilsMockedStatic = createClientAuthenticationUtilsStaticMock()) { + try (MockedStatic keyStoreMockedStatic = createKeyStoreStaticMock(); + MockedStatic clientAuthenticationUtilsMockedStatic = + createClientAuthenticationUtilsStaticMock()) { setOperatingSystemMock(clientAuthenticationUtilsMockedStatic, false, false); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getCertificatesInputStream(Mockito.any())) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getCertificatesInputStream(Mockito.any())) .thenReturn(mock); - keyStoreMockedStatic.when(() -> ClientAuthenticationUtils - .getDefaultKeyStoreInstance(Mockito.any())) + keyStoreMockedStatic + .when(() -> ClientAuthenticationUtils.getDefaultKeyStoreInstance(Mockito.any())) .thenReturn(keyStoreMock); clientAuthenticationUtilsMockedStatic .when(ClientAuthenticationUtils::getKeystoreInputStream) .thenCallRealMethod(); keyStoreMockedStatic.when(KeyStore::getDefaultType).thenCallRealMethod(); - InputStream inputStream = ClientAuthenticationUtils.getCertificateInputStreamFromSystem("changeit"); + InputStream inputStream = + ClientAuthenticationUtils.getCertificateInputStreamFromSystem("changeit"); Assert.assertEquals(inputStream, mock); inputStream = ClientAuthenticationUtils.getCertificateInputStreamFromSystem(null); Assert.assertEquals(inputStream, mock); } } - private MockedStatic createKeyStoreStaticMock() { - return Mockito.mockStatic(KeyStore.class, invocationOnMock -> { + return Mockito.mockStatic( + KeyStore.class, + invocationOnMock -> { Method method = invocationOnMock.getMethod(); if (method.getName().equals("getInstance")) { return invocationOnMock.callRealMethod(); } return method.invoke(invocationOnMock.getMock(), invocationOnMock.getArguments()); - } - ); + }); } private MockedStatic createClientAuthenticationUtilsStaticMock() { - return Mockito.mockStatic(ClientAuthenticationUtils.class , invocationOnMock -> { - Method method = invocationOnMock.getMethod(); - if (method.getName().equals("getCertificateInputStreamFromSystem")) { - return invocationOnMock.callRealMethod(); - } - return method.invoke(invocationOnMock.getMock(), invocationOnMock.getArguments()); - }); + return Mockito.mockStatic( + ClientAuthenticationUtils.class, + invocationOnMock -> { + Method method = invocationOnMock.getMethod(); + if (method.getName().equals("getCertificateInputStreamFromSystem")) { + return invocationOnMock.callRealMethod(); + } + return method.invoke(invocationOnMock.getMock(), invocationOnMock.getArguments()); + }); } - private void setOperatingSystemMock(MockedStatic clientAuthenticationUtilsMockedStatic, - boolean isWindows, boolean isMac) { + private void setOperatingSystemMock( + MockedStatic clientAuthenticationUtilsMockedStatic, + boolean isWindows, + boolean isMac) { clientAuthenticationUtilsMockedStatic.when(ClientAuthenticationUtils::isMac).thenReturn(isMac); Assert.assertEquals(ClientAuthenticationUtils.isMac(), isMac); - clientAuthenticationUtilsMockedStatic.when(ClientAuthenticationUtils::isWindows).thenReturn(isWindows); + clientAuthenticationUtilsMockedStatic + .when(ClientAuthenticationUtils::isWindows) + .thenReturn(isWindows); Assert.assertEquals(ClientAuthenticationUtils.isWindows(), isWindows); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/AccessorTestUtils.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/AccessorTestUtils.java index bc1e8a04203..08f37e4a754 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/AccessorTestUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/AccessorTestUtils.java @@ -26,7 +26,6 @@ import java.util.function.Function; import java.util.function.IntSupplier; import java.util.function.Supplier; - import org.apache.arrow.driver.jdbc.accessor.ArrowFlightJdbcAccessor; import org.apache.arrow.vector.ValueVector; import org.hamcrest.Matcher; @@ -106,35 +105,43 @@ public List toList(ValueVector vector) throws Exception { return result; } - public void assertAccessorGetter(ValueVector vector, CheckedFunction getter, - MatcherGetter matcherGetter) throws Exception { - iterate(vector, (accessor, currentRow) -> { - R object = getter.apply(accessor); - boolean wasNull = accessor.wasNull(); - - collector.checkThat(object, matcherGetter.get(accessor, currentRow)); - collector.checkThat(wasNull, is(accessor.getObject() == null)); - }); + public void assertAccessorGetter( + ValueVector vector, CheckedFunction getter, MatcherGetter matcherGetter) + throws Exception { + iterate( + vector, + (accessor, currentRow) -> { + R object = getter.apply(accessor); + boolean wasNull = accessor.wasNull(); + + collector.checkThat(object, matcherGetter.get(accessor, currentRow)); + collector.checkThat(wasNull, is(accessor.getObject() == null)); + }); } - public void assertAccessorGetterThrowingException(ValueVector vector, CheckedFunction getter) - throws Exception { - iterate(vector, (accessor, currentRow) -> - ThrowableAssertionUtils.simpleAssertThrowableClass(SQLException.class, () -> getter.apply(accessor))); + public void assertAccessorGetterThrowingException( + ValueVector vector, CheckedFunction getter) throws Exception { + iterate( + vector, + (accessor, currentRow) -> + ThrowableAssertionUtils.simpleAssertThrowableClass( + SQLException.class, () -> getter.apply(accessor))); } - public void assertAccessorGetter(ValueVector vector, CheckedFunction getter, - Function> matcherGetter) throws Exception { + public void assertAccessorGetter( + ValueVector vector, CheckedFunction getter, Function> matcherGetter) + throws Exception { assertAccessorGetter(vector, getter, (accessor, currentRow) -> matcherGetter.apply(accessor)); } - public void assertAccessorGetter(ValueVector vector, CheckedFunction getter, - Supplier> matcherGetter) throws Exception { + public void assertAccessorGetter( + ValueVector vector, CheckedFunction getter, Supplier> matcherGetter) + throws Exception { assertAccessorGetter(vector, getter, (accessor, currentRow) -> matcherGetter.get()); } - public void assertAccessorGetter(ValueVector vector, CheckedFunction getter, - Matcher matcher) throws Exception { + public void assertAccessorGetter( + ValueVector vector, CheckedFunction getter, Matcher matcher) throws Exception { assertAccessorGetter(vector, getter, (accessor, currentRow) -> matcher); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImplTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImplTest.java index 4fb07428af4..467a12baa1c 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImplTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionConfigImplTest.java @@ -31,7 +31,6 @@ import java.util.Properties; import java.util.Random; import java.util.function.Function; - import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; import org.junit.Before; import org.junit.Rule; @@ -50,11 +49,9 @@ public final class ArrowFlightConnectionConfigImplTest { private final Properties properties = new Properties(); private ArrowFlightConnectionConfigImpl arrowFlightConnectionConfig; - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); - @Parameter - public ArrowFlightConnectionProperty property; + @Parameter public ArrowFlightConnectionProperty property; @Parameter(value = 1) public Object value; @@ -70,27 +67,47 @@ public void setUp() { @Test public void testGetProperty() { - collector.checkThat(arrowFlightConnectionConfigFunction.apply(arrowFlightConnectionConfig), - is(value)); + collector.checkThat( + arrowFlightConnectionConfigFunction.apply(arrowFlightConnectionConfig), is(value)); } @Parameters(name = "<{0}> as <{1}>") public static List provideParameters() { - return asList(new Object[][] { - {HOST, "host", - (Function) ArrowFlightConnectionConfigImpl::getHost}, - {PORT, + return asList( + new Object[][] { + { + HOST, + "host", + (Function) ArrowFlightConnectionConfigImpl::getHost + }, + { + PORT, RANDOM.nextInt(Short.toUnsignedInt(Short.MAX_VALUE)), - (Function) ArrowFlightConnectionConfigImpl::getPort}, - {USER, "user", - (Function) ArrowFlightConnectionConfigImpl::getUser}, - {PASSWORD, "password", - (Function) ArrowFlightConnectionConfigImpl::getPassword}, - {USE_ENCRYPTION, RANDOM.nextBoolean(), - (Function) ArrowFlightConnectionConfigImpl::useEncryption}, - {THREAD_POOL_SIZE, + (Function) ArrowFlightConnectionConfigImpl::getPort + }, + { + USER, + "user", + (Function) ArrowFlightConnectionConfigImpl::getUser + }, + { + PASSWORD, + "password", + (Function) + ArrowFlightConnectionConfigImpl::getPassword + }, + { + USE_ENCRYPTION, + RANDOM.nextBoolean(), + (Function) + ArrowFlightConnectionConfigImpl::useEncryption + }, + { + THREAD_POOL_SIZE, RANDOM.nextInt(getRuntime().availableProcessors()), - (Function) ArrowFlightConnectionConfigImpl::threadPoolSize}, - }); + (Function) + ArrowFlightConnectionConfigImpl::threadPoolSize + }, + }); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionPropertyTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionPropertyTest.java index 25a48612cbd..dc302f26169 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionPropertyTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ArrowFlightConnectionPropertyTest.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; - import org.apache.arrow.driver.jdbc.utils.ArrowFlightConnectionConfigImpl.ArrowFlightConnectionProperty; import org.junit.After; import org.junit.Assert; @@ -39,13 +38,11 @@ @RunWith(Parameterized.class) public final class ArrowFlightConnectionPropertyTest { - @Mock - public Properties properties; + @Mock public Properties properties; private AutoCloseable mockitoResource; - @Parameter - public ArrowFlightConnectionProperty arrowFlightConnectionProperty; + @Parameter public ArrowFlightConnectionProperty arrowFlightConnectionProperty; @Before public void setUp() { @@ -59,21 +56,22 @@ public void tearDown() throws Exception { @Test public void testWrapIsUnsupported() { - ThrowableAssertionUtils.simpleAssertThrowableClass(UnsupportedOperationException.class, - () -> arrowFlightConnectionProperty.wrap(properties)); + ThrowableAssertionUtils.simpleAssertThrowableClass( + UnsupportedOperationException.class, () -> arrowFlightConnectionProperty.wrap(properties)); } @Test public void testRequiredPropertyThrows() { Assume.assumeTrue(arrowFlightConnectionProperty.required()); - ThrowableAssertionUtils.simpleAssertThrowableClass(IllegalStateException.class, - () -> arrowFlightConnectionProperty.get(new Properties())); + ThrowableAssertionUtils.simpleAssertThrowableClass( + IllegalStateException.class, () -> arrowFlightConnectionProperty.get(new Properties())); } @Test public void testOptionalPropertyReturnsDefault() { Assume.assumeTrue(!arrowFlightConnectionProperty.required()); - Assert.assertEquals(arrowFlightConnectionProperty.defaultValue(), + Assert.assertEquals( + arrowFlightConnectionProperty.defaultValue(), arrowFlightConnectionProperty.get(new Properties())); } @@ -82,7 +80,8 @@ public static List provideParameters() { final ArrowFlightConnectionProperty[] arrowFlightConnectionProperties = ArrowFlightConnectionProperty.values(); final List parameters = new ArrayList<>(arrowFlightConnectionProperties.length); - for (final ArrowFlightConnectionProperty arrowFlightConnectionProperty : arrowFlightConnectionProperties) { + for (final ArrowFlightConnectionProperty arrowFlightConnectionProperty : + arrowFlightConnectionProperties) { parameters.add(new Object[] {arrowFlightConnectionProperty}); } return parameters; diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapperTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapperTest.java index 6044f3a363c..ebbc42cbaff 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapperTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ConnectionWrapperTest.java @@ -35,7 +35,6 @@ import java.sql.Statement; import java.util.Arrays; import java.util.Random; - import org.apache.arrow.driver.jdbc.ArrowFlightConnection; import org.apache.arrow.util.AutoCloseables; import org.apache.calcite.avatica.AvaticaConnection; @@ -66,11 +65,9 @@ public final class ConnectionWrapperTest { private static final Random RANDOM = new Random(Long.MAX_VALUE); private static final int TIMEOUT = RANDOM.nextInt(Integer.MAX_VALUE); - @Mock - public AvaticaConnection underlyingConnection; + @Mock public AvaticaConnection underlyingConnection; private ConnectionWrapper connectionWrapper; - @Rule - public final ErrorCollector collector = new ErrorCollector(); + @Rule public final ErrorCollector collector = new ErrorCollector(); @Before public void setUp() { @@ -93,10 +90,10 @@ public void testUnwrappingUnderlyingConnectionShouldReturnUnderlyingConnection() collector.checkThat( collector.checkSucceeds(() -> connectionWrapper.unwrap(AvaticaConnection.class)), is(sameInstance(underlyingConnection))); - ThrowableAssertionUtils.simpleAssertThrowableClass(ClassCastException.class, - () -> connectionWrapper.unwrap(ArrowFlightConnection.class)); - ThrowableAssertionUtils.simpleAssertThrowableClass(ClassCastException.class, - () -> connectionWrapper.unwrap(ConnectionWrapper.class)); + ThrowableAssertionUtils.simpleAssertThrowableClass( + ClassCastException.class, () -> connectionWrapper.unwrap(ArrowFlightConnection.class)); + ThrowableAssertionUtils.simpleAssertThrowableClass( + ClassCastException.class, () -> connectionWrapper.unwrap(ConnectionWrapper.class)); } @Test @@ -106,14 +103,16 @@ public void testCreateStatementShouldCreateStatementFromUnderlyingConnection() connectionWrapper.createStatement(), is(sameInstance(verify(underlyingConnection, times(1)).createStatement()))); collector.checkThat( - connectionWrapper.createStatement(RESULT_SET_TYPE, RESULT_SET_CONCURRENCY, - RESULT_SET_HOLDABILITY), - is(verify(underlyingConnection, times(1)) - .createStatement(RESULT_SET_TYPE, RESULT_SET_CONCURRENCY, RESULT_SET_HOLDABILITY))); + connectionWrapper.createStatement( + RESULT_SET_TYPE, RESULT_SET_CONCURRENCY, RESULT_SET_HOLDABILITY), + is( + verify(underlyingConnection, times(1)) + .createStatement(RESULT_SET_TYPE, RESULT_SET_CONCURRENCY, RESULT_SET_HOLDABILITY))); collector.checkThat( connectionWrapper.createStatement(RESULT_SET_TYPE, RESULT_SET_CONCURRENCY), - is(verify(underlyingConnection, times(1)) - .createStatement(RESULT_SET_TYPE, RESULT_SET_CONCURRENCY))); + is( + verify(underlyingConnection, times(1)) + .createStatement(RESULT_SET_TYPE, RESULT_SET_CONCURRENCY))); } @Test @@ -121,49 +120,62 @@ public void testPrepareStatementShouldPrepareStatementFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.prepareStatement(PLACEHOLDER_QUERY), - is(sameInstance( - verify(underlyingConnection, times(1)).prepareStatement(PLACEHOLDER_QUERY)))); + is( + sameInstance( + verify(underlyingConnection, times(1)).prepareStatement(PLACEHOLDER_QUERY)))); collector.checkThat( connectionWrapper.prepareStatement(PLACEHOLDER_QUERY, COLUMN_INDICES), - is(allOf(sameInstance(verify(underlyingConnection, times(1)) - .prepareStatement(PLACEHOLDER_QUERY, COLUMN_INDICES)), - nullValue()))); + is( + allOf( + sameInstance( + verify(underlyingConnection, times(1)) + .prepareStatement(PLACEHOLDER_QUERY, COLUMN_INDICES)), + nullValue()))); collector.checkThat( connectionWrapper.prepareStatement(PLACEHOLDER_QUERY, COLUMN_NAMES), - is(allOf(sameInstance(verify(underlyingConnection, times(1)) - .prepareStatement(PLACEHOLDER_QUERY, COLUMN_NAMES)), - nullValue()))); - collector.checkThat( - connectionWrapper.prepareStatement(PLACEHOLDER_QUERY, RESULT_SET_TYPE, - RESULT_SET_CONCURRENCY), - is(allOf(sameInstance(verify(underlyingConnection, times(1)) - .prepareStatement(PLACEHOLDER_QUERY, RESULT_SET_TYPE, RESULT_SET_CONCURRENCY)), - nullValue()))); + is( + allOf( + sameInstance( + verify(underlyingConnection, times(1)) + .prepareStatement(PLACEHOLDER_QUERY, COLUMN_NAMES)), + nullValue()))); + collector.checkThat( + connectionWrapper.prepareStatement( + PLACEHOLDER_QUERY, RESULT_SET_TYPE, RESULT_SET_CONCURRENCY), + is( + allOf( + sameInstance( + verify(underlyingConnection, times(1)) + .prepareStatement( + PLACEHOLDER_QUERY, RESULT_SET_TYPE, RESULT_SET_CONCURRENCY)), + nullValue()))); collector.checkThat( connectionWrapper.prepareStatement(PLACEHOLDER_QUERY, GENERATED_KEYS), - is(allOf(sameInstance(verify(underlyingConnection, times(1)) - .prepareStatement(PLACEHOLDER_QUERY, GENERATED_KEYS)), - nullValue()))); + is( + allOf( + sameInstance( + verify(underlyingConnection, times(1)) + .prepareStatement(PLACEHOLDER_QUERY, GENERATED_KEYS)), + nullValue()))); } @Test public void testPrepareCallShouldPrepareCallFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.prepareCall(PLACEHOLDER_QUERY), - is(sameInstance( - verify(underlyingConnection, times(1)).prepareCall(PLACEHOLDER_QUERY)))); + is(sameInstance(verify(underlyingConnection, times(1)).prepareCall(PLACEHOLDER_QUERY)))); collector.checkThat( connectionWrapper.prepareCall(PLACEHOLDER_QUERY, RESULT_SET_TYPE, RESULT_SET_CONCURRENCY), - is(verify(underlyingConnection, times(1)) - .prepareCall(PLACEHOLDER_QUERY, RESULT_SET_TYPE, RESULT_SET_CONCURRENCY))); + is( + verify(underlyingConnection, times(1)) + .prepareCall(PLACEHOLDER_QUERY, RESULT_SET_TYPE, RESULT_SET_CONCURRENCY))); } @Test public void testNativeSqlShouldGetNativeSqlFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.nativeSQL(PLACEHOLDER_QUERY), - is(sameInstance( - verify(underlyingConnection, times(1)).nativeSQL(PLACEHOLDER_QUERY)))); + is(sameInstance(verify(underlyingConnection, times(1)).nativeSQL(PLACEHOLDER_QUERY)))); } @Test @@ -221,8 +233,8 @@ public void testSetReadOnlyShouldSetUnderlyingConnectionAsReadOnly() throws SQLE @Test public void testSetIsReadOnlyShouldGetStatusFromUnderlyingConnection() throws SQLException { - collector.checkThat(connectionWrapper.isReadOnly(), - is(verify(underlyingConnection).isReadOnly())); + collector.checkThat( + connectionWrapper.isReadOnly(), is(verify(underlyingConnection).isReadOnly())); } @Test @@ -257,9 +269,7 @@ public void getTransactionIsolationShouldGetUnderlyingConnectionIsolation() thro public void getWarningShouldGetWarningsFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.getWarnings(), - is(allOf( - sameInstance(verify(underlyingConnection, times(1)).getWarnings()), - nullValue()))); + is(allOf(sameInstance(verify(underlyingConnection, times(1)).getWarnings()), nullValue()))); } @Test @@ -272,8 +282,7 @@ public void testClearWarningShouldClearWarningsFromUnderlyingConnection() throws public void getTypeMapShouldGetTypeMapFromUnderlyingConnection() throws SQLException { when(underlyingConnection.getTypeMap()).thenReturn(null); collector.checkThat( - connectionWrapper.getTypeMap(), - is(verify(underlyingConnection, times(1)).getTypeMap())); + connectionWrapper.getTypeMap(), is(verify(underlyingConnection, times(1)).getTypeMap())); } @Test @@ -299,13 +308,12 @@ public void testGetHoldabilityShouldGetHoldabilityFromUnderlyingConnection() thr public void testSetSavepointShouldSetSavepointInUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.setSavepoint(), - is(allOf( - sameInstance(verify(underlyingConnection, times(1)).setSavepoint()), - nullValue()))); + is( + allOf( + sameInstance(verify(underlyingConnection, times(1)).setSavepoint()), nullValue()))); collector.checkThat( connectionWrapper.setSavepoint(SAVEPOINT_NAME), - is(sameInstance( - verify(underlyingConnection, times(1)).setSavepoint(SAVEPOINT_NAME)))); + is(sameInstance(verify(underlyingConnection, times(1)).setSavepoint(SAVEPOINT_NAME)))); } @Test @@ -325,32 +333,30 @@ public void testReleaseSavepointShouldReleaseSavepointFromUnderlyingConnection() public void testCreateClobShouldCreateClobFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.createClob(), - is(allOf(sameInstance( - verify(underlyingConnection, times(1)).createClob()), nullValue()))); + is(allOf(sameInstance(verify(underlyingConnection, times(1)).createClob()), nullValue()))); } @Test public void testCreateBlobShouldCreateBlobFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.createBlob(), - is(allOf(sameInstance( - verify(underlyingConnection, times(1)).createBlob()), nullValue()))); + is(allOf(sameInstance(verify(underlyingConnection, times(1)).createBlob()), nullValue()))); } @Test public void testCreateNClobShouldCreateNClobFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.createNClob(), - is(allOf(sameInstance( - verify(underlyingConnection, times(1)).createNClob()), nullValue()))); + is(allOf(sameInstance(verify(underlyingConnection, times(1)).createNClob()), nullValue()))); } @Test public void testCreateSQLXMLShouldCreateSQLXMLFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.createSQLXML(), - is(allOf(sameInstance( - verify(underlyingConnection, times(1)).createSQLXML()), nullValue()))); + is( + allOf( + sameInstance(verify(underlyingConnection, times(1)).createSQLXML()), nullValue()))); } @Test @@ -371,16 +377,16 @@ public void testSetClientInfoShouldSetClientInfoInUnderlyingConnection() public void testGetClientInfoShouldGetClientInfoFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.getClientInfo(CLIENT_INFO), - is(allOf( - sameInstance( - verify(underlyingConnection, times(1)).getClientInfo(CLIENT_INFO)), - nullValue()))); + is( + allOf( + sameInstance(verify(underlyingConnection, times(1)).getClientInfo(CLIENT_INFO)), + nullValue()))); collector.checkThat( connectionWrapper.getClientInfo(), - is(allOf( - sameInstance( - verify(underlyingConnection, times(1)).getClientInfo()), - nullValue()))); + is( + allOf( + sameInstance(verify(underlyingConnection, times(1)).getClientInfo()), + nullValue()))); } @Test @@ -388,10 +394,11 @@ public void testCreateArrayOfShouldCreateArrayFromUnderlyingConnection() throws final Object[] elements = range(0, 100).boxed().toArray(); collector.checkThat( connectionWrapper.createArrayOf(TYPE_NAME, elements), - is(allOf( - sameInstance( - verify(underlyingConnection, times(1)).createArrayOf(TYPE_NAME, elements)), - nullValue()))); + is( + allOf( + sameInstance( + verify(underlyingConnection, times(1)).createArrayOf(TYPE_NAME, elements)), + nullValue()))); } @Test @@ -399,10 +406,11 @@ public void testCreateStructShouldCreateStructFromUnderlyingConnection() throws final Object[] attributes = range(0, 120).boxed().toArray(); collector.checkThat( connectionWrapper.createStruct(TYPE_NAME, attributes), - is(allOf( - sameInstance( - verify(underlyingConnection, times(1)).createStruct(TYPE_NAME, attributes)), - nullValue()))); + is( + allOf( + sameInstance( + verify(underlyingConnection, times(1)).createStruct(TYPE_NAME, attributes)), + nullValue()))); } @Test @@ -415,9 +423,7 @@ public void testSetSchemaShouldSetSchemaInUnderlyingConnection() throws SQLExcep public void testGetSchemaShouldGetSchemaFromUnderlyingConnection() throws SQLException { collector.checkThat( connectionWrapper.getSchema(), - is(allOf( - sameInstance(verify(underlyingConnection, times(1)).getSchema()), - nullValue()))); + is(allOf(sameInstance(verify(underlyingConnection, times(1)).getSchema()), nullValue()))); } @Test diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ConvertUtilsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ConvertUtilsTest.java index 5cea3749283..2d7cc09392d 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ConvertUtilsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ConvertUtilsTest.java @@ -19,8 +19,8 @@ import static org.hamcrest.CoreMatchers.equalTo; +import com.google.common.collect.ImmutableList; import java.util.List; - import org.apache.arrow.flight.sql.FlightSqlColumnMetadata; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; @@ -31,28 +31,26 @@ import org.junit.Test; import org.junit.rules.ErrorCollector; -import com.google.common.collect.ImmutableList; - public class ConvertUtilsTest { - @Rule - public ErrorCollector collector = new ErrorCollector(); + @Rule public ErrorCollector collector = new ErrorCollector(); @Test public void testShouldSetOnColumnMetaDataBuilder() { final Common.ColumnMetaData.Builder builder = Common.ColumnMetaData.newBuilder(); - final FlightSqlColumnMetadata expectedColumnMetaData = new FlightSqlColumnMetadata.Builder() - .catalogName("catalog1") - .schemaName("schema1") - .tableName("table1") - .isAutoIncrement(true) - .isCaseSensitive(true) - .isReadOnly(true) - .isSearchable(true) - .precision(20) - .scale(10) - .build(); + final FlightSqlColumnMetadata expectedColumnMetaData = + new FlightSqlColumnMetadata.Builder() + .catalogName("catalog1") + .schemaName("schema1") + .tableName("table1") + .isAutoIncrement(true) + .isCaseSensitive(true) + .isReadOnly(true) + .isSearchable(true) + .precision(20) + .scale(10) + .build(); ConvertUtils.setOnColumnMetaDataBuilder(builder, expectedColumnMetaData.getMetadataMap()); assertBuilder(builder, expectedColumnMetaData); } @@ -60,57 +58,77 @@ public void testShouldSetOnColumnMetaDataBuilder() { @Test public void testShouldConvertArrowFieldsToColumnMetaDataList() { - final List listField = ImmutableList.of( - new Field("col1", - new FieldType(true, ArrowType.Utf8.INSTANCE, null, - new FlightSqlColumnMetadata.Builder() - .catalogName("catalog1") - .schemaName("schema1") - .tableName("table1") - .build().getMetadataMap() - ), null)); - - final List expectedColumnMetaData = ImmutableList.of( - ColumnMetaData.fromProto( - Common.ColumnMetaData.newBuilder() - .setCatalogName("catalog1") - .setSchemaName("schema1") - .setTableName("table1") - .build())); - - final List actualColumnMetaData = ConvertUtils.convertArrowFieldsToColumnMetaDataList(listField); + final List listField = + ImmutableList.of( + new Field( + "col1", + new FieldType( + true, + ArrowType.Utf8.INSTANCE, + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("catalog1") + .schemaName("schema1") + .tableName("table1") + .build() + .getMetadataMap()), + null)); + + final List expectedColumnMetaData = + ImmutableList.of( + ColumnMetaData.fromProto( + Common.ColumnMetaData.newBuilder() + .setCatalogName("catalog1") + .setSchemaName("schema1") + .setTableName("table1") + .build())); + + final List actualColumnMetaData = + ConvertUtils.convertArrowFieldsToColumnMetaDataList(listField); assertColumnMetaData(expectedColumnMetaData, actualColumnMetaData); } - private void assertColumnMetaData(final List expected, final List actual) { + private void assertColumnMetaData( + final List expected, final List actual) { collector.checkThat(expected.size(), equalTo(actual.size())); int size = expected.size(); for (int i = 0; i < size; i++) { final ColumnMetaData expectedColumnMetaData = expected.get(i); final ColumnMetaData actualColumnMetaData = actual.get(i); - collector.checkThat(expectedColumnMetaData.catalogName, equalTo(actualColumnMetaData.catalogName)); - collector.checkThat(expectedColumnMetaData.schemaName, equalTo(actualColumnMetaData.schemaName)); - collector.checkThat(expectedColumnMetaData.tableName, equalTo(actualColumnMetaData.tableName)); + collector.checkThat( + expectedColumnMetaData.catalogName, equalTo(actualColumnMetaData.catalogName)); + collector.checkThat( + expectedColumnMetaData.schemaName, equalTo(actualColumnMetaData.schemaName)); + collector.checkThat( + expectedColumnMetaData.tableName, equalTo(actualColumnMetaData.tableName)); collector.checkThat(expectedColumnMetaData.readOnly, equalTo(actualColumnMetaData.readOnly)); - collector.checkThat(expectedColumnMetaData.autoIncrement, equalTo(actualColumnMetaData.autoIncrement)); - collector.checkThat(expectedColumnMetaData.precision, equalTo(actualColumnMetaData.precision)); + collector.checkThat( + expectedColumnMetaData.autoIncrement, equalTo(actualColumnMetaData.autoIncrement)); + collector.checkThat( + expectedColumnMetaData.precision, equalTo(actualColumnMetaData.precision)); collector.checkThat(expectedColumnMetaData.scale, equalTo(actualColumnMetaData.scale)); - collector.checkThat(expectedColumnMetaData.caseSensitive, equalTo(actualColumnMetaData.caseSensitive)); - collector.checkThat(expectedColumnMetaData.searchable, equalTo(actualColumnMetaData.searchable)); + collector.checkThat( + expectedColumnMetaData.caseSensitive, equalTo(actualColumnMetaData.caseSensitive)); + collector.checkThat( + expectedColumnMetaData.searchable, equalTo(actualColumnMetaData.searchable)); } } - private void assertBuilder(final Common.ColumnMetaData.Builder builder, - final FlightSqlColumnMetadata flightSqlColumnMetaData) { + private void assertBuilder( + final Common.ColumnMetaData.Builder builder, + final FlightSqlColumnMetadata flightSqlColumnMetaData) { final Integer precision = flightSqlColumnMetaData.getPrecision(); final Integer scale = flightSqlColumnMetaData.getScale(); - collector.checkThat(flightSqlColumnMetaData.getCatalogName(), equalTo(builder.getCatalogName())); + collector.checkThat( + flightSqlColumnMetaData.getCatalogName(), equalTo(builder.getCatalogName())); collector.checkThat(flightSqlColumnMetaData.getSchemaName(), equalTo(builder.getSchemaName())); collector.checkThat(flightSqlColumnMetaData.getTableName(), equalTo(builder.getTableName())); - collector.checkThat(flightSqlColumnMetaData.isAutoIncrement(), equalTo(builder.getAutoIncrement())); - collector.checkThat(flightSqlColumnMetaData.isCaseSensitive(), equalTo(builder.getCaseSensitive())); + collector.checkThat( + flightSqlColumnMetaData.isAutoIncrement(), equalTo(builder.getAutoIncrement())); + collector.checkThat( + flightSqlColumnMetaData.isCaseSensitive(), equalTo(builder.getCaseSensitive())); collector.checkThat(flightSqlColumnMetaData.isSearchable(), equalTo(builder.getSearchable())); collector.checkThat(flightSqlColumnMetaData.isReadOnly(), equalTo(builder.getReadOnly())); collector.checkThat(precision == null ? 0 : precision, equalTo(builder.getPrecision())); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/CoreMockedSqlProducers.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/CoreMockedSqlProducers.java index a8e2e7f2e4c..607d60c1f44 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/CoreMockedSqlProducers.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/CoreMockedSqlProducers.java @@ -21,6 +21,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; +import com.google.common.collect.ImmutableList; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; @@ -30,7 +31,6 @@ import java.util.List; import java.util.function.Consumer; import java.util.stream.IntStream; - import org.apache.arrow.flight.FlightProducer.ServerStreamListener; import org.apache.arrow.flight.sql.FlightSqlColumnMetadata; import org.apache.arrow.memory.BufferAllocator; @@ -53,11 +53,7 @@ import org.apache.arrow.vector.util.Text; import org.junit.rules.ErrorCollector; -import com.google.common.collect.ImmutableList; - -/** - * Standard {@link MockFlightSqlProducer} instances for tests. - */ +/** Standard {@link MockFlightSqlProducer} instances for tests. */ // TODO Remove this once all tests are refactor to use only the queries they need. public final class CoreMockedSqlProducers { @@ -86,210 +82,216 @@ public static MockFlightSqlProducer getLegacyProducer() { } private static void addQueryWithEmbeddedEmptyRoot(final MockFlightSqlProducer producer) { - final Schema querySchema = new Schema(ImmutableList.of( - new Field( - "ID", - new FieldType(true, new ArrowType.Int(64, true), - null), - null) - )); + final Schema querySchema = + new Schema( + ImmutableList.of( + new Field("ID", new FieldType(true, new ArrowType.Int(64, true), null), null))); final List> resultProducers = new ArrayList<>(); - Consumer dataRoot = listener -> { - try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - final VectorSchemaRoot root = VectorSchemaRoot.create(querySchema, allocator)) { - root.allocateNew(); - root.setRowCount(0); - listener.start(root); - listener.putNext(); // empty root - ((BigIntVector) root.getVector("ID")).setSafe(0, 100L); - root.setRowCount(1); - listener.putNext(); // data root - root.clear(); - root.setRowCount(0); - listener.putNext(); // empty root - ((BigIntVector) root.getVector("ID")).setSafe(0, 100L); - root.setRowCount(1); - listener.putNext(); // data root - } finally { - listener.completed(); - } - }; + Consumer dataRoot = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); + final VectorSchemaRoot root = VectorSchemaRoot.create(querySchema, allocator)) { + root.allocateNew(); + root.setRowCount(0); + listener.start(root); + listener.putNext(); // empty root + ((BigIntVector) root.getVector("ID")).setSafe(0, 100L); + root.setRowCount(1); + listener.putNext(); // data root + root.clear(); + root.setRowCount(0); + listener.putNext(); // empty root + ((BigIntVector) root.getVector("ID")).setSafe(0, 100L); + root.setRowCount(1); + listener.putNext(); // data root + } finally { + listener.completed(); + } + }; resultProducers.add(dataRoot); producer.addSelectQuery(LEGACY_REGULAR_WITH_EMPTY_SQL_CMD, querySchema, resultProducers); } private static void addLegacyRegularSqlCmdSupport(final MockFlightSqlProducer producer) { - final Schema querySchema = new Schema(ImmutableList.of( - new Field( - "ID", - new FieldType(true, new ArrowType.Int(64, true), - null), - null), - new Field( - "Name", - new FieldType(true, new ArrowType.Utf8(), null), - null), - new Field( - "Age", - new FieldType(true, new ArrowType.Int(32, false), - null), - null), - new Field( - "Salary", - new FieldType(true, new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), - null), - null), - new Field( - "Hire Date", - new FieldType(true, new ArrowType.Date(DateUnit.DAY), null), - null), - new Field( - "Last Sale", - new FieldType(true, new ArrowType.Timestamp(TimeUnit.MILLISECOND, null), - null), - null) - )); + final Schema querySchema = + new Schema( + ImmutableList.of( + new Field("ID", new FieldType(true, new ArrowType.Int(64, true), null), null), + new Field("Name", new FieldType(true, new ArrowType.Utf8(), null), null), + new Field("Age", new FieldType(true, new ArrowType.Int(32, false), null), null), + new Field( + "Salary", + new FieldType( + true, new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), null), + null), + new Field( + "Hire Date", new FieldType(true, new ArrowType.Date(DateUnit.DAY), null), null), + new Field( + "Last Sale", + new FieldType(true, new ArrowType.Timestamp(TimeUnit.MILLISECOND, null), null), + null))); final List> resultProducers = new ArrayList<>(); - IntStream.range(0, 10).forEach(page -> { - resultProducers.add(listener -> { - final int rowsPerPage = 5000; - try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - final VectorSchemaRoot root = VectorSchemaRoot.create(querySchema, allocator)) { - root.allocateNew(); - listener.start(root); - int batchSize = 500; - int indexOnBatch = 0; - int resultsOffset = page * rowsPerPage; - for (int i = 0; i < rowsPerPage; i++) { - ((BigIntVector) root.getVector("ID")) - .setSafe(indexOnBatch, (long) Integer.MAX_VALUE + 1 + i + resultsOffset); - ((VarCharVector) root.getVector("Name")) - .setSafe(indexOnBatch, new Text("Test Name #" + (resultsOffset + i))); - ((UInt4Vector) root.getVector("Age")) - .setSafe(indexOnBatch, (int) Short.MAX_VALUE + 1 + i + resultsOffset); - ((Float8Vector) root.getVector("Salary")) - .setSafe(indexOnBatch, - Math.scalb((double) (i + resultsOffset) / 2, i + resultsOffset)); - ((DateDayVector) root.getVector("Hire Date")) - .setSafe(indexOnBatch, i + resultsOffset); - ((TimeStampMilliVector) root.getVector("Last Sale")) - .setSafe(indexOnBatch, Long.MAX_VALUE - i - resultsOffset); - indexOnBatch++; - if (indexOnBatch == batchSize) { - root.setRowCount(indexOnBatch); - if (listener.isCancelled()) { - return; - } - listener.putNext(); - root.allocateNew(); - indexOnBatch = 0; - } - } - if (listener.isCancelled()) { - return; - } - root.setRowCount(indexOnBatch); - listener.putNext(); - } finally { - listener.completed(); - } - }); - }); + IntStream.range(0, 10) + .forEach( + page -> { + resultProducers.add( + listener -> { + final int rowsPerPage = 5000; + try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); + final VectorSchemaRoot root = + VectorSchemaRoot.create(querySchema, allocator)) { + root.allocateNew(); + listener.start(root); + int batchSize = 500; + int indexOnBatch = 0; + int resultsOffset = page * rowsPerPage; + for (int i = 0; i < rowsPerPage; i++) { + ((BigIntVector) root.getVector("ID")) + .setSafe( + indexOnBatch, (long) Integer.MAX_VALUE + 1 + i + resultsOffset); + ((VarCharVector) root.getVector("Name")) + .setSafe(indexOnBatch, new Text("Test Name #" + (resultsOffset + i))); + ((UInt4Vector) root.getVector("Age")) + .setSafe(indexOnBatch, (int) Short.MAX_VALUE + 1 + i + resultsOffset); + ((Float8Vector) root.getVector("Salary")) + .setSafe( + indexOnBatch, + Math.scalb((double) (i + resultsOffset) / 2, i + resultsOffset)); + ((DateDayVector) root.getVector("Hire Date")) + .setSafe(indexOnBatch, i + resultsOffset); + ((TimeStampMilliVector) root.getVector("Last Sale")) + .setSafe(indexOnBatch, Long.MAX_VALUE - i - resultsOffset); + indexOnBatch++; + if (indexOnBatch == batchSize) { + root.setRowCount(indexOnBatch); + if (listener.isCancelled()) { + return; + } + listener.putNext(); + root.allocateNew(); + indexOnBatch = 0; + } + } + if (listener.isCancelled()) { + return; + } + root.setRowCount(indexOnBatch); + listener.putNext(); + } finally { + listener.completed(); + } + }); + }); producer.addSelectQuery(LEGACY_REGULAR_SQL_CMD, querySchema, resultProducers); } private static void addLegacyMetadataSqlCmdSupport(final MockFlightSqlProducer producer) { - final Schema metadataSchema = new Schema(ImmutableList.of( - new Field( - "integer0", - new FieldType(true, new ArrowType.Int(64, true), - null, new FlightSqlColumnMetadata.Builder() - .catalogName("CATALOG_NAME_1") - .schemaName("SCHEMA_NAME_1") - .tableName("TABLE_NAME_1") - .typeName("TYPE_NAME_1") - .precision(10) - .scale(0) - .isAutoIncrement(true) - .isCaseSensitive(false) - .isReadOnly(true) - .isSearchable(true) - .build().getMetadataMap()), - null), - new Field( - "string1", - new FieldType(true, new ArrowType.Utf8(), - null, new FlightSqlColumnMetadata.Builder() - .catalogName("CATALOG_NAME_2") - .schemaName("SCHEMA_NAME_2") - .tableName("TABLE_NAME_2") - .typeName("TYPE_NAME_2") - .precision(65535) - .scale(0) - .isAutoIncrement(false) - .isCaseSensitive(true) - .isReadOnly(false) - .isSearchable(true) - .build().getMetadataMap()), - null), - new Field( - "float2", - new FieldType(true, new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), - null, new FlightSqlColumnMetadata.Builder() - .catalogName("CATALOG_NAME_3") - .schemaName("SCHEMA_NAME_3") - .tableName("TABLE_NAME_3") - .typeName("TYPE_NAME_3") - .precision(15) - .scale(20) - .isAutoIncrement(false) - .isCaseSensitive(false) - .isReadOnly(false) - .isSearchable(true) - .build().getMetadataMap()), - null))); - final Consumer formula = listener -> { - try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - final VectorSchemaRoot root = VectorSchemaRoot.create(metadataSchema, allocator)) { - root.allocateNew(); - ((BigIntVector) root.getVector("integer0")).setSafe(0, 1); - ((VarCharVector) root.getVector("string1")).setSafe(0, new Text("teste")); - ((Float4Vector) root.getVector("float2")).setSafe(0, (float) 4.1); - root.setRowCount(1); - listener.start(root); - listener.putNext(); - } finally { - listener.completed(); - } - }; - producer.addSelectQuery(LEGACY_METADATA_SQL_CMD, metadataSchema, - Collections.singletonList(formula)); + final Schema metadataSchema = + new Schema( + ImmutableList.of( + new Field( + "integer0", + new FieldType( + true, + new ArrowType.Int(64, true), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("CATALOG_NAME_1") + .schemaName("SCHEMA_NAME_1") + .tableName("TABLE_NAME_1") + .typeName("TYPE_NAME_1") + .precision(10) + .scale(0) + .isAutoIncrement(true) + .isCaseSensitive(false) + .isReadOnly(true) + .isSearchable(true) + .build() + .getMetadataMap()), + null), + new Field( + "string1", + new FieldType( + true, + new ArrowType.Utf8(), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("CATALOG_NAME_2") + .schemaName("SCHEMA_NAME_2") + .tableName("TABLE_NAME_2") + .typeName("TYPE_NAME_2") + .precision(65535) + .scale(0) + .isAutoIncrement(false) + .isCaseSensitive(true) + .isReadOnly(false) + .isSearchable(true) + .build() + .getMetadataMap()), + null), + new Field( + "float2", + new FieldType( + true, + new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("CATALOG_NAME_3") + .schemaName("SCHEMA_NAME_3") + .tableName("TABLE_NAME_3") + .typeName("TYPE_NAME_3") + .precision(15) + .scale(20) + .isAutoIncrement(false) + .isCaseSensitive(false) + .isReadOnly(false) + .isSearchable(true) + .build() + .getMetadataMap()), + null))); + final Consumer formula = + listener -> { + try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); + final VectorSchemaRoot root = VectorSchemaRoot.create(metadataSchema, allocator)) { + root.allocateNew(); + ((BigIntVector) root.getVector("integer0")).setSafe(0, 1); + ((VarCharVector) root.getVector("string1")).setSafe(0, new Text("teste")); + ((Float4Vector) root.getVector("float2")).setSafe(0, (float) 4.1); + root.setRowCount(1); + listener.start(root); + listener.putNext(); + } finally { + listener.completed(); + } + }; + producer.addSelectQuery( + LEGACY_METADATA_SQL_CMD, metadataSchema, Collections.singletonList(formula)); } private static void addLegacyCancellationSqlCmdSupport(final MockFlightSqlProducer producer) { producer.addSelectQuery( LEGACY_CANCELLATION_SQL_CMD, - new Schema(Collections.singletonList(new Field( - "integer0", - new FieldType(true, new ArrowType.Int(64, true), null), - null))), - Collections.singletonList(listener -> { - // Should keep hanging until canceled. - })); + new Schema( + Collections.singletonList( + new Field( + "integer0", new FieldType(true, new ArrowType.Int(64, true), null), null))), + Collections.singletonList( + listener -> { + // Should keep hanging until canceled. + })); } /** - * Asserts that the values in the provided {@link ResultSet} are expected for the - * legacy {@link MockFlightSqlProducer}. + * Asserts that the values in the provided {@link ResultSet} are expected for the legacy {@link + * MockFlightSqlProducer}. * * @param resultSet the result set. * @param collector the {@link ErrorCollector} to use. * @throws SQLException on error. */ - public static void assertLegacyRegularSqlResultSet(final ResultSet resultSet, - final ErrorCollector collector) - throws SQLException { + public static void assertLegacyRegularSqlResultSet( + final ResultSet resultSet, final ErrorCollector collector) throws SQLException { final int expectedRowCount = 50_000; final long[] expectedIds = new long[expectedRowCount]; diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/DateTimeUtilsTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/DateTimeUtilsTest.java index adb892fcdc7..58db9723990 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/DateTimeUtilsTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/DateTimeUtilsTest.java @@ -23,15 +23,13 @@ import java.time.Instant; import java.util.Calendar; import java.util.TimeZone; - import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.ErrorCollector; public class DateTimeUtilsTest { - @ClassRule - public static final ErrorCollector collector = new ErrorCollector(); + @ClassRule public static final ErrorCollector collector = new ErrorCollector(); private final TimeZone defaultTimezone = TimeZone.getTimeZone("UTC"); private final TimeZone alternateTimezone = TimeZone.getTimeZone("America/Vancouver"); private final long positiveEpochMilli = 959817600000L; // 2000-06-01 00:00:00 UTC @@ -48,7 +46,8 @@ public void testShouldGetOffsetWithSameTimeZone() { try { // Trying to guarantee timezone returns to its original value final long expected = epochMillis + offset; - final long actual = DateTimeUtils.applyCalendarOffset(epochMillis, Calendar.getInstance(defaultTimezone)); + final long actual = + DateTimeUtils.applyCalendarOffset(epochMillis, Calendar.getInstance(defaultTimezone)); collector.checkThat(actual, is(expected)); } finally { @@ -68,8 +67,8 @@ public void testShouldGetOffsetWithDifferentTimeZone() { try { // Trying to guarantee timezone returns to its original value final long expectedEpochMillis = epochMillis + offset; - final long actualEpochMillis = DateTimeUtils.applyCalendarOffset(epochMillis, Calendar.getInstance( - defaultTimezone)); + final long actualEpochMillis = + DateTimeUtils.applyCalendarOffset(epochMillis, Calendar.getInstance(defaultTimezone)); collector.checkThat(actualEpochMillis, is(expectedEpochMillis)); } finally { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueueTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueueTest.java index 05325faa18e..d6e5726f219 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueueTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueueTest.java @@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock; import java.util.concurrent.CompletionService; - import org.apache.arrow.driver.jdbc.client.CloseableEndpointStreamPair; import org.junit.Before; import org.junit.Rule; @@ -32,16 +31,12 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -/** - * Tests for {@link FlightEndpointDataQueue}. - */ +/** Tests for {@link FlightEndpointDataQueue}. */ @RunWith(MockitoJUnitRunner.class) public class FlightEndpointDataQueueTest { - @Rule - public final ErrorCollector collector = new ErrorCollector(); - @Mock - private CompletionService mockedService; + @Rule public final ErrorCollector collector = new ErrorCollector(); + @Mock private CompletionService mockedService; private FlightEndpointDataQueue queue; @Before @@ -57,24 +52,27 @@ public void testNextShouldRetrieveNullIfEmpty() throws Exception { @Test public void testNextShouldThrowExceptionUponClose() throws Exception { queue.close(); - ThrowableAssertionUtils.simpleAssertThrowableClass(IllegalStateException.class, () -> queue.next()); + ThrowableAssertionUtils.simpleAssertThrowableClass( + IllegalStateException.class, () -> queue.next()); } @Test public void testEnqueueShouldThrowExceptionUponClose() throws Exception { queue.close(); - ThrowableAssertionUtils.simpleAssertThrowableClass(IllegalStateException.class, - () -> queue.enqueue(mock(CloseableEndpointStreamPair.class))); + ThrowableAssertionUtils.simpleAssertThrowableClass( + IllegalStateException.class, () -> queue.enqueue(mock(CloseableEndpointStreamPair.class))); } @Test public void testCheckOpen() throws Exception { - collector.checkSucceeds(() -> { - queue.checkOpen(); - return true; - }); + collector.checkSucceeds( + () -> { + queue.checkOpen(); + return true; + }); queue.close(); - ThrowableAssertionUtils.simpleAssertThrowableClass(IllegalStateException.class, () -> queue.checkOpen()); + ThrowableAssertionUtils.simpleAssertThrowableClass( + IllegalStateException.class, () -> queue.checkOpen()); } @Test diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/FlightSqlTestCertificates.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/FlightSqlTestCertificates.java index 89e27be9f53..744e87a8c4a 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/FlightSqlTestCertificates.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/FlightSqlTestCertificates.java @@ -24,9 +24,7 @@ import java.util.List; import java.util.Objects; -/** - * Utility class for unit tests that need to reference the certificate params. - */ +/** Utility class for unit tests that need to reference the certificate params. */ public class FlightSqlTestCertificates { public static final String TEST_DATA_ENV_VAR = "ARROW_TEST_DATA"; @@ -37,9 +35,12 @@ static Path getTestDataRoot() { if (path == null) { path = System.getProperty(TEST_DATA_PROPERTY); } - return Paths.get(Objects.requireNonNull(path, - String.format("Could not find test data path. Set the environment variable %s or the JVM property %s.", - TEST_DATA_ENV_VAR, TEST_DATA_PROPERTY))); + return Paths.get( + Objects.requireNonNull( + path, + String.format( + "Could not find test data path. Set the environment variable %s or the JVM property %s.", + TEST_DATA_ENV_VAR, TEST_DATA_PROPERTY))); } /** @@ -68,10 +69,9 @@ public static File exampleCACert() { */ public static List exampleTlsCerts() { final Path root = getFlightTestDataRoot(); - return Arrays.asList(new CertKeyPair(root.resolve("cert0.pem") - .toFile(), root.resolve("cert0.pkcs1").toFile()), - new CertKeyPair(root.resolve("cert1.pem") - .toFile(), root.resolve("cert1.pkcs1").toFile())); + return Arrays.asList( + new CertKeyPair(root.resolve("cert0.pem").toFile(), root.resolve("cert0.pkcs1").toFile()), + new CertKeyPair(root.resolve("cert1.pem").toFile(), root.resolve("cert1.pkcs1").toFile())); } public static class CertKeyPair { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java index c165bfb7ce3..965498be0f4 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/MockFlightSqlProducer.java @@ -23,6 +23,9 @@ import static java.util.UUID.randomUUID; import static java.util.stream.Collectors.toList; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.Message; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; @@ -40,7 +43,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.stream.IntStream; - import org.apache.arrow.flight.Action; import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.Criteria; @@ -84,13 +86,7 @@ import org.apache.arrow.vector.util.JsonStringArrayList; import org.apache.calcite.avatica.Meta.StatementType; -import com.google.protobuf.Any; -import com.google.protobuf.ByteString; -import com.google.protobuf.Message; - -/** - * An ad-hoc {@link FlightSqlProducer} for tests. - */ +/** An ad-hoc {@link FlightSqlProducer} for tests. */ public final class MockFlightSqlProducer implements FlightSqlProducer { private final Map>> queryResults = new HashMap<>(); @@ -99,26 +95,26 @@ public final class MockFlightSqlProducer implements FlightSqlProducer { private final Map> catalogQueriesResults = new HashMap<>(); private final Map>> - updateResultProviders = - new HashMap<>(); + updateResultProviders = new HashMap<>(); private final SqlInfoBuilder sqlInfoBuilder = new SqlInfoBuilder(); private final Map parameterSchemas = new HashMap<>(); private final Map>> expectedParameterValues = new HashMap<>(); private final Map actionTypeCounter = new HashMap<>(); - private static FlightInfo getFlightInfoExportedAndImportedKeys(final Message message, - final FlightDescriptor descriptor) { + private static FlightInfo getFlightInfoExportedAndImportedKeys( + final Message message, final FlightDescriptor descriptor) { return getFlightInfo(message, Schemas.GET_IMPORTED_KEYS_SCHEMA, descriptor); } - private static FlightInfo getFlightInfo(final Message message, final Schema schema, - final FlightDescriptor descriptor) { + private static FlightInfo getFlightInfo( + final Message message, final Schema schema, final FlightDescriptor descriptor) { return new FlightInfo( schema, descriptor, Collections.singletonList(new FlightEndpoint(new Ticket(Any.pack(message).toByteArray()))), - -1, -1); + -1, + -1); } public static ByteBuffer serializeSchema(final Schema schema) { @@ -135,12 +131,14 @@ public static ByteBuffer serializeSchema(final Schema schema) { /** * Registers a new {@link StatementType#SELECT} SQL query. * - * @param sqlCommand the SQL command under which to register the new query. - * @param schema the schema to use for the query result. + * @param sqlCommand the SQL command under which to register the new query. + * @param schema the schema to use for the query result. * @param resultProviders the result provider for this query. */ - public void addSelectQuery(final String sqlCommand, final Schema schema, - final List> resultProviders) { + public void addSelectQuery( + final String sqlCommand, + final Schema schema, + final List> resultProviders) { final int providers = resultProviders.size(); final List uuids = IntStream.range(0, providers) @@ -155,59 +153,64 @@ public void addSelectQuery(final String sqlCommand, final Schema schema, /** * Registers a new {@link StatementType#UPDATE} SQL query. * - * @param sqlCommand the SQL command. + * @param sqlCommand the SQL command. * @param updatedRows the number of rows affected. */ public void addUpdateQuery(final String sqlCommand, final long updatedRows) { - addUpdateQuery(sqlCommand, ((flightStream, putResultStreamListener) -> { - final DoPutUpdateResult result = - DoPutUpdateResult.newBuilder().setRecordCount(updatedRows).build(); - try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - final ArrowBuf buffer = allocator.buffer(result.getSerializedSize())) { - buffer.writeBytes(result.toByteArray()); - putResultStreamListener.onNext(PutResult.metadata(buffer)); - } catch (final Throwable throwable) { - putResultStreamListener.onError(throwable); - } finally { - putResultStreamListener.onCompleted(); - } - })); + addUpdateQuery( + sqlCommand, + ((flightStream, putResultStreamListener) -> { + final DoPutUpdateResult result = + DoPutUpdateResult.newBuilder().setRecordCount(updatedRows).build(); + try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); + final ArrowBuf buffer = allocator.buffer(result.getSerializedSize())) { + buffer.writeBytes(result.toByteArray()); + putResultStreamListener.onNext(PutResult.metadata(buffer)); + } catch (final Throwable throwable) { + putResultStreamListener.onError(throwable); + } finally { + putResultStreamListener.onCompleted(); + } + })); } /** * Adds a catalog query to the results. * - * @param message the {@link Message} corresponding to the catalog query request type to register. + * @param message the {@link Message} corresponding to the catalog query request type to register. * @param resultsProvider the results provider. */ - public void addCatalogQuery(final Message message, - final Consumer resultsProvider) { + public void addCatalogQuery( + final Message message, final Consumer resultsProvider) { catalogQueriesResults.put(message, resultsProvider); } /** * Registers a new {@link StatementType#UPDATE} SQL query. * - * @param sqlCommand the SQL command. + * @param sqlCommand the SQL command. * @param resultsProvider consumer for producing update results. */ - void addUpdateQuery(final String sqlCommand, - final BiConsumer> resultsProvider) { + void addUpdateQuery( + final String sqlCommand, + final BiConsumer> resultsProvider) { Preconditions.checkState( updateResultProviders.putIfAbsent(sqlCommand, resultsProvider) == null, format("Attempted to overwrite preexisting query: <%s>.", sqlCommand)); } /** Registers parameters expected to be provided with a prepared statement. */ - public void addExpectedParameters(String query, Schema parameterSchema, List> expectedValues) { + public void addExpectedParameters( + String query, Schema parameterSchema, List> expectedValues) { parameterSchemas.put(query, parameterSchema); expectedParameterValues.put(query, expectedValues); } @Override - public void createPreparedStatement(final ActionCreatePreparedStatementRequest request, - final CallContext callContext, - final StreamListener listener) { + public void createPreparedStatement( + final ActionCreatePreparedStatementRequest request, + final CallContext callContext, + final StreamListener listener) { try { final ByteString preparedStatementHandle = copyFrom(randomUUID().toString().getBytes(StandardCharsets.UTF_8)); @@ -222,8 +225,7 @@ public void createPreparedStatement(final ActionCreatePreparedStatementRequest r preparedStatements.put(preparedStatementHandle, query); final Schema datasetSchema = entry.getKey(); - final ByteString datasetSchemaBytes = - ByteString.copyFrom(serializeSchema(datasetSchema)); + final ByteString datasetSchemaBytes = ByteString.copyFrom(serializeSchema(datasetSchema)); resultBuilder.setDatasetSchema(datasetSchemaBytes); } else if (updateResultProviders.containsKey(query)) { @@ -238,7 +240,8 @@ public void createPreparedStatement(final ActionCreatePreparedStatementRequest r final Schema parameterSchema = parameterSchemas.get(query); if (parameterSchema != null) { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - MessageSerializer.serialize(new WriteChannel(Channels.newChannel(outputStream)), parameterSchema); + MessageSerializer.serialize( + new WriteChannel(Channels.newChannel(outputStream)), parameterSchema); resultBuilder.setParameterSchema(ByteString.copyFrom(outputStream.toByteArray())); } @@ -253,19 +256,21 @@ public void createPreparedStatement(final ActionCreatePreparedStatementRequest r @Override public void closePreparedStatement( final ActionClosePreparedStatementRequest actionClosePreparedStatementRequest, - final CallContext callContext, final StreamListener streamListener) { + final CallContext callContext, + final StreamListener streamListener) { // TODO Implement this method. streamListener.onCompleted(); } @Override - public FlightInfo getFlightInfoStatement(final CommandStatementQuery commandStatementQuery, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoStatement( + final CommandStatementQuery commandStatementQuery, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { final String query = commandStatementQuery.getQuery(); final Entry> queryInfo = - Preconditions.checkNotNull(queryResults.get(query), - format("Query not registered: <%s>.", query)); + Preconditions.checkNotNull( + queryResults.get(query), format("Query not registered: <%s>.", query)); final List endpoints = queryInfo.getValue().stream() .map(TicketConversionUtils::getTicketBytesFromUuid) @@ -273,8 +278,8 @@ public FlightInfo getFlightInfoStatement(final CommandStatementQuery commandStat .map(TicketConversionUtils::getEndpointFromMessage) .collect(toList()); return FlightInfo.builder(queryInfo.getKey(), flightDescriptor, endpoints) - .setAppMetadata("foo".getBytes(StandardCharsets.UTF_8)) - .build(); + .setAppMetadata("foo".getBytes(StandardCharsets.UTF_8)) + .build(); } @Override @@ -285,12 +290,13 @@ public FlightInfo getFlightInfoPreparedStatement( final ByteString preparedStatementHandle = commandPreparedStatementQuery.getPreparedStatementHandle(); - final String query = Preconditions.checkNotNull( - preparedStatements.get(preparedStatementHandle), - format("No query registered under handle: <%s>.", preparedStatementHandle)); + final String query = + Preconditions.checkNotNull( + preparedStatements.get(preparedStatementHandle), + format("No query registered under handle: <%s>.", preparedStatementHandle)); final Entry> queryInfo = - Preconditions.checkNotNull(queryResults.get(query), - format("Query not registered: <%s>.", query)); + Preconditions.checkNotNull( + queryResults.get(query), format("Query not registered: <%s>.", query)); final List endpoints = queryInfo.getValue().stream() .map(TicketConversionUtils::getTicketBytesFromUuid) @@ -298,30 +304,33 @@ public FlightInfo getFlightInfoPreparedStatement( .map(TicketConversionUtils::getEndpointFromMessage) .collect(toList()); return FlightInfo.builder(queryInfo.getKey(), flightDescriptor, endpoints) - .setAppMetadata("foo".getBytes(StandardCharsets.UTF_8)) - .build(); + .setAppMetadata("foo".getBytes(StandardCharsets.UTF_8)) + .build(); } @Override - public SchemaResult getSchemaStatement(final CommandStatementQuery commandStatementQuery, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public SchemaResult getSchemaStatement( + final CommandStatementQuery commandStatementQuery, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { final String query = commandStatementQuery.getQuery(); final Entry> queryInfo = - Preconditions.checkNotNull(queryResults.get(query), - format("Query not registered: <%s>.", query)); + Preconditions.checkNotNull( + queryResults.get(query), format("Query not registered: <%s>.", query)); return new SchemaResult(queryInfo.getKey()); } @Override - public void getStreamStatement(final TicketStatementQuery ticketStatementQuery, - final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamStatement( + final TicketStatementQuery ticketStatementQuery, + final CallContext callContext, + final ServerStreamListener serverStreamListener) { final UUID uuid = UUID.fromString(ticketStatementQuery.getStatementHandle().toStringUtf8()); Preconditions.checkNotNull( selectResultProviders.get(uuid), - "No consumer was registered for the specified UUID: <%s>.", uuid) + "No consumer was registered for the specified UUID: <%s>.", + uuid) .accept(serverStreamListener); } @@ -334,15 +343,17 @@ public void getStreamPreparedStatement( UUID.fromString(commandPreparedStatementQuery.getPreparedStatementHandle().toStringUtf8()); Preconditions.checkNotNull( selectResultProviders.get(uuid), - "No consumer was registered for the specified UUID: <%s>.", uuid) + "No consumer was registered for the specified UUID: <%s>.", + uuid) .accept(serverStreamListener); } @Override - public Runnable acceptPutStatement(final CommandStatementUpdate commandStatementUpdate, - final CallContext callContext, - final FlightStream flightStream, - final StreamListener streamListener) { + public Runnable acceptPutStatement( + final CommandStatementUpdate commandStatementUpdate, + final CallContext callContext, + final FlightStream flightStream, + final StreamListener streamListener) { return () -> { final String query = commandStatementUpdate.getQuery(); final BiConsumer> resultProvider = @@ -353,9 +364,8 @@ public Runnable acceptPutStatement(final CommandStatementUpdate commandStatement }; } - private boolean validateParameters(String query, - FlightStream flightStream, - StreamListener streamListener) { + private boolean validateParameters( + String query, FlightStream flightStream, StreamListener streamListener) { final List> expectedValues = expectedParameterValues.get(query); if (expectedValues != null) { int index = 0; @@ -363,16 +373,18 @@ private boolean validateParameters(String query, final VectorSchemaRoot root = flightStream.getRoot(); for (int i = 0; i < root.getRowCount(); i++) { if (index >= expectedValues.size()) { - streamListener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("More parameter rows provided than expected") - .toRuntimeException()); + streamListener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("More parameter rows provided than expected") + .toRuntimeException()); return true; } List expectedRow = expectedValues.get(index++); if (root.getFieldVectors().size() != expectedRow.size()) { - streamListener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Parameter count mismatch") - .toRuntimeException()); + streamListener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Parameter count mismatch") + .toRuntimeException()); return true; } @@ -381,23 +393,28 @@ private boolean validateParameters(String query, Object actual = root.getVector(paramIndex).getObject(i); boolean matches; if (expected.getClass().isArray()) { - matches = Arrays.equals((Object[]) expected, ((JsonStringArrayList) actual).toArray()); + matches = + Arrays.equals((Object[]) expected, ((JsonStringArrayList) actual).toArray()); } else { matches = Objects.equals(expected, actual); } if (!matches) { - streamListener.onError(CallStatus.INVALID_ARGUMENT - .withDescription(String.format("Parameter mismatch. Expected: %s Actual: %s", expected, actual)) - .toRuntimeException()); + streamListener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription( + String.format( + "Parameter mismatch. Expected: %s Actual: %s", expected, actual)) + .toRuntimeException()); return true; } } } } if (index < expectedValues.size()) { - streamListener.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Fewer parameter rows provided than expected") - .toRuntimeException()); + streamListener.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Fewer parameter rows provided than expected") + .toRuntimeException()); return true; } } @@ -407,147 +424,167 @@ private boolean validateParameters(String query, @Override public Runnable acceptPutPreparedStatementUpdate( final CommandPreparedStatementUpdate commandPreparedStatementUpdate, - final CallContext callContext, final FlightStream flightStream, + final CallContext callContext, + final FlightStream flightStream, final StreamListener streamListener) { final ByteString handle = commandPreparedStatementUpdate.getPreparedStatementHandle(); - final String query = Preconditions.checkNotNull( - preparedStatements.get(handle), - format("No query registered under handle: <%s>.", handle)); + final String query = + Preconditions.checkNotNull( + preparedStatements.get(handle), + format("No query registered under handle: <%s>.", handle)); if (validateParameters(query, flightStream, streamListener)) { - return () -> { }; + return () -> {}; } return acceptPutStatement( - CommandStatementUpdate.newBuilder().setQuery(query).build(), callContext, flightStream, + CommandStatementUpdate.newBuilder().setQuery(query).build(), + callContext, + flightStream, streamListener); } @Override public Runnable acceptPutPreparedStatementQuery( final CommandPreparedStatementQuery commandPreparedStatementQuery, - final CallContext callContext, final FlightStream flightStream, + final CallContext callContext, + final FlightStream flightStream, final StreamListener streamListener) { final ByteString handle = commandPreparedStatementQuery.getPreparedStatementHandle(); - final String query = Preconditions.checkNotNull( - preparedStatements.get(handle), - format("No query registered under handle: <%s>.", handle)); + final String query = + Preconditions.checkNotNull( + preparedStatements.get(handle), + format("No query registered under handle: <%s>.", handle)); if (validateParameters(query, flightStream, streamListener)) { - return () -> { }; + return () -> {}; } return streamListener::onCompleted; } @Override - public FlightInfo getFlightInfoSqlInfo(final CommandGetSqlInfo commandGetSqlInfo, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoSqlInfo( + final CommandGetSqlInfo commandGetSqlInfo, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { return getFlightInfo(commandGetSqlInfo, Schemas.GET_SQL_INFO_SCHEMA, flightDescriptor); } @Override - public void getStreamSqlInfo(final CommandGetSqlInfo commandGetSqlInfo, - final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamSqlInfo( + final CommandGetSqlInfo commandGetSqlInfo, + final CallContext callContext, + final ServerStreamListener serverStreamListener) { sqlInfoBuilder.send(commandGetSqlInfo.getInfoList(), serverStreamListener); } @Override - public FlightInfo getFlightInfoTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTypeInfo( + FlightSql.CommandGetXdbcTypeInfo request, CallContext context, FlightDescriptor descriptor) { // TODO Implement this return null; } @Override - public void getStreamTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, CallContext context, - ServerStreamListener listener) { + public void getStreamTypeInfo( + FlightSql.CommandGetXdbcTypeInfo request, + CallContext context, + ServerStreamListener listener) { // TODO Implement this } @Override - public FlightInfo getFlightInfoCatalogs(final CommandGetCatalogs commandGetCatalogs, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoCatalogs( + final CommandGetCatalogs commandGetCatalogs, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { return getFlightInfo(commandGetCatalogs, Schemas.GET_CATALOGS_SCHEMA, flightDescriptor); } @Override - public void getStreamCatalogs(final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamCatalogs( + final CallContext callContext, final ServerStreamListener serverStreamListener) { final CommandGetCatalogs command = CommandGetCatalogs.getDefaultInstance(); getStreamCatalogFunctions(command, serverStreamListener); } @Override - public FlightInfo getFlightInfoSchemas(final CommandGetDbSchemas commandGetSchemas, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoSchemas( + final CommandGetDbSchemas commandGetSchemas, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { return getFlightInfo(commandGetSchemas, Schemas.GET_SCHEMAS_SCHEMA, flightDescriptor); } @Override - public void getStreamSchemas(final CommandGetDbSchemas commandGetSchemas, - final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamSchemas( + final CommandGetDbSchemas commandGetSchemas, + final CallContext callContext, + final ServerStreamListener serverStreamListener) { getStreamCatalogFunctions(commandGetSchemas, serverStreamListener); } @Override - public FlightInfo getFlightInfoTables(final CommandGetTables commandGetTables, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoTables( + final CommandGetTables commandGetTables, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { return getFlightInfo(commandGetTables, Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, flightDescriptor); } @Override - public void getStreamTables(final CommandGetTables commandGetTables, - final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamTables( + final CommandGetTables commandGetTables, + final CallContext callContext, + final ServerStreamListener serverStreamListener) { getStreamCatalogFunctions(commandGetTables, serverStreamListener); } @Override - public FlightInfo getFlightInfoTableTypes(final CommandGetTableTypes commandGetTableTypes, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoTableTypes( + final CommandGetTableTypes commandGetTableTypes, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { return getFlightInfo(commandGetTableTypes, Schemas.GET_TABLE_TYPES_SCHEMA, flightDescriptor); } @Override - public void getStreamTableTypes(final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamTableTypes( + final CallContext callContext, final ServerStreamListener serverStreamListener) { final CommandGetTableTypes command = CommandGetTableTypes.getDefaultInstance(); getStreamCatalogFunctions(command, serverStreamListener); } @Override - public FlightInfo getFlightInfoPrimaryKeys(final CommandGetPrimaryKeys commandGetPrimaryKeys, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoPrimaryKeys( + final CommandGetPrimaryKeys commandGetPrimaryKeys, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { return getFlightInfo(commandGetPrimaryKeys, Schemas.GET_PRIMARY_KEYS_SCHEMA, flightDescriptor); } @Override - public void getStreamPrimaryKeys(final CommandGetPrimaryKeys commandGetPrimaryKeys, - final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamPrimaryKeys( + final CommandGetPrimaryKeys commandGetPrimaryKeys, + final CallContext callContext, + final ServerStreamListener serverStreamListener) { getStreamCatalogFunctions(commandGetPrimaryKeys, serverStreamListener); } @Override - public FlightInfo getFlightInfoExportedKeys(final CommandGetExportedKeys commandGetExportedKeys, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoExportedKeys( + final CommandGetExportedKeys commandGetExportedKeys, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { return getFlightInfoExportedAndImportedKeys(commandGetExportedKeys, flightDescriptor); } @Override - public FlightInfo getFlightInfoImportedKeys(final CommandGetImportedKeys commandGetImportedKeys, - final CallContext callContext, - final FlightDescriptor flightDescriptor) { + public FlightInfo getFlightInfoImportedKeys( + final CommandGetImportedKeys commandGetImportedKeys, + final CallContext callContext, + final FlightDescriptor flightDescriptor) { return getFlightInfoExportedAndImportedKeys(commandGetImportedKeys, flightDescriptor); } @@ -560,23 +597,26 @@ public FlightInfo getFlightInfoCrossReference( } @Override - public void getStreamExportedKeys(final CommandGetExportedKeys commandGetExportedKeys, - final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamExportedKeys( + final CommandGetExportedKeys commandGetExportedKeys, + final CallContext callContext, + final ServerStreamListener serverStreamListener) { getStreamCatalogFunctions(commandGetExportedKeys, serverStreamListener); } @Override - public void getStreamImportedKeys(final CommandGetImportedKeys commandGetImportedKeys, - final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamImportedKeys( + final CommandGetImportedKeys commandGetImportedKeys, + final CallContext callContext, + final ServerStreamListener serverStreamListener) { getStreamCatalogFunctions(commandGetImportedKeys, serverStreamListener); } @Override - public void getStreamCrossReference(final CommandGetCrossReference commandGetCrossReference, - final CallContext callContext, - final ServerStreamListener serverStreamListener) { + public void getStreamCrossReference( + final CommandGetCrossReference commandGetCrossReference, + final CallContext callContext, + final ServerStreamListener serverStreamListener) { getStreamCatalogFunctions(commandGetCrossReference, serverStreamListener); } @@ -586,8 +626,10 @@ public void close() { } @Override - public void listFlights(final CallContext callContext, final Criteria criteria, - final StreamListener streamListener) { + public void listFlights( + final CallContext callContext, + final Criteria criteria, + final StreamListener streamListener) { // TODO Implement this method. throw CallStatus.UNIMPLEMENTED.toRuntimeException(); } @@ -595,11 +637,13 @@ public void listFlights(final CallContext callContext, final Criteria criteria, @Override public void doAction(CallContext context, Action action, StreamListener listener) { FlightSqlProducer.super.doAction(context, action, listener); - actionTypeCounter.put(action.getType(), actionTypeCounter.getOrDefault(action.getType(), 0) + 1); + actionTypeCounter.put( + action.getType(), actionTypeCounter.getOrDefault(action.getType(), 0) + 1); } /** - * Clear the `actionTypeCounter` map and restore to its default state. Intended to be used in tests. + * Clear the `actionTypeCounter` map and restore to its default state. Intended to be used in + * tests. */ public void clearActionTypeCounter() { actionTypeCounter.clear(); @@ -609,9 +653,8 @@ public Map getActionTypeCounter() { return actionTypeCounter; } - - private void getStreamCatalogFunctions(final Message ticket, - final ServerStreamListener serverStreamListener) { + private void getStreamCatalogFunctions( + final Message ticket, final ServerStreamListener serverStreamListener) { Preconditions.checkNotNull( catalogQueriesResults.get(ticket), format("Query not registered for ticket: <%s>", ticket)) diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/PartitionedFlightSqlProducer.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/PartitionedFlightSqlProducer.java index 3230ce626fa..a5f1851c224 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/PartitionedFlightSqlProducer.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/PartitionedFlightSqlProducer.java @@ -19,9 +19,10 @@ import static com.google.protobuf.Any.pack; +import com.google.protobuf.ByteString; +import com.google.protobuf.Message; import java.util.Arrays; import java.util.List; - import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.FlightDescriptor; import org.apache.arrow.flight.FlightEndpoint; @@ -34,14 +35,9 @@ import org.apache.arrow.vector.VectorSchemaRoot; import org.apache.arrow.vector.types.pojo.Schema; -import com.google.protobuf.ByteString; -import com.google.protobuf.Message; - public class PartitionedFlightSqlProducer extends BasicFlightSqlProducer { - /** - * A minimal FlightProducer intended to just serve data when given the correct Ticket. - */ + /** A minimal FlightProducer intended to just serve data when given the correct Ticket. */ public static class DataOnlyFlightSqlProducer extends NoOpFlightProducer { private final Ticket ticket; private final VectorSchemaRoot data; @@ -54,7 +50,8 @@ public DataOnlyFlightSqlProducer(Ticket ticket, VectorSchemaRoot data) { @Override public void getStream(CallContext context, Ticket ticket, ServerStreamListener listener) { if (!Arrays.equals(ticket.getBytes(), this.ticket.getBytes())) { - listener.error(CallStatus.INVALID_ARGUMENT.withDescription("Illegal ticket.").toRuntimeException()); + listener.error( + CallStatus.INVALID_ARGUMENT.withDescription("Illegal ticket.").toRuntimeException()); return; } @@ -80,8 +77,10 @@ protected List determineEndpoints( } @Override - public void createPreparedStatement(FlightSql.ActionCreatePreparedStatementRequest request, - CallContext context, StreamListener listener) { + public void createPreparedStatement( + FlightSql.ActionCreatePreparedStatementRequest request, + CallContext context, + StreamListener listener) { final FlightSql.ActionCreatePreparedStatementResult.Builder resultBuilder = FlightSql.ActionCreatePreparedStatementResult.newBuilder() .setPreparedStatementHandle(ByteString.EMPTY); @@ -100,14 +99,18 @@ public FlightInfo getFlightInfoStatement( } @Override - public FlightInfo getFlightInfoPreparedStatement(FlightSql.CommandPreparedStatementQuery command, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoPreparedStatement( + FlightSql.CommandPreparedStatementQuery command, + CallContext context, + FlightDescriptor descriptor) { return FlightInfo.builder(schema, descriptor, endpoints).build(); } @Override - public void closePreparedStatement(FlightSql.ActionClosePreparedStatementRequest request, - CallContext context, StreamListener listener) { + public void closePreparedStatement( + FlightSql.ActionClosePreparedStatementRequest request, + CallContext context, + StreamListener listener) { listener.onCompleted(); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ResultSetTestUtils.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ResultSetTestUtils.java index d5ce7fb8fb3..c78da3dd935 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ResultSetTestUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ResultSetTestUtils.java @@ -25,34 +25,35 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Function; - import org.apache.arrow.util.Preconditions; import org.junit.rules.ErrorCollector; /** - * Utility class for testing that require asserting that the values in a {@link ResultSet} are expected. + * Utility class for testing that require asserting that the values in a {@link ResultSet} are + * expected. */ public final class ResultSetTestUtils { private final ErrorCollector collector; public ResultSetTestUtils(final ErrorCollector collector) { - this.collector = - Preconditions.checkNotNull(collector, "Error collector cannot be null."); + this.collector = Preconditions.checkNotNull(collector, "Error collector cannot be null."); } /** * Checks that the values (rows and columns) in the provided {@link ResultSet} are expected. * - * @param resultSet the {@code ResultSet} to assert. + * @param resultSet the {@code ResultSet} to assert. * @param expectedResults the rows and columns representing the only values the {@code resultSet} - * is expected to have. - * @param collector the {@link ErrorCollector} to use for asserting that the {@code resultSet} - * has the expected values. - * @param the type to be found in the expected results for the {@code resultSet}. + * is expected to have. + * @param collector the {@link ErrorCollector} to use for asserting that the {@code resultSet} has + * the expected values. + * @param the type to be found in the expected results for the {@code resultSet}. * @throws SQLException if querying the {@code ResultSet} fails at some point unexpectedly. */ - public static void testData(final ResultSet resultSet, final List> expectedResults, - final ErrorCollector collector) + public static void testData( + final ResultSet resultSet, + final List> expectedResults, + final ErrorCollector collector) throws SQLException { testData( resultSet, @@ -64,19 +65,21 @@ public static void testData(final ResultSet resultSet, final List> e /** * Checks that the values (rows and columns) in the provided {@link ResultSet} are expected. * - * @param resultSet the {@code ResultSet} to assert. - * @param columnNames the column names to fetch in the {@code ResultSet} for comparison. + * @param resultSet the {@code ResultSet} to assert. + * @param columnNames the column names to fetch in the {@code ResultSet} for comparison. * @param expectedResults the rows and columns representing the only values the {@code resultSet} - * is expected to have. - * @param collector the {@link ErrorCollector} to use for asserting that the {@code resultSet} - * has the expected values. - * @param the type to be found in the expected results for the {@code resultSet}. + * is expected to have. + * @param collector the {@link ErrorCollector} to use for asserting that the {@code resultSet} has + * the expected values. + * @param the type to be found in the expected results for the {@code resultSet}. * @throws SQLException if querying the {@code ResultSet} fails at some point unexpectedly. */ @SuppressWarnings("unchecked") - public static void testData(final ResultSet resultSet, final List columnNames, - final List> expectedResults, - final ErrorCollector collector) + public static void testData( + final ResultSet resultSet, + final List columnNames, + final List> expectedResults, + final ErrorCollector collector) throws SQLException { testData( resultSet, @@ -98,19 +101,21 @@ public static void testData(final ResultSet resultSet, final List co /** * Checks that the values (rows and columns) in the provided {@link ResultSet} are expected. * - * @param resultSet the {@code ResultSet} to assert. - * @param columnIndices the column indices to fetch in the {@code ResultSet} for comparison. + * @param resultSet the {@code ResultSet} to assert. + * @param columnIndices the column indices to fetch in the {@code ResultSet} for comparison. * @param expectedResults the rows and columns representing the only values the {@code resultSet} - * is expected to have. - * @param collector the {@link ErrorCollector} to use for asserting that the {@code resultSet} - * has the expected values. - * @param the type to be found in the expected results for the {@code resultSet}. + * is expected to have. + * @param collector the {@link ErrorCollector} to use for asserting that the {@code resultSet} has + * the expected values. + * @param the type to be found in the expected results for the {@code resultSet}. * @throws SQLException if querying the {@code ResultSet} fails at some point unexpectedly. */ @SuppressWarnings("unchecked") - public static void testData(final ResultSet resultSet, final int[] columnIndices, - final List> expectedResults, - final ErrorCollector collector) + public static void testData( + final ResultSet resultSet, + final int[] columnIndices, + final List> expectedResults, + final ErrorCollector collector) throws SQLException { testData( resultSet, @@ -132,19 +137,20 @@ public static void testData(final ResultSet resultSet, final int[] columnInd /** * Checks that the values (rows and columns) in the provided {@link ResultSet} are expected. * - * @param resultSet the {@code ResultSet} to assert. - * @param dataConsumer the column indices to fetch in the {@code ResultSet} for comparison. + * @param resultSet the {@code ResultSet} to assert. + * @param dataConsumer the column indices to fetch in the {@code ResultSet} for comparison. * @param expectedResults the rows and columns representing the only values the {@code resultSet} - * is expected to have. - * @param collector the {@link ErrorCollector} to use for asserting that the {@code resultSet} - * has the expected values. - * @param the type to be found in the expected results for the {@code resultSet}. + * is expected to have. + * @param collector the {@link ErrorCollector} to use for asserting that the {@code resultSet} has + * the expected values. + * @param the type to be found in the expected results for the {@code resultSet}. * @throws SQLException if querying the {@code ResultSet} fails at some point unexpectedly. */ - public static void testData(final ResultSet resultSet, - final Function> dataConsumer, - final List> expectedResults, - final ErrorCollector collector) + public static void testData( + final ResultSet resultSet, + final Function> dataConsumer, + final List> expectedResults, + final ErrorCollector collector) throws SQLException { final List> actualResults = new ArrayList<>(); while (resultSet.next()) { @@ -156,9 +162,10 @@ public static void testData(final ResultSet resultSet, /** * Checks that the values (rows and columns) in the provided {@link ResultSet} are expected. * - * @param resultSet the {@code ResultSet} to assert. - * @param expectedResults the rows and columns representing the only values the {@code resultSet} is expected to have. - * @param the type to be found in the expected results for the {@code resultSet}. + * @param resultSet the {@code ResultSet} to assert. + * @param expectedResults the rows and columns representing the only values the {@code resultSet} + * is expected to have. + * @param the type to be found in the expected results for the {@code resultSet}. * @throws SQLException if querying the {@code ResultSet} fails at some point unexpectedly. */ public void testData(final ResultSet resultSet, final List> expectedResults) @@ -169,45 +176,54 @@ public void testData(final ResultSet resultSet, final List> expected /** * Checks that the values (rows and columns) in the provided {@link ResultSet} are expected. * - * @param resultSet the {@code ResultSet} to assert. - * @param columnNames the column names to fetch in the {@code ResultSet} for comparison. - * @param expectedResults the rows and columns representing the only values the {@code resultSet} is expected to have. - * @param the type to be found in the expected results for the {@code resultSet}. + * @param resultSet the {@code ResultSet} to assert. + * @param columnNames the column names to fetch in the {@code ResultSet} for comparison. + * @param expectedResults the rows and columns representing the only values the {@code resultSet} + * is expected to have. + * @param the type to be found in the expected results for the {@code resultSet}. * @throws SQLException if querying the {@code ResultSet} fails at some point unexpectedly. */ @SuppressWarnings("unchecked") - public void testData(final ResultSet resultSet, final List columnNames, - final List> expectedResults) throws SQLException { + public void testData( + final ResultSet resultSet, + final List columnNames, + final List> expectedResults) + throws SQLException { testData(resultSet, columnNames, expectedResults, collector); } /** * Checks that the values (rows and columns) in the provided {@link ResultSet} are expected. * - * @param resultSet the {@code ResultSet} to assert. - * @param columnIndices the column indices to fetch in the {@code ResultSet} for comparison. - * @param expectedResults the rows and columns representing the only values the {@code resultSet} is expected to have. - * @param the type to be found in the expected results for the {@code resultSet}. + * @param resultSet the {@code ResultSet} to assert. + * @param columnIndices the column indices to fetch in the {@code ResultSet} for comparison. + * @param expectedResults the rows and columns representing the only values the {@code resultSet} + * is expected to have. + * @param the type to be found in the expected results for the {@code resultSet}. * @throws SQLException if querying the {@code ResultSet} fails at some point unexpectedly. */ @SuppressWarnings("unchecked") - public void testData(final ResultSet resultSet, final int[] columnIndices, - final List> expectedResults) throws SQLException { + public void testData( + final ResultSet resultSet, final int[] columnIndices, final List> expectedResults) + throws SQLException { testData(resultSet, columnIndices, expectedResults, collector); } /** * Checks that the values (rows and columns) in the provided {@link ResultSet} are expected. * - * @param resultSet the {@code ResultSet} to assert. - * @param dataConsumer the column indices to fetch in the {@code ResultSet} for comparison. - * @param expectedResults the rows and columns representing the only values the {@code resultSet} is expected to have. - * @param the type to be found in the expected results for the {@code resultSet}. + * @param resultSet the {@code ResultSet} to assert. + * @param dataConsumer the column indices to fetch in the {@code ResultSet} for comparison. + * @param expectedResults the rows and columns representing the only values the {@code resultSet} + * is expected to have. + * @param the type to be found in the expected results for the {@code resultSet}. * @throws SQLException if querying the {@code ResultSet} fails at some point unexpectedly. */ - public void testData(final ResultSet resultSet, - final Function> dataConsumer, - final List> expectedResults) throws SQLException { + public void testData( + final ResultSet resultSet, + final Function> dataConsumer, + final List> expectedResults) + throws SQLException { testData(resultSet, dataConsumer, expectedResults, collector); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/RootAllocatorTestRule.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/RootAllocatorTestRule.java index a200fc8d39c..47b64ba0c08 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/RootAllocatorTestRule.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/RootAllocatorTestRule.java @@ -21,7 +21,6 @@ import java.util.Random; import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.util.AutoCloseables; @@ -102,31 +101,32 @@ public void close() throws Exception { * @return Float8Vector */ public Float8Vector createFloat8Vector() { - double[] doubleVectorValues = new double[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - Short.MIN_VALUE, - Short.MAX_VALUE, - Integer.MIN_VALUE, - Integer.MAX_VALUE, - Long.MIN_VALUE, - Long.MAX_VALUE, - Float.MAX_VALUE, - -Float.MAX_VALUE, - Float.NEGATIVE_INFINITY, - Float.POSITIVE_INFINITY, - Float.MIN_VALUE, - -Float.MIN_VALUE, - Double.MAX_VALUE, - -Double.MAX_VALUE, - Double.NEGATIVE_INFINITY, - Double.POSITIVE_INFINITY, - Double.MIN_VALUE, - -Double.MIN_VALUE, - }; + double[] doubleVectorValues = + new double[] { + 0, + 1, + -1, + Byte.MIN_VALUE, + Byte.MAX_VALUE, + Short.MIN_VALUE, + Short.MAX_VALUE, + Integer.MIN_VALUE, + Integer.MAX_VALUE, + Long.MIN_VALUE, + Long.MAX_VALUE, + Float.MAX_VALUE, + -Float.MAX_VALUE, + Float.NEGATIVE_INFINITY, + Float.POSITIVE_INFINITY, + Float.MIN_VALUE, + -Float.MIN_VALUE, + Double.MAX_VALUE, + -Double.MAX_VALUE, + Double.NEGATIVE_INFINITY, + Double.POSITIVE_INFINITY, + Double.MIN_VALUE, + -Double.MIN_VALUE, + }; Float8Vector result = new Float8Vector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -157,25 +157,26 @@ public Float8Vector createFloat8VectorForNullTests() { */ public Float4Vector createFloat4Vector() { - float[] floatVectorValues = new float[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - Short.MIN_VALUE, - Short.MAX_VALUE, - Integer.MIN_VALUE, - Integer.MAX_VALUE, - Long.MIN_VALUE, - Long.MAX_VALUE, - Float.MAX_VALUE, - -Float.MAX_VALUE, - Float.NEGATIVE_INFINITY, - Float.POSITIVE_INFINITY, - Float.MIN_VALUE, - -Float.MIN_VALUE, - }; + float[] floatVectorValues = + new float[] { + 0, + 1, + -1, + Byte.MIN_VALUE, + Byte.MAX_VALUE, + Short.MIN_VALUE, + Short.MAX_VALUE, + Integer.MIN_VALUE, + Integer.MAX_VALUE, + Long.MIN_VALUE, + Long.MAX_VALUE, + Float.MAX_VALUE, + -Float.MAX_VALUE, + Float.NEGATIVE_INFINITY, + Float.POSITIVE_INFINITY, + Float.MIN_VALUE, + -Float.MIN_VALUE, + }; Float4Vector result = new Float4Vector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -197,17 +198,18 @@ public Float4Vector createFloat4Vector() { */ public IntVector createIntVector() { - int[] intVectorValues = new int[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - Short.MIN_VALUE, - Short.MAX_VALUE, - Integer.MIN_VALUE, - Integer.MAX_VALUE, - }; + int[] intVectorValues = + new int[] { + 0, + 1, + -1, + Byte.MIN_VALUE, + Byte.MAX_VALUE, + Short.MIN_VALUE, + Short.MAX_VALUE, + Integer.MIN_VALUE, + Integer.MAX_VALUE, + }; IntVector result = new IntVector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -229,15 +231,10 @@ public IntVector createIntVector() { */ public SmallIntVector createSmallIntVector() { - short[] smallIntVectorValues = new short[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - Short.MIN_VALUE, - Short.MAX_VALUE, - }; + short[] smallIntVectorValues = + new short[] { + 0, 1, -1, Byte.MIN_VALUE, Byte.MAX_VALUE, Short.MIN_VALUE, Short.MAX_VALUE, + }; SmallIntVector result = new SmallIntVector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -259,13 +256,10 @@ public SmallIntVector createSmallIntVector() { */ public TinyIntVector createTinyIntVector() { - byte[] byteVectorValues = new byte[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - }; + byte[] byteVectorValues = + new byte[] { + 0, 1, -1, Byte.MIN_VALUE, Byte.MAX_VALUE, + }; TinyIntVector result = new TinyIntVector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -287,19 +281,20 @@ public TinyIntVector createTinyIntVector() { */ public BigIntVector createBigIntVector() { - long[] longVectorValues = new long[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - Short.MIN_VALUE, - Short.MAX_VALUE, - Integer.MIN_VALUE, - Integer.MAX_VALUE, - Long.MIN_VALUE, - Long.MAX_VALUE, - }; + long[] longVectorValues = + new long[] { + 0, + 1, + -1, + Byte.MIN_VALUE, + Byte.MAX_VALUE, + Short.MIN_VALUE, + Short.MAX_VALUE, + Integer.MIN_VALUE, + Integer.MAX_VALUE, + Long.MIN_VALUE, + Long.MAX_VALUE, + }; BigIntVector result = new BigIntVector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -321,13 +316,10 @@ public BigIntVector createBigIntVector() { */ public UInt1Vector createUInt1Vector() { - short[] uInt1VectorValues = new short[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - }; + short[] uInt1VectorValues = + new short[] { + 0, 1, -1, Byte.MIN_VALUE, Byte.MAX_VALUE, + }; UInt1Vector result = new UInt1Vector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -349,15 +341,10 @@ public UInt1Vector createUInt1Vector() { */ public UInt2Vector createUInt2Vector() { - int[] uInt2VectorValues = new int[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - Short.MIN_VALUE, - Short.MAX_VALUE, - }; + int[] uInt2VectorValues = + new int[] { + 0, 1, -1, Byte.MIN_VALUE, Byte.MAX_VALUE, Short.MIN_VALUE, Short.MAX_VALUE, + }; UInt2Vector result = new UInt2Vector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -379,18 +366,18 @@ public UInt2Vector createUInt2Vector() { */ public UInt4Vector createUInt4Vector() { - - int[] uInt4VectorValues = new int[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - Short.MIN_VALUE, - Short.MAX_VALUE, - Integer.MIN_VALUE, - Integer.MAX_VALUE - }; + int[] uInt4VectorValues = + new int[] { + 0, + 1, + -1, + Byte.MIN_VALUE, + Byte.MAX_VALUE, + Short.MIN_VALUE, + Short.MAX_VALUE, + Integer.MIN_VALUE, + Integer.MAX_VALUE + }; UInt4Vector result = new UInt4Vector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -412,19 +399,20 @@ public UInt4Vector createUInt4Vector() { */ public UInt8Vector createUInt8Vector() { - long[] uInt8VectorValues = new long[] { - 0, - 1, - -1, - Byte.MIN_VALUE, - Byte.MAX_VALUE, - Short.MIN_VALUE, - Short.MAX_VALUE, - Integer.MIN_VALUE, - Integer.MAX_VALUE, - Long.MIN_VALUE, - Long.MAX_VALUE - }; + long[] uInt8VectorValues = + new long[] { + 0, + 1, + -1, + Byte.MIN_VALUE, + Byte.MAX_VALUE, + Short.MIN_VALUE, + Short.MAX_VALUE, + Integer.MIN_VALUE, + Integer.MAX_VALUE, + Long.MIN_VALUE, + Long.MAX_VALUE + }; UInt8Vector result = new UInt8Vector("", this.getRootAllocator()); result.setValueCount(MAX_VALUE); @@ -503,20 +491,21 @@ public FixedSizeBinaryVector createFixedSizeBinaryVector() { */ public DecimalVector createDecimalVector() { - BigDecimal[] bigDecimalValues = new BigDecimal[] { - new BigDecimal(0), - new BigDecimal(1), - new BigDecimal(-1), - new BigDecimal(Byte.MIN_VALUE), - new BigDecimal(Byte.MAX_VALUE), - new BigDecimal(-Short.MAX_VALUE), - new BigDecimal(Short.MIN_VALUE), - new BigDecimal(Integer.MIN_VALUE), - new BigDecimal(Integer.MAX_VALUE), - new BigDecimal(Long.MIN_VALUE), - new BigDecimal(-Long.MAX_VALUE), - new BigDecimal("170141183460469231731687303715884105727") - }; + BigDecimal[] bigDecimalValues = + new BigDecimal[] { + new BigDecimal(0), + new BigDecimal(1), + new BigDecimal(-1), + new BigDecimal(Byte.MIN_VALUE), + new BigDecimal(Byte.MAX_VALUE), + new BigDecimal(-Short.MAX_VALUE), + new BigDecimal(Short.MIN_VALUE), + new BigDecimal(Integer.MIN_VALUE), + new BigDecimal(Integer.MAX_VALUE), + new BigDecimal(Long.MIN_VALUE), + new BigDecimal(-Long.MAX_VALUE), + new BigDecimal("170141183460469231731687303715884105727") + }; DecimalVector result = new DecimalVector("ID", this.getRootAllocator(), 39, 0); result.setValueCount(MAX_VALUE); @@ -538,30 +527,31 @@ public DecimalVector createDecimalVector() { */ public Decimal256Vector createDecimal256Vector() { - BigDecimal[] bigDecimalValues = new BigDecimal[] { - new BigDecimal(0), - new BigDecimal(1), - new BigDecimal(-1), - new BigDecimal(Byte.MIN_VALUE), - new BigDecimal(Byte.MAX_VALUE), - new BigDecimal(-Short.MAX_VALUE), - new BigDecimal(Short.MIN_VALUE), - new BigDecimal(Integer.MIN_VALUE), - new BigDecimal(Integer.MAX_VALUE), - new BigDecimal(Long.MIN_VALUE), - new BigDecimal(-Long.MAX_VALUE), - new BigDecimal("170141183460469231731687303715884105727"), - new BigDecimal("17014118346046923173168234157303715884105727"), - new BigDecimal("1701411834604692317316823415265417303715884105727"), - new BigDecimal("-17014118346046923173168234152654115451237303715884105727"), - new BigDecimal("-17014118346046923173168234152654115451231545157303715884105727"), - new BigDecimal("1701411834604692315815656534152654115451231545157303715884105727"), - new BigDecimal("30560141183460469231581565634152654115451231545157303715884105727"), - new BigDecimal( - "57896044618658097711785492504343953926634992332820282019728792003956564819967"), - new BigDecimal( - "-56896044618658097711785492504343953926634992332820282019728792003956564819967") - }; + BigDecimal[] bigDecimalValues = + new BigDecimal[] { + new BigDecimal(0), + new BigDecimal(1), + new BigDecimal(-1), + new BigDecimal(Byte.MIN_VALUE), + new BigDecimal(Byte.MAX_VALUE), + new BigDecimal(-Short.MAX_VALUE), + new BigDecimal(Short.MIN_VALUE), + new BigDecimal(Integer.MIN_VALUE), + new BigDecimal(Integer.MAX_VALUE), + new BigDecimal(Long.MIN_VALUE), + new BigDecimal(-Long.MAX_VALUE), + new BigDecimal("170141183460469231731687303715884105727"), + new BigDecimal("17014118346046923173168234157303715884105727"), + new BigDecimal("1701411834604692317316823415265417303715884105727"), + new BigDecimal("-17014118346046923173168234152654115451237303715884105727"), + new BigDecimal("-17014118346046923173168234152654115451231545157303715884105727"), + new BigDecimal("1701411834604692315815656534152654115451231545157303715884105727"), + new BigDecimal("30560141183460469231581565634152654115451231545157303715884105727"), + new BigDecimal( + "57896044618658097711785492504343953926634992332820282019728792003956564819967"), + new BigDecimal( + "-56896044618658097711785492504343953926634992332820282019728792003956564819967") + }; Decimal256Vector result = new Decimal256Vector("ID", this.getRootAllocator(), 77, 0); result.setValueCount(MAX_VALUE); @@ -763,13 +753,14 @@ public ListVector createListVector(String fieldName) { IntStream range = IntStream.range(0, MAX_VALUE); - range.forEach(row -> { - writer.startList(); - writer.setPosition(row); - IntStream.range(0, 5).map(j -> j * row).forEach(writer::writeInt); - writer.setValueCount(5); - writer.endList(); - }); + range.forEach( + row -> { + writer.startList(); + writer.setPosition(row); + IntStream.range(0, 5).map(j -> j * row).forEach(writer::writeInt); + writer.setValueCount(5); + writer.endList(); + }); valueVector.setValueCount(MAX_VALUE); @@ -784,13 +775,14 @@ public LargeListVector createLargeListVector() { IntStream range = IntStream.range(0, MAX_VALUE); - range.forEach(row -> { - writer.startList(); - writer.setPosition(row); - IntStream.range(0, 5).map(j -> j * row).forEach(writer::writeInt); - writer.setValueCount(5); - writer.endList(); - }); + range.forEach( + row -> { + writer.startList(); + writer.setPosition(row); + IntStream.range(0, 5).map(j -> j * row).forEach(writer::writeInt); + writer.setValueCount(5); + writer.endList(); + }); valueVector.setValueCount(MAX_VALUE); @@ -805,13 +797,14 @@ public FixedSizeListVector createFixedSizeListVector() { IntStream range = IntStream.range(0, MAX_VALUE); - range.forEach(row -> { - writer.startList(); - writer.setPosition(row); - IntStream.range(0, 5).map(j -> j * row).forEach(writer::writeInt); - writer.setValueCount(5); - writer.endList(); - }); + range.forEach( + row -> { + writer.startList(); + writer.setPosition(row); + IntStream.range(0, 5).map(j -> j * row).forEach(writer::writeInt); + writer.setValueCount(5); + writer.endList(); + }); valueVector.setValueCount(MAX_VALUE); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/SqlTypesTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/SqlTypesTest.java index 5c7c873e55c..efc32e8354b 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/SqlTypesTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/SqlTypesTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals; import java.sql.Types; - import org.apache.arrow.vector.types.DateUnit; import org.apache.arrow.vector.types.FloatingPointPrecision; import org.apache.arrow.vector.types.IntervalUnit; @@ -48,17 +47,20 @@ public void testGetSqlTypeIdFromArrowType() { assertEquals(Types.LONGVARCHAR, getSqlTypeIdFromArrowType(new ArrowType.LargeUtf8())); assertEquals(Types.DATE, getSqlTypeIdFromArrowType(new ArrowType.Date(DateUnit.MILLISECOND))); - assertEquals(Types.TIME, - getSqlTypeIdFromArrowType(new ArrowType.Time(TimeUnit.MILLISECOND, 32))); - assertEquals(Types.TIMESTAMP, + assertEquals( + Types.TIME, getSqlTypeIdFromArrowType(new ArrowType.Time(TimeUnit.MILLISECOND, 32))); + assertEquals( + Types.TIMESTAMP, getSqlTypeIdFromArrowType(new ArrowType.Timestamp(TimeUnit.MILLISECOND, ""))); assertEquals(Types.BOOLEAN, getSqlTypeIdFromArrowType(new ArrowType.Bool())); assertEquals(Types.DECIMAL, getSqlTypeIdFromArrowType(new ArrowType.Decimal(0, 0, 64))); - assertEquals(Types.DOUBLE, + assertEquals( + Types.DOUBLE, getSqlTypeIdFromArrowType(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE))); - assertEquals(Types.FLOAT, + assertEquals( + Types.FLOAT, getSqlTypeIdFromArrowType(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE))); assertEquals(Types.ARRAY, getSqlTypeIdFromArrowType(new ArrowType.List())); @@ -66,12 +68,13 @@ public void testGetSqlTypeIdFromArrowType() { assertEquals(Types.ARRAY, getSqlTypeIdFromArrowType(new ArrowType.FixedSizeList(10))); assertEquals(Types.JAVA_OBJECT, getSqlTypeIdFromArrowType(new ArrowType.Struct())); - assertEquals(Types.JAVA_OBJECT, - getSqlTypeIdFromArrowType(new ArrowType.Duration(TimeUnit.MILLISECOND))); - assertEquals(Types.JAVA_OBJECT, + assertEquals( + Types.JAVA_OBJECT, getSqlTypeIdFromArrowType(new ArrowType.Duration(TimeUnit.MILLISECOND))); + assertEquals( + Types.JAVA_OBJECT, getSqlTypeIdFromArrowType(new ArrowType.Interval(IntervalUnit.DAY_TIME))); - assertEquals(Types.JAVA_OBJECT, - getSqlTypeIdFromArrowType(new ArrowType.Union(UnionMode.Dense, null))); + assertEquals( + Types.JAVA_OBJECT, getSqlTypeIdFromArrowType(new ArrowType.Union(UnionMode.Dense, null))); assertEquals(Types.JAVA_OBJECT, getSqlTypeIdFromArrowType(new ArrowType.Map(true))); assertEquals(Types.NULL, getSqlTypeIdFromArrowType(new ArrowType.Null())); @@ -93,15 +96,18 @@ public void testGetSqlTypeNameFromArrowType() { assertEquals("DATE", getSqlTypeNameFromArrowType(new ArrowType.Date(DateUnit.MILLISECOND))); assertEquals("TIME", getSqlTypeNameFromArrowType(new ArrowType.Time(TimeUnit.MILLISECOND, 32))); - assertEquals("TIMESTAMP", + assertEquals( + "TIMESTAMP", getSqlTypeNameFromArrowType(new ArrowType.Timestamp(TimeUnit.MILLISECOND, ""))); assertEquals("BOOLEAN", getSqlTypeNameFromArrowType(new ArrowType.Bool())); assertEquals("DECIMAL", getSqlTypeNameFromArrowType(new ArrowType.Decimal(0, 0, 64))); - assertEquals("DOUBLE", + assertEquals( + "DOUBLE", getSqlTypeNameFromArrowType(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE))); - assertEquals("FLOAT", + assertEquals( + "FLOAT", getSqlTypeNameFromArrowType(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE))); assertEquals("ARRAY", getSqlTypeNameFromArrowType(new ArrowType.List())); @@ -110,12 +116,12 @@ public void testGetSqlTypeNameFromArrowType() { assertEquals("JAVA_OBJECT", getSqlTypeNameFromArrowType(new ArrowType.Struct())); - assertEquals("JAVA_OBJECT", - getSqlTypeNameFromArrowType(new ArrowType.Duration(TimeUnit.MILLISECOND))); - assertEquals("JAVA_OBJECT", - getSqlTypeNameFromArrowType(new ArrowType.Interval(IntervalUnit.DAY_TIME))); - assertEquals("JAVA_OBJECT", - getSqlTypeNameFromArrowType(new ArrowType.Union(UnionMode.Dense, null))); + assertEquals( + "JAVA_OBJECT", getSqlTypeNameFromArrowType(new ArrowType.Duration(TimeUnit.MILLISECOND))); + assertEquals( + "JAVA_OBJECT", getSqlTypeNameFromArrowType(new ArrowType.Interval(IntervalUnit.DAY_TIME))); + assertEquals( + "JAVA_OBJECT", getSqlTypeNameFromArrowType(new ArrowType.Union(UnionMode.Dense, null))); assertEquals("JAVA_OBJECT", getSqlTypeNameFromArrowType(new ArrowType.Map(true))); assertEquals("NULL", getSqlTypeNameFromArrowType(new ArrowType.Null())); diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ThrowableAssertionUtils.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ThrowableAssertionUtils.java index f1bd44539ac..505cff3a100 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ThrowableAssertionUtils.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/ThrowableAssertionUtils.java @@ -18,12 +18,11 @@ package org.apache.arrow.driver.jdbc.utils; /** - * Utility class to avoid upgrading JUnit to version >= 4.13 and keep using code to assert a {@link Throwable}. - * This should be removed as soon as we can use the proper assertThrows/checkThrows. + * Utility class to avoid upgrading JUnit to version >= 4.13 and keep using code to assert a {@link + * Throwable}. This should be removed as soon as we can use the proper assertThrows/checkThrows. */ public class ThrowableAssertionUtils { - private ThrowableAssertionUtils() { - } + private ThrowableAssertionUtils() {} public static void simpleAssertThrowableClass( final Class expectedThrowable, final ThrowingRunnable runnable) { @@ -33,15 +32,17 @@ public static void simpleAssertThrowableClass( if (expectedThrowable.isInstance(actualThrown)) { return; } else { - final String mismatchMessage = String.format("unexpected exception type thrown;\nexpected: %s\nactual: %s", - formatClass(expectedThrowable), - formatClass(actualThrown.getClass())); + final String mismatchMessage = + String.format( + "unexpected exception type thrown;\nexpected: %s\nactual: %s", + formatClass(expectedThrowable), formatClass(actualThrown.getClass())); throw new AssertionError(mismatchMessage, actualThrown); } } - final String notThrownMessage = String.format("expected %s to be thrown, but nothing was thrown", - formatClass(expectedThrowable)); + final String notThrownMessage = + String.format( + "expected %s to be thrown, but nothing was thrown", formatClass(expectedThrowable)); throw new AssertionError(notThrownMessage); } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/UrlParserTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/UrlParserTest.java index 4e764ab322c..4d2999abaed 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/UrlParserTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/UrlParserTest.java @@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import java.util.Map; - import org.junit.jupiter.api.Test; class UrlParserTest { diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformerTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformerTest.java index 1804b42cecb..02f07ab940c 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformerTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/utils/VectorSchemaRootTransformerTest.java @@ -17,9 +17,9 @@ package org.apache.arrow.driver.jdbc.utils; +import com.google.common.collect.ImmutableList; import java.util.List; import java.util.stream.Collectors; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.VarBinaryVector; @@ -34,12 +34,9 @@ import org.junit.Rule; import org.junit.Test; -import com.google.common.collect.ImmutableList; - public class VectorSchemaRootTransformerTest { - @Rule - public RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); + @Rule public RootAllocatorTestRule rootAllocatorTestRule = new RootAllocatorTestRule(); private final BufferAllocator rootAllocator = rootAllocatorTestRule.getRootAllocator(); @Test @@ -49,11 +46,10 @@ public void testTransformerBuilderWorksCorrectly() throws Exception { final VarBinaryVector field3 = rootAllocatorTestRule.createVarBinaryVector("FIELD_3"); try (final VectorSchemaRoot originalRoot = VectorSchemaRoot.of(field1, field2, field3); - final VectorSchemaRoot clonedRoot = cloneVectorSchemaRoot(originalRoot)) { + final VectorSchemaRoot clonedRoot = cloneVectorSchemaRoot(originalRoot)) { final VectorSchemaRootTransformer.Builder builder = - new VectorSchemaRootTransformer.Builder(originalRoot.getSchema(), - rootAllocator); + new VectorSchemaRootTransformer.Builder(originalRoot.getSchema(), rootAllocator); builder.renameFieldVector("FIELD_3", "FIELD_3_RENAMED"); builder.addEmptyField("EMPTY_FIELD", new ArrowType.Bool()); @@ -62,12 +58,13 @@ public void testTransformerBuilderWorksCorrectly() throws Exception { final VectorSchemaRootTransformer transformer = builder.build(); - final Schema transformedSchema = new Schema(ImmutableList.of( - Field.nullable("FIELD_3_RENAMED", new ArrowType.Binary()), - Field.nullable("EMPTY_FIELD", new ArrowType.Bool()), - Field.nullable("FIELD_2_RENAMED", new ArrowType.Binary()), - Field.nullable("FIELD_1_RENAMED", new ArrowType.Binary()) - )); + final Schema transformedSchema = + new Schema( + ImmutableList.of( + Field.nullable("FIELD_3_RENAMED", new ArrowType.Binary()), + Field.nullable("EMPTY_FIELD", new ArrowType.Bool()), + Field.nullable("FIELD_2_RENAMED", new ArrowType.Binary()), + Field.nullable("FIELD_1_RENAMED", new ArrowType.Binary()))); try (final VectorSchemaRoot transformedRoot = createVectorSchemaRoot(transformedSchema)) { Assert.assertSame(transformedRoot, transformer.transform(clonedRoot, transformedRoot)); Assert.assertEquals(transformedSchema, transformedRoot.getSchema()); @@ -75,12 +72,9 @@ public void testTransformerBuilderWorksCorrectly() throws Exception { final int rowCount = originalRoot.getRowCount(); Assert.assertEquals(rowCount, transformedRoot.getRowCount()); - final VarBinaryVector originalField1 = - (VarBinaryVector) originalRoot.getVector("FIELD_1"); - final VarBinaryVector originalField2 = - (VarBinaryVector) originalRoot.getVector("FIELD_2"); - final VarBinaryVector originalField3 = - (VarBinaryVector) originalRoot.getVector("FIELD_3"); + final VarBinaryVector originalField1 = (VarBinaryVector) originalRoot.getVector("FIELD_1"); + final VarBinaryVector originalField2 = (VarBinaryVector) originalRoot.getVector("FIELD_2"); + final VarBinaryVector originalField3 = (VarBinaryVector) originalRoot.getVector("FIELD_3"); final VarBinaryVector transformedField1 = (VarBinaryVector) transformedRoot.getVector("FIELD_1_RENAMED"); @@ -111,9 +105,10 @@ private VectorSchemaRoot cloneVectorSchemaRoot(final VectorSchemaRoot originalRo } private VectorSchemaRoot createVectorSchemaRoot(final Schema schema) { - final List fieldVectors = schema.getFields().stream() - .map(field -> field.createVector(rootAllocator)) - .collect(Collectors.toList()); + final List fieldVectors = + schema.getFields().stream() + .map(field -> field.createVector(rootAllocator)) + .collect(Collectors.toList()); return new VectorSchemaRoot(fieldVectors); } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/resources/logback.xml b/java/flight/flight-sql-jdbc-core/src/test/resources/logback.xml index ce66f8d82ac..d72538644f0 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/resources/logback.xml +++ b/java/flight/flight-sql-jdbc-core/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + - - + 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. --> diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/BasicFlightSqlProducer.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/BasicFlightSqlProducer.java index ea99191f28e..810257eff46 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/BasicFlightSqlProducer.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/BasicFlightSqlProducer.java @@ -17,48 +17,44 @@ package org.apache.arrow.flight.sql; +import com.google.protobuf.Message; import java.util.List; - import org.apache.arrow.flight.FlightDescriptor; import org.apache.arrow.flight.FlightEndpoint; import org.apache.arrow.flight.FlightInfo; import org.apache.arrow.flight.sql.impl.FlightSql; import org.apache.arrow.vector.types.pojo.Schema; -import com.google.protobuf.Message; - -/** - * A {@link FlightSqlProducer} that implements getting FlightInfo for each metadata request. - */ +/** A {@link FlightSqlProducer} that implements getting FlightInfo for each metadata request. */ public abstract class BasicFlightSqlProducer extends NoOpFlightSqlProducer { @Override - public FlightInfo getFlightInfoSqlInfo(FlightSql.CommandGetSqlInfo request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoSqlInfo( + FlightSql.CommandGetSqlInfo request, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_SQL_INFO_SCHEMA); } @Override - public FlightInfo getFlightInfoTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTypeInfo( + FlightSql.CommandGetXdbcTypeInfo request, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_TYPE_INFO_SCHEMA); } @Override - public FlightInfo getFlightInfoCatalogs(FlightSql.CommandGetCatalogs request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoCatalogs( + FlightSql.CommandGetCatalogs request, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_CATALOGS_SCHEMA); } @Override - public FlightInfo getFlightInfoSchemas(FlightSql.CommandGetDbSchemas request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoSchemas( + FlightSql.CommandGetDbSchemas request, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_SCHEMAS_SCHEMA); } @Override - public FlightInfo getFlightInfoTables(FlightSql.CommandGetTables request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTables( + FlightSql.CommandGetTables request, CallContext context, FlightDescriptor descriptor) { if (request.getIncludeSchema()) { return generateFlightInfo(request, descriptor, Schemas.GET_TABLES_SCHEMA); } @@ -66,43 +62,46 @@ public FlightInfo getFlightInfoTables(FlightSql.CommandGetTables request, CallCo } @Override - public FlightInfo getFlightInfoTableTypes(FlightSql.CommandGetTableTypes request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTableTypes( + FlightSql.CommandGetTableTypes request, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_TABLE_TYPES_SCHEMA); } @Override - public FlightInfo getFlightInfoPrimaryKeys(FlightSql.CommandGetPrimaryKeys request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoPrimaryKeys( + FlightSql.CommandGetPrimaryKeys request, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_PRIMARY_KEYS_SCHEMA); } @Override - public FlightInfo getFlightInfoExportedKeys(FlightSql.CommandGetExportedKeys request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoExportedKeys( + FlightSql.CommandGetExportedKeys request, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_EXPORTED_KEYS_SCHEMA); } @Override - public FlightInfo getFlightInfoImportedKeys(FlightSql.CommandGetImportedKeys request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoImportedKeys( + FlightSql.CommandGetImportedKeys request, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_IMPORTED_KEYS_SCHEMA); } @Override - public FlightInfo getFlightInfoCrossReference(FlightSql.CommandGetCrossReference request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoCrossReference( + FlightSql.CommandGetCrossReference request, + CallContext context, + FlightDescriptor descriptor) { return generateFlightInfo(request, descriptor, Schemas.GET_CROSS_REFERENCE_SCHEMA); } /** - * Return a list of FlightEndpoints for the given request and FlightDescriptor. This method should validate that - * the request is supported by this FlightSqlProducer. + * Return a list of FlightEndpoints for the given request and FlightDescriptor. This method should + * validate that the request is supported by this FlightSqlProducer. */ - protected abstract - List determineEndpoints(T request, FlightDescriptor flightDescriptor, Schema schema); + protected abstract List determineEndpoints( + T request, FlightDescriptor flightDescriptor, Schema schema); - protected FlightInfo generateFlightInfo(T request, FlightDescriptor descriptor, Schema schema) { + protected FlightInfo generateFlightInfo( + T request, FlightDescriptor descriptor, Schema schema) { final List endpoints = determineEndpoints(request, descriptor, schema); return new FlightInfo(schema, descriptor, endpoints, -1, -1); } diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/CancelListener.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/CancelListener.java index e7b645be747..b3ddeffa75c 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/CancelListener.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/CancelListener.java @@ -17,12 +17,11 @@ package org.apache.arrow.flight.sql; +import com.google.protobuf.Any; import org.apache.arrow.flight.FlightProducer; import org.apache.arrow.flight.Result; import org.apache.arrow.flight.sql.impl.FlightSql; -import com.google.protobuf.Any; - /** Typed StreamListener for cancelQuery. */ @SuppressWarnings("deprecation") class CancelListener implements FlightProducer.StreamListener { @@ -34,9 +33,8 @@ class CancelListener implements FlightProducer.StreamListener { @Override public void onNext(CancelResult val) { - FlightSql.ActionCancelQueryResult result = FlightSql.ActionCancelQueryResult.newBuilder() - .setResult(val.toProtocol()) - .build(); + FlightSql.ActionCancelQueryResult result = + FlightSql.ActionCancelQueryResult.newBuilder().setResult(val.toProtocol()).build(); listener.onNext(new Result(Any.pack(result).toByteArray())); } diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlClient.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlClient.java index 93d933f00f3..80ea1029899 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlClient.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlClient.java @@ -45,6 +45,9 @@ import static org.apache.arrow.flight.sql.impl.FlightSql.DoPutUpdateResult; import static org.apache.arrow.flight.sql.impl.FlightSql.SqlInfo; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.channels.Channels; @@ -55,7 +58,6 @@ import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; - import org.apache.arrow.flight.Action; import org.apache.arrow.flight.CallOption; import org.apache.arrow.flight.CallStatus; @@ -83,13 +85,7 @@ import org.apache.arrow.vector.ipc.message.MessageSerializer; import org.apache.arrow.vector.types.pojo.Schema; -import com.google.protobuf.Any; -import com.google.protobuf.ByteString; -import com.google.protobuf.InvalidProtocolBufferException; - -/** - * Flight client with Flight SQL semantics. - */ +/** Flight client with Flight SQL semantics. */ public class FlightSqlClient implements AutoCloseable { private final FlightClient client; @@ -100,7 +96,7 @@ public FlightSqlClient(final FlightClient client) { /** * Execute a query on the server. * - * @param query The query to execute. + * @param query The query to execute. * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ @@ -116,12 +112,15 @@ public FlightInfo execute(final String query, final CallOption... options) { * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ - public FlightInfo execute(final String query, Transaction transaction, final CallOption... options) { - final CommandStatementQuery.Builder builder = CommandStatementQuery.newBuilder().setQuery(query); + public FlightInfo execute( + final String query, Transaction transaction, final CallOption... options) { + final CommandStatementQuery.Builder builder = + CommandStatementQuery.newBuilder().setQuery(query); if (transaction != null) { builder.setTransactionId(ByteString.copyFrom(transaction.getTransactionId())); } - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -144,61 +143,67 @@ public FlightInfo executeSubstrait(SubstraitPlan plan, CallOption... options) { * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ - public FlightInfo executeSubstrait(SubstraitPlan plan, Transaction transaction, CallOption... options) { - final CommandStatementSubstraitPlan.Builder builder = CommandStatementSubstraitPlan.newBuilder(); - builder.getPlanBuilder().setPlan(ByteString.copyFrom(plan.getPlan())).setVersion(plan.getVersion()); + public FlightInfo executeSubstrait( + SubstraitPlan plan, Transaction transaction, CallOption... options) { + final CommandStatementSubstraitPlan.Builder builder = + CommandStatementSubstraitPlan.newBuilder(); + builder + .getPlanBuilder() + .setPlan(ByteString.copyFrom(plan.getPlan())) + .setVersion(plan.getVersion()); if (transaction != null) { builder.setTransactionId(ByteString.copyFrom(transaction.getTransactionId())); } - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } - /** - * Get the schema of the result set of a query. - */ - public SchemaResult getExecuteSchema(String query, Transaction transaction, CallOption... options) { + /** Get the schema of the result set of a query. */ + public SchemaResult getExecuteSchema( + String query, Transaction transaction, CallOption... options) { final CommandStatementQuery.Builder builder = CommandStatementQuery.newBuilder(); builder.setQuery(query); if (transaction != null) { builder.setTransactionId(ByteString.copyFrom(transaction.getTransactionId())); } - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getSchema(descriptor, options); } - /** - * Get the schema of the result set of a query. - */ + /** Get the schema of the result set of a query. */ public SchemaResult getExecuteSchema(String query, CallOption... options) { - return getExecuteSchema(query, /*transaction*/null, options); + return getExecuteSchema(query, /*transaction*/ null, options); } - /** - * Get the schema of the result set of a Substrait plan. - */ - public SchemaResult getExecuteSubstraitSchema(SubstraitPlan plan, Transaction transaction, - final CallOption... options) { - final CommandStatementSubstraitPlan.Builder builder = CommandStatementSubstraitPlan.newBuilder(); - builder.getPlanBuilder().setPlan(ByteString.copyFrom(plan.getPlan())).setVersion(plan.getVersion()); + /** Get the schema of the result set of a Substrait plan. */ + public SchemaResult getExecuteSubstraitSchema( + SubstraitPlan plan, Transaction transaction, final CallOption... options) { + final CommandStatementSubstraitPlan.Builder builder = + CommandStatementSubstraitPlan.newBuilder(); + builder + .getPlanBuilder() + .setPlan(ByteString.copyFrom(plan.getPlan())) + .setVersion(plan.getVersion()); if (transaction != null) { builder.setTransactionId(ByteString.copyFrom(transaction.getTransactionId())); } - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getSchema(descriptor, options); } - /** - * Get the schema of the result set of a Substrait plan. - */ - public SchemaResult getExecuteSubstraitSchema(SubstraitPlan substraitPlan, final CallOption... options) { - return getExecuteSubstraitSchema(substraitPlan, /*transaction*/null, options); + /** Get the schema of the result set of a Substrait plan. */ + public SchemaResult getExecuteSubstraitSchema( + SubstraitPlan substraitPlan, final CallOption... options) { + return getExecuteSubstraitSchema(substraitPlan, /*transaction*/ null, options); } /** * Execute an update query on the server. * - * @param query The query to execute. + * @param query The query to execute. * @param options RPC-layer hints for this call. * @return the number of rows affected. */ @@ -209,24 +214,27 @@ public long executeUpdate(final String query, final CallOption... options) { /** * Execute an update query on the server. * - * @param query The query to execute. + * @param query The query to execute. * @param transaction The transaction that this query is part of. * @param options RPC-layer hints for this call. * @return the number of rows affected. */ - public long executeUpdate(final String query, Transaction transaction, final CallOption... options) { - final CommandStatementUpdate.Builder builder = CommandStatementUpdate.newBuilder().setQuery(query); + public long executeUpdate( + final String query, Transaction transaction, final CallOption... options) { + final CommandStatementUpdate.Builder builder = + CommandStatementUpdate.newBuilder().setQuery(query); if (transaction != null) { builder.setTransactionId(ByteString.copyFrom(transaction.getTransactionId())); } - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); try (final SyncPutListener putListener = new SyncPutListener()) { final FlightClient.ClientStreamListener listener = client.startPut(descriptor, VectorSchemaRoot.of(), putListener, options); try (final PutResult result = putListener.read()) { - final DoPutUpdateResult doPutUpdateResult = DoPutUpdateResult.parseFrom( - result.getApplicationMetadata().nioBuffer()); + final DoPutUpdateResult doPutUpdateResult = + DoPutUpdateResult.parseFrom(result.getApplicationMetadata().nioBuffer()); return doPutUpdateResult.getRecordCount(); } finally { listener.getResult(); @@ -257,20 +265,26 @@ public long executeSubstraitUpdate(SubstraitPlan plan, CallOption... options) { * @param options RPC-layer hints for this call. * @return the number of rows affected. */ - public long executeSubstraitUpdate(SubstraitPlan plan, Transaction transaction, CallOption... options) { - final CommandStatementSubstraitPlan.Builder builder = CommandStatementSubstraitPlan.newBuilder(); - builder.getPlanBuilder().setPlan(ByteString.copyFrom(plan.getPlan())).setVersion(plan.getVersion()); + public long executeSubstraitUpdate( + SubstraitPlan plan, Transaction transaction, CallOption... options) { + final CommandStatementSubstraitPlan.Builder builder = + CommandStatementSubstraitPlan.newBuilder(); + builder + .getPlanBuilder() + .setPlan(ByteString.copyFrom(plan.getPlan())) + .setVersion(plan.getVersion()); if (transaction != null) { builder.setTransactionId(ByteString.copyFrom(transaction.getTransactionId())); } - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); try (final SyncPutListener putListener = new SyncPutListener()) { final FlightClient.ClientStreamListener listener = client.startPut(descriptor, VectorSchemaRoot.of(), putListener, options); try (final PutResult result = putListener.read()) { - final DoPutUpdateResult doPutUpdateResult = DoPutUpdateResult.parseFrom( - result.getApplicationMetadata().nioBuffer()); + final DoPutUpdateResult doPutUpdateResult = + DoPutUpdateResult.parseFrom(result.getApplicationMetadata().nioBuffer()); return doPutUpdateResult.getRecordCount(); } finally { listener.getResult(); @@ -290,7 +304,8 @@ public long executeSubstraitUpdate(SubstraitPlan plan, Transaction transaction, */ public FlightInfo getCatalogs(final CallOption... options) { final CommandGetCatalogs.Builder builder = CommandGetCatalogs.newBuilder(); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -308,12 +323,13 @@ public SchemaResult getCatalogsSchema(final CallOption... options) { /** * Request a list of schemas. * - * @param catalog The catalog. + * @param catalog The catalog. * @param dbSchemaFilterPattern The schema filter pattern. - * @param options RPC-layer hints for this call. + * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ - public FlightInfo getSchemas(final String catalog, final String dbSchemaFilterPattern, final CallOption... options) { + public FlightInfo getSchemas( + final String catalog, final String dbSchemaFilterPattern, final CallOption... options) { final CommandGetDbSchemas.Builder builder = CommandGetDbSchemas.newBuilder(); if (catalog != null) { @@ -324,7 +340,8 @@ public FlightInfo getSchemas(final String catalog, final String dbSchemaFilterPa builder.setDbSchemaFilterPattern(dbSchemaFilterPattern); } - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -343,7 +360,7 @@ public SchemaResult getSchemasSchema(final CallOption... options) { * Get schema for a stream. * * @param descriptor The descriptor for the stream. - * @param options RPC-layer hints for this call. + * @param options RPC-layer hints for this call. */ public SchemaResult getSchema(FlightDescriptor descriptor, CallOption... options) { return client.getSchema(descriptor, options); @@ -352,7 +369,7 @@ public SchemaResult getSchema(FlightDescriptor descriptor, CallOption... options /** * Retrieve a stream from the server. * - * @param ticket The ticket granting access to the data stream. + * @param ticket The ticket granting access to the data stream. * @param options RPC-layer hints for this call. */ public FlightStream getStream(Ticket ticket, CallOption... options) { @@ -372,7 +389,7 @@ public FlightInfo getSqlInfo(final SqlInfo... info) { /** * Request a set of Flight SQL metadata. * - * @param info The set of metadata to retrieve. None to retrieve all metadata. + * @param info The set of metadata to retrieve. None to retrieve all metadata. * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ @@ -382,11 +399,10 @@ public FlightInfo getSqlInfo(final SqlInfo[] info, final CallOption... options) } /** - * Request a set of Flight SQL metadata. - * Use this method if you would like to retrieve custom metadata, where the custom metadata key values start - * from 10_000. + * Request a set of Flight SQL metadata. Use this method if you would like to retrieve custom + * metadata, where the custom metadata key values start from 10_000. * - * @param info The set of metadata to retrieve. None to retrieve all metadata. + * @param info The set of metadata to retrieve. None to retrieve all metadata. * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ @@ -395,18 +411,18 @@ public FlightInfo getSqlInfo(final int[] info, final CallOption... options) { } /** - * Request a set of Flight SQL metadata. - * Use this method if you would like to retrieve custom metadata, where the custom metadata key values start - * from 10_000. + * Request a set of Flight SQL metadata. Use this method if you would like to retrieve custom + * metadata, where the custom metadata key values start from 10_000. * - * @param info The set of metadata to retrieve. None to retrieve all metadata. + * @param info The set of metadata to retrieve. None to retrieve all metadata. * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ public FlightInfo getSqlInfo(final Iterable info, final CallOption... options) { final CommandGetSqlInfo.Builder builder = CommandGetSqlInfo.newBuilder(); builder.addAllInfo(info); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -422,11 +438,10 @@ public SchemaResult getSqlInfoSchema(final CallOption... options) { } /** - * Request the information about the data types supported related to - * a filter data type. + * Request the information about the data types supported related to a filter data type. * - * @param dataType the data type to be used as filter. - * @param options RPC-layer hints for this call. + * @param dataType the data type to be used as filter. + * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ public FlightInfo getXdbcTypeInfo(final int dataType, final CallOption... options) { @@ -434,20 +449,22 @@ public FlightInfo getXdbcTypeInfo(final int dataType, final CallOption... option builder.setDataType(dataType); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } /** * Request the information about all the data types supported. * - * @param options RPC-layer hints for this call. + * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ public FlightInfo getXdbcTypeInfo(final CallOption... options) { final CommandGetXdbcTypeInfo.Builder builder = CommandGetXdbcTypeInfo.newBuilder(); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -465,17 +482,21 @@ public SchemaResult getXdbcTypeInfoSchema(final CallOption... options) { /** * Request a list of tables. * - * @param catalog The catalog. + * @param catalog The catalog. * @param dbSchemaFilterPattern The schema filter pattern. - * @param tableFilterPattern The table filter pattern. - * @param tableTypes The table types to include. - * @param includeSchema True to include the schema upon return, false to not include the schema. - * @param options RPC-layer hints for this call. + * @param tableFilterPattern The table filter pattern. + * @param tableTypes The table types to include. + * @param includeSchema True to include the schema upon return, false to not include the schema. + * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ - public FlightInfo getTables(final String catalog, final String dbSchemaFilterPattern, - final String tableFilterPattern, final List tableTypes, - final boolean includeSchema, final CallOption... options) { + public FlightInfo getTables( + final String catalog, + final String dbSchemaFilterPattern, + final String tableFilterPattern, + final List tableTypes, + final boolean includeSchema, + final CallOption... options) { final CommandGetTables.Builder builder = CommandGetTables.newBuilder(); if (catalog != null) { @@ -495,18 +516,21 @@ public FlightInfo getTables(final String catalog, final String dbSchemaFilterPat } builder.setIncludeSchema(includeSchema); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } /** - * Get the schema of {@link #getTables(String, String, String, List, boolean, CallOption...)} from the server. + * Get the schema of {@link #getTables(String, String, String, List, boolean, CallOption...)} from + * the server. * - *

Should be identical to {@link FlightSqlProducer.Schemas#GET_TABLES_SCHEMA} or - * {@link FlightSqlProducer.Schemas#GET_TABLES_SCHEMA_NO_SCHEMA}. + *

Should be identical to {@link FlightSqlProducer.Schemas#GET_TABLES_SCHEMA} or {@link + * FlightSqlProducer.Schemas#GET_TABLES_SCHEMA_NO_SCHEMA}. */ public SchemaResult getTablesSchema(boolean includeSchema, final CallOption... options) { - final CommandGetTables command = CommandGetTables.newBuilder().setIncludeSchema(includeSchema).build(); + final CommandGetTables command = + CommandGetTables.newBuilder().setIncludeSchema(includeSchema).build(); final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(command).toByteArray()); return client.getSchema(descriptor, options); } @@ -514,8 +538,8 @@ public SchemaResult getTablesSchema(boolean includeSchema, final CallOption... o /** * Request the primary keys for a table. * - * @param tableRef An object which hold info about catalog, dbSchema and table. - * @param options RPC-layer hints for this call. + * @param tableRef An object which hold info about catalog, dbSchema and table. + * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ public FlightInfo getPrimaryKeys(final TableRef tableRef, final CallOption... options) { @@ -532,7 +556,8 @@ public FlightInfo getPrimaryKeys(final TableRef tableRef, final CallOption... op Objects.requireNonNull(tableRef.getTable()); builder.setTable(tableRef.getTable()); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -548,10 +573,11 @@ public SchemaResult getPrimaryKeysSchema(final CallOption... options) { } /** - * Retrieves a description about the foreign key columns that reference the primary key columns of the given table. + * Retrieves a description about the foreign key columns that reference the primary key columns of + * the given table. * - * @param tableRef An object which hold info about catalog, dbSchema and table. - * @param options RPC-layer hints for this call. + * @param tableRef An object which hold info about catalog, dbSchema and table. + * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ public FlightInfo getExportedKeys(final TableRef tableRef, final CallOption... options) { @@ -570,7 +596,8 @@ public FlightInfo getExportedKeys(final TableRef tableRef, final CallOption... o Objects.requireNonNull(tableRef.getTable()); builder.setTable(tableRef.getTable()); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -588,12 +615,11 @@ public SchemaResult getExportedKeysSchema(final CallOption... options) { /** * Retrieves the foreign key columns for the given table. * - * @param tableRef An object which hold info about catalog, dbSchema and table. - * @param options RPC-layer hints for this call. + * @param tableRef An object which hold info about catalog, dbSchema and table. + * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ - public FlightInfo getImportedKeys(final TableRef tableRef, - final CallOption... options) { + public FlightInfo getImportedKeys(final TableRef tableRef, final CallOption... options) { Objects.requireNonNull(tableRef.getTable(), "Table cannot be null."); final CommandGetImportedKeys.Builder builder = CommandGetImportedKeys.newBuilder(); @@ -609,7 +635,8 @@ public FlightInfo getImportedKeys(final TableRef tableRef, Objects.requireNonNull(tableRef.getTable()); builder.setTable(tableRef.getTable()); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -625,16 +652,18 @@ public SchemaResult getImportedKeysSchema(final CallOption... options) { } /** - * Retrieves a description of the foreign key columns that reference the given table's - * primary key columns (the foreign keys exported by a table). + * Retrieves a description of the foreign key columns that reference the given table's primary key + * columns (the foreign keys exported by a table). * - * @param pkTableRef An object which hold info about catalog, dbSchema and table from a primary table. - * @param fkTableRef An object which hold info about catalog, dbSchema and table from a foreign table. - * @param options RPC-layer hints for this call. + * @param pkTableRef An object which hold info about catalog, dbSchema and table from a primary + * table. + * @param fkTableRef An object which hold info about catalog, dbSchema and table from a foreign + * table. + * @param options RPC-layer hints for this call. * @return a FlightInfo object representing the stream(s) to fetch. */ - public FlightInfo getCrossReference(final TableRef pkTableRef, - final TableRef fkTableRef, final CallOption... options) { + public FlightInfo getCrossReference( + final TableRef pkTableRef, final TableRef fkTableRef, final CallOption... options) { Objects.requireNonNull(pkTableRef.getTable(), "Parent Table cannot be null."); Objects.requireNonNull(fkTableRef.getTable(), "Foreign Table cannot be null."); @@ -659,12 +688,14 @@ public FlightInfo getCrossReference(final TableRef pkTableRef, builder.setPkTable(pkTableRef.getTable()); builder.setFkTable(fkTableRef.getTable()); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } /** - * Get the schema of {@link #getCrossReference(TableRef, TableRef, CallOption...)} from the server. + * Get the schema of {@link #getCrossReference(TableRef, TableRef, CallOption...)} from the + * server. * *

Should be identical to {@link FlightSqlProducer.Schemas#GET_CROSS_REFERENCE_SCHEMA}. */ @@ -682,7 +713,8 @@ public SchemaResult getCrossReferenceSchema(final CallOption... options) { */ public FlightInfo getTableTypes(final CallOption... options) { final CommandGetTableTypes.Builder builder = CommandGetTableTypes.newBuilder(); - final FlightDescriptor descriptor = FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command(Any.pack(builder.build()).toByteArray()); return client.getInfo(descriptor, options); } @@ -700,7 +732,7 @@ public SchemaResult getTableTypesSchema(final CallOption... options) { /** * Create a prepared statement for a SQL query on the server. * - * @param query The query to prepare. + * @param query The query to prepare. * @param options RPC-layer hints for this call. * @return The representation of the prepared statement which exists on the server. */ @@ -722,7 +754,8 @@ public PreparedStatement prepare(String query, Transaction transaction, CallOpti if (transaction != null) { builder.setTransactionId(ByteString.copyFrom(transaction.getTransactionId())); } - return new PreparedStatement(client, + return new PreparedStatement( + client, new Action( FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT.getType(), Any.pack(builder.build()).toByteArray()), @@ -732,7 +765,7 @@ public PreparedStatement prepare(String query, Transaction transaction, CallOpti /** * Create a prepared statement for a Substrait plan on the server. * - * @param plan The query to prepare. + * @param plan The query to prepare. * @param options RPC-layer hints for this call. * @return The representation of the prepared statement which exists on the server. */ @@ -748,14 +781,19 @@ public PreparedStatement prepare(SubstraitPlan plan, CallOption... options) { * @param options RPC-layer hints for this call. * @return The representation of the prepared statement which exists on the server. */ - public PreparedStatement prepare(SubstraitPlan plan, Transaction transaction, CallOption... options) { + public PreparedStatement prepare( + SubstraitPlan plan, Transaction transaction, CallOption... options) { ActionCreatePreparedSubstraitPlanRequest.Builder builder = ActionCreatePreparedSubstraitPlanRequest.newBuilder(); - builder.getPlanBuilder().setPlan(ByteString.copyFrom(plan.getPlan())).setVersion(plan.getVersion()); + builder + .getPlanBuilder() + .setPlan(ByteString.copyFrom(plan.getPlan())) + .setVersion(plan.getVersion()); if (transaction != null) { builder.setTransactionId(ByteString.copyFrom(transaction.getTransactionId())); } - return new PreparedStatement(client, + return new PreparedStatement( + client, new Action( FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_SUBSTRAIT_PLAN.getType(), Any.pack(builder.build()).toByteArray()), @@ -764,95 +802,114 @@ public PreparedStatement prepare(SubstraitPlan plan, Transaction transaction, Ca /** Begin a transaction. */ public Transaction beginTransaction(CallOption... options) { - final Action action = new Action( - FlightSqlUtils.FLIGHT_SQL_BEGIN_TRANSACTION.getType(), - Any.pack(ActionBeginTransactionRequest.getDefaultInstance()).toByteArray()); + final Action action = + new Action( + FlightSqlUtils.FLIGHT_SQL_BEGIN_TRANSACTION.getType(), + Any.pack(ActionBeginTransactionRequest.getDefaultInstance()).toByteArray()); final Iterator preparedStatementResults = client.doAction(action, options); - final ActionBeginTransactionResult result = FlightSqlUtils.unpackAndParseOrThrow( - preparedStatementResults.next().getBody(), - ActionBeginTransactionResult.class); - preparedStatementResults.forEachRemaining((ignored) -> { }); + final ActionBeginTransactionResult result = + FlightSqlUtils.unpackAndParseOrThrow( + preparedStatementResults.next().getBody(), ActionBeginTransactionResult.class); + preparedStatementResults.forEachRemaining((ignored) -> {}); if (result.getTransactionId().isEmpty()) { - throw CallStatus.INTERNAL.withDescription("Server returned an empty transaction ID").toRuntimeException(); + throw CallStatus.INTERNAL + .withDescription("Server returned an empty transaction ID") + .toRuntimeException(); } return new Transaction(result.getTransactionId().toByteArray()); } /** Create a savepoint within a transaction. */ public Savepoint beginSavepoint(Transaction transaction, String name, CallOption... options) { - Preconditions.checkArgument(transaction.getTransactionId().length != 0, "Transaction must be initialized"); - ActionBeginSavepointRequest request = ActionBeginSavepointRequest.newBuilder() - .setTransactionId(ByteString.copyFrom(transaction.getTransactionId())) - .setName(name) - .build(); - final Action action = new Action( - FlightSqlUtils.FLIGHT_SQL_BEGIN_SAVEPOINT.getType(), - Any.pack(request).toByteArray()); + Preconditions.checkArgument( + transaction.getTransactionId().length != 0, "Transaction must be initialized"); + ActionBeginSavepointRequest request = + ActionBeginSavepointRequest.newBuilder() + .setTransactionId(ByteString.copyFrom(transaction.getTransactionId())) + .setName(name) + .build(); + final Action action = + new Action( + FlightSqlUtils.FLIGHT_SQL_BEGIN_SAVEPOINT.getType(), Any.pack(request).toByteArray()); final Iterator preparedStatementResults = client.doAction(action, options); - final ActionBeginSavepointResult result = FlightSqlUtils.unpackAndParseOrThrow( - preparedStatementResults.next().getBody(), - ActionBeginSavepointResult.class); - preparedStatementResults.forEachRemaining((ignored) -> { }); + final ActionBeginSavepointResult result = + FlightSqlUtils.unpackAndParseOrThrow( + preparedStatementResults.next().getBody(), ActionBeginSavepointResult.class); + preparedStatementResults.forEachRemaining((ignored) -> {}); if (result.getSavepointId().isEmpty()) { - throw CallStatus.INTERNAL.withDescription("Server returned an empty transaction ID").toRuntimeException(); + throw CallStatus.INTERNAL + .withDescription("Server returned an empty transaction ID") + .toRuntimeException(); } return new Savepoint(result.getSavepointId().toByteArray()); } /** Commit a transaction. */ public void commit(Transaction transaction, CallOption... options) { - Preconditions.checkArgument(transaction.getTransactionId().length != 0, "Transaction must be initialized"); - ActionEndTransactionRequest request = ActionEndTransactionRequest.newBuilder() - .setTransactionId(ByteString.copyFrom(transaction.getTransactionId())) - .setActionValue(ActionEndTransactionRequest.EndTransaction.END_TRANSACTION_COMMIT.getNumber()) - .build(); - final Action action = new Action( - FlightSqlUtils.FLIGHT_SQL_END_TRANSACTION.getType(), - Any.pack(request).toByteArray()); + Preconditions.checkArgument( + transaction.getTransactionId().length != 0, "Transaction must be initialized"); + ActionEndTransactionRequest request = + ActionEndTransactionRequest.newBuilder() + .setTransactionId(ByteString.copyFrom(transaction.getTransactionId())) + .setActionValue( + ActionEndTransactionRequest.EndTransaction.END_TRANSACTION_COMMIT.getNumber()) + .build(); + final Action action = + new Action( + FlightSqlUtils.FLIGHT_SQL_END_TRANSACTION.getType(), Any.pack(request).toByteArray()); final Iterator preparedStatementResults = client.doAction(action, options); - preparedStatementResults.forEachRemaining((ignored) -> { }); + preparedStatementResults.forEachRemaining((ignored) -> {}); } /** Release a savepoint. */ public void release(Savepoint savepoint, CallOption... options) { - Preconditions.checkArgument(savepoint.getSavepointId().length != 0, "Savepoint must be initialized"); - ActionEndSavepointRequest request = ActionEndSavepointRequest.newBuilder() - .setSavepointId(ByteString.copyFrom(savepoint.getSavepointId())) - .setActionValue(ActionEndSavepointRequest.EndSavepoint.END_SAVEPOINT_RELEASE.getNumber()) - .build(); - final Action action = new Action( - FlightSqlUtils.FLIGHT_SQL_END_SAVEPOINT.getType(), - Any.pack(request).toByteArray()); + Preconditions.checkArgument( + savepoint.getSavepointId().length != 0, "Savepoint must be initialized"); + ActionEndSavepointRequest request = + ActionEndSavepointRequest.newBuilder() + .setSavepointId(ByteString.copyFrom(savepoint.getSavepointId())) + .setActionValue( + ActionEndSavepointRequest.EndSavepoint.END_SAVEPOINT_RELEASE.getNumber()) + .build(); + final Action action = + new Action( + FlightSqlUtils.FLIGHT_SQL_END_SAVEPOINT.getType(), Any.pack(request).toByteArray()); final Iterator preparedStatementResults = client.doAction(action, options); - preparedStatementResults.forEachRemaining((ignored) -> { }); + preparedStatementResults.forEachRemaining((ignored) -> {}); } /** Rollback a transaction. */ public void rollback(Transaction transaction, CallOption... options) { - Preconditions.checkArgument(transaction.getTransactionId().length != 0, "Transaction must be initialized"); - ActionEndTransactionRequest request = ActionEndTransactionRequest.newBuilder() - .setTransactionId(ByteString.copyFrom(transaction.getTransactionId())) - .setActionValue(ActionEndTransactionRequest.EndTransaction.END_TRANSACTION_ROLLBACK.getNumber()) - .build(); - final Action action = new Action( - FlightSqlUtils.FLIGHT_SQL_END_TRANSACTION.getType(), - Any.pack(request).toByteArray()); + Preconditions.checkArgument( + transaction.getTransactionId().length != 0, "Transaction must be initialized"); + ActionEndTransactionRequest request = + ActionEndTransactionRequest.newBuilder() + .setTransactionId(ByteString.copyFrom(transaction.getTransactionId())) + .setActionValue( + ActionEndTransactionRequest.EndTransaction.END_TRANSACTION_ROLLBACK.getNumber()) + .build(); + final Action action = + new Action( + FlightSqlUtils.FLIGHT_SQL_END_TRANSACTION.getType(), Any.pack(request).toByteArray()); final Iterator preparedStatementResults = client.doAction(action, options); - preparedStatementResults.forEachRemaining((ignored) -> { }); + preparedStatementResults.forEachRemaining((ignored) -> {}); } /** Rollback to a savepoint. */ public void rollback(Savepoint savepoint, CallOption... options) { - Preconditions.checkArgument(savepoint.getSavepointId().length != 0, "Savepoint must be initialized"); - ActionEndSavepointRequest request = ActionEndSavepointRequest.newBuilder() - .setSavepointId(ByteString.copyFrom(savepoint.getSavepointId())) - .setActionValue(ActionEndSavepointRequest.EndSavepoint.END_SAVEPOINT_RELEASE.getNumber()) - .build(); - final Action action = new Action( - FlightSqlUtils.FLIGHT_SQL_END_SAVEPOINT.getType(), - Any.pack(request).toByteArray()); + Preconditions.checkArgument( + savepoint.getSavepointId().length != 0, "Savepoint must be initialized"); + ActionEndSavepointRequest request = + ActionEndSavepointRequest.newBuilder() + .setSavepointId(ByteString.copyFrom(savepoint.getSavepointId())) + .setActionValue( + ActionEndSavepointRequest.EndSavepoint.END_SAVEPOINT_RELEASE.getNumber()) + .build(); + final Action action = + new Action( + FlightSqlUtils.FLIGHT_SQL_END_SAVEPOINT.getType(), Any.pack(request).toByteArray()); final Iterator preparedStatementResults = client.doAction(action, options); - preparedStatementResults.forEachRemaining((ignored) -> { }); + preparedStatementResults.forEachRemaining((ignored) -> {}); } /** @@ -862,35 +919,36 @@ public void rollback(Savepoint savepoint, CallOption... options) { * @param options Call options. * @return The server response. */ - public CancelFlightInfoResult cancelFlightInfo(CancelFlightInfoRequest request, CallOption... options) { + public CancelFlightInfoResult cancelFlightInfo( + CancelFlightInfoRequest request, CallOption... options) { return client.cancelFlightInfo(request, options); } /** * Explicitly cancel a running query. - *

- * This lets a single client explicitly cancel work, no matter how many clients - * are involved/whether the query is distributed or not, given server support. - * The transaction/statement is not rolled back; it is the application's job to - * commit or rollback as appropriate. This only indicates the client no longer - * wishes to read the remainder of the query results or continue submitting - * data. + * + *

This lets a single client explicitly cancel work, no matter how many clients are + * involved/whether the query is distributed or not, given server support. The + * transaction/statement is not rolled back; it is the application's job to commit or rollback as + * appropriate. This only indicates the client no longer wishes to read the remainder of the query + * results or continue submitting data. * * @deprecated Prefer {@link #cancelFlightInfo}. */ @Deprecated public CancelResult cancelQuery(FlightInfo info, CallOption... options) { - ActionCancelQueryRequest request = ActionCancelQueryRequest.newBuilder() - .setInfo(ByteString.copyFrom(info.serialize())) - .build(); - final Action action = new Action( - FlightSqlUtils.FLIGHT_SQL_CANCEL_QUERY.getType(), - Any.pack(request).toByteArray()); + ActionCancelQueryRequest request = + ActionCancelQueryRequest.newBuilder() + .setInfo(ByteString.copyFrom(info.serialize())) + .build(); + final Action action = + new Action( + FlightSqlUtils.FLIGHT_SQL_CANCEL_QUERY.getType(), Any.pack(request).toByteArray()); final Iterator preparedStatementResults = client.doAction(action, options); - final ActionCancelQueryResult result = FlightSqlUtils.unpackAndParseOrThrow( - preparedStatementResults.next().getBody(), - ActionCancelQueryResult.class); - preparedStatementResults.forEachRemaining((ignored) -> { }); + final ActionCancelQueryResult result = + FlightSqlUtils.unpackAndParseOrThrow( + preparedStatementResults.next().getBody(), ActionCancelQueryResult.class); + preparedStatementResults.forEachRemaining((ignored) -> {}); switch (result.getResult()) { case CANCEL_RESULT_UNSPECIFIED: return CancelResult.UNSPECIFIED; @@ -902,7 +960,9 @@ public CancelResult cancelQuery(FlightInfo info, CallOption... options) { return CancelResult.NOT_CANCELLABLE; case UNRECOGNIZED: default: - throw CallStatus.INTERNAL.withDescription("Unknown result: " + result.getResult()).toRuntimeException(); + throw CallStatus.INTERNAL + .withDescription("Unknown result: " + result.getResult()) + .toRuntimeException(); } } @@ -913,7 +973,8 @@ public CancelResult cancelQuery(FlightInfo info, CallOption... options) { * @param options Call options. * @return The new endpoint with an updated expiration time. */ - public FlightEndpoint renewFlightEndpoint(RenewFlightEndpointRequest request, CallOption... options) { + public FlightEndpoint renewFlightEndpoint( + RenewFlightEndpointRequest request, CallOption... options) { return client.renewFlightEndpoint(request, options); } @@ -922,9 +983,7 @@ public void close() throws Exception { AutoCloseables.close(client); } - /** - * Helper class to encapsulate Flight SQL prepared statement logic. - */ + /** Helper class to encapsulate Flight SQL prepared statement logic. */ public static class PreparedStatement implements AutoCloseable { private final FlightClient client; private final ActionCreatePreparedStatementResult preparedStatementResult; @@ -937,18 +996,18 @@ public static class PreparedStatement implements AutoCloseable { this.client = client; final Iterator preparedStatementResults = client.doAction(action, options); - preparedStatementResult = FlightSqlUtils.unpackAndParseOrThrow( - preparedStatementResults.next().getBody(), - ActionCreatePreparedStatementResult.class); + preparedStatementResult = + FlightSqlUtils.unpackAndParseOrThrow( + preparedStatementResults.next().getBody(), ActionCreatePreparedStatementResult.class); isClosed = false; } /** - * Set the {@link #parameterBindingRoot} containing the parameter binding from a {@link PreparedStatement} - * operation. + * Set the {@link #parameterBindingRoot} containing the parameter binding from a {@link + * PreparedStatement} operation. * - * @param parameterBindingRoot a {@code VectorSchemaRoot} object containing the values to be used in the - * {@code PreparedStatement} setters. + * @param parameterBindingRoot a {@code VectorSchemaRoot} object containing the values to be + * used in the {@code PreparedStatement} setters. */ public void setParameters(final VectorSchemaRoot parameterBindingRoot) { if (parameterBindingRoot == this.parameterBindingRoot) { @@ -960,8 +1019,8 @@ public void setParameters(final VectorSchemaRoot parameterBindingRoot) { } /** - * Closes the {@link #parameterBindingRoot}, which contains the parameter binding from - * a {@link PreparedStatement} operation, releasing its resources. + * Closes the {@link #parameterBindingRoot}, which contains the parameter binding from a {@link + * PreparedStatement} operation, releasing its resources. */ public void clearParameters() { if (parameterBindingRoot != null) { @@ -995,27 +1054,28 @@ public Schema getParameterSchema() { return parameterSchema; } - /** - * Get the schema of the result set (should be identical to {@link #getResultSetSchema()}). - */ + /** Get the schema of the result set (should be identical to {@link #getResultSetSchema()}). */ public SchemaResult fetchSchema(CallOption... options) { checkOpen(); - final FlightDescriptor descriptor = FlightDescriptor - .command(Any.pack(CommandPreparedStatementQuery.newBuilder() - .setPreparedStatementHandle(preparedStatementResult.getPreparedStatementHandle()) - .build()) - .toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command( + Any.pack( + CommandPreparedStatementQuery.newBuilder() + .setPreparedStatementHandle( + preparedStatementResult.getPreparedStatementHandle()) + .build()) + .toByteArray()); return client.getSchema(descriptor, options); } private Schema deserializeSchema(final ByteString bytes) { try { - return bytes.isEmpty() ? - new Schema(Collections.emptyList()) : - MessageSerializer.deserializeSchema( - new ReadChannel(Channels.newChannel( - new ByteArrayInputStream(bytes.toByteArray())))); + return bytes.isEmpty() + ? new Schema(Collections.emptyList()) + : MessageSerializer.deserializeSchema( + new ReadChannel( + Channels.newChannel(new ByteArrayInputStream(bytes.toByteArray())))); } catch (final IOException e) { throw new RuntimeException("Failed to deserialize schema", e); } @@ -1030,11 +1090,14 @@ private Schema deserializeSchema(final ByteString bytes) { public FlightInfo execute(final CallOption... options) { checkOpen(); - final FlightDescriptor descriptor = FlightDescriptor - .command(Any.pack(CommandPreparedStatementQuery.newBuilder() - .setPreparedStatementHandle(preparedStatementResult.getPreparedStatementHandle()) - .build()) - .toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command( + Any.pack( + CommandPreparedStatementQuery.newBuilder() + .setPreparedStatementHandle( + preparedStatementResult.getPreparedStatementHandle()) + .build()) + .toByteArray()); if (parameterBindingRoot != null && parameterBindingRoot.getRowCount() > 0) { putParameters(descriptor, options); @@ -1047,7 +1110,7 @@ private SyncPutListener putParameters(FlightDescriptor descriptor, CallOption... final SyncPutListener putListener = new SyncPutListener(); FlightClient.ClientStreamListener listener = - client.startPut(descriptor, parameterBindingRoot, putListener, options); + client.startPut(descriptor, parameterBindingRoot, putListener, options); listener.putNext(); listener.completed(); @@ -1073,11 +1136,14 @@ protected final void checkOpen() { */ public long executeUpdate(final CallOption... options) { checkOpen(); - final FlightDescriptor descriptor = FlightDescriptor - .command(Any.pack(CommandPreparedStatementUpdate.newBuilder() - .setPreparedStatementHandle(preparedStatementResult.getPreparedStatementHandle()) - .build()) - .toByteArray()); + final FlightDescriptor descriptor = + FlightDescriptor.command( + Any.pack( + CommandPreparedStatementUpdate.newBuilder() + .setPreparedStatementHandle( + preparedStatementResult.getPreparedStatementHandle()) + .build()) + .toByteArray()); setParameters(parameterBindingRoot == null ? VectorSchemaRoot.of() : parameterBindingRoot); SyncPutListener putListener = putParameters(descriptor, options); @@ -1105,15 +1171,17 @@ public void close(final CallOption... options) { return; } isClosed = true; - final Action action = new Action( - FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT.getType(), - Any.pack(ActionClosePreparedStatementRequest.newBuilder() - .setPreparedStatementHandle(preparedStatementResult.getPreparedStatementHandle()) - .build()) - .toByteArray()); + final Action action = + new Action( + FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT.getType(), + Any.pack( + ActionClosePreparedStatementRequest.newBuilder() + .setPreparedStatementHandle( + preparedStatementResult.getPreparedStatementHandle()) + .build()) + .toByteArray()); final Iterator closePreparedStatementResults = client.doAction(action, options); - closePreparedStatementResults.forEachRemaining(result -> { - }); + closePreparedStatementResults.forEachRemaining(result -> {}); clearParameters(); } @@ -1202,10 +1270,13 @@ public int hashCode() { @Override public String toString() { - return "SubstraitPlan{" + - "plan=" + Arrays.toString(plan) + - ", version='" + version + '\'' + - '}'; + return "SubstraitPlan{" + + "plan=" + + Arrays.toString(plan) + + ", version='" + + version + + '\'' + + '}'; } } } diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlColumnMetadata.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlColumnMetadata.java index 186e8bc04ec..d8dd954a035 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlColumnMetadata.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlColumnMetadata.java @@ -24,14 +24,16 @@ /** * Metadata for a column in a Flight SQL query. * - * This can be used with FlightSqlClient to access column's metadata contained in schemas returned - * by GetTables and query execution as follows: + *

This can be used with FlightSqlClient to access column's metadata contained in schemas + * returned by GetTables and query execution as follows: + * *

  *   FlightSqlColumnMetadata metadata = new FlightSqlColumnMetadata(field.getMetadata());
  *   Integer precision = metadata.getPrecision();
  * 
* * FlightSqlProducer can use this to set metadata on a column in a schema as follows: + * *
  *   FlightSqlColumnMetadata metadata = new FlightSqlColumnMetadata.Builder()
  *         .precision(10)
@@ -58,15 +60,14 @@ public class FlightSqlColumnMetadata {
 
   private final Map metadataMap;
 
-  /**
-   * Creates a new instance of FlightSqlColumnMetadata.
-   */
+  /** Creates a new instance of FlightSqlColumnMetadata. */
   public FlightSqlColumnMetadata(Map metadataMap) {
     this.metadataMap = new HashMap<>(metadataMap);
   }
 
   /**
    * Returns the metadata map.
+   *
    * @return The metadata map.
    */
   public Map getMetadataMap() {
@@ -75,6 +76,7 @@ public Map getMetadataMap() {
 
   /**
    * Returns the catalog name.
+   *
    * @return The catalog name.
    */
   public String getCatalogName() {
@@ -83,6 +85,7 @@ public String getCatalogName() {
 
   /**
    * Returns the schema name.
+   *
    * @return The schema name.
    */
   public String getSchemaName() {
@@ -91,6 +94,7 @@ public String getSchemaName() {
 
   /**
    * Returns the table name.
+   *
    * @return The table name.
    */
   public String getTableName() {
@@ -99,6 +103,7 @@ public String getTableName() {
 
   /**
    * Returns the type name.
+   *
    * @return The type name.
    */
   public String getTypeName() {
@@ -107,6 +112,7 @@ public String getTypeName() {
 
   /**
    * Returns the precision / column size.
+   *
    * @return The precision / column size.
    */
   public Integer getPrecision() {
@@ -120,6 +126,7 @@ public Integer getPrecision() {
 
   /**
    * Returns the scale / decimal digits.
+   *
    * @return The scale / decimal digits.
    */
   public Integer getScale() {
@@ -133,6 +140,7 @@ public Integer getScale() {
 
   /**
    * Returns if the column is auto incremented.
+   *
    * @return True if the column is auto incremented, false otherwise.
    */
   public Boolean isAutoIncrement() {
@@ -146,6 +154,7 @@ public Boolean isAutoIncrement() {
 
   /**
    * Returns if the column is case-sensitive.
+   *
    * @return True if the column is case-sensitive, false otherwise.
    */
   public Boolean isCaseSensitive() {
@@ -159,6 +168,7 @@ public Boolean isCaseSensitive() {
 
   /**
    * Returns if the column is read only.
+   *
    * @return True if the column is read only, false otherwise.
    */
   public Boolean isReadOnly() {
@@ -172,6 +182,7 @@ public Boolean isReadOnly() {
 
   /**
    * Returns if the column is searchable.
+   *
    * @return True if the column is searchable, false otherwise.
    */
   public Boolean isSearchable() {
@@ -183,21 +194,18 @@ public Boolean isSearchable() {
     return stringToBoolean(value);
   }
 
-  /**
-   * Builder of FlightSqlColumnMetadata, used on FlightSqlProducer implementations.
-   */
+  /** Builder of FlightSqlColumnMetadata, used on FlightSqlProducer implementations. */
   public static class Builder {
     private final Map metadataMap;
 
-    /**
-     * Creates a new instance of FlightSqlColumnMetadata.Builder.
-     */
+    /** Creates a new instance of FlightSqlColumnMetadata.Builder. */
     public Builder() {
       this.metadataMap = new HashMap<>();
     }
 
     /**
      * Sets the catalog name.
+     *
      * @param catalogName the catalog name.
      * @return This builder.
      */
@@ -208,6 +216,7 @@ public Builder catalogName(String catalogName) {
 
     /**
      * Sets the schema name.
+     *
      * @param schemaName The schema name.
      * @return This builder.
      */
@@ -218,6 +227,7 @@ public Builder schemaName(String schemaName) {
 
     /**
      * Sets the table name.
+     *
      * @param tableName The table name.
      * @return This builder.
      */
@@ -228,6 +238,7 @@ public Builder tableName(String tableName) {
 
     /**
      * Sets the type name.
+     *
      * @param typeName The type name.
      * @return This builder.
      */
@@ -238,6 +249,7 @@ public Builder typeName(String typeName) {
 
     /**
      * Sets the precision / column size.
+     *
      * @param precision The precision / column size.
      * @return This builder.
      */
@@ -248,6 +260,7 @@ public Builder precision(int precision) {
 
     /**
      * Sets the scale / decimal digits.
+     *
      * @param scale The scale / decimal digits.
      * @return This builder.
      */
@@ -258,6 +271,7 @@ public Builder scale(int scale) {
 
     /**
      * Sets if the column is auto incremented.
+     *
      * @param isAutoIncrement True if the column is auto incremented.
      * @return This builder.
      */
@@ -268,6 +282,7 @@ public Builder isAutoIncrement(boolean isAutoIncrement) {
 
     /**
      * Sets if the column is case-sensitive.
+     *
      * @param isCaseSensitive If the column is case-sensitive.
      * @return This builder.
      */
@@ -278,6 +293,7 @@ public Builder isCaseSensitive(boolean isCaseSensitive) {
 
     /**
      * Sets if the column is read only.
+     *
      * @param isReadOnly If the column is read only.
      * @return This builder.
      */
@@ -288,6 +304,7 @@ public Builder isReadOnly(boolean isReadOnly) {
 
     /**
      * Sets if the column is searchable.
+     *
      * @param isSearchable If the column is searchable.
      * @return This builder.
      */
@@ -298,6 +315,7 @@ public Builder isSearchable(boolean isSearchable) {
 
     /**
      * Builds a new instance of FlightSqlColumnMetadata.
+     *
      * @return A new instance of FlightSqlColumnMetadata.
      */
     public FlightSqlColumnMetadata build() {
diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java
index e2d79129c1f..488462cc222 100644
--- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java
+++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlProducer.java
@@ -46,11 +46,13 @@
 import static org.apache.arrow.vector.types.Types.MinorType.UINT4;
 import static org.apache.arrow.vector.types.Types.MinorType.VARCHAR;
 
+import com.google.common.collect.ImmutableList;
+import com.google.protobuf.Any;
+import com.google.protobuf.InvalidProtocolBufferException;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.nio.ByteBuffer;
 import java.util.List;
-
 import org.apache.arrow.flight.Action;
 import org.apache.arrow.flight.ActionType;
 import org.apache.arrow.flight.CallStatus;
@@ -88,20 +90,13 @@
 import org.apache.arrow.vector.types.pojo.FieldType;
 import org.apache.arrow.vector.types.pojo.Schema;
 
-import com.google.common.collect.ImmutableList;
-import com.google.protobuf.Any;
-import com.google.protobuf.InvalidProtocolBufferException;
-
-/**
- * API to Implement an Arrow Flight SQL producer.
- */
+/** API to Implement an Arrow Flight SQL producer. */
 public interface FlightSqlProducer extends FlightProducer, AutoCloseable {
   /**
-   * Depending on the provided command, method either:
-   * 1. Return information about a SQL query, or
+   * Depending on the provided command, method either: 1. Return information about a SQL query, or
    * 2. Return information about a prepared statement. In this case, parameters binding is allowed.
    *
-   * @param context    Per-call context.
+   * @param context Per-call context.
    * @param descriptor The descriptor identifying the data stream.
    * @return information about the given SQL query, or the given prepared statement.
    */
@@ -114,10 +109,14 @@ default FlightInfo getFlightInfo(CallContext context, FlightDescriptor descripto
           FlightSqlUtils.unpackOrThrow(command, CommandStatementQuery.class), context, descriptor);
     } else if (command.is(CommandStatementSubstraitPlan.class)) {
       return getFlightInfoSubstraitPlan(
-          FlightSqlUtils.unpackOrThrow(command, CommandStatementSubstraitPlan.class), context, descriptor);
+          FlightSqlUtils.unpackOrThrow(command, CommandStatementSubstraitPlan.class),
+          context,
+          descriptor);
     } else if (command.is(CommandPreparedStatementQuery.class)) {
       return getFlightInfoPreparedStatement(
-          FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementQuery.class), context, descriptor);
+          FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementQuery.class),
+          context,
+          descriptor);
     } else if (command.is(CommandGetCatalogs.class)) {
       return getFlightInfoCatalogs(
           FlightSqlUtils.unpackOrThrow(command, CommandGetCatalogs.class), context, descriptor);
@@ -144,7 +143,9 @@ default FlightInfo getFlightInfo(CallContext context, FlightDescriptor descripto
           FlightSqlUtils.unpackOrThrow(command, CommandGetImportedKeys.class), context, descriptor);
     } else if (command.is(CommandGetCrossReference.class)) {
       return getFlightInfoCrossReference(
-          FlightSqlUtils.unpackOrThrow(command, CommandGetCrossReference.class), context, descriptor);
+          FlightSqlUtils.unpackOrThrow(command, CommandGetCrossReference.class),
+          context,
+          descriptor);
     } else if (command.is(CommandGetXdbcTypeInfo.class)) {
       return getFlightInfoTypeInfo(
           FlightSqlUtils.unpackOrThrow(command, CommandGetXdbcTypeInfo.class), context, descriptor);
@@ -158,7 +159,7 @@ default FlightInfo getFlightInfo(CallContext context, FlightDescriptor descripto
   /**
    * Returns the schema of the result produced by the SQL query.
    *
-   * @param context    Per-call context.
+   * @param context Per-call context.
    * @param descriptor The descriptor identifying the data stream.
    * @return the result set schema.
    */
@@ -171,10 +172,14 @@ default SchemaResult getSchema(CallContext context, FlightDescriptor descriptor)
           FlightSqlUtils.unpackOrThrow(command, CommandStatementQuery.class), context, descriptor);
     } else if (command.is(CommandPreparedStatementQuery.class)) {
       return getSchemaPreparedStatement(
-          FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementQuery.class), context, descriptor);
+          FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementQuery.class),
+          context,
+          descriptor);
     } else if (command.is(CommandStatementSubstraitPlan.class)) {
       return getSchemaSubstraitPlan(
-          FlightSqlUtils.unpackOrThrow(command, CommandStatementSubstraitPlan.class), context, descriptor);
+          FlightSqlUtils.unpackOrThrow(command, CommandStatementSubstraitPlan.class),
+          context,
+          descriptor);
     } else if (command.is(CommandGetCatalogs.class)) {
       return new SchemaResult(Schemas.GET_CATALOGS_SCHEMA);
     } else if (command.is(CommandGetCrossReference.class)) {
@@ -206,12 +211,12 @@ default SchemaResult getSchema(CallContext context, FlightDescriptor descriptor)
   }
 
   /**
-   * Depending on the provided command, method either:
-   * 1. Return data for a stream produced by executing the provided SQL query, or
-   * 2. Return data for a prepared statement. In this case, parameters binding is allowed.
+   * Depending on the provided command, method either: 1. Return data for a stream produced by
+   * executing the provided SQL query, or 2. Return data for a prepared statement. In this case,
+   * parameters binding is allowed.
    *
-   * @param context  Per-call context.
-   * @param ticket   The application-defined ticket identifying this stream.
+   * @param context Per-call context.
+   * @param ticket The application-defined ticket identifying this stream.
    * @param listener An interface for sending data back to the client.
    */
   @Override
@@ -230,73 +235,94 @@ default void getStream(CallContext context, Ticket ticket, ServerStreamListener
           FlightSqlUtils.unpackOrThrow(command, TicketStatementQuery.class), context, listener);
     } else if (command.is(CommandPreparedStatementQuery.class)) {
       getStreamPreparedStatement(
-          FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementQuery.class), context, listener);
+          FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementQuery.class),
+          context,
+          listener);
     } else if (command.is(CommandGetCatalogs.class)) {
       getStreamCatalogs(context, listener);
     } else if (command.is(CommandGetDbSchemas.class)) {
-      getStreamSchemas(FlightSqlUtils.unpackOrThrow(command, CommandGetDbSchemas.class), context, listener);
+      getStreamSchemas(
+          FlightSqlUtils.unpackOrThrow(command, CommandGetDbSchemas.class), context, listener);
     } else if (command.is(CommandGetTables.class)) {
-      getStreamTables(FlightSqlUtils.unpackOrThrow(command, CommandGetTables.class), context, listener);
+      getStreamTables(
+          FlightSqlUtils.unpackOrThrow(command, CommandGetTables.class), context, listener);
     } else if (command.is(CommandGetTableTypes.class)) {
       getStreamTableTypes(context, listener);
     } else if (command.is(CommandGetSqlInfo.class)) {
-      getStreamSqlInfo(FlightSqlUtils.unpackOrThrow(command, CommandGetSqlInfo.class), context, listener);
+      getStreamSqlInfo(
+          FlightSqlUtils.unpackOrThrow(command, CommandGetSqlInfo.class), context, listener);
     } else if (command.is(CommandGetPrimaryKeys.class)) {
-      getStreamPrimaryKeys(FlightSqlUtils.unpackOrThrow(command, CommandGetPrimaryKeys.class), context, listener);
+      getStreamPrimaryKeys(
+          FlightSqlUtils.unpackOrThrow(command, CommandGetPrimaryKeys.class), context, listener);
     } else if (command.is(CommandGetExportedKeys.class)) {
-      getStreamExportedKeys(FlightSqlUtils.unpackOrThrow(command, CommandGetExportedKeys.class), context, listener);
+      getStreamExportedKeys(
+          FlightSqlUtils.unpackOrThrow(command, CommandGetExportedKeys.class), context, listener);
     } else if (command.is(CommandGetImportedKeys.class)) {
-      getStreamImportedKeys(FlightSqlUtils.unpackOrThrow(command, CommandGetImportedKeys.class), context, listener);
+      getStreamImportedKeys(
+          FlightSqlUtils.unpackOrThrow(command, CommandGetImportedKeys.class), context, listener);
     } else if (command.is(CommandGetCrossReference.class)) {
-      getStreamCrossReference(FlightSqlUtils.unpackOrThrow(command, CommandGetCrossReference.class), context, listener);
+      getStreamCrossReference(
+          FlightSqlUtils.unpackOrThrow(command, CommandGetCrossReference.class), context, listener);
     } else if (command.is(CommandGetXdbcTypeInfo.class)) {
-      getStreamTypeInfo(FlightSqlUtils.unpackOrThrow(command, CommandGetXdbcTypeInfo.class), context, listener);
+      getStreamTypeInfo(
+          FlightSqlUtils.unpackOrThrow(command, CommandGetXdbcTypeInfo.class), context, listener);
     } else {
-      throw CallStatus.INVALID_ARGUMENT.withDescription("The defined request is invalid.").toRuntimeException();
+      throw CallStatus.INVALID_ARGUMENT
+          .withDescription("The defined request is invalid.")
+          .toRuntimeException();
     }
   }
 
   /**
-   * Depending on the provided command, method either:
-   * 1. Execute provided SQL query as an update statement, or
-   * 2. Execute provided update SQL query prepared statement. In this case, parameters binding
-   * is allowed, or
-   * 3. Binds parameters to the provided prepared statement.
+   * Depending on the provided command, method either: 1. Execute provided SQL query as an update
+   * statement, or 2. Execute provided update SQL query prepared statement. In this case, parameters
+   * binding is allowed, or 3. Binds parameters to the provided prepared statement.
    *
-   * @param context      Per-call context.
+   * @param context Per-call context.
    * @param flightStream The data stream being uploaded.
-   * @param ackStream    The data stream listener for update result acknowledgement.
+   * @param ackStream The data stream listener for update result acknowledgement.
    * @return a Runnable to process the stream.
    */
   @Override
-  default Runnable acceptPut(CallContext context, FlightStream flightStream, StreamListener ackStream) {
+  default Runnable acceptPut(
+      CallContext context, FlightStream flightStream, StreamListener ackStream) {
     final Any command = FlightSqlUtils.parseOrThrow(flightStream.getDescriptor().getCommand());
 
     if (command.is(CommandStatementUpdate.class)) {
       return acceptPutStatement(
           FlightSqlUtils.unpackOrThrow(command, CommandStatementUpdate.class),
-          context, flightStream, ackStream);
+          context,
+          flightStream,
+          ackStream);
     } else if (command.is(CommandStatementSubstraitPlan.class)) {
       return acceptPutSubstraitPlan(
           FlightSqlUtils.unpackOrThrow(command, CommandStatementSubstraitPlan.class),
-          context, flightStream, ackStream);
+          context,
+          flightStream,
+          ackStream);
     } else if (command.is(CommandPreparedStatementUpdate.class)) {
       return acceptPutPreparedStatementUpdate(
           FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementUpdate.class),
-          context, flightStream, ackStream);
+          context,
+          flightStream,
+          ackStream);
     } else if (command.is(CommandPreparedStatementQuery.class)) {
       return acceptPutPreparedStatementQuery(
           FlightSqlUtils.unpackOrThrow(command, CommandPreparedStatementQuery.class),
-          context, flightStream, ackStream);
+          context,
+          flightStream,
+          ackStream);
     }
 
-    throw CallStatus.INVALID_ARGUMENT.withDescription("The defined request is invalid.").toRuntimeException();
+    throw CallStatus.INVALID_ARGUMENT
+        .withDescription("The defined request is invalid.")
+        .toRuntimeException();
   }
 
   /**
    * Lists all available Flight SQL actions.
    *
-   * @param context  Per-call context.
+   * @param context Per-call context.
    * @param listener An interface for sending data back to the client.
    */
   @Override
@@ -308,8 +334,8 @@ default void listActions(CallContext context, StreamListener listene
   /**
    * Performs the requested Flight SQL action.
    *
-   * @param context  Per-call context.
-   * @param action   Client-supplied parameters.
+   * @param context Per-call context.
+   * @param action Client-supplied parameters.
    * @param listener A stream of responses.
    */
   @Override
@@ -322,7 +348,8 @@ default void doAction(CallContext context, Action action, StreamListener
       beginSavepoint(request, context, new ProtoListener<>(listener));
     } else if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_BEGIN_TRANSACTION.getType())) {
       final ActionBeginTransactionRequest request =
-          FlightSqlUtils.unpackAndParseOrThrow(action.getBody(), ActionBeginTransactionRequest.class);
+          FlightSqlUtils.unpackAndParseOrThrow(
+              action.getBody(), ActionBeginTransactionRequest.class);
       beginTransaction(request, context, new ProtoListener<>(listener));
     } else if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_CANCEL_QUERY.getType())) {
       //noinspection deprecation
@@ -332,24 +359,29 @@ default void doAction(CallContext context, Action action, StreamListener
       try {
         info = FlightInfo.deserialize(request.getInfo().asReadOnlyByteBuffer());
       } catch (IOException | URISyntaxException e) {
-        listener.onError(CallStatus.INTERNAL
-            .withDescription("Could not unpack FlightInfo: " + e)
-            .withCause(e)
-            .toRuntimeException());
+        listener.onError(
+            CallStatus.INTERNAL
+                .withDescription("Could not unpack FlightInfo: " + e)
+                .withCause(e)
+                .toRuntimeException());
         return;
       }
       cancelQuery(info, context, new CancelListener(listener));
     } else if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT.getType())) {
-      final ActionCreatePreparedStatementRequest request = FlightSqlUtils.unpackAndParseOrThrow(action.getBody(),
-          ActionCreatePreparedStatementRequest.class);
+      final ActionCreatePreparedStatementRequest request =
+          FlightSqlUtils.unpackAndParseOrThrow(
+              action.getBody(), ActionCreatePreparedStatementRequest.class);
       createPreparedStatement(request, context, listener);
-    } else if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_SUBSTRAIT_PLAN.getType())) {
+    } else if (actionType.equals(
+        FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_SUBSTRAIT_PLAN.getType())) {
       final ActionCreatePreparedSubstraitPlanRequest request =
-          FlightSqlUtils.unpackAndParseOrThrow(action.getBody(), ActionCreatePreparedSubstraitPlanRequest.class);
+          FlightSqlUtils.unpackAndParseOrThrow(
+              action.getBody(), ActionCreatePreparedSubstraitPlanRequest.class);
       createPreparedSubstraitPlan(request, context, new ProtoListener<>(listener));
     } else if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT.getType())) {
       final ActionClosePreparedStatementRequest request =
-          FlightSqlUtils.unpackAndParseOrThrow(action.getBody(), ActionClosePreparedStatementRequest.class);
+          FlightSqlUtils.unpackAndParseOrThrow(
+              action.getBody(), ActionClosePreparedStatementRequest.class);
       closePreparedStatement(request, context, new NoResultListener(listener));
     } else if (actionType.equals(FlightSqlUtils.FLIGHT_SQL_END_SAVEPOINT.getType())) {
       ActionEndSavepointRequest request =
@@ -364,10 +396,11 @@ default void doAction(CallContext context, Action action, StreamListener
       try {
         request = CancelFlightInfoRequest.deserialize(ByteBuffer.wrap(action.getBody()));
       } catch (IOException | URISyntaxException e) {
-        listener.onError(CallStatus.INTERNAL
-            .withDescription("Could not unpack FlightInfo: " + e)
-            .withCause(e)
-            .toRuntimeException());
+        listener.onError(
+            CallStatus.INTERNAL
+                .withDescription("Could not unpack FlightInfo: " + e)
+                .withCause(e)
+                .toRuntimeException());
         return;
       }
       cancelFlightInfo(request, context, new CancelStatusListener(listener));
@@ -376,10 +409,11 @@ default void doAction(CallContext context, Action action, StreamListener
       try {
         request = RenewFlightEndpointRequest.deserialize(ByteBuffer.wrap(action.getBody()));
       } catch (IOException | URISyntaxException e) {
-        listener.onError(CallStatus.INTERNAL
-            .withDescription("Could not unpack FlightInfo: " + e)
-            .withCause(e)
-            .toRuntimeException());
+        listener.onError(
+            CallStatus.INTERNAL
+                .withDescription("Could not unpack FlightInfo: " + e)
+                .withCause(e)
+                .toRuntimeException());
         return;
       }
       renewFlightEndpoint(request, context, new FlightEndpointListener(listener));
@@ -393,24 +427,28 @@ default void doAction(CallContext context, Action action, StreamListener
   /**
    * Create a savepoint within a transaction.
    *
-   * @param request  The savepoint request.
-   * @param context  Per-call context.
+   * @param request The savepoint request.
+   * @param context Per-call context.
    * @param listener The newly created savepoint ID.
    */
-  default void beginSavepoint(ActionBeginSavepointRequest request, CallContext context,
-                              StreamListener listener) {
+  default void beginSavepoint(
+      ActionBeginSavepointRequest request,
+      CallContext context,
+      StreamListener listener) {
     listener.onError(CallStatus.UNIMPLEMENTED.toRuntimeException());
   }
 
   /**
    * Begin a transaction.
    *
-   * @param request  The transaction request.
-   * @param context  Per-call context.
+   * @param request The transaction request.
+   * @param context Per-call context.
    * @param listener The newly created transaction ID.
    */
-  default void beginTransaction(ActionBeginTransactionRequest request, CallContext context,
-                                StreamListener listener) {
+  default void beginTransaction(
+      ActionBeginTransactionRequest request,
+      CallContext context,
+      StreamListener listener) {
     listener.onError(CallStatus.UNIMPLEMENTED.toRuntimeException());
   }
 
@@ -421,172 +459,181 @@ default void beginTransaction(ActionBeginTransactionRequest request, CallContext
    * @param context Per-call context.
    * @param listener An interface for sending data back to the client.
    */
-  default void cancelFlightInfo(CancelFlightInfoRequest request, CallContext context,
-                                StreamListener listener) {
+  default void cancelFlightInfo(
+      CancelFlightInfoRequest request, CallContext context, StreamListener listener) {
     listener.onError(CallStatus.UNIMPLEMENTED.toRuntimeException());
   }
 
-
   /**
    * Explicitly cancel a query.
    *
-   * @param info     The FlightInfo of the query to cancel.
-   * @param context  Per-call context.
+   * @param info The FlightInfo of the query to cancel.
+   * @param context Per-call context.
    * @param listener Whether cancellation succeeded.
    * @deprecated Prefer {@link #cancelFlightInfo(FlightInfo, CallContext, StreamListener)}.
    */
   @Deprecated
-  default void cancelQuery(FlightInfo info, CallContext context, StreamListener listener) {
+  default void cancelQuery(
+      FlightInfo info, CallContext context, StreamListener listener) {
     CancelFlightInfoRequest request = new CancelFlightInfoRequest(info);
-    cancelFlightInfo(request, context, new StreamListener() {
-      @Override
-      public void onNext(CancelStatus val) {
-        switch (val) {
-          case UNSPECIFIED:
-            listener.onNext(CancelResult.UNSPECIFIED);
-            break;
-          case CANCELLED:
-            listener.onNext(CancelResult.CANCELLED);
-            break;
-          case CANCELLING:
-            listener.onNext(CancelResult.CANCELLING);
-            break;
-          case NOT_CANCELLABLE:
-            listener.onNext(CancelResult.NOT_CANCELLABLE);
-            break;
-          default:
-            // XXX: CheckStyle requires a default clause which arguably makes the code worse.
-            throw new AssertionError("Unknown enum variant " + val);
-        }
-      }
-
-      @Override
-      public void onError(Throwable t) {
-        listener.onError(t);
-      }
-
-      @Override
-      public void onCompleted() {
-        listener.onCompleted();
-      }
-    });
+    cancelFlightInfo(
+        request,
+        context,
+        new StreamListener() {
+          @Override
+          public void onNext(CancelStatus val) {
+            switch (val) {
+              case UNSPECIFIED:
+                listener.onNext(CancelResult.UNSPECIFIED);
+                break;
+              case CANCELLED:
+                listener.onNext(CancelResult.CANCELLED);
+                break;
+              case CANCELLING:
+                listener.onNext(CancelResult.CANCELLING);
+                break;
+              case NOT_CANCELLABLE:
+                listener.onNext(CancelResult.NOT_CANCELLABLE);
+                break;
+              default:
+                // XXX: CheckStyle requires a default clause which arguably makes the code worse.
+                throw new AssertionError("Unknown enum variant " + val);
+            }
+          }
+
+          @Override
+          public void onError(Throwable t) {
+            listener.onError(t);
+          }
+
+          @Override
+          public void onCompleted() {
+            listener.onCompleted();
+          }
+        });
   }
 
   /**
-   * Creates a prepared statement on the server and returns a handle and metadata for in a
-   * {@link ActionCreatePreparedStatementResult} object in a {@link Result}
-   * object.
+   * Creates a prepared statement on the server and returns a handle and metadata for in a {@link
+   * ActionCreatePreparedStatementResult} object in a {@link Result} object.
    *
-   * @param request  The sql command to generate the prepared statement.
-   * @param context  Per-call context.
+   * @param request The sql command to generate the prepared statement.
+   * @param context Per-call context.
    * @param listener A stream of responses.
    */
-  void createPreparedStatement(ActionCreatePreparedStatementRequest request, CallContext context,
-                               StreamListener listener);
+  void createPreparedStatement(
+      ActionCreatePreparedStatementRequest request,
+      CallContext context,
+      StreamListener listener);
 
   /**
    * Pre-compile a Substrait plan.
-   * @param request  The plan.
-   * @param context  Per-call context.
+   *
+   * @param request The plan.
+   * @param context Per-call context.
    * @param listener The resulting prepared statement.
    */
-  default void createPreparedSubstraitPlan(ActionCreatePreparedSubstraitPlanRequest request, CallContext context,
-                                           StreamListener listener) {
+  default void createPreparedSubstraitPlan(
+      ActionCreatePreparedSubstraitPlanRequest request,
+      CallContext context,
+      StreamListener listener) {
     listener.onError(CallStatus.UNIMPLEMENTED.toRuntimeException());
   }
 
   /**
    * Closes a prepared statement on the server. No result is expected.
    *
-   * @param request  The sql command to generate the prepared statement.
-   * @param context  Per-call context.
+   * @param request The sql command to generate the prepared statement.
+   * @param context Per-call context.
    * @param listener A stream of responses.
    */
-  void closePreparedStatement(ActionClosePreparedStatementRequest request, CallContext context,
-                              StreamListener listener);
+  void closePreparedStatement(
+      ActionClosePreparedStatementRequest request,
+      CallContext context,
+      StreamListener listener);
 
   /**
    * Release or roll back to a savepoint.
    *
-   * @param request  The savepoint, and whether to release/rollback.
-   * @param context  Per-call context.
-   * @param listener Call {@link StreamListener#onCompleted()} or
-   *                 {@link StreamListener#onError(Throwable)} when done; do not send a result.
+   * @param request The savepoint, and whether to release/rollback.
+   * @param context Per-call context.
+   * @param listener Call {@link StreamListener#onCompleted()} or {@link
+   *     StreamListener#onError(Throwable)} when done; do not send a result.
    */
-  default void endSavepoint(ActionEndSavepointRequest request, CallContext context,
-                            StreamListener listener) {
+  default void endSavepoint(
+      ActionEndSavepointRequest request, CallContext context, StreamListener listener) {
     listener.onError(CallStatus.UNIMPLEMENTED.toRuntimeException());
   }
 
   /**
    * Commit or roll back to a transaction.
    *
-   * @param request  The transaction, and whether to release/rollback.
-   * @param context  Per-call context.
-   * @param listener Call {@link StreamListener#onCompleted()} or
-   *                 {@link StreamListener#onError(Throwable)} when done; do not send a result.
+   * @param request The transaction, and whether to release/rollback.
+   * @param context Per-call context.
+   * @param listener Call {@link StreamListener#onCompleted()} or {@link
+   *     StreamListener#onError(Throwable)} when done; do not send a result.
    */
-  default void endTransaction(ActionEndTransactionRequest request, CallContext context,
-                              StreamListener listener) {
+  default void endTransaction(
+      ActionEndTransactionRequest request, CallContext context, StreamListener listener) {
     listener.onError(CallStatus.UNIMPLEMENTED.toRuntimeException());
   }
 
   /**
    * Evaluate a SQL query.
    *
-   * @param command    The SQL query.
-   * @param context    Per-call context.
+   * @param command The SQL query.
+   * @param context Per-call context.
    * @param descriptor The descriptor identifying the data stream.
    * @return Metadata about the stream.
    */
-  FlightInfo getFlightInfoStatement(CommandStatementQuery command, CallContext context,
-                                    FlightDescriptor descriptor);
+  FlightInfo getFlightInfoStatement(
+      CommandStatementQuery command, CallContext context, FlightDescriptor descriptor);
 
   /**
    * Evaluate a Substrait plan.
    *
-   * @param command    The Substrait plan.
-   * @param context    Per-call context.
+   * @param command The Substrait plan.
+   * @param context Per-call context.
    * @param descriptor The descriptor identifying the data stream.
    * @return Metadata about the stream.
    */
-  default FlightInfo getFlightInfoSubstraitPlan(CommandStatementSubstraitPlan command, CallContext context,
-                                                FlightDescriptor descriptor) {
+  default FlightInfo getFlightInfoSubstraitPlan(
+      CommandStatementSubstraitPlan command, CallContext context, FlightDescriptor descriptor) {
     throw CallStatus.UNIMPLEMENTED.toRuntimeException();
   }
 
   /**
    * Gets information about a particular prepared statement data stream.
    *
-   * @param command    The prepared statement to generate the data stream.
-   * @param context    Per-call context.
+   * @param command The prepared statement to generate the data stream.
+   * @param context Per-call context.
    * @param descriptor The descriptor identifying the data stream.
    * @return Metadata about the stream.
    */
-  FlightInfo getFlightInfoPreparedStatement(CommandPreparedStatementQuery command,
-                                            CallContext context, FlightDescriptor descriptor);
+  FlightInfo getFlightInfoPreparedStatement(
+      CommandPreparedStatementQuery command, CallContext context, FlightDescriptor descriptor);
 
   /**
    * Get the result schema for a SQL query.
    *
-   * @param command    The SQL query.
-   * @param context    Per-call context.
+   * @param command The SQL query.
+   * @param context Per-call context.
    * @param descriptor The descriptor identifying the data stream.
    * @return the schema of the result set.
    */
-  SchemaResult getSchemaStatement(CommandStatementQuery command, CallContext context,
-                                  FlightDescriptor descriptor);
+  SchemaResult getSchemaStatement(
+      CommandStatementQuery command, CallContext context, FlightDescriptor descriptor);
 
   /**
    * Get the schema of the result set of a prepared statement.
    *
-   * @param command    The prepared statement handle.
-   * @param context    Per-call context.
+   * @param command The prepared statement handle.
+   * @param context Per-call context.
    * @param descriptor The descriptor identifying the data stream.
    * @return the schema of the result set.
    */
-  default SchemaResult getSchemaPreparedStatement(CommandPreparedStatementQuery command, CallContext context,
-                                  FlightDescriptor descriptor) {
+  default SchemaResult getSchemaPreparedStatement(
+      CommandPreparedStatementQuery command, CallContext context, FlightDescriptor descriptor) {
     throw CallStatus.UNIMPLEMENTED
         .withDescription("GetSchema with CommandPreparedStatementQuery is not implemented")
         .toRuntimeException();
@@ -595,59 +642,67 @@ default SchemaResult getSchemaPreparedStatement(CommandPreparedStatementQuery co
   /**
    * Get the result schema for a Substrait plan.
    *
-   * @param command    The Substrait plan.
-   * @param context    Per-call context.
+   * @param command The Substrait plan.
+   * @param context Per-call context.
    * @param descriptor The descriptor identifying the data stream.
    * @return Schema for the stream.
    */
-  default SchemaResult getSchemaSubstraitPlan(CommandStatementSubstraitPlan command, CallContext context,
-                                              FlightDescriptor descriptor) {
+  default SchemaResult getSchemaSubstraitPlan(
+      CommandStatementSubstraitPlan command, CallContext context, FlightDescriptor descriptor) {
     throw CallStatus.UNIMPLEMENTED.toRuntimeException();
   }
 
   /**
    * Returns data for a SQL query based data stream.
-   * @param ticket   Ticket message containing the statement handle.
-   * @param context  Per-call context.
+   *
+   * @param ticket Ticket message containing the statement handle.
+   * @param context Per-call context.
    * @param listener An interface for sending data back to the client.
    */
-  void getStreamStatement(TicketStatementQuery ticket, CallContext context,
-                          ServerStreamListener listener);
+  void getStreamStatement(
+      TicketStatementQuery ticket, CallContext context, ServerStreamListener listener);
 
   /**
    * Returns data for a particular prepared statement query instance.
    *
-   * @param command  The prepared statement to generate the data stream.
-   * @param context  Per-call context.
+   * @param command The prepared statement to generate the data stream.
+   * @param context Per-call context.
    * @param listener An interface for sending data back to the client.
    */
-  void getStreamPreparedStatement(CommandPreparedStatementQuery command, CallContext context,
-                                  ServerStreamListener listener);
+  void getStreamPreparedStatement(
+      CommandPreparedStatementQuery command, CallContext context, ServerStreamListener listener);
 
   /**
    * Accepts uploaded data for a particular SQL query based data stream.
+   *
    * 

`PutResult`s must be in the form of a {@link DoPutUpdateResult}. * - * @param command The sql command to generate the data stream. - * @param context Per-call context. + * @param command The sql command to generate the data stream. + * @param context Per-call context. * @param flightStream The data stream being uploaded. - * @param ackStream The result data stream. + * @param ackStream The result data stream. * @return A runnable to process the stream. */ - Runnable acceptPutStatement(CommandStatementUpdate command, CallContext context, - FlightStream flightStream, StreamListener ackStream); + Runnable acceptPutStatement( + CommandStatementUpdate command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream); /** * Handle a Substrait plan with uploaded data. * - * @param command The Substrait plan to evaluate. - * @param context Per-call context. + * @param command The Substrait plan to evaluate. + * @param context Per-call context. * @param flightStream The data stream being uploaded. - * @param ackStream The result data stream. + * @param ackStream The result data stream. * @return A runnable to process the stream. */ - default Runnable acceptPutSubstraitPlan(CommandStatementSubstraitPlan command, CallContext context, - FlightStream flightStream, StreamListener ackStream) { + default Runnable acceptPutSubstraitPlan( + CommandStatementSubstraitPlan command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { return () -> { ackStream.onError(CallStatus.UNIMPLEMENTED.toRuntimeException()); }; @@ -655,239 +710,247 @@ default Runnable acceptPutSubstraitPlan(CommandStatementSubstraitPlan command, C /** * Accepts uploaded data for a particular prepared statement data stream. + * *

`PutResult`s must be in the form of a {@link DoPutUpdateResult}. * - * @param command The prepared statement to generate the data stream. - * @param context Per-call context. + * @param command The prepared statement to generate the data stream. + * @param context Per-call context. * @param flightStream The data stream being uploaded. - * @param ackStream The result data stream. + * @param ackStream The result data stream. * @return A runnable to process the stream. */ - Runnable acceptPutPreparedStatementUpdate(CommandPreparedStatementUpdate command, - CallContext context, FlightStream flightStream, - StreamListener ackStream); + Runnable acceptPutPreparedStatementUpdate( + CommandPreparedStatementUpdate command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream); /** * Accepts uploaded parameter values for a particular prepared statement query. * - * @param command The prepared statement the parameter values will bind to. - * @param context Per-call context. + * @param command The prepared statement the parameter values will bind to. + * @param context Per-call context. * @param flightStream The data stream being uploaded. - * @param ackStream The result data stream. + * @param ackStream The result data stream. * @return A runnable to process the stream. */ - Runnable acceptPutPreparedStatementQuery(CommandPreparedStatementQuery command, - CallContext context, FlightStream flightStream, - StreamListener ackStream); + Runnable acceptPutPreparedStatementQuery( + CommandPreparedStatementQuery command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream); /** - * Returns the SQL Info of the server by returning a - * {@link CommandGetSqlInfo} in a {@link Result}. + * Returns the SQL Info of the server by returning a {@link CommandGetSqlInfo} in a {@link + * Result}. * - * @param request request filter parameters. - * @param context Per-call context. + * @param request request filter parameters. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoSqlInfo(CommandGetSqlInfo request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoSqlInfo( + CommandGetSqlInfo request, CallContext context, FlightDescriptor descriptor); /** * Returns data for SQL info based data stream. * - * @param command The command to generate the data stream. - * @param context Per-call context. + * @param command The command to generate the data stream. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - void getStreamSqlInfo(CommandGetSqlInfo command, CallContext context, ServerStreamListener listener); - + void getStreamSqlInfo( + CommandGetSqlInfo command, CallContext context, ServerStreamListener listener); /** * Returns a description of all the data types supported by source. * - * @param request request filter parameters. - * @param descriptor The descriptor identifying the data stream. - * @return Metadata about the stream. + * @param request request filter parameters. + * @param descriptor The descriptor identifying the data stream. + * @return Metadata about the stream. */ - FlightInfo getFlightInfoTypeInfo(CommandGetXdbcTypeInfo request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoTypeInfo( + CommandGetXdbcTypeInfo request, CallContext context, FlightDescriptor descriptor); /** * Returns data for type info based data stream. * - * @param context Per-call context. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - void getStreamTypeInfo(CommandGetXdbcTypeInfo request, CallContext context, ServerStreamListener listener); + void getStreamTypeInfo( + CommandGetXdbcTypeInfo request, CallContext context, ServerStreamListener listener); /** - * Returns the available catalogs by returning a stream of - * {@link CommandGetCatalogs} objects in {@link Result} objects. + * Returns the available catalogs by returning a stream of {@link CommandGetCatalogs} objects in + * {@link Result} objects. * - * @param request request filter parameters. - * @param context Per-call context. + * @param request request filter parameters. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoCatalogs(CommandGetCatalogs request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoCatalogs( + CommandGetCatalogs request, CallContext context, FlightDescriptor descriptor); /** * Returns data for catalogs based data stream. * - * @param context Per-call context. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ void getStreamCatalogs(CallContext context, ServerStreamListener listener); /** - * Returns the available schemas by returning a stream of - * {@link CommandGetDbSchemas} objects in {@link Result} objects. + * Returns the available schemas by returning a stream of {@link CommandGetDbSchemas} objects in + * {@link Result} objects. * - * @param request request filter parameters. - * @param context Per-call context. + * @param request request filter parameters. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoSchemas(CommandGetDbSchemas request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoSchemas( + CommandGetDbSchemas request, CallContext context, FlightDescriptor descriptor); /** * Returns data for schemas based data stream. * - * @param command The command to generate the data stream. - * @param context Per-call context. + * @param command The command to generate the data stream. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - void getStreamSchemas(CommandGetDbSchemas command, CallContext context, ServerStreamListener listener); + void getStreamSchemas( + CommandGetDbSchemas command, CallContext context, ServerStreamListener listener); /** - * Returns the available tables by returning a stream of - * {@link CommandGetTables} objects in {@link Result} objects. + * Returns the available tables by returning a stream of {@link CommandGetTables} objects in + * {@link Result} objects. * - * @param request request filter parameters. - * @param context Per-call context. + * @param request request filter parameters. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoTables(CommandGetTables request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoTables( + CommandGetTables request, CallContext context, FlightDescriptor descriptor); /** * Returns data for tables based data stream. * - * @param command The command to generate the data stream. - * @param context Per-call context. + * @param command The command to generate the data stream. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - void getStreamTables(CommandGetTables command, CallContext context, ServerStreamListener listener); + void getStreamTables( + CommandGetTables command, CallContext context, ServerStreamListener listener); /** - * Returns the available table types by returning a stream of - * {@link CommandGetTableTypes} objects in {@link Result} objects. + * Returns the available table types by returning a stream of {@link CommandGetTableTypes} objects + * in {@link Result} objects. * - * @param context Per-call context. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoTableTypes(CommandGetTableTypes request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoTableTypes( + CommandGetTableTypes request, CallContext context, FlightDescriptor descriptor); /** * Returns data for table types based data stream. * - * @param context Per-call context. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ void getStreamTableTypes(CallContext context, ServerStreamListener listener); /** - * Returns the available primary keys by returning a stream of - * {@link CommandGetPrimaryKeys} objects in {@link Result} objects. + * Returns the available primary keys by returning a stream of {@link CommandGetPrimaryKeys} + * objects in {@link Result} objects. * - * @param request request filter parameters. - * @param context Per-call context. + * @param request request filter parameters. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoPrimaryKeys(CommandGetPrimaryKeys request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoPrimaryKeys( + CommandGetPrimaryKeys request, CallContext context, FlightDescriptor descriptor); /** * Returns data for primary keys based data stream. * - * @param command The command to generate the data stream. - * @param context Per-call context. + * @param command The command to generate the data stream. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - void getStreamPrimaryKeys(CommandGetPrimaryKeys command, CallContext context, - ServerStreamListener listener); + void getStreamPrimaryKeys( + CommandGetPrimaryKeys command, CallContext context, ServerStreamListener listener); /** - * Retrieves a description of the foreign key columns that reference the given table's primary key columns - * {@link CommandGetExportedKeys} objects in {@link Result} objects. + * Retrieves a description of the foreign key columns that reference the given table's primary key + * columns {@link CommandGetExportedKeys} objects in {@link Result} objects. * - * @param request request filter parameters. - * @param context Per-call context. + * @param request request filter parameters. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoExportedKeys(CommandGetExportedKeys request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoExportedKeys( + CommandGetExportedKeys request, CallContext context, FlightDescriptor descriptor); /** - * Retrieves a description of the primary key columns that are referenced by given table's foreign key columns - * {@link CommandGetImportedKeys} objects in {@link Result} objects. + * Retrieves a description of the primary key columns that are referenced by given table's foreign + * key columns {@link CommandGetImportedKeys} objects in {@link Result} objects. * - * @param request request filter parameters. - * @param context Per-call context. + * @param request request filter parameters. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoImportedKeys(CommandGetImportedKeys request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoImportedKeys( + CommandGetImportedKeys request, CallContext context, FlightDescriptor descriptor); /** - * Retrieve a description of the foreign key columns that reference the given table's primary key columns - * {@link CommandGetCrossReference} objects in {@link Result} objects. + * Retrieve a description of the foreign key columns that reference the given table's primary key + * columns {@link CommandGetCrossReference} objects in {@link Result} objects. * - * @param request request filter parameters. - * @param context Per-call context. + * @param request request filter parameters. + * @param context Per-call context. * @param descriptor The descriptor identifying the data stream. * @return Metadata about the stream. */ - FlightInfo getFlightInfoCrossReference(CommandGetCrossReference request, CallContext context, - FlightDescriptor descriptor); + FlightInfo getFlightInfoCrossReference( + CommandGetCrossReference request, CallContext context, FlightDescriptor descriptor); /** * Returns data for foreign keys based data stream. * - * @param command The command to generate the data stream. - * @param context Per-call context. + * @param command The command to generate the data stream. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - void getStreamExportedKeys(CommandGetExportedKeys command, CallContext context, - ServerStreamListener listener); + void getStreamExportedKeys( + CommandGetExportedKeys command, CallContext context, ServerStreamListener listener); /** * Returns data for foreign keys based data stream. * - * @param command The command to generate the data stream. - * @param context Per-call context. + * @param command The command to generate the data stream. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - void getStreamImportedKeys(CommandGetImportedKeys command, CallContext context, - ServerStreamListener listener); + void getStreamImportedKeys( + CommandGetImportedKeys command, CallContext context, ServerStreamListener listener); /** * Returns data for cross reference based data stream. * - * @param command The command to generate the data stream. - * @param context Per-call context. + * @param command The command to generate the data stream. + * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - void getStreamCrossReference(CommandGetCrossReference command, CallContext context, - ServerStreamListener listener); + void getStreamCrossReference( + CommandGetCrossReference command, CallContext context, ServerStreamListener listener); /** * Renew the duration of the given endpoint. @@ -896,107 +959,129 @@ void getStreamCrossReference(CommandGetCrossReference command, CallContext conte * @param context Per-call context. * @param listener An interface for sending data back to the client. */ - default void renewFlightEndpoint(RenewFlightEndpointRequest request, CallContext context, - StreamListener listener) { + default void renewFlightEndpoint( + RenewFlightEndpointRequest request, + CallContext context, + StreamListener listener) { listener.onError(CallStatus.UNIMPLEMENTED.toRuntimeException()); } - /** - * Default schema templates for the {@link FlightSqlProducer}. - */ + /** Default schema templates for the {@link FlightSqlProducer}. */ final class Schemas { - public static final Schema GET_TABLES_SCHEMA = new Schema(asList( - Field.nullable("catalog_name", VARCHAR.getType()), - Field.nullable("db_schema_name", VARCHAR.getType()), - Field.notNullable("table_name", VARCHAR.getType()), - Field.notNullable("table_type", VARCHAR.getType()), - Field.notNullable("table_schema", MinorType.VARBINARY.getType()))); - public static final Schema GET_TABLES_SCHEMA_NO_SCHEMA = new Schema(asList( - Field.nullable("catalog_name", VARCHAR.getType()), - Field.nullable("db_schema_name", VARCHAR.getType()), - Field.notNullable("table_name", VARCHAR.getType()), - Field.notNullable("table_type", VARCHAR.getType()))); - public static final Schema GET_CATALOGS_SCHEMA = new Schema( - singletonList(Field.notNullable("catalog_name", VARCHAR.getType()))); + public static final Schema GET_TABLES_SCHEMA = + new Schema( + asList( + Field.nullable("catalog_name", VARCHAR.getType()), + Field.nullable("db_schema_name", VARCHAR.getType()), + Field.notNullable("table_name", VARCHAR.getType()), + Field.notNullable("table_type", VARCHAR.getType()), + Field.notNullable("table_schema", MinorType.VARBINARY.getType()))); + public static final Schema GET_TABLES_SCHEMA_NO_SCHEMA = + new Schema( + asList( + Field.nullable("catalog_name", VARCHAR.getType()), + Field.nullable("db_schema_name", VARCHAR.getType()), + Field.notNullable("table_name", VARCHAR.getType()), + Field.notNullable("table_type", VARCHAR.getType()))); + public static final Schema GET_CATALOGS_SCHEMA = + new Schema(singletonList(Field.notNullable("catalog_name", VARCHAR.getType()))); public static final Schema GET_TABLE_TYPES_SCHEMA = new Schema(singletonList(Field.notNullable("table_type", VARCHAR.getType()))); public static final Schema GET_SCHEMAS_SCHEMA = - new Schema(asList( - Field.nullable("catalog_name", VARCHAR.getType()), - Field.notNullable("db_schema_name", VARCHAR.getType()))); + new Schema( + asList( + Field.nullable("catalog_name", VARCHAR.getType()), + Field.notNullable("db_schema_name", VARCHAR.getType()))); private static final Schema GET_IMPORTED_EXPORTED_AND_CROSS_REFERENCE_KEYS_SCHEMA = - new Schema(asList( - Field.nullable("pk_catalog_name", VARCHAR.getType()), - Field.nullable("pk_db_schema_name", VARCHAR.getType()), - Field.notNullable("pk_table_name", VARCHAR.getType()), - Field.notNullable("pk_column_name", VARCHAR.getType()), - Field.nullable("fk_catalog_name", VARCHAR.getType()), - Field.nullable("fk_db_schema_name", VARCHAR.getType()), - Field.notNullable("fk_table_name", VARCHAR.getType()), - Field.notNullable("fk_column_name", VARCHAR.getType()), - Field.notNullable("key_sequence", INT.getType()), - Field.nullable("fk_key_name", VARCHAR.getType()), - Field.nullable("pk_key_name", VARCHAR.getType()), - Field.notNullable("update_rule", MinorType.UINT1.getType()), - Field.notNullable("delete_rule", MinorType.UINT1.getType()))); - public static final Schema GET_IMPORTED_KEYS_SCHEMA = GET_IMPORTED_EXPORTED_AND_CROSS_REFERENCE_KEYS_SCHEMA; - public static final Schema GET_EXPORTED_KEYS_SCHEMA = GET_IMPORTED_EXPORTED_AND_CROSS_REFERENCE_KEYS_SCHEMA; - public static final Schema GET_CROSS_REFERENCE_SCHEMA = GET_IMPORTED_EXPORTED_AND_CROSS_REFERENCE_KEYS_SCHEMA; - private static final List GET_SQL_INFO_DENSE_UNION_SCHEMA_FIELDS = asList( - Field.notNullable("string_value", VARCHAR.getType()), - Field.notNullable("bool_value", BIT.getType()), - Field.notNullable("bigint_value", BIGINT.getType()), - Field.notNullable("int32_bitmask", INT.getType()), - new Field( - "string_list", FieldType.notNullable(LIST.getType()), - singletonList(Field.nullable("item", VARCHAR.getType()))), - new Field( - "int32_to_int32_list_map", FieldType.notNullable(new ArrowType.Map(false)), - singletonList(new Field(DATA_VECTOR_NAME, new FieldType(false, STRUCT.getType(), null), - ImmutableList.of( - Field.notNullable(KEY_NAME, INT.getType()), + new Schema( + asList( + Field.nullable("pk_catalog_name", VARCHAR.getType()), + Field.nullable("pk_db_schema_name", VARCHAR.getType()), + Field.notNullable("pk_table_name", VARCHAR.getType()), + Field.notNullable("pk_column_name", VARCHAR.getType()), + Field.nullable("fk_catalog_name", VARCHAR.getType()), + Field.nullable("fk_db_schema_name", VARCHAR.getType()), + Field.notNullable("fk_table_name", VARCHAR.getType()), + Field.notNullable("fk_column_name", VARCHAR.getType()), + Field.notNullable("key_sequence", INT.getType()), + Field.nullable("fk_key_name", VARCHAR.getType()), + Field.nullable("pk_key_name", VARCHAR.getType()), + Field.notNullable("update_rule", MinorType.UINT1.getType()), + Field.notNullable("delete_rule", MinorType.UINT1.getType()))); + public static final Schema GET_IMPORTED_KEYS_SCHEMA = + GET_IMPORTED_EXPORTED_AND_CROSS_REFERENCE_KEYS_SCHEMA; + public static final Schema GET_EXPORTED_KEYS_SCHEMA = + GET_IMPORTED_EXPORTED_AND_CROSS_REFERENCE_KEYS_SCHEMA; + public static final Schema GET_CROSS_REFERENCE_SCHEMA = + GET_IMPORTED_EXPORTED_AND_CROSS_REFERENCE_KEYS_SCHEMA; + private static final List GET_SQL_INFO_DENSE_UNION_SCHEMA_FIELDS = + asList( + Field.notNullable("string_value", VARCHAR.getType()), + Field.notNullable("bool_value", BIT.getType()), + Field.notNullable("bigint_value", BIGINT.getType()), + Field.notNullable("int32_bitmask", INT.getType()), + new Field( + "string_list", + FieldType.notNullable(LIST.getType()), + singletonList(Field.nullable("item", VARCHAR.getType()))), + new Field( + "int32_to_int32_list_map", + FieldType.notNullable(new ArrowType.Map(false)), + singletonList( new Field( - VALUE_NAME, FieldType.nullable(LIST.getType()), - singletonList(Field.nullable("item", INT.getType())))))))); + DATA_VECTOR_NAME, + new FieldType(false, STRUCT.getType(), null), + ImmutableList.of( + Field.notNullable(KEY_NAME, INT.getType()), + new Field( + VALUE_NAME, + FieldType.nullable(LIST.getType()), + singletonList(Field.nullable("item", INT.getType())))))))); public static final Schema GET_SQL_INFO_SCHEMA = - new Schema(asList( - Field.notNullable("info_name", UINT4.getType()), - new Field("value", - FieldType.notNullable( - new Union(UnionMode.Dense, range(0, GET_SQL_INFO_DENSE_UNION_SCHEMA_FIELDS.size()).toArray())), - GET_SQL_INFO_DENSE_UNION_SCHEMA_FIELDS))); + new Schema( + asList( + Field.notNullable("info_name", UINT4.getType()), + new Field( + "value", + FieldType.notNullable( + new Union( + UnionMode.Dense, + range(0, GET_SQL_INFO_DENSE_UNION_SCHEMA_FIELDS.size()).toArray())), + GET_SQL_INFO_DENSE_UNION_SCHEMA_FIELDS))); public static final Schema GET_TYPE_INFO_SCHEMA = - new Schema(asList( - Field.notNullable("type_name", VARCHAR.getType()), - Field.notNullable("data_type", INT.getType()), - Field.nullable("column_size", INT.getType()), - Field.nullable("literal_prefix", VARCHAR.getType()), - Field.nullable("literal_suffix", VARCHAR.getType()), - new Field( - "create_params", FieldType.nullable(LIST.getType()), - singletonList(Field.notNullable("item", VARCHAR.getType()))), - Field.notNullable("nullable", INT.getType()), - Field.notNullable("case_sensitive", BIT.getType()), - Field.notNullable("searchable", INT.getType()), - Field.nullable("unsigned_attribute", BIT.getType()), - Field.notNullable("fixed_prec_scale", BIT.getType()), - Field.nullable("auto_increment", BIT.getType()), - Field.nullable("local_type_name", VARCHAR.getType()), - Field.nullable("minimum_scale", INT.getType()), - Field.nullable("maximum_scale", INT.getType()), - Field.notNullable("sql_data_type", INT.getType()), - Field.nullable("datetime_subcode", INT.getType()), - Field.nullable("num_prec_radix", INT.getType()), - Field.nullable("interval_precision", INT.getType()) - )); + new Schema( + asList( + Field.notNullable("type_name", VARCHAR.getType()), + Field.notNullable("data_type", INT.getType()), + Field.nullable("column_size", INT.getType()), + Field.nullable("literal_prefix", VARCHAR.getType()), + Field.nullable("literal_suffix", VARCHAR.getType()), + new Field( + "create_params", + FieldType.nullable(LIST.getType()), + singletonList(Field.notNullable("item", VARCHAR.getType()))), + Field.notNullable("nullable", INT.getType()), + Field.notNullable("case_sensitive", BIT.getType()), + Field.notNullable("searchable", INT.getType()), + Field.nullable("unsigned_attribute", BIT.getType()), + Field.notNullable("fixed_prec_scale", BIT.getType()), + Field.nullable("auto_increment", BIT.getType()), + Field.nullable("local_type_name", VARCHAR.getType()), + Field.nullable("minimum_scale", INT.getType()), + Field.nullable("maximum_scale", INT.getType()), + Field.notNullable("sql_data_type", INT.getType()), + Field.nullable("datetime_subcode", INT.getType()), + Field.nullable("num_prec_radix", INT.getType()), + Field.nullable("interval_precision", INT.getType()))); public static final Schema GET_PRIMARY_KEYS_SCHEMA = - new Schema(asList( - Field.nullable("catalog_name", VARCHAR.getType()), - Field.nullable("db_schema_name", VARCHAR.getType()), - Field.notNullable("table_name", VARCHAR.getType()), - Field.notNullable("column_name", VARCHAR.getType()), - Field.notNullable("key_sequence", INT.getType()), - Field.nullable("key_name", VARCHAR.getType()))); + new Schema( + asList( + Field.nullable("catalog_name", VARCHAR.getType()), + Field.nullable("db_schema_name", VARCHAR.getType()), + Field.notNullable("table_name", VARCHAR.getType()), + Field.notNullable("column_name", VARCHAR.getType()), + Field.notNullable("key_sequence", INT.getType()), + Field.nullable("key_name", VARCHAR.getType()))); private Schemas() { // Prevent instantiation. diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java index 532921a8ac6..e95caec696a 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlUtils.java @@ -17,69 +17,73 @@ package org.apache.arrow.flight.sql; -import java.util.List; - -import org.apache.arrow.flight.ActionType; -import org.apache.arrow.flight.CallStatus; - import com.google.common.collect.ImmutableList; import com.google.protobuf.Any; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.Message; +import java.util.List; +import org.apache.arrow.flight.ActionType; +import org.apache.arrow.flight.CallStatus; -/** - * Utilities to work with Flight SQL semantics. - */ +/** Utilities to work with Flight SQL semantics. */ public final class FlightSqlUtils { public static final ActionType FLIGHT_SQL_BEGIN_SAVEPOINT = - new ActionType("BeginSavepoint", - "Create a new savepoint.\n" + - "Request Message: ActionBeginSavepointRequest\n" + - "Response Message: ActionBeginSavepointResult"); + new ActionType( + "BeginSavepoint", + "Create a new savepoint.\n" + + "Request Message: ActionBeginSavepointRequest\n" + + "Response Message: ActionBeginSavepointResult"); public static final ActionType FLIGHT_SQL_BEGIN_TRANSACTION = - new ActionType("BeginTransaction", - "Start a new transaction.\n" + - "Request Message: ActionBeginTransactionRequest\n" + - "Response Message: ActionBeginTransactionResult"); - public static final ActionType FLIGHT_SQL_CREATE_PREPARED_STATEMENT = new ActionType("CreatePreparedStatement", - "Creates a reusable prepared statement resource on the server. \n" + - "Request Message: ActionCreatePreparedStatementRequest\n" + - "Response Message: ActionCreatePreparedStatementResult"); + new ActionType( + "BeginTransaction", + "Start a new transaction.\n" + + "Request Message: ActionBeginTransactionRequest\n" + + "Response Message: ActionBeginTransactionResult"); + public static final ActionType FLIGHT_SQL_CREATE_PREPARED_STATEMENT = + new ActionType( + "CreatePreparedStatement", + "Creates a reusable prepared statement resource on the server. \n" + + "Request Message: ActionCreatePreparedStatementRequest\n" + + "Response Message: ActionCreatePreparedStatementResult"); - public static final ActionType FLIGHT_SQL_CLOSE_PREPARED_STATEMENT = new ActionType("ClosePreparedStatement", - "Closes a reusable prepared statement resource on the server. \n" + - "Request Message: ActionClosePreparedStatementRequest\n" + - "Response Message: N/A"); + public static final ActionType FLIGHT_SQL_CLOSE_PREPARED_STATEMENT = + new ActionType( + "ClosePreparedStatement", + "Closes a reusable prepared statement resource on the server. \n" + + "Request Message: ActionClosePreparedStatementRequest\n" + + "Response Message: N/A"); public static final ActionType FLIGHT_SQL_CREATE_PREPARED_SUBSTRAIT_PLAN = - new ActionType("CreatePreparedSubstraitPlan", - "Creates a reusable prepared statement resource on the server.\n" + - "Request Message: ActionCreatePreparedSubstraitPlanRequest\n" + - "Response Message: ActionCreatePreparedStatementResult"); + new ActionType( + "CreatePreparedSubstraitPlan", + "Creates a reusable prepared statement resource on the server.\n" + + "Request Message: ActionCreatePreparedSubstraitPlanRequest\n" + + "Response Message: ActionCreatePreparedStatementResult"); public static final ActionType FLIGHT_SQL_CANCEL_QUERY = - new ActionType("CancelQuery", - "Explicitly cancel a running query.\n" + - "Request Message: ActionCancelQueryRequest\n" + - "Response Message: ActionCancelQueryResult"); + new ActionType( + "CancelQuery", + "Explicitly cancel a running query.\n" + + "Request Message: ActionCancelQueryRequest\n" + + "Response Message: ActionCancelQueryResult"); public static final ActionType FLIGHT_SQL_END_SAVEPOINT = - new ActionType("EndSavepoint", - "End a savepoint.\n" + - "Request Message: ActionEndSavepointRequest\n" + - "Response Message: N/A"); + new ActionType( + "EndSavepoint", + "End a savepoint.\n" + + "Request Message: ActionEndSavepointRequest\n" + + "Response Message: N/A"); public static final ActionType FLIGHT_SQL_END_TRANSACTION = - new ActionType("EndTransaction", - "End a transaction.\n" + - "Request Message: ActionEndTransactionRequest\n" + - "Response Message: N/A"); + new ActionType( + "EndTransaction", + "End a transaction.\n" + + "Request Message: ActionEndTransactionRequest\n" + + "Response Message: N/A"); - public static final List FLIGHT_SQL_ACTIONS = ImmutableList.of( - FLIGHT_SQL_CREATE_PREPARED_STATEMENT, - FLIGHT_SQL_CLOSE_PREPARED_STATEMENT - ); + public static final List FLIGHT_SQL_ACTIONS = + ImmutableList.of(FLIGHT_SQL_CREATE_PREPARED_STATEMENT, FLIGHT_SQL_CLOSE_PREPARED_STATEMENT); /** * Helper to parse {@link com.google.protobuf.Any} objects to the specific protobuf object. @@ -102,8 +106,8 @@ public static Any parseOrThrow(byte[] source) { * Helper to unpack {@link com.google.protobuf.Any} objects to the specific protobuf object. * * @param source the parsed Source value. - * @param as the class to unpack as. - * @param the class to unpack as. + * @param as the class to unpack as. + * @param the class to unpack as. * @return the materialized protobuf object. */ public static T unpackOrThrow(Any source, Class as) { @@ -118,11 +122,12 @@ public static T unpackOrThrow(Any source, Class as) { } /** - * Helper to parse and unpack {@link com.google.protobuf.Any} objects to the specific protobuf object. + * Helper to parse and unpack {@link com.google.protobuf.Any} objects to the specific protobuf + * object. * * @param source the raw bytes source value. - * @param as the class to unpack as. - * @param the class to unpack as. + * @param as the class to unpack as. + * @param the class to unpack as. * @return the materialized protobuf object. */ public static T unpackAndParseOrThrow(byte[] source, Class as) { diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/NoOpFlightSqlProducer.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/NoOpFlightSqlProducer.java index a02cee64bd8..64bae109f78 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/NoOpFlightSqlProducer.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/NoOpFlightSqlProducer.java @@ -27,195 +27,233 @@ import org.apache.arrow.flight.SchemaResult; import org.apache.arrow.flight.sql.impl.FlightSql; -/** - * A {@link FlightSqlProducer} that throws on all FlightSql-specific operations. - */ +/** A {@link FlightSqlProducer} that throws on all FlightSql-specific operations. */ public class NoOpFlightSqlProducer implements FlightSqlProducer { @Override - public void createPreparedStatement(FlightSql.ActionCreatePreparedStatementRequest request, - CallContext context, StreamListener listener) { - listener.onError(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void createPreparedStatement( + FlightSql.ActionCreatePreparedStatementRequest request, + CallContext context, + StreamListener listener) { + listener.onError( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public void closePreparedStatement(FlightSql.ActionClosePreparedStatementRequest request, - CallContext context, StreamListener listener) { - listener.onError(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void closePreparedStatement( + FlightSql.ActionClosePreparedStatementRequest request, + CallContext context, + StreamListener listener) { + listener.onError( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public FlightInfo getFlightInfoStatement(FlightSql.CommandStatementQuery command, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoStatement( + FlightSql.CommandStatementQuery command, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public FlightInfo getFlightInfoPreparedStatement(FlightSql.CommandPreparedStatementQuery command, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoPreparedStatement( + FlightSql.CommandPreparedStatementQuery command, + CallContext context, + FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public SchemaResult getSchemaStatement(FlightSql.CommandStatementQuery command, - CallContext context, FlightDescriptor descriptor) { + public SchemaResult getSchemaStatement( + FlightSql.CommandStatementQuery command, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public void getStreamStatement(FlightSql.TicketStatementQuery ticket, - CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamStatement( + FlightSql.TicketStatementQuery ticket, CallContext context, ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public void getStreamPreparedStatement(FlightSql.CommandPreparedStatementQuery command, - CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamPreparedStatement( + FlightSql.CommandPreparedStatementQuery command, + CallContext context, + ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public Runnable acceptPutStatement(FlightSql.CommandStatementUpdate command, CallContext context, - FlightStream flightStream, StreamListener ackStream) { + public Runnable acceptPutStatement( + FlightSql.CommandStatementUpdate command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public Runnable acceptPutPreparedStatementUpdate(FlightSql.CommandPreparedStatementUpdate command, - CallContext context, FlightStream flightStream, - StreamListener ackStream) { + public Runnable acceptPutPreparedStatementUpdate( + FlightSql.CommandPreparedStatementUpdate command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public Runnable acceptPutPreparedStatementQuery(FlightSql.CommandPreparedStatementQuery command, CallContext context, - FlightStream flightStream, StreamListener ackStream) { + public Runnable acceptPutPreparedStatementQuery( + FlightSql.CommandPreparedStatementQuery command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public FlightInfo getFlightInfoSqlInfo(FlightSql.CommandGetSqlInfo request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoSqlInfo( + FlightSql.CommandGetSqlInfo request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public void getStreamSqlInfo(FlightSql.CommandGetSqlInfo command, CallContext context, - ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamSqlInfo( + FlightSql.CommandGetSqlInfo command, CallContext context, ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public FlightInfo getFlightInfoTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTypeInfo( + FlightSql.CommandGetXdbcTypeInfo request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public void getStreamTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, - CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamTypeInfo( + FlightSql.CommandGetXdbcTypeInfo request, + CallContext context, + ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public FlightInfo getFlightInfoCatalogs(FlightSql.CommandGetCatalogs request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoCatalogs( + FlightSql.CommandGetCatalogs request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override public void getStreamCatalogs(CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public FlightInfo getFlightInfoSchemas(FlightSql.CommandGetDbSchemas request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoSchemas( + FlightSql.CommandGetDbSchemas request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public void getStreamSchemas(FlightSql.CommandGetDbSchemas command, - CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamSchemas( + FlightSql.CommandGetDbSchemas command, CallContext context, ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public FlightInfo getFlightInfoTables(FlightSql.CommandGetTables request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTables( + FlightSql.CommandGetTables request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public void getStreamTables(FlightSql.CommandGetTables command, CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamTables( + FlightSql.CommandGetTables command, CallContext context, ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public FlightInfo getFlightInfoTableTypes(FlightSql.CommandGetTableTypes request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTableTypes( + FlightSql.CommandGetTableTypes request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override public void getStreamTableTypes(CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public FlightInfo getFlightInfoPrimaryKeys(FlightSql.CommandGetPrimaryKeys request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoPrimaryKeys( + FlightSql.CommandGetPrimaryKeys request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public void getStreamPrimaryKeys(FlightSql.CommandGetPrimaryKeys command, - CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamPrimaryKeys( + FlightSql.CommandGetPrimaryKeys command, CallContext context, ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public FlightInfo getFlightInfoExportedKeys(FlightSql.CommandGetExportedKeys request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoExportedKeys( + FlightSql.CommandGetExportedKeys request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public FlightInfo getFlightInfoImportedKeys(FlightSql.CommandGetImportedKeys request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoImportedKeys( + FlightSql.CommandGetImportedKeys request, CallContext context, FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public FlightInfo getFlightInfoCrossReference(FlightSql.CommandGetCrossReference request, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoCrossReference( + FlightSql.CommandGetCrossReference request, + CallContext context, + FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public void getStreamExportedKeys(FlightSql.CommandGetExportedKeys command, - CallContext context, ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamExportedKeys( + FlightSql.CommandGetExportedKeys command, + CallContext context, + ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public void getStreamImportedKeys(FlightSql.CommandGetImportedKeys command, CallContext context, - ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamImportedKeys( + FlightSql.CommandGetImportedKeys command, + CallContext context, + ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public void getStreamCrossReference(FlightSql.CommandGetCrossReference command, CallContext context, - ServerStreamListener listener) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + public void getStreamCrossReference( + FlightSql.CommandGetCrossReference command, + CallContext context, + ServerStreamListener listener) { + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } @Override - public void close() throws Exception { - - } + public void close() throws Exception {} @Override - public void listFlights(CallContext context, Criteria criteria, StreamListener listener) { + public void listFlights( + CallContext context, Criteria criteria, StreamListener listener) { throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } } diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/ProtoListener.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/ProtoListener.java index fd5fd048962..0323f243b1d 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/ProtoListener.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/ProtoListener.java @@ -17,11 +17,10 @@ package org.apache.arrow.flight.sql; -import org.apache.arrow.flight.FlightProducer; -import org.apache.arrow.flight.Result; - import com.google.protobuf.Any; import com.google.protobuf.Message; +import org.apache.arrow.flight.FlightProducer; +import org.apache.arrow.flight.Result; /** * A StreamListener that accepts a particular type. diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/SqlInfoBuilder.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/SqlInfoBuilder.java index 251a709f639..ab06d9be113 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/SqlInfoBuilder.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/SqlInfoBuilder.java @@ -23,6 +23,7 @@ import static org.apache.arrow.flight.sql.impl.FlightSql.SqlSupportedTransaction; import static org.apache.arrow.flight.sql.util.SqlInfoOptionsUtils.createBitmaskFromEnums; +import com.google.protobuf.ProtocolMessageEnum; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; @@ -30,7 +31,6 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.ObjIntConsumer; - import org.apache.arrow.flight.sql.impl.FlightSql.SqlInfo; import org.apache.arrow.flight.sql.impl.FlightSql.SqlNullOrdering; import org.apache.arrow.flight.sql.impl.FlightSql.SqlOuterJoinsSupportLevel; @@ -60,24 +60,24 @@ import org.apache.arrow.vector.holders.NullableIntHolder; import org.apache.arrow.vector.holders.NullableVarCharHolder; -import com.google.protobuf.ProtocolMessageEnum; - /** - * Auxiliary class meant to facilitate the implementation of {@link FlightSqlProducer#getStreamSqlInfo}. - *

- * Usage requires the user to add the required SqlInfo values using the {@code with*} methods - * like {@link SqlInfoBuilder#withFlightSqlServerName(String)}, and request it back - * through the {@link SqlInfoBuilder#send(List, ServerStreamListener)} method. + * Auxiliary class meant to facilitate the implementation of {@link + * FlightSqlProducer#getStreamSqlInfo}. + * + *

Usage requires the user to add the required SqlInfo values using the {@code with*} methods + * like {@link SqlInfoBuilder#withFlightSqlServerName(String)}, and request it back through the + * {@link SqlInfoBuilder#send(List, ServerStreamListener)} method. */ @SuppressWarnings({"unused"}) public class SqlInfoBuilder { private final Map> providers = new HashMap<>(); /** - * Gets a {@link NullableVarCharHolder} from the provided {@code string} using the provided {@code buf}. + * Gets a {@link NullableVarCharHolder} from the provided {@code string} using the provided {@code + * buf}. * * @param string the {@link StandardCharsets#UTF_8}-encoded text input to store onto the holder. - * @param buf the {@link ArrowBuf} from which to create the new holder. + * @param buf the {@link ArrowBuf} from which to create the new holder. * @return a new {@link NullableVarCharHolder} with the provided input data {@code string}. */ public static NullableVarCharHolder getHolderForUtf8(final String string, final ArrowBuf buf) { @@ -293,7 +293,8 @@ public SqlInfoBuilder withSqlSupportsTableCorrelationNames(final boolean value) /** * Sets a value for {@link SqlInfo#SQL_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES} in the builder. * - * @param value the value for {@link SqlInfo#SQL_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES} to be set. + * @param value the value for {@link SqlInfo#SQL_SUPPORTS_DIFFERENT_TABLE_CORRELATION_NAMES} to be + * set. * @return the SqlInfoBuilder itself. */ public SqlInfoBuilder withSqlSupportsDifferentTableCorrelationNames(final boolean value) { @@ -343,7 +344,8 @@ public SqlInfoBuilder withSqlSupportsNonNullableColumns(final boolean value) { /** * Sets a value for {@link SqlInfo#SQL_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY} in the builder. * - * @param value the value for {@link SqlInfo#SQL_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY} to be set. + * @param value the value for {@link SqlInfo#SQL_SUPPORTS_INTEGRITY_ENHANCEMENT_FACILITY} to be + * set. * @return the SqlInfoBuilder itself. */ public SqlInfoBuilder withSqlSupportsIntegrityEnhancementFacility(final boolean value) { @@ -413,23 +415,23 @@ public SqlInfoBuilder withSqlTransactionsSupported(final boolean value) { /** * Sets a value for {@link SqlInfo#SQL_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT} in the builder. * - * @param value the value for {@link SqlInfo#SQL_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT} to be set. + * @param value the value for {@link SqlInfo#SQL_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT} to be + * set. * @return the SqlInfoBuilder itself. */ public SqlInfoBuilder withSqlDataDefinitionCausesTransactionCommit(final boolean value) { - return withBooleanProvider(SqlInfo.SQL_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT_VALUE, - value); + return withBooleanProvider(SqlInfo.SQL_DATA_DEFINITION_CAUSES_TRANSACTION_COMMIT_VALUE, value); } /** * Sets a value for {@link SqlInfo#SQL_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED} in the builder. * - * @param value the value for {@link SqlInfo#SQL_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED} to be set. + * @param value the value for {@link SqlInfo#SQL_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED} to be + * set. * @return the SqlInfoBuilder itself. */ public SqlInfoBuilder withSqlDataDefinitionsInTransactionsIgnored(final boolean value) { - return withBooleanProvider(SqlInfo.SQL_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED_VALUE, - value); + return withBooleanProvider(SqlInfo.SQL_DATA_DEFINITIONS_IN_TRANSACTIONS_IGNORED_VALUE, value); } /** @@ -473,14 +475,16 @@ public SqlInfoBuilder withSqlLocatorsUpdateCopy(final boolean value) { } /** - * Sets a value for {@link SqlInfo#SQL_STORED_FUNCTIONS_USING_CALL_SYNTAX_SUPPORTED} in the builder. + * Sets a value for {@link SqlInfo#SQL_STORED_FUNCTIONS_USING_CALL_SYNTAX_SUPPORTED} in the + * builder. * - * @param value the value for {@link SqlInfo#SQL_STORED_FUNCTIONS_USING_CALL_SYNTAX_SUPPORTED} to be set. + * @param value the value for {@link SqlInfo#SQL_STORED_FUNCTIONS_USING_CALL_SYNTAX_SUPPORTED} to + * be set. * @return the SqlInfoBuilder itself. */ public SqlInfoBuilder withSqlStoredFunctionsUsingCallSyntaxSupported(final boolean value) { - return withBooleanProvider(SqlInfo.SQL_STORED_FUNCTIONS_USING_CALL_SYNTAX_SUPPORTED_VALUE, - value); + return withBooleanProvider( + SqlInfo.SQL_STORED_FUNCTIONS_USING_CALL_SYNTAX_SUPPORTED_VALUE, value); } /** @@ -759,7 +763,8 @@ public SqlInfoBuilder withSqlSupportedGrammar(final SupportedSqlGrammar... value * @param values the value for {@link SqlInfo#SQL_ANSI92_SUPPORTED_LEVEL} to be set. * @return the SqlInfoBuilder itself. */ - public SqlInfoBuilder withSqlAnsi92SupportedLevel(final SupportedAnsi92SqlGrammarLevel... values) { + public SqlInfoBuilder withSqlAnsi92SupportedLevel( + final SupportedAnsi92SqlGrammarLevel... values) { return withEnumProvider(SqlInfo.SQL_ANSI92_SUPPORTED_LEVEL_VALUE, values); } @@ -779,7 +784,8 @@ public SqlInfoBuilder withSqlSchemasSupportedActions(final SqlSupportedElementAc * @param values the value for {@link SqlInfo#SQL_CATALOGS_SUPPORTED_ACTIONS} to be set. * @return the SqlInfoBuilder itself. */ - public SqlInfoBuilder withSqlCatalogsSupportedActions(final SqlSupportedElementActions... values) { + public SqlInfoBuilder withSqlCatalogsSupportedActions( + final SqlSupportedElementActions... values) { return withEnumProvider(SqlInfo.SQL_CATALOGS_SUPPORTED_ACTIONS_VALUE, values); } @@ -789,7 +795,8 @@ public SqlInfoBuilder withSqlCatalogsSupportedActions(final SqlSupportedElementA * @param values the value for {@link SqlInfo#SQL_SUPPORTED_POSITIONED_COMMANDS} to be set. * @return the SqlInfoBuilder itself. */ - public SqlInfoBuilder withSqlSupportedPositionedCommands(final SqlSupportedPositionedCommands... values) { + public SqlInfoBuilder withSqlSupportedPositionedCommands( + final SqlSupportedPositionedCommands... values) { return withEnumProvider(SqlInfo.SQL_SUPPORTED_POSITIONED_COMMANDS_VALUE, values); } @@ -826,10 +833,12 @@ public SqlInfoBuilder withSqlOuterJoinSupportLevel(final SqlOuterJoinsSupportLev /** * Sets a value for {@link SqlInfo#SQL_SUPPORTED_TRANSACTIONS_ISOLATION_LEVELS} in the builder. * - * @param values the values for {@link SqlInfo#SQL_SUPPORTED_TRANSACTIONS_ISOLATION_LEVELS} to be set. + * @param values the values for {@link SqlInfo#SQL_SUPPORTED_TRANSACTIONS_ISOLATION_LEVELS} to be + * set. * @return the SqlInfoBuilder itself. */ - public SqlInfoBuilder withSqlSupportedTransactionsIsolationLevels(final SqlTransactionIsolationLevel... values) { + public SqlInfoBuilder withSqlSupportedTransactionsIsolationLevels( + final SqlTransactionIsolationLevel... values) { return withEnumProvider(SqlInfo.SQL_SUPPORTED_TRANSACTIONS_ISOLATION_LEVELS_VALUE, values); } @@ -840,8 +849,7 @@ public SqlInfoBuilder withSqlSupportedTransactionsIsolationLevels(final SqlTrans * @return the SqlInfoBuilder itself. */ public SqlInfoBuilder withSqlSupportedResultSetTypes(final SqlSupportedResultSetType... values) { - return withEnumProvider(SqlInfo.SQL_SUPPORTED_RESULT_SET_TYPES_VALUE, values - ); + return withEnumProvider(SqlInfo.SQL_SUPPORTED_RESULT_SET_TYPES_VALUE, values); } /** @@ -922,8 +930,7 @@ private SqlInfoBuilder withBitIntProvider(final int sqlInfo, final long value) { return this; } - private SqlInfoBuilder withBooleanProvider(final int sqlInfo, - final boolean value) { + private SqlInfoBuilder withBooleanProvider(final int sqlInfo, final boolean value) { addProvider(sqlInfo, (root, index) -> setDataForBooleanField(root, index, sqlInfo, value)); return this; } @@ -933,14 +940,13 @@ private SqlInfoBuilder withStringProvider(final int sqlInfo, final String value) return this; } - private SqlInfoBuilder withStringArrayProvider(final int sqlInfo, - final String[] value) { + private SqlInfoBuilder withStringArrayProvider(final int sqlInfo, final String[] value) { addProvider(sqlInfo, (root, index) -> setDataVarCharListField(root, index, sqlInfo, value)); return this; } - private SqlInfoBuilder withIntToIntListMapProvider(final int sqlInfo, - final Map> value) { + private SqlInfoBuilder withIntToIntListMapProvider( + final int sqlInfo, final Map> value) { addProvider(sqlInfo, (root, index) -> setIntToIntListMapField(root, index, sqlInfo, value)); return this; } @@ -948,7 +954,7 @@ private SqlInfoBuilder withIntToIntListMapProvider(final int sqlInfo, /** * Send the requested information to given ServerStreamListener. * - * @param infos List of SqlInfo to be sent. + * @param infos List of SqlInfo to be sent. * @param listener ServerStreamListener to send data to. */ public void send(List infos, final ServerStreamListener listener) { @@ -956,9 +962,8 @@ public void send(List infos, final ServerStreamListener listener) { infos = new ArrayList<>(providers.keySet()); } try (final BufferAllocator allocator = new RootAllocator(); - final VectorSchemaRoot root = VectorSchemaRoot.create( - FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA, - allocator)) { + final VectorSchemaRoot root = + VectorSchemaRoot.create(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA, allocator)) { final int rows = infos.size(); for (int i = 0; i < rows; i++) { providers.get(infos.get(i)).accept(root, i); @@ -978,8 +983,11 @@ private void setInfoName(final VectorSchemaRoot root, final int index, final int infoName.setSafe(index, info); } - private void setValues(final VectorSchemaRoot root, final int index, final byte typeId, - final Consumer dataSetter) { + private void setValues( + final VectorSchemaRoot root, + final int index, + final byte typeId, + final Consumer dataSetter) { final DenseUnionVector values = (DenseUnionVector) root.getVector("value"); values.setTypeId(index, typeId); dataSetter.accept(values); @@ -992,23 +1000,24 @@ private void setValues(final VectorSchemaRoot root, final int index, final byte */ private void onCreateArrowBuf(final Consumer executor) { try (final BufferAllocator allocator = new RootAllocator(); - final ArrowBuf buf = allocator.buffer(1024)) { + final ArrowBuf buf = allocator.buffer(1024)) { executor.accept(buf); } } - private void setDataForUtf8Field(final VectorSchemaRoot root, final int index, - final int sqlInfo, final String value) { + private void setDataForUtf8Field( + final VectorSchemaRoot root, final int index, final int sqlInfo, final String value) { setInfoName(root, index, sqlInfo); - onCreateArrowBuf(buf -> { - final Consumer producer = - values -> values.setSafe(index, getHolderForUtf8(value, buf)); - setValues(root, index, (byte) 0, producer); - }); + onCreateArrowBuf( + buf -> { + final Consumer producer = + values -> values.setSafe(index, getHolderForUtf8(value, buf)); + setValues(root, index, (byte) 0, producer); + }); } - private void setDataForIntField(final VectorSchemaRoot root, final int index, - final int sqlInfo, final int value) { + private void setDataForIntField( + final VectorSchemaRoot root, final int index, final int sqlInfo, final int value) { setInfoName(root, index, sqlInfo); final NullableIntHolder dataHolder = new NullableIntHolder(); dataHolder.isSet = 1; @@ -1016,8 +1025,8 @@ private void setDataForIntField(final VectorSchemaRoot root, final int index, setValues(root, index, (byte) 3, values -> values.setSafe(index, dataHolder)); } - private void setDataForBigIntField(final VectorSchemaRoot root, final int index, - final int sqlInfo, final long value) { + private void setDataForBigIntField( + final VectorSchemaRoot root, final int index, final int sqlInfo, final long value) { setInfoName(root, index, sqlInfo); final NullableBigIntHolder dataHolder = new NullableBigIntHolder(); dataHolder.isSet = 1; @@ -1025,8 +1034,8 @@ private void setDataForBigIntField(final VectorSchemaRoot root, final int index, setValues(root, index, (byte) 2, values -> values.setSafe(index, dataHolder)); } - private void setDataForBooleanField(final VectorSchemaRoot root, final int index, - final int sqlInfo, final boolean value) { + private void setDataForBooleanField( + final VectorSchemaRoot root, final int index, final int sqlInfo, final boolean value) { setInfoName(root, index, sqlInfo); final NullableBitHolder dataHolder = new NullableBitHolder(); dataHolder.isSet = 1; @@ -1034,9 +1043,8 @@ private void setDataForBooleanField(final VectorSchemaRoot root, final int index setValues(root, index, (byte) 1, values -> values.setSafe(index, dataHolder)); } - private void setDataVarCharListField(final VectorSchemaRoot root, final int index, - final int sqlInfo, - final String[] values) { + private void setDataVarCharListField( + final VectorSchemaRoot root, final int index, final int sqlInfo, final String[] values) { final DenseUnionVector denseUnion = (DenseUnionVector) root.getVector("value"); final ListVector listVector = denseUnion.getList((byte) 4); final int listIndex = listVector.getValueCount(); @@ -1050,11 +1058,14 @@ private void setDataVarCharListField(final VectorSchemaRoot root, final int inde writer.startList(); final int length = values.length; range(0, length) - .forEach(i -> onCreateArrowBuf(buf -> { - final byte[] bytes = values[i].getBytes(UTF_8); - buf.setBytes(0, bytes); - writer.writeVarChar(0, bytes.length, buf); - })); + .forEach( + i -> + onCreateArrowBuf( + buf -> { + final byte[] bytes = values[i].getBytes(UTF_8); + buf.setBytes(0, bytes); + writer.writeVarChar(0, bytes.length, buf); + })); writer.endList(); writer.setValueCount(listVectorValueCount); @@ -1063,9 +1074,11 @@ private void setDataVarCharListField(final VectorSchemaRoot root, final int inde setInfoName(root, index, sqlInfo); } - private void setIntToIntListMapField(final VectorSchemaRoot root, final int index, - final int sqlInfo, - final Map> values) { + private void setIntToIntListMapField( + final VectorSchemaRoot root, + final int index, + final int sqlInfo, + final Map> values) { final DenseUnionVector denseUnion = (DenseUnionVector) root.getVector("value"); final MapVector mapVector = denseUnion.getMap((byte) 5); final int mapIndex = mapVector.getValueCount(); @@ -1075,17 +1088,18 @@ private void setIntToIntListMapField(final VectorSchemaRoot root, final int inde final UnionMapWriter mapWriter = mapVector.getWriter(); mapWriter.setPosition(mapIndex); mapWriter.startMap(); - values.forEach((key, value) -> { - mapWriter.startEntry(); - mapWriter.key().integer().writeInt(key); - final BaseWriter.ListWriter listWriter = mapWriter.value().list(); - listWriter.startList(); - for (final int v : value) { - listWriter.integer().writeInt(v); - } - listWriter.endList(); - mapWriter.endEntry(); - }); + values.forEach( + (key, value) -> { + mapWriter.startEntry(); + mapWriter.key().integer().writeInt(key); + final BaseWriter.ListWriter listWriter = mapWriter.value().list(); + listWriter.startList(); + for (final int v : value) { + listWriter.integer().writeInt(v); + } + listWriter.endList(); + mapWriter.endEntry(); + }); mapWriter.endMap(); mapWriter.setValueCount(mapIndex + 1); diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/example/FlightSqlClientDemoApp.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/example/FlightSqlClientDemoApp.java index 4d3241c7c37..20bd8462cda 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/example/FlightSqlClientDemoApp.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/example/FlightSqlClientDemoApp.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; - import org.apache.arrow.flight.CallOption; import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightInfo; @@ -37,9 +36,7 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -/** - * Flight SQL Client Demo CLI Application. - */ +/** Flight SQL Client Demo CLI Application. */ public class FlightSqlClientDemoApp implements AutoCloseable { public final List callOptions = new ArrayList<>(); public final BufferAllocator allocator; @@ -67,7 +64,8 @@ public static void main(final String[] args) throws Exception { try { cmd = parser.parse(options, args); - try (final FlightSqlClientDemoApp thisApp = new FlightSqlClientDemoApp(new RootAllocator(Integer.MAX_VALUE))) { + try (final FlightSqlClientDemoApp thisApp = + new FlightSqlClientDemoApp(new RootAllocator(Integer.MAX_VALUE))) { thisApp.executeApp(cmd); } @@ -79,8 +77,8 @@ public static void main(final String[] args) throws Exception { } /** - * Gets the current {@link CallOption} as an array; usually used as an - * argument in {@link FlightSqlClient} methods. + * Gets the current {@link CallOption} as an array; usually used as an argument in {@link + * FlightSqlClient} methods. * * @return current {@link CallOption} array. */ @@ -89,12 +87,12 @@ public CallOption[] getCallOptions() { } /** - * Calls {@link FlightSqlClientDemoApp#createFlightSqlClient(String, int)} - * in order to create a {@link FlightSqlClient} to be used in future calls, - * and then calls {@link FlightSqlClientDemoApp#executeCommand(CommandLine)} - * to execute the command parsed at execution. + * Calls {@link FlightSqlClientDemoApp#createFlightSqlClient(String, int)} in order to create a + * {@link FlightSqlClient} to be used in future calls, and then calls {@link + * FlightSqlClientDemoApp#executeCommand(CommandLine)} to execute the command parsed at execution. * - * @param cmd parsed {@link CommandLine}; often the result of {@link DefaultParser#parse(Options, String[])}. + * @param cmd parsed {@link CommandLine}; often the result of {@link DefaultParser#parse(Options, + * String[])}. */ public void executeApp(final CommandLine cmd) throws Exception { final String host = cmd.getOptionValue("host").trim(); @@ -107,29 +105,22 @@ public void executeApp(final CommandLine cmd) throws Exception { /** * Parses the "{@code command}" CLI argument and redirects to the appropriate method. * - * @param cmd parsed {@link CommandLine}; often the result of - * {@link DefaultParser#parse(Options, String[])}. + * @param cmd parsed {@link CommandLine}; often the result of {@link DefaultParser#parse(Options, + * String[])}. */ public void executeCommand(CommandLine cmd) throws Exception { switch (cmd.getOptionValue("command").trim()) { case "Execute": - exampleExecute( - cmd.getOptionValue("query") - ); + exampleExecute(cmd.getOptionValue("query")); break; case "ExecuteUpdate": - exampleExecuteUpdate( - cmd.getOptionValue("query") - ); + exampleExecuteUpdate(cmd.getOptionValue("query")); break; case "GetCatalogs": exampleGetCatalogs(); break; case "GetSchemas": - exampleGetSchemas( - cmd.getOptionValue("catalog"), - cmd.getOptionValue("schema") - ); + exampleGetSchemas(cmd.getOptionValue("catalog"), cmd.getOptionValue("schema")); break; case "GetTableTypes": exampleGetTableTypes(); @@ -138,41 +129,38 @@ public void executeCommand(CommandLine cmd) throws Exception { exampleGetTables( cmd.getOptionValue("catalog"), cmd.getOptionValue("schema"), - cmd.getOptionValue("table") - ); + cmd.getOptionValue("table")); break; case "GetExportedKeys": exampleGetExportedKeys( cmd.getOptionValue("catalog"), cmd.getOptionValue("schema"), - cmd.getOptionValue("table") - ); + cmd.getOptionValue("table")); break; case "GetImportedKeys": exampleGetImportedKeys( cmd.getOptionValue("catalog"), cmd.getOptionValue("schema"), - cmd.getOptionValue("table") - ); + cmd.getOptionValue("table")); break; case "GetPrimaryKeys": exampleGetPrimaryKeys( cmd.getOptionValue("catalog"), cmd.getOptionValue("schema"), - cmd.getOptionValue("table") - ); + cmd.getOptionValue("table")); break; default: - System.out.println("Command used is not valid! Please use one of: \n" + - "[\"ExecuteUpdate\",\n" + - "\"Execute\",\n" + - "\"GetCatalogs\",\n" + - "\"GetSchemas\",\n" + - "\"GetTableTypes\",\n" + - "\"GetTables\",\n" + - "\"GetExportedKeys\",\n" + - "\"GetImportedKeys\",\n" + - "\"GetPrimaryKeys\"]"); + System.out.println( + "Command used is not valid! Please use one of: \n" + + "[\"ExecuteUpdate\",\n" + + "\"Execute\",\n" + + "\"GetCatalogs\",\n" + + "\"GetSchemas\",\n" + + "\"GetTableTypes\",\n" + + "\"GetTables\",\n" + + "\"GetExportedKeys\",\n" + + "\"GetImportedKeys\",\n" + + "\"GetPrimaryKeys\"]"); } } @@ -192,7 +180,8 @@ private void exampleExecute(final String query) throws Exception { } private void exampleExecuteUpdate(final String query) { - System.out.println("Updated: " + flightSqlClient.executeUpdate(query, getCallOptions()) + "rows."); + System.out.println( + "Updated: " + flightSqlClient.executeUpdate(query, getCallOptions()) + "rows."); } private void exampleGetCatalogs() throws Exception { @@ -207,22 +196,29 @@ private void exampleGetTableTypes() throws Exception { printFlightInfoResults(flightSqlClient.getTableTypes(getCallOptions())); } - private void exampleGetTables(final String catalog, final String schema, final String table) throws Exception { + private void exampleGetTables(final String catalog, final String schema, final String table) + throws Exception { // For now, this won't filter by table types. - printFlightInfoResults(flightSqlClient.getTables( - catalog, schema, table, null, false, getCallOptions())); + printFlightInfoResults( + flightSqlClient.getTables(catalog, schema, table, null, false, getCallOptions())); } - private void exampleGetExportedKeys(final String catalog, final String schema, final String table) throws Exception { - printFlightInfoResults(flightSqlClient.getExportedKeys(TableRef.of(catalog, schema, table), getCallOptions())); + private void exampleGetExportedKeys(final String catalog, final String schema, final String table) + throws Exception { + printFlightInfoResults( + flightSqlClient.getExportedKeys(TableRef.of(catalog, schema, table), getCallOptions())); } - private void exampleGetImportedKeys(final String catalog, final String schema, final String table) throws Exception { - printFlightInfoResults(flightSqlClient.getImportedKeys(TableRef.of(catalog, schema, table), getCallOptions())); + private void exampleGetImportedKeys(final String catalog, final String schema, final String table) + throws Exception { + printFlightInfoResults( + flightSqlClient.getImportedKeys(TableRef.of(catalog, schema, table), getCallOptions())); } - private void exampleGetPrimaryKeys(final String catalog, final String schema, final String table) throws Exception { - printFlightInfoResults(flightSqlClient.getPrimaryKeys(TableRef.of(catalog, schema, table), getCallOptions())); + private void exampleGetPrimaryKeys(final String catalog, final String schema, final String table) + throws Exception { + printFlightInfoResults( + flightSqlClient.getPrimaryKeys(TableRef.of(catalog, schema, table), getCallOptions())); } private void printFlightInfoResults(final FlightInfo flightInfo) throws Exception { diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtils.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtils.java index c43c48eb8e0..223e9bad54f 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtils.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtils.java @@ -17,31 +17,29 @@ package org.apache.arrow.flight.sql.util; +import com.google.protobuf.ProtocolMessageEnum; import java.util.Arrays; import java.util.Collection; - import org.apache.arrow.flight.sql.FlightSqlClient; import org.apache.arrow.flight.sql.impl.FlightSql.SqlInfo; -import com.google.protobuf.ProtocolMessageEnum; - -/** - * Utility class for {@link SqlInfo} and {@link FlightSqlClient#getSqlInfo} option parsing. - */ +/** Utility class for {@link SqlInfo} and {@link FlightSqlClient#getSqlInfo} option parsing. */ public final class SqlInfoOptionsUtils { private SqlInfoOptionsUtils() { // Prevent instantiation. } /** - * Returns whether the provided {@code bitmask} points to the provided {@link ProtocolMessageEnum} by comparing - * {@link ProtocolMessageEnum#getNumber} with the respective bit index of the {@code bitmask}. + * Returns whether the provided {@code bitmask} points to the provided {@link ProtocolMessageEnum} + * by comparing {@link ProtocolMessageEnum#getNumber} with the respective bit index of the {@code + * bitmask}. * * @param enumInstance the protobuf message enum to use. - * @param bitmask the bitmask response from {@link FlightSqlClient#getSqlInfo}. + * @param bitmask the bitmask response from {@link FlightSqlClient#getSqlInfo}. * @return whether the provided {@code bitmask} points to the specified {@code enumInstance}. */ - public static boolean doesBitmaskTranslateToEnum(final ProtocolMessageEnum enumInstance, final long bitmask) { + public static boolean doesBitmaskTranslateToEnum( + final ProtocolMessageEnum enumInstance, final long bitmask) { return ((bitmask >> enumInstance.getNumber()) & 1) == 1; } diff --git a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/util/TableRef.java b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/util/TableRef.java index b3751cab903..f4e97a5317e 100644 --- a/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/util/TableRef.java +++ b/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/util/TableRef.java @@ -17,10 +17,7 @@ package org.apache.arrow.flight.sql.util; -/** - * A helper class to reference a table to be passed to the flight - * sql client. - */ +/** A helper class to reference a table to be passed to the flight sql client. */ public class TableRef { private final String catalog; private final String dbSchema; @@ -28,9 +25,10 @@ public class TableRef { /** * The complete constructor for the TableRef class. - * @param catalog the catalog from a table. - * @param dbSchema the database schema from a table. - * @param table the table name from a table. + * + * @param catalog the catalog from a table. + * @param dbSchema the database schema from a table. + * @param table the table name from a table. */ public TableRef(String catalog, String dbSchema, String table) { this.catalog = catalog; @@ -40,10 +38,11 @@ public TableRef(String catalog, String dbSchema, String table) { /** * A static initializer of the TableRef with all the arguments. - * @param catalog the catalog from a table. - * @param dbSchema the database schema from a table. - * @param table the table name from a table. - * @return A TableRef object. + * + * @param catalog the catalog from a table. + * @param dbSchema the database schema from a table. + * @param table the table name from a table. + * @return A TableRef object. */ public static TableRef of(String catalog, String dbSchema, String table) { return new TableRef(catalog, dbSchema, table); @@ -51,7 +50,8 @@ public static TableRef of(String catalog, String dbSchema, String table) { /** * Retrieve the catalog from the object. - * @return the catalog. + * + * @return the catalog. */ public String getCatalog() { return catalog; @@ -59,7 +59,8 @@ public String getCatalog() { /** * Retrieves the db schema from the object. - * @return the dbSchema + * + * @return the dbSchema */ public String getDbSchema() { return dbSchema; @@ -67,10 +68,10 @@ public String getDbSchema() { /** * Retrieves the table from the object. - * @return the table. + * + * @return the table. */ public String getTable() { return table; } } - diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java index 11f38ded5fc..31fca3d3938 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java @@ -38,6 +38,15 @@ import static org.apache.arrow.util.Preconditions.checkState; import static org.slf4j.LoggerFactory.getLogger; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.protobuf.ByteString; +import com.google.protobuf.Message; +import com.google.protobuf.ProtocolStringList; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -74,7 +83,6 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Stream; - import org.apache.arrow.adapter.jdbc.ArrowVectorIterator; import org.apache.arrow.adapter.jdbc.JdbcFieldInfo; import org.apache.arrow.adapter.jdbc.JdbcParameterBinder; @@ -140,19 +148,9 @@ import org.apache.commons.pool2.impl.GenericObjectPool; import org.slf4j.Logger; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalNotification; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.protobuf.ByteString; -import com.google.protobuf.Message; -import com.google.protobuf.ProtocolStringList; - /** - * Example {@link FlightSqlProducer} implementation showing an Apache Derby backed Flight SQL server that generally - * supports all current features of Flight SQL. + * Example {@link FlightSqlProducer} implementation showing an Apache Derby backed Flight SQL server + * that generally supports all current features of Flight SQL. */ public class FlightSqlExample implements FlightSqlProducer, AutoCloseable { private static final String DATABASE_URI = "jdbc:derby:target/derbyDB"; @@ -163,7 +161,8 @@ public class FlightSqlExample implements FlightSqlProducer, AutoCloseable { private final Location location; private final PoolingDataSource dataSource; private final BufferAllocator rootAllocator = new RootAllocator(); - private final Cache> preparedStatementLoadingCache; + private final Cache> + preparedStatementLoadingCache; private final Cache> statementLoadingCache; private final SqlInfoBuilder sqlInfoBuilder; @@ -172,7 +171,8 @@ public static void main(String[] args) throws Exception { final FlightSqlExample example = new FlightSqlExample(location); Location listenLocation = Location.forGrpcInsecure("0.0.0.0", 55555); try (final BufferAllocator allocator = new RootAllocator(); - final FlightServer server = FlightServer.builder(allocator, listenLocation, example).build()) { + final FlightServer server = + FlightServer.builder(allocator, listenLocation, example).build()) { server.start(); server.awaitTermination(); } @@ -187,7 +187,8 @@ public FlightSqlExample(final Location location) { new DriverManagerConnectionFactory(DATABASE_URI, new Properties()); final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); - final ObjectPool connectionPool = new GenericObjectPool<>(poolableConnectionFactory); + final ObjectPool connectionPool = + new GenericObjectPool<>(poolableConnectionFactory); poolableConnectionFactory.setPool(connectionPool); // PoolingDataSource takes ownership of `connectionPool` @@ -213,7 +214,8 @@ public FlightSqlExample(final Location location) { try (final Connection connection = dataSource.getConnection()) { final DatabaseMetaData metaData = connection.getMetaData(); - sqlInfoBuilder.withFlightSqlServerName(metaData.getDatabaseProductName()) + sqlInfoBuilder + .withFlightSqlServerName(metaData.getDatabaseProductName()) .withFlightSqlServerVersion(metaData.getDatabaseProductVersion()) .withFlightSqlServerArrowVersion(metaData.getDriverVersion()) .withFlightSqlServerReadOnly(metaData.isReadOnly()) @@ -222,29 +224,30 @@ public FlightSqlExample(final Location location) { .withFlightSqlServerTransaction(SqlSupportedTransaction.SQL_SUPPORTED_TRANSACTION_NONE) .withSqlIdentifierQuoteChar(metaData.getIdentifierQuoteString()) .withSqlDdlCatalog(metaData.supportsCatalogsInDataManipulation()) - .withSqlDdlSchema( metaData.supportsSchemasInDataManipulation()) - .withSqlDdlTable( metaData.allTablesAreSelectable()) - .withSqlIdentifierCase(metaData.storesMixedCaseIdentifiers() ? - SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_CASE_INSENSITIVE : - metaData.storesUpperCaseIdentifiers() ? - SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UPPERCASE : - metaData.storesLowerCaseIdentifiers() ? - SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_LOWERCASE : - SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UNKNOWN) - .withSqlQuotedIdentifierCase(metaData.storesMixedCaseQuotedIdentifiers() ? - SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_CASE_INSENSITIVE : - metaData.storesUpperCaseQuotedIdentifiers() ? - SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UPPERCASE : - metaData.storesLowerCaseQuotedIdentifiers() ? - SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_LOWERCASE : - SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UNKNOWN) + .withSqlDdlSchema(metaData.supportsSchemasInDataManipulation()) + .withSqlDdlTable(metaData.allTablesAreSelectable()) + .withSqlIdentifierCase( + metaData.storesMixedCaseIdentifiers() + ? SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_CASE_INSENSITIVE + : metaData.storesUpperCaseIdentifiers() + ? SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UPPERCASE + : metaData.storesLowerCaseIdentifiers() + ? SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_LOWERCASE + : SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UNKNOWN) + .withSqlQuotedIdentifierCase( + metaData.storesMixedCaseQuotedIdentifiers() + ? SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_CASE_INSENSITIVE + : metaData.storesUpperCaseQuotedIdentifiers() + ? SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UPPERCASE + : metaData.storesLowerCaseQuotedIdentifiers() + ? SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_LOWERCASE + : SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UNKNOWN) .withSqlAllTablesAreSelectable(true) .withSqlNullOrdering(SqlNullOrdering.SQL_NULLS_SORTED_AT_END) .withSqlMaxColumnsInTable(42); } catch (SQLException e) { throw new RuntimeException(e); } - } private static boolean removeDerbyDatabaseIfExists() { @@ -260,8 +263,12 @@ private static boolean removeDerbyDatabaseIfExists() { * If for whatever reason the resulting `Stream` is empty, throw an `IOException`; * this not expected. */ - wasSuccess = walk.sorted(Comparator.reverseOrder()).map(Path::toFile).map(File::delete) - .reduce(Boolean::logicalAnd).orElseThrow(IOException::new); + wasSuccess = + walk.sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .map(File::delete) + .reduce(Boolean::logicalAnd) + .orElseThrow(IOException::new); } catch (IOException e) { /* * The only acceptable scenario for an `IOException` to be thrown here is if @@ -277,23 +284,27 @@ private static boolean removeDerbyDatabaseIfExists() { } private static boolean populateDerbyDatabase() { - try (final Connection connection = DriverManager.getConnection("jdbc:derby:target/derbyDB;create=true"); - Statement statement = connection.createStatement()) { - statement.execute("CREATE TABLE foreignTable (" + - "id INT not null primary key GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), " + - "foreignName varchar(100), " + - "value int)"); - statement.execute("CREATE TABLE intTable (" + - "id INT not null primary key GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), " + - "keyName varchar(100), " + - "value int, " + - "foreignId int references foreignTable(id))"); + try (final Connection connection = + DriverManager.getConnection("jdbc:derby:target/derbyDB;create=true"); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE TABLE foreignTable (" + + "id INT not null primary key GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), " + + "foreignName varchar(100), " + + "value int)"); + statement.execute( + "CREATE TABLE intTable (" + + "id INT not null primary key GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), " + + "keyName varchar(100), " + + "value int, " + + "foreignId int references foreignTable(id))"); statement.execute("INSERT INTO foreignTable (foreignName, value) VALUES ('keyOne', 1)"); statement.execute("INSERT INTO foreignTable (foreignName, value) VALUES ('keyTwo', 0)"); statement.execute("INSERT INTO foreignTable (foreignName, value) VALUES ('keyThree', -1)"); statement.execute("INSERT INTO intTable (keyName, value, foreignId) VALUES ('one', 1, 1)"); statement.execute("INSERT INTO intTable (keyName, value, foreignId) VALUES ('zero', 0, 1)"); - statement.execute("INSERT INTO intTable (keyName, value, foreignId) VALUES ('negative one', -1, 1)"); + statement.execute( + "INSERT INTO intTable (keyName, value, foreignId) VALUES ('negative one', -1, 1)"); } catch (final SQLException e) { LOGGER.error(format("Failed attempt to populate DerbyDB: <%s>", e.getMessage()), e); return false; @@ -301,10 +312,11 @@ private static boolean populateDerbyDatabase() { return true; } - private static ArrowType getArrowTypeFromJdbcType(final int jdbcDataType, final int precision, final int scale) { + private static ArrowType getArrowTypeFromJdbcType( + final int jdbcDataType, final int precision, final int scale) { try { - return JdbcToArrowUtils.getArrowTypeFromJdbcType(new JdbcFieldInfo(jdbcDataType, precision, scale), - DEFAULT_CALENDAR); + return JdbcToArrowUtils.getArrowTypeFromJdbcType( + new JdbcFieldInfo(jdbcDataType, precision, scale), DEFAULT_CALENDAR); } catch (UnsupportedOperationException ignored) { return ArrowType.Utf8.INSTANCE; } @@ -328,19 +340,29 @@ private static void saveToVector(final Byte data, final BitVector vector, final private static void saveToVector(final String data, final VarCharVector vector, final int index) { preconditionCheckSaveToVector(vector, index); - vectorConsumer(data, vector, fieldVector -> fieldVector.setNull(index), + vectorConsumer( + data, + vector, + fieldVector -> fieldVector.setNull(index), (theData, fieldVector) -> fieldVector.setSafe(index, new Text(theData))); } private static void saveToVector(final Integer data, final IntVector vector, final int index) { preconditionCheckSaveToVector(vector, index); - vectorConsumer(data, vector, fieldVector -> fieldVector.setNull(index), + vectorConsumer( + data, + vector, + fieldVector -> fieldVector.setNull(index), (theData, fieldVector) -> fieldVector.setSafe(index, theData)); } - private static void saveToVector(final byte[] data, final VarBinaryVector vector, final int index) { + private static void saveToVector( + final byte[] data, final VarBinaryVector vector, final int index) { preconditionCheckSaveToVector(vector, index); - vectorConsumer(data, vector, fieldVector -> fieldVector.setNull(index), + vectorConsumer( + data, + vector, + fieldVector -> fieldVector.setNull(index), (theData, fieldVector) -> fieldVector.setSafe(index, theData)); } @@ -349,9 +371,11 @@ private static void preconditionCheckSaveToVector(final FieldVector vector, fina checkState(index >= 0, "Index must be a positive number!"); } - private static void vectorConsumer(final T data, final V vector, - final Consumer consumerIfNullable, - final BiConsumer defaultConsumer) { + private static void vectorConsumer( + final T data, + final V vector, + final Consumer consumerIfNullable, + final BiConsumer defaultConsumer) { if (isNull(data)) { consumerIfNullable.accept(vector); return; @@ -359,32 +383,40 @@ private static void vectorConsumer(final T data, fina defaultConsumer.accept(data, vector); } - private static VectorSchemaRoot getSchemasRoot(final ResultSet data, final BufferAllocator allocator) - throws SQLException { + private static VectorSchemaRoot getSchemasRoot( + final ResultSet data, final BufferAllocator allocator) throws SQLException { final VarCharVector catalogs = new VarCharVector("catalog_name", allocator); final VarCharVector schemas = - new VarCharVector("db_schema_name", FieldType.notNullable(MinorType.VARCHAR.getType()), allocator); + new VarCharVector( + "db_schema_name", FieldType.notNullable(MinorType.VARCHAR.getType()), allocator); final List vectors = ImmutableList.of(catalogs, schemas); vectors.forEach(FieldVector::allocateNew); - final Map vectorToColumnName = ImmutableMap.of( - catalogs, "TABLE_CATALOG", - schemas, "TABLE_SCHEM"); + final Map vectorToColumnName = + ImmutableMap.of( + catalogs, "TABLE_CATALOG", + schemas, "TABLE_SCHEM"); saveToVectors(vectorToColumnName, data); - final int rows = vectors.stream().map(FieldVector::getValueCount).findAny().orElseThrow(IllegalStateException::new); + final int rows = + vectors.stream() + .map(FieldVector::getValueCount) + .findAny() + .orElseThrow(IllegalStateException::new); vectors.forEach(vector -> vector.setValueCount(rows)); return new VectorSchemaRoot(vectors); } - private static int saveToVectors(final Map vectorToColumnName, - final ResultSet data, boolean emptyToNull) + private static int saveToVectors( + final Map vectorToColumnName, final ResultSet data, boolean emptyToNull) throws SQLException { Predicate alwaysTrue = (resultSet) -> true; return saveToVectors(vectorToColumnName, data, emptyToNull, alwaysTrue); } - private static int saveToVectors(final Map vectorToColumnName, - final ResultSet data, boolean emptyToNull, - Predicate resultSetPredicate) + private static int saveToVectors( + final Map vectorToColumnName, + final ResultSet data, + boolean emptyToNull, + Predicate resultSetPredicate) throws SQLException { Objects.requireNonNull(vectorToColumnName, "vectorToColumnName cannot be null."); Objects.requireNonNull(data, "data cannot be null."); @@ -400,7 +432,8 @@ private static int saveToVectors(final Map ve final String columnName = vectorToColumn.getValue(); if (vector instanceof VarCharVector) { String thisData = data.getString(columnName); - saveToVector(emptyToNull ? emptyToNull(thisData) : thisData, (VarCharVector) vector, rows); + saveToVector( + emptyToNull ? emptyToNull(thisData) : thisData, (VarCharVector) vector, rows); } else if (vector instanceof IntVector) { final int intValue = data.getInt(columnName); saveToVector(data.wasNull() ? null : intValue, (IntVector) vector, rows); @@ -425,21 +458,25 @@ private static int saveToVectors(final Map ve String[] split = createParamsValues.split(","); range(0, split.length) - .forEach(i -> { - byte[] bytes = split[i].getBytes(UTF_8); - Preconditions.checkState(bytes.length < 1024, - "The amount of bytes is greater than what the ArrowBuf supports"); - buf.setBytes(0, bytes); - writer.varChar().writeVarChar(0, bytes.length, buf); - }); + .forEach( + i -> { + byte[] bytes = split[i].getBytes(UTF_8); + Preconditions.checkState( + bytes.length < 1024, + "The amount of bytes is greater than what the ArrowBuf supports"); + buf.setBytes(0, bytes); + writer.varChar().writeVarChar(0, bytes.length, buf); + }); } buf.close(); writer.endList(); } else { - throw CallStatus.INVALID_ARGUMENT.withDescription("Provided vector not supported").toRuntimeException(); + throw CallStatus.INVALID_ARGUMENT + .withDescription("Provided vector not supported") + .toRuntimeException(); } } - rows ++; + rows++; } for (final Entry vectorToColumn : entrySet) { vectorToColumn.getKey().setValueCount(rows); @@ -448,35 +485,38 @@ private static int saveToVectors(final Map ve return rows; } - private static void saveToVectors(final Map vectorToColumnName, - final ResultSet data) - throws SQLException { + private static void saveToVectors( + final Map vectorToColumnName, final ResultSet data) throws SQLException { saveToVectors(vectorToColumnName, data, false); } - private static VectorSchemaRoot getTableTypesRoot(final ResultSet data, final BufferAllocator allocator) - throws SQLException { + private static VectorSchemaRoot getTableTypesRoot( + final ResultSet data, final BufferAllocator allocator) throws SQLException { return getRoot(data, allocator, "table_type", "TABLE_TYPE"); } - private static VectorSchemaRoot getCatalogsRoot(final ResultSet data, final BufferAllocator allocator) - throws SQLException { + private static VectorSchemaRoot getCatalogsRoot( + final ResultSet data, final BufferAllocator allocator) throws SQLException { return getRoot(data, allocator, "catalog_name", "TABLE_CATALOG"); } - private static VectorSchemaRoot getRoot(final ResultSet data, final BufferAllocator allocator, - final String fieldVectorName, final String columnName) + private static VectorSchemaRoot getRoot( + final ResultSet data, + final BufferAllocator allocator, + final String fieldVectorName, + final String columnName) throws SQLException { final VarCharVector dataVector = - new VarCharVector(fieldVectorName, FieldType.notNullable(MinorType.VARCHAR.getType()), allocator); + new VarCharVector( + fieldVectorName, FieldType.notNullable(MinorType.VARCHAR.getType()), allocator); saveToVectors(ImmutableMap.of(dataVector, columnName), data); final int rows = dataVector.getValueCount(); dataVector.setValueCount(rows); return new VectorSchemaRoot(singletonList(dataVector)); } - private static VectorSchemaRoot getTypeInfoRoot(CommandGetXdbcTypeInfo request, ResultSet typeInfo, - final BufferAllocator allocator) + private static VectorSchemaRoot getTypeInfoRoot( + CommandGetXdbcTypeInfo request, ResultSet typeInfo, final BufferAllocator allocator) throws SQLException { Preconditions.checkNotNull(allocator, "BufferAllocator cannot be null."); @@ -504,13 +544,14 @@ private static VectorSchemaRoot getTypeInfoRoot(CommandGetXdbcTypeInfo request, Predicate predicate; if (request.hasDataType()) { - predicate = (resultSet) -> { - try { - return resultSet.getInt("DATA_TYPE") == request.getDataType(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - }; + predicate = + (resultSet) -> { + try { + return resultSet.getInt("DATA_TYPE") == request.getDataType(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }; } else { predicate = (resultSet -> true); } @@ -521,13 +562,14 @@ private static VectorSchemaRoot getTypeInfoRoot(CommandGetXdbcTypeInfo request, return root; } - private static VectorSchemaRoot getTablesRoot(final DatabaseMetaData databaseMetaData, - final BufferAllocator allocator, - final boolean includeSchema, - final String catalog, - final String schemaFilterPattern, - final String tableFilterPattern, - final String... tableTypes) + private static VectorSchemaRoot getTablesRoot( + final DatabaseMetaData databaseMetaData, + final BufferAllocator allocator, + final boolean includeSchema, + final String catalog, + final String schemaFilterPattern, + final String tableFilterPattern, + final String... tableTypes) throws SQLException, IOException { /* * TODO Fix DerbyDB inconsistency if possible. @@ -543,9 +585,11 @@ private static VectorSchemaRoot getTablesRoot(final DatabaseMetaData databaseMet final VarCharVector catalogNameVector = new VarCharVector("catalog_name", allocator); final VarCharVector schemaNameVector = new VarCharVector("db_schema_name", allocator); final VarCharVector tableNameVector = - new VarCharVector("table_name", FieldType.notNullable(MinorType.VARCHAR.getType()), allocator); + new VarCharVector( + "table_name", FieldType.notNullable(MinorType.VARCHAR.getType()), allocator); final VarCharVector tableTypeVector = - new VarCharVector("table_type", FieldType.notNullable(MinorType.VARCHAR.getType()), allocator); + new VarCharVector( + "table_type", FieldType.notNullable(MinorType.VARCHAR.getType()), allocator); final List vectors = new ArrayList<>(4); vectors.add(catalogNameVector); @@ -555,30 +599,35 @@ private static VectorSchemaRoot getTablesRoot(final DatabaseMetaData databaseMet vectors.forEach(FieldVector::allocateNew); - final Map vectorToColumnName = ImmutableMap.of( - catalogNameVector, "TABLE_CAT", - schemaNameVector, "TABLE_SCHEM", - tableNameVector, "TABLE_NAME", - tableTypeVector, "TABLE_TYPE"); + final Map vectorToColumnName = + ImmutableMap.of( + catalogNameVector, "TABLE_CAT", + schemaNameVector, "TABLE_SCHEM", + tableNameVector, "TABLE_NAME", + tableTypeVector, "TABLE_TYPE"); try (final ResultSet data = - Objects.requireNonNull( - databaseMetaData, - format("%s cannot be null.", databaseMetaData.getClass().getName())) - .getTables(catalog, schemaFilterPattern, tableFilterPattern, tableTypes)) { + Objects.requireNonNull( + databaseMetaData, + format("%s cannot be null.", databaseMetaData.getClass().getName())) + .getTables(catalog, schemaFilterPattern, tableFilterPattern, tableTypes)) { saveToVectors(vectorToColumnName, data, true); final int rows = - vectors.stream().map(FieldVector::getValueCount).findAny().orElseThrow(IllegalStateException::new); + vectors.stream() + .map(FieldVector::getValueCount) + .findAny() + .orElseThrow(IllegalStateException::new); vectors.forEach(vector -> vector.setValueCount(rows)); if (includeSchema) { final VarBinaryVector tableSchemaVector = - new VarBinaryVector("table_schema", FieldType.notNullable(MinorType.VARBINARY.getType()), allocator); + new VarBinaryVector( + "table_schema", FieldType.notNullable(MinorType.VARBINARY.getType()), allocator); tableSchemaVector.allocateNew(rows); try (final ResultSet columnsData = - databaseMetaData.getColumns(catalog, schemaFilterPattern, tableFilterPattern, null)) { + databaseMetaData.getColumns(catalog, schemaFilterPattern, tableFilterPattern, null)) { final Map> tableToFields = new HashMap<>(); while (columnsData.next()) { @@ -588,23 +637,26 @@ private static VectorSchemaRoot getTablesRoot(final DatabaseMetaData databaseMet final String typeName = columnsData.getString("TYPE_NAME"); final String fieldName = columnsData.getString("COLUMN_NAME"); final int dataType = columnsData.getInt("DATA_TYPE"); - final boolean isNullable = columnsData.getInt("NULLABLE") != DatabaseMetaData.columnNoNulls; + final boolean isNullable = + columnsData.getInt("NULLABLE") != DatabaseMetaData.columnNoNulls; final int precision = columnsData.getInt("COLUMN_SIZE"); final int scale = columnsData.getInt("DECIMAL_DIGITS"); boolean isAutoIncrement = Objects.equals(columnsData.getString("IS_AUTOINCREMENT"), "YES"); - final List fields = tableToFields.computeIfAbsent(tableName, tableName_ -> new ArrayList<>()); + final List fields = + tableToFields.computeIfAbsent(tableName, tableName_ -> new ArrayList<>()); - final FlightSqlColumnMetadata columnMetadata = new FlightSqlColumnMetadata.Builder() - .catalogName(catalogName) - .schemaName(schemaName) - .tableName(tableName) - .typeName(typeName) - .precision(precision) - .scale(scale) - .isAutoIncrement(isAutoIncrement) - .build(); + final FlightSqlColumnMetadata columnMetadata = + new FlightSqlColumnMetadata.Builder() + .catalogName(catalogName) + .schemaName(schemaName) + .tableName(tableName) + .typeName(typeName) + .precision(precision) + .scale(scale) + .isAutoIncrement(isAutoIncrement) + .build(); final Field field = new Field( @@ -622,8 +674,7 @@ private static VectorSchemaRoot getTablesRoot(final DatabaseMetaData databaseMet final String tableName = tableNameVector.getObject(index).toString(); final Schema schema = new Schema(tableToFields.get(tableName)); saveToVector( - copyFrom(serializeMetadata(schema)).toByteArray(), - tableSchemaVector, index); + copyFrom(serializeMetadata(schema)).toByteArray(), tableSchemaVector, index); } } @@ -647,15 +698,19 @@ private static ByteBuffer serializeMetadata(final Schema schema) { } @Override - public void getStreamPreparedStatement(final CommandPreparedStatementQuery command, final CallContext context, - final ServerStreamListener listener) { + public void getStreamPreparedStatement( + final CommandPreparedStatementQuery command, + final CallContext context, + final ServerStreamListener listener) { final ByteString handle = command.getPreparedStatementHandle(); - StatementContext statementContext = preparedStatementLoadingCache.getIfPresent(handle); + StatementContext statementContext = + preparedStatementLoadingCache.getIfPresent(handle); Objects.requireNonNull(statementContext); final PreparedStatement statement = statementContext.getStatement(); try (final ResultSet resultSet = statement.executeQuery()) { final Schema schema = jdbcToArrowSchema(resultSet.getMetaData(), DEFAULT_CALENDAR); - try (final VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.create(schema, rootAllocator)) { + try (final VectorSchemaRoot vectorSchemaRoot = + VectorSchemaRoot.create(schema, rootAllocator)) { final VectorLoader loader = new VectorLoader(vectorSchemaRoot); listener.start(vectorSchemaRoot); @@ -675,60 +730,67 @@ public void getStreamPreparedStatement(final CommandPreparedStatementQuery comma } } catch (final SQLException | IOException e) { LOGGER.error(format("Failed to getStreamPreparedStatement: <%s>.", e.getMessage()), e); - listener.error(CallStatus.INTERNAL.withDescription("Failed to prepare statement: " + e).toRuntimeException()); + listener.error( + CallStatus.INTERNAL + .withDescription("Failed to prepare statement: " + e) + .toRuntimeException()); } finally { listener.completed(); } } @Override - public void closePreparedStatement(final ActionClosePreparedStatementRequest request, final CallContext context, - final StreamListener listener) { + public void closePreparedStatement( + final ActionClosePreparedStatementRequest request, + final CallContext context, + final StreamListener listener) { // Running on another thread - executorService.submit(() -> { - try { - preparedStatementLoadingCache.invalidate(request.getPreparedStatementHandle()); - } catch (final Exception e) { - listener.onError(e); - return; - } - listener.onCompleted(); - }); + executorService.submit( + () -> { + try { + preparedStatementLoadingCache.invalidate(request.getPreparedStatementHandle()); + } catch (final Exception e) { + listener.onError(e); + return; + } + listener.onCompleted(); + }); } @Override - public FlightInfo getFlightInfoStatement(final CommandStatementQuery request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoStatement( + final CommandStatementQuery request, + final CallContext context, + final FlightDescriptor descriptor) { ByteString handle = copyFrom(randomUUID().toString().getBytes(UTF_8)); try { // Ownership of the connection will be passed to the context. Do NOT close! final Connection connection = dataSource.getConnection(); - final Statement statement = connection.createStatement( - ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + final Statement statement = + connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); final String query = request.getQuery(); final StatementContext statementContext = new StatementContext<>(statement, query); statementLoadingCache.put(handle, statementContext); final ResultSet resultSet = statement.executeQuery(query); - TicketStatementQuery ticket = TicketStatementQuery.newBuilder() - .setStatementHandle(handle) - .build(); - return getFlightInfoForSchema(ticket, descriptor, - jdbcToArrowSchema(resultSet.getMetaData(), DEFAULT_CALENDAR)); + TicketStatementQuery ticket = + TicketStatementQuery.newBuilder().setStatementHandle(handle).build(); + return getFlightInfoForSchema( + ticket, descriptor, jdbcToArrowSchema(resultSet.getMetaData(), DEFAULT_CALENDAR)); } catch (final SQLException e) { LOGGER.error( - format("There was a problem executing the prepared statement: <%s>.", e.getMessage()), - e); + format("There was a problem executing the prepared statement: <%s>.", e.getMessage()), e); throw CallStatus.INTERNAL.withCause(e).toRuntimeException(); } } @Override - public FlightInfo getFlightInfoPreparedStatement(final CommandPreparedStatementQuery command, - final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoPreparedStatement( + final CommandPreparedStatementQuery command, + final CallContext context, + final FlightDescriptor descriptor) { final ByteString preparedStatementHandle = command.getPreparedStatementHandle(); StatementContext statementContext = preparedStatementLoadingCache.getIfPresent(preparedStatementHandle); @@ -737,19 +799,20 @@ public FlightInfo getFlightInfoPreparedStatement(final CommandPreparedStatementQ PreparedStatement statement = statementContext.getStatement(); ResultSetMetaData metaData = statement.getMetaData(); - return getFlightInfoForSchema(command, descriptor, - jdbcToArrowSchema(metaData, DEFAULT_CALENDAR)); + return getFlightInfoForSchema( + command, descriptor, jdbcToArrowSchema(metaData, DEFAULT_CALENDAR)); } catch (final SQLException e) { LOGGER.error( - format("There was a problem executing the prepared statement: <%s>.", e.getMessage()), - e); + format("There was a problem executing the prepared statement: <%s>.", e.getMessage()), e); throw CallStatus.INTERNAL.withCause(e).toRuntimeException(); } } @Override - public SchemaResult getSchemaStatement(final CommandStatementQuery command, final CallContext context, - final FlightDescriptor descriptor) { + public SchemaResult getSchemaStatement( + final CommandStatementQuery command, + final CallContext context, + final FlightDescriptor descriptor) { throw CallStatus.UNIMPLEMENTED.toRuntimeException(); } @@ -765,52 +828,64 @@ public void close() throws Exception { } @Override - public void listFlights(CallContext context, Criteria criteria, StreamListener listener) { + public void listFlights( + CallContext context, Criteria criteria, StreamListener listener) { // TODO - build example implementation throw CallStatus.UNIMPLEMENTED.toRuntimeException(); } @Override - public void createPreparedStatement(final ActionCreatePreparedStatementRequest request, final CallContext context, - final StreamListener listener) { + public void createPreparedStatement( + final ActionCreatePreparedStatementRequest request, + final CallContext context, + final StreamListener listener) { // Running on another thread - executorService.submit(() -> { - try { - final ByteString preparedStatementHandle = copyFrom(randomUUID().toString().getBytes(UTF_8)); - // Ownership of the connection will be passed to the context. Do NOT close! - final Connection connection = dataSource.getConnection(); - final PreparedStatement preparedStatement = connection.prepareStatement(request.getQuery(), - ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - final StatementContext preparedStatementContext = - new StatementContext<>(preparedStatement, request.getQuery()); - - preparedStatementLoadingCache.put(preparedStatementHandle, preparedStatementContext); - - final Schema parameterSchema = - jdbcToArrowSchema(preparedStatement.getParameterMetaData(), DEFAULT_CALENDAR); - - final ResultSetMetaData metaData = preparedStatement.getMetaData(); - final ByteString bytes = isNull(metaData) ? - ByteString.EMPTY : - ByteString.copyFrom( - serializeMetadata(jdbcToArrowSchema(metaData, DEFAULT_CALENDAR))); - final ActionCreatePreparedStatementResult result = ActionCreatePreparedStatementResult.newBuilder() - .setDatasetSchema(bytes) - .setParameterSchema(copyFrom(serializeMetadata(parameterSchema))) - .setPreparedStatementHandle(preparedStatementHandle) - .build(); - listener.onNext(new Result(pack(result).toByteArray())); - } catch (final SQLException e) { - listener.onError(CallStatus.INTERNAL - .withDescription("Failed to create prepared statement: " + e) - .toRuntimeException()); - return; - } catch (final Throwable t) { - listener.onError(CallStatus.INTERNAL.withDescription("Unknown error: " + t).toRuntimeException()); - return; - } - listener.onCompleted(); - }); + executorService.submit( + () -> { + try { + final ByteString preparedStatementHandle = + copyFrom(randomUUID().toString().getBytes(UTF_8)); + // Ownership of the connection will be passed to the context. Do NOT close! + final Connection connection = dataSource.getConnection(); + final PreparedStatement preparedStatement = + connection.prepareStatement( + request.getQuery(), + ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_READ_ONLY); + final StatementContext preparedStatementContext = + new StatementContext<>(preparedStatement, request.getQuery()); + + preparedStatementLoadingCache.put(preparedStatementHandle, preparedStatementContext); + + final Schema parameterSchema = + jdbcToArrowSchema(preparedStatement.getParameterMetaData(), DEFAULT_CALENDAR); + + final ResultSetMetaData metaData = preparedStatement.getMetaData(); + final ByteString bytes = + isNull(metaData) + ? ByteString.EMPTY + : ByteString.copyFrom( + serializeMetadata(jdbcToArrowSchema(metaData, DEFAULT_CALENDAR))); + final ActionCreatePreparedStatementResult result = + ActionCreatePreparedStatementResult.newBuilder() + .setDatasetSchema(bytes) + .setParameterSchema(copyFrom(serializeMetadata(parameterSchema))) + .setPreparedStatementHandle(preparedStatementHandle) + .build(); + listener.onNext(new Result(pack(result).toByteArray())); + } catch (final SQLException e) { + listener.onError( + CallStatus.INTERNAL + .withDescription("Failed to create prepared statement: " + e) + .toRuntimeException()); + return; + } catch (final Throwable t) { + listener.onError( + CallStatus.INTERNAL.withDescription("Unknown error: " + t).toRuntimeException()); + return; + } + listener.onCompleted(); + }); } @Override @@ -820,14 +895,16 @@ public void doExchange(CallContext context, FlightStream reader, ServerStreamLis } @Override - public Runnable acceptPutStatement(CommandStatementUpdate command, - CallContext context, FlightStream flightStream, - StreamListener ackStream) { + public Runnable acceptPutStatement( + CommandStatementUpdate command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { final String query = command.getQuery(); return () -> { try (final Connection connection = dataSource.getConnection(); - final Statement statement = connection.createStatement()) { + final Statement statement = connection.createStatement()) { final int result = statement.executeUpdate(query); final DoPutUpdateResult build = @@ -839,28 +916,34 @@ public Runnable acceptPutStatement(CommandStatementUpdate command, ackStream.onCompleted(); } } catch (SQLSyntaxErrorException e) { - ackStream.onError(CallStatus.INVALID_ARGUMENT - .withDescription("Failed to execute statement (invalid syntax): " + e) - .toRuntimeException()); + ackStream.onError( + CallStatus.INVALID_ARGUMENT + .withDescription("Failed to execute statement (invalid syntax): " + e) + .toRuntimeException()); } catch (SQLException e) { - ackStream.onError(CallStatus.INTERNAL - .withDescription("Failed to execute statement: " + e) - .toRuntimeException()); + ackStream.onError( + CallStatus.INTERNAL + .withDescription("Failed to execute statement: " + e) + .toRuntimeException()); } }; } @Override - public Runnable acceptPutPreparedStatementUpdate(CommandPreparedStatementUpdate command, CallContext context, - FlightStream flightStream, StreamListener ackStream) { + public Runnable acceptPutPreparedStatementUpdate( + CommandPreparedStatementUpdate command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { final StatementContext statement = preparedStatementLoadingCache.getIfPresent(command.getPreparedStatementHandle()); return () -> { if (statement == null) { - ackStream.onError(CallStatus.NOT_FOUND - .withDescription("Prepared statement does not exist") - .toRuntimeException()); + ackStream.onError( + CallStatus.NOT_FOUND + .withDescription("Prepared statement does not exist") + .toRuntimeException()); return; } try { @@ -876,7 +959,8 @@ public Runnable acceptPutPreparedStatementUpdate(CommandPreparedStatementUpdate preparedStatement.execute(); recordCount = preparedStatement.getUpdateCount(); } else { - final JdbcParameterBinder binder = JdbcParameterBinder.builder(preparedStatement, root).bindAll().build(); + final JdbcParameterBinder binder = + JdbcParameterBinder.builder(preparedStatement, root).bindAll().build(); while (binder.next()) { preparedStatement.addBatch(); } @@ -893,7 +977,10 @@ public Runnable acceptPutPreparedStatementUpdate(CommandPreparedStatementUpdate } } } catch (SQLException e) { - ackStream.onError(CallStatus.INTERNAL.withDescription("Failed to execute update: " + e).toRuntimeException()); + ackStream.onError( + CallStatus.INTERNAL + .withDescription("Failed to execute update: " + e) + .toRuntimeException()); return; } ackStream.onCompleted(); @@ -901,8 +988,11 @@ public Runnable acceptPutPreparedStatementUpdate(CommandPreparedStatementUpdate } @Override - public Runnable acceptPutPreparedStatementQuery(CommandPreparedStatementQuery command, CallContext context, - FlightStream flightStream, StreamListener ackStream) { + public Runnable acceptPutPreparedStatementQuery( + CommandPreparedStatementQuery command, + CallContext context, + FlightStream flightStream, + StreamListener ackStream) { final StatementContext statementContext = preparedStatementLoadingCache.getIfPresent(command.getPreparedStatementHandle()); @@ -913,17 +1003,19 @@ public Runnable acceptPutPreparedStatementQuery(CommandPreparedStatementQuery co try { while (flightStream.next()) { final VectorSchemaRoot root = flightStream.getRoot(); - final JdbcParameterBinder binder = JdbcParameterBinder.builder(preparedStatement, root).bindAll().build(); + final JdbcParameterBinder binder = + JdbcParameterBinder.builder(preparedStatement, root).bindAll().build(); while (binder.next()) { // Do not execute() - will be done in a getStream call } } } catch (SQLException e) { - ackStream.onError(CallStatus.INTERNAL - .withDescription("Failed to bind parameters: " + e.getMessage()) - .withCause(e) - .toRuntimeException()); + ackStream.onError( + CallStatus.INTERNAL + .withDescription("Failed to bind parameters: " + e.getMessage()) + .withCause(e) + .toRuntimeException()); return; } ackStream.onCompleted(); @@ -931,29 +1023,34 @@ public Runnable acceptPutPreparedStatementQuery(CommandPreparedStatementQuery co } @Override - public FlightInfo getFlightInfoSqlInfo(final CommandGetSqlInfo request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoSqlInfo( + final CommandGetSqlInfo request, + final CallContext context, + final FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_SQL_INFO_SCHEMA); } @Override - public void getStreamSqlInfo(final CommandGetSqlInfo command, final CallContext context, - final ServerStreamListener listener) { + public void getStreamSqlInfo( + final CommandGetSqlInfo command, + final CallContext context, + final ServerStreamListener listener) { this.sqlInfoBuilder.send(command.getInfoList(), listener); } @Override - public FlightInfo getFlightInfoTypeInfo(CommandGetXdbcTypeInfo request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTypeInfo( + CommandGetXdbcTypeInfo request, CallContext context, FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_TYPE_INFO_SCHEMA); } @Override - public void getStreamTypeInfo(CommandGetXdbcTypeInfo request, CallContext context, - ServerStreamListener listener) { + public void getStreamTypeInfo( + CommandGetXdbcTypeInfo request, CallContext context, ServerStreamListener listener) { try (final Connection connection = dataSource.getConnection(); - final ResultSet typeInfo = connection.getMetaData().getTypeInfo(); - final VectorSchemaRoot vectorSchemaRoot = getTypeInfoRoot(request, typeInfo, rootAllocator)) { + final ResultSet typeInfo = connection.getMetaData().getTypeInfo(); + final VectorSchemaRoot vectorSchemaRoot = + getTypeInfoRoot(request, typeInfo, rootAllocator)) { listener.start(vectorSchemaRoot); listener.putNext(); } catch (SQLException e) { @@ -965,16 +1062,18 @@ public void getStreamTypeInfo(CommandGetXdbcTypeInfo request, CallContext contex } @Override - public FlightInfo getFlightInfoCatalogs(final CommandGetCatalogs request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoCatalogs( + final CommandGetCatalogs request, + final CallContext context, + final FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_CATALOGS_SCHEMA); } @Override public void getStreamCatalogs(final CallContext context, final ServerStreamListener listener) { try (final Connection connection = dataSource.getConnection(); - final ResultSet catalogs = connection.getMetaData().getCatalogs(); - final VectorSchemaRoot vectorSchemaRoot = getCatalogsRoot(catalogs, rootAllocator)) { + final ResultSet catalogs = connection.getMetaData().getCatalogs(); + final VectorSchemaRoot vectorSchemaRoot = getCatalogsRoot(catalogs, rootAllocator)) { listener.start(vectorSchemaRoot); listener.putNext(); } catch (SQLException e) { @@ -986,19 +1085,25 @@ public void getStreamCatalogs(final CallContext context, final ServerStreamListe } @Override - public FlightInfo getFlightInfoSchemas(final CommandGetDbSchemas request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoSchemas( + final CommandGetDbSchemas request, + final CallContext context, + final FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_SCHEMAS_SCHEMA); } @Override - public void getStreamSchemas(final CommandGetDbSchemas command, final CallContext context, - final ServerStreamListener listener) { + public void getStreamSchemas( + final CommandGetDbSchemas command, + final CallContext context, + final ServerStreamListener listener) { final String catalog = command.hasCatalog() ? command.getCatalog() : null; - final String schemaFilterPattern = command.hasDbSchemaFilterPattern() ? command.getDbSchemaFilterPattern() : null; + final String schemaFilterPattern = + command.hasDbSchemaFilterPattern() ? command.getDbSchemaFilterPattern() : null; try (final Connection connection = dataSource.getConnection(); - final ResultSet schemas = connection.getMetaData().getSchemas(catalog, schemaFilterPattern); - final VectorSchemaRoot vectorSchemaRoot = getSchemasRoot(schemas, rootAllocator)) { + final ResultSet schemas = + connection.getMetaData().getSchemas(catalog, schemaFilterPattern); + final VectorSchemaRoot vectorSchemaRoot = getSchemasRoot(schemas, rootAllocator)) { listener.start(vectorSchemaRoot); listener.putNext(); } catch (SQLException e) { @@ -1010,8 +1115,10 @@ public void getStreamSchemas(final CommandGetDbSchemas command, final CallContex } @Override - public FlightInfo getFlightInfoTables(final CommandGetTables request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTables( + final CommandGetTables request, + final CallContext context, + final FlightDescriptor descriptor) { Schema schemaToUse = Schemas.GET_TABLES_SCHEMA; if (!request.getIncludeSchema()) { schemaToUse = Schemas.GET_TABLES_SCHEMA_NO_SCHEMA; @@ -1020,8 +1127,10 @@ public FlightInfo getFlightInfoTables(final CommandGetTables request, final Call } @Override - public void getStreamTables(final CommandGetTables command, final CallContext context, - final ServerStreamListener listener) { + public void getStreamTables( + final CommandGetTables command, + final CallContext context, + final ServerStreamListener listener) { final String catalog = command.hasCatalog() ? command.getCatalog() : null; final String schemaFilterPattern = command.hasDbSchemaFilterPattern() ? command.getDbSchemaFilterPattern() : null; @@ -1034,11 +1143,15 @@ public void getStreamTables(final CommandGetTables command, final CallContext co protocolSize == 0 ? null : protocolStringList.toArray(new String[protocolSize]); try (final Connection connection = DriverManager.getConnection(DATABASE_URI); - final VectorSchemaRoot vectorSchemaRoot = getTablesRoot( - connection.getMetaData(), - rootAllocator, - command.getIncludeSchema(), - catalog, schemaFilterPattern, tableFilterPattern, tableTypes)) { + final VectorSchemaRoot vectorSchemaRoot = + getTablesRoot( + connection.getMetaData(), + rootAllocator, + command.getIncludeSchema(), + catalog, + schemaFilterPattern, + tableFilterPattern, + tableTypes)) { listener.start(vectorSchemaRoot); listener.putNext(); } catch (SQLException | IOException e) { @@ -1050,16 +1163,18 @@ public void getStreamTables(final CommandGetTables command, final CallContext co } @Override - public FlightInfo getFlightInfoTableTypes(final CommandGetTableTypes request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoTableTypes( + final CommandGetTableTypes request, + final CallContext context, + final FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_TABLE_TYPES_SCHEMA); } @Override public void getStreamTableTypes(final CallContext context, final ServerStreamListener listener) { try (final Connection connection = dataSource.getConnection(); - final ResultSet tableTypes = connection.getMetaData().getTableTypes(); - final VectorSchemaRoot vectorSchemaRoot = getTableTypesRoot(tableTypes, rootAllocator)) { + final ResultSet tableTypes = connection.getMetaData().getTableTypes(); + final VectorSchemaRoot vectorSchemaRoot = getTableTypesRoot(tableTypes, rootAllocator)) { listener.start(vectorSchemaRoot); listener.putNext(); } catch (SQLException e) { @@ -1071,14 +1186,18 @@ public void getStreamTableTypes(final CallContext context, final ServerStreamLis } @Override - public FlightInfo getFlightInfoPrimaryKeys(final CommandGetPrimaryKeys request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoPrimaryKeys( + final CommandGetPrimaryKeys request, + final CallContext context, + final FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_PRIMARY_KEYS_SCHEMA); } @Override - public void getStreamPrimaryKeys(final CommandGetPrimaryKeys command, final CallContext context, - final ServerStreamListener listener) { + public void getStreamPrimaryKeys( + final CommandGetPrimaryKeys command, + final CallContext context, + final ServerStreamListener listener) { final String catalog = command.hasCatalog() ? command.getCatalog() : null; final String schema = command.hasDbSchema() ? command.getDbSchema() : null; @@ -1097,7 +1216,11 @@ public void getStreamPrimaryKeys(final CommandGetPrimaryKeys command, final Call final List vectors = new ArrayList<>( ImmutableList.of( - catalogNameVector, schemaNameVector, tableNameVector, columnNameVector, keySequenceVector, + catalogNameVector, + schemaNameVector, + tableNameVector, + columnNameVector, + keySequenceVector, keyNameVector)); vectors.forEach(FieldVector::allocateNew); @@ -1126,21 +1249,25 @@ public void getStreamPrimaryKeys(final CommandGetPrimaryKeys command, final Call } @Override - public FlightInfo getFlightInfoExportedKeys(final CommandGetExportedKeys request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoExportedKeys( + final CommandGetExportedKeys request, + final CallContext context, + final FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_EXPORTED_KEYS_SCHEMA); } @Override - public void getStreamExportedKeys(final CommandGetExportedKeys command, final CallContext context, - final ServerStreamListener listener) { + public void getStreamExportedKeys( + final CommandGetExportedKeys command, + final CallContext context, + final ServerStreamListener listener) { String catalog = command.hasCatalog() ? command.getCatalog() : null; String schema = command.hasDbSchema() ? command.getDbSchema() : null; String table = command.getTable(); try (Connection connection = DriverManager.getConnection(DATABASE_URI); - ResultSet keys = connection.getMetaData().getExportedKeys(catalog, schema, table); - VectorSchemaRoot vectorSchemaRoot = createVectors(keys)) { + ResultSet keys = connection.getMetaData().getExportedKeys(catalog, schema, table); + VectorSchemaRoot vectorSchemaRoot = createVectors(keys)) { listener.start(vectorSchemaRoot); listener.putNext(); } catch (SQLException e) { @@ -1151,21 +1278,25 @@ public void getStreamExportedKeys(final CommandGetExportedKeys command, final Ca } @Override - public FlightInfo getFlightInfoImportedKeys(final CommandGetImportedKeys request, final CallContext context, - final FlightDescriptor descriptor) { + public FlightInfo getFlightInfoImportedKeys( + final CommandGetImportedKeys request, + final CallContext context, + final FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_IMPORTED_KEYS_SCHEMA); } @Override - public void getStreamImportedKeys(final CommandGetImportedKeys command, final CallContext context, - final ServerStreamListener listener) { + public void getStreamImportedKeys( + final CommandGetImportedKeys command, + final CallContext context, + final ServerStreamListener listener) { String catalog = command.hasCatalog() ? command.getCatalog() : null; String schema = command.hasDbSchema() ? command.getDbSchema() : null; String table = command.getTable(); try (Connection connection = DriverManager.getConnection(DATABASE_URI); - ResultSet keys = connection.getMetaData().getImportedKeys(catalog, schema, table); - VectorSchemaRoot vectorSchemaRoot = createVectors(keys)) { + ResultSet keys = connection.getMetaData().getImportedKeys(catalog, schema, table); + VectorSchemaRoot vectorSchemaRoot = createVectors(keys)) { listener.start(vectorSchemaRoot); listener.putNext(); } catch (final SQLException e) { @@ -1176,14 +1307,14 @@ public void getStreamImportedKeys(final CommandGetImportedKeys command, final Ca } @Override - public FlightInfo getFlightInfoCrossReference(CommandGetCrossReference request, CallContext context, - FlightDescriptor descriptor) { + public FlightInfo getFlightInfoCrossReference( + CommandGetCrossReference request, CallContext context, FlightDescriptor descriptor) { return getFlightInfoForSchema(request, descriptor, Schemas.GET_CROSS_REFERENCE_SCHEMA); } @Override - public void getStreamCrossReference(CommandGetCrossReference command, CallContext context, - ServerStreamListener listener) { + public void getStreamCrossReference( + CommandGetCrossReference command, CallContext context, ServerStreamListener listener) { final String pkCatalog = command.hasPkCatalog() ? command.getPkCatalog() : null; final String pkSchema = command.hasPkDbSchema() ? command.getPkDbSchema() : null; final String fkCatalog = command.hasFkCatalog() ? command.getFkCatalog() : null; @@ -1192,9 +1323,11 @@ public void getStreamCrossReference(CommandGetCrossReference command, CallContex final String fkTable = command.getFkTable(); try (Connection connection = DriverManager.getConnection(DATABASE_URI); - ResultSet keys = connection.getMetaData() - .getCrossReference(pkCatalog, pkSchema, pkTable, fkCatalog, fkSchema, fkTable); - VectorSchemaRoot vectorSchemaRoot = createVectors(keys)) { + ResultSet keys = + connection + .getMetaData() + .getCrossReference(pkCatalog, pkSchema, pkTable, fkCatalog, fkSchema, fkTable); + VectorSchemaRoot vectorSchemaRoot = createVectors(keys)) { listener.start(vectorSchemaRoot); listener.putNext(); } catch (final SQLException e) { @@ -1234,10 +1367,21 @@ private VectorSchemaRoot createVectors(ResultSet keys) throws SQLException { vectorToColumnName.put(fkKeyNameVector, "FK_NAME"); vectorToColumnName.put(pkKeyNameVector, "PK_NAME"); - final VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.of( - pkCatalogNameVector, pkSchemaNameVector, pkTableNameVector, pkColumnNameVector, fkCatalogNameVector, - fkSchemaNameVector, fkTableNameVector, fkColumnNameVector, keySequenceVector, fkKeyNameVector, - pkKeyNameVector, updateRuleVector, deleteRuleVector); + final VectorSchemaRoot vectorSchemaRoot = + VectorSchemaRoot.of( + pkCatalogNameVector, + pkSchemaNameVector, + pkTableNameVector, + pkColumnNameVector, + fkCatalogNameVector, + fkSchemaNameVector, + fkTableNameVector, + fkColumnNameVector, + keySequenceVector, + fkKeyNameVector, + pkKeyNameVector, + updateRuleVector, + deleteRuleVector); vectorSchemaRoot.allocateNew(); final int rowCount = saveToVectors(vectorToColumnName, keys, true); @@ -1248,8 +1392,10 @@ private VectorSchemaRoot createVectors(ResultSet keys) throws SQLException { } @Override - public void getStreamStatement(final TicketStatementQuery ticketStatementQuery, final CallContext context, - final ServerStreamListener listener) { + public void getStreamStatement( + final TicketStatementQuery ticketStatementQuery, + final CallContext context, + final ServerStreamListener listener) { final ByteString handle = ticketStatementQuery.getStatementHandle(); final StatementContext statementContext = Objects.requireNonNull(statementLoadingCache.getIfPresent(handle)); @@ -1278,8 +1424,8 @@ public void getStreamStatement(final TicketStatementQuery ticketStatementQuery, } } - private FlightInfo getFlightInfoForSchema(final T request, final FlightDescriptor descriptor, - final Schema schema) { + private FlightInfo getFlightInfoForSchema( + final T request, final FlightDescriptor descriptor, final Schema schema) { final Ticket ticket = new Ticket(pack(request).toByteArray()); // TODO Support multiple endpoints. final List endpoints = singletonList(new FlightEndpoint(ticket, location)); diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/StatementContext.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/StatementContext.java index 764ef3f54aa..8d0c4e7f206 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/StatementContext.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/StatementContext.java @@ -20,7 +20,6 @@ import java.sql.Connection; import java.sql.Statement; import java.util.Objects; - import org.apache.arrow.flight.sql.FlightSqlProducer; import org.apache.arrow.util.AutoCloseables; diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/test/TestFlightSql.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/test/TestFlightSql.java index a39736e939f..cc71c6ddb9b 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/test/TestFlightSql.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/test/TestFlightSql.java @@ -29,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import com.google.common.collect.ImmutableList; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; @@ -37,7 +38,6 @@ import java.util.Map; import java.util.Optional; import java.util.stream.IntStream; - import org.apache.arrow.flight.CancelFlightInfoRequest; import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightInfo; @@ -73,23 +73,25 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; -import com.google.common.collect.ImmutableList; - -/** - * Test direct usage of Flight SQL workflows. - */ +/** Test direct usage of Flight SQL workflows. */ public class TestFlightSql { - protected static final Schema SCHEMA_INT_TABLE = new Schema(asList( - new Field("ID", new FieldType(false, MinorType.INT.getType(), null), null), - Field.nullable("KEYNAME", MinorType.VARCHAR.getType()), - Field.nullable("VALUE", MinorType.INT.getType()), - Field.nullable("FOREIGNID", MinorType.INT.getType()))); - private static final List> EXPECTED_RESULTS_FOR_STAR_SELECT_QUERY = ImmutableList.of( - asList("1", "one", "1", "1"), asList("2", "zero", "0", "1"), asList("3", "negative one", "-1", "1")); - private static final List> EXPECTED_RESULTS_FOR_PARAMETER_BINDING = ImmutableList.of( - asList("1", "one", "1", "1")); - private static final Map GET_SQL_INFO_EXPECTED_RESULTS_MAP = new LinkedHashMap<>(); + protected static final Schema SCHEMA_INT_TABLE = + new Schema( + asList( + new Field("ID", new FieldType(false, MinorType.INT.getType(), null), null), + Field.nullable("KEYNAME", MinorType.VARCHAR.getType()), + Field.nullable("VALUE", MinorType.INT.getType()), + Field.nullable("FOREIGNID", MinorType.INT.getType()))); + private static final List> EXPECTED_RESULTS_FOR_STAR_SELECT_QUERY = + ImmutableList.of( + asList("1", "one", "1", "1"), + asList("2", "zero", "0", "1"), + asList("3", "negative one", "-1", "1")); + private static final List> EXPECTED_RESULTS_FOR_PARAMETER_BINDING = + ImmutableList.of(asList("1", "one", "1", "1")); + private static final Map GET_SQL_INFO_EXPECTED_RESULTS_MAP = + new LinkedHashMap<>(); private static final String LOCALHOST = "localhost"; private static BufferAllocator allocator; private static FlightServer server; @@ -100,45 +102,45 @@ public static void setUp() throws Exception { allocator = new RootAllocator(Integer.MAX_VALUE); final Location serverLocation = Location.forGrpcInsecure(LOCALHOST, 0); - server = FlightServer.builder(allocator, serverLocation, new FlightSqlExample(serverLocation)) - .build() - .start(); + server = + FlightServer.builder(allocator, serverLocation, new FlightSqlExample(serverLocation)) + .build() + .start(); final Location clientLocation = Location.forGrpcInsecure(LOCALHOST, server.getPort()); sqlClient = new FlightSqlClient(FlightClient.builder(allocator, clientLocation).build()); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME_VALUE), "Apache Derby"); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_VERSION_VALUE), "10.14.2.0 - (1828579)"); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_ARROW_VERSION_VALUE), "10.14.2.0 - (1828579)"); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_READ_ONLY_VALUE), "false"); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.SQL_ALL_TABLES_ARE_SELECTABLE_VALUE), "true"); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put( - Integer.toString(FlightSql.SqlInfo.SQL_NULL_ORDERING_VALUE), - Integer.toString(FlightSql.SqlNullOrdering.SQL_NULLS_SORTED_AT_END_VALUE)); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.SQL_DDL_CATALOG_VALUE), "false"); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.SQL_DDL_SCHEMA_VALUE), "true"); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.SQL_DDL_TABLE_VALUE), "true"); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put( - Integer.toString(FlightSql.SqlInfo.SQL_IDENTIFIER_CASE_VALUE), - Integer.toString(SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UPPERCASE_VALUE)); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.SQL_IDENTIFIER_QUOTE_CHAR_VALUE), "\""); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put( - Integer.toString(FlightSql.SqlInfo.SQL_QUOTED_IDENTIFIER_CASE_VALUE), - Integer.toString(SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_CASE_INSENSITIVE_VALUE)); - GET_SQL_INFO_EXPECTED_RESULTS_MAP - .put(Integer.toString(FlightSql.SqlInfo.SQL_MAX_COLUMNS_IN_TABLE_VALUE), "42"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME_VALUE), "Apache Derby"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_VERSION_VALUE), + "10.14.2.0 - (1828579)"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_ARROW_VERSION_VALUE), + "10.14.2.0 - (1828579)"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.FLIGHT_SQL_SERVER_READ_ONLY_VALUE), "false"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_ALL_TABLES_ARE_SELECTABLE_VALUE), "true"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_NULL_ORDERING_VALUE), + Integer.toString(FlightSql.SqlNullOrdering.SQL_NULLS_SORTED_AT_END_VALUE)); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_DDL_CATALOG_VALUE), "false"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_DDL_SCHEMA_VALUE), "true"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_DDL_TABLE_VALUE), "true"); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_IDENTIFIER_CASE_VALUE), + Integer.toString(SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_UPPERCASE_VALUE)); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_IDENTIFIER_QUOTE_CHAR_VALUE), "\""); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_QUOTED_IDENTIFIER_CASE_VALUE), + Integer.toString(SqlSupportedCaseSensitivity.SQL_CASE_SENSITIVITY_CASE_INSENSITIVE_VALUE)); + GET_SQL_INFO_EXPECTED_RESULTS_MAP.put( + Integer.toString(FlightSql.SqlInfo.SQL_MAX_COLUMNS_IN_TABLE_VALUE), "42"); } @AfterAll @@ -146,8 +148,10 @@ public static void tearDown() throws Exception { close(sqlClient, server, allocator); } - private static List> getNonConformingResultsForGetSqlInfo(final List> results) { - return getNonConformingResultsForGetSqlInfo(results, + private static List> getNonConformingResultsForGetSqlInfo( + final List> results) { + return getNonConformingResultsForGetSqlInfo( + results, FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME, FlightSql.SqlInfo.FLIGHT_SQL_SERVER_VERSION, FlightSql.SqlInfo.FLIGHT_SQL_SERVER_ARROW_VERSION, @@ -164,8 +168,7 @@ private static List> getNonConformingResultsForGetSqlInfo(final Lis } private static List> getNonConformingResultsForGetSqlInfo( - final List> results, - final FlightSql.SqlInfo... args) { + final List> results, final FlightSql.SqlInfo... args) { final List> nonConformingResults = new ArrayList<>(); if (results.size() == args.length) { for (int index = 0; index < results.size(); index++) { @@ -173,8 +176,8 @@ private static List> getNonConformingResultsForGetSqlInfo( final String providedName = result.get(0); final String expectedName = Integer.toString(args[index].getNumber()); System.err.println(expectedName); - if (!(GET_SQL_INFO_EXPECTED_RESULTS_MAP.get(providedName).equals(result.get(1)) && - providedName.equals(expectedName))) { + if (!(GET_SQL_INFO_EXPECTED_RESULTS_MAP.get(providedName).equals(result.get(1)) + && providedName.equals(expectedName))) { nonConformingResults.add(result); break; } @@ -186,181 +189,248 @@ private static List> getNonConformingResultsForGetSqlInfo( @Test public void testGetTablesSchema() { final FlightInfo info = sqlClient.getTables(null, null, null, null, true); - MatcherAssert.assertThat(info.getSchemaOptional(), is(Optional.of(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA))); + MatcherAssert.assertThat( + info.getSchemaOptional(), is(Optional.of(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA))); } @Test public void testGetTablesSchemaExcludeSchema() { final FlightInfo info = sqlClient.getTables(null, null, null, null, false); MatcherAssert.assertThat( - info.getSchemaOptional(), - is(Optional.of(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA))); + info.getSchemaOptional(), + is(Optional.of(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA))); } @Test public void testGetTablesResultNoSchema() throws Exception { try (final FlightStream stream = - sqlClient.getStream( - sqlClient.getTables(null, null, null, null, false) - .getEndpoints().get(0).getTicket())) { + sqlClient.getStream( + sqlClient.getTables(null, null, null, null, false).getEndpoints().get(0).getTicket())) { Assertions.assertAll( () -> { - MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA)); + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA)); }, () -> { final List> results = getResults(stream); - final List> expectedResults = ImmutableList.of( - // catalog_name | schema_name | table_name | table_type | table_schema - asList(null /* TODO No catalog yet */, "SYS", "SYSALIASES", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSCHECKS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSCOLPERMS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSCOLUMNS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSCONGLOMERATES", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSCONSTRAINTS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSDEPENDS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSFILES", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSFOREIGNKEYS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSKEYS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSPERMS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSROLES", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSROUTINEPERMS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSSCHEMAS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSSEQUENCES", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSSTATEMENTS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSSTATISTICS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSTABLEPERMS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSTABLES", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSTRIGGERS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSUSERS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYS", "SYSVIEWS", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "SYSIBM", "SYSDUMMY1", "SYSTEM TABLE"), - asList(null /* TODO No catalog yet */, "APP", "FOREIGNTABLE", "TABLE"), - asList(null /* TODO No catalog yet */, "APP", "INTTABLE", "TABLE")); + final List> expectedResults = + ImmutableList.of( + // catalog_name | schema_name | table_name | table_type | table_schema + asList(null /* TODO No catalog yet */, "SYS", "SYSALIASES", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSCHECKS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSCOLPERMS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSCOLUMNS", "SYSTEM TABLE"), + asList( + null /* TODO No catalog yet */, "SYS", "SYSCONGLOMERATES", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSCONSTRAINTS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSDEPENDS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSFILES", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSFOREIGNKEYS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSKEYS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSPERMS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSROLES", "SYSTEM TABLE"), + asList( + null /* TODO No catalog yet */, "SYS", "SYSROUTINEPERMS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSSCHEMAS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSSEQUENCES", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSSTATEMENTS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSSTATISTICS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSTABLEPERMS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSTABLES", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSTRIGGERS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSUSERS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYS", "SYSVIEWS", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "SYSIBM", "SYSDUMMY1", "SYSTEM TABLE"), + asList(null /* TODO No catalog yet */, "APP", "FOREIGNTABLE", "TABLE"), + asList(null /* TODO No catalog yet */, "APP", "INTTABLE", "TABLE")); MatcherAssert.assertThat(results, is(expectedResults)); - } - ); + }); } } @Test public void testGetTablesResultFilteredNoSchema() throws Exception { try (final FlightStream stream = - sqlClient.getStream( - sqlClient.getTables(null, null, null, singletonList("TABLE"), false) - .getEndpoints().get(0).getTicket())) { + sqlClient.getStream( + sqlClient + .getTables(null, null, null, singletonList("TABLE"), false) + .getEndpoints() + .get(0) + .getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA)), + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA)), () -> { final List> results = getResults(stream); - final List> expectedResults = ImmutableList.of( - // catalog_name | schema_name | table_name | table_type | table_schema - asList(null /* TODO No catalog yet */, "APP", "FOREIGNTABLE", "TABLE"), - asList(null /* TODO No catalog yet */, "APP", "INTTABLE", "TABLE")); + final List> expectedResults = + ImmutableList.of( + // catalog_name | schema_name | table_name | table_type | table_schema + asList(null /* TODO No catalog yet */, "APP", "FOREIGNTABLE", "TABLE"), + asList(null /* TODO No catalog yet */, "APP", "INTTABLE", "TABLE")); MatcherAssert.assertThat(results, is(expectedResults)); - } - ); + }); } } @Test public void testGetTablesResultFilteredWithSchema() throws Exception { try (final FlightStream stream = - sqlClient.getStream( - sqlClient.getTables(null, null, null, singletonList("TABLE"), true) - .getEndpoints().get(0).getTicket())) { + sqlClient.getStream( + sqlClient + .getTables(null, null, null, singletonList("TABLE"), true) + .getEndpoints() + .get(0) + .getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA)), + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA)), () -> { - MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA)); + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA)); final List> results = getResults(stream); - final List> expectedResults = ImmutableList.of( - // catalog_name | schema_name | table_name | table_type | table_schema - asList( - null /* TODO No catalog yet */, - "APP", - "FOREIGNTABLE", - "TABLE", - new Schema(asList( - new Field("ID", new FieldType(false, MinorType.INT.getType(), null, - new FlightSqlColumnMetadata.Builder() - .catalogName("") - .typeName("INTEGER") - .schemaName("APP") - .tableName("FOREIGNTABLE") - .precision(10) - .scale(0) - .isAutoIncrement(true) - .build().getMetadataMap()), null), - new Field("FOREIGNNAME", new FieldType(true, MinorType.VARCHAR.getType(), null, - new FlightSqlColumnMetadata.Builder() - .catalogName("") - .typeName("VARCHAR") - .schemaName("APP") - .tableName("FOREIGNTABLE") - .precision(100) - .scale(0) - .isAutoIncrement(false) - .build().getMetadataMap()), null), - new Field("VALUE", new FieldType(true, MinorType.INT.getType(), null, - new FlightSqlColumnMetadata.Builder() - .catalogName("") - .typeName("INTEGER") - .schemaName("APP") - .tableName("FOREIGNTABLE") - .precision(10) - .scale(0) - .isAutoIncrement(false) - .build().getMetadataMap()), null))).toJson()), - asList( - null /* TODO No catalog yet */, - "APP", - "INTTABLE", - "TABLE", - new Schema(asList( - new Field("ID", new FieldType(false, MinorType.INT.getType(), null, - new FlightSqlColumnMetadata.Builder() - .catalogName("") - .typeName("INTEGER") - .schemaName("APP") - .tableName("INTTABLE") - .precision(10) - .scale(0) - .isAutoIncrement(true) - .build().getMetadataMap()), null), - new Field("KEYNAME", new FieldType(true, MinorType.VARCHAR.getType(), null, - new FlightSqlColumnMetadata.Builder() - .catalogName("") - .typeName("VARCHAR") - .schemaName("APP") - .tableName("INTTABLE") - .precision(100) - .scale(0) - .isAutoIncrement(false) - .build().getMetadataMap()), null), - new Field("VALUE", new FieldType(true, MinorType.INT.getType(), null, - new FlightSqlColumnMetadata.Builder() - .catalogName("") - .typeName("INTEGER") - .schemaName("APP") - .tableName("INTTABLE") - .precision(10) - .scale(0) - .isAutoIncrement(false) - .build().getMetadataMap()), null), - new Field("FOREIGNID", new FieldType(true, MinorType.INT.getType(), null, - new FlightSqlColumnMetadata.Builder() - .catalogName("") - .typeName("INTEGER") - .schemaName("APP") - .tableName("INTTABLE") - .precision(10) - .scale(0) - .isAutoIncrement(false) - .build().getMetadataMap()), null))).toJson())); + final List> expectedResults = + ImmutableList.of( + // catalog_name | schema_name | table_name | table_type | table_schema + asList( + null /* TODO No catalog yet */, + "APP", + "FOREIGNTABLE", + "TABLE", + new Schema( + asList( + new Field( + "ID", + new FieldType( + false, + MinorType.INT.getType(), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("") + .typeName("INTEGER") + .schemaName("APP") + .tableName("FOREIGNTABLE") + .precision(10) + .scale(0) + .isAutoIncrement(true) + .build() + .getMetadataMap()), + null), + new Field( + "FOREIGNNAME", + new FieldType( + true, + MinorType.VARCHAR.getType(), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("") + .typeName("VARCHAR") + .schemaName("APP") + .tableName("FOREIGNTABLE") + .precision(100) + .scale(0) + .isAutoIncrement(false) + .build() + .getMetadataMap()), + null), + new Field( + "VALUE", + new FieldType( + true, + MinorType.INT.getType(), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("") + .typeName("INTEGER") + .schemaName("APP") + .tableName("FOREIGNTABLE") + .precision(10) + .scale(0) + .isAutoIncrement(false) + .build() + .getMetadataMap()), + null))) + .toJson()), + asList( + null /* TODO No catalog yet */, + "APP", + "INTTABLE", + "TABLE", + new Schema( + asList( + new Field( + "ID", + new FieldType( + false, + MinorType.INT.getType(), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("") + .typeName("INTEGER") + .schemaName("APP") + .tableName("INTTABLE") + .precision(10) + .scale(0) + .isAutoIncrement(true) + .build() + .getMetadataMap()), + null), + new Field( + "KEYNAME", + new FieldType( + true, + MinorType.VARCHAR.getType(), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("") + .typeName("VARCHAR") + .schemaName("APP") + .tableName("INTTABLE") + .precision(100) + .scale(0) + .isAutoIncrement(false) + .build() + .getMetadataMap()), + null), + new Field( + "VALUE", + new FieldType( + true, + MinorType.INT.getType(), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("") + .typeName("INTEGER") + .schemaName("APP") + .tableName("INTTABLE") + .precision(10) + .scale(0) + .isAutoIncrement(false) + .build() + .getMetadataMap()), + null), + new Field( + "FOREIGNID", + new FieldType( + true, + MinorType.INT.getType(), + null, + new FlightSqlColumnMetadata.Builder() + .catalogName("") + .typeName("INTEGER") + .schemaName("APP") + .tableName("INTTABLE") + .precision(10) + .scale(0) + .isAutoIncrement(false) + .build() + .getMetadataMap()), + null))) + .toJson())); MatcherAssert.assertThat(results, is(expectedResults)); - } - ); + }); } } @@ -371,25 +441,24 @@ public void testSimplePreparedStatementSchema() throws Exception { () -> { final Schema actualSchema = preparedStatement.getResultSetSchema(); MatcherAssert.assertThat(actualSchema, is(SCHEMA_INT_TABLE)); - }, () -> { final FlightInfo info = preparedStatement.execute(); MatcherAssert.assertThat(info.getSchemaOptional(), is(Optional.of(SCHEMA_INT_TABLE))); - } - ); + }); } } @Test public void testSimplePreparedStatementResults() throws Exception { try (final PreparedStatement preparedStatement = sqlClient.prepare("SELECT * FROM intTable"); - final FlightStream stream = sqlClient.getStream( - preparedStatement.execute().getEndpoints().get(0).getTicket())) { + final FlightStream stream = + sqlClient.getStream(preparedStatement.execute().getEndpoints().get(0).getTicket())) { Assertions.assertAll( () -> MatcherAssert.assertThat(stream.getSchema(), is(SCHEMA_INT_TABLE)), - () -> MatcherAssert.assertThat(getResults(stream), is(EXPECTED_RESULTS_FOR_STAR_SELECT_QUERY)) - ); + () -> + MatcherAssert.assertThat( + getResults(stream), is(EXPECTED_RESULTS_FOR_STAR_SELECT_QUERY))); } } @@ -397,7 +466,8 @@ public void testSimplePreparedStatementResults() throws Exception { public void testSimplePreparedStatementResultsWithParameterBinding() throws Exception { try (PreparedStatement prepare = sqlClient.prepare("SELECT * FROM intTable WHERE id = ?")) { final Schema parameterSchema = prepare.getParameterSchema(); - try (final VectorSchemaRoot insertRoot = VectorSchemaRoot.create(parameterSchema, allocator)) { + try (final VectorSchemaRoot insertRoot = + VectorSchemaRoot.create(parameterSchema, allocator)) { insertRoot.allocateNew(); final IntVector valueVector = (IntVector) insertRoot.getVector(0); @@ -407,24 +477,26 @@ public void testSimplePreparedStatementResultsWithParameterBinding() throws Exce prepare.setParameters(insertRoot); FlightInfo flightInfo = prepare.execute(); - FlightStream stream = sqlClient.getStream(flightInfo - .getEndpoints() - .get(0).getTicket()); + FlightStream stream = sqlClient.getStream(flightInfo.getEndpoints().get(0).getTicket()); Assertions.assertAll( () -> MatcherAssert.assertThat(stream.getSchema(), is(SCHEMA_INT_TABLE)), - () -> MatcherAssert.assertThat(getResults(stream), is(EXPECTED_RESULTS_FOR_PARAMETER_BINDING)) - ); + () -> + MatcherAssert.assertThat( + getResults(stream), is(EXPECTED_RESULTS_FOR_PARAMETER_BINDING))); } } } @Test public void testSimplePreparedStatementUpdateResults() throws SQLException { - try (PreparedStatement prepare = sqlClient.prepare("INSERT INTO INTTABLE (keyName, value ) VALUES (?, ?)"); - PreparedStatement deletePrepare = sqlClient.prepare("DELETE FROM INTTABLE WHERE keyName = ?")) { + try (PreparedStatement prepare = + sqlClient.prepare("INSERT INTO INTTABLE (keyName, value ) VALUES (?, ?)"); + PreparedStatement deletePrepare = + sqlClient.prepare("DELETE FROM INTTABLE WHERE keyName = ?")) { final Schema parameterSchema = prepare.getParameterSchema(); - try (final VectorSchemaRoot insertRoot = VectorSchemaRoot.create(parameterSchema, allocator)) { + try (final VectorSchemaRoot insertRoot = + VectorSchemaRoot.create(parameterSchema, allocator)) { final VarCharVector varCharVector = (VarCharVector) insertRoot.getVector(0); final IntVector valueVector = (IntVector) insertRoot.getVector(1); final int counter = 10; @@ -432,10 +504,11 @@ public void testSimplePreparedStatementUpdateResults() throws SQLException { final IntStream range = IntStream.range(0, counter); - range.forEach(i -> { - valueVector.setSafe(i, i * counter); - varCharVector.setSafe(i, new Text("value" + i)); - }); + range.forEach( + i -> { + valueVector.setSafe(i, i * counter); + varCharVector.setSafe(i, new Text("value" + i)); + }); insertRoot.setRowCount(counter); @@ -449,25 +522,24 @@ public void testSimplePreparedStatementUpdateResults() throws SQLException { } Assertions.assertAll( () -> MatcherAssert.assertThat(updatedRows, is(10L)), - () -> MatcherAssert.assertThat(deletedRows, is(10L)) - ); + () -> MatcherAssert.assertThat(deletedRows, is(10L))); } } } @Test public void testSimplePreparedStatementUpdateResultsWithoutParameters() throws SQLException { - try (PreparedStatement prepare = sqlClient - .prepare("INSERT INTO INTTABLE (keyName, value ) VALUES ('test', 1000)"); - PreparedStatement deletePrepare = sqlClient.prepare("DELETE FROM INTTABLE WHERE keyName = 'test'")) { + try (PreparedStatement prepare = + sqlClient.prepare("INSERT INTO INTTABLE (keyName, value ) VALUES ('test', 1000)"); + PreparedStatement deletePrepare = + sqlClient.prepare("DELETE FROM INTTABLE WHERE keyName = 'test'")) { final long updatedRows = prepare.executeUpdate(); final long deletedRows = deletePrepare.executeUpdate(); Assertions.assertAll( () -> MatcherAssert.assertThat(updatedRows, is(1L)), - () -> MatcherAssert.assertThat(deletedRows, is(1L)) - ); + () -> MatcherAssert.assertThat(deletedRows, is(1L))); } } @@ -481,27 +553,28 @@ public void testSimplePreparedStatementClosesProperly() { () -> { preparedStatement.close(); MatcherAssert.assertThat(preparedStatement.isClosed(), is(true)); - } - ); + }); } @Test public void testGetCatalogsSchema() { final FlightInfo info = sqlClient.getCatalogs(); - MatcherAssert.assertThat(info.getSchemaOptional(), is(Optional.of(FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA))); + MatcherAssert.assertThat( + info.getSchemaOptional(), is(Optional.of(FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA))); } @Test public void testGetCatalogsResults() throws Exception { try (final FlightStream stream = - sqlClient.getStream(sqlClient.getCatalogs().getEndpoints().get(0).getTicket())) { + sqlClient.getStream(sqlClient.getCatalogs().getEndpoints().get(0).getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA)), + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_CATALOGS_SCHEMA)), () -> { List> catalogs = getResults(stream); MatcherAssert.assertThat(catalogs, is(emptyList())); - } - ); + }); } } @@ -509,65 +582,67 @@ public void testGetCatalogsResults() throws Exception { public void testGetTableTypesSchema() { final FlightInfo info = sqlClient.getTableTypes(); MatcherAssert.assertThat( - info.getSchemaOptional(), - is(Optional.of(FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA))); + info.getSchemaOptional(), + is(Optional.of(FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA))); } @Test public void testGetTableTypesResult() throws Exception { try (final FlightStream stream = - sqlClient.getStream(sqlClient.getTableTypes().getEndpoints().get(0).getTicket())) { + sqlClient.getStream(sqlClient.getTableTypes().getEndpoints().get(0).getTicket())) { Assertions.assertAll( () -> { - MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA)); + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA)); }, () -> { final List> tableTypes = getResults(stream); - final List> expectedTableTypes = ImmutableList.of( - // table_type - singletonList("SYNONYM"), - singletonList("SYSTEM TABLE"), - singletonList("TABLE"), - singletonList("VIEW") - ); + final List> expectedTableTypes = + ImmutableList.of( + // table_type + singletonList("SYNONYM"), + singletonList("SYSTEM TABLE"), + singletonList("TABLE"), + singletonList("VIEW")); MatcherAssert.assertThat(tableTypes, is(expectedTableTypes)); - } - ); + }); } } @Test public void testGetSchemasSchema() { final FlightInfo info = sqlClient.getSchemas(null, null); - MatcherAssert.assertThat(info.getSchemaOptional(), is(Optional.of(FlightSqlProducer.Schemas.GET_SCHEMAS_SCHEMA))); + MatcherAssert.assertThat( + info.getSchemaOptional(), is(Optional.of(FlightSqlProducer.Schemas.GET_SCHEMAS_SCHEMA))); } @Test public void testGetSchemasResult() throws Exception { try (final FlightStream stream = - sqlClient.getStream(sqlClient.getSchemas(null, null).getEndpoints().get(0).getTicket())) { + sqlClient.getStream(sqlClient.getSchemas(null, null).getEndpoints().get(0).getTicket())) { Assertions.assertAll( () -> { - MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SCHEMAS_SCHEMA)); + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SCHEMAS_SCHEMA)); }, () -> { final List> schemas = getResults(stream); - final List> expectedSchemas = ImmutableList.of( - // catalog_name | schema_name - asList(null /* TODO Add catalog. */, "APP"), - asList(null /* TODO Add catalog. */, "NULLID"), - asList(null /* TODO Add catalog. */, "SQLJ"), - asList(null /* TODO Add catalog. */, "SYS"), - asList(null /* TODO Add catalog. */, "SYSCAT"), - asList(null /* TODO Add catalog. */, "SYSCS_DIAG"), - asList(null /* TODO Add catalog. */, "SYSCS_UTIL"), - asList(null /* TODO Add catalog. */, "SYSFUN"), - asList(null /* TODO Add catalog. */, "SYSIBM"), - asList(null /* TODO Add catalog. */, "SYSPROC"), - asList(null /* TODO Add catalog. */, "SYSSTAT")); + final List> expectedSchemas = + ImmutableList.of( + // catalog_name | schema_name + asList(null /* TODO Add catalog. */, "APP"), + asList(null /* TODO Add catalog. */, "NULLID"), + asList(null /* TODO Add catalog. */, "SQLJ"), + asList(null /* TODO Add catalog. */, "SYS"), + asList(null /* TODO Add catalog. */, "SYSCAT"), + asList(null /* TODO Add catalog. */, "SYSCS_DIAG"), + asList(null /* TODO Add catalog. */, "SYSCS_UTIL"), + asList(null /* TODO Add catalog. */, "SYSFUN"), + asList(null /* TODO Add catalog. */, "SYSIBM"), + asList(null /* TODO Add catalog. */, "SYSPROC"), + asList(null /* TODO Add catalog. */, "SYSSTAT")); MatcherAssert.assertThat(schemas, is(expectedSchemas)); - } - ); + }); } } @@ -588,16 +663,15 @@ public void testGetPrimaryKey() { () -> MatcherAssert.assertThat(result.get(2), is("INTTABLE")), () -> MatcherAssert.assertThat(result.get(3), is("ID")), () -> MatcherAssert.assertThat(result.get(4), is("1")), - () -> MatcherAssert.assertThat(result.get(5), notNullValue()) - ); - } - ); + () -> MatcherAssert.assertThat(result.get(5), notNullValue())); + }); } @Test public void testGetSqlInfoSchema() { final FlightInfo info = sqlClient.getSqlInfo(); - MatcherAssert.assertThat(info.getSchemaOptional(), is(Optional.of(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA))); + MatcherAssert.assertThat( + info.getSchemaOptional(), is(Optional.of(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA))); } @Test @@ -605,9 +679,12 @@ public void testGetSqlInfoResults() throws Exception { final FlightInfo info = sqlClient.getSqlInfo(); try (final FlightStream stream = sqlClient.getStream(info.getEndpoints().get(0).getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA)), - () -> MatcherAssert.assertThat(getNonConformingResultsForGetSqlInfo(getResults(stream)), is(emptyList())) - ); + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA)), + () -> + MatcherAssert.assertThat( + getNonConformingResultsForGetSqlInfo(getResults(stream)), is(emptyList()))); } } @@ -617,40 +694,41 @@ public void testGetSqlInfoResultsWithSingleArg() throws Exception { final FlightInfo info = sqlClient.getSqlInfo(arg); try (final FlightStream stream = sqlClient.getStream(info.getEndpoints().get(0).getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA)), - () -> MatcherAssert.assertThat(getNonConformingResultsForGetSqlInfo(getResults(stream), arg), is(emptyList())) - ); + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA)), + () -> + MatcherAssert.assertThat( + getNonConformingResultsForGetSqlInfo(getResults(stream), arg), is(emptyList()))); } } @Test public void testGetSqlInfoResultsWithManyArgs() throws Exception { final FlightSql.SqlInfo[] args = { - FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME, - FlightSql.SqlInfo.FLIGHT_SQL_SERVER_VERSION, - FlightSql.SqlInfo.FLIGHT_SQL_SERVER_ARROW_VERSION, - FlightSql.SqlInfo.FLIGHT_SQL_SERVER_READ_ONLY, - FlightSql.SqlInfo.SQL_ALL_TABLES_ARE_SELECTABLE, - FlightSql.SqlInfo.SQL_NULL_ORDERING, - FlightSql.SqlInfo.SQL_DDL_CATALOG, - FlightSql.SqlInfo.SQL_DDL_SCHEMA, - FlightSql.SqlInfo.SQL_DDL_TABLE, - FlightSql.SqlInfo.SQL_IDENTIFIER_CASE, - FlightSql.SqlInfo.SQL_IDENTIFIER_QUOTE_CHAR, - FlightSql.SqlInfo.SQL_QUOTED_IDENTIFIER_CASE, - FlightSql.SqlInfo.SQL_MAX_COLUMNS_IN_TABLE}; + FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME, + FlightSql.SqlInfo.FLIGHT_SQL_SERVER_VERSION, + FlightSql.SqlInfo.FLIGHT_SQL_SERVER_ARROW_VERSION, + FlightSql.SqlInfo.FLIGHT_SQL_SERVER_READ_ONLY, + FlightSql.SqlInfo.SQL_ALL_TABLES_ARE_SELECTABLE, + FlightSql.SqlInfo.SQL_NULL_ORDERING, + FlightSql.SqlInfo.SQL_DDL_CATALOG, + FlightSql.SqlInfo.SQL_DDL_SCHEMA, + FlightSql.SqlInfo.SQL_DDL_TABLE, + FlightSql.SqlInfo.SQL_IDENTIFIER_CASE, + FlightSql.SqlInfo.SQL_IDENTIFIER_QUOTE_CHAR, + FlightSql.SqlInfo.SQL_QUOTED_IDENTIFIER_CASE, + FlightSql.SqlInfo.SQL_MAX_COLUMNS_IN_TABLE + }; final FlightInfo info = sqlClient.getSqlInfo(args); try (final FlightStream stream = sqlClient.getStream(info.getEndpoints().get(0).getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat( - stream.getSchema(), - is(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA) - ), - () -> MatcherAssert.assertThat( - getNonConformingResultsForGetSqlInfo(getResults(stream), args), - is(emptyList()) - ) - ); + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA)), + () -> + MatcherAssert.assertThat( + getNonConformingResultsForGetSqlInfo(getResults(stream), args), is(emptyList()))); } } @@ -658,25 +736,29 @@ public void testGetSqlInfoResultsWithManyArgs() throws Exception { public void testGetCommandExportedKeys() throws Exception { try (final FlightStream stream = sqlClient.getStream( - sqlClient.getExportedKeys(TableRef.of(null, null, "FOREIGNTABLE")) - .getEndpoints().get(0).getTicket())) { + sqlClient + .getExportedKeys(TableRef.of(null, null, "FOREIGNTABLE")) + .getEndpoints() + .get(0) + .getTicket())) { final List> results = getResults(stream); - final List> matchers = asList( - nullValue(String.class), // pk_catalog_name - is("APP"), // pk_schema_name - is("FOREIGNTABLE"), // pk_table_name - is("ID"), // pk_column_name - nullValue(String.class), // fk_catalog_name - is("APP"), // fk_schema_name - is("INTTABLE"), // fk_table_name - is("FOREIGNID"), // fk_column_name - is("1"), // key_sequence - containsString("SQL"), // fk_key_name - containsString("SQL"), // pk_key_name - is("3"), // update_rule - is("3")); // delete_rule + final List> matchers = + asList( + nullValue(String.class), // pk_catalog_name + is("APP"), // pk_schema_name + is("FOREIGNTABLE"), // pk_table_name + is("ID"), // pk_column_name + nullValue(String.class), // fk_catalog_name + is("APP"), // fk_schema_name + is("INTTABLE"), // fk_table_name + is("FOREIGNID"), // fk_column_name + is("1"), // key_sequence + containsString("SQL"), // fk_key_name + containsString("SQL"), // pk_key_name + is("3"), // update_rule + is("3")); // delete_rule final List assertions = new ArrayList<>(); Assertions.assertEquals(1, results.size()); @@ -693,25 +775,29 @@ public void testGetCommandExportedKeys() throws Exception { public void testGetCommandImportedKeys() throws Exception { try (final FlightStream stream = sqlClient.getStream( - sqlClient.getImportedKeys(TableRef.of(null, null, "INTTABLE")) - .getEndpoints().get(0).getTicket())) { + sqlClient + .getImportedKeys(TableRef.of(null, null, "INTTABLE")) + .getEndpoints() + .get(0) + .getTicket())) { final List> results = getResults(stream); - final List> matchers = asList( - nullValue(String.class), // pk_catalog_name - is("APP"), // pk_schema_name - is("FOREIGNTABLE"), // pk_table_name - is("ID"), // pk_column_name - nullValue(String.class), // fk_catalog_name - is("APP"), // fk_schema_name - is("INTTABLE"), // fk_table_name - is("FOREIGNID"), // fk_column_name - is("1"), // key_sequence - containsString("SQL"), // fk_key_name - containsString("SQL"), // pk_key_name - is("3"), // update_rule - is("3")); // delete_rule + final List> matchers = + asList( + nullValue(String.class), // pk_catalog_name + is("APP"), // pk_schema_name + is("FOREIGNTABLE"), // pk_table_name + is("ID"), // pk_column_name + nullValue(String.class), // fk_catalog_name + is("APP"), // fk_schema_name + is("INTTABLE"), // fk_table_name + is("FOREIGNID"), // fk_column_name + is("1"), // key_sequence + containsString("SQL"), // fk_key_name + containsString("SQL"), // pk_key_name + is("3"), // update_rule + is("3")); // delete_rule Assertions.assertEquals(1, results.size()); final List assertions = new ArrayList<>(); @@ -732,73 +818,448 @@ public void testGetTypeInfo() throws Exception { final List> results = getResults(stream); - final List> matchers = ImmutableList.of( - asList("BIGINT", "-5", "19", null, null, emptyList().toString(), "1", "false", "2", "false", "false", "true", - "BIGINT", "0", "0", - null, null, "10", null), - asList("LONG VARCHAR FOR BIT DATA", "-4", "32700", "X'", "'", emptyList().toString(), "1", "false", "0", - "true", "false", "false", - "LONG VARCHAR FOR BIT DATA", null, null, null, null, null, null), - asList("VARCHAR () FOR BIT DATA", "-3", "32672", "X'", "'", singletonList("length").toString(), "1", "false", - "2", "true", "false", - "false", "VARCHAR () FOR BIT DATA", null, null, null, null, null, null), - asList("CHAR () FOR BIT DATA", "-2", "254", "X'", "'", singletonList("length").toString(), "1", "false", "2", - "true", "false", "false", - "CHAR () FOR BIT DATA", null, null, null, null, null, null), - asList("LONG VARCHAR", "-1", "32700", "'", "'", emptyList().toString(), "1", "true", "1", "true", "false", - "false", - "LONG VARCHAR", null, null, null, null, null, null), - asList("CHAR", "1", "254", "'", "'", singletonList("length").toString(), "1", "true", "3", "true", "false", - "false", "CHAR", null, null, - null, null, null, null), - asList("NUMERIC", "2", "31", null, null, Arrays.asList("precision", "scale").toString(), "1", "false", "2", - "false", "true", "false", - "NUMERIC", "0", "31", null, null, "10", null), - asList("DECIMAL", "3", "31", null, null, Arrays.asList("precision", "scale").toString(), "1", "false", "2", - "false", "true", "false", - "DECIMAL", "0", "31", null, null, "10", null), - asList("INTEGER", "4", "10", null, null, emptyList().toString(), "1", "false", "2", "false", "false", "true", - "INTEGER", "0", "0", - null, null, "10", null), - asList("SMALLINT", "5", "5", null, null, emptyList().toString(), "1", "false", "2", "false", "false", "true", - "SMALLINT", "0", - "0", null, null, "10", null), - asList("FLOAT", "6", "52", null, null, singletonList("precision").toString(), "1", "false", "2", "false", - "false", "false", "FLOAT", null, - null, null, null, "2", null), - asList("REAL", "7", "23", null, null, emptyList().toString(), "1", "false", "2", "false", "false", "false", - "REAL", null, null, - null, null, "2", null), - asList("DOUBLE", "8", "52", null, null, emptyList().toString(), "1", "false", "2", "false", "false", "false", - "DOUBLE", null, - null, null, null, "2", null), - asList("VARCHAR", "12", "32672", "'", "'", singletonList("length").toString(), "1", "true", "3", "true", - "false", "false", "VARCHAR", - null, null, null, null, null, null), - asList("BOOLEAN", "16", "1", null, null, emptyList().toString(), "1", "false", "2", "true", "false", "false", - "BOOLEAN", null, - null, null, null, null, null), - asList("DATE", "91", "10", "DATE'", "'", emptyList().toString(), "1", "false", "2", "true", "false", "false", - "DATE", "0", "0", - null, null, "10", null), - asList("TIME", "92", "8", "TIME'", "'", emptyList().toString(), "1", "false", "2", "true", "false", "false", - "TIME", "0", "0", - null, null, "10", null), - asList("TIMESTAMP", "93", "29", "TIMESTAMP'", "'", emptyList().toString(), "1", "false", "2", "true", "false", - "false", - "TIMESTAMP", "0", "9", null, null, "10", null), - asList("OBJECT", "2000", null, null, null, emptyList().toString(), "1", "false", "2", "true", "false", - "false", "OBJECT", null, - null, null, null, null, null), - asList("BLOB", "2004", "2147483647", null, null, singletonList("length").toString(), "1", "false", "0", null, - "false", null, "BLOB", null, - null, null, null, null, null), - asList("CLOB", "2005", "2147483647", "'", "'", singletonList("length").toString(), "1", "true", "1", null, - "false", null, "CLOB", null, - null, null, null, null, null), - asList("XML", "2009", null, null, null, emptyList().toString(), "1", "true", "0", "false", "false", "false", - "XML", null, null, - null, null, null, null)); + final List> matchers = + ImmutableList.of( + asList( + "BIGINT", + "-5", + "19", + null, + null, + emptyList().toString(), + "1", + "false", + "2", + "false", + "false", + "true", + "BIGINT", + "0", + "0", + null, + null, + "10", + null), + asList( + "LONG VARCHAR FOR BIT DATA", + "-4", + "32700", + "X'", + "'", + emptyList().toString(), + "1", + "false", + "0", + "true", + "false", + "false", + "LONG VARCHAR FOR BIT DATA", + null, + null, + null, + null, + null, + null), + asList( + "VARCHAR () FOR BIT DATA", + "-3", + "32672", + "X'", + "'", + singletonList("length").toString(), + "1", + "false", + "2", + "true", + "false", + "false", + "VARCHAR () FOR BIT DATA", + null, + null, + null, + null, + null, + null), + asList( + "CHAR () FOR BIT DATA", + "-2", + "254", + "X'", + "'", + singletonList("length").toString(), + "1", + "false", + "2", + "true", + "false", + "false", + "CHAR () FOR BIT DATA", + null, + null, + null, + null, + null, + null), + asList( + "LONG VARCHAR", + "-1", + "32700", + "'", + "'", + emptyList().toString(), + "1", + "true", + "1", + "true", + "false", + "false", + "LONG VARCHAR", + null, + null, + null, + null, + null, + null), + asList( + "CHAR", + "1", + "254", + "'", + "'", + singletonList("length").toString(), + "1", + "true", + "3", + "true", + "false", + "false", + "CHAR", + null, + null, + null, + null, + null, + null), + asList( + "NUMERIC", + "2", + "31", + null, + null, + Arrays.asList("precision", "scale").toString(), + "1", + "false", + "2", + "false", + "true", + "false", + "NUMERIC", + "0", + "31", + null, + null, + "10", + null), + asList( + "DECIMAL", + "3", + "31", + null, + null, + Arrays.asList("precision", "scale").toString(), + "1", + "false", + "2", + "false", + "true", + "false", + "DECIMAL", + "0", + "31", + null, + null, + "10", + null), + asList( + "INTEGER", + "4", + "10", + null, + null, + emptyList().toString(), + "1", + "false", + "2", + "false", + "false", + "true", + "INTEGER", + "0", + "0", + null, + null, + "10", + null), + asList( + "SMALLINT", + "5", + "5", + null, + null, + emptyList().toString(), + "1", + "false", + "2", + "false", + "false", + "true", + "SMALLINT", + "0", + "0", + null, + null, + "10", + null), + asList( + "FLOAT", + "6", + "52", + null, + null, + singletonList("precision").toString(), + "1", + "false", + "2", + "false", + "false", + "false", + "FLOAT", + null, + null, + null, + null, + "2", + null), + asList( + "REAL", + "7", + "23", + null, + null, + emptyList().toString(), + "1", + "false", + "2", + "false", + "false", + "false", + "REAL", + null, + null, + null, + null, + "2", + null), + asList( + "DOUBLE", + "8", + "52", + null, + null, + emptyList().toString(), + "1", + "false", + "2", + "false", + "false", + "false", + "DOUBLE", + null, + null, + null, + null, + "2", + null), + asList( + "VARCHAR", + "12", + "32672", + "'", + "'", + singletonList("length").toString(), + "1", + "true", + "3", + "true", + "false", + "false", + "VARCHAR", + null, + null, + null, + null, + null, + null), + asList( + "BOOLEAN", + "16", + "1", + null, + null, + emptyList().toString(), + "1", + "false", + "2", + "true", + "false", + "false", + "BOOLEAN", + null, + null, + null, + null, + null, + null), + asList( + "DATE", + "91", + "10", + "DATE'", + "'", + emptyList().toString(), + "1", + "false", + "2", + "true", + "false", + "false", + "DATE", + "0", + "0", + null, + null, + "10", + null), + asList( + "TIME", + "92", + "8", + "TIME'", + "'", + emptyList().toString(), + "1", + "false", + "2", + "true", + "false", + "false", + "TIME", + "0", + "0", + null, + null, + "10", + null), + asList( + "TIMESTAMP", + "93", + "29", + "TIMESTAMP'", + "'", + emptyList().toString(), + "1", + "false", + "2", + "true", + "false", + "false", + "TIMESTAMP", + "0", + "9", + null, + null, + "10", + null), + asList( + "OBJECT", + "2000", + null, + null, + null, + emptyList().toString(), + "1", + "false", + "2", + "true", + "false", + "false", + "OBJECT", + null, + null, + null, + null, + null, + null), + asList( + "BLOB", + "2004", + "2147483647", + null, + null, + singletonList("length").toString(), + "1", + "false", + "0", + null, + "false", + null, + "BLOB", + null, + null, + null, + null, + null, + null), + asList( + "CLOB", + "2005", + "2147483647", + "'", + "'", + singletonList("length").toString(), + "1", + "true", + "1", + null, + "false", + null, + "CLOB", + null, + null, + null, + null, + null, + null), + asList( + "XML", + "2009", + null, + null, + null, + emptyList().toString(), + "1", + "true", + "0", + "false", + "false", + "false", + "XML", + null, + null, + null, + null, + null, + null)); MatcherAssert.assertThat(results, is(matchers)); } } @@ -811,36 +1272,57 @@ public void testGetTypeInfoWithFiltering() throws Exception { final List> results = getResults(stream); - final List> matchers = ImmutableList.of( - asList("BIGINT", "-5", "19", null, null, emptyList().toString(), "1", "false", "2", "false", "false", "true", - "BIGINT", "0", "0", - null, null, "10", null)); + final List> matchers = + ImmutableList.of( + asList( + "BIGINT", + "-5", + "19", + null, + null, + emptyList().toString(), + "1", + "false", + "2", + "false", + "false", + "true", + "BIGINT", + "0", + "0", + null, + null, + "10", + null)); MatcherAssert.assertThat(results, is(matchers)); } } @Test public void testGetCommandCrossReference() throws Exception { - final FlightInfo flightInfo = sqlClient.getCrossReference(TableRef.of(null, null, - "FOREIGNTABLE"), TableRef.of(null, null, "INTTABLE")); - try (final FlightStream stream = sqlClient.getStream(flightInfo.getEndpoints().get(0).getTicket())) { + final FlightInfo flightInfo = + sqlClient.getCrossReference( + TableRef.of(null, null, "FOREIGNTABLE"), TableRef.of(null, null, "INTTABLE")); + try (final FlightStream stream = + sqlClient.getStream(flightInfo.getEndpoints().get(0).getTicket())) { final List> results = getResults(stream); - final List> matchers = asList( - nullValue(String.class), // pk_catalog_name - is("APP"), // pk_schema_name - is("FOREIGNTABLE"), // pk_table_name - is("ID"), // pk_column_name - nullValue(String.class), // fk_catalog_name - is("APP"), // fk_schema_name - is("INTTABLE"), // fk_table_name - is("FOREIGNID"), // fk_column_name - is("1"), // key_sequence - containsString("SQL"), // fk_key_name - containsString("SQL"), // pk_key_name - is("3"), // update_rule - is("3")); // delete_rule + final List> matchers = + asList( + nullValue(String.class), // pk_catalog_name + is("APP"), // pk_schema_name + is("FOREIGNTABLE"), // pk_table_name + is("ID"), // pk_column_name + nullValue(String.class), // fk_catalog_name + is("APP"), // fk_schema_name + is("INTTABLE"), // fk_table_name + is("FOREIGNID"), // fk_column_name + is("1"), // key_sequence + containsString("SQL"), // fk_key_name + containsString("SQL"), // pk_key_name + is("3"), // update_rule + is("3")); // delete_rule Assertions.assertEquals(1, results.size()); final List assertions = new ArrayList<>(); @@ -868,16 +1350,17 @@ public void testCreateStatementSchema() throws Exception { @Test public void testCreateStatementResults() throws Exception { - try (final FlightStream stream = sqlClient - .getStream(sqlClient.execute("SELECT * FROM intTable").getEndpoints().get(0).getTicket())) { + try (final FlightStream stream = + sqlClient.getStream( + sqlClient.execute("SELECT * FROM intTable").getEndpoints().get(0).getTicket())) { Assertions.assertAll( () -> { MatcherAssert.assertThat(stream.getSchema(), is(SCHEMA_INT_TABLE)); }, () -> { - MatcherAssert.assertThat(getResults(stream), is(EXPECTED_RESULTS_FOR_STAR_SELECT_QUERY)); - } - ); + MatcherAssert.assertThat( + getResults(stream), is(EXPECTED_RESULTS_FOR_STAR_SELECT_QUERY)); + }); } } @@ -885,36 +1368,38 @@ public void testCreateStatementResults() throws Exception { public void testExecuteUpdate() { Assertions.assertAll( () -> { - long insertedCount = sqlClient.executeUpdate("INSERT INTO INTTABLE (keyName, value) VALUES " + - "('KEYNAME1', 1001), ('KEYNAME2', 1002), ('KEYNAME3', 1003)"); + long insertedCount = + sqlClient.executeUpdate( + "INSERT INTO INTTABLE (keyName, value) VALUES " + + "('KEYNAME1', 1001), ('KEYNAME2', 1002), ('KEYNAME3', 1003)"); MatcherAssert.assertThat(insertedCount, is(3L)); - }, () -> { - long updatedCount = sqlClient.executeUpdate("UPDATE INTTABLE SET keyName = 'KEYNAME1' " + - "WHERE keyName = 'KEYNAME2' OR keyName = 'KEYNAME3'"); + long updatedCount = + sqlClient.executeUpdate( + "UPDATE INTTABLE SET keyName = 'KEYNAME1' " + + "WHERE keyName = 'KEYNAME2' OR keyName = 'KEYNAME3'"); MatcherAssert.assertThat(updatedCount, is(2L)); - }, () -> { - long deletedCount = sqlClient.executeUpdate("DELETE FROM INTTABLE WHERE keyName = 'KEYNAME1'"); + long deletedCount = + sqlClient.executeUpdate("DELETE FROM INTTABLE WHERE keyName = 'KEYNAME1'"); MatcherAssert.assertThat(deletedCount, is(3L)); - } - ); + }); } @Test public void testQueryWithNoResultsShouldNotHang() throws Exception { - try (final PreparedStatement preparedStatement = sqlClient.prepare("SELECT * FROM intTable WHERE 1 = 0"); - final FlightStream stream = sqlClient - .getStream(preparedStatement.execute().getEndpoints().get(0).getTicket())) { + try (final PreparedStatement preparedStatement = + sqlClient.prepare("SELECT * FROM intTable WHERE 1 = 0"); + final FlightStream stream = + sqlClient.getStream(preparedStatement.execute().getEndpoints().get(0).getTicket())) { Assertions.assertAll( () -> MatcherAssert.assertThat(stream.getSchema(), is(SCHEMA_INT_TABLE)), () -> { final List> result = getResults(stream); MatcherAssert.assertThat(result, is(emptyList())); - } - ); + }); } } @@ -922,22 +1407,28 @@ public void testQueryWithNoResultsShouldNotHang() throws Exception { public void testCancelFlightInfo() { FlightInfo info = sqlClient.getSqlInfo(); CancelFlightInfoRequest request = new CancelFlightInfoRequest(info); - FlightRuntimeException fre = assertThrows(FlightRuntimeException.class, () -> sqlClient.cancelFlightInfo(request)); + FlightRuntimeException fre = + assertThrows(FlightRuntimeException.class, () -> sqlClient.cancelFlightInfo(request)); Assertions.assertEquals(FlightStatusCode.UNIMPLEMENTED, fre.status().code()); } @Test public void testCancelQuery() { FlightInfo info = sqlClient.getSqlInfo(); - FlightRuntimeException fre = assertThrows(FlightRuntimeException.class, () -> sqlClient.cancelQuery(info)); + FlightRuntimeException fre = + assertThrows(FlightRuntimeException.class, () -> sqlClient.cancelQuery(info)); assertEquals(FlightStatusCode.UNIMPLEMENTED, fre.status().code()); } @Test public void testRenewEndpoint() { FlightInfo info = sqlClient.getSqlInfo(); - FlightRuntimeException fre = assertThrows(FlightRuntimeException.class, - () -> sqlClient.renewFlightEndpoint(new RenewFlightEndpointRequest(info.getEndpoints().get(0)))); + FlightRuntimeException fre = + assertThrows( + FlightRuntimeException.class, + () -> + sqlClient.renewFlightEndpoint( + new RenewFlightEndpointRequest(info.getEndpoints().get(0)))); assertEquals(FlightStatusCode.UNIMPLEMENTED, fre.status().code()); } } diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/test/TestFlightSqlStreams.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/test/TestFlightSqlStreams.java index 1dd96f0fd4e..4fae0d1ab79 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/test/TestFlightSqlStreams.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/test/TestFlightSqlStreams.java @@ -25,9 +25,11 @@ import static org.apache.arrow.vector.types.Types.MinorType.INT; import static org.hamcrest.CoreMatchers.is; +import com.google.common.collect.ImmutableList; +import com.google.protobuf.Any; +import com.google.protobuf.Message; import java.util.Collections; import java.util.List; - import org.apache.arrow.flight.CallStatus; import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightDescriptor; @@ -57,23 +59,21 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.protobuf.Any; -import com.google.protobuf.Message; - public class TestFlightSqlStreams { /** - * A limited {@link FlightSqlProducer} for testing GetTables, GetTableTypes, GetSqlInfo, and limited SQL commands. + * A limited {@link FlightSqlProducer} for testing GetTables, GetTableTypes, GetSqlInfo, and + * limited SQL commands. */ private static class FlightSqlTestProducer extends BasicFlightSqlProducer { - // Note that for simplicity the getStream* implementations are blocking, but a proper FlightSqlProducer should + // Note that for simplicity the getStream* implementations are blocking, but a proper + // FlightSqlProducer should // have non-blocking implementations of getStream*. private static final String FIXED_QUERY = "SELECT 1 AS c1 FROM test_table"; - private static final Schema FIXED_SCHEMA = new Schema(asList( - Field.nullable("c1", Types.MinorType.INT.getType()))); + private static final Schema FIXED_SCHEMA = + new Schema(asList(Field.nullable("c1", Types.MinorType.INT.getType()))); private BufferAllocator allocator; @@ -82,39 +82,45 @@ private static class FlightSqlTestProducer extends BasicFlightSqlProducer { } @Override - protected List determineEndpoints(T request, FlightDescriptor flightDescriptor, - Schema schema) { - if (request instanceof FlightSql.CommandGetTables || - request instanceof FlightSql.CommandGetTableTypes || - request instanceof FlightSql.CommandGetXdbcTypeInfo || - request instanceof FlightSql.CommandGetSqlInfo) { - return Collections.singletonList(new FlightEndpoint(new Ticket(Any.pack(request).toByteArray()))); - } else if (request instanceof FlightSql.CommandStatementQuery && - ((FlightSql.CommandStatementQuery) request).getQuery().equals(FIXED_QUERY)) { - - // Tickets from CommandStatementQuery requests should be built using TicketStatementQuery then packed() into - // a ticket. The content of the statement handle is specific to the FlightSqlProducer. It does not need to + protected List determineEndpoints( + T request, FlightDescriptor flightDescriptor, Schema schema) { + if (request instanceof FlightSql.CommandGetTables + || request instanceof FlightSql.CommandGetTableTypes + || request instanceof FlightSql.CommandGetXdbcTypeInfo + || request instanceof FlightSql.CommandGetSqlInfo) { + return Collections.singletonList( + new FlightEndpoint(new Ticket(Any.pack(request).toByteArray()))); + } else if (request instanceof FlightSql.CommandStatementQuery + && ((FlightSql.CommandStatementQuery) request).getQuery().equals(FIXED_QUERY)) { + + // Tickets from CommandStatementQuery requests should be built using TicketStatementQuery + // then packed() into + // a ticket. The content of the statement handle is specific to the FlightSqlProducer. It + // does not need to // be the query. It can be a query ID for example. - FlightSql.TicketStatementQuery ticketStatementQuery = FlightSql.TicketStatementQuery.newBuilder() - .setStatementHandle(((FlightSql.CommandStatementQuery) request).getQueryBytes()) - .build(); - return Collections.singletonList(new FlightEndpoint(new Ticket(Any.pack(ticketStatementQuery).toByteArray()))); + FlightSql.TicketStatementQuery ticketStatementQuery = + FlightSql.TicketStatementQuery.newBuilder() + .setStatementHandle(((FlightSql.CommandStatementQuery) request).getQueryBytes()) + .build(); + return Collections.singletonList( + new FlightEndpoint(new Ticket(Any.pack(ticketStatementQuery).toByteArray()))); } throw CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException(); } @Override - public FlightInfo getFlightInfoStatement(FlightSql.CommandStatementQuery command, - CallContext context, FlightDescriptor descriptor) { + public FlightInfo getFlightInfoStatement( + FlightSql.CommandStatementQuery command, CallContext context, FlightDescriptor descriptor) { return generateFlightInfo(command, descriptor, FIXED_SCHEMA); } @Override - public void getStreamStatement(FlightSql.TicketStatementQuery ticket, - CallContext context, ServerStreamListener listener) { + public void getStreamStatement( + FlightSql.TicketStatementQuery ticket, CallContext context, ServerStreamListener listener) { final String query = ticket.getStatementHandle().toStringUtf8(); if (!query.equals(FIXED_QUERY)) { - listener.error(CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); + listener.error( + CallStatus.UNIMPLEMENTED.withDescription("Not implemented.").toRuntimeException()); } try (VectorSchemaRoot root = VectorSchemaRoot.create(FIXED_SCHEMA, allocator)) { @@ -127,9 +133,10 @@ public void getStreamStatement(FlightSql.TicketStatementQuery ticket, } @Override - public void getStreamSqlInfo(FlightSql.CommandGetSqlInfo command, CallContext context, - ServerStreamListener listener) { - try (VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_SQL_INFO_SCHEMA, allocator)) { + public void getStreamSqlInfo( + FlightSql.CommandGetSqlInfo command, CallContext context, ServerStreamListener listener) { + try (VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_SQL_INFO_SCHEMA, allocator)) { root.setRowCount(0); listener.start(root); listener.putNext(); @@ -138,9 +145,12 @@ public void getStreamSqlInfo(FlightSql.CommandGetSqlInfo command, CallContext co } @Override - public void getStreamTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, - CallContext context, ServerStreamListener listener) { - try (VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_TYPE_INFO_SCHEMA, allocator)) { + public void getStreamTypeInfo( + FlightSql.CommandGetXdbcTypeInfo request, + CallContext context, + ServerStreamListener listener) { + try (VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TYPE_INFO_SCHEMA, allocator)) { root.setRowCount(1); ((VarCharVector) root.getVector("type_name")).setSafe(0, new Text("Integer")); ((IntVector) root.getVector("data_type")).setSafe(0, INT.ordinal()); @@ -148,9 +158,11 @@ public void getStreamTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, root.getVector("literal_prefix").setNull(0); root.getVector("literal_suffix").setNull(0); root.getVector("create_params").setNull(0); - ((IntVector) root.getVector("nullable")).setSafe(0, FlightSql.Nullable.NULLABILITY_NULLABLE.getNumber()); + ((IntVector) root.getVector("nullable")) + .setSafe(0, FlightSql.Nullable.NULLABILITY_NULLABLE.getNumber()); ((BitVector) root.getVector("case_sensitive")).setSafe(0, 1); - ((IntVector) root.getVector("nullable")).setSafe(0, FlightSql.Searchable.SEARCHABLE_FULL.getNumber()); + ((IntVector) root.getVector("nullable")) + .setSafe(0, FlightSql.Searchable.SEARCHABLE_FULL.getNumber()); ((BitVector) root.getVector("unsigned_attribute")).setSafe(0, 1); root.getVector("fixed_prec_scale").setNull(0); ((BitVector) root.getVector("auto_increment")).setSafe(0, 1); @@ -169,9 +181,10 @@ public void getStreamTypeInfo(FlightSql.CommandGetXdbcTypeInfo request, } @Override - public void getStreamTables(FlightSql.CommandGetTables command, CallContext context, - ServerStreamListener listener) { - try (VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, allocator)) { + public void getStreamTables( + FlightSql.CommandGetTables command, CallContext context, ServerStreamListener listener) { + try (VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TABLES_SCHEMA_NO_SCHEMA, allocator)) { root.setRowCount(1); root.getVector("catalog_name").setNull(0); root.getVector("db_schema_name").setNull(0); @@ -186,7 +199,8 @@ public void getStreamTables(FlightSql.CommandGetTables command, CallContext cont @Override public void getStreamTableTypes(CallContext context, ServerStreamListener listener) { - try (VectorSchemaRoot root = VectorSchemaRoot.create(Schemas.GET_TABLE_TYPES_SCHEMA, allocator)) { + try (VectorSchemaRoot root = + VectorSchemaRoot.create(Schemas.GET_TABLE_TYPES_SCHEMA, allocator)) { root.setRowCount(1); ((VarCharVector) root.getVector("table_type")).setSafe(0, new Text("TABLE")); @@ -207,9 +221,10 @@ public static void setUp() throws Exception { allocator = new RootAllocator(Integer.MAX_VALUE); final Location serverLocation = Location.forGrpcInsecure("localhost", 0); - server = FlightServer.builder(allocator, serverLocation, new FlightSqlTestProducer(allocator)) - .build() - .start(); + server = + FlightServer.builder(allocator, serverLocation, new FlightSqlTestProducer(allocator)) + .build() + .start(); final Location clientLocation = Location.forGrpcInsecure("localhost", server.getPort()); sqlClient = new FlightSqlClient(FlightClient.builder(allocator, clientLocation).build()); @@ -227,37 +242,39 @@ public static void tearDown() throws Exception { @Test public void testGetTablesResultNoSchema() throws Exception { try (final FlightStream stream = - sqlClient.getStream( - sqlClient.getTables(null, null, null, null, false) - .getEndpoints().get(0).getTicket())) { + sqlClient.getStream( + sqlClient.getTables(null, null, null, null, false).getEndpoints().get(0).getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA)), + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLES_SCHEMA_NO_SCHEMA)), () -> { final List> results = getResults(stream); - final List> expectedResults = ImmutableList.of( - // catalog_name | schema_name | table_name | table_type | table_schema - asList(null, null, "test_table", "TABLE")); + final List> expectedResults = + ImmutableList.of( + // catalog_name | schema_name | table_name | table_type | table_schema + asList(null, null, "test_table", "TABLE")); MatcherAssert.assertThat(results, is(expectedResults)); - } - ); + }); } } @Test public void testGetTableTypesResult() throws Exception { try (final FlightStream stream = - sqlClient.getStream(sqlClient.getTableTypes().getEndpoints().get(0).getTicket())) { + sqlClient.getStream(sqlClient.getTableTypes().getEndpoints().get(0).getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA)), + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_TABLE_TYPES_SCHEMA)), () -> { final List> tableTypes = getResults(stream); - final List> expectedTableTypes = ImmutableList.of( - // table_type - singletonList("TABLE") - ); + final List> expectedTableTypes = + ImmutableList.of( + // table_type + singletonList("TABLE")); MatcherAssert.assertThat(tableTypes, is(expectedTableTypes)); - } - ); + }); } } @@ -266,9 +283,10 @@ public void testGetSqlInfoResults() throws Exception { final FlightInfo info = sqlClient.getSqlInfo(); try (final FlightStream stream = sqlClient.getStream(info.getEndpoints().get(0).getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA)), - () -> MatcherAssert.assertThat(getResults(stream), is(emptyList())) - ); + () -> + MatcherAssert.assertThat( + stream.getSchema(), is(FlightSqlProducer.Schemas.GET_SQL_INFO_SCHEMA)), + () -> MatcherAssert.assertThat(getResults(stream), is(emptyList()))); } } @@ -280,9 +298,11 @@ public void testGetTypeInfo() throws Exception { final List> results = getResults(stream); - final List> matchers = ImmutableList.of( - asList("Integer", "4", "400", null, null, "3", "true", null, "true", null, "true", - "Integer", null, null, "4", null, "10", null)); + final List> matchers = + ImmutableList.of( + asList( + "Integer", "4", "400", null, null, "3", "true", null, "true", null, "true", + "Integer", null, null, "4", null, "10", null)); MatcherAssert.assertThat(results, is(matchers)); } @@ -290,12 +310,18 @@ public void testGetTypeInfo() throws Exception { @Test public void testExecuteQuery() throws Exception { - try (final FlightStream stream = sqlClient - .getStream(sqlClient.execute(FlightSqlTestProducer.FIXED_QUERY).getEndpoints().get(0).getTicket())) { + try (final FlightStream stream = + sqlClient.getStream( + sqlClient + .execute(FlightSqlTestProducer.FIXED_QUERY) + .getEndpoints() + .get(0) + .getTicket())) { Assertions.assertAll( - () -> MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlTestProducer.FIXED_SCHEMA)), - () -> MatcherAssert.assertThat(getResults(stream), is(singletonList(singletonList("1")))) - ); + () -> + MatcherAssert.assertThat(stream.getSchema(), is(FlightSqlTestProducer.FIXED_SCHEMA)), + () -> + MatcherAssert.assertThat(getResults(stream), is(singletonList(singletonList("1"))))); } } } diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/AdhocTestOption.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/AdhocTestOption.java index 6988a86049d..af4b88223dc 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/AdhocTestOption.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/AdhocTestOption.java @@ -22,7 +22,9 @@ import com.google.protobuf.ProtocolMessageEnum; enum AdhocTestOption implements ProtocolMessageEnum { - OPTION_A, OPTION_B, OPTION_C; + OPTION_A, + OPTION_B, + OPTION_C; @Override public int getNumber() { @@ -40,6 +42,7 @@ public EnumDescriptor getDescriptorForType() { } private UnsupportedOperationException getUnsupportedException() { - return new UnsupportedOperationException("Unimplemented method is irrelevant for the scope of this test."); + return new UnsupportedOperationException( + "Unimplemented method is irrelevant for the scope of this test."); } } diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/FlightStreamUtils.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/FlightStreamUtils.java index fbbe9ef0181..7eecd4fb2ff 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/FlightStreamUtils.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/FlightStreamUtils.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; - import org.apache.arrow.flight.FlightStream; import org.apache.arrow.vector.BitVector; import org.apache.arrow.vector.FieldVector; @@ -52,75 +51,82 @@ public static List> getResults(FlightStream stream) { results.add(new ArrayList<>()); } - root.getSchema().getFields().forEach(field -> { - try (final FieldVector fieldVector = root.getVector(field.getName())) { - if (fieldVector instanceof VarCharVector) { - final VarCharVector varcharVector = (VarCharVector) fieldVector; - for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { - final Text data = varcharVector.getObject(rowIndex); - results.get(rowIndex).add(isNull(data) ? null : data.toString()); - } - } else if (fieldVector instanceof IntVector) { - for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { - Object data = fieldVector.getObject(rowIndex); - results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); - } - } else if (fieldVector instanceof VarBinaryVector) { - final VarBinaryVector varbinaryVector = (VarBinaryVector) fieldVector; - for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { - final byte[] data = varbinaryVector.getObject(rowIndex); - final String output; - try { - output = isNull(data) ? - null : - MessageSerializer.deserializeSchema( - new ReadChannel(Channels.newChannel(new ByteArrayInputStream(data)))).toJson(); - } catch (final IOException e) { - throw new RuntimeException("Failed to deserialize schema", e); - } - results.get(rowIndex).add(output); - } - } else if (fieldVector instanceof DenseUnionVector) { - final DenseUnionVector denseUnionVector = (DenseUnionVector) fieldVector; - for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { - final Object data = denseUnionVector.getObject(rowIndex); - results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); - } - } else if (fieldVector instanceof ListVector) { - for (int i = 0; i < fieldVector.getValueCount(); i++) { - if (!fieldVector.isNull(i)) { - List elements = (List) ((ListVector) fieldVector).getObject(i); - List values = new ArrayList<>(); + root.getSchema() + .getFields() + .forEach( + field -> { + try (final FieldVector fieldVector = root.getVector(field.getName())) { + if (fieldVector instanceof VarCharVector) { + final VarCharVector varcharVector = (VarCharVector) fieldVector; + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { + final Text data = varcharVector.getObject(rowIndex); + results.get(rowIndex).add(isNull(data) ? null : data.toString()); + } + } else if (fieldVector instanceof IntVector) { + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { + Object data = fieldVector.getObject(rowIndex); + results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); + } + } else if (fieldVector instanceof VarBinaryVector) { + final VarBinaryVector varbinaryVector = (VarBinaryVector) fieldVector; + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { + final byte[] data = varbinaryVector.getObject(rowIndex); + final String output; + try { + output = + isNull(data) + ? null + : MessageSerializer.deserializeSchema( + new ReadChannel( + Channels.newChannel(new ByteArrayInputStream(data)))) + .toJson(); + } catch (final IOException e) { + throw new RuntimeException("Failed to deserialize schema", e); + } + results.get(rowIndex).add(output); + } + } else if (fieldVector instanceof DenseUnionVector) { + final DenseUnionVector denseUnionVector = (DenseUnionVector) fieldVector; + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { + final Object data = denseUnionVector.getObject(rowIndex); + results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); + } + } else if (fieldVector instanceof ListVector) { + for (int i = 0; i < fieldVector.getValueCount(); i++) { + if (!fieldVector.isNull(i)) { + List elements = + (List) ((ListVector) fieldVector).getObject(i); + List values = new ArrayList<>(); - for (Text element : elements) { - values.add(element.toString()); - } - results.get(i).add(values.toString()); - } - } + for (Text element : elements) { + values.add(element.toString()); + } + results.get(i).add(values.toString()); + } + } - } else if (fieldVector instanceof UInt4Vector) { - final UInt4Vector uInt4Vector = (UInt4Vector) fieldVector; - for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { - final Object data = uInt4Vector.getObject(rowIndex); - results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); - } - } else if (fieldVector instanceof UInt1Vector) { - final UInt1Vector uInt1Vector = (UInt1Vector) fieldVector; - for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { - final Object data = uInt1Vector.getObject(rowIndex); - results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); - } - } else if (fieldVector instanceof BitVector) { - for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { - Object data = fieldVector.getObject(rowIndex); - results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); - } - } else { - throw new UnsupportedOperationException("Not yet implemented"); - } - } - }); + } else if (fieldVector instanceof UInt4Vector) { + final UInt4Vector uInt4Vector = (UInt4Vector) fieldVector; + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { + final Object data = uInt4Vector.getObject(rowIndex); + results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); + } + } else if (fieldVector instanceof UInt1Vector) { + final UInt1Vector uInt1Vector = (UInt1Vector) fieldVector; + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { + final Object data = uInt1Vector.getObject(rowIndex); + results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); + } + } else if (fieldVector instanceof BitVector) { + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { + Object data = fieldVector.getObject(rowIndex); + results.get(rowIndex).add(isNull(data) ? null : Objects.toString(data)); + } + } else { + throw new UnsupportedOperationException("Not yet implemented"); + } + } + }); } } diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtilsBitmaskCreationTest.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtilsBitmaskCreationTest.java index dfb1b9da3e2..c3d4c5606a8 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtilsBitmaskCreationTest.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtilsBitmaskCreationTest.java @@ -24,7 +24,6 @@ import static org.apache.arrow.flight.sql.util.SqlInfoOptionsUtils.createBitmaskFromEnums; import java.util.List; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -33,23 +32,22 @@ public final class SqlInfoOptionsUtilsBitmaskCreationTest { public static List provideParameters() { return asList( - new Object[][]{ - {new AdhocTestOption[0], 0L}, - {new AdhocTestOption[]{OPTION_A}, 1L}, - {new AdhocTestOption[]{OPTION_B}, 0b10L}, - {new AdhocTestOption[]{OPTION_A, OPTION_B}, 0b11L}, - {new AdhocTestOption[]{OPTION_C}, 0b100L}, - {new AdhocTestOption[]{OPTION_A, OPTION_C}, 0b101L}, - {new AdhocTestOption[]{OPTION_B, OPTION_C}, 0b110L}, - {AdhocTestOption.values(), 0b111L}, + new Object[][] { + {new AdhocTestOption[0], 0L}, + {new AdhocTestOption[] {OPTION_A}, 1L}, + {new AdhocTestOption[] {OPTION_B}, 0b10L}, + {new AdhocTestOption[] {OPTION_A, OPTION_B}, 0b11L}, + {new AdhocTestOption[] {OPTION_C}, 0b100L}, + {new AdhocTestOption[] {OPTION_A, OPTION_C}, 0b101L}, + {new AdhocTestOption[] {OPTION_B, OPTION_C}, 0b110L}, + {AdhocTestOption.values(), 0b111L}, }); } @ParameterizedTest @MethodSource("provideParameters") public void testShouldBuildBitmaskFromEnums( - AdhocTestOption[] adhocTestOptions, long expectedBitmask - ) { + AdhocTestOption[] adhocTestOptions, long expectedBitmask) { Assertions.assertEquals(createBitmaskFromEnums(adhocTestOptions), expectedBitmask); } } diff --git a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtilsBitmaskParsingTest.java b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtilsBitmaskParsingTest.java index 818326a582d..4baabf1da22 100644 --- a/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtilsBitmaskParsingTest.java +++ b/java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/util/SqlInfoOptionsUtilsBitmaskParsingTest.java @@ -28,7 +28,6 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -37,21 +36,22 @@ public final class SqlInfoOptionsUtilsBitmaskParsingTest { public static List provideParameters() { return asList( - new Object[][]{ - {0L, EnumSet.noneOf(AdhocTestOption.class)}, - {1L, EnumSet.of(OPTION_A)}, - {0b10L, EnumSet.of(OPTION_B)}, - {0b11L, EnumSet.of(OPTION_A, OPTION_B)}, - {0b100L, EnumSet.of(OPTION_C)}, - {0b101L, EnumSet.of(OPTION_A, OPTION_C)}, - {0b110L, EnumSet.of(OPTION_B, OPTION_C)}, - {0b111L, EnumSet.allOf(AdhocTestOption.class)}, + new Object[][] { + {0L, EnumSet.noneOf(AdhocTestOption.class)}, + {1L, EnumSet.of(OPTION_A)}, + {0b10L, EnumSet.of(OPTION_B)}, + {0b11L, EnumSet.of(OPTION_A, OPTION_B)}, + {0b100L, EnumSet.of(OPTION_C)}, + {0b101L, EnumSet.of(OPTION_A, OPTION_C)}, + {0b110L, EnumSet.of(OPTION_B, OPTION_C)}, + {0b111L, EnumSet.allOf(AdhocTestOption.class)}, }); } @ParameterizedTest @MethodSource("provideParameters") - public void testShouldFilterOutEnumsBasedOnBitmask(long bitmask, Set expectedOptions) { + public void testShouldFilterOutEnumsBasedOnBitmask( + long bitmask, Set expectedOptions) { final Set actualOptions = stream(AdhocTestOption.values()) .filter(enumInstance -> doesBitmaskTranslateToEnum(enumInstance, bitmask)) diff --git a/java/flight/flight-sql/src/test/resources/logback.xml b/java/flight/flight-sql/src/test/resources/logback.xml index 4c54d18a210..9fa3f1e3b43 100644 --- a/java/flight/flight-sql/src/test/resources/logback.xml +++ b/java/flight/flight-sql/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/format/pom.xml b/java/format/pom.xml index e6b40f93589..cc6249c3a73 100644 --- a/java/format/pom.xml +++ b/java/format/pom.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/ExpandableByteBuf.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/ExpandableByteBuf.java index 09b7300444c..0e203299dfb 100644 --- a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/ExpandableByteBuf.java +++ b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/ExpandableByteBuf.java @@ -21,8 +21,7 @@ /** * Allows us to decorate ArrowBuf to make it expandable so that we can use them in the context of - * the Netty framework - * (thus supporting RPC level memory accounting). + * the Netty framework (thus supporting RPC level memory accounting). */ public class ExpandableByteBuf extends MutableWrappedByteBuf { @@ -52,5 +51,4 @@ public ByteBuf capacity(int newCapacity) { return super.capacity(newCapacity); } } - } diff --git a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java index 5221dd3c19d..ba40e49ac21 100644 --- a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java +++ b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java @@ -17,6 +17,7 @@ package io.netty.buffer; +import io.netty.util.ByteProcessor; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -26,11 +27,9 @@ import java.nio.channels.GatheringByteChannel; import java.nio.channels.ScatteringByteChannel; -import io.netty.util.ByteProcessor; - /** - * This is basically a complete copy of netty's DuplicatedByteBuf. We copy because we want to override - * some behaviors and make buffer mutable. + * This is basically a complete copy of netty's DuplicatedByteBuf. We copy because we want to + * override some behaviors and make buffer mutable. */ abstract class MutableWrappedByteBuf extends AbstractByteBuf { @@ -343,40 +342,33 @@ public ByteBuf setBytes(int index, ByteBuffer src) { } @Override - public int setBytes(int index, FileChannel in, long position, int length) - throws IOException { + public int setBytes(int index, FileChannel in, long position, int length) throws IOException { return buffer.setBytes(index, in, position, length); } @Override - public ByteBuf getBytes(int index, OutputStream out, int length) - throws IOException { + public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { buffer.getBytes(index, out, length); return this; } @Override - public int getBytes(int index, GatheringByteChannel out, int length) - throws IOException { + public int getBytes(int index, GatheringByteChannel out, int length) throws IOException { return buffer.getBytes(index, out, length); } @Override - public int setBytes(int index, InputStream in, int length) - throws IOException { + public int setBytes(int index, InputStream in, int length) throws IOException { return buffer.setBytes(index, in, length); } @Override - public int setBytes(int index, ScatteringByteChannel in, int length) - throws IOException { + public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { return buffer.setBytes(index, in, length); } - @Override - public int getBytes(int index, FileChannel out, long position, int length) - throws IOException { + public int getBytes(int index, FileChannel out, long position, int length) throws IOException { return buffer.getBytes(index, out, position, length); } @@ -444,5 +436,4 @@ public boolean release(int decrement) { boolean released = unwrap().release(decrement); return released; } - } diff --git a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/NettyArrowBuf.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/NettyArrowBuf.java index 466444c7d53..5660c9e340c 100644 --- a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/NettyArrowBuf.java +++ b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/NettyArrowBuf.java @@ -17,6 +17,7 @@ package io.netty.buffer; +import io.netty.util.internal.PlatformDependent; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -25,7 +26,6 @@ import java.nio.channels.FileChannel; import java.nio.channels.GatheringByteChannel; import java.nio.channels.ScatteringByteChannel; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BoundsChecking; import org.apache.arrow.memory.BufferAllocator; @@ -34,11 +34,7 @@ import org.apache.arrow.util.Preconditions; import org.apache.arrow.util.VisibleForTesting; -import io.netty.util.internal.PlatformDependent; - -/** - * Netty specific wrapper over ArrowBuf for use in Netty framework. - */ +/** Netty specific wrapper over ArrowBuf for use in Netty framework. */ public class NettyArrowBuf extends AbstractByteBuf implements AutoCloseable { private final ArrowBuf arrowBuf; @@ -49,14 +45,12 @@ public class NettyArrowBuf extends AbstractByteBuf implements AutoCloseable { /** * Constructs a new instance. * - * @param arrowBuf The buffer to wrap. + * @param arrowBuf The buffer to wrap. * @param bufferAllocator The allocator for the buffer. - * @param length The length of this buffer. + * @param length The length of this buffer. */ public NettyArrowBuf( - final ArrowBuf arrowBuf, - final BufferAllocator bufferAllocator, - final int length) { + final ArrowBuf arrowBuf, final BufferAllocator bufferAllocator, final int length) { super(length); this.arrowBuf = arrowBuf; this.arrowByteBufAllocator = new ArrowByteBufAllocator(bufferAllocator); @@ -105,13 +99,15 @@ public synchronized ByteBuf capacity(int newCapacity) { length = newCapacity; return this; } - throw new UnsupportedOperationException("Buffers don't support resizing that increases the size."); + throw new UnsupportedOperationException( + "Buffers don't support resizing that increases the size."); } @Override public ByteBuf unwrap() { - // According to Netty's ByteBuf interface, unwrap() should return null if the buffer cannot be unwrapped + // According to Netty's ByteBuf interface, unwrap() should return null if the buffer cannot be + // unwrapped // https://github.com/netty/netty/blob/9fe796e10a433b6cd20ad78b2c39cd56b86ccd2e/buffer/src/main/java/io/netty/buffer/ByteBuf.java#L305 // Throwing here breaks toString() in AbstractByteBuf @@ -234,10 +230,9 @@ public ByteBuffer nioBuffer() { return nioBuffer(readerIndex(), readableBytes()); } - /** - * Returns a buffer that is zero positioned but points - * to a slice of the original buffer starting at given index. + * Returns a buffer that is zero positioned but points to a slice of the original buffer starting + * at given index. */ @Override public ByteBuffer nioBuffer(int index, int length) { @@ -248,8 +243,8 @@ public ByteBuffer nioBuffer(int index, int length) { } /** - * Returns a buffer that is zero positioned but points - * to a slice of the original buffer starting at given index. + * Returns a buffer that is zero positioned but points to a slice of the original buffer starting + * at given index. */ public ByteBuffer nioBuffer(long index, int length) { chk(index, length); @@ -264,7 +259,8 @@ public ByteBuffer nioBuffer(long index, int length) { * @return ByteBuffer */ private ByteBuffer getDirectBuffer(long index) { - return PlatformDependent.directBuffer(addr(index), LargeMemoryUtil.checkedCastToInt(length - index)); + return PlatformDependent.directBuffer( + addr(index), LargeMemoryUtil.checkedCastToInt(length - index)); } @Override @@ -294,11 +290,11 @@ public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) { /** * Determine if the requested {@code index} and {@code length} will fit within {@code capacity}. * - * @param index The starting index. - * @param length The length which will be utilized (starting from {@code index}). + * @param index The starting index. + * @param length The length which will be utilized (starting from {@code index}). * @param capacity The capacity that {@code index + length} is allowed to be within. - * @return {@code true} if the requested {@code index} and {@code length} will fit within {@code capacity}. - * {@code false} if this would result in an index out of bounds exception. + * @return {@code true} if the requested {@code index} and {@code length} will fit within {@code + * capacity}. {@code false} if this would result in an index out of bounds exception. */ private static boolean isOutOfBounds(int index, int length, int capacity) { return (index | length | (index + length) | (capacity - (index + length))) < 0; @@ -413,18 +409,16 @@ protected int _getUnsignedMedium(int index) { protected int _getUnsignedMediumLE(int index) { this.chk(index, 3); long addr = this.addr(index); - return PlatformDependent.getByte(addr) & 255 | - (Short.reverseBytes(PlatformDependent.getShort(addr + 1L)) & '\uffff') << 8; + return PlatformDependent.getByte(addr) & 255 + | (Short.reverseBytes(PlatformDependent.getShort(addr + 1L)) & '\uffff') << 8; } - /*-------------------------------------------------* - | | - | get() APIs | - | | + | | + | get() APIs | + | | *-------------------------------------------------*/ - @Override protected byte _getByte(int index) { return getByte(index); @@ -483,14 +477,12 @@ public long getLong(int index) { return arrowBuf.getLong(index); } - /*-------------------------------------------------* - | | - | set() APIs | - | | + | | + | set() APIs | + | | *-------------------------------------------------*/ - @Override protected void _setByte(int index, int value) { setByte(index, value); @@ -524,10 +516,9 @@ private long addr(long index) { } /** - * Helper function to do bounds checking at a particular - * index for particular length of data. + * Helper function to do bounds checking at a particular index for particular length of data. * - * @param index index (0 based relative to this ArrowBuf) + * @param index index (0 based relative to this ArrowBuf) * @param fieldLength provided length of data for get/set */ private void chk(long index, long fieldLength) { @@ -539,8 +530,9 @@ private void chk(long index, long fieldLength) { throw new IllegalArgumentException("length: " + fieldLength + " (expected: >= 0)"); } if (index < 0 || index > capacity() - fieldLength) { - throw new IndexOutOfBoundsException(String.format( - "index: %d, length: %d (expected: range(0, %d))", index, fieldLength, capacity())); + throw new IndexOutOfBoundsException( + String.format( + "index: %d, length: %d (expected: range(0, %d))", index, fieldLength, capacity())); } } } @@ -615,17 +607,15 @@ public NettyArrowBuf setLong(int index, long value) { return this; } - /** - * unwrap arrow buffer into a netty buffer. - */ + /** unwrap arrow buffer into a netty buffer. */ public static NettyArrowBuf unwrapBuffer(ArrowBuf buf) { - final NettyArrowBuf nettyArrowBuf = new NettyArrowBuf( - buf, - buf.getReferenceManager().getAllocator(), - LargeMemoryUtil.checkedCastToInt(buf.capacity())); + final NettyArrowBuf nettyArrowBuf = + new NettyArrowBuf( + buf, + buf.getReferenceManager().getAllocator(), + LargeMemoryUtil.checkedCastToInt(buf.capacity())); nettyArrowBuf.readerIndex(LargeMemoryUtil.checkedCastToInt(buf.readerIndex())); nettyArrowBuf.writerIndex(LargeMemoryUtil.checkedCastToInt(buf.writerIndex())); return nettyArrowBuf; } - } diff --git a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java index ea84a3258e8..28393aaaef7 100644 --- a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java +++ b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java @@ -17,24 +17,23 @@ package io.netty.buffer; +import io.netty.util.internal.OutOfDirectMemoryError; +import io.netty.util.internal.StringUtil; import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicLong; - import org.apache.arrow.memory.OutOfMemoryException; import org.apache.arrow.memory.util.AssertionUtil; import org.apache.arrow.memory.util.LargeMemoryUtil; -import io.netty.util.internal.OutOfDirectMemoryError; -import io.netty.util.internal.StringUtil; - /** * The base allocator that we use for all of Arrow's memory management. Returns * UnsafeDirectLittleEndian buffers. */ public class PooledByteBufAllocatorL { - private static final org.slf4j.Logger memoryLogger = org.slf4j.LoggerFactory.getLogger("arrow.allocator"); + private static final org.slf4j.Logger memoryLogger = + org.slf4j.LoggerFactory.getLogger("arrow.allocator"); private static final int MEMORY_LOGGER_FREQUENCY_SECONDS = 60; public final UnsafeDirectLittleEndian empty; @@ -49,9 +48,7 @@ public PooledByteBufAllocatorL() { empty = new UnsafeDirectLittleEndian(new DuplicatedByteBuf(Unpooled.EMPTY_BUFFER)); } - /** - * Returns a {@linkplain UnsafeDirectLittleEndian} of the given size. - */ + /** Returns a {@linkplain UnsafeDirectLittleEndian} of the given size. */ public UnsafeDirectLittleEndian allocate(long size) { try { return allocator.directBuffer(LargeMemoryUtil.checkedCastToInt(size), Integer.MAX_VALUE); @@ -102,8 +99,8 @@ private AccountedUnsafeDirectLittleEndian(LargeBuffer buf, AtomicLong count, Ato this.size = size; } - private AccountedUnsafeDirectLittleEndian(PooledUnsafeDirectByteBuf buf, AtomicLong count, - AtomicLong size) { + private AccountedUnsafeDirectLittleEndian( + PooledUnsafeDirectByteBuf buf, AtomicLong count, AtomicLong size) { super(buf); this.initialCapacity = buf.capacity(); this.count = count; @@ -129,7 +126,6 @@ public boolean release(int decrement) { } return released; } - } private class InnerAllocator extends PooledByteBufAllocator { @@ -145,7 +141,8 @@ public InnerAllocator() { f.setAccessible(true); this.directArenas = (PoolArena[]) f.get(this); } catch (Exception e) { - throw new RuntimeException("Failure while initializing allocator. Unable to retrieve direct arenas field.", e); + throw new RuntimeException( + "Failure while initializing allocator. Unable to retrieve direct arenas field.", e); } if (memoryLogger.isTraceEnabled()) { @@ -170,8 +167,8 @@ private UnsafeDirectLittleEndian newDirectBufferL(int initialCapacity, int maxCa hugeBufferCount.incrementAndGet(); // logger.debug("Allocating huge buffer of size {}", initialCapacity, new Exception()); - return new AccountedUnsafeDirectLittleEndian(new LargeBuffer(buf), hugeBufferCount, - hugeBufferSize); + return new AccountedUnsafeDirectLittleEndian( + new LargeBuffer(buf), hugeBufferCount, hugeBufferSize); } else { // within chunk, use arena. ByteBuf buf = directArena.allocate(cache, initialCapacity, maxCapacity); @@ -186,8 +183,8 @@ private UnsafeDirectLittleEndian newDirectBufferL(int initialCapacity, int maxCa normalBufferSize.addAndGet(buf.capacity()); normalBufferCount.incrementAndGet(); - return new AccountedUnsafeDirectLittleEndian((PooledUnsafeDirectByteBuf) buf, - normalBufferCount, normalBufferSize); + return new AccountedUnsafeDirectLittleEndian( + (PooledUnsafeDirectByteBuf) buf, normalBufferCount, normalBufferSize); } } else { @@ -197,8 +194,8 @@ private UnsafeDirectLittleEndian newDirectBufferL(int initialCapacity, int maxCa private UnsupportedOperationException fail() { return new UnsupportedOperationException( - "Arrow requires that the JVM used supports access sun.misc.Unsafe. This platform " + - "didn't provide that functionality."); + "Arrow requires that the JVM used supports access sun.misc.Unsafe. This platform " + + "didn't provide that functionality."); } @Override @@ -215,15 +212,16 @@ public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) { throw new UnsupportedOperationException("Arrow doesn't support using heap buffers."); } - private void validate(int initialCapacity, int maxCapacity) { if (initialCapacity < 0) { - throw new IllegalArgumentException("initialCapacity: " + initialCapacity + " (expected: 0+)"); + throw new IllegalArgumentException( + "initialCapacity: " + initialCapacity + " (expected: 0+)"); } if (initialCapacity > maxCapacity) { - throw new IllegalArgumentException(String.format( - "initialCapacity: %d (expected: not greater than maxCapacity(%d)", - initialCapacity, maxCapacity)); + throw new IllegalArgumentException( + String.format( + "initialCapacity: %d (expected: not greater than maxCapacity(%d)", + initialCapacity, maxCapacity)); } } @@ -272,7 +270,5 @@ public void run() { } } } - - } } diff --git a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/UnsafeDirectLittleEndian.java b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/UnsafeDirectLittleEndian.java index e51c6c3d488..9405221f530 100644 --- a/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/UnsafeDirectLittleEndian.java +++ b/java/memory/memory-netty-buffer-patch/src/main/java/io/netty/buffer/UnsafeDirectLittleEndian.java @@ -17,18 +17,16 @@ package io.netty.buffer; +import io.netty.util.internal.PlatformDependent; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteOrder; import java.util.concurrent.atomic.AtomicLong; -import io.netty.util.internal.PlatformDependent; - /** - * The underlying class we use for little-endian access to memory. Is used underneath ArrowBufs - * to abstract away the - * Netty classes and underlying Netty memory management. + * The underlying class we use for little-endian access to memory. Is used underneath ArrowBufs to + * abstract away the Netty classes and underlying Netty memory management. */ public class UnsafeDirectLittleEndian extends WrappedByteBuf { private static final AtomicLong ID_GENERATOR = new AtomicLong(0); diff --git a/java/memory/memory-netty-buffer-patch/src/main/java/org/apache/arrow/memory/patch/ArrowByteBufAllocator.java b/java/memory/memory-netty-buffer-patch/src/main/java/org/apache/arrow/memory/patch/ArrowByteBufAllocator.java index 6ce08b5a590..26b3d41adfb 100644 --- a/java/memory/memory-netty-buffer-patch/src/main/java/org/apache/arrow/memory/patch/ArrowByteBufAllocator.java +++ b/java/memory/memory-netty-buffer-patch/src/main/java/org/apache/arrow/memory/patch/ArrowByteBufAllocator.java @@ -17,22 +17,18 @@ package org.apache.arrow.memory.patch; -import org.apache.arrow.memory.BufferAllocator; - import io.netty.buffer.AbstractByteBufAllocator; import io.netty.buffer.ByteBuf; import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.ExpandableByteBuf; import io.netty.buffer.NettyArrowBuf; +import org.apache.arrow.memory.BufferAllocator; /** * An implementation of ByteBufAllocator that wraps a Arrow BufferAllocator. This allows the RPC - * layer to be accounted - * and managed using Arrow's BufferAllocator infrastructure. The only thin different from a - * typical BufferAllocator is - * the signature and the fact that this Allocator returns ExpandableByteBufs which enable - * otherwise non-expandable - * ArrowBufs to be expandable. + * layer to be accounted and managed using Arrow's BufferAllocator infrastructure. The only thin + * different from a typical BufferAllocator is the signature and the fact that this Allocator + * returns ExpandableByteBufs which enable otherwise non-expandable ArrowBufs to be expandable. * * @deprecated This class may be removed in a future release. */ @@ -59,7 +55,8 @@ public ByteBuf buffer() { @Override public ByteBuf buffer(int initialCapacity) { - return new ExpandableByteBuf(NettyArrowBuf.unwrapBuffer(allocator.buffer(initialCapacity)), allocator); + return new ExpandableByteBuf( + NettyArrowBuf.unwrapBuffer(allocator.buffer(initialCapacity)), allocator); } @Override diff --git a/java/memory/memory-netty-buffer-patch/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java b/java/memory/memory-netty-buffer-patch/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java index 043c2c1605a..c9df9d6059a 100644 --- a/java/memory/memory-netty-buffer-patch/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java +++ b/java/memory/memory-netty-buffer-patch/src/test/java/io/netty/buffer/TestUnsafeDirectLittleEndian.java @@ -17,7 +17,6 @@ package io.netty.buffer; - import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; @@ -25,14 +24,8 @@ import java.io.IOException; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; - import org.junit.Test; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.LargeBuffer; -import io.netty.buffer.Unpooled; -import io.netty.buffer.UnsafeDirectLittleEndian; - public class TestUnsafeDirectLittleEndian { private static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN; @@ -71,7 +64,7 @@ public void testPrimitiveGetSet() { byte[] inBytes = "1234567".getBytes(StandardCharsets.UTF_8); try (ByteArrayInputStream bais = new ByteArrayInputStream(inBytes); - ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + ByteArrayOutputStream baos = new ByteArrayOutputStream()) { assertEquals(5, unsafeDirect.setBytes(56, bais, 5)); unsafeDirect.getBytes(56, baos, 5); assertEquals("12345", new String(baos.toByteArray(), StandardCharsets.UTF_8)); diff --git a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.java b/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.java index 8ece77178f0..b81562a256f 100644 --- a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.java +++ b/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/DefaultAllocationManagerFactory.java @@ -21,10 +21,7 @@ import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; -/** - * The default Allocation Manager Factory for a module. - * - */ +/** The default Allocation Manager Factory for a module. */ public class DefaultAllocationManagerFactory implements AllocationManager.Factory { public static final AllocationManager.Factory FACTORY = NettyAllocationManager.FACTORY; @@ -38,5 +35,4 @@ public AllocationManager create(BufferAllocator accountingAllocator, long size) public ArrowBuf empty() { return FACTORY.empty(); } - } diff --git a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/NettyAllocationManager.java b/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/NettyAllocationManager.java index 58354d0c2ee..1383d5518f2 100644 --- a/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/NettyAllocationManager.java +++ b/java/memory/memory-netty/src/main/java/org/apache/arrow/memory/netty/NettyAllocationManager.java @@ -17,60 +17,56 @@ package org.apache.arrow.memory.netty; +import io.netty.buffer.PooledByteBufAllocatorL; +import io.netty.buffer.UnsafeDirectLittleEndian; +import io.netty.util.internal.PlatformDependent; import org.apache.arrow.memory.AllocationManager; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.ReferenceManager; -import io.netty.buffer.PooledByteBufAllocatorL; -import io.netty.buffer.UnsafeDirectLittleEndian; -import io.netty.util.internal.PlatformDependent; - /** - * The default implementation of {@link AllocationManager}. The implementation is responsible for managing when memory - * is allocated and returned to the Netty-based PooledByteBufAllocatorL. + * The default implementation of {@link AllocationManager}. The implementation is responsible for + * managing when memory is allocated and returned to the Netty-based PooledByteBufAllocatorL. */ public class NettyAllocationManager extends AllocationManager { - public static final AllocationManager.Factory FACTORY = new AllocationManager.Factory() { + public static final AllocationManager.Factory FACTORY = + new AllocationManager.Factory() { - @Override - public AllocationManager create(BufferAllocator accountingAllocator, long size) { - return new NettyAllocationManager(accountingAllocator, size); - } + @Override + public AllocationManager create(BufferAllocator accountingAllocator, long size) { + return new NettyAllocationManager(accountingAllocator, size); + } - @Override - public ArrowBuf empty() { - return EMPTY_BUFFER; - } - }; + @Override + public ArrowBuf empty() { + return EMPTY_BUFFER; + } + }; /** - * The default cut-off value for switching allocation strategies. - * If the request size is not greater than the cut-off value, we will allocate memory by - * {@link PooledByteBufAllocatorL} APIs, - * otherwise, we will use {@link PlatformDependent} APIs. + * The default cut-off value for switching allocation strategies. If the request size is not + * greater than the cut-off value, we will allocate memory by {@link PooledByteBufAllocatorL} + * APIs, otherwise, we will use {@link PlatformDependent} APIs. */ public static final int DEFAULT_ALLOCATION_CUTOFF_VALUE = Integer.MAX_VALUE; private static final PooledByteBufAllocatorL INNER_ALLOCATOR = new PooledByteBufAllocatorL(); static final UnsafeDirectLittleEndian EMPTY = INNER_ALLOCATOR.empty; - static final ArrowBuf EMPTY_BUFFER = new ArrowBuf(ReferenceManager.NO_OP, - null, - 0, - NettyAllocationManager.EMPTY.memoryAddress()); + static final ArrowBuf EMPTY_BUFFER = + new ArrowBuf(ReferenceManager.NO_OP, null, 0, NettyAllocationManager.EMPTY.memoryAddress()); static final long CHUNK_SIZE = INNER_ALLOCATOR.getChunkSize(); private final long allocatedSize; private final UnsafeDirectLittleEndian memoryChunk; private final long allocatedAddress; - /** - * The cut-off value for switching allocation strategies. - */ + /** The cut-off value for switching allocation strategies. */ private final int allocationCutOffValue; - NettyAllocationManager(BufferAllocator accountingAllocator, long requestedSize, int allocationCutOffValue) { + NettyAllocationManager( + BufferAllocator accountingAllocator, long requestedSize, int allocationCutOffValue) { super(accountingAllocator); this.allocationCutOffValue = allocationCutOffValue; @@ -91,9 +87,9 @@ public ArrowBuf empty() { /** * Get the underlying memory chunk managed by this AllocationManager. - * @return the underlying memory chunk if the request size is not greater than the - * {@link NettyAllocationManager#allocationCutOffValue}, or null otherwise. * + * @return the underlying memory chunk if the request size is not greater than the {@link + * NettyAllocationManager#allocationCutOffValue}, or null otherwise. * @deprecated this method will be removed in a future release. */ @Deprecated @@ -124,5 +120,4 @@ protected void release0() { public long getSize() { return allocatedSize; } - } diff --git a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestExpandableByteBuf.java b/java/memory/memory-netty/src/test/java/io/netty/buffer/TestExpandableByteBuf.java index 67557b65a62..5a5396444cf 100644 --- a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestExpandableByteBuf.java +++ b/java/memory/memory-netty/src/test/java/io/netty/buffer/TestExpandableByteBuf.java @@ -23,17 +23,12 @@ import org.junit.Assert; import org.junit.Test; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ExpandableByteBuf; -import io.netty.buffer.NettyArrowBuf; - public class TestExpandableByteBuf { @Test public void testCapacity() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf srcByteBuf = NettyArrowBuf.unwrapBuffer(buf); ExpandableByteBuf expandableByteBuf = new ExpandableByteBuf(srcByteBuf, allocator); ByteBuf newByteBuf = expandableByteBuf.capacity(31); @@ -45,8 +40,7 @@ public void testCapacity() { @Test public void testCapacity1() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf srcByteBuf = NettyArrowBuf.unwrapBuffer(buf); ExpandableByteBuf expandableByteBuf = new ExpandableByteBuf(srcByteBuf, allocator); ByteBuf newByteBuf = expandableByteBuf.capacity(32); @@ -58,13 +52,20 @@ public void testCapacity1() { @Test public void testSetAndGetIntValues() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf srcByteBuf = NettyArrowBuf.unwrapBuffer(buf); ExpandableByteBuf expandableByteBuf = new ExpandableByteBuf(srcByteBuf, allocator); - int [] intVals = new int[] {Integer.MIN_VALUE, Short.MIN_VALUE - 1, Short.MIN_VALUE, 0 , - Short.MAX_VALUE , Short.MAX_VALUE + 1, Integer.MAX_VALUE}; - for (int intValue :intVals) { + int[] intVals = + new int[] { + Integer.MIN_VALUE, + Short.MIN_VALUE - 1, + Short.MIN_VALUE, + 0, + Short.MAX_VALUE, + Short.MAX_VALUE + 1, + Integer.MAX_VALUE + }; + for (int intValue : intVals) { expandableByteBuf.setInt(0, intValue); Assert.assertEquals(expandableByteBuf.getInt(0), intValue); Assert.assertEquals(expandableByteBuf.getIntLE(0), Integer.reverseBytes(intValue)); @@ -75,12 +76,11 @@ public void testSetAndGetIntValues() { @Test public void testSetAndGetLongValues() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf srcByteBuf = NettyArrowBuf.unwrapBuffer(buf); ExpandableByteBuf expandableByteBuf = new ExpandableByteBuf(srcByteBuf, allocator); - long [] longVals = new long[] {Long.MIN_VALUE, 0 , Long.MAX_VALUE}; - for (long longValue :longVals) { + long[] longVals = new long[] {Long.MIN_VALUE, 0, Long.MAX_VALUE}; + for (long longValue : longVals) { expandableByteBuf.setLong(0, longValue); Assert.assertEquals(expandableByteBuf.getLong(0), longValue); Assert.assertEquals(expandableByteBuf.getLongLE(0), Long.reverseBytes(longValue)); @@ -91,12 +91,11 @@ public void testSetAndGetLongValues() { @Test public void testSetAndGetShortValues() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf srcByteBuf = NettyArrowBuf.unwrapBuffer(buf); ExpandableByteBuf expandableByteBuf = new ExpandableByteBuf(srcByteBuf, allocator); - short [] shortVals = new short[] {Short.MIN_VALUE, 0 , Short.MAX_VALUE}; - for (short shortValue :shortVals) { + short[] shortVals = new short[] {Short.MIN_VALUE, 0, Short.MAX_VALUE}; + for (short shortValue : shortVals) { expandableByteBuf.setShort(0, shortValue); Assert.assertEquals(expandableByteBuf.getShort(0), shortValue); Assert.assertEquals(expandableByteBuf.getShortLE(0), Short.reverseBytes(shortValue)); @@ -107,12 +106,11 @@ public void testSetAndGetShortValues() { @Test public void testSetAndGetByteValues() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf srcByteBuf = NettyArrowBuf.unwrapBuffer(buf); ExpandableByteBuf expandableByteBuf = new ExpandableByteBuf(srcByteBuf, allocator); - byte [] byteVals = new byte[] {Byte.MIN_VALUE, 0 , Byte.MAX_VALUE}; - for (short byteValue :byteVals) { + byte[] byteVals = new byte[] {Byte.MIN_VALUE, 0, Byte.MAX_VALUE}; + for (short byteValue : byteVals) { expandableByteBuf.setByte(0, byteValue); Assert.assertEquals(expandableByteBuf.getByte(0), byteValue); } diff --git a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestNettyArrowBuf.java b/java/memory/memory-netty/src/test/java/io/netty/buffer/TestNettyArrowBuf.java index f18bccb4c9d..3e7df95adc3 100644 --- a/java/memory/memory-netty/src/test/java/io/netty/buffer/TestNettyArrowBuf.java +++ b/java/memory/memory-netty/src/test/java/io/netty/buffer/TestNettyArrowBuf.java @@ -18,7 +18,6 @@ package io.netty.buffer; import java.nio.ByteBuffer; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -26,16 +25,12 @@ import org.junit.Assert; import org.junit.Test; -import io.netty.buffer.CompositeByteBuf; -import io.netty.buffer.NettyArrowBuf; - public class TestNettyArrowBuf { @Test public void testSliceWithoutArgs() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf nettyBuf = NettyArrowBuf.unwrapBuffer(buf); nettyBuf.writerIndex(20); nettyBuf.readerIndex(10); @@ -48,8 +43,7 @@ public void testSliceWithoutArgs() { @Test public void testNioBuffer() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf nettyBuf = NettyArrowBuf.unwrapBuffer(buf); ByteBuffer byteBuffer = nettyBuf.nioBuffer(4, 6); // Nio Buffers should always be 0 indexed @@ -57,46 +51,50 @@ public void testNioBuffer() { Assert.assertEquals(6, byteBuffer.limit()); // Underlying buffer has size 32 excluding 4 should have capacity of 28. Assert.assertEquals(28, byteBuffer.capacity()); - } } @Test public void testInternalNioBuffer() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf nettyBuf = NettyArrowBuf.unwrapBuffer(buf); ByteBuffer byteBuffer = nettyBuf.internalNioBuffer(4, 6); Assert.assertEquals(0, byteBuffer.position()); Assert.assertEquals(6, byteBuffer.limit()); // Underlying buffer has size 32 excluding 4 should have capacity of 28. Assert.assertEquals(28, byteBuffer.capacity()); - } } @Test public void testSetLEValues() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf nettyBuf = NettyArrowBuf.unwrapBuffer(buf); - int [] intVals = new int[] {Integer.MIN_VALUE, Short.MIN_VALUE - 1, Short.MIN_VALUE, 0 , - Short.MAX_VALUE , Short.MAX_VALUE + 1, Integer.MAX_VALUE}; - for (int intValue :intVals ) { + int[] intVals = + new int[] { + Integer.MIN_VALUE, + Short.MIN_VALUE - 1, + Short.MIN_VALUE, + 0, + Short.MAX_VALUE, + Short.MAX_VALUE + 1, + Integer.MAX_VALUE + }; + for (int intValue : intVals) { nettyBuf._setInt(0, intValue); Assert.assertEquals(nettyBuf._getIntLE(0), Integer.reverseBytes(intValue)); } - long [] longVals = new long[] {Long.MIN_VALUE, 0 , Long.MAX_VALUE}; - for (long longValue :longVals ) { + long[] longVals = new long[] {Long.MIN_VALUE, 0, Long.MAX_VALUE}; + for (long longValue : longVals) { nettyBuf._setLong(0, longValue); Assert.assertEquals(nettyBuf._getLongLE(0), Long.reverseBytes(longValue)); } - short [] shortVals = new short[] {Short.MIN_VALUE, 0 , Short.MAX_VALUE}; - for (short shortValue :shortVals ) { + short[] shortVals = new short[] {Short.MIN_VALUE, 0, Short.MAX_VALUE}; + for (short shortValue : shortVals) { nettyBuf._setShort(0, shortValue); Assert.assertEquals(nettyBuf._getShortLE(0), Short.reverseBytes(shortValue)); } @@ -106,11 +104,10 @@ public void testSetLEValues() { @Test public void testSetCompositeBuffer() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - NettyArrowBuf buf2 = NettyArrowBuf.unwrapBuffer(allocator.buffer(20)); - ) { - CompositeByteBuf byteBufs = new CompositeByteBuf(new ArrowByteBufAllocator(allocator), - true, 1); + ArrowBuf buf = allocator.buffer(20); + NettyArrowBuf buf2 = NettyArrowBuf.unwrapBuffer(allocator.buffer(20)); ) { + CompositeByteBuf byteBufs = + new CompositeByteBuf(new ArrowByteBufAllocator(allocator), true, 1); int expected = 4; buf2.setInt(0, expected); buf2.writerIndex(4); @@ -124,10 +121,9 @@ public void testSetCompositeBuffer() { @Test public void testGetCompositeBuffer() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { - CompositeByteBuf byteBufs = new CompositeByteBuf(new ArrowByteBufAllocator(allocator), - true, 1); + ArrowBuf buf = allocator.buffer(20); ) { + CompositeByteBuf byteBufs = + new CompositeByteBuf(new ArrowByteBufAllocator(allocator), true, 1); int expected = 4; buf.setInt(0, expected); NettyArrowBuf buf2 = NettyArrowBuf.unwrapBuffer(allocator.buffer(20)); @@ -145,8 +141,7 @@ public void testGetCompositeBuffer() { @Test public void testUnwrapReturnsNull() { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(20); - ) { + ArrowBuf buf = allocator.buffer(20); ) { NettyArrowBuf nettyBuf = NettyArrowBuf.unwrapBuffer(buf); // NettyArrowBuf cannot be unwrapped, so unwrap() should return null per the Netty ByteBuf API Assert.assertNull(nettyBuf.unwrap()); diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/ITTestLargeArrowBuf.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/ITTestLargeArrowBuf.java index 71dba73d289..6ed686fdf2d 100644 --- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/ITTestLargeArrowBuf.java +++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/ITTestLargeArrowBuf.java @@ -26,17 +26,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** - * Integration test for large (more than 2GB) {@link org.apache.arrow.memory.ArrowBuf}. - * To run this test, please make sure there is at least 4GB memory in the system. + * Integration test for large (more than 2GB) {@link org.apache.arrow.memory.ArrowBuf}. To run this + * test, please make sure there is at least 4GB memory in the system. */ public class ITTestLargeArrowBuf { private static final Logger logger = LoggerFactory.getLogger(ITTestLargeArrowBuf.class); private void run(long bufSize) { try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - ArrowBuf largeBuf = allocator.buffer(bufSize)) { + ArrowBuf largeBuf = allocator.buffer(bufSize)) { assertEquals(bufSize, largeBuf.capacity()); logger.trace("Successfully allocated a buffer with capacity {}", largeBuf.capacity()); @@ -71,5 +70,4 @@ public void testLargeArrowBuf() { public void testMaxIntArrowBuf() { run(Integer.MAX_VALUE); } - } diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestAllocationManagerNetty.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestAllocationManagerNetty.java index 7f1e34ddc5f..50830b35ead 100644 --- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestAllocationManagerNetty.java +++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestAllocationManagerNetty.java @@ -23,9 +23,7 @@ import org.apache.arrow.memory.DefaultAllocationManagerOption; import org.junit.Test; -/** - * Test cases for {@link AllocationManager}. - */ +/** Test cases for {@link AllocationManager}. */ public class TestAllocationManagerNetty { @Test diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEmptyArrowBuf.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEmptyArrowBuf.java index b9948083e6f..db3bbfb32c9 100644 --- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEmptyArrowBuf.java +++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEmptyArrowBuf.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; +import io.netty.buffer.PooledByteBufAllocatorL; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.ReferenceManager; import org.apache.arrow.memory.RootAllocator; @@ -26,8 +27,6 @@ import org.junit.BeforeClass; import org.junit.Test; -import io.netty.buffer.PooledByteBufAllocatorL; - public class TestEmptyArrowBuf { private static final int MAX_ALLOCATION = 8 * 1024; @@ -37,7 +36,7 @@ public class TestEmptyArrowBuf { public static void beforeClass() { allocator = new RootAllocator(MAX_ALLOCATION); } - + /** Ensure the allocator is closed. */ @AfterClass public static void afterClass() { @@ -48,16 +47,22 @@ public static void afterClass() { @Test public void testZeroBuf() { - // Exercise the historical log inside the empty ArrowBuf. This is initialized statically, and there is a circular - // dependency between ArrowBuf and BaseAllocator, so if the initialization happens in the wrong order, the + // Exercise the historical log inside the empty ArrowBuf. This is initialized statically, and + // there is a circular + // dependency between ArrowBuf and BaseAllocator, so if the initialization happens in the wrong + // order, the // historical log will be null even though RootAllocator.DEBUG is true. allocator.getEmpty().print(new StringBuilder(), 0, RootAllocator.Verbosity.LOG_WITH_STACKTRACE); } @Test public void testEmptyArrowBuf() { - ArrowBuf buf = new ArrowBuf(ReferenceManager.NO_OP, null, - 1024, new PooledByteBufAllocatorL().empty.memoryAddress()); + ArrowBuf buf = + new ArrowBuf( + ReferenceManager.NO_OP, + null, + 1024, + new PooledByteBufAllocatorL().empty.memoryAddress()); buf.getReferenceManager().retain(); buf.getReferenceManager().retain(8); @@ -74,7 +79,8 @@ public void testEmptyArrowBuf() { assertEquals(false, buf.getReferenceManager().release()); assertEquals(false, buf.getReferenceManager().release(2)); assertEquals(0, buf.getReferenceManager().getAllocator().getLimit()); - assertEquals(buf, buf.getReferenceManager().transferOwnership(buf, allocator).getTransferredBuffer()); + assertEquals( + buf, buf.getReferenceManager().transferOwnership(buf, allocator).getTransferredBuffer()); assertEquals(0, buf.readerIndex()); assertEquals(0, buf.writerIndex()); assertEquals(1, buf.refCnt()); @@ -85,7 +91,5 @@ public void testEmptyArrowBuf() { assertEquals(1, derive.refCnt()); buf.close(); - } - } diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEndianness.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEndianness.java index a782523cbc6..2dbd1272e58 100644 --- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEndianness.java +++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestEndianness.java @@ -19,15 +19,13 @@ import static org.junit.Assert.assertEquals; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.NettyArrowBuf; import java.nio.ByteOrder; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.junit.Test; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.NettyArrowBuf; - public class TestEndianness { @Test @@ -49,5 +47,4 @@ public void testNativeEndian() { b.release(); a.close(); } - } diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocationManager.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocationManager.java index 39692c96ceb..907ce11474c 100644 --- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocationManager.java +++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocationManager.java @@ -29,26 +29,28 @@ import org.apache.arrow.memory.RootAllocator; import org.junit.Test; -/** - * Test cases for {@link NettyAllocationManager}. - */ +/** Test cases for {@link NettyAllocationManager}. */ public class TestNettyAllocationManager { static int CUSTOMIZED_ALLOCATION_CUTOFF_VALUE = 1024; private RootAllocator createCustomizedAllocator() { - return new RootAllocator(RootAllocator.configBuilder() - .allocationManagerFactory(new AllocationManager.Factory() { - @Override - public AllocationManager create(BufferAllocator accountingAllocator, long size) { - return new NettyAllocationManager(accountingAllocator, size, CUSTOMIZED_ALLOCATION_CUTOFF_VALUE); - } - - @Override - public ArrowBuf empty() { - return null; - } - }).build()); + return new RootAllocator( + RootAllocator.configBuilder() + .allocationManagerFactory( + new AllocationManager.Factory() { + @Override + public AllocationManager create(BufferAllocator accountingAllocator, long size) { + return new NettyAllocationManager( + accountingAllocator, size, CUSTOMIZED_ALLOCATION_CUTOFF_VALUE); + } + + @Override + public ArrowBuf empty() { + return null; + } + }) + .build()); } private void readWriteArrowBuf(ArrowBuf buffer) { @@ -64,14 +66,12 @@ private void readWriteArrowBuf(ArrowBuf buffer) { } } - /** - * Test the allocation strategy for small buffers.. - */ + /** Test the allocation strategy for small buffers.. */ @Test public void testSmallBufferAllocation() { final long bufSize = CUSTOMIZED_ALLOCATION_CUTOFF_VALUE - 512L; try (RootAllocator allocator = createCustomizedAllocator(); - ArrowBuf buffer = allocator.buffer(bufSize)) { + ArrowBuf buffer = allocator.buffer(bufSize)) { assertTrue(buffer.getReferenceManager() instanceof BufferLedger); BufferLedger bufferLedger = (BufferLedger) buffer.getReferenceManager(); @@ -88,14 +88,12 @@ public void testSmallBufferAllocation() { } } - /** - * Test the allocation strategy for large buffers.. - */ + /** Test the allocation strategy for large buffers.. */ @Test public void testLargeBufferAllocation() { final long bufSize = CUSTOMIZED_ALLOCATION_CUTOFF_VALUE + 1024L; try (RootAllocator allocator = createCustomizedAllocator(); - ArrowBuf buffer = allocator.buffer(bufSize)) { + ArrowBuf buffer = allocator.buffer(bufSize)) { assertTrue(buffer.getReferenceManager() instanceof BufferLedger); BufferLedger bufferLedger = (BufferLedger) buffer.getReferenceManager(); diff --git a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocator.java b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocator.java index 07fdc3f784e..8c312b83ce6 100644 --- a/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocator.java +++ b/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/netty/TestNettyAllocator.java @@ -19,23 +19,19 @@ import static org.junit.Assert.assertTrue; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; +import io.netty.buffer.PooledByteBufAllocatorL; import java.util.Collections; import java.util.stream.Collectors; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.ReferenceManager; import org.junit.Test; import org.slf4j.LoggerFactory; -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.read.ListAppender; -import io.netty.buffer.PooledByteBufAllocatorL; - -/** - * Test netty allocators. - */ +/** Test netty allocators. */ public class TestNettyAllocator { @Test @@ -47,30 +43,41 @@ public void testMemoryUsage() { logger.setLevel(Level.TRACE); logger.addAppender(memoryLogsAppender); memoryLogsAppender.start(); - try (ArrowBuf buf = new ArrowBuf(ReferenceManager.NO_OP, null, - 1024, new PooledByteBufAllocatorL().empty.memoryAddress())) { + try (ArrowBuf buf = + new ArrowBuf( + ReferenceManager.NO_OP, + null, + 1024, + new PooledByteBufAllocatorL().empty.memoryAddress())) { buf.memoryAddress(); } boolean result = false; long startTime = System.currentTimeMillis(); - while ((System.currentTimeMillis() - startTime) < 10000) { // 10 seconds maximum for time to read logs - // Lock on the list backing the appender since a background thread might try to add more logs - // while stream() is iterating over list elements. This would throw a flakey ConcurrentModificationException. + while ((System.currentTimeMillis() - startTime) + < 10000) { // 10 seconds maximum for time to read logs + // Lock on the list backing the appender since a background thread might try to add more + // logs + // while stream() is iterating over list elements. This would throw a flakey + // ConcurrentModificationException. synchronized (memoryLogsAppender.list) { - result = memoryLogsAppender.list.stream() - .anyMatch( - log -> log.toString().contains("Memory Usage: \n") && - log.toString().contains("Large buffers outstanding: ") && - log.toString().contains("Normal buffers outstanding: ") && - log.getLevel().equals(Level.TRACE) - ); + result = + memoryLogsAppender.list.stream() + .anyMatch( + log -> + log.toString().contains("Memory Usage: \n") + && log.toString().contains("Large buffers outstanding: ") + && log.toString().contains("Normal buffers outstanding: ") + && log.getLevel().equals(Level.TRACE)); } if (result) { break; } } - assertTrue("Log messages are:\n" + - memoryLogsAppender.list.stream().map(ILoggingEvent::toString).collect(Collectors.joining("\n")), + assertTrue( + "Log messages are:\n" + + memoryLogsAppender.list.stream() + .map(ILoggingEvent::toString) + .collect(Collectors.joining("\n")), result); } finally { memoryLogsAppender.stop(); diff --git a/java/memory/memory-netty/src/test/resources/logback.xml b/java/memory/memory-netty/src/test/resources/logback.xml index 4c54d18a210..9fa3f1e3b43 100644 --- a/java/memory/memory-netty/src/test/resources/logback.xml +++ b/java/memory/memory-netty/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/memory/memory-unsafe/src/main/java/module-info.java b/java/memory/memory-unsafe/src/main/java/module-info.java index aa340d21716..526ebbdabbf 100644 --- a/java/memory/memory-unsafe/src/main/java/module-info.java +++ b/java/memory/memory-unsafe/src/main/java/module-info.java @@ -16,7 +16,8 @@ */ module org.apache.arrow.memory.unsafe { - exports org.apache.arrow.memory.unsafe to org.apache.arrow.memory.core; - + exports org.apache.arrow.memory.unsafe to + org.apache.arrow.memory.core; + requires org.apache.arrow.memory.core; } diff --git a/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/DefaultAllocationManagerFactory.java b/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/DefaultAllocationManagerFactory.java index dfb6c706856..7dc9db5df42 100644 --- a/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/DefaultAllocationManagerFactory.java +++ b/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/DefaultAllocationManagerFactory.java @@ -21,10 +21,7 @@ import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; -/** - * The default Allocation Manager Factory for a module. - * - */ +/** The default Allocation Manager Factory for a module. */ public class DefaultAllocationManagerFactory implements AllocationManager.Factory { public static final AllocationManager.Factory FACTORY = UnsafeAllocationManager.FACTORY; diff --git a/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/UnsafeAllocationManager.java b/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/UnsafeAllocationManager.java index 3468a6ec65c..02d79bd041a 100644 --- a/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/UnsafeAllocationManager.java +++ b/java/memory/memory-unsafe/src/main/java/org/apache/arrow/memory/unsafe/UnsafeAllocationManager.java @@ -23,28 +23,24 @@ import org.apache.arrow.memory.ReferenceManager; import org.apache.arrow.memory.util.MemoryUtil; -/** - * Allocation manager based on unsafe API. - */ +/** Allocation manager based on unsafe API. */ public final class UnsafeAllocationManager extends AllocationManager { - private static final ArrowBuf EMPTY = new ArrowBuf(ReferenceManager.NO_OP, - null, - 0, - MemoryUtil.UNSAFE.allocateMemory(0) - ); + private static final ArrowBuf EMPTY = + new ArrowBuf(ReferenceManager.NO_OP, null, 0, MemoryUtil.UNSAFE.allocateMemory(0)); - public static final AllocationManager.Factory FACTORY = new Factory() { - @Override - public AllocationManager create(BufferAllocator accountingAllocator, long size) { - return new UnsafeAllocationManager(accountingAllocator, size); - } + public static final AllocationManager.Factory FACTORY = + new Factory() { + @Override + public AllocationManager create(BufferAllocator accountingAllocator, long size) { + return new UnsafeAllocationManager(accountingAllocator, size); + } - @Override - public ArrowBuf empty() { - return EMPTY; - } - }; + @Override + public ArrowBuf empty() { + return EMPTY; + } + }; private final long allocatedSize; @@ -70,5 +66,4 @@ protected long memoryAddress() { protected void release0() { MemoryUtil.UNSAFE.freeMemory(allocatedAddress); } - } diff --git a/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestAllocationManagerUnsafe.java b/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestAllocationManagerUnsafe.java index f1ca96eea0f..25be2cc424f 100644 --- a/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestAllocationManagerUnsafe.java +++ b/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestAllocationManagerUnsafe.java @@ -23,9 +23,7 @@ import org.apache.arrow.memory.DefaultAllocationManagerOption; import org.junit.Test; -/** - * Test cases for {@link AllocationManager}. - */ +/** Test cases for {@link AllocationManager}. */ public class TestAllocationManagerUnsafe { @Test @@ -38,6 +36,5 @@ public void testAllocationManagerType() { DefaultAllocationManagerOption.getDefaultAllocationManagerType(); assertEquals(DefaultAllocationManagerOption.AllocationManagerType.Unsafe, mgrType); - } } diff --git a/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestUnsafeAllocationManager.java b/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestUnsafeAllocationManager.java index 77233e73cb3..67ae649335a 100644 --- a/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestUnsafeAllocationManager.java +++ b/java/memory/memory-unsafe/src/test/java/org/apache/arrow/memory/unsafe/TestUnsafeAllocationManager.java @@ -27,14 +27,14 @@ import org.apache.arrow.memory.RootAllocator; import org.junit.Test; -/** - * Test cases for {@link UnsafeAllocationManager}. - */ +/** Test cases for {@link UnsafeAllocationManager}. */ public class TestUnsafeAllocationManager { private BufferAllocator createUnsafeAllocator() { - return new RootAllocator(RootAllocator.configBuilder().allocationManagerFactory(UnsafeAllocationManager.FACTORY) - .build()); + return new RootAllocator( + RootAllocator.configBuilder() + .allocationManagerFactory(UnsafeAllocationManager.FACTORY) + .build()); } private void readWriteArrowBuf(ArrowBuf buffer) { @@ -50,14 +50,12 @@ private void readWriteArrowBuf(ArrowBuf buffer) { } } - /** - * Test the memory allocation for {@link UnsafeAllocationManager}. - */ + /** Test the memory allocation for {@link UnsafeAllocationManager}. */ @Test public void testBufferAllocation() { final long bufSize = 4096L; try (BufferAllocator allocator = createUnsafeAllocator(); - ArrowBuf buffer = allocator.buffer(bufSize)) { + ArrowBuf buffer = allocator.buffer(bufSize)) { assertTrue(buffer.getReferenceManager() instanceof BufferLedger); BufferLedger bufferLedger = (BufferLedger) buffer.getReferenceManager(); diff --git a/java/memory/memory-unsafe/src/test/resources/logback.xml b/java/memory/memory-unsafe/src/test/resources/logback.xml index 4c54d18a210..9fa3f1e3b43 100644 --- a/java/memory/memory-unsafe/src/test/resources/logback.xml +++ b/java/memory/memory-unsafe/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/memory/pom.xml b/java/memory/pom.xml index 55fbb90353f..6cb2617388d 100644 --- a/java/memory/pom.xml +++ b/java/memory/pom.xml @@ -1,4 +1,4 @@ - + - diff --git a/java/vector/pom.xml b/java/vector/pom.xml index da26fc29827..307e8734adc 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -1,4 +1,4 @@ - + sourceVector index: " + (start + i) + - " toVector index: " + i, expected, actual); + assertEquals( + "different data values not expected --> sourceVector index: " + + (start + i) + + " toVector index: " + + i, + expected, + actual); } } } @@ -167,8 +171,13 @@ public void testSplitAndTransfer1() throws Exception { for (int i = 0; i < length; i++) { int actual = toVector.get(i); int expected = sourceVector.get(start + i); - assertEquals("different data values not expected --> sourceVector index: " + (start + i) + - " toVector index: " + i, expected, actual); + assertEquals( + "different data values not expected --> sourceVector index: " + + (start + i) + + " toVector index: " + + i, + expected, + actual); } } } @@ -206,7 +215,9 @@ public void testSplitAndTransfer2() throws Exception { try (final BitVector toVector = new BitVector("toVector", allocator)) { final TransferPair transferPair = sourceVector.makeTransferPair(toVector); - final int[][] transferLengths = {{5, 22}, {5, 24}, {5, 25}, {5, 27}, {0, 31}, {5, 7}, {2, 3}}; + final int[][] transferLengths = { + {5, 22}, {5, 24}, {5, 25}, {5, 27}, {0, 31}, {5, 7}, {2, 3} + }; for (final int[] transferLength : transferLengths) { final int start = transferLength[0]; @@ -218,8 +229,13 @@ public void testSplitAndTransfer2() throws Exception { for (int i = 0; i < length; i++) { int actual = toVector.get(i); int expected = sourceVector.get(start + i); - assertEquals("different data values not expected --> sourceVector index: " + (start + i) + - " toVector index: " + i, expected, actual); + assertEquals( + "different data values not expected --> sourceVector index: " + + (start + i) + + " toVector index: " + + i, + expected, + actual); } } } @@ -295,8 +311,10 @@ public void testReallocAfterVectorTransfer1() { for (int i = 0; i < toVector.getValueCapacity(); i++) { if (i <= valueCapacity * 4) { - if (((i & 1) == 1) || (i == valueCapacity) || - (i == valueCapacity * 2) || (i == valueCapacity * 4)) { + if (((i & 1) == 1) + || (i == valueCapacity) + || (i == valueCapacity * 2) + || (i == valueCapacity * 4)) { assertEquals("unexpected cleared bit at index: " + i, 1, toVector.get(i)); } else { assertTrue("unexpected set bit at index: " + i, toVector.isNull(i)); @@ -379,8 +397,10 @@ public void testReallocAfterVectorTransfer2() { for (int i = 0; i < toVector.getValueCapacity(); i++) { if (i <= valueCapacity * 4) { - if (((i & 1) == 1) || (i == valueCapacity) || - (i == valueCapacity * 2) || (i == valueCapacity * 4)) { + if (((i & 1) == 1) + || (i == valueCapacity) + || (i == valueCapacity * 2) + || (i == valueCapacity * 4)) { assertFalse("unexpected cleared bit at index: " + i, toVector.isNull(i)); } else { assertTrue("unexpected set bit at index: " + i, toVector.isNull(i)); @@ -547,7 +567,8 @@ public void testGetTransferPairWithField() { final BitVector fromVector = new BitVector(EMPTY_SCHEMA_PATH, allocator); final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); final BitVector toVector = (BitVector) transferPair.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(fromVector.getField(), toVector.getField()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java index 96005dc511c..770f0b21c2e 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java @@ -114,7 +114,7 @@ public void testAllBitsNull() { public void testAllBitsSet() { final int bufferLength = 32 * 1024; try (RootAllocator allocator = new RootAllocator(bufferLength); - ArrowBuf validityBuffer = allocator.buffer(bufferLength)) { + ArrowBuf validityBuffer = allocator.buffer(bufferLength)) { MemoryUtil.UNSAFE.setMemory(validityBuffer.memoryAddress(), bufferLength, (byte) -1); int bitLength = 1024; @@ -155,8 +155,8 @@ public void testAllBitsSet() { public void testConcatBits() { try (RootAllocator allocator = new RootAllocator(1024 * 1024)) { try (ArrowBuf buf1 = allocator.buffer(1024); - ArrowBuf buf2 = allocator.buffer(1024); - ArrowBuf output = allocator.buffer(1024)) { + ArrowBuf buf2 = allocator.buffer(1024); + ArrowBuf output = allocator.buffer(1024)) { buf1.setZero(0, buf1.capacity()); buf2.setZero(0, buf2.capacity()); @@ -191,7 +191,7 @@ public void testConcatBits() { public void testConcatBitsInPlace() { try (RootAllocator allocator = new RootAllocator(1024 * 1024)) { try (ArrowBuf buf1 = allocator.buffer(1024); - ArrowBuf buf2 = allocator.buffer(1024)) { + ArrowBuf buf2 = allocator.buffer(1024)) { buf1.setZero(0, buf1.capacity()); buf2.setZero(0, buf2.capacity()); @@ -247,14 +247,14 @@ public void testLoadValidityBuffer() { // null fieldNode = new ArrowFieldNode(1024, 1024); try (ArrowBuf src = allocator.buffer(128); - ArrowBuf dst = BitVectorHelper.loadValidityBuffer(fieldNode, src, allocator)) { + ArrowBuf dst = BitVectorHelper.loadValidityBuffer(fieldNode, src, allocator)) { assertEquals(128, allocator.getAllocatedMemory()); } // ... similarly if all values are not null fieldNode = new ArrowFieldNode(1024, 0); try (ArrowBuf src = allocator.buffer(128); - ArrowBuf dst = BitVectorHelper.loadValidityBuffer(fieldNode, src, allocator)) { + ArrowBuf dst = BitVectorHelper.loadValidityBuffer(fieldNode, src, allocator)) { assertEquals(128, allocator.getAllocatedMemory()); } @@ -277,7 +277,8 @@ public void testLoadValidityBuffer() { } } - private void concatAndVerify(ArrowBuf buf1, int count1, ArrowBuf buf2, int count2, ArrowBuf output) { + private void concatAndVerify( + ArrowBuf buf1, int count1, ArrowBuf buf2, int count2, ArrowBuf output) { BitVectorHelper.concatBits(buf1, count1, buf2, count2, output); int outputIdx = 0; for (int i = 0; i < count1; i++, outputIdx++) { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestBufferOwnershipTransfer.java b/java/vector/src/test/java/org/apache/arrow/vector/TestBufferOwnershipTransfer.java index 8efadad9b3b..721de2b3fc5 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestBufferOwnershipTransfer.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestBufferOwnershipTransfer.java @@ -103,12 +103,18 @@ public void emptyListTransferShouldNotTriggerSchemaChange() { final Pointer trigger1 = new Pointer<>(); final Pointer trigger2 = new Pointer<>(); - final ListVector v1 = new ListVector("v1", allocator, - FieldType.nullable(ArrowType.Null.INSTANCE), - newTriggerCallback(trigger1)); - final ListVector v2 = new ListVector("v2", allocator, - FieldType.nullable(ArrowType.Null.INSTANCE), - newTriggerCallback(trigger2)); + final ListVector v1 = + new ListVector( + "v1", + allocator, + FieldType.nullable(ArrowType.Null.INSTANCE), + newTriggerCallback(trigger1)); + final ListVector v2 = + new ListVector( + "v2", + allocator, + FieldType.nullable(ArrowType.Null.INSTANCE), + newTriggerCallback(trigger2)); try { // since we are working with empty vectors, their internal diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java b/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java index 3786f63c31b..f18eccf9850 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java @@ -26,7 +26,6 @@ import java.nio.charset.Charset; import java.time.Duration; import java.time.Period; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.types.Types.MinorType; @@ -1071,16 +1070,15 @@ public void testCopyFromWithNulls14() { } } - @Test //https://issues.apache.org/jira/browse/ARROW-7837 + @Test // https://issues.apache.org/jira/browse/ARROW-7837 public void testCopySafeArrow7837() { // this test exposes a bug in `handleSafe` where // it reads a stale index and as a result missed a required resize of the value vector. try (VarCharVector vc1 = new VarCharVector("vc1", allocator); - VarCharVector vc2 = new VarCharVector("vc2", allocator); - ) { - //initial size is carefully set in order to force the second 'copyFromSafe' operation + VarCharVector vc2 = new VarCharVector("vc2", allocator); ) { + // initial size is carefully set in order to force the second 'copyFromSafe' operation // to trigger a reallocation of the vector. - vc2.setInitialCapacity(/*valueCount*/20, /*density*/0.5); + vc2.setInitialCapacity(/*valueCount*/ 20, /*density*/ 0.5); vc1.setSafe(0, "1234567890".getBytes(Charset.forName("utf-8"))); assertFalse(vc1.isNull(0)); @@ -1099,6 +1097,4 @@ public void testCopySafeArrow7837() { assertEquals(vc2.getObject(5).toString(), "1234567890"); } } - - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java index b703959d2bb..24b857020c1 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java @@ -24,7 +24,6 @@ import java.math.BigDecimal; import java.math.BigInteger; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.types.pojo.ArrowType; @@ -61,10 +60,15 @@ public void terminate() throws Exception { @Test public void testValuesWriteRead() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(10, scale, 256), allocator);) { - - try (Decimal256Vector oldConstructor = new Decimal256Vector("decimal", allocator, 10, scale);) { + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, + "decimal", + new ArrowType.Decimal(10, scale, 256), + allocator); ) { + + try (Decimal256Vector oldConstructor = + new Decimal256Vector("decimal", allocator, 10, scale); ) { assertEquals(decimalVector.getField().getType(), oldConstructor.getField().getType()); } @@ -87,32 +91,39 @@ public void testValuesWriteRead() { @Test public void testDecimal256DifferentScaleAndPrecision() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(4, 2, 256), allocator)) { + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(4, 2, 256), allocator)) { decimalVector.allocateNew(); // test Decimal256 with different scale { BigDecimal decimal = new BigDecimal(BigInteger.valueOf(0), 3); UnsupportedOperationException ue = - assertThrows(UnsupportedOperationException.class, () -> decimalVector.setSafe(0, decimal)); - assertEquals("BigDecimal scale must equal that in the Arrow vector: 3 != 2", ue.getMessage()); + assertThrows( + UnsupportedOperationException.class, () -> decimalVector.setSafe(0, decimal)); + assertEquals( + "BigDecimal scale must equal that in the Arrow vector: 3 != 2", ue.getMessage()); } // test BigDecimal with larger precision than initialized { BigDecimal decimal = new BigDecimal(BigInteger.valueOf(12345), 2); UnsupportedOperationException ue = - assertThrows(UnsupportedOperationException.class, () -> decimalVector.setSafe(0, decimal)); - assertEquals("BigDecimal precision cannot be greater than that in the Arrow vector: 5 > 4", ue.getMessage()); + assertThrows( + UnsupportedOperationException.class, () -> decimalVector.setSafe(0, decimal)); + assertEquals( + "BigDecimal precision cannot be greater than that in the Arrow vector: 5 > 4", + ue.getMessage()); } } } @Test public void testWriteBigEndian() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(38, 18, 256), allocator);) { + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(38, 18, 256), allocator); ) { decimalVector.allocateNew(); BigDecimal decimal1 = new BigDecimal("123456789.000000000000000000"); BigDecimal decimal2 = new BigDecimal("11.123456789123456789"); @@ -156,8 +167,9 @@ public void testWriteBigEndian() { @Test public void testLongReadWrite() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(38, 0, 256), allocator)) { + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(38, 0, 256), allocator)) { decimalVector.allocateNew(); long[] longValues = {0L, -2L, Long.MAX_VALUE, Long.MIN_VALUE, 187L}; @@ -174,11 +186,11 @@ public void testLongReadWrite() { } } - @Test public void testBigDecimalReadWrite() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(38, 9, 256), allocator);) { + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(38, 9, 256), allocator); ) { decimalVector.allocateNew(); BigDecimal decimal1 = new BigDecimal("123456789.000000000"); BigDecimal decimal2 = new BigDecimal("11.123456789"); @@ -212,29 +224,33 @@ public void testBigDecimalReadWrite() { } /** - * Test {@link Decimal256Vector#setBigEndian(int, byte[])} which takes BE layout input and stores in native-endian - * (NE) layout. - * Cases to cover: input byte array in different lengths in range [1-16] and negative values. + * Test {@link Decimal256Vector#setBigEndian(int, byte[])} which takes BE layout input and stores + * in native-endian (NE) layout. Cases to cover: input byte array in different lengths in range + * [1-16] and negative values. */ @Test public void decimalBE2NE() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(23, 2, 256), allocator)) { + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(23, 2, 256), allocator)) { decimalVector.allocateNew(); - BigInteger[] testBigInts = new BigInteger[] { - new BigInteger("0"), - new BigInteger("-1"), - new BigInteger("23"), - new BigInteger("234234"), - new BigInteger("-234234234"), - new BigInteger("234234234234"), - new BigInteger("-56345345345345"), - new BigInteger("2982346298346289346293467923465345634500"), // converts to 16+ byte array - new BigInteger("-389457298347598237459832459823434653600"), // converts to 16+ byte array - new BigInteger("-345345"), - new BigInteger("754533") - }; + BigInteger[] testBigInts = + new BigInteger[] { + new BigInteger("0"), + new BigInteger("-1"), + new BigInteger("23"), + new BigInteger("234234"), + new BigInteger("-234234234"), + new BigInteger("234234234234"), + new BigInteger("-56345345345345"), + new BigInteger( + "2982346298346289346293467923465345634500"), // converts to 16+ byte array + new BigInteger( + "-389457298347598237459832459823434653600"), // converts to 16+ byte array + new BigInteger("-345345"), + new BigInteger("754533") + }; int insertionIdx = 0; insertionIdx++; // insert a null @@ -247,9 +263,12 @@ public void decimalBE2NE() { // Try inserting a buffer larger than 33 bytes and expect a failure final int insertionIdxCapture = insertionIdx; - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> decimalVector.setBigEndian(insertionIdxCapture, new byte[33])); - assertTrue(ex.getMessage().equals("Invalid decimal value length. Valid length in [1 - 32], got 33")); + IllegalArgumentException ex = + assertThrows( + IllegalArgumentException.class, + () -> decimalVector.setBigEndian(insertionIdxCapture, new byte[33])); + assertTrue( + ex.getMessage().equals("Invalid decimal value length. Valid length in [1 - 32], got 33")); decimalVector.setValueCount(insertionIdx); // retrieve values and check if they are correct @@ -266,9 +285,10 @@ public void decimalBE2NE() { @Test public void setUsingArrowBufOfLEInts() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(5, 2, 256), allocator); - ArrowBuf buf = allocator.buffer(8);) { + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(5, 2, 256), allocator); + ArrowBuf buf = allocator.buffer(8); ) { decimalVector.allocateNew(); // add a positive value equivalent to 705.32 @@ -283,21 +303,21 @@ public void setUsingArrowBufOfLEInts() { decimalVector.setValueCount(2); - BigDecimal [] expectedValues = new BigDecimal[] {BigDecimal.valueOf(705.32), BigDecimal - .valueOf(-705.32)}; - for (int i = 0; i < 2; i ++) { + BigDecimal[] expectedValues = + new BigDecimal[] {BigDecimal.valueOf(705.32), BigDecimal.valueOf(-705.32)}; + for (int i = 0; i < 2; i++) { BigDecimal value = decimalVector.getObject(i); assertEquals(expectedValues[i], value); } } - } @Test public void setUsingArrowLongLEBytes() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(18, 0, 256), allocator); - ArrowBuf buf = allocator.buffer(16);) { + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(18, 0, 256), allocator); + ArrowBuf buf = allocator.buffer(16); ) { decimalVector.allocateNew(); long val = Long.MAX_VALUE; @@ -310,9 +330,9 @@ public void setUsingArrowLongLEBytes() { decimalVector.setValueCount(2); - BigDecimal [] expectedValues = new BigDecimal[] {BigDecimal.valueOf(Long.MAX_VALUE), BigDecimal - .valueOf(Long.MIN_VALUE)}; - for (int i = 0; i < 2; i ++) { + BigDecimal[] expectedValues = + new BigDecimal[] {BigDecimal.valueOf(Long.MAX_VALUE), BigDecimal.valueOf(Long.MIN_VALUE)}; + for (int i = 0; i < 2; i++) { BigDecimal value = decimalVector.getObject(i); assertEquals(expectedValues[i], value); } @@ -321,20 +341,27 @@ public void setUsingArrowLongLEBytes() { @Test public void setUsingArrowBufOfBEBytes() { - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(5, 2, 256), allocator); - ArrowBuf buf = allocator.buffer(9);) { - BigDecimal [] expectedValues = new BigDecimal[] {BigDecimal.valueOf(705.32), BigDecimal - .valueOf(-705.32), BigDecimal.valueOf(705.32)}; + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(5, 2, 256), allocator); + ArrowBuf buf = allocator.buffer(9); ) { + BigDecimal[] expectedValues = + new BigDecimal[] { + BigDecimal.valueOf(705.32), BigDecimal.valueOf(-705.32), BigDecimal.valueOf(705.32) + }; verifyWritingArrowBufWithBigEndianBytes(decimalVector, buf, expectedValues, 3); } - try (Decimal256Vector decimalVector = TestUtils.newVector(Decimal256Vector.class, "decimal", - new ArrowType.Decimal(43, 2, 256), allocator); - ArrowBuf buf = allocator.buffer(45);) { - BigDecimal[] expectedValues = new BigDecimal[] {new BigDecimal("29823462983462893462934679234653450000000.63"), - new BigDecimal("-2982346298346289346293467923465345.63"), - new BigDecimal("2982346298346289346293467923465345.63")}; + try (Decimal256Vector decimalVector = + TestUtils.newVector( + Decimal256Vector.class, "decimal", new ArrowType.Decimal(43, 2, 256), allocator); + ArrowBuf buf = allocator.buffer(45); ) { + BigDecimal[] expectedValues = + new BigDecimal[] { + new BigDecimal("29823462983462893462934679234653450000000.63"), + new BigDecimal("-2982346298346289346293467923465345.63"), + new BigDecimal("2982346298346289346293467923465345.63") + }; verifyWritingArrowBufWithBigEndianBytes(decimalVector, buf, expectedValues, 15); } } @@ -344,23 +371,23 @@ public void testGetTransferPairWithField() { final Decimal256Vector fromVector = new Decimal256Vector("decimal", allocator, 10, scale); final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); final Decimal256Vector toVector = (Decimal256Vector) transferPair.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(fromVector.getField(), toVector.getField()); } - private void verifyWritingArrowBufWithBigEndianBytes(Decimal256Vector decimalVector, - ArrowBuf buf, BigDecimal[] expectedValues, - int length) { + private void verifyWritingArrowBufWithBigEndianBytes( + Decimal256Vector decimalVector, ArrowBuf buf, BigDecimal[] expectedValues, int length) { decimalVector.allocateNew(); for (int i = 0; i < expectedValues.length; i++) { byte[] bigEndianBytes = expectedValues[i].unscaledValue().toByteArray(); - buf.setBytes(length * i , bigEndianBytes, 0 , bigEndianBytes.length); + buf.setBytes(length * i, bigEndianBytes, 0, bigEndianBytes.length); decimalVector.setBigEndianSafe(i, length * i, buf, bigEndianBytes.length); } decimalVector.setValueCount(3); - for (int i = 0; i < expectedValues.length; i ++) { + for (int i = 0; i < expectedValues.length; i++) { BigDecimal value = decimalVector.getObject(i); assertEquals(expectedValues[i], value); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java index ba25cbe8b52..803f78cbf81 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java @@ -24,7 +24,6 @@ import java.math.BigDecimal; import java.math.BigInteger; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.types.pojo.ArrowType; @@ -61,10 +60,11 @@ public void terminate() throws Exception { @Test public void testValuesWriteRead() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(10, scale, 128), allocator);) { + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(10, scale, 128), allocator); ) { - try (DecimalVector oldConstructor = new DecimalVector("decimal", allocator, 10, scale);) { + try (DecimalVector oldConstructor = new DecimalVector("decimal", allocator, 10, scale); ) { assertEquals(decimalVector.getField().getType(), oldConstructor.getField().getType()); } @@ -87,8 +87,9 @@ public void testValuesWriteRead() { @Test public void testBigDecimalDifferentScaleAndPrecision() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(4, 2, 128), allocator);) { + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(4, 2, 128), allocator); ) { decimalVector.allocateNew(); // test BigDecimal with different scale @@ -117,8 +118,9 @@ public void testBigDecimalDifferentScaleAndPrecision() { @Test public void testWriteBigEndian() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(38, 9, 128), allocator);) { + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(38, 9, 128), allocator); ) { decimalVector.allocateNew(); BigDecimal decimal1 = new BigDecimal("123456789.000000000"); BigDecimal decimal2 = new BigDecimal("11.123456789"); @@ -162,8 +164,9 @@ public void testWriteBigEndian() { @Test public void testLongReadWrite() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(38, 0, 128), allocator)) { + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(38, 0, 128), allocator)) { decimalVector.allocateNew(); long[] longValues = {0L, -2L, Long.MAX_VALUE, Long.MIN_VALUE, 187L}; @@ -180,11 +183,11 @@ public void testLongReadWrite() { } } - @Test public void testBigDecimalReadWrite() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(38, 9, 128), allocator);) { + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(38, 9, 128), allocator); ) { decimalVector.allocateNew(); BigDecimal decimal1 = new BigDecimal("123456789.000000000"); BigDecimal decimal2 = new BigDecimal("11.123456789"); @@ -218,29 +221,31 @@ public void testBigDecimalReadWrite() { } /** - * Test {@link DecimalVector#setBigEndian(int, byte[])} which takes BE layout input and stores in native-endian (NE) - * layout. - * Cases to cover: input byte array in different lengths in range [1-16] and negative values. + * Test {@link DecimalVector#setBigEndian(int, byte[])} which takes BE layout input and stores in + * native-endian (NE) layout. Cases to cover: input byte array in different lengths in range + * [1-16] and negative values. */ @Test public void decimalBE2NE() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(21, 2, 128), allocator)) { + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(21, 2, 128), allocator)) { decimalVector.allocateNew(); - BigInteger[] testBigInts = new BigInteger[] { - new BigInteger("0"), - new BigInteger("-1"), - new BigInteger("23"), - new BigInteger("234234"), - new BigInteger("-234234234"), - new BigInteger("234234234234"), - new BigInteger("-56345345345345"), - new BigInteger("29823462983462893462934679234653456345"), // converts to 16 byte array - new BigInteger("-3894572983475982374598324598234346536"), // converts to 16 byte array - new BigInteger("-345345"), - new BigInteger("754533") - }; + BigInteger[] testBigInts = + new BigInteger[] { + new BigInteger("0"), + new BigInteger("-1"), + new BigInteger("23"), + new BigInteger("234234"), + new BigInteger("-234234234"), + new BigInteger("234234234234"), + new BigInteger("-56345345345345"), + new BigInteger("29823462983462893462934679234653456345"), // converts to 16 byte array + new BigInteger("-3894572983475982374598324598234346536"), // converts to 16 byte array + new BigInteger("-345345"), + new BigInteger("754533") + }; int insertionIdx = 0; insertionIdx++; // insert a null @@ -256,7 +261,9 @@ public void decimalBE2NE() { decimalVector.setBigEndian(insertionIdx, new byte[17]); fail("above statement should have failed"); } catch (IllegalArgumentException ex) { - assertTrue(ex.getMessage().equals("Invalid decimal value length. Valid length in [1 - 16], got 17")); + assertTrue( + ex.getMessage() + .equals("Invalid decimal value length. Valid length in [1 - 16], got 17")); } decimalVector.setValueCount(insertionIdx); @@ -274,9 +281,10 @@ public void decimalBE2NE() { @Test public void setUsingArrowBufOfInts() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(5, 2, 128), allocator); - ArrowBuf buf = allocator.buffer(8);) { + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(5, 2, 128), allocator); + ArrowBuf buf = allocator.buffer(8); ) { decimalVector.allocateNew(); // add a positive value equivalent to 705.32 @@ -291,21 +299,21 @@ public void setUsingArrowBufOfInts() { decimalVector.setValueCount(2); - BigDecimal [] expectedValues = new BigDecimal[] {BigDecimal.valueOf(705.32), BigDecimal - .valueOf(-705.32)}; - for (int i = 0; i < 2; i ++) { + BigDecimal[] expectedValues = + new BigDecimal[] {BigDecimal.valueOf(705.32), BigDecimal.valueOf(-705.32)}; + for (int i = 0; i < 2; i++) { BigDecimal value = decimalVector.getObject(i); assertEquals(expectedValues[i], value); } } - } @Test public void setUsingArrowLongBytes() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(18, 0, 128), allocator); - ArrowBuf buf = allocator.buffer(16);) { + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(18, 0, 128), allocator); + ArrowBuf buf = allocator.buffer(16); ) { decimalVector.allocateNew(); long val = Long.MAX_VALUE; @@ -318,9 +326,9 @@ public void setUsingArrowLongBytes() { decimalVector.setValueCount(2); - BigDecimal [] expectedValues = new BigDecimal[] {BigDecimal.valueOf(Long.MAX_VALUE), BigDecimal - .valueOf(Long.MIN_VALUE)}; - for (int i = 0; i < 2; i ++) { + BigDecimal[] expectedValues = + new BigDecimal[] {BigDecimal.valueOf(Long.MAX_VALUE), BigDecimal.valueOf(Long.MIN_VALUE)}; + for (int i = 0; i < 2; i++) { BigDecimal value = decimalVector.getObject(i); assertEquals(expectedValues[i], value); } @@ -329,20 +337,27 @@ public void setUsingArrowLongBytes() { @Test public void setUsingArrowBufOfBEBytes() { - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(5, 2, 128), allocator); - ArrowBuf buf = allocator.buffer(9);) { - BigDecimal [] expectedValues = new BigDecimal[] {BigDecimal.valueOf(705.32), BigDecimal - .valueOf(-705.32), BigDecimal.valueOf(705.32)}; + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(5, 2, 128), allocator); + ArrowBuf buf = allocator.buffer(9); ) { + BigDecimal[] expectedValues = + new BigDecimal[] { + BigDecimal.valueOf(705.32), BigDecimal.valueOf(-705.32), BigDecimal.valueOf(705.32) + }; verifyWritingArrowBufWithBigEndianBytes(decimalVector, buf, expectedValues, 3); } - try (DecimalVector decimalVector = TestUtils.newVector(DecimalVector.class, "decimal", - new ArrowType.Decimal(36, 2, 128), allocator); - ArrowBuf buf = allocator.buffer(45);) { - BigDecimal[] expectedValues = new BigDecimal[] {new BigDecimal("2982346298346289346293467923465345.63"), - new BigDecimal("-2982346298346289346293467923465345.63"), - new BigDecimal("2982346298346289346293467923465345.63")}; + try (DecimalVector decimalVector = + TestUtils.newVector( + DecimalVector.class, "decimal", new ArrowType.Decimal(36, 2, 128), allocator); + ArrowBuf buf = allocator.buffer(45); ) { + BigDecimal[] expectedValues = + new BigDecimal[] { + new BigDecimal("2982346298346289346293467923465345.63"), + new BigDecimal("-2982346298346289346293467923465345.63"), + new BigDecimal("2982346298346289346293467923465345.63") + }; verifyWritingArrowBufWithBigEndianBytes(decimalVector, buf, expectedValues, 15); } } @@ -352,23 +367,23 @@ public void testGetTransferPairWithField() { final DecimalVector fromVector = new DecimalVector("decimal", allocator, 10, scale); final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); final DecimalVector toVector = (DecimalVector) transferPair.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(fromVector.getField(), toVector.getField()); } - private void verifyWritingArrowBufWithBigEndianBytes(DecimalVector decimalVector, - ArrowBuf buf, BigDecimal[] expectedValues, - int length) { + private void verifyWritingArrowBufWithBigEndianBytes( + DecimalVector decimalVector, ArrowBuf buf, BigDecimal[] expectedValues, int length) { decimalVector.allocateNew(); for (int i = 0; i < expectedValues.length; i++) { - byte []bigEndianBytes = expectedValues[i].unscaledValue().toByteArray(); - buf.setBytes(length * i , bigEndianBytes, 0 , bigEndianBytes.length); + byte[] bigEndianBytes = expectedValues[i].unscaledValue().toByteArray(); + buf.setBytes(length * i, bigEndianBytes, 0, bigEndianBytes.length); decimalVector.setBigEndianSafe(i, length * i, buf, bigEndianBytes.length); } decimalVector.setValueCount(3); - for (int i = 0; i < expectedValues.length; i ++) { + for (int i = 0; i < expectedValues.length; i++) { BigDecimal value = decimalVector.getObject(i); assertEquals(expectedValues[i], value); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDenseUnionVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDenseUnionVector.java index 9cb12481612..546498985ea 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDenseUnionVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDenseUnionVector.java @@ -26,7 +26,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.DenseUnionVector; @@ -73,11 +72,13 @@ public void testDenseUnionVector() throws Exception { uInt4Holder.value = 100; uInt4Holder.isSet = 1; - try (DenseUnionVector unionVector = new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { + try (DenseUnionVector unionVector = + new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { unionVector.allocateNew(); // write some data - byte uint4TypeId = unionVector.registerNewTypeId(Field.nullable("", MinorType.UINT4.getType())); + byte uint4TypeId = + unionVector.registerNewTypeId(Field.nullable("", MinorType.UINT4.getType())); unionVector.setTypeId(0, uint4TypeId); unionVector.setSafe(0, uInt4Holder); unionVector.setTypeId(2, uint4TypeId); @@ -101,7 +102,8 @@ public void testDenseUnionVector() throws Exception { @Test public void testTransfer() throws Exception { - try (DenseUnionVector srcVector = new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { + try (DenseUnionVector srcVector = + new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { srcVector.allocateNew(); // write some data @@ -117,7 +119,8 @@ public void testTransfer() throws Exception { srcVector.setSafe(5, newBitHolder(false)); srcVector.setValueCount(6); - try (DenseUnionVector destVector = new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { + try (DenseUnionVector destVector = + new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { TransferPair pair = srcVector.makeTransferPair(destVector); // Creating the transfer should transfer the type of the field at least. @@ -152,7 +155,8 @@ public void testTransfer() throws Exception { @Test public void testSplitAndTransfer() throws Exception { - try (DenseUnionVector sourceVector = new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { + try (DenseUnionVector sourceVector = + new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { sourceVector.allocateNew(); @@ -203,18 +207,13 @@ public void testSplitAndTransfer() throws Exception { assertEquals(false, sourceVector.isNull(9)); assertEquals(50, sourceVector.getObject(9)); - try (DenseUnionVector toVector = new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { + try (DenseUnionVector toVector = + new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { toVector.registerNewTypeId(Field.nullable("", MinorType.INT.getType())); final TransferPair transferPair = sourceVector.makeTransferPair(toVector); - final int[][] transferLengths = {{0, 3}, - {3, 1}, - {4, 2}, - {6, 1}, - {7, 1}, - {8, 2} - }; + final int[][] transferLengths = {{0, 3}, {3, 1}, {4, 2}, {6, 1}, {7, 1}, {8, 2}}; for (final int[] transferLength : transferLengths) { final int start = transferLength[0]; @@ -224,8 +223,10 @@ public void testSplitAndTransfer() throws Exception { /* check the toVector output after doing the splitAndTransfer */ for (int i = 0; i < length; i++) { - assertEquals("Different data at indexes: " + (start + i) + "and " + i, sourceVector.getObject(start + i), - toVector.getObject(i)); + assertEquals( + "Different data at indexes: " + (start + i) + "and " + i, + sourceVector.getObject(start + i), + toVector.getObject(i)); } } } @@ -234,7 +235,8 @@ public void testSplitAndTransfer() throws Exception { @Test public void testSplitAndTransferWithMixedVectors() throws Exception { - try (DenseUnionVector sourceVector = new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { + try (DenseUnionVector sourceVector = + new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { sourceVector.allocateNew(); @@ -244,7 +246,8 @@ public void testSplitAndTransferWithMixedVectors() throws Exception { sourceVector.setTypeId(0, intTypeId); sourceVector.setSafe(0, newIntHolder(5)); - byte float4TypeId = sourceVector.registerNewTypeId(Field.nullable("", MinorType.FLOAT4.getType())); + byte float4TypeId = + sourceVector.registerNewTypeId(Field.nullable("", MinorType.FLOAT4.getType())); sourceVector.setTypeId(1, float4TypeId); sourceVector.setSafe(1, newFloat4Holder(5.5f)); @@ -297,18 +300,14 @@ public void testSplitAndTransferWithMixedVectors() throws Exception { assertEquals(false, sourceVector.isNull(9)); assertEquals(30.5f, sourceVector.getObject(9)); - try (DenseUnionVector toVector = new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { + try (DenseUnionVector toVector = + new DenseUnionVector(EMPTY_SCHEMA_PATH, allocator, null, null)) { toVector.registerNewTypeId(Field.nullable("", MinorType.INT.getType())); toVector.registerNewTypeId(Field.nullable("", MinorType.FLOAT4.getType())); final TransferPair transferPair = sourceVector.makeTransferPair(toVector); - final int[][] transferLengths = {{0, 2}, - {2, 1}, - {3, 2}, - {5, 3}, - {8, 2} - }; + final int[][] transferLengths = {{0, 2}, {2, 1}, {3, 2}, {5, 3}, {8, 2}}; for (final int[] transferLength : transferLengths) { final int start = transferLength[0]; @@ -318,7 +317,10 @@ public void testSplitAndTransferWithMixedVectors() throws Exception { /* check the toVector output after doing the splitAndTransfer */ for (int i = 0; i < length; i++) { - assertEquals("Different values at index: " + i, sourceVector.getObject(start + i), toVector.getObject(i)); + assertEquals( + "Different values at index: " + i, + sourceVector.getObject(start + i), + toVector.getObject(i)); } } } @@ -338,8 +340,9 @@ public void testGetFieldTypeInfo() throws Exception { children.add(new Field("int", FieldType.nullable(MinorType.INT.getType()), null)); children.add(new Field("varchar", FieldType.nullable(MinorType.VARCHAR.getType()), null)); - final FieldType fieldType = new FieldType(false, new ArrowType.Union(UnionMode.Dense, typeIds), - /*dictionary=*/null, metadata); + final FieldType fieldType = + new FieldType( + false, new ArrowType.Union(UnionMode.Dense, typeIds), /* dictionary= */ null, metadata); final Field field = new Field("union", fieldType, children); MinorType minorType = MinorType.DENSEUNION; @@ -414,26 +417,26 @@ public void testGetBufferAddress() throws Exception { } } - /** - * Test adding two struct vectors to the dense union vector. - */ + /** Test adding two struct vectors to the dense union vector. */ @Test public void testMultipleStructs() { FieldType type = new FieldType(true, ArrowType.Struct.INSTANCE, null, null); try (StructVector structVector1 = new StructVector("struct1", allocator, type, null); - StructVector structVector2 = new StructVector("struct2", allocator, type, null); - DenseUnionVector unionVector = DenseUnionVector.empty("union", allocator)) { + StructVector structVector2 = new StructVector("struct2", allocator, type, null); + DenseUnionVector unionVector = DenseUnionVector.empty("union", allocator)) { // prepare sub vectors // first struct vector: (int, int) - IntVector subVector11 = structVector1 - .addOrGet("sub11", FieldType.nullable(MinorType.INT.getType()), IntVector.class); + IntVector subVector11 = + structVector1.addOrGet( + "sub11", FieldType.nullable(MinorType.INT.getType()), IntVector.class); subVector11.allocateNew(); ValueVectorDataPopulator.setVector(subVector11, 0, 1); - IntVector subVector12 = structVector1 - .addOrGet("sub12", FieldType.nullable(MinorType.INT.getType()), IntVector.class); + IntVector subVector12 = + structVector1.addOrGet( + "sub12", FieldType.nullable(MinorType.INT.getType()), IntVector.class); subVector12.allocateNew(); ValueVectorDataPopulator.setVector(subVector12, 0, 10); @@ -442,13 +445,15 @@ public void testMultipleStructs() { structVector1.setValueCount(2); // second struct vector: (string, string) - VarCharVector subVector21 = structVector2 - .addOrGet("sub21", FieldType.nullable(MinorType.VARCHAR.getType()), VarCharVector.class); + VarCharVector subVector21 = + structVector2.addOrGet( + "sub21", FieldType.nullable(MinorType.VARCHAR.getType()), VarCharVector.class); subVector21.allocateNew(); ValueVectorDataPopulator.setVector(subVector21, "a0"); - VarCharVector subVector22 = structVector2 - .addOrGet("sub22", FieldType.nullable(MinorType.VARCHAR.getType()), VarCharVector.class); + VarCharVector subVector22 = + structVector2.addOrGet( + "sub22", FieldType.nullable(MinorType.VARCHAR.getType()), VarCharVector.class); subVector22.allocateNew(); ValueVectorDataPopulator.setVector(subVector22, "b0"); @@ -502,14 +507,12 @@ public void testMultipleStructs() { } } - /** - * Test adding two varchar vectors to the dense union vector. - */ + /** Test adding two varchar vectors to the dense union vector. */ @Test public void testMultipleVarChars() { try (VarCharVector childVector1 = new VarCharVector("child1", allocator); - VarCharVector childVector2 = new VarCharVector("child2", allocator); - DenseUnionVector unionVector = DenseUnionVector.empty("union", allocator)) { + VarCharVector childVector2 = new VarCharVector("child2", allocator); + DenseUnionVector unionVector = DenseUnionVector.empty("union", allocator)) { // prepare sub vectors ValueVectorDataPopulator.setVector(childVector1, "a0", "a4"); @@ -544,7 +547,6 @@ public void testMultipleVarChars() { unionVector.setTypeId(2, typeId2); offsetBuf.setInt(DenseUnionVector.OFFSET_WIDTH * 2, 1); - // slot 4 points to child1 unionVector.setTypeId(4, typeId1); offsetBuf.setInt(DenseUnionVector.OFFSET_WIDTH * 4, 1); @@ -581,11 +583,13 @@ public void testChildVectorValueCounts() { vector.setTypeId(0, intTypeId); intHolder.value = 7; vector.setSafe(0, intHolder); - byte longTypeId = vector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); + byte longTypeId = + vector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); vector.setTypeId(2, longTypeId); longHolder.value = 8L; vector.setSafe(2, longHolder); - byte floatTypeId = vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); + byte floatTypeId = + vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); vector.setTypeId(3, floatTypeId); floatHolder.value = 9.0f; vector.setSafe(3, floatHolder); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java index 501059733c6..22f3e335571 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.function.ToIntBiFunction; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.FixedSizeListVector; @@ -77,7 +76,7 @@ public void terminate() throws Exception { public void testEncodeStrings() { // Create a new value vector try (final VarCharVector vector = newVarCharVector("foo", allocator); - final VarCharVector dictionaryVector = newVarCharVector("dict", allocator);) { + final VarCharVector dictionaryVector = newVarCharVector("dict", allocator); ) { setVector(vector, zero, one, one, two, zero); setVector(dictionaryVector, zero, one, two); @@ -113,7 +112,7 @@ public void testEncodeStrings() { public void testEncodeLargeVector() { // Create a new value vector try (final VarCharVector vector = newVarCharVector("foo", allocator); - final VarCharVector dictionaryVector = newVarCharVector("dict", allocator);) { + final VarCharVector dictionaryVector = newVarCharVector("dict", allocator); ) { vector.allocateNew(); int count = 10000; @@ -154,30 +153,31 @@ public void testEncodeLargeVector() { public void testEncodeList() { // Create a new value vector try (final ListVector vector = ListVector.empty("vector", allocator); - final ListVector dictionaryVector = ListVector.empty("dict", allocator);) { + final ListVector dictionaryVector = ListVector.empty("dict", allocator); ) { UnionListWriter writer = vector.getWriter(); writer.allocate(); - //set some values - writeListVector(writer, new int[]{10, 20}); - writeListVector(writer, new int[]{10, 20}); - writeListVector(writer, new int[]{10, 20}); - writeListVector(writer, new int[]{30, 40, 50}); - writeListVector(writer, new int[]{30, 40, 50}); - writeListVector(writer, new int[]{10, 20}); + // set some values + writeListVector(writer, new int[] {10, 20}); + writeListVector(writer, new int[] {10, 20}); + writeListVector(writer, new int[] {10, 20}); + writeListVector(writer, new int[] {30, 40, 50}); + writeListVector(writer, new int[] {30, 40, 50}); + writeListVector(writer, new int[] {10, 20}); writer.setValueCount(6); UnionListWriter dictWriter = dictionaryVector.getWriter(); dictWriter.allocate(); - writeListVector(dictWriter, new int[]{10, 20}); - writeListVector(dictWriter, new int[]{30, 40, 50}); + writeListVector(dictWriter, new int[] {10, 20}); + writeListVector(dictWriter, new int[] {30, 40, 50}); dictWriter.setValueCount(2); - Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + Dictionary dictionary = + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); try (final ValueVector encoded = DictionaryEncoder.encode(vector, dictionary)) { // verify indices @@ -208,11 +208,13 @@ public void testEncodeList() { public void testEncodeStruct() { // Create a new value vector try (final StructVector vector = StructVector.empty("vector", allocator); - final StructVector dictionaryVector = StructVector.empty("dict", allocator);) { + final StructVector dictionaryVector = StructVector.empty("dict", allocator); ) { vector.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); vector.addOrGet("f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); - dictionaryVector.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); - dictionaryVector.addOrGet("f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); + dictionaryVector.addOrGet( + "f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); + dictionaryVector.addOrGet( + "f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); NullableStructWriter writer = vector.getWriter(); writer.allocate(); @@ -233,10 +235,10 @@ public void testEncodeStruct() { writeStructVector(dictWriter, 1, 10L); writeStructVector(dictWriter, 2, 20L); - dictionaryVector.setValueCount(2); - Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + Dictionary dictionary = + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); try (final ValueVector encoded = DictionaryEncoder.encode(vector, dictionary)) { // verify indices @@ -268,12 +270,13 @@ public void testEncodeStruct() { public void testEncodeBinaryVector() { // Create a new value vector try (final VarBinaryVector vector = newVarBinaryVector("foo", allocator); - final VarBinaryVector dictionaryVector = newVarBinaryVector("dict", allocator)) { + final VarBinaryVector dictionaryVector = newVarBinaryVector("dict", allocator)) { setVector(vector, zero, one, one, two, zero); setVector(dictionaryVector, zero, one, two); - Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + Dictionary dictionary = + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); try (final ValueVector encoded = DictionaryEncoder.encode(vector, dictionary)) { // verify indices @@ -288,7 +291,8 @@ public void testEncodeBinaryVector() { assertEquals(0, index.get(4)); // now run through the decoder and verify we get the original back - try (VarBinaryVector decoded = (VarBinaryVector) DictionaryEncoder.decode(encoded, dictionary)) { + try (VarBinaryVector decoded = + (VarBinaryVector) DictionaryEncoder.decode(encoded, dictionary)) { assertEquals(vector.getClass(), decoded.getClass()); assertEquals(vector.getValueCount(), decoded.getValueCount()); for (int i = 0; i < 5; i++) { @@ -302,9 +306,10 @@ public void testEncodeBinaryVector() { @Test public void testEncodeUnion() { // Create a new value vector - try (final UnionVector vector = new UnionVector("vector", allocator, /* field type */ null, /* call-back */ null); - final UnionVector dictionaryVector = - new UnionVector("dict", allocator, /* field type */ null, /* call-back */ null);) { + try (final UnionVector vector = + new UnionVector("vector", allocator, /* field type */ null, /* call-back */ null); + final UnionVector dictionaryVector = + new UnionVector("dict", allocator, /* field type */ null, /* call-back */ null); ) { final NullableUInt4Holder uintHolder1 = new NullableUInt4Holder(); uintHolder1.value = 10; @@ -318,7 +323,7 @@ public void testEncodeUnion() { intHolder2.value = 20; intHolder2.isSet = 1; - //write data + // write data vector.setType(0, Types.MinorType.UINT4); vector.setSafe(0, uintHolder1); @@ -336,7 +341,7 @@ public void testEncodeUnion() { vector.setValueCount(5); - //write dictionary + // write dictionary dictionaryVector.setType(0, Types.MinorType.UINT4); dictionaryVector.setSafe(0, uintHolder1); @@ -348,7 +353,8 @@ public void testEncodeUnion() { dictionaryVector.setValueCount(3); - Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + Dictionary dictionary = + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); try (final ValueVector encoded = DictionaryEncoder.encode(vector, dictionary)) { // verify indices @@ -376,9 +382,9 @@ public void testEncodeUnion() { @Test public void testIntEquals() { - //test Int + // test Int try (final IntVector vector1 = new IntVector("int", allocator); - final IntVector vector2 = new IntVector("int", allocator)) { + final IntVector vector2 = new IntVector("int", allocator)) { Dictionary dict1 = new Dictionary(vector1, new DictionaryEncoding(1L, false, null)); Dictionary dict2 = new Dictionary(vector2, new DictionaryEncoding(1L, false, null)); @@ -396,7 +402,7 @@ public void testIntEquals() { @Test public void testVarcharEquals() { try (final VarCharVector vector1 = new VarCharVector("varchar", allocator); - final VarCharVector vector2 = new VarCharVector("varchar", allocator)) { + final VarCharVector vector2 = new VarCharVector("varchar", allocator)) { Dictionary dict1 = new Dictionary(vector1, new DictionaryEncoding(1L, false, null)); Dictionary dict2 = new Dictionary(vector2, new DictionaryEncoding(1L, false, null)); @@ -414,7 +420,7 @@ public void testVarcharEquals() { @Test public void testVarBinaryEquals() { try (final VarBinaryVector vector1 = new VarBinaryVector("binary", allocator); - final VarBinaryVector vector2 = new VarBinaryVector("binary", allocator)) { + final VarBinaryVector vector2 = new VarBinaryVector("binary", allocator)) { Dictionary dict1 = new Dictionary(vector1, new DictionaryEncoding(1L, false, null)); Dictionary dict2 = new Dictionary(vector2, new DictionaryEncoding(1L, false, null)); @@ -432,7 +438,7 @@ public void testVarBinaryEquals() { @Test public void testListEquals() { try (final ListVector vector1 = ListVector.empty("list", allocator); - final ListVector vector2 = ListVector.empty("list", allocator);) { + final ListVector vector2 = ListVector.empty("list", allocator); ) { Dictionary dict1 = new Dictionary(vector1, new DictionaryEncoding(1L, false, null)); Dictionary dict2 = new Dictionary(vector2, new DictionaryEncoding(1L, false, null)); @@ -440,7 +446,7 @@ public void testListEquals() { UnionListWriter writer1 = vector1.getWriter(); writer1.allocate(); - //set some values + // set some values writeListVector(writer1, new int[] {1, 2}); writeListVector(writer1, new int[] {3, 4}); writeListVector(writer1, new int[] {5, 6}); @@ -449,7 +455,7 @@ public void testListEquals() { UnionListWriter writer2 = vector2.getWriter(); writer2.allocate(); - //set some values + // set some values writeListVector(writer2, new int[] {1, 2}); writeListVector(writer2, new int[] {3, 4}); writeListVector(writer2, new int[] {5, 6}); @@ -462,7 +468,7 @@ public void testListEquals() { @Test public void testStructEquals() { try (final StructVector vector1 = StructVector.empty("struct", allocator); - final StructVector vector2 = StructVector.empty("struct", allocator);) { + final StructVector vector2 = StructVector.empty("struct", allocator); ) { vector1.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); vector1.addOrGet("f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); vector2.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); @@ -491,9 +497,10 @@ public void testStructEquals() { @Test public void testUnionEquals() { - try (final UnionVector vector1 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); - final UnionVector vector2 = - new UnionVector("union", allocator, /* field type */ null, /* call-back */ null);) { + try (final UnionVector vector1 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); + final UnionVector vector2 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); ) { final NullableUInt4Holder uInt4Holder = new NullableUInt4Holder(); uInt4Holder.value = 10; @@ -528,7 +535,7 @@ public void testUnionEquals() { public void testEncodeWithEncoderInstance() { // Create a new value vector try (final VarCharVector vector = newVarCharVector("vector", allocator); - final VarCharVector dictionaryVector = newVarCharVector("dict", allocator);) { + final VarCharVector dictionaryVector = newVarCharVector("dict", allocator); ) { setVector(vector, zero, one, one, two, zero); setVector(dictionaryVector, zero, one, two); @@ -565,8 +572,8 @@ public void testEncodeWithEncoderInstance() { public void testEncodeMultiVectors() { // Create a new value vector try (final VarCharVector vector1 = newVarCharVector("vector1", allocator); - final VarCharVector vector2 = newVarCharVector("vector2", allocator); - final VarCharVector dictionaryVector = newVarCharVector("dict", allocator);) { + final VarCharVector vector2 = newVarCharVector("vector2", allocator); + final VarCharVector dictionaryVector = newVarCharVector("dict", allocator); ) { setVector(vector1, zero, one, one, two, zero); setVector(vector2, zero, one, one); @@ -624,26 +631,27 @@ public void testEncodeMultiVectors() { public void testEncodeListSubField() { // Create a new value vector try (final ListVector vector = ListVector.empty("vector", allocator); - final ListVector dictionaryVector = ListVector.empty("dict", allocator);) { + final ListVector dictionaryVector = ListVector.empty("dict", allocator); ) { UnionListWriter writer = vector.getWriter(); writer.allocate(); - //set some values - writeListVector(writer, new int[]{10, 20}); - writeListVector(writer, new int[]{10, 20}); - writeListVector(writer, new int[]{10, 20}); - writeListVector(writer, new int[]{30, 40, 50}); - writeListVector(writer, new int[]{30, 40, 50}); - writeListVector(writer, new int[]{10, 20}); + // set some values + writeListVector(writer, new int[] {10, 20}); + writeListVector(writer, new int[] {10, 20}); + writeListVector(writer, new int[] {10, 20}); + writeListVector(writer, new int[] {30, 40, 50}); + writeListVector(writer, new int[] {30, 40, 50}); + writeListVector(writer, new int[] {10, 20}); writer.setValueCount(6); UnionListWriter dictWriter = dictionaryVector.getWriter(); dictWriter.allocate(); - writeListVector(dictWriter, new int[]{10, 20, 30, 40, 50}); + writeListVector(dictWriter, new int[] {10, 20, 30, 40, 50}); dictionaryVector.setValueCount(1); - Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + Dictionary dictionary = + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); ListSubfieldEncoder encoder = new ListSubfieldEncoder(dictionary, allocator); try (final ListVector encoded = (ListVector) encoder.encodeListSubField(vector)) { @@ -680,13 +688,15 @@ public void testEncodeListSubField() { public void testEncodeFixedSizeListSubField() { // Create a new value vector try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", 2, allocator); - final FixedSizeListVector dictionaryVector = FixedSizeListVector.empty("dict", 2, allocator)) { + final FixedSizeListVector dictionaryVector = + FixedSizeListVector.empty("dict", 2, allocator)) { vector.allocateNew(); vector.setValueCount(4); IntVector dataVector = - (IntVector) vector.addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())).getVector(); + (IntVector) + vector.addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())).getVector(); dataVector.allocateNew(8); dataVector.setValueCount(8); // set value at index 0 @@ -709,7 +719,10 @@ public void testEncodeFixedSizeListSubField() { dictionaryVector.allocateNew(); dictionaryVector.setValueCount(2); IntVector dictDataVector = - (IntVector) dictionaryVector.addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())).getVector(); + (IntVector) + dictionaryVector + .addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())) + .getVector(); dictDataVector.allocateNew(4); dictDataVector.setValueCount(4); @@ -720,7 +733,8 @@ public void testEncodeFixedSizeListSubField() { dictDataVector.set(2, 30); dictDataVector.set(3, 40); - Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + Dictionary dictionary = + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); ListSubfieldEncoder encoder = new ListSubfieldEncoder(dictionary, allocator); try (final FixedSizeListVector encoded = @@ -753,15 +767,15 @@ public void testEncodeFixedSizeListSubField() { @Test public void testEncodeStructSubField() { try (final StructVector vector = StructVector.empty("vector", allocator); - final VarCharVector dictVector1 = new VarCharVector("f0", allocator); - final VarCharVector dictVector2 = new VarCharVector("f1", allocator)) { + final VarCharVector dictVector1 = new VarCharVector("f0", allocator); + final VarCharVector dictVector2 = new VarCharVector("f1", allocator)) { vector.addOrGet("f0", FieldType.nullable(ArrowType.Utf8.INSTANCE), VarCharVector.class); vector.addOrGet("f1", FieldType.nullable(ArrowType.Utf8.INSTANCE), VarCharVector.class); NullableStructWriter writer = vector.getWriter(); writer.allocate(); - //set some values + // set some values writeStructVector(writer, "aa", "baz"); writeStructVector(writer, "bb", "bar"); writeStructVector(writer, "cc", "foo"); @@ -770,15 +784,17 @@ public void testEncodeStructSubField() { writer.setValueCount(5); // initialize dictionaries - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); - - setVector(dictVector1, + setVector( + dictVector1, "aa".getBytes(StandardCharsets.UTF_8), "bb".getBytes(StandardCharsets.UTF_8), "cc".getBytes(StandardCharsets.UTF_8), "dd".getBytes(StandardCharsets.UTF_8)); - setVector(dictVector2, + setVector( + dictVector2, "foo".getBytes(StandardCharsets.UTF_8), "baz".getBytes(StandardCharsets.UTF_8), "bar".getBytes(StandardCharsets.UTF_8)); @@ -791,7 +807,8 @@ public void testEncodeStructSubField() { columnToDictionaryId.put(0, 1L); columnToDictionaryId.put(1, 2L); - try (final StructVector encoded = (StructVector) encoder.encode(vector, columnToDictionaryId)) { + try (final StructVector encoded = + (StructVector) encoder.encode(vector, columnToDictionaryId)) { // verify indices assertEquals(StructVector.class, encoded.getClass()); @@ -823,14 +840,14 @@ public void testEncodeStructSubField() { public void testEncodeStructSubFieldWithCertainColumns() { // in this case, some child vector is encoded and others are not try (final StructVector vector = StructVector.empty("vector", allocator); - final VarCharVector dictVector1 = new VarCharVector("f0", allocator)) { + final VarCharVector dictVector1 = new VarCharVector("f0", allocator)) { vector.addOrGet("f0", FieldType.nullable(ArrowType.Utf8.INSTANCE), VarCharVector.class); vector.addOrGet("f1", FieldType.nullable(ArrowType.Utf8.INSTANCE), VarCharVector.class); NullableStructWriter writer = vector.getWriter(); writer.allocate(); - //set some values + // set some values writeStructVector(writer, "aa", "baz"); writeStructVector(writer, "bb", "bar"); writeStructVector(writer, "cc", "foo"); @@ -839,7 +856,8 @@ public void testEncodeStructSubFieldWithCertainColumns() { writer.setValueCount(5); // initialize dictionaries - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); setVector(dictVector1, "aa".getBytes(), "bb".getBytes(), "cc".getBytes(), "dd".getBytes()); @@ -848,7 +866,8 @@ public void testEncodeStructSubFieldWithCertainColumns() { Map columnToDictionaryId = new HashMap<>(); columnToDictionaryId.put(0, 1L); - try (final StructVector encoded = (StructVector) encoder.encode(vector, columnToDictionaryId)) { + try (final StructVector encoded = + (StructVector) encoder.encode(vector, columnToDictionaryId)) { // verify indices assertEquals(StructVector.class, encoded.getClass()); @@ -873,7 +892,6 @@ public void testEncodeStructSubFieldWithCertainColumns() { } } } - } } @@ -881,13 +899,13 @@ public void testEncodeStructSubFieldWithCertainColumns() { public void testNoMemoryLeak() { // test no memory leak when encode try (final VarCharVector vector = newVarCharVector("foo", allocator); - final VarCharVector dictionaryVector = newVarCharVector("dict", allocator)) { + final VarCharVector dictionaryVector = newVarCharVector("dict", allocator)) { setVector(vector, zero, one, two); setVector(dictionaryVector, zero, one); Dictionary dictionary = - new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); try (final ValueVector encoded = DictionaryEncoder.encode(vector, dictionary)) { fail("There should be an exception when encoding"); @@ -899,13 +917,13 @@ public void testNoMemoryLeak() { // test no memory leak when decode try (final IntVector indices = newVector(IntVector.class, "", Types.MinorType.INT, allocator); - final VarCharVector dictionaryVector = newVarCharVector("dict", allocator)) { + final VarCharVector dictionaryVector = newVarCharVector("dict", allocator)) { setVector(indices, 3); setVector(dictionaryVector, zero, one); Dictionary dictionary = - new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); try (final ValueVector decoded = DictionaryEncoder.decode(indices, dictionary, allocator)) { fail("There should be an exception when decoding"); @@ -920,19 +938,20 @@ public void testNoMemoryLeak() { public void testListNoMemoryLeak() { // Create a new value vector try (final ListVector vector = ListVector.empty("vector", allocator); - final ListVector dictionaryVector = ListVector.empty("dict", allocator)) { + final ListVector dictionaryVector = ListVector.empty("dict", allocator)) { UnionListWriter writer = vector.getWriter(); writer.allocate(); - writeListVector(writer, new int[]{10, 20}); + writeListVector(writer, new int[] {10, 20}); writer.setValueCount(1); UnionListWriter dictWriter = dictionaryVector.getWriter(); dictWriter.allocate(); - writeListVector(dictWriter, new int[]{10}); + writeListVector(dictWriter, new int[] {10}); dictionaryVector.setValueCount(1); - Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + Dictionary dictionary = + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); ListSubfieldEncoder encoder = new ListSubfieldEncoder(dictionary, allocator); try (final ListVector encoded = (ListVector) encoder.encodeListSubField(vector)) { @@ -944,22 +963,23 @@ public void testListNoMemoryLeak() { assertEquals("list encode memory leak", 0, allocator.getAllocatedMemory()); try (final ListVector indices = ListVector.empty("indices", allocator); - final ListVector dictionaryVector = ListVector.empty("dict", allocator)) { + final ListVector dictionaryVector = ListVector.empty("dict", allocator)) { UnionListWriter writer = indices.getWriter(); writer.allocate(); - writeListVector(writer, new int[]{3}); + writeListVector(writer, new int[] {3}); writer.setValueCount(1); UnionListWriter dictWriter = dictionaryVector.getWriter(); dictWriter.allocate(); - writeListVector(dictWriter, new int[]{10, 20}); + writeListVector(dictWriter, new int[] {10, 20}); dictionaryVector.setValueCount(1); Dictionary dictionary = - new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); + new Dictionary(dictionaryVector, new DictionaryEncoding(1L, false, null)); - try (final ValueVector decoded = ListSubfieldEncoder.decodeListSubField(indices, dictionary, allocator)) { + try (final ValueVector decoded = + ListSubfieldEncoder.decodeListSubField(indices, dictionary, allocator)) { fail("There should be an exception when decoding"); } catch (Exception e) { assertEquals("Provided dictionary does not contain value for index 3", e.getMessage()); @@ -971,8 +991,8 @@ public void testListNoMemoryLeak() { @Test public void testStructNoMemoryLeak() { try (final StructVector vector = StructVector.empty("vector", allocator); - final VarCharVector dictVector1 = new VarCharVector("f0", allocator); - final VarCharVector dictVector2 = new VarCharVector("f1", allocator)) { + final VarCharVector dictVector1 = new VarCharVector("f0", allocator); + final VarCharVector dictVector2 = new VarCharVector("f1", allocator)) { vector.addOrGet("f0", FieldType.nullable(ArrowType.Utf8.INSTANCE), VarCharVector.class); vector.addOrGet("f1", FieldType.nullable(ArrowType.Utf8.INSTANCE), VarCharVector.class); @@ -982,11 +1002,10 @@ public void testStructNoMemoryLeak() { writeStructVector(writer, "aa", "baz"); writer.setValueCount(1); - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); - setVector(dictVector1, - "aa".getBytes(StandardCharsets.UTF_8)); - setVector(dictVector2, - "foo".getBytes(StandardCharsets.UTF_8)); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); + setVector(dictVector1, "aa".getBytes(StandardCharsets.UTF_8)); + setVector(dictVector2, "foo".getBytes(StandardCharsets.UTF_8)); provider.put(new Dictionary(dictVector1, new DictionaryEncoding(1L, false, null))); provider.put(new Dictionary(dictVector2, new DictionaryEncoding(2L, false, null))); @@ -996,7 +1015,8 @@ public void testStructNoMemoryLeak() { columnToDictionaryId.put(0, 1L); columnToDictionaryId.put(1, 2L); - try (final StructVector encoded = (StructVector) encoder.encode(vector, columnToDictionaryId)) { + try (final StructVector encoded = + (StructVector) encoder.encode(vector, columnToDictionaryId)) { fail("There should be an exception when encoding"); } catch (Exception e) { assertEquals("Dictionary encoding not defined for value:baz", e.getMessage()); @@ -1005,25 +1025,22 @@ public void testStructNoMemoryLeak() { assertEquals("struct encode memory leak", 0, allocator.getAllocatedMemory()); try (final StructVector indices = StructVector.empty("indices", allocator); - final VarCharVector dictVector1 = new VarCharVector("f0", allocator); - final VarCharVector dictVector2 = new VarCharVector("f1", allocator)) { + final VarCharVector dictVector1 = new VarCharVector("f0", allocator); + final VarCharVector dictVector2 = new VarCharVector("f1", allocator)) { - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); - setVector(dictVector1, - "aa".getBytes(StandardCharsets.UTF_8)); - setVector(dictVector2, - "foo".getBytes(StandardCharsets.UTF_8)); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); + setVector(dictVector1, "aa".getBytes(StandardCharsets.UTF_8)); + setVector(dictVector2, "foo".getBytes(StandardCharsets.UTF_8)); provider.put(new Dictionary(dictVector1, new DictionaryEncoding(1L, false, null))); provider.put(new Dictionary(dictVector2, new DictionaryEncoding(2L, false, null))); ArrowType int32 = new ArrowType.Int(32, true); - indices.addOrGet("f0", - new FieldType(true, int32, provider.lookup(1L).getEncoding()), - IntVector.class); - indices.addOrGet("f1", - new FieldType(true, int32, provider.lookup(2L).getEncoding()), - IntVector.class); + indices.addOrGet( + "f0", new FieldType(true, int32, provider.lookup(1L).getEncoding()), IntVector.class); + indices.addOrGet( + "f1", new FieldType(true, int32, provider.lookup(2L).getEncoding()), IntVector.class); NullableStructWriter writer = indices.getWriter(); writer.allocate(); @@ -1042,7 +1059,8 @@ public void testStructNoMemoryLeak() { assertEquals("struct decode memory leak", 0, allocator.getAllocatedMemory()); } - private void testDictionary(Dictionary dictionary, ToIntBiFunction valGetter) { + private void testDictionary( + Dictionary dictionary, ToIntBiFunction valGetter) { try (VarCharVector vector = new VarCharVector("vector", allocator)) { setVector(vector, "1", "3", "5", "7", "9"); try (ValueVector encodedVector = DictionaryEncoder.encode(vector, dictionary)) { @@ -1072,9 +1090,13 @@ private void testDictionary(Dictionary dictionary, ToIntBiFunction ((UInt1Vector) vector).get(index)); } } @@ -1083,9 +1105,13 @@ public void testDictionaryUInt1() { public void testDictionaryUInt2() { try (VarCharVector dictionaryVector = new VarCharVector("dict vector", allocator)) { setVector(dictionaryVector, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); - Dictionary dictionary2 = new Dictionary(dictionaryVector, - new DictionaryEncoding(/*id=*/20L, /*ordered=*/false, - /*indexType=*/new ArrowType.Int(/*indexType=*/16, /*isSigned*/false))); + Dictionary dictionary2 = + new Dictionary( + dictionaryVector, + new DictionaryEncoding( + /* id= */ 20L, + /* ordered= */ false, + /* indexType= */ new ArrowType.Int(/* indexType= */ 16, /*isSigned*/ false))); testDictionary(dictionary2, (vector, index) -> ((UInt2Vector) vector).get(index)); } } @@ -1094,9 +1120,13 @@ public void testDictionaryUInt2() { public void testDictionaryUInt4() { try (VarCharVector dictionaryVector = new VarCharVector("dict vector", allocator)) { setVector(dictionaryVector, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); - Dictionary dictionary4 = new Dictionary(dictionaryVector, - new DictionaryEncoding(/*id=*/30L, /*ordered=*/false, - /*indexType=*/new ArrowType.Int(/*indexType=*/32, /*isSigned*/false))); + Dictionary dictionary4 = + new Dictionary( + dictionaryVector, + new DictionaryEncoding( + /* id= */ 30L, + /* ordered= */ false, + /* indexType= */ new ArrowType.Int(/* indexType= */ 32, /*isSigned*/ false))); testDictionary(dictionary4, (vector, index) -> ((UInt4Vector) vector).get(index)); } } @@ -1105,9 +1135,13 @@ public void testDictionaryUInt4() { public void testDictionaryUInt8() { try (VarCharVector dictionaryVector = new VarCharVector("dict vector", allocator)) { setVector(dictionaryVector, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); - Dictionary dictionary8 = new Dictionary(dictionaryVector, - new DictionaryEncoding(/*id=*/40L, /*ordered=*/false, - /*indexType=*/new ArrowType.Int(/*indexType=*/64, /*isSigned*/false))); + Dictionary dictionary8 = + new Dictionary( + dictionaryVector, + new DictionaryEncoding( + /* id= */ 40L, + /* ordered= */ false, + /* indexType= */ new ArrowType.Int(/* indexType= */ 64, /*isSigned*/ false))); testDictionary(dictionary8, (vector, index) -> (int) ((UInt8Vector) vector).get(index)); } } @@ -1123,19 +1157,25 @@ public void testDictionaryUIntOverflow() { } dictionaryVector.setValueCount(vecLength); - Dictionary dictionary = new Dictionary(dictionaryVector, - new DictionaryEncoding(/*id=*/10L, /*ordered=*/false, - /*indexType=*/new ArrowType.Int(/*indexType=*/8, /*isSigned*/false))); + Dictionary dictionary = + new Dictionary( + dictionaryVector, + new DictionaryEncoding( + /* id= */ 10L, + /* ordered= */ false, + /* indexType= */ new ArrowType.Int(/* indexType= */ 8, /*isSigned*/ false))); try (VarCharVector vector = new VarCharVector("vector", allocator)) { setVector(vector, "255"); - try (UInt1Vector encodedVector = (UInt1Vector) DictionaryEncoder.encode(vector, dictionary)) { + try (UInt1Vector encodedVector = + (UInt1Vector) DictionaryEncoder.encode(vector, dictionary)) { // verify encoded result assertEquals(1, encodedVector.getValueCount()); assertEquals(255, encodedVector.getValueAsLong(0)); - try (VarCharVector decodedVector = (VarCharVector) DictionaryEncoder.decode(encodedVector, dictionary)) { + try (VarCharVector decodedVector = + (VarCharVector) DictionaryEncoder.decode(encodedVector, dictionary)) { assertEquals(1, decodedVector.getValueCount()); assertArrayEquals("255".getBytes(), decodedVector.get(0)); } @@ -1185,7 +1225,7 @@ private void writeStructVector(NullableStructWriter writer, int value1, long val private void writeListVector(UnionListWriter writer, int[] values) { writer.startList(); - for (int v: values) { + for (int v : values) { writer.integer().writeInt(v); } writer.endList(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDurationVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDurationVector.java index c5d4d296cc0..131073ece41 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDurationVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDurationVector.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertSame; import java.time.Duration; - import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.holders.NullableDurationHolder; import org.apache.arrow.vector.types.TimeUnit; @@ -47,8 +46,9 @@ public void terminate() { @Test public void testSecBasics() { - try (DurationVector secVector = TestUtils.newVector(DurationVector.class, "second", - new ArrowType.Duration(TimeUnit.SECOND), allocator)) { + try (DurationVector secVector = + TestUtils.newVector( + DurationVector.class, "second", new ArrowType.Duration(TimeUnit.SECOND), allocator)) { secVector.allocateNew(); secVector.setNull(0); @@ -63,15 +63,19 @@ public void testSecBasics() { secVector.get(0, holder); assertEquals(0, holder.isSet); secVector.get(1, holder); - assertEquals(1 , holder.isSet); - assertEquals(1000 , holder.value); + assertEquals(1, holder.isSet); + assertEquals(1000, holder.value); } } @Test public void testMilliBasics() { - try (DurationVector milliVector = TestUtils.newVector(DurationVector.class, "nanos", - new ArrowType.Duration(TimeUnit.MILLISECOND), allocator)) { + try (DurationVector milliVector = + TestUtils.newVector( + DurationVector.class, + "nanos", + new ArrowType.Duration(TimeUnit.MILLISECOND), + allocator)) { milliVector.allocateNew(); milliVector.setNull(0); @@ -86,15 +90,19 @@ public void testMilliBasics() { milliVector.get(0, holder); assertEquals(0, holder.isSet); milliVector.get(1, holder); - assertEquals(1 , holder.isSet); - assertEquals(1000 , holder.value); + assertEquals(1, holder.isSet); + assertEquals(1000, holder.value); } } @Test public void testMicroBasics() { - try (DurationVector microVector = TestUtils.newVector(DurationVector.class, "micro", - new ArrowType.Duration(TimeUnit.MICROSECOND), allocator)) { + try (DurationVector microVector = + TestUtils.newVector( + DurationVector.class, + "micro", + new ArrowType.Duration(TimeUnit.MICROSECOND), + allocator)) { microVector.allocateNew(); microVector.setNull(0); @@ -109,15 +117,19 @@ public void testMicroBasics() { microVector.get(0, holder); assertEquals(0, holder.isSet); microVector.get(1, holder); - assertEquals(1 , holder.isSet); - assertEquals(1000 , holder.value); + assertEquals(1, holder.isSet); + assertEquals(1000, holder.value); } } @Test public void testNanosBasics() { - try (DurationVector nanoVector = TestUtils.newVector(DurationVector.class, "nanos", - new ArrowType.Duration(TimeUnit.NANOSECOND), allocator)) { + try (DurationVector nanoVector = + TestUtils.newVector( + DurationVector.class, + "nanos", + new ArrowType.Duration(TimeUnit.NANOSECOND), + allocator)) { nanoVector.allocateNew(); nanoVector.setNull(0); @@ -132,18 +144,20 @@ public void testNanosBasics() { nanoVector.get(0, holder); assertEquals(0, holder.isSet); nanoVector.get(1, holder); - assertEquals(1 , holder.isSet); - assertEquals(1000000 , holder.value); + assertEquals(1, holder.isSet); + assertEquals(1000000, holder.value); } } @Test public void testGetTransferPairWithField() { - final DurationVector fromVector = TestUtils.newVector(DurationVector.class, "nanos", - new ArrowType.Duration(TimeUnit.NANOSECOND), allocator); + final DurationVector fromVector = + TestUtils.newVector( + DurationVector.class, "nanos", new ArrowType.Duration(TimeUnit.NANOSECOND), allocator); final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); final DurationVector toVector = (DurationVector) transferPair.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(fromVector.getField(), toVector.getField()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java index b9cd89e4ad7..7330e46f7b5 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java @@ -49,7 +49,8 @@ public class TestFixedSizeBinaryVector { private ArrowBuf[] bufs = new ArrowBuf[numValues]; private FixedSizeBinaryHolder[] holders = new FixedSizeBinaryHolder[numValues]; - private NullableFixedSizeBinaryHolder[] nullableHolders = new NullableFixedSizeBinaryHolder[numValues]; + private NullableFixedSizeBinaryHolder[] nullableHolders = + new NullableFixedSizeBinaryHolder[numValues]; private static byte[] smallValue; @@ -84,7 +85,6 @@ private static void failWithException(String message) throws Exception { throw new Exception(message); } - @Before public void init() throws Exception { allocator = new DirtyRootAllocator(Integer.MAX_VALUE, (byte) 100); @@ -156,9 +156,12 @@ public void testSetUsingNull() { final byte[] value = null; for (int i = 0; i < numValues; i++) { final int index = i; - Exception e = assertThrows(NullPointerException.class, () -> { - vector.set(index, value); - }); + Exception e = + assertThrows( + NullPointerException.class, + () -> { + vector.set(index, value); + }); assertEquals("expecting a valid byte array", e.getMessage()); } } @@ -281,10 +284,12 @@ public void testGetNull() { @Test public void testGetTransferPairWithField() { - final FixedSizeBinaryVector fromVector = new FixedSizeBinaryVector("fixedSizeBinary", allocator, typeWidth); + final FixedSizeBinaryVector fromVector = + new FixedSizeBinaryVector("fixedSizeBinary", allocator, typeWidth); final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); final FixedSizeBinaryVector toVector = (FixedSizeBinaryVector) transferPair.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(fromVector.getField(), toVector.getField()); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java index 0023b1dddb8..3572551206d 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java @@ -27,7 +27,6 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.FixedSizeListVector; import org.apache.arrow.vector.complex.ListVector; @@ -62,7 +61,9 @@ public void terminate() throws Exception { @Test public void testIntType() { try (FixedSizeListVector vector = FixedSizeListVector.empty("list", 2, allocator)) { - IntVector nested = (IntVector) vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())).getVector(); + IntVector nested = + (IntVector) + vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())).getVector(); vector.allocateNew(); for (int i = 0; i < 10; i++) { @@ -89,8 +90,9 @@ public void testIntType() { @Test public void testFloatTypeNullable() { try (FixedSizeListVector vector = FixedSizeListVector.empty("list", 2, allocator)) { - Float4Vector nested = (Float4Vector) vector.addOrGetVector(FieldType.nullable(MinorType.FLOAT4.getType())) - .getVector(); + Float4Vector nested = + (Float4Vector) + vector.addOrGetVector(FieldType.nullable(MinorType.FLOAT4.getType())).getVector(); vector.allocateNew(); for (int i = 0; i < 10; i++) { @@ -124,10 +126,12 @@ public void testFloatTypeNullable() { @Test public void testNestedInList() { try (ListVector vector = ListVector.empty("list", allocator)) { - FixedSizeListVector tuples = (FixedSizeListVector) vector.addOrGetVector( - FieldType.nullable(new ArrowType.FixedSizeList(2))).getVector(); - IntVector innerVector = (IntVector) tuples.addOrGetVector(FieldType.nullable(MinorType.INT.getType())) - .getVector(); + FixedSizeListVector tuples = + (FixedSizeListVector) + vector.addOrGetVector(FieldType.nullable(new ArrowType.FixedSizeList(2))).getVector(); + IntVector innerVector = + (IntVector) + tuples.addOrGetVector(FieldType.nullable(MinorType.INT.getType())).getVector(); vector.allocateNew(); for (int i = 0; i < 10; i++) { @@ -167,12 +171,18 @@ public void testNestedInList() { @Test public void testTransferPair() { - try (FixedSizeListVector from = new FixedSizeListVector( - "from", allocator, new FieldType(true, new ArrowType.FixedSizeList(2), null), null); - FixedSizeListVector to = new FixedSizeListVector( - "to", allocator, new FieldType(true, new ArrowType.FixedSizeList(2), null), null)) { - Float4Vector nested = (Float4Vector) from.addOrGetVector(FieldType.nullable(MinorType.FLOAT4.getType())) - .getVector(); + try (FixedSizeListVector from = + new FixedSizeListVector( + "from", + allocator, + new FieldType(true, new ArrowType.FixedSizeList(2), null), + null); + FixedSizeListVector to = + new FixedSizeListVector( + "to", allocator, new FieldType(true, new ArrowType.FixedSizeList(2), null), null)) { + Float4Vector nested = + (Float4Vector) + from.addOrGetVector(FieldType.nullable(MinorType.FLOAT4.getType())).getVector(); from.allocateNew(); for (int i = 0; i < 10; i++) { @@ -251,7 +261,8 @@ public void testUnionFixedSizeListWriterWithNulls() throws Exception { * each list of size 3 and having its data values alternating between null and a non-null. * Read and verify */ - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/3, allocator)) { + try (final FixedSizeListVector vector = + FixedSizeListVector.empty("vector", /* listSize= */ 3, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -288,7 +299,7 @@ public void testUnionFixedSizeListWriter() throws Exception { int[] values2 = new int[] {4, 5, 6}; int[] values3 = new int[] {7, 8, 9}; - //set some values + // set some values writeListVector(vector1, writer1, values1); writeListVector(vector1, writer1, values2); writeListVector(vector1, writer1, values3); @@ -307,7 +318,8 @@ public void testUnionFixedSizeListWriter() throws Exception { @Test public void testWriteDecimal() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/3, allocator)) { + try (final FixedSizeListVector vector = + FixedSizeListVector.empty("vector", /* listSize= */ 3, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -335,24 +347,27 @@ public void testWriteDecimal() throws Exception { @Test public void testDecimalIndexCheck() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/3, allocator)) { + try (final FixedSizeListVector vector = + FixedSizeListVector.empty("vector", /* listSize= */ 3, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); - IllegalStateException e = assertThrows(IllegalStateException.class, () -> { - writer.startList(); - writer.decimal().writeDecimal(new BigDecimal(1)); - writer.decimal().writeDecimal(new BigDecimal(2)); - writer.decimal().writeDecimal(new BigDecimal(3)); - writer.decimal().writeDecimal(new BigDecimal(4)); - writer.endList(); - }); + IllegalStateException e = + assertThrows( + IllegalStateException.class, + () -> { + writer.startList(); + writer.decimal().writeDecimal(new BigDecimal(1)); + writer.decimal().writeDecimal(new BigDecimal(2)); + writer.decimal().writeDecimal(new BigDecimal(3)); + writer.decimal().writeDecimal(new BigDecimal(4)); + writer.endList(); + }); assertEquals("values at index 0 is greater than listSize 3", e.getMessage()); } } - @Test(expected = IllegalStateException.class) public void testWriteIllegalData() throws Exception { try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("vector", 3, allocator)) { @@ -363,7 +378,7 @@ public void testWriteIllegalData() throws Exception { int[] values1 = new int[] {1, 2, 3}; int[] values2 = new int[] {4, 5, 6, 7, 8}; - //set some values + // set some values writeListVector(vector1, writer1, values1); writeListVector(vector1, writer1, values2); writer1.setValueCount(3); @@ -387,7 +402,7 @@ public void testSplitAndTransfer() throws Exception { int[] values2 = new int[] {4, 5, 6}; int[] values3 = new int[] {7, 8, 9}; - //set some values + // set some values writeListVector(vector1, writer1, values1); writeListVector(vector1, writer1, values2); writeListVector(vector1, writer1, values3); @@ -419,7 +434,7 @@ public void testZeroWidthVector() { int[] values3 = null; int[] values4 = new int[] {}; - //set some values + // set some values writeListVector(vector1, writer1, values1); writeListVector(vector1, writer1, values2); writeListVector(vector1, writer1, values3); @@ -450,7 +465,7 @@ public void testVectorWithNulls() { List values3 = null; List values4 = Arrays.asList(7, 8, null, 9); - //set some values + // set some values writeListVector(vector1, writer1, values1); writeListVector(vector1, writer1, values2); writeListVector(vector1, writer1, values3); @@ -472,7 +487,8 @@ public void testVectorWithNulls() { @Test public void testWriteVarCharHelpers() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/4, allocator)) { + try (final FixedSizeListVector vector = + FixedSizeListVector.empty("vector", /* listSize= */ 4, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -491,7 +507,8 @@ public void testWriteVarCharHelpers() throws Exception { @Test public void testWriteLargeVarCharHelpers() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/4, allocator)) { + try (final FixedSizeListVector vector = + FixedSizeListVector.empty("vector", /* listSize= */ 4, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -510,7 +527,8 @@ public void testWriteLargeVarCharHelpers() throws Exception { @Test public void testWriteVarBinaryHelpers() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/4, allocator)) { + try (final FixedSizeListVector vector = + FixedSizeListVector.empty("vector", /* listSize= */ 4, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -531,7 +549,8 @@ public void testWriteVarBinaryHelpers() throws Exception { @Test public void testWriteLargeVarBinaryHelpers() throws Exception { - try (final FixedSizeListVector vector = FixedSizeListVector.empty("vector", /*listSize=*/4, allocator)) { + try (final FixedSizeListVector vector = + FixedSizeListVector.empty("vector", /* listSize= */ 4, allocator)) { UnionFixedSizeListWriter writer = vector.getWriter(); writer.allocate(); @@ -540,7 +559,8 @@ public void testWriteLargeVarBinaryHelpers() throws Exception { writer.writeLargeVarBinary("row1,1".getBytes()); writer.writeLargeVarBinary("row1,2".getBytes(), 0, "row1,2".getBytes().length); writer.writeLargeVarBinary(ByteBuffer.wrap("row1,3".getBytes())); - writer.writeLargeVarBinary(ByteBuffer.wrap("row1,4".getBytes()), 0, "row1,4".getBytes().length); + writer.writeLargeVarBinary( + ByteBuffer.wrap("row1,4".getBytes()), 0, "row1,4".getBytes().length); writer.endList(); assertEquals("row1,1", new String((byte[]) (vector.getObject(0).get(0)))); @@ -558,7 +578,8 @@ private int[] convertListToIntArray(List list) { return values; } - private void writeListVector(FixedSizeListVector vector, UnionFixedSizeListWriter writer, int[] values) { + private void writeListVector( + FixedSizeListVector vector, UnionFixedSizeListWriter writer, int[] values) { writer.startList(); if (values != null) { for (int v : values) { @@ -570,7 +591,8 @@ private void writeListVector(FixedSizeListVector vector, UnionFixedSizeListWrite writer.endList(); } - private void writeListVector(FixedSizeListVector vector, UnionFixedSizeListWriter writer, List values) { + private void writeListVector( + FixedSizeListVector vector, UnionFixedSizeListWriter writer, List values) { writer.startList(); if (values != null) { for (Integer v : values) { @@ -585,5 +607,4 @@ private void writeListVector(FixedSizeListVector vector, UnionFixedSizeListWrite } writer.endList(); } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalMonthDayNanoVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalMonthDayNanoVector.java index 681897b93c1..d43590e5c41 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalMonthDayNanoVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalMonthDayNanoVector.java @@ -19,10 +19,8 @@ import static org.junit.Assert.assertEquals; - import java.time.Duration; import java.time.Period; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.holders.IntervalMonthDayNanoHolder; import org.apache.arrow.vector.holders.NullableIntervalMonthDayNanoHolder; @@ -49,7 +47,8 @@ public void terminate() throws Exception { @Test public void testBasics() { - try (final IntervalMonthDayNanoVector vector = new IntervalMonthDayNanoVector(/*name=*/"", allocator)) { + try (final IntervalMonthDayNanoVector vector = + new IntervalMonthDayNanoVector(/* name= */ "", allocator)) { int valueCount = 100; vector.setInitialCapacity(valueCount); vector.allocateNew(); @@ -63,20 +62,21 @@ public void testBasics() { holder.days = Integer.MIN_VALUE; holder.nanoseconds = Long.MIN_VALUE; - - vector.set(0, /*months=*/1, /*days=*/2, /*nanoseconds=*/-2); - vector.setSafe(2, /*months=*/1, /*days=*/2, /*nanoseconds=*/-3); - vector.setSafe(/*index=*/4, nullableHolder); + vector.set(0, /* months= */ 1, /* days= */ 2, /* nanoseconds= */ -2); + vector.setSafe(2, /* months= */ 1, /* days= */ 2, /* nanoseconds= */ -3); + vector.setSafe(/* index= */ 4, nullableHolder); vector.set(3, holder); nullableHolder.isSet = 0; - vector.setSafe(/*index=*/5, nullableHolder); + vector.setSafe(/* index= */ 5, nullableHolder); vector.setValueCount(5); assertEquals("P1M2D PT-0.000000002S ", vector.getAsStringBuilder(0).toString()); assertEquals(null, vector.getAsStringBuilder(1)); assertEquals("P1M2D PT-0.000000003S ", vector.getAsStringBuilder(2).toString()); - assertEquals(new PeriodDuration(Period.of(0, Integer.MIN_VALUE, Integer.MIN_VALUE), - Duration.ofNanos(Long.MIN_VALUE)), vector.getObject(3)); + assertEquals( + new PeriodDuration( + Period.of(0, Integer.MIN_VALUE, Integer.MIN_VALUE), Duration.ofNanos(Long.MIN_VALUE)), + vector.getObject(3)); assertEquals("P2M20D PT0.000000123S ", vector.getAsStringBuilder(4).toString()); assertEquals(null, vector.getObject(5)); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java index 4b2ae2eb3d4..0d7d8ca6a9e 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java @@ -71,7 +71,8 @@ public void testGetTransferPairWithField() { final IntervalYearVector fromVector = new IntervalYearVector("", allocator); final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); final IntervalYearVector toVector = (IntervalYearVector) transferPair.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(fromVector.getField(), toVector.getField()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java index 993ce0b0897..a506608920d 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeListVector.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.BaseRepeatedValueVector; @@ -61,7 +60,7 @@ public void terminate() throws Exception { @Test public void testCopyFrom() throws Exception { try (LargeListVector inVector = LargeListVector.empty("input", allocator); - LargeListVector outVector = LargeListVector.empty("output", allocator)) { + LargeListVector outVector = LargeListVector.empty("output", allocator)) { UnionLargeListWriter writer = inVector.getWriter(); writer.allocate(); @@ -97,7 +96,6 @@ public void testCopyFrom() throws Exception { reader.setPosition(2); Assert.assertTrue("shouldn't be null", reader.isSet()); - /* index 0 */ Object result = outVector.getObject(0); ArrayList resultSet = (ArrayList) result; @@ -429,20 +427,26 @@ public void testSplitAndTransfer() throws Exception { BigIntVector dataVector1 = (BigIntVector) toVector.getDataVector(); for (int i = 0; i < splitLength; i++) { - dataLength1 = (int) offsetBuffer.getLong((start + i + 1) * LargeListVector.OFFSET_WIDTH) - - (int) offsetBuffer.getLong((start + i) * LargeListVector.OFFSET_WIDTH); - dataLength2 = (int) toOffsetBuffer.getLong((i + 1) * LargeListVector.OFFSET_WIDTH) - - (int) toOffsetBuffer.getLong(i * LargeListVector.OFFSET_WIDTH); - - assertEquals("Different data lengths at index: " + i + " and start: " + start, - dataLength1, dataLength2); + dataLength1 = + (int) offsetBuffer.getLong((start + i + 1) * LargeListVector.OFFSET_WIDTH) + - (int) offsetBuffer.getLong((start + i) * LargeListVector.OFFSET_WIDTH); + dataLength2 = + (int) toOffsetBuffer.getLong((i + 1) * LargeListVector.OFFSET_WIDTH) + - (int) toOffsetBuffer.getLong(i * LargeListVector.OFFSET_WIDTH); + + assertEquals( + "Different data lengths at index: " + i + " and start: " + start, + dataLength1, + dataLength2); offset1 = (int) offsetBuffer.getLong((start + i) * LargeListVector.OFFSET_WIDTH); offset2 = (int) toOffsetBuffer.getLong(i * LargeListVector.OFFSET_WIDTH); for (int j = 0; j < dataLength1; j++) { - assertEquals("Different data at indexes: " + offset1 + " and " + offset2, - dataVector.getObject(offset1), dataVector1.getObject(offset2)); + assertEquals( + "Different data at indexes: " + offset1 + " and " + offset2, + dataVector.getObject(offset1), + dataVector1.getObject(offset2)); offset1++; offset2++; @@ -773,8 +777,8 @@ public void testSetInitialCapacity() { vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())); /** - * use the default multiplier of 5, - * 512 * 5 => 2560 * 4 => 10240 bytes => 16KB => 4096 value capacity. + * use the default multiplier of 5, 512 * 5 => 2560 * 4 => 10240 bytes => 16KB => 4096 value + * capacity. */ vector.setInitialCapacity(512); vector.allocateNew(); @@ -788,12 +792,10 @@ public void testSetInitialCapacity() { assertTrue(vector.getDataVector().getValueCapacity() >= 512 * 4); /** - * inner value capacity we pass to data vector is 512 * 0.1 => 51 - * For an int vector this is 204 bytes of memory for data buffer - * and 7 bytes for validity buffer. - * and with power of 2 allocation, we allocate 256 bytes and 8 bytes - * for the data buffer and validity buffer of the inner vector. Thus - * value capacity of inner vector is 64 + * inner value capacity we pass to data vector is 512 * 0.1 => 51 For an int vector this is + * 204 bytes of memory for data buffer and 7 bytes for validity buffer. and with power of 2 + * allocation, we allocate 256 bytes and 8 bytes for the data buffer and validity buffer of + * the inner vector. Thus value capacity of inner vector is 64 */ vector.setInitialCapacity(512, 0.1); vector.allocateNew(); @@ -801,12 +803,10 @@ public void testSetInitialCapacity() { assertTrue(vector.getDataVector().getValueCapacity() >= 51); /** - * inner value capacity we pass to data vector is 512 * 0.01 => 5 - * For an int vector this is 20 bytes of memory for data buffer - * and 1 byte for validity buffer. - * and with power of 2 allocation, we allocate 32 bytes and 1 bytes - * for the data buffer and validity buffer of the inner vector. Thus - * value capacity of inner vector is 8 + * inner value capacity we pass to data vector is 512 * 0.01 => 5 For an int vector this is 20 + * bytes of memory for data buffer and 1 byte for validity buffer. and with power of 2 + * allocation, we allocate 32 bytes and 1 bytes for the data buffer and validity buffer of the + * inner vector. Thus value capacity of inner vector is 8 */ vector.setInitialCapacity(512, 0.01); vector.allocateNew(); @@ -814,14 +814,11 @@ public void testSetInitialCapacity() { assertTrue(vector.getDataVector().getValueCapacity() >= 5); /** - * inner value capacity we pass to data vector is 5 * 0.1 => 0 - * which is then rounded off to 1. So we pass value count as 1 - * to the inner int vector. - * the offset buffer of the list vector is allocated for 6 values - * which is 24 bytes and then rounded off to 32 bytes (8 values) - * the validity buffer of the list vector is allocated for 5 - * values which is 1 byte. This is why value capacity of the list - * vector is 7 as we take the min of validity buffer value capacity + * inner value capacity we pass to data vector is 5 * 0.1 => 0 which is then rounded off to 1. + * So we pass value count as 1 to the inner int vector. the offset buffer of the list vector + * is allocated for 6 values which is 24 bytes and then rounded off to 32 bytes (8 values) the + * validity buffer of the list vector is allocated for 5 values which is 1 byte. This is why + * value capacity of the list vector is 7 as we take the min of validity buffer value capacity * and offset buffer value capacity. */ vector.setInitialCapacity(5, 0.1); @@ -835,7 +832,8 @@ public void testSetInitialCapacity() { public void testClearAndReuse() { try (final LargeListVector vector = LargeListVector.empty("list", allocator)) { BigIntVector bigIntVector = - (BigIntVector) vector.addOrGetVector(FieldType.nullable(MinorType.BIGINT.getType())).getVector(); + (BigIntVector) + vector.addOrGetVector(FieldType.nullable(MinorType.BIGINT.getType())).getVector(); vector.setInitialCapacity(10); vector.allocateNew(); @@ -884,17 +882,23 @@ public void testWriterGetField() { UnionLargeListWriter writer = vector.getWriter(); writer.allocate(); - //set some values + // set some values writer.startList(); writer.integer().writeInt(1); writer.integer().writeInt(2); writer.endList(); vector.setValueCount(2); - Field expectedDataField = new Field(BaseRepeatedValueVector.DATA_VECTOR_NAME, - FieldType.nullable(new ArrowType.Int(32, true)), null); - Field expectedField = new Field(vector.getName(), FieldType.nullable(ArrowType.LargeList.INSTANCE), - Arrays.asList(expectedDataField)); + Field expectedDataField = + new Field( + BaseRepeatedValueVector.DATA_VECTOR_NAME, + FieldType.nullable(new ArrowType.Int(32, true)), + null); + Field expectedField = + new Field( + vector.getName(), + FieldType.nullable(ArrowType.LargeList.INSTANCE), + Arrays.asList(expectedDataField)); assertEquals(expectedField, writer.getField()); } @@ -907,7 +911,7 @@ public void testClose() throws Exception { UnionLargeListWriter writer = vector.getWriter(); writer.allocate(); - //set some values + // set some values writer.startList(); writer.integer().writeInt(1); writer.integer().writeInt(2); @@ -930,7 +934,7 @@ public void testGetBufferSizeFor() { UnionLargeListWriter writer = vector.getWriter(); writer.allocate(); - //set some values + // set some values writeIntValues(writer, new int[] {1, 2}); writeIntValues(writer, new int[] {3, 4}); writeIntValues(writer, new int[] {5, 6}); @@ -945,7 +949,10 @@ public void testGetBufferSizeFor() { int validityBufferSize = BitVectorHelper.getValidityBufferSize(valueCount); int offsetBufferSize = (valueCount + 1) * LargeListVector.OFFSET_WIDTH; - int expectedSize = validityBufferSize + offsetBufferSize + dataVector.getBufferSizeFor(indices[valueCount]); + int expectedSize = + validityBufferSize + + offsetBufferSize + + dataVector.getBufferSizeFor(indices[valueCount]); assertEquals(expectedSize, vector.getBufferSizeFor(valueCount)); } } @@ -1000,24 +1007,25 @@ public void testGetTransferPairWithField() throws Exception { UnionLargeListWriter writer = fromVector.getWriter(); writer.allocate(); - //set some values + // set some values writer.startList(); writer.integer().writeInt(1); writer.integer().writeInt(2); writer.endList(); fromVector.setValueCount(2); - final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), - allocator); + final TransferPair transferPair = + fromVector.getTransferPair(fromVector.getField(), allocator); final LargeListVector toVector = (LargeListVector) transferPair.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(toVector.getField(), fromVector.getField()); } } private void writeIntValues(UnionLargeListWriter writer, int[] values) { writer.startList(); - for (int v: values) { + for (int v : values) { writer.integer().writeInt(v); } writer.endList(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarBinaryVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarBinaryVector.java index ecababde8de..57d9b8d1cb6 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarBinaryVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarBinaryVector.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue; import java.util.Arrays; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -120,12 +119,16 @@ public void testGetBytesRepeatedly() { ReusableByteArray reusableByteArray = new ReusableByteArray(); vector.read(0, reusableByteArray); byte[] oldBuffer = reusableByteArray.getBuffer(); - assertArrayEquals(str.getBytes(), Arrays.copyOfRange(reusableByteArray.getBuffer(), - 0, (int) reusableByteArray.getLength())); + assertArrayEquals( + str.getBytes(), + Arrays.copyOfRange( + reusableByteArray.getBuffer(), 0, (int) reusableByteArray.getLength())); vector.read(1, reusableByteArray); - assertArrayEquals(str2.getBytes(), Arrays.copyOfRange(reusableByteArray.getBuffer(), - 0, (int) reusableByteArray.getLength())); + assertArrayEquals( + str2.getBytes(), + Arrays.copyOfRange( + reusableByteArray.getBuffer(), 0, (int) reusableByteArray.getLength())); // There should not have been any reallocation since the newer value is smaller in length. assertSame(oldBuffer, reusableByteArray.getBuffer()); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarCharVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarCharVector.java index 7d074c39364..c8ed514bf4c 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarCharVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestLargeVarCharVector.java @@ -27,7 +27,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.OutOfMemoryException; @@ -70,9 +69,9 @@ public void shutdown() { @Test public void testTransfer() { try (BufferAllocator childAllocator1 = allocator.newChildAllocator("child1", 1000000, 1000000); - BufferAllocator childAllocator2 = allocator.newChildAllocator("child2", 1000000, 1000000); - LargeVarCharVector v1 = new LargeVarCharVector("v1", childAllocator1); - LargeVarCharVector v2 = new LargeVarCharVector("v2", childAllocator2);) { + BufferAllocator childAllocator2 = allocator.newChildAllocator("child2", 1000000, 1000000); + LargeVarCharVector v1 = new LargeVarCharVector("v1", childAllocator1); + LargeVarCharVector v2 = new LargeVarCharVector("v2", childAllocator2); ) { v1.allocateNew(); v1.setSafe(4094, "hello world".getBytes(), 0, 11); v1.setValueCount(4001); @@ -88,8 +87,10 @@ public void testTransfer() { @Test public void testCopyValueSafe() { - try (final LargeVarCharVector largeVarCharVector = new LargeVarCharVector("myvector", allocator); - final LargeVarCharVector newLargeVarCharVector = new LargeVarCharVector("newvector", allocator)) { + try (final LargeVarCharVector largeVarCharVector = + new LargeVarCharVector("myvector", allocator); + final LargeVarCharVector newLargeVarCharVector = + new LargeVarCharVector("newvector", allocator)) { largeVarCharVector.allocateNew(10000, 1000); final int valueCount = 500; @@ -118,7 +119,8 @@ public void testCopyValueSafe() { @Test public void testSplitAndTransferNon() { - try (final LargeVarCharVector largeVarCharVector = new LargeVarCharVector("myvector", allocator)) { + try (final LargeVarCharVector largeVarCharVector = + new LargeVarCharVector("myvector", allocator)) { largeVarCharVector.allocateNew(10000, 1000); final int valueCount = 500; @@ -135,7 +137,8 @@ public void testSplitAndTransferNon() { @Test public void testSplitAndTransferAll() { - try (final LargeVarCharVector largeVarCharVector = new LargeVarCharVector("myvector", allocator)) { + try (final LargeVarCharVector largeVarCharVector = + new LargeVarCharVector("myvector", allocator)) { largeVarCharVector.allocateNew(10000, 1000); final int valueCount = 500; @@ -152,8 +155,10 @@ public void testSplitAndTransferAll() { @Test public void testInvalidStartIndex() { - try (final LargeVarCharVector largeVarCharVector = new LargeVarCharVector("myvector", allocator); - final LargeVarCharVector newLargeVarCharVector = new LargeVarCharVector("newvector", allocator)) { + try (final LargeVarCharVector largeVarCharVector = + new LargeVarCharVector("myvector", allocator); + final LargeVarCharVector newLargeVarCharVector = + new LargeVarCharVector("newvector", allocator)) { largeVarCharVector.allocateNew(10000, 1000); final int valueCount = 500; @@ -161,9 +166,9 @@ public void testInvalidStartIndex() { final TransferPair tp = largeVarCharVector.makeTransferPair(newLargeVarCharVector); - IllegalArgumentException e = Assertions.assertThrows( - IllegalArgumentException.class, - () -> tp.splitAndTransfer(valueCount, 10)); + IllegalArgumentException e = + Assertions.assertThrows( + IllegalArgumentException.class, () -> tp.splitAndTransfer(valueCount, 10)); assertEquals("Invalid startIndex: 500", e.getMessage()); } @@ -171,8 +176,10 @@ public void testInvalidStartIndex() { @Test public void testInvalidLength() { - try (final LargeVarCharVector largeVarCharVector = new LargeVarCharVector("myvector", allocator); - final LargeVarCharVector newLargeVarCharVector = new LargeVarCharVector("newvector", allocator)) { + try (final LargeVarCharVector largeVarCharVector = + new LargeVarCharVector("myvector", allocator); + final LargeVarCharVector newLargeVarCharVector = + new LargeVarCharVector("newvector", allocator)) { largeVarCharVector.allocateNew(10000, 1000); final int valueCount = 500; @@ -180,9 +187,9 @@ public void testInvalidLength() { final TransferPair tp = largeVarCharVector.makeTransferPair(newLargeVarCharVector); - IllegalArgumentException e = Assertions.assertThrows( - IllegalArgumentException.class, - () -> tp.splitAndTransfer(0, valueCount * 2)); + IllegalArgumentException e = + Assertions.assertThrows( + IllegalArgumentException.class, () -> tp.splitAndTransfer(0, valueCount * 2)); assertEquals("Invalid length: 1000", e.getMessage()); } @@ -289,7 +296,7 @@ public void testSetLastSetUsage() { assertEquals(40, vector.offsetBuffer.getLong(17 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); assertEquals(40, vector.offsetBuffer.getLong(18 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); assertEquals(40, vector.offsetBuffer.getLong(19 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - + vector.set(19, STR6); assertArrayEquals(STR6, vector.get(19)); assertEquals(40, vector.offsetBuffer.getLong(19 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); @@ -334,7 +341,8 @@ public void testLargeVariableVectorReallocation() { @Test public void testSplitAndTransfer() { - try (final LargeVarCharVector largeVarCharVector = new LargeVarCharVector("myvector", allocator)) { + try (final LargeVarCharVector largeVarCharVector = + new LargeVarCharVector("myvector", allocator)) { largeVarCharVector.allocateNew(10000, 1000); final int valueCount = 500; @@ -495,13 +503,12 @@ public void testVectorLoadUnload() { Schema schema = new Schema(fields); - VectorSchemaRoot schemaRoot1 = new VectorSchemaRoot(schema, fieldVectors, vector1.getValueCount()); + VectorSchemaRoot schemaRoot1 = + new VectorSchemaRoot(schema, fieldVectors, vector1.getValueCount()); VectorUnloader vectorUnloader = new VectorUnloader(schemaRoot1); - try ( - ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); - VectorSchemaRoot schemaRoot2 = VectorSchemaRoot.create(schema, allocator); - ) { + try (ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); + VectorSchemaRoot schemaRoot2 = VectorSchemaRoot.create(schema, allocator); ) { VectorLoader vectorLoader = new VectorLoader(schemaRoot2); vectorLoader.load(recordBatch); @@ -597,41 +604,25 @@ public void testFillEmptiesUsage() { assertEquals(0, vector.getValueLength(14)); /* Check offsets */ - assertEquals(0, - vector.offsetBuffer.getLong(0 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(6, - vector.offsetBuffer.getLong(1 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(16, - vector.offsetBuffer.getLong(2 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(21, - vector.offsetBuffer.getLong(3 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(30, - vector.offsetBuffer.getLong(4 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(34, - vector.offsetBuffer.getLong(5 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - - assertEquals(40, - vector.offsetBuffer.getLong(6 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(40, - vector.offsetBuffer.getLong(7 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(40, - vector.offsetBuffer.getLong(8 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(40, - vector.offsetBuffer.getLong(9 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(40, - vector.offsetBuffer.getLong(10 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - - assertEquals(46, - vector.offsetBuffer.getLong(11 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(56, - vector.offsetBuffer.getLong(12 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - - assertEquals(56, - vector.offsetBuffer.getLong(13 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(56, - vector.offsetBuffer.getLong(14 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); - assertEquals(56, - vector.offsetBuffer.getLong(15 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(0, vector.offsetBuffer.getLong(0 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(6, vector.offsetBuffer.getLong(1 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(16, vector.offsetBuffer.getLong(2 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(21, vector.offsetBuffer.getLong(3 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(30, vector.offsetBuffer.getLong(4 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(34, vector.offsetBuffer.getLong(5 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + + assertEquals(40, vector.offsetBuffer.getLong(6 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(40, vector.offsetBuffer.getLong(7 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(40, vector.offsetBuffer.getLong(8 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(40, vector.offsetBuffer.getLong(9 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(40, vector.offsetBuffer.getLong(10 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + + assertEquals(46, vector.offsetBuffer.getLong(11 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(56, vector.offsetBuffer.getLong(12 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + + assertEquals(56, vector.offsetBuffer.getLong(13 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(56, vector.offsetBuffer.getLong(14 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); + assertEquals(56, vector.offsetBuffer.getLong(15 * BaseLargeVariableWidthVector.OFFSET_WIDTH)); } } @@ -724,8 +715,10 @@ public void testSetNullableLargeVarCharHolderSafe() { @Test public void testGetNullFromLargeVariableWidthVector() { - try (final LargeVarCharVector largeVarCharVector = new LargeVarCharVector("largevarcharvec", allocator); - final LargeVarBinaryVector largeVarBinaryVector = new LargeVarBinaryVector("largevarbinary", allocator)) { + try (final LargeVarCharVector largeVarCharVector = + new LargeVarCharVector("largevarcharvec", allocator); + final LargeVarBinaryVector largeVarBinaryVector = + new LargeVarBinaryVector("largevarbinary", allocator)) { largeVarCharVector.allocateNew(10, 1); largeVarBinaryVector.allocateNew(10, 1); @@ -736,10 +729,11 @@ public void testGetNullFromLargeVariableWidthVector() { assertNull(largeVarBinaryVector.get(0)); } } - + @Test public void testLargeVariableWidthVectorNullHashCode() { - try (LargeVarCharVector largeVarChVec = new LargeVarCharVector("large var char vector", allocator)) { + try (LargeVarCharVector largeVarChVec = + new LargeVarCharVector("large var char vector", allocator)) { largeVarChVec.allocateNew(100, 1); largeVarChVec.setValueCount(1); @@ -752,7 +746,8 @@ public void testLargeVariableWidthVectorNullHashCode() { @Test public void testUnloadLargeVariableWidthVector() { - try (final LargeVarCharVector largeVarCharVector = new LargeVarCharVector("var char", allocator)) { + try (final LargeVarCharVector largeVarCharVector = + new LargeVarCharVector("var char", allocator)) { largeVarCharVector.allocateNew(5, 2); largeVarCharVector.setValueCount(2); @@ -832,7 +827,8 @@ public void testGetTransferPairWithField() { } } - private void populateLargeVarcharVector(final LargeVarCharVector vector, int valueCount, String[] values) { + private void populateLargeVarcharVector( + final LargeVarCharVector vector, int valueCount, String[] values) { for (int i = 0; i < valueCount; i += 3) { final String s = String.format("%010d", i); vector.set(i, s.getBytes()); @@ -844,11 +840,13 @@ private void populateLargeVarcharVector(final LargeVarCharVector vector, int val } public static void setBytes(int index, byte[] bytes, LargeVarCharVector vector) { - final long currentOffset = vector.offsetBuffer.getLong((long) index * BaseLargeVariableWidthVector.OFFSET_WIDTH); + final long currentOffset = + vector.offsetBuffer.getLong((long) index * BaseLargeVariableWidthVector.OFFSET_WIDTH); BitVectorHelper.setBit(vector.validityBuffer, index); vector.offsetBuffer.setLong( - (long) (index + 1) * BaseLargeVariableWidthVector.OFFSET_WIDTH, currentOffset + bytes.length); + (long) (index + 1) * BaseLargeVariableWidthVector.OFFSET_WIDTH, + currentOffset + bytes.length); vector.valueBuffer.setBytes(currentOffset, bytes, 0, bytes.length); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java index 278f497b479..a0daed599d4 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestListVector.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.AutoCloseables; @@ -66,7 +65,7 @@ public void terminate() throws Exception { @Test public void testCopyFrom() throws Exception { try (ListVector inVector = ListVector.empty("input", allocator); - ListVector outVector = ListVector.empty("output", allocator)) { + ListVector outVector = ListVector.empty("output", allocator)) { UnionListWriter writer = inVector.getWriter(); writer.allocate(); @@ -102,7 +101,6 @@ public void testCopyFrom() throws Exception { reader.setPosition(2); Assert.assertTrue("shouldn't be null", reader.isSet()); - /* index 0 */ Object result = outVector.getObject(0); ArrayList resultSet = (ArrayList) result; @@ -434,20 +432,26 @@ public void testSplitAndTransfer() throws Exception { BigIntVector dataVector1 = (BigIntVector) toVector.getDataVector(); for (int i = 0; i < splitLength; i++) { - dataLength1 = offsetBuffer.getInt((start + i + 1) * ListVector.OFFSET_WIDTH) - - offsetBuffer.getInt((start + i) * ListVector.OFFSET_WIDTH); - dataLength2 = toOffsetBuffer.getInt((i + 1) * ListVector.OFFSET_WIDTH) - - toOffsetBuffer.getInt(i * ListVector.OFFSET_WIDTH); - - assertEquals("Different data lengths at index: " + i + " and start: " + start, - dataLength1, dataLength2); + dataLength1 = + offsetBuffer.getInt((start + i + 1) * ListVector.OFFSET_WIDTH) + - offsetBuffer.getInt((start + i) * ListVector.OFFSET_WIDTH); + dataLength2 = + toOffsetBuffer.getInt((i + 1) * ListVector.OFFSET_WIDTH) + - toOffsetBuffer.getInt(i * ListVector.OFFSET_WIDTH); + + assertEquals( + "Different data lengths at index: " + i + " and start: " + start, + dataLength1, + dataLength2); offset1 = offsetBuffer.getInt((start + i) * ListVector.OFFSET_WIDTH); offset2 = toOffsetBuffer.getInt(i * ListVector.OFFSET_WIDTH); for (int j = 0; j < dataLength1; j++) { - assertEquals("Different data at indexes: " + offset1 + " and " + offset2, - dataVector.getObject(offset1), dataVector1.getObject(offset2)); + assertEquals( + "Different data at indexes: " + offset1 + " and " + offset2, + dataVector.getObject(offset1), + dataVector1.getObject(offset2)); offset1++; offset2++; @@ -778,8 +782,8 @@ public void testSetInitialCapacity() { vector.addOrGetVector(FieldType.nullable(MinorType.INT.getType())); /** - * use the default multiplier of 5, - * 512 * 5 => 2560 * 4 => 10240 bytes => 16KB => 4096 value capacity. + * use the default multiplier of 5, 512 * 5 => 2560 * 4 => 10240 bytes => 16KB => 4096 value + * capacity. */ vector.setInitialCapacity(512); vector.allocateNew(); @@ -793,12 +797,10 @@ public void testSetInitialCapacity() { assertTrue(vector.getDataVector().getValueCapacity() >= 512 * 4); /** - * inner value capacity we pass to data vector is 512 * 0.1 => 51 - * For an int vector this is 204 bytes of memory for data buffer - * and 7 bytes for validity buffer. - * and with power of 2 allocation, we allocate 256 bytes and 8 bytes - * for the data buffer and validity buffer of the inner vector. Thus - * value capacity of inner vector is 64 + * inner value capacity we pass to data vector is 512 * 0.1 => 51 For an int vector this is + * 204 bytes of memory for data buffer and 7 bytes for validity buffer. and with power of 2 + * allocation, we allocate 256 bytes and 8 bytes for the data buffer and validity buffer of + * the inner vector. Thus value capacity of inner vector is 64 */ vector.setInitialCapacity(512, 0.1); vector.allocateNew(); @@ -806,12 +808,10 @@ public void testSetInitialCapacity() { assertTrue(vector.getDataVector().getValueCapacity() >= 51); /** - * inner value capacity we pass to data vector is 512 * 0.01 => 5 - * For an int vector this is 20 bytes of memory for data buffer - * and 1 byte for validity buffer. - * and with power of 2 allocation, we allocate 32 bytes and 1 bytes - * for the data buffer and validity buffer of the inner vector. Thus - * value capacity of inner vector is 8 + * inner value capacity we pass to data vector is 512 * 0.01 => 5 For an int vector this is 20 + * bytes of memory for data buffer and 1 byte for validity buffer. and with power of 2 + * allocation, we allocate 32 bytes and 1 bytes for the data buffer and validity buffer of the + * inner vector. Thus value capacity of inner vector is 8 */ vector.setInitialCapacity(512, 0.01); vector.allocateNew(); @@ -819,14 +819,11 @@ public void testSetInitialCapacity() { assertTrue(vector.getDataVector().getValueCapacity() >= 5); /** - * inner value capacity we pass to data vector is 5 * 0.1 => 0 - * which is then rounded off to 1. So we pass value count as 1 - * to the inner int vector. - * the offset buffer of the list vector is allocated for 6 values - * which is 24 bytes and then rounded off to 32 bytes (8 values) - * the validity buffer of the list vector is allocated for 5 - * values which is 1 byte. This is why value capacity of the list - * vector is 7 as we take the min of validity buffer value capacity + * inner value capacity we pass to data vector is 5 * 0.1 => 0 which is then rounded off to 1. + * So we pass value count as 1 to the inner int vector. the offset buffer of the list vector + * is allocated for 6 values which is 24 bytes and then rounded off to 32 bytes (8 values) the + * validity buffer of the list vector is allocated for 5 values which is 1 byte. This is why + * value capacity of the list vector is 7 as we take the min of validity buffer value capacity * and offset buffer value capacity. */ vector.setInitialCapacity(5, 0.1); @@ -840,7 +837,8 @@ public void testSetInitialCapacity() { public void testClearAndReuse() { try (final ListVector vector = ListVector.empty("list", allocator)) { BigIntVector bigIntVector = - (BigIntVector) vector.addOrGetVector(FieldType.nullable(MinorType.BIGINT.getType())).getVector(); + (BigIntVector) + vector.addOrGetVector(FieldType.nullable(MinorType.BIGINT.getType())).getVector(); vector.setInitialCapacity(10); vector.allocateNew(); @@ -889,17 +887,23 @@ public void testWriterGetField() { UnionListWriter writer = vector.getWriter(); writer.allocate(); - //set some values + // set some values writer.startList(); writer.integer().writeInt(1); writer.integer().writeInt(2); writer.endList(); vector.setValueCount(2); - Field expectedDataField = new Field(BaseRepeatedValueVector.DATA_VECTOR_NAME, - FieldType.nullable(new ArrowType.Int(32, true)), null); - Field expectedField = new Field(vector.getName(), FieldType.nullable(ArrowType.List.INSTANCE), - Arrays.asList(expectedDataField)); + Field expectedDataField = + new Field( + BaseRepeatedValueVector.DATA_VECTOR_NAME, + FieldType.nullable(new ArrowType.Int(32, true)), + null); + Field expectedField = + new Field( + vector.getName(), + FieldType.nullable(ArrowType.List.INSTANCE), + Arrays.asList(expectedDataField)); assertEquals(expectedField, writer.getField()); } @@ -917,10 +921,16 @@ public void testWriterGetTimestampMilliTZField() { writer.endList(); vector.setValueCount(1); - Field expectedDataField = new Field(BaseRepeatedValueVector.DATA_VECTOR_NAME, - FieldType.nullable(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC")), null); - Field expectedField = new Field(vector.getName(), FieldType.nullable(ArrowType.List.INSTANCE), - Arrays.asList(expectedDataField)); + Field expectedDataField = + new Field( + BaseRepeatedValueVector.DATA_VECTOR_NAME, + FieldType.nullable(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC")), + null); + Field expectedField = + new Field( + vector.getName(), + FieldType.nullable(ArrowType.List.INSTANCE), + Arrays.asList(expectedDataField)); assertEquals(expectedField, writer.getField()); } @@ -943,17 +953,26 @@ public void testWriterUsingHolderGetTimestampMilliTZField() { // Writing with a different timezone should throw holder.timezone = "AsdfTimeZone"; holder.value = 77777; - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> writer.timeStampMilliTZ().write(holder)); - assertEquals("holder.timezone: AsdfTimeZone not equal to vector timezone: SomeFakeTimeZone", ex.getMessage()); + IllegalArgumentException ex = + assertThrows( + IllegalArgumentException.class, () -> writer.timeStampMilliTZ().write(holder)); + assertEquals( + "holder.timezone: AsdfTimeZone not equal to vector timezone: SomeFakeTimeZone", + ex.getMessage()); writer.endList(); vector.setValueCount(1); - Field expectedDataField = new Field(BaseRepeatedValueVector.DATA_VECTOR_NAME, - FieldType.nullable(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "SomeFakeTimeZone")), null); - Field expectedField = new Field(vector.getName(), FieldType.nullable(ArrowType.List.INSTANCE), - Arrays.asList(expectedDataField)); + Field expectedDataField = + new Field( + BaseRepeatedValueVector.DATA_VECTOR_NAME, + FieldType.nullable(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "SomeFakeTimeZone")), + null); + Field expectedField = + new Field( + vector.getName(), + FieldType.nullable(ArrowType.List.INSTANCE), + Arrays.asList(expectedDataField)); assertEquals(expectedField, writer.getField()); } @@ -977,17 +996,24 @@ public void testWriterGetDurationField() { // Writing with a different unit should throw durationHolder.unit = TimeUnit.SECOND; durationHolder.value = 8888888; - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> writer.duration().write(durationHolder)); + IllegalArgumentException ex = + assertThrows( + IllegalArgumentException.class, () -> writer.duration().write(durationHolder)); assertEquals("holder.unit: SECOND not equal to vector unit: MILLISECOND", ex.getMessage()); writer.endList(); vector.setValueCount(1); - Field expectedDataField = new Field(BaseRepeatedValueVector.DATA_VECTOR_NAME, - FieldType.nullable(new ArrowType.Duration(TimeUnit.MILLISECOND)), null); - Field expectedField = new Field(vector.getName(), FieldType.nullable(ArrowType.List.INSTANCE), - Arrays.asList(expectedDataField)); + Field expectedDataField = + new Field( + BaseRepeatedValueVector.DATA_VECTOR_NAME, + FieldType.nullable(new ArrowType.Duration(TimeUnit.MILLISECOND)), + null); + Field expectedField = + new Field( + vector.getName(), + FieldType.nullable(ArrowType.List.INSTANCE), + Arrays.asList(expectedDataField)); assertEquals(expectedField, writer.getField()); } @@ -1026,17 +1052,24 @@ public void testWriterGetFixedSizeBinaryField() throws Exception { // Writing with a different byteWidth should throw // Note just reusing the last buffer value since that won't matter here anyway binHolder.byteWidth = 3; - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> writer.fixedSizeBinary().write(binHolder)); + IllegalArgumentException ex = + assertThrows( + IllegalArgumentException.class, () -> writer.fixedSizeBinary().write(binHolder)); assertEquals("holder.byteWidth: 3 not equal to vector byteWidth: 9", ex.getMessage()); writer.endList(); vector.setValueCount(1); - Field expectedDataField = new Field(BaseRepeatedValueVector.DATA_VECTOR_NAME, - FieldType.nullable(new ArrowType.FixedSizeBinary(byteWidth)), null); - Field expectedField = new Field(vector.getName(), FieldType.nullable(ArrowType.List.INSTANCE), - Arrays.asList(expectedDataField)); + Field expectedDataField = + new Field( + BaseRepeatedValueVector.DATA_VECTOR_NAME, + FieldType.nullable(new ArrowType.FixedSizeBinary(byteWidth)), + null); + Field expectedField = + new Field( + vector.getName(), + FieldType.nullable(ArrowType.List.INSTANCE), + Arrays.asList(expectedDataField)); assertEquals(expectedField, writer.getField()); } @@ -1050,7 +1083,7 @@ public void testClose() throws Exception { UnionListWriter writer = vector.getWriter(); writer.allocate(); - //set some values + // set some values writer.startList(); writer.integer().writeInt(1); writer.integer().writeInt(2); @@ -1073,7 +1106,7 @@ public void testGetBufferSizeFor() { UnionListWriter writer = vector.getWriter(); writer.allocate(); - //set some values + // set some values writeIntValues(writer, new int[] {1, 2}); writeIntValues(writer, new int[] {3, 4}); writeIntValues(writer, new int[] {5, 6}); @@ -1088,7 +1121,10 @@ public void testGetBufferSizeFor() { int validityBufferSize = BitVectorHelper.getValidityBufferSize(valueCount); int offsetBufferSize = (valueCount + 1) * BaseRepeatedValueVector.OFFSET_WIDTH; - int expectedSize = validityBufferSize + offsetBufferSize + dataVector.getBufferSizeFor(indices[valueCount]); + int expectedSize = + validityBufferSize + + offsetBufferSize + + dataVector.getBufferSizeFor(indices[valueCount]); assertEquals(expectedSize, vector.getBufferSizeFor(valueCount)); } } @@ -1148,17 +1184,18 @@ public void testGetTransferPairWithField() { writer.bigInt().writeBigInt(3); writer.endList(); writer.setValueCount(1); - final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), - allocator); + final TransferPair transferPair = + fromVector.getTransferPair(fromVector.getField(), allocator); final ListVector toVector = (ListVector) transferPair.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(toVector.getField(), fromVector.getField()); } } private void writeIntValues(UnionListWriter writer, int[] values) { writer.startList(); - for (int v: values) { + for (int v : values) { writer.integer().writeInt(v); } writer.endList(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestMapVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestMapVector.java index 1db55198e4b..98c68092674 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestMapVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestMapVector.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.Map; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.MapVector; @@ -152,7 +151,7 @@ public void testBasicOperationNulls() { @Test public void testCopyFrom() throws Exception { try (MapVector inVector = MapVector.empty("input", allocator, false); - MapVector outVector = MapVector.empty("output", allocator, false)) { + MapVector outVector = MapVector.empty("output", allocator, false)) { UnionMapWriter writer = inVector.getWriter(); writer.allocate(); @@ -200,7 +199,6 @@ public void testCopyFrom() throws Exception { reader.setPosition(2); assertTrue("shouldn't be null", reader.isSet()); - /* index 0 */ Object result = outVector.getObject(0); ArrayList resultSet = (ArrayList) result; @@ -455,20 +453,26 @@ public void testSplitAndTransfer() throws Exception { StructVector dataVector1 = (StructVector) toVector.getDataVector(); for (int i = 0; i < splitLength; i++) { - dataLength1 = offsetBuffer.getInt((start + i + 1) * MapVector.OFFSET_WIDTH) - - offsetBuffer.getInt((start + i) * MapVector.OFFSET_WIDTH); - dataLength2 = toOffsetBuffer.getInt((i + 1) * MapVector.OFFSET_WIDTH) - - toOffsetBuffer.getInt(i * MapVector.OFFSET_WIDTH); - - assertEquals("Different data lengths at index: " + i + " and start: " + start, - dataLength1, dataLength2); + dataLength1 = + offsetBuffer.getInt((start + i + 1) * MapVector.OFFSET_WIDTH) + - offsetBuffer.getInt((start + i) * MapVector.OFFSET_WIDTH); + dataLength2 = + toOffsetBuffer.getInt((i + 1) * MapVector.OFFSET_WIDTH) + - toOffsetBuffer.getInt(i * MapVector.OFFSET_WIDTH); + + assertEquals( + "Different data lengths at index: " + i + " and start: " + start, + dataLength1, + dataLength2); offset1 = offsetBuffer.getInt((start + i) * MapVector.OFFSET_WIDTH); offset2 = toOffsetBuffer.getInt(i * MapVector.OFFSET_WIDTH); for (int j = 0; j < dataLength1; j++) { - assertEquals("Different data at indexes: " + offset1 + " and " + offset2, - dataVector.getObject(offset1), dataVector1.getObject(offset2)); + assertEquals( + "Different data at indexes: " + offset1 + " and " + offset2, + dataVector.getObject(offset1), + dataVector1.getObject(offset2)); offset1++; offset2++; @@ -806,7 +810,8 @@ public void testMapWithMapKeyAndMapValue() throws Exception { // populate map vector with the following two records // [ // [[5: 10, 20: 40]:[50: 100, 200: 400], [50: 100]:[75: 175, 150: 250]], - // [[1: 2]:[10: 20], [30: 40]:[15: 20], [50: 60, 70: null]:[25: 30, 35: null], [5: null]: null] + // [[1: 2]:[10: 20], [30: 40]:[15: 20], [50: 60, 70: null]:[25: 30, 35: null], [5: null]: + // null] // ] mapWriter.setPosition(0); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestNullCheckingForGet.java b/java/vector/src/test/java/org/apache/arrow/vector/TestNullCheckingForGet.java index f1345e88ab8..ae4326c0b4f 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestNullCheckingForGet.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestNullCheckingForGet.java @@ -19,17 +19,15 @@ import java.lang.reflect.Field; import java.net.URLClassLoader; - import org.junit.Assert; import org.junit.Test; -/** - * Test cases for {@link NullCheckingForGet}. - */ +/** Test cases for {@link NullCheckingForGet}. */ public class TestNullCheckingForGet { /** * Get a copy of the current class loader. + * * @return the newly created class loader. */ private ClassLoader copyClassLoader() { @@ -44,7 +42,8 @@ private ClassLoader copyClassLoader() { } /** - * Get the value of flag {@link NullCheckingForGet#NULL_CHECKING_ENABLED}. + * Get the value of flag {@link NullCheckingForGet#NULL_CHECKING_ENABLED}. + * * @param classLoader the class loader from which to get the flag value. * @return value of the flag. */ @@ -55,8 +54,8 @@ private boolean getFlagValue(ClassLoader classLoader) throws Exception { } /** - * Ensure the flag for null checking is enabled by default. - * This will protect users from JVM crashes. + * Ensure the flag for null checking is enabled by default. This will protect users from JVM + * crashes. */ @Test public void testDefaultValue() throws Exception { @@ -69,6 +68,7 @@ public void testDefaultValue() throws Exception { /** * Test setting the null checking flag by the system property. + * * @throws Exception if loading class {@link NullCheckingForGet#NULL_CHECKING_ENABLED} fails. */ @Test diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestOutOfMemoryForValueVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestOutOfMemoryForValueVector.java index 7f26b5c1b79..5b58b4d2e82 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestOutOfMemoryForValueVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestOutOfMemoryForValueVector.java @@ -24,9 +24,7 @@ import org.junit.Before; import org.junit.Test; -/** - * This class tests cases where we expect to receive {@link OutOfMemoryException}. - */ +/** This class tests cases where we expect to receive {@link OutOfMemoryException}. */ public class TestOutOfMemoryForValueVector { private static final String EMPTY_SCHEMA_PATH = ""; diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestOversizedAllocationForValueVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestOversizedAllocationForValueVector.java index 23414e9f5df..a88cda8b7c2 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestOversizedAllocationForValueVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestOversizedAllocationForValueVector.java @@ -29,9 +29,10 @@ import org.junit.Test; /** - * This class tests that OversizedAllocationException occurs when a large memory is allocated for a vector. - * Typically, arrow allows the allocation of the size of at most Integer.MAX_VALUE, but this might cause OOM in tests. - * Thus, the max allocation size is limited to 1 KB in this class. Please see the surefire option in pom.xml. + * This class tests that OversizedAllocationException occurs when a large memory is allocated for a + * vector. Typically, arrow allows the allocation of the size of at most Integer.MAX_VALUE, but this + * might cause OOM in tests. Thus, the max allocation size is limited to 1 KB in this class. Please + * see the surefire option in pom.xml. */ public class TestOversizedAllocationForValueVector { @@ -102,7 +103,6 @@ public void testBitVectorReallocation() { } } - @Test(expected = OversizedAllocationException.class) public void testVariableVectorReallocation() { final VarCharVector vector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestPeriodDuration.java b/java/vector/src/test/java/org/apache/arrow/vector/TestPeriodDuration.java index c8965dec3b8..1994ea38a92 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestPeriodDuration.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestPeriodDuration.java @@ -22,7 +22,6 @@ import java.time.Duration; import java.time.Period; - import org.junit.Test; public class TestPeriodDuration { @@ -42,5 +41,4 @@ public void testBasics() { assertNotEquals(pd1, pd3); assertNotEquals(pd1.hashCode(), pd3.hashCode()); } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestSplitAndTransfer.java b/java/vector/src/test/java/org/apache/arrow/vector/TestSplitAndTransfer.java index 716fa0bde45..2bcfc0f3ff9 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestSplitAndTransfer.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestSplitAndTransfer.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.Map; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.complex.FixedSizeListVector; @@ -48,13 +47,14 @@ public class TestSplitAndTransfer { public void init() { allocator = new RootAllocator(Long.MAX_VALUE); } - + @After public void terminate() throws Exception { allocator.close(); } - private void populateVarcharVector(final VarCharVector vector, int valueCount, String[] compareArray) { + private void populateVarcharVector( + final VarCharVector vector, int valueCount, String[] compareArray) { for (int i = 0; i < valueCount; i += 3) { final String s = String.format("%010d", i); vector.set(i, s.getBytes()); @@ -64,21 +64,21 @@ private void populateVarcharVector(final VarCharVector vector, int valueCount, S } vector.setValueCount(valueCount); } - + @Test /* VarCharVector */ public void test() throws Exception { try (final VarCharVector varCharVector = new VarCharVector("myvector", allocator)) { varCharVector.allocateNew(10000, 1000); - + final int valueCount = 500; final String[] compareArray = new String[valueCount]; - + populateVarcharVector(varCharVector, valueCount, compareArray); - + final TransferPair tp = varCharVector.getTransferPair(allocator); final VarCharVector newVarCharVector = (VarCharVector) tp.getTo(); final int[][] startLengths = {{0, 201}, {201, 0}, {201, 200}, {401, 99}}; - + for (final int[] startLength : startLengths) { final int start = startLength[0]; final int length = startLength[1]; @@ -156,7 +156,7 @@ public void testTransfer() { @Test public void testCopyValueSafe() { try (final VarCharVector varCharVector = new VarCharVector("myvector", allocator); - final VarCharVector newVarCharVector = new VarCharVector("newvector", allocator)) { + final VarCharVector newVarCharVector = new VarCharVector("newvector", allocator)) { varCharVector.allocateNew(10000, 1000); final int valueCount = 500; @@ -230,11 +230,12 @@ public void testInvalidStartIndex() { final TransferPair tp = varCharVector.makeTransferPair(newVarCharVector); - IllegalArgumentException e = Assertions.assertThrows( - IllegalArgumentException.class, - () -> tp.splitAndTransfer(valueCount, 10)); + IllegalArgumentException e = + Assertions.assertThrows( + IllegalArgumentException.class, () -> tp.splitAndTransfer(valueCount, 10)); - assertEquals("Invalid parameters startIndex: 500, length: 10 for valueCount: 500", e.getMessage()); + assertEquals( + "Invalid parameters startIndex: 500, length: 10 for valueCount: 500", e.getMessage()); newVarCharVector.clear(); } @@ -251,11 +252,12 @@ public void testInvalidLength() { final TransferPair tp = varCharVector.makeTransferPair(newVarCharVector); - IllegalArgumentException e = Assertions.assertThrows( - IllegalArgumentException.class, - () -> tp.splitAndTransfer(0, valueCount * 2)); + IllegalArgumentException e = + Assertions.assertThrows( + IllegalArgumentException.class, () -> tp.splitAndTransfer(0, valueCount * 2)); - assertEquals("Invalid parameters startIndex: 0, length: 1000 for valueCount: 500", e.getMessage()); + assertEquals( + "Invalid parameters startIndex: 0, length: 1000 for valueCount: 500", e.getMessage()); newVarCharVector.clear(); } @@ -264,7 +266,7 @@ public void testInvalidLength() { @Test public void testZeroStartIndexAndLength() { try (final VarCharVector varCharVector = new VarCharVector("myvector", allocator); - final VarCharVector newVarCharVector = new VarCharVector("newvector", allocator)) { + final VarCharVector newVarCharVector = new VarCharVector("newvector", allocator)) { varCharVector.allocateNew(0, 0); final int valueCount = 0; @@ -282,7 +284,7 @@ public void testZeroStartIndexAndLength() { @Test public void testZeroLength() { try (final VarCharVector varCharVector = new VarCharVector("myvector", allocator); - final VarCharVector newVarCharVector = new VarCharVector("newvector", allocator)) { + final VarCharVector newVarCharVector = new VarCharVector("newvector", allocator)) { varCharVector.allocateNew(10000, 1000); final int valueCount = 500; @@ -300,7 +302,7 @@ public void testZeroLength() { @Test public void testUnionVectorZeroStartIndexAndLength() { try (final UnionVector unionVector = UnionVector.empty("myvector", allocator); - final UnionVector newUnionVector = UnionVector.empty("newvector", allocator)) { + final UnionVector newUnionVector = UnionVector.empty("newvector", allocator)) { unionVector.allocateNew(); final int valueCount = 0; @@ -318,7 +320,7 @@ public void testUnionVectorZeroStartIndexAndLength() { @Test public void testFixedWidthVectorZeroStartIndexAndLength() { try (final IntVector intVector = new IntVector("myvector", allocator); - final IntVector newIntVector = new IntVector("newvector", allocator)) { + final IntVector newIntVector = new IntVector("newvector", allocator)) { intVector.allocateNew(0); final int valueCount = 0; @@ -336,7 +338,7 @@ public void testFixedWidthVectorZeroStartIndexAndLength() { @Test public void testBitVectorZeroStartIndexAndLength() { try (final BitVector bitVector = new BitVector("myvector", allocator); - final BitVector newBitVector = new BitVector("newvector", allocator)) { + final BitVector newBitVector = new BitVector("newvector", allocator)) { bitVector.allocateNew(0); final int valueCount = 0; @@ -354,7 +356,8 @@ public void testBitVectorZeroStartIndexAndLength() { @Test public void testFixedSizeListVectorZeroStartIndexAndLength() { try (final FixedSizeListVector listVector = FixedSizeListVector.empty("list", 4, allocator); - final FixedSizeListVector newListVector = FixedSizeListVector.empty("newList", 4, allocator)) { + final FixedSizeListVector newListVector = + FixedSizeListVector.empty("newList", 4, allocator)) { listVector.allocateNew(); final int valueCount = 0; @@ -372,7 +375,7 @@ public void testFixedSizeListVectorZeroStartIndexAndLength() { @Test public void testListVectorZeroStartIndexAndLength() { try (final ListVector listVector = ListVector.empty("list", allocator); - final ListVector newListVector = ListVector.empty("newList", allocator)) { + final ListVector newListVector = ListVector.empty("newList", allocator)) { listVector.allocateNew(); final int valueCount = 0; @@ -393,7 +396,8 @@ public void testStructVectorZeroStartIndexAndLength() { metadata.put("k1", "v1"); FieldType type = new FieldType(true, Struct.INSTANCE, null, metadata); try (final StructVector structVector = new StructVector("structvec", allocator, type, null); - final StructVector newStructVector = new StructVector("newStructvec", allocator, type, null)) { + final StructVector newStructVector = + new StructVector("newStructvec", allocator, type, null)) { structVector.allocateNew(); final int valueCount = 0; @@ -414,7 +418,7 @@ public void testMapVectorZeroStartIndexAndLength() { metadata.put("k1", "v1"); FieldType type = new FieldType(true, new ArrowType.Map(false), null, metadata); try (final MapVector mapVector = new MapVector("mapVec", allocator, type, null); - final MapVector newMapVector = new MapVector("newMapVec", allocator, type, null)) { + final MapVector newMapVector = new MapVector("newMapVec", allocator, type, null)) { mapVector.allocateNew(); final int valueCount = 0; @@ -428,5 +432,4 @@ public void testMapVectorZeroStartIndexAndLength() { newMapVector.clear(); } } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java index 68f5e14dabb..c1fe07ed9a8 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestStructVector.java @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.AbstractStructVector; import org.apache.arrow.vector.complex.ListVector; @@ -71,11 +70,12 @@ public void testFieldMetadata() throws Exception { @Test public void testMakeTransferPair() { try (final StructVector s1 = StructVector.empty("s1", allocator); - final StructVector s2 = StructVector.empty("s2", allocator)) { + final StructVector s2 = StructVector.empty("s2", allocator)) { s1.addOrGet("struct_child", FieldType.nullable(MinorType.INT.getType()), IntVector.class); s1.makeTransferPair(s2); final FieldVector child = s1.getChild("struct_child"); - final FieldVector toChild = s2.addOrGet("struct_child", child.getField().getFieldType(), child.getClass()); + final FieldVector toChild = + s2.addOrGet("struct_child", child.getField().getFieldType(), child.getClass()); assertEquals(0, toChild.getValueCapacity()); assertEquals(0, toChild.getDataBuffer().capacity()); assertEquals(0, toChild.getValidityBuffer().capacity()); @@ -157,7 +157,8 @@ public void testGetPrimitiveVectors() { unionVector.addVector(new SmallIntVector("smallInt", allocator)); // add varchar vector - vector.addOrGet("varchar", FieldType.nullable(MinorType.VARCHAR.getType()), VarCharVector.class); + vector.addOrGet( + "varchar", FieldType.nullable(MinorType.VARCHAR.getType()), VarCharVector.class); List primitiveVectors = vector.getPrimitiveVectors(); assertEquals(4, primitiveVectors.size()); @@ -192,8 +193,14 @@ public void testAddOrGetComplexChildVectors() { @Test public void testAddChildVectorsWithDuplicatedFieldNamesForConflictPolicyAppend() { final FieldType type = new FieldType(true, Struct.INSTANCE, null, null); - try (StructVector vector = new StructVector("struct", allocator, type, null, - AbstractStructVector.ConflictPolicy.CONFLICT_APPEND, true)) { + try (StructVector vector = + new StructVector( + "struct", + allocator, + type, + null, + AbstractStructVector.ConflictPolicy.CONFLICT_APPEND, + true)) { final List initFields = new ArrayList<>(); // Add a bit more fields to test against stability of the internal field @@ -245,8 +252,14 @@ public void testAddChildVectorsWithDuplicatedFieldNamesForConflictPolicyAppend() @Test public void testAddChildVectorsWithDuplicatedFieldNamesForConflictPolicyReplace() { final FieldType type = new FieldType(true, Struct.INSTANCE, null, null); - try (StructVector vector = new StructVector("struct", allocator, type, null, - AbstractStructVector.ConflictPolicy.CONFLICT_REPLACE, true)) { + try (StructVector vector = + new StructVector( + "struct", + allocator, + type, + null, + AbstractStructVector.ConflictPolicy.CONFLICT_REPLACE, + true)) { final List initFields = new ArrayList<>(); // Add a bit more fields to test against stability of the internal field @@ -301,7 +314,8 @@ public void testGetTransferPair() { try (final StructVector fromVector = simpleStructVector("s1", allocator)) { TransferPair tp = fromVector.getTransferPair(fromVector.getField(), allocator); final StructVector toVector = (StructVector) tp.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(toVector.getField(), fromVector.getField()); toVector.clear(); } @@ -313,7 +327,8 @@ public void testGetTransferPairWithFieldAndCallBack() { try (final StructVector fromVector = simpleStructVector("s1", allocator)) { TransferPair tp = fromVector.getTransferPair(fromVector.getField(), allocator, callBack); final StructVector toVector = (StructVector) tp.getTo(); - // Field inside a new vector created by reusing a field should be the same in memory as the original field. + // Field inside a new vector created by reusing a field should be the same in memory as the + // original field. assertSame(toVector.getField(), fromVector.getField()); toVector.clear(); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestTypeLayout.java b/java/vector/src/test/java/org/apache/arrow/vector/TestTypeLayout.java index 97930f433d3..0750b483d92 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestTypeLayout.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestTypeLayout.java @@ -32,67 +32,108 @@ public class TestTypeLayout { @Test public void testTypeBufferCount() { ArrowType type = new ArrowType.Int(8, true); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Union(UnionMode.Sparse, new int[2]); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Union(UnionMode.Dense, new int[1]); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Struct(); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Timestamp(TimeUnit.MILLISECOND, null); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.List(); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.FixedSizeList(5); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Map(false); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Decimal(10, 10, 128); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Decimal(10, 10, 256); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); - + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.FixedSizeBinary(5); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Bool(); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Binary(); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Utf8(); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Null(); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Date(DateUnit.DAY); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Time(TimeUnit.MILLISECOND, 32); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Interval(IntervalUnit.DAY_TIME); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); type = new ArrowType.Duration(TimeUnit.MILLISECOND); - assertEquals(TypeLayout.getTypeBufferCount(type), TypeLayout.getTypeLayout(type).getBufferLayouts().size()); + assertEquals( + TypeLayout.getTypeBufferCount(type), + TypeLayout.getTypeLayout(type).getBufferLayouts().size()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java index b53171a5976..dffb6a86fba 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.MapVector; @@ -71,7 +70,8 @@ public void testUnionVector() throws Exception { uInt4Holder.isSet = 1; try (UnionVector unionVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { unionVector.allocateNew(); // write some data @@ -99,7 +99,8 @@ public void testUnionVector() throws Exception { @Test public void testUnionVectorMapValue() throws Exception { try (UnionVector unionVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { unionVector.allocateNew(); UnionWriter writer = (UnionWriter) unionVector.getWriter(); @@ -161,7 +162,8 @@ public void testUnionVectorMapValue() throws Exception { @Test public void testTransfer() throws Exception { try (UnionVector srcVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { srcVector.allocateNew(); // write some data @@ -176,7 +178,8 @@ public void testTransfer() throws Exception { srcVector.setValueCount(6); try (UnionVector destVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { TransferPair pair = srcVector.makeTransferPair(destVector); // Creating the transfer should transfer the type of the field at least. @@ -212,7 +215,8 @@ public void testTransfer() throws Exception { @Test public void testSplitAndTransfer() throws Exception { try (UnionVector sourceVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { sourceVector.allocateNew(); @@ -263,17 +267,12 @@ public void testSplitAndTransfer() throws Exception { assertEquals(50, sourceVector.getObject(9)); try (UnionVector toVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { final TransferPair transferPair = sourceVector.makeTransferPair(toVector); - final int[][] transferLengths = {{0, 3}, - {3, 1}, - {4, 2}, - {6, 1}, - {7, 1}, - {8, 2} - }; + final int[][] transferLengths = {{0, 3}, {3, 1}, {4, 2}, {6, 1}, {7, 1}, {8, 2}}; for (final int[] transferLength : transferLengths) { final int start = transferLength[0]; @@ -283,7 +282,9 @@ public void testSplitAndTransfer() throws Exception { /* check the toVector output after doing the splitAndTransfer */ for (int i = 0; i < length; i++) { - assertEquals("Different data at indexes: " + (start + i) + "and " + i, sourceVector.getObject(start + i), + assertEquals( + "Different data at indexes: " + (start + i) + "and " + i, + sourceVector.getObject(start + i), toVector.getObject(i)); } } @@ -294,7 +295,8 @@ public void testSplitAndTransfer() throws Exception { @Test public void testSplitAndTransferWithMixedVectors() throws Exception { try (UnionVector sourceVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { sourceVector.allocateNew(); @@ -354,16 +356,12 @@ public void testSplitAndTransferWithMixedVectors() throws Exception { assertEquals(30.5f, sourceVector.getObject(9)); try (UnionVector toVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { final TransferPair transferPair = sourceVector.makeTransferPair(toVector); - final int[][] transferLengths = {{0, 2}, - {2, 1}, - {3, 2}, - {5, 3}, - {8, 2} - }; + final int[][] transferLengths = {{0, 2}, {2, 1}, {3, 2}, {5, 3}, {8, 2}}; for (final int[] transferLength : transferLengths) { final int start = transferLength[0]; @@ -373,7 +371,10 @@ public void testSplitAndTransferWithMixedVectors() throws Exception { /* check the toVector output after doing the splitAndTransfer */ for (int i = 0; i < length; i++) { - assertEquals("Different values at index: " + i, sourceVector.getObject(start + i), toVector.getObject(i)); + assertEquals( + "Different values at index: " + i, + sourceVector.getObject(start + i), + toVector.getObject(i)); } } } @@ -393,8 +394,12 @@ public void testGetFieldTypeInfo() throws Exception { children.add(new Field("int", FieldType.nullable(MinorType.INT.getType()), null)); children.add(new Field("varchar", FieldType.nullable(MinorType.VARCHAR.getType()), null)); - final FieldType fieldType = new FieldType(false, new ArrowType.Union(UnionMode.Sparse, typeIds), - /*dictionary=*/null, metadata); + final FieldType fieldType = + new FieldType( + false, + new ArrowType.Union(UnionMode.Sparse, typeIds), + /* dictionary= */ null, + metadata); final Field field = new Field("union", fieldType, children); MinorType minorType = MinorType.UNION; @@ -420,7 +425,8 @@ public void testGetFieldTypeInfo() throws Exception { @Test public void testGetBufferAddress() throws Exception { try (UnionVector vector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { boolean error = false; vector.allocateNew(); @@ -453,7 +459,6 @@ public void testGetBufferAddress() throws Exception { List buffers = vector.getFieldBuffers(); - try { long offsetAddress = vector.getOffsetBufferAddress(); } catch (UnsupportedOperationException ue) { @@ -478,7 +483,8 @@ public void testGetBufferAddress() throws Exception { @Test public void testSetGetNull() { try (UnionVector srcVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { srcVector.allocateNew(); final NullableIntHolder holder = new NullableIntHolder(); @@ -501,22 +507,30 @@ public void testSetGetNull() { @Test public void testCreateNewVectorWithoutTypeExceptionThrown() { try (UnionVector vector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { - IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, - () -> vector.getTimeStampMilliTZVector()); - assertEquals("No TimeStampMilliTZ present. Provide ArrowType argument to create a new vector", e1.getMessage()); - - IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, - () -> vector.getDurationVector()); - assertEquals("No Duration present. Provide ArrowType argument to create a new vector", e2.getMessage()); - - IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, - () -> vector.getFixedSizeBinaryVector()); - assertEquals("No FixedSizeBinary present. Provide ArrowType argument to create a new vector", e3.getMessage()); - - IllegalArgumentException e4 = assertThrows(IllegalArgumentException.class, - () -> vector.getDecimalVector()); - assertEquals("No Decimal present. Provide ArrowType argument to create a new vector", e4.getMessage()); + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + IllegalArgumentException e1 = + assertThrows(IllegalArgumentException.class, () -> vector.getTimeStampMilliTZVector()); + assertEquals( + "No TimeStampMilliTZ present. Provide ArrowType argument to create a new vector", + e1.getMessage()); + + IllegalArgumentException e2 = + assertThrows(IllegalArgumentException.class, () -> vector.getDurationVector()); + assertEquals( + "No Duration present. Provide ArrowType argument to create a new vector", + e2.getMessage()); + + IllegalArgumentException e3 = + assertThrows(IllegalArgumentException.class, () -> vector.getFixedSizeBinaryVector()); + assertEquals( + "No FixedSizeBinary present. Provide ArrowType argument to create a new vector", + e3.getMessage()); + + IllegalArgumentException e4 = + assertThrows(IllegalArgumentException.class, () -> vector.getDecimalVector()); + assertEquals( + "No Decimal present. Provide ArrowType argument to create a new vector", e4.getMessage()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestUtils.java b/java/vector/src/test/java/org/apache/arrow/vector/TestUtils.java index 7e64dd38646..d7cc59b4e23 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestUtils.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestUtils.java @@ -34,12 +34,13 @@ public static VarBinaryVector newVarBinaryVector(String name, BufferAllocator al FieldType.nullable(new ArrowType.Binary()).createNewSingleVector(name, allocator, null); } - public static T newVector(Class c, String name, ArrowType type, BufferAllocator allocator) { + public static T newVector( + Class c, String name, ArrowType type, BufferAllocator allocator) { return c.cast(FieldType.nullable(type).createNewSingleVector(name, allocator, null)); } - public static T newVector(Class c, String name, MinorType type, BufferAllocator allocator) { + public static T newVector( + Class c, String name, MinorType type, BufferAllocator allocator) { return c.cast(FieldType.nullable(type.getType()).createNewSingleVector(name, allocator, null)); } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java index fb968708044..94bf00f42ea 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java @@ -35,7 +35,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -196,10 +195,10 @@ public void testFixedType1() { @Test public void testNoOverFlowWithUINT() { try (final UInt8Vector uInt8Vector = new UInt8Vector("uint8", allocator); - final UInt4Vector uInt4Vector = new UInt4Vector("uint4", allocator); - final UInt1Vector uInt1Vector = new UInt1Vector("uint1", allocator)) { + final UInt4Vector uInt4Vector = new UInt4Vector("uint4", allocator); + final UInt1Vector uInt1Vector = new UInt1Vector("uint1", allocator)) { - long[] longValues = new long[]{Long.MIN_VALUE, Long.MAX_VALUE, -1L}; + long[] longValues = new long[] {Long.MIN_VALUE, Long.MAX_VALUE, -1L}; uInt8Vector.allocateNew(3); uInt8Vector.setValueCount(3); for (int i = 0; i < longValues.length; i++) { @@ -208,7 +207,7 @@ public void testNoOverFlowWithUINT() { assertEquals(readValue, longValues[i]); } - int[] intValues = new int[]{Integer.MIN_VALUE, Integer.MAX_VALUE, -1}; + int[] intValues = new int[] {Integer.MIN_VALUE, Integer.MAX_VALUE, -1}; uInt4Vector.allocateNew(3); uInt4Vector.setValueCount(3); for (int i = 0; i < intValues.length; i++) { @@ -217,7 +216,7 @@ public void testNoOverFlowWithUINT() { assertEquals(intValues[i], actualValue); } - byte[] byteValues = new byte[]{Byte.MIN_VALUE, Byte.MAX_VALUE, -1}; + byte[] byteValues = new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE, -1}; uInt1Vector.allocateNew(3); uInt1Vector.setValueCount(3); for (int i = 0; i < byteValues.length; i++) { @@ -535,8 +534,9 @@ public void testFixedType4() { public void testNullableFixedType1() { // Create a new value vector for 1024 integers. - try (final UInt4Vector vector = newVector(UInt4Vector.class, EMPTY_SCHEMA_PATH, new ArrowType.Int(32, false), - allocator);) { + try (final UInt4Vector vector = + newVector( + UInt4Vector.class, EMPTY_SCHEMA_PATH, new ArrowType.Int(32, false), allocator); ) { boolean error = false; int initialCapacity = 1024; @@ -635,7 +635,8 @@ public void testNullableFixedType1() { @Test /* Float4Vector */ public void testNullableFixedType2() { // Create a new value vector for 1024 integers - try (final Float4Vector vector = newVector(Float4Vector.class, EMPTY_SCHEMA_PATH, MinorType.FLOAT4, allocator);) { + try (final Float4Vector vector = + newVector(Float4Vector.class, EMPTY_SCHEMA_PATH, MinorType.FLOAT4, allocator); ) { boolean error = false; int initialCapacity = 16; @@ -734,7 +735,8 @@ public void testNullableFixedType2() { @Test /* IntVector */ public void testNullableFixedType3() { // Create a new value vector for 1024 integers - try (final IntVector vector = newVector(IntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, allocator)) { + try (final IntVector vector = + newVector(IntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, allocator)) { boolean error = false; int initialCapacity = 1024; @@ -825,7 +827,8 @@ public void testNullableFixedType3() { @Test /* IntVector */ public void testNullableFixedType4() { - try (final IntVector vector = newVector(IntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, allocator)) { + try (final IntVector vector = + newVector(IntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, allocator)) { /* no memory allocation has happened yet */ assertEquals(0, vector.getValueCapacity()); @@ -928,7 +931,8 @@ public void testNullableFixedType4() { */ /** - * ARROW-7831: this checks that a slice taken off a buffer is still readable after that buffer's allocator is closed. + * ARROW-7831: this checks that a slice taken off a buffer is still readable after that buffer's + * allocator is closed. */ @Test /* VarCharVector */ public void testSplitAndTransfer1() { @@ -946,11 +950,14 @@ public void testSplitAndTransfer1() { final int offsetRefCnt = sourceVector.getOffsetBuffer().refCnt(); final int dataRefCnt = sourceVector.getDataBuffer().refCnt(); - // split and transfer with slice starting at the beginning: this should not allocate anything new + // split and transfer with slice starting at the beginning: this should not allocate + // anything new sourceVector.splitAndTransferTo(0, 2, targetVector); assertEquals(allocatedMem, allocator.getAllocatedMemory()); - // The validity and offset buffers are sliced from a same buffer.See BaseFixedWidthVector#allocateBytes. - // Therefore, the refcnt of the validity buffer is increased once since the startIndex is 0. The refcnt of the + // The validity and offset buffers are sliced from a same buffer.See + // BaseFixedWidthVector#allocateBytes. + // Therefore, the refcnt of the validity buffer is increased once since the startIndex is 0. + // The refcnt of the // offset buffer is increased as well for the same reason. This amounts to a total of 2. assertEquals(validityRefCnt + 2, sourceVector.getValidityBuffer().refCnt()); assertEquals(offsetRefCnt + 2, sourceVector.getOffsetBuffer().refCnt()); @@ -962,7 +969,8 @@ public void testSplitAndTransfer1() { } /** - * ARROW-7831: this checks that a vector that got sliced is still readable after the slice's allocator got closed. + * ARROW-7831: this checks that a vector that got sliced is still readable after the slice's + * allocator got closed. */ @Test /* VarCharVector */ public void testSplitAndTransfer2() { @@ -980,11 +988,14 @@ public void testSplitAndTransfer2() { final int offsetRefCnt = sourceVector.getOffsetBuffer().refCnt(); final int dataRefCnt = sourceVector.getDataBuffer().refCnt(); - // split and transfer with slice starting at the beginning: this should not allocate anything new + // split and transfer with slice starting at the beginning: this should not allocate + // anything new sourceVector.splitAndTransferTo(0, 2, targetVector); assertEquals(allocatedMem, allocator.getAllocatedMemory()); - // The validity and offset buffers are sliced from a same buffer.See BaseFixedWidthVector#allocateBytes. - // Therefore, the refcnt of the validity buffer is increased once since the startIndex is 0. The refcnt of the + // The validity and offset buffers are sliced from a same buffer.See + // BaseFixedWidthVector#allocateBytes. + // Therefore, the refcnt of the validity buffer is increased once since the startIndex is 0. + // The refcnt of the // offset buffer is increased as well for the same reason. This amounts to a total of 2. assertEquals(validityRefCnt + 2, sourceVector.getValidityBuffer().refCnt()); assertEquals(offsetRefCnt + 2, sourceVector.getOffsetBuffer().refCnt()); @@ -997,13 +1008,13 @@ public void testSplitAndTransfer2() { } /** - * ARROW-7831: this checks an offset splitting optimization, in the case where all the values up to the start of the - * slice are null/empty, which avoids allocation for the offset buffer. + * ARROW-7831: this checks an offset splitting optimization, in the case where all the values up + * to the start of the slice are null/empty, which avoids allocation for the offset buffer. */ @Test /* VarCharVector */ public void testSplitAndTransfer3() { try (final VarCharVector targetVector = newVarCharVector("split-target", allocator); - final VarCharVector sourceVector = newVarCharVector(EMPTY_SCHEMA_PATH, allocator)) { + final VarCharVector sourceVector = newVarCharVector(EMPTY_SCHEMA_PATH, allocator)) { sourceVector.allocateNew(1024 * 10, 1024); sourceVector.set(0, new byte[0]); @@ -1019,14 +1030,17 @@ public void testSplitAndTransfer3() { final int dataRefCnt = sourceVector.getDataBuffer().refCnt(); sourceVector.splitAndTransferTo(2, 2, targetVector); - // because the offset starts at 0 since the first 2 values are empty/null, the allocation only consists in + // because the offset starts at 0 since the first 2 values are empty/null, the allocation only + // consists in // the size needed for the validity buffer final long validitySize = DefaultRoundingPolicy.DEFAULT_ROUNDING_POLICY.getRoundedSize( BaseValueVector.getValidityBufferSizeFromCount(2)); assertEquals(allocatedMem + validitySize, allocator.getAllocatedMemory()); - // The validity and offset buffers are sliced from a same buffer.See BaseFixedWidthVector#allocateBytes. - // Since values up to the startIndex are empty/null, the offset buffer doesn't need to be reallocated and + // The validity and offset buffers are sliced from a same buffer.See + // BaseFixedWidthVector#allocateBytes. + // Since values up to the startIndex are empty/null, the offset buffer doesn't need to be + // reallocated and // therefore its refcnt is increased by 1. assertEquals(validityRefCnt + 1, sourceVector.getValidityBuffer().refCnt()); assertEquals(offsetRefCnt + 1, sourceVector.getOffsetBuffer().refCnt()); @@ -1038,14 +1052,17 @@ public void testSplitAndTransfer3() { } /** - * ARROW-7831: ensures that data is transferred from one allocator to another in case of 0-index start special cases. + * ARROW-7831: ensures that data is transferred from one allocator to another in case of 0-index + * start special cases. */ @Test /* VarCharVector */ public void testSplitAndTransfer4() { - try (final BufferAllocator targetAllocator = allocator.newChildAllocator("target-alloc", 256, 256); - final VarCharVector targetVector = newVarCharVector("split-target", targetAllocator)) { - try (final BufferAllocator sourceAllocator = allocator.newChildAllocator("source-alloc", 256, 256); - final VarCharVector sourceVector = newVarCharVector(EMPTY_SCHEMA_PATH, sourceAllocator)) { + try (final BufferAllocator targetAllocator = + allocator.newChildAllocator("target-alloc", 256, 256); + final VarCharVector targetVector = newVarCharVector("split-target", targetAllocator)) { + try (final BufferAllocator sourceAllocator = + allocator.newChildAllocator("source-alloc", 256, 256); + final VarCharVector sourceVector = newVarCharVector(EMPTY_SCHEMA_PATH, sourceAllocator)) { sourceVector.allocateNew(50, 3); sourceVector.set(0, STR1); @@ -1058,10 +1075,12 @@ public void testSplitAndTransfer4() { final int offsetRefCnt = sourceVector.getOffsetBuffer().refCnt(); final int dataRefCnt = sourceVector.getDataBuffer().refCnt(); - // split and transfer with slice starting at the beginning: this should not allocate anything new + // split and transfer with slice starting at the beginning: this should not allocate + // anything new sourceVector.splitAndTransferTo(0, 2, targetVector); assertEquals(allocatedMem, allocator.getAllocatedMemory()); - // Unlike testSplitAndTransfer1 where the buffers originated from the same allocator, the refcnts of each + // Unlike testSplitAndTransfer1 where the buffers originated from the same allocator, the + // refcnts of each // buffers for this test should be the same as what the source allocator ended up with. assertEquals(validityRefCnt, sourceVector.getValidityBuffer().refCnt()); assertEquals(offsetRefCnt, sourceVector.getOffsetBuffer().refCnt()); @@ -1188,13 +1207,17 @@ public void testGetBytesRepeatedly() { // verify results ReusableByteArray reusableByteArray = new ReusableByteArray(); vector.read(0, reusableByteArray); - assertArrayEquals(str.getBytes(), Arrays.copyOfRange(reusableByteArray.getBuffer(), - 0, (int) reusableByteArray.getLength())); + assertArrayEquals( + str.getBytes(), + Arrays.copyOfRange( + reusableByteArray.getBuffer(), 0, (int) reusableByteArray.getLength())); byte[] oldBuffer = reusableByteArray.getBuffer(); vector.read(1, reusableByteArray); - assertArrayEquals(str2.getBytes(), Arrays.copyOfRange(reusableByteArray.getBuffer(), - 0, (int) reusableByteArray.getLength())); + assertArrayEquals( + str2.getBytes(), + Arrays.copyOfRange( + reusableByteArray.getBuffer(), 0, (int) reusableByteArray.getLength())); // There should not have been any reallocation since the newer value is smaller in length. assertSame(oldBuffer, reusableByteArray.getBuffer()); @@ -1579,7 +1602,8 @@ public void testReallocAfterVectorTransfer4() { @Test public void testReAllocFixedWidthVector() { // Create a new value vector for 1024 integers - try (final Float4Vector vector = newVector(Float4Vector.class, EMPTY_SCHEMA_PATH, MinorType.FLOAT4, allocator)) { + try (final Float4Vector vector = + newVector(Float4Vector.class, EMPTY_SCHEMA_PATH, MinorType.FLOAT4, allocator)) { vector.allocateNew(1024); assertTrue(vector.getValueCapacity() >= 1024); @@ -1601,8 +1625,10 @@ public void testReAllocFixedWidthVector() { assertEquals(104.5f, vector.get(1023), 0); assertEquals(105.5f, vector.get(2000), 0); - // Set the valueCount to be more than valueCapacity of current allocation. This is possible for ValueVectors - // as we don't call setSafe for null values, but we do call setValueCount when all values are inserted into the + // Set the valueCount to be more than valueCapacity of current allocation. This is possible + // for ValueVectors + // as we don't call setSafe for null values, but we do call setValueCount when all values are + // inserted into the // vector vector.setValueCount(vector.getValueCapacity() + 200); } @@ -1610,7 +1636,8 @@ public void testReAllocFixedWidthVector() { @Test public void testReAllocVariableWidthVector() { - try (final VarCharVector vector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { + try (final VarCharVector vector = + newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { vector.setInitialCapacity(4095); vector.allocateNew(); @@ -1634,15 +1661,18 @@ public void testReAllocVariableWidthVector() { assertArrayEquals(STR2, vector.get(initialCapacity - 1)); assertArrayEquals(STR3, vector.get(initialCapacity + 200)); - // Set the valueCount to be more than valueCapacity of current allocation. This is possible for ValueVectors - // as we don't call setSafe for null values, but we do call setValueCount when the current batch is processed. + // Set the valueCount to be more than valueCapacity of current allocation. This is possible + // for ValueVectors + // as we don't call setSafe for null values, but we do call setValueCount when the current + // batch is processed. vector.setValueCount(vector.getValueCapacity() + 200); } } @Test public void testFillEmptiesNotOverfill() { - try (final VarCharVector vector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { + try (final VarCharVector vector = + newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { vector.setInitialCapacity(4095); vector.allocateNew(); @@ -1667,11 +1697,10 @@ public void testSetSafeWithArrowBufNoExcessAllocs() { final int valueBytesLength = valueBytes.length; final int isSet = 1; - try ( - final VarCharVector fromVector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, - MinorType.VARCHAR, allocator); - final VarCharVector toVector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, - MinorType.VARCHAR, allocator)) { + try (final VarCharVector fromVector = + newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator); + final VarCharVector toVector = + newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { /* * Populate the from vector with 'numValues' with byte-arrays, each of size 'valueBytesLength'. */ @@ -1707,9 +1736,10 @@ public void testSetSafeWithArrowBufNoExcessAllocs() { @Test public void testCopyFromWithNulls() { - try (final VarCharVector vector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator); - final VarCharVector vector2 = - newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { + try (final VarCharVector vector = + newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator); + final VarCharVector vector2 = + newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { vector.setInitialCapacity(4095); vector.allocateNew(); @@ -1733,7 +1763,10 @@ public void testCopyFromWithNulls() { if (i % 3 == 0) { assertNull(vector.getObject(i)); } else { - assertEquals("unexpected value at index: " + i, Integer.toString(i), vector.getObject(i).toString()); + assertEquals( + "unexpected value at index: " + i, + Integer.toString(i), + vector.getObject(i).toString()); } } @@ -1747,7 +1780,10 @@ public void testCopyFromWithNulls() { if (i % 3 == 0) { assertNull(vector2.getObject(i)); } else { - assertEquals("unexpected value at index: " + i, Integer.toString(i), vector2.getObject(i).toString()); + assertEquals( + "unexpected value at index: " + i, + Integer.toString(i), + vector2.getObject(i).toString()); } } @@ -1760,7 +1796,10 @@ public void testCopyFromWithNulls() { if (i % 3 == 0) { assertNull(vector2.getObject(i)); } else { - assertEquals("unexpected value at index: " + i, Integer.toString(i), vector2.getObject(i).toString()); + assertEquals( + "unexpected value at index: " + i, + Integer.toString(i), + vector2.getObject(i).toString()); } } } @@ -1768,9 +1807,10 @@ public void testCopyFromWithNulls() { @Test public void testCopyFromWithNulls1() { - try (final VarCharVector vector = newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator); - final VarCharVector vector2 = - newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { + try (final VarCharVector vector = + newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator); + final VarCharVector vector2 = + newVector(VarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) { vector.setInitialCapacity(4095); vector.allocateNew(); @@ -1794,7 +1834,10 @@ public void testCopyFromWithNulls1() { if (i % 3 == 0) { assertNull(vector.getObject(i)); } else { - assertEquals("unexpected value at index: " + i, Integer.toString(i), vector.getObject(i).toString()); + assertEquals( + "unexpected value at index: " + i, + Integer.toString(i), + vector.getObject(i).toString()); } } @@ -1812,7 +1855,10 @@ public void testCopyFromWithNulls1() { if (i % 3 == 0) { assertNull(vector2.getObject(i)); } else { - assertEquals("unexpected value at index: " + i, Integer.toString(i), vector2.getObject(i).toString()); + assertEquals( + "unexpected value at index: " + i, + Integer.toString(i), + vector2.getObject(i).toString()); } } @@ -1825,7 +1871,10 @@ public void testCopyFromWithNulls1() { if (i % 3 == 0) { assertNull(vector2.getObject(i)); } else { - assertEquals("unexpected value at index: " + i, Integer.toString(i), vector2.getObject(i).toString()); + assertEquals( + "unexpected value at index: " + i, + Integer.toString(i), + vector2.getObject(i).toString()); } } } @@ -1909,7 +1958,7 @@ public void testSetLastSetUsage() { assertEquals(40, vector.offsetBuffer.getInt(17 * BaseVariableWidthVector.OFFSET_WIDTH)); assertEquals(40, vector.offsetBuffer.getInt(18 * BaseVariableWidthVector.OFFSET_WIDTH)); assertEquals(40, vector.offsetBuffer.getInt(19 * BaseVariableWidthVector.OFFSET_WIDTH)); - + vector.set(19, STR6); assertArrayEquals(STR6, vector.get(19)); assertEquals(40, vector.offsetBuffer.getInt(19 * BaseVariableWidthVector.OFFSET_WIDTH)); @@ -1947,14 +1996,14 @@ public void testVectorLoadUnload() { Schema schema = new Schema(fields); - VectorSchemaRoot schemaRoot1 = new VectorSchemaRoot(schema, fieldVectors, vector1.getValueCount()); + VectorSchemaRoot schemaRoot1 = + new VectorSchemaRoot(schema, fieldVectors, vector1.getValueCount()); VectorUnloader vectorUnloader = new VectorUnloader(schemaRoot1); - try ( - ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); - BufferAllocator finalVectorsAllocator = allocator.newChildAllocator("new vector", 0, Long.MAX_VALUE); - VectorSchemaRoot schemaRoot2 = VectorSchemaRoot.create(schema, finalVectorsAllocator); - ) { + try (ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); + BufferAllocator finalVectorsAllocator = + allocator.newChildAllocator("new vector", 0, Long.MAX_VALUE); + VectorSchemaRoot schemaRoot2 = VectorSchemaRoot.create(schema, finalVectorsAllocator); ) { VectorLoader vectorLoader = new VectorLoader(schemaRoot2); vectorLoader.load(recordBatch); @@ -2050,41 +2099,25 @@ public void testFillEmptiesUsage() { assertEquals(0, vector.getValueLength(14)); /* Check offsets */ - assertEquals(0, - vector.offsetBuffer.getInt(0 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(6, - vector.offsetBuffer.getInt(1 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(16, - vector.offsetBuffer.getInt(2 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(21, - vector.offsetBuffer.getInt(3 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(30, - vector.offsetBuffer.getInt(4 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(34, - vector.offsetBuffer.getInt(5 * BaseVariableWidthVector.OFFSET_WIDTH)); - - assertEquals(40, - vector.offsetBuffer.getInt(6 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(40, - vector.offsetBuffer.getInt(7 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(40, - vector.offsetBuffer.getInt(8 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(40, - vector.offsetBuffer.getInt(9 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(40, - vector.offsetBuffer.getInt(10 * BaseVariableWidthVector.OFFSET_WIDTH)); - - assertEquals(46, - vector.offsetBuffer.getInt(11 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(56, - vector.offsetBuffer.getInt(12 * BaseVariableWidthVector.OFFSET_WIDTH)); - - assertEquals(56, - vector.offsetBuffer.getInt(13 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(56, - vector.offsetBuffer.getInt(14 * BaseVariableWidthVector.OFFSET_WIDTH)); - assertEquals(56, - vector.offsetBuffer.getInt(15 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(0, vector.offsetBuffer.getInt(0 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(6, vector.offsetBuffer.getInt(1 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(16, vector.offsetBuffer.getInt(2 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(21, vector.offsetBuffer.getInt(3 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(30, vector.offsetBuffer.getInt(4 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(34, vector.offsetBuffer.getInt(5 * BaseVariableWidthVector.OFFSET_WIDTH)); + + assertEquals(40, vector.offsetBuffer.getInt(6 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(40, vector.offsetBuffer.getInt(7 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(40, vector.offsetBuffer.getInt(8 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(40, vector.offsetBuffer.getInt(9 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(40, vector.offsetBuffer.getInt(10 * BaseVariableWidthVector.OFFSET_WIDTH)); + + assertEquals(46, vector.offsetBuffer.getInt(11 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(56, vector.offsetBuffer.getInt(12 * BaseVariableWidthVector.OFFSET_WIDTH)); + + assertEquals(56, vector.offsetBuffer.getInt(13 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(56, vector.offsetBuffer.getInt(14 * BaseVariableWidthVector.OFFSET_WIDTH)); + assertEquals(56, vector.offsetBuffer.getInt(15 * BaseVariableWidthVector.OFFSET_WIDTH)); } } @@ -2152,8 +2185,10 @@ public void testGetBufferAddress2() { @Test public void testMultipleClose() { - BufferAllocator vectorAllocator = allocator.newChildAllocator("vector_allocator", 0, Long.MAX_VALUE); - IntVector vector = newVector(IntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, vectorAllocator); + BufferAllocator vectorAllocator = + allocator.newChildAllocator("vector_allocator", 0, Long.MAX_VALUE); + IntVector vector = + newVector(IntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, vectorAllocator); vector.close(); vectorAllocator.close(); vector.close(); @@ -2165,10 +2200,12 @@ public void testMultipleClose() { * in a way that lastSet is not set automatically. */ public static void setBytes(int index, byte[] bytes, VarCharVector vector) { - final int currentOffset = vector.offsetBuffer.getInt(index * BaseVariableWidthVector.OFFSET_WIDTH); + final int currentOffset = + vector.offsetBuffer.getInt(index * BaseVariableWidthVector.OFFSET_WIDTH); BitVectorHelper.setBit(vector.validityBuffer, index); - vector.offsetBuffer.setInt((index + 1) * BaseVariableWidthVector.OFFSET_WIDTH, currentOffset + bytes.length); + vector.offsetBuffer.setInt( + (index + 1) * BaseVariableWidthVector.OFFSET_WIDTH, currentOffset + bytes.length); vector.valueBuffer.setBytes(currentOffset, bytes, 0, bytes.length); } @@ -2181,7 +2218,8 @@ public void testSetInitialCapacity() { vector.setInitialCapacity(defaultCapacity); vector.allocateNew(); assertEquals(defaultCapacity, vector.getValueCapacity()); - assertEquals(CommonUtil.nextPowerOfTwo(defaultCapacity * 8), vector.getDataBuffer().capacity()); + assertEquals( + CommonUtil.nextPowerOfTwo(defaultCapacity * 8), vector.getDataBuffer().capacity()); vector.setInitialCapacity(defaultCapacity, 1); vector.allocateNew(); @@ -2191,12 +2229,16 @@ public void testSetInitialCapacity() { vector.setInitialCapacity(defaultCapacity, 0.1); vector.allocateNew(); assertEquals(defaultCapacity, vector.getValueCapacity()); - assertEquals(CommonUtil.nextPowerOfTwo((int) (defaultCapacity * 0.1)), vector.getDataBuffer().capacity()); + assertEquals( + CommonUtil.nextPowerOfTwo((int) (defaultCapacity * 0.1)), + vector.getDataBuffer().capacity()); vector.setInitialCapacity(defaultCapacity, 0.01); vector.allocateNew(); assertEquals(defaultCapacity, vector.getValueCapacity()); - assertEquals(CommonUtil.nextPowerOfTwo((int) (defaultCapacity * 0.01)), vector.getDataBuffer().capacity()); + assertEquals( + CommonUtil.nextPowerOfTwo((int) (defaultCapacity * 0.01)), + vector.getDataBuffer().capacity()); vector.setInitialCapacity(5, 0.01); vector.allocateNew(); @@ -2210,35 +2252,40 @@ public void testDefaultAllocNewAll() { int defaultCapacity = BaseValueVector.INITIAL_VALUE_ALLOCATION; int expectedSize; long beforeSize; - try (BufferAllocator childAllocator = allocator.newChildAllocator("defaultAllocs", 0, Long.MAX_VALUE); + try (BufferAllocator childAllocator = + allocator.newChildAllocator("defaultAllocs", 0, Long.MAX_VALUE); final IntVector intVector = new IntVector(EMPTY_SCHEMA_PATH, childAllocator); final BigIntVector bigIntVector = new BigIntVector(EMPTY_SCHEMA_PATH, childAllocator); final BitVector bitVector = new BitVector(EMPTY_SCHEMA_PATH, childAllocator); - final DecimalVector decimalVector = new DecimalVector(EMPTY_SCHEMA_PATH, childAllocator, 38, 6); + final DecimalVector decimalVector = + new DecimalVector(EMPTY_SCHEMA_PATH, childAllocator, 38, 6); final VarCharVector varCharVector = new VarCharVector(EMPTY_SCHEMA_PATH, childAllocator)) { // verify that the wastage is within bounds for IntVector. beforeSize = childAllocator.getAllocatedMemory(); intVector.allocateNew(); assertTrue(intVector.getValueCapacity() >= defaultCapacity); - expectedSize = (defaultCapacity * IntVector.TYPE_WIDTH) + - BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity); + expectedSize = + (defaultCapacity * IntVector.TYPE_WIDTH) + + BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity); assertTrue(childAllocator.getAllocatedMemory() - beforeSize <= expectedSize * 1.05); // verify that the wastage is within bounds for BigIntVector. beforeSize = childAllocator.getAllocatedMemory(); bigIntVector.allocateNew(); assertTrue(bigIntVector.getValueCapacity() >= defaultCapacity); - expectedSize = (defaultCapacity * bigIntVector.TYPE_WIDTH) + - BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity); + expectedSize = + (defaultCapacity * bigIntVector.TYPE_WIDTH) + + BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity); assertTrue(childAllocator.getAllocatedMemory() - beforeSize <= expectedSize * 1.05); // verify that the wastage is within bounds for DecimalVector. beforeSize = childAllocator.getAllocatedMemory(); decimalVector.allocateNew(); assertTrue(decimalVector.getValueCapacity() >= defaultCapacity); - expectedSize = (defaultCapacity * decimalVector.TYPE_WIDTH) + - BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity); + expectedSize = + (defaultCapacity * decimalVector.TYPE_WIDTH) + + BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity); assertTrue(childAllocator.getAllocatedMemory() - beforeSize <= expectedSize * 1.05); // verify that the wastage is within bounds for VarCharVector. @@ -2246,9 +2293,10 @@ public void testDefaultAllocNewAll() { beforeSize = childAllocator.getAllocatedMemory(); varCharVector.allocateNew(); assertTrue(varCharVector.getValueCapacity() >= defaultCapacity - 1); - expectedSize = (defaultCapacity * VarCharVector.OFFSET_WIDTH) + - BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity) + - defaultCapacity * 8; + expectedSize = + (defaultCapacity * VarCharVector.OFFSET_WIDTH) + + BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity) + + defaultCapacity * 8; // wastage should be less than 5%. assertTrue(childAllocator.getAllocatedMemory() - beforeSize <= expectedSize * 1.05); @@ -2258,7 +2306,6 @@ public void testDefaultAllocNewAll() { assertTrue(bitVector.getValueCapacity() >= defaultCapacity); expectedSize = BaseFixedWidthVector.getValidityBufferSizeFromCount(defaultCapacity) * 2; assertTrue(childAllocator.getAllocatedMemory() - beforeSize <= expectedSize * 1.05); - } } @@ -2386,7 +2433,7 @@ public void testSetNullableVarBinaryHolderSafe() { public void testGetPointerFixedWidth() { final int vectorLength = 100; try (IntVector vec1 = new IntVector("vec1", allocator); - IntVector vec2 = new IntVector("vec2", allocator)) { + IntVector vec2 = new IntVector("vec2", allocator)) { vec1.allocateNew(vectorLength); vec2.allocateNew(vectorLength); @@ -2420,11 +2467,11 @@ public void testGetPointerFixedWidth() { @Test public void testGetPointerVariableWidth() { - final String[] sampleData = new String[]{ - "abc", "123", "def", null, "hello", "aaaaa", "world", "2019", null, "0717"}; + final String[] sampleData = + new String[] {"abc", "123", "def", null, "hello", "aaaaa", "world", "2019", null, "0717"}; try (VarCharVector vec1 = new VarCharVector("vec1", allocator); - VarCharVector vec2 = new VarCharVector("vec2", allocator)) { + VarCharVector vec2 = new VarCharVector("vec2", allocator)) { vec1.allocateNew(sampleData.length * 10, sampleData.length); vec2.allocateNew(sampleData.length * 10, sampleData.length); @@ -2455,7 +2502,7 @@ public void testGetPointerVariableWidth() { @Test public void testGetNullFromVariableWidthVector() { try (final VarCharVector varCharVector = new VarCharVector("varcharvec", allocator); - final VarBinaryVector varBinaryVector = new VarBinaryVector("varbinary", allocator)) { + final VarBinaryVector varBinaryVector = new VarBinaryVector("varbinary", allocator)) { varCharVector.allocateNew(10, 1); varBinaryVector.allocateNew(10, 1); @@ -2515,7 +2562,7 @@ public void testBitVectorEquals() { @Test public void testIntVectorEqualsWithNull() { try (final IntVector vector1 = new IntVector("int", allocator); - final IntVector vector2 = new IntVector("int", allocator)) { + final IntVector vector2 = new IntVector("int", allocator)) { setVector(vector1, 1, 2); setVector(vector2, 1, null); @@ -2529,7 +2576,7 @@ public void testIntVectorEqualsWithNull() { @Test public void testIntVectorEquals() { try (final IntVector vector1 = new IntVector("int", allocator); - final IntVector vector2 = new IntVector("int", allocator)) { + final IntVector vector2 = new IntVector("int", allocator)) { setVector(vector1, 1, 2, 3); setVector(vector2, 1, 2, null); @@ -2550,8 +2597,8 @@ public void testIntVectorEquals() { @Test public void testDecimalVectorEquals() { try (final DecimalVector vector1 = new DecimalVector("decimal", allocator, 3, 3); - final DecimalVector vector2 = new DecimalVector("decimal", allocator, 3, 3); - final DecimalVector vector3 = new DecimalVector("decimal", allocator, 3, 2)) { + final DecimalVector vector2 = new DecimalVector("decimal", allocator, 3, 3); + final DecimalVector vector3 = new DecimalVector("decimal", allocator, 3, 2)) { setVector(vector1, 100L, 200L); setVector(vector2, 100L, 200L); @@ -2568,7 +2615,7 @@ public void testDecimalVectorEquals() { @Test public void testVarcharVectorEqualsWithNull() { try (final VarCharVector vector1 = new VarCharVector("varchar", allocator); - final VarCharVector vector2 = new VarCharVector("varchar", allocator)) { + final VarCharVector vector2 = new VarCharVector("varchar", allocator)) { setVector(vector1, STR1, STR2); setVector(vector2, STR1, null); @@ -2581,7 +2628,7 @@ public void testVarcharVectorEqualsWithNull() { @Test public void testVarcharVectorEquals() { try (final VarCharVector vector1 = new VarCharVector("varchar", allocator); - final VarCharVector vector2 = new VarCharVector("varchar", allocator)) { + final VarCharVector vector2 = new VarCharVector("varchar", allocator)) { setVector(vector1, STR1, STR2, STR3); setVector(vector2, STR1, STR2); @@ -2598,7 +2645,7 @@ public void testVarcharVectorEquals() { @Test public void testVarBinaryVectorEquals() { try (final VarBinaryVector vector1 = new VarBinaryVector("binary", allocator); - final VarBinaryVector vector2 = new VarBinaryVector("binary", allocator)) { + final VarBinaryVector vector2 = new VarBinaryVector("binary", allocator)) { setVector(vector1, STR1, STR2, STR3); setVector(vector2, STR1, STR2); @@ -2615,12 +2662,12 @@ public void testVarBinaryVectorEquals() { @Test public void testListVectorEqualsWithNull() { try (final ListVector vector1 = ListVector.empty("list", allocator); - final ListVector vector2 = ListVector.empty("list", allocator);) { + final ListVector vector2 = ListVector.empty("list", allocator); ) { UnionListWriter writer1 = vector1.getWriter(); writer1.allocate(); - //set some values + // set some values writeListVector(writer1, new int[] {1, 2}); writeListVector(writer1, new int[] {3, 4}); writeListVector(writer1, new int[] {}); @@ -2629,7 +2676,7 @@ public void testListVectorEqualsWithNull() { UnionListWriter writer2 = vector2.getWriter(); writer2.allocate(); - //set some values + // set some values writeListVector(writer2, new int[] {1, 2}); writeListVector(writer2, new int[] {3, 4}); writer2.setValueCount(3); @@ -2643,12 +2690,12 @@ public void testListVectorEqualsWithNull() { @Test public void testListVectorEquals() { try (final ListVector vector1 = ListVector.empty("list", allocator); - final ListVector vector2 = ListVector.empty("list", allocator);) { + final ListVector vector2 = ListVector.empty("list", allocator); ) { UnionListWriter writer1 = vector1.getWriter(); writer1.allocate(); - //set some values + // set some values writeListVector(writer1, new int[] {1, 2}); writeListVector(writer1, new int[] {3, 4}); writeListVector(writer1, new int[] {5, 6}); @@ -2657,7 +2704,7 @@ public void testListVectorEquals() { UnionListWriter writer2 = vector2.getWriter(); writer2.allocate(); - //set some values + // set some values writeListVector(writer2, new int[] {1, 2}); writeListVector(writer2, new int[] {3, 4}); writer2.setValueCount(2); @@ -2676,7 +2723,7 @@ public void testListVectorEquals() { public void testStructVectorEqualsWithNull() { try (final StructVector vector1 = StructVector.empty("struct", allocator); - final StructVector vector2 = StructVector.empty("struct", allocator);) { + final StructVector vector2 = StructVector.empty("struct", allocator); ) { vector1.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); vector1.addOrGet("f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); vector2.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); @@ -2705,7 +2752,7 @@ public void testStructVectorEqualsWithNull() { @Test public void testStructVectorEquals() { try (final StructVector vector1 = StructVector.empty("struct", allocator); - final StructVector vector2 = StructVector.empty("struct", allocator);) { + final StructVector vector2 = StructVector.empty("struct", allocator); ) { vector1.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); vector1.addOrGet("f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); vector2.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); @@ -2739,7 +2786,7 @@ public void testStructVectorEquals() { @Test public void testStructVectorEqualsWithDiffChild() { try (final StructVector vector1 = StructVector.empty("struct", allocator); - final StructVector vector2 = StructVector.empty("struct", allocator);) { + final StructVector vector2 = StructVector.empty("struct", allocator); ) { vector1.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); vector1.addOrGet("f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); vector2.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); @@ -2766,8 +2813,10 @@ public void testStructVectorEqualsWithDiffChild() { @Test public void testUnionVectorEquals() { - try (final UnionVector vector1 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); - final UnionVector vector2 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null);) { + try (final UnionVector vector1 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); + final UnionVector vector2 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); ) { final NullableUInt4Holder uInt4Holder = new NullableUInt4Holder(); uInt4Holder.value = 10; @@ -2799,7 +2848,7 @@ public void testUnionVectorEquals() { @Test(expected = IllegalArgumentException.class) public void testEqualsWithIndexOutOfRange() { try (final IntVector vector1 = new IntVector("int", allocator); - final IntVector vector2 = new IntVector("int", allocator)) { + final IntVector vector2 = new IntVector("int", allocator)) { setVector(vector1, 1, 2); setVector(vector2, 1, 2); @@ -2837,7 +2886,8 @@ public void testVariableWidthVectorNullHashCode() { @Test public void testUnionNullHashCode() { try (UnionVector srcVector = - new UnionVector(EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { + new UnionVector( + EMPTY_SCHEMA_PATH, allocator, /* field type */ null, /* call-back */ null)) { srcVector.allocateNew(); final NullableIntHolder holder = new NullableIntHolder(); @@ -2854,8 +2904,8 @@ public void testUnionNullHashCode() { @Test public void testToString() { try (final IntVector intVector = new IntVector("intVector", allocator); - final ListVector listVector = ListVector.empty("listVector", allocator); - final StructVector structVector = StructVector.empty("structVector", allocator)) { + final ListVector listVector = ListVector.empty("listVector", allocator); + final StructVector structVector = StructVector.empty("structVector", allocator)) { // validate intVector toString assertEquals("[]", intVector.toString()); @@ -2870,7 +2920,8 @@ public void testToString() { for (int i = 0; i < 100; i++) { intVector.setSafe(i, i); } - assertEquals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]", + assertEquals( + "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]", intVector.toString()); // validate listVector toString @@ -2894,7 +2945,8 @@ public void testToString() { // validate structVector toString structVector.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); - structVector.addOrGet("f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); + structVector.addOrGet( + "f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); NullableStructWriter structWriter = structVector.getWriter(); structWriter.allocate(); @@ -2970,7 +3022,7 @@ private void writeStructVector(NullableStructWriter writer, int value1, long val private void writeListVector(UnionListWriter writer, int[] values) { writer.startList(); - for (int v: values) { + for (int v : values) { writer.integer().writeInt(v); } writer.endList(); @@ -2979,7 +3031,7 @@ private void writeListVector(UnionListWriter writer, int[] values) { @Test public void testVariableVectorGetEndOffset() { try (final VarCharVector vector1 = new VarCharVector("v1", allocator); - final VarBinaryVector vector2 = new VarBinaryVector("v2", allocator)) { + final VarBinaryVector vector2 = new VarBinaryVector("v2", allocator)) { setVector(vector1, STR1, null, STR2); setVector(vector2, STR1, STR2, STR3); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVarCharListVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVarCharListVector.java index a9b155499f7..f4651cb0d7b 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVarCharListVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVarCharListVector.java @@ -45,9 +45,10 @@ public void terminate() throws Exception { @Test public void testVarCharListWithNulls() { byte[] bytes = "a".getBytes(); - try (ListVector vector = new ListVector("VarList", allocator, FieldType.nullable(Types - .MinorType.VARCHAR.getType()), null); - ArrowBuf tempBuf = allocator.buffer(bytes.length)) { + try (ListVector vector = + new ListVector( + "VarList", allocator, FieldType.nullable(Types.MinorType.VARCHAR.getType()), null); + ArrowBuf tempBuf = allocator.buffer(bytes.length)) { UnionListWriter writer = vector.getWriter(); writer.allocate(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorAlloc.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorAlloc.java index dfc75ec8e34..80ccb880fc9 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorAlloc.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorAlloc.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collections; - import org.apache.arrow.memory.AllocationListener; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -67,45 +66,47 @@ private static Field field(String name, ArrowType type) { @Test public void testVectorAllocWithField() { - Schema schema = new Schema(Arrays.asList( - field("TINYINT", MinorType.TINYINT.getType()), - field("SMALLINT", MinorType.SMALLINT.getType()), - field("INT", MinorType.INT.getType()), - field("BIGINT", MinorType.BIGINT.getType()), - field("UINT1", MinorType.UINT1.getType()), - field("UINT2", MinorType.UINT2.getType()), - field("UINT4", MinorType.UINT4.getType()), - field("UINT8", MinorType.UINT8.getType()), - field("FLOAT4", MinorType.FLOAT4.getType()), - field("FLOAT8", MinorType.FLOAT8.getType()), - field("UTF8", MinorType.VARCHAR.getType()), - field("VARBINARY", MinorType.VARBINARY.getType()), - field("BIT", MinorType.BIT.getType()), - field("DECIMAL", new Decimal(38, 5, 128)), - field("FIXEDSIZEBINARY", new FixedSizeBinary(50)), - field("DATEDAY", MinorType.DATEDAY.getType()), - field("DATEMILLI", MinorType.DATEMILLI.getType()), - field("TIMESEC", MinorType.TIMESEC.getType()), - field("TIMEMILLI", MinorType.TIMEMILLI.getType()), - field("TIMEMICRO", MinorType.TIMEMICRO.getType()), - field("TIMENANO", MinorType.TIMENANO.getType()), - field("TIMESTAMPSEC", MinorType.TIMESTAMPSEC.getType()), - field("TIMESTAMPMILLI", MinorType.TIMESTAMPMILLI.getType()), - field("TIMESTAMPMICRO", MinorType.TIMESTAMPMICRO.getType()), - field("TIMESTAMPNANO", MinorType.TIMESTAMPNANO.getType()), - field("TIMESTAMPSECTZ", new Timestamp(TimeUnit.SECOND, "PST")), - field("TIMESTAMPMILLITZ", new Timestamp(TimeUnit.MILLISECOND, "PST")), - field("TIMESTAMPMICROTZ", new Timestamp(TimeUnit.MICROSECOND, "PST")), - field("TIMESTAMPNANOTZ", new Timestamp(TimeUnit.NANOSECOND, "PST")), - field("INTERVALDAY", MinorType.INTERVALDAY.getType()), - field("INTERVALYEAR", MinorType.INTERVALYEAR.getType()), - field("DURATION", new Duration(TimeUnit.MILLISECOND)) - )); + Schema schema = + new Schema( + Arrays.asList( + field("TINYINT", MinorType.TINYINT.getType()), + field("SMALLINT", MinorType.SMALLINT.getType()), + field("INT", MinorType.INT.getType()), + field("BIGINT", MinorType.BIGINT.getType()), + field("UINT1", MinorType.UINT1.getType()), + field("UINT2", MinorType.UINT2.getType()), + field("UINT4", MinorType.UINT4.getType()), + field("UINT8", MinorType.UINT8.getType()), + field("FLOAT4", MinorType.FLOAT4.getType()), + field("FLOAT8", MinorType.FLOAT8.getType()), + field("UTF8", MinorType.VARCHAR.getType()), + field("VARBINARY", MinorType.VARBINARY.getType()), + field("BIT", MinorType.BIT.getType()), + field("DECIMAL", new Decimal(38, 5, 128)), + field("FIXEDSIZEBINARY", new FixedSizeBinary(50)), + field("DATEDAY", MinorType.DATEDAY.getType()), + field("DATEMILLI", MinorType.DATEMILLI.getType()), + field("TIMESEC", MinorType.TIMESEC.getType()), + field("TIMEMILLI", MinorType.TIMEMILLI.getType()), + field("TIMEMICRO", MinorType.TIMEMICRO.getType()), + field("TIMENANO", MinorType.TIMENANO.getType()), + field("TIMESTAMPSEC", MinorType.TIMESTAMPSEC.getType()), + field("TIMESTAMPMILLI", MinorType.TIMESTAMPMILLI.getType()), + field("TIMESTAMPMICRO", MinorType.TIMESTAMPMICRO.getType()), + field("TIMESTAMPNANO", MinorType.TIMESTAMPNANO.getType()), + field("TIMESTAMPSECTZ", new Timestamp(TimeUnit.SECOND, "PST")), + field("TIMESTAMPMILLITZ", new Timestamp(TimeUnit.MILLISECOND, "PST")), + field("TIMESTAMPMICROTZ", new Timestamp(TimeUnit.MICROSECOND, "PST")), + field("TIMESTAMPNANOTZ", new Timestamp(TimeUnit.NANOSECOND, "PST")), + field("INTERVALDAY", MinorType.INTERVALDAY.getType()), + field("INTERVALYEAR", MinorType.INTERVALYEAR.getType()), + field("DURATION", new Duration(TimeUnit.MILLISECOND)))); try (BufferAllocator allocator = rootAllocator.newChildAllocator("child", 0, Long.MAX_VALUE)) { for (Field field : schema.getFields()) { try (FieldVector vector = field.createVector(allocator)) { - assertEquals(vector.getMinorType(), + assertEquals( + vector.getMinorType(), Types.getMinorTypeForArrowType(field.getFieldType().getType())); vector.allocateNew(); } @@ -115,10 +116,7 @@ public void testVectorAllocWithField() { private static final int CUSTOM_SEGMENT_SIZE = 200; - /** - * A custom rounding policy that rounds the size to - * the next multiple of 200. - */ + /** A custom rounding policy that rounds the size to the next multiple of 200. */ private static class CustomPolicy implements RoundingPolicy { @Override @@ -150,7 +148,7 @@ public void testFixedWidthVectorAllocation() { @Test public void testVariableWidthVectorAllocation() { try (VarCharVector vec1 = new VarCharVector("vec", policyAllocator); - VarCharVector vec2 = new VarCharVector("vec", rootAllocator)) { + VarCharVector vec2 = new VarCharVector("vec", rootAllocator)) { assertTrue(vec1.getAllocator().getRoundingPolicy() instanceof CustomPolicy); vec1.allocateNew(50); long totalCapacity = vec1.getValidityBuffer().capacity() + vec1.getOffsetBuffer().capacity(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java index 7d5701ddb76..08059be3cd8 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java @@ -20,7 +20,6 @@ import static org.junit.Assert.*; import java.nio.charset.StandardCharsets; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.complex.DenseUnionVector; @@ -42,7 +41,6 @@ import org.junit.Before; import org.junit.Test; - public class TestVectorReAlloc { private BufferAllocator allocator; @@ -254,10 +252,14 @@ public void testVarCharAllocateNew() throws Exception { try (final VarCharVector vector = new VarCharVector("", allocator)) { vector.allocateNew(count); - - // verify that the validity buffer and value buffer have capacity for at least 'count' elements. - Assert.assertTrue(vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count)); - Assert.assertTrue(vector.getOffsetBuffer().capacity() >= (count + 1) * BaseVariableWidthVector.OFFSET_WIDTH); + + // verify that the validity buffer and value buffer have capacity for at least 'count' + // elements. + Assert.assertTrue( + vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count)); + Assert.assertTrue( + vector.getOffsetBuffer().capacity() + >= (count + 1) * BaseVariableWidthVector.OFFSET_WIDTH); } } @@ -267,10 +269,14 @@ public void testLargeVarCharAllocateNew() throws Exception { try (final LargeVarCharVector vector = new LargeVarCharVector("", allocator)) { vector.allocateNew(count); - - // verify that the validity buffer and value buffer have capacity for at least 'count' elements. - Assert.assertTrue(vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count)); - Assert.assertTrue(vector.getOffsetBuffer().capacity() >= (count + 1) * BaseLargeVariableWidthVector.OFFSET_WIDTH); + + // verify that the validity buffer and value buffer have capacity for at least 'count' + // elements. + Assert.assertTrue( + vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count)); + Assert.assertTrue( + vector.getOffsetBuffer().capacity() + >= (count + 1) * BaseLargeVariableWidthVector.OFFSET_WIDTH); } } @@ -281,9 +287,13 @@ public void testVarCharAllocateNewUsingHelper() throws Exception { try (final VarCharVector vector = new VarCharVector("", allocator)) { AllocationHelper.allocateNew(vector, count); - // verify that the validity buffer and value buffer have capacity for at least 'count' elements. - Assert.assertTrue(vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count)); - Assert.assertTrue(vector.getOffsetBuffer().capacity() >= (count + 1) * BaseVariableWidthVector.OFFSET_WIDTH); + // verify that the validity buffer and value buffer have capacity for at least 'count' + // elements. + Assert.assertTrue( + vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count)); + Assert.assertTrue( + vector.getOffsetBuffer().capacity() + >= (count + 1) * BaseVariableWidthVector.OFFSET_WIDTH); } } @@ -294,9 +304,13 @@ public void testLargeVarCharAllocateNewUsingHelper() throws Exception { try (final LargeVarCharVector vector = new LargeVarCharVector("", allocator)) { AllocationHelper.allocateNew(vector, count); - // verify that the validity buffer and value buffer have capacity for at least 'count' elements. - Assert.assertTrue(vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count)); - Assert.assertTrue(vector.getOffsetBuffer().capacity() >= (count + 1) * BaseLargeVariableWidthVector.OFFSET_WIDTH); + // verify that the validity buffer and value buffer have capacity for at least 'count' + // elements. + Assert.assertTrue( + vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count)); + Assert.assertTrue( + vector.getOffsetBuffer().capacity() + >= (count + 1) * BaseLargeVariableWidthVector.OFFSET_WIDTH); } } @@ -339,7 +353,8 @@ public void testVariableRepeatedClearAndSet() throws Exception { @Test public void testRepeatedValueVectorClearAndSet() throws Exception { - try (final ListVector vector = new ListVector("", allocator, FieldType.nullable(MinorType.INT.getType()), null)) { + try (final ListVector vector = + new ListVector("", allocator, FieldType.nullable(MinorType.INT.getType()), null)) { vector.allocateNewSafe(); // Initial allocation UnionListWriter writer = vector.getWriter(); @@ -392,8 +407,9 @@ public void testStructVectorClearAndSet() throws Exception { @Test public void testFixedSizeListVectorClearAndSet() { - try (final FixedSizeListVector vector = new FixedSizeListVector("", allocator, - FieldType.nullable(new ArrowType.FixedSizeList(2)), null)) { + try (final FixedSizeListVector vector = + new FixedSizeListVector( + "", allocator, FieldType.nullable(new ArrowType.FixedSizeList(2)), null)) { vector.allocateNewSafe(); // Initial allocation UnionFixedSizeListWriter writer = vector.getWriter(); @@ -421,7 +437,8 @@ public void testFixedSizeListVectorClearAndSet() { @Test public void testUnionVectorClearAndSet() { - try (final UnionVector vector = new UnionVector("", allocator, /* field type */ null, /* call-back */ null)) { + try (final UnionVector vector = + new UnionVector("", allocator, /* field type */ null, /* call-back */ null)) { vector.allocateNewSafe(); // Initial allocation NullableIntHolder holder = new NullableIntHolder(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReset.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReset.java index 71009a33375..4b8afa1cba9 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReset.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReset.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertTrue; import java.nio.charset.StandardCharsets; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -108,10 +107,11 @@ public void testLargeVariableTypeReset() { @Test public void testListTypeReset() { try (final ListVector variableList = - new ListVector("VarList", allocator, FieldType.nullable(MinorType.INT.getType()), null); - final FixedSizeListVector fixedList = - new FixedSizeListVector("FixedList", allocator, FieldType.nullable(new FixedSizeList(2)), null) - ) { + new ListVector( + "VarList", allocator, FieldType.nullable(MinorType.INT.getType()), null); + final FixedSizeListVector fixedList = + new FixedSizeListVector( + "FixedList", allocator, FieldType.nullable(new FixedSizeList(2)), null)) { // ListVector variableList.allocateNewSafe(); variableList.startNewValue(0); @@ -131,14 +131,16 @@ public void testListTypeReset() { @Test public void testStructTypeReset() { try (final NonNullableStructVector nonNullableStructVector = - new NonNullableStructVector("Struct", allocator, FieldType.nullable(MinorType.INT.getType()), null); - final StructVector structVector = - new StructVector("NullableStruct", allocator, FieldType.nullable(MinorType.INT.getType()), null) - ) { + new NonNullableStructVector( + "Struct", allocator, FieldType.nullable(MinorType.INT.getType()), null); + final StructVector structVector = + new StructVector( + "NullableStruct", allocator, FieldType.nullable(MinorType.INT.getType()), null)) { // NonNullableStructVector nonNullableStructVector.allocateNewSafe(); - IntVector structChild = nonNullableStructVector - .addOrGet("child", FieldType.nullable(new Int(32, true)), IntVector.class); + IntVector structChild = + nonNullableStructVector.addOrGet( + "child", FieldType.nullable(new Int(32, true)), IntVector.class); structChild.setNull(0); nonNullableStructVector.setValueCount(1); resetVectorAndVerify(nonNullableStructVector, nonNullableStructVector.getBuffers(false)); @@ -153,9 +155,9 @@ public void testStructTypeReset() { @Test public void testUnionTypeReset() { - try (final UnionVector vector = new UnionVector("Union", allocator, /* field type */ null, /* call-back */ null); - final IntVector dataVector = new IntVector("Int", allocator) - ) { + try (final UnionVector vector = + new UnionVector("Union", allocator, /* field type */ null, /* call-back */ null); + final IntVector dataVector = new IntVector("Int", allocator)) { vector.getBufferSize(); vector.allocateNewSafe(); dataVector.allocateNewSafe(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java index ce3fb2cdf0e..8bbe8d12fcb 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.complex.ListVector; @@ -57,7 +56,7 @@ public void terminate() { public void testResetRowCount() { final int size = 20; try (final BitVector vec1 = new BitVector("bit", allocator); - final IntVector vec2 = new IntVector("int", allocator)) { + final IntVector vec2 = new IntVector("int", allocator)) { VectorSchemaRoot vsr = VectorSchemaRoot.of(vec1, vec2); vsr.allocateNew(); @@ -92,8 +91,8 @@ private void checkCount(BitVector vec1, IntVector vec2, VectorSchemaRoot vsr, in } private VectorSchemaRoot createBatch() { - FieldType varCharType = new FieldType(true, new ArrowType.Utf8(), /*dictionary=*/null); - FieldType listType = new FieldType(true, new ArrowType.List(), /*dictionary=*/null); + FieldType varCharType = new FieldType(true, new ArrowType.Utf8(), /* dictionary= */ null); + FieldType listType = new FieldType(true, new ArrowType.List(), /* dictionary= */ null); // create the schema List schemaFields = new ArrayList<>(); @@ -157,8 +156,8 @@ private VectorSchemaRoot createBatch() { @Test public void testAddVector() { try (final IntVector intVector1 = new IntVector("intVector1", allocator); - final IntVector intVector2 = new IntVector("intVector2", allocator); - final IntVector intVector3 = new IntVector("intVector3", allocator);) { + final IntVector intVector2 = new IntVector("intVector2", allocator); + final IntVector intVector3 = new IntVector("intVector3", allocator); ) { VectorSchemaRoot original = new VectorSchemaRoot(Arrays.asList(intVector1, intVector2)); assertEquals(2, original.getFieldVectors().size()); @@ -176,7 +175,7 @@ public void testAddVector() { public void testRemoveVector() { try (final IntVector intVector1 = new IntVector("intVector1", allocator); final IntVector intVector2 = new IntVector("intVector2", allocator); - final IntVector intVector3 = new IntVector("intVector3", allocator);) { + final IntVector intVector3 = new IntVector("intVector3", allocator); ) { VectorSchemaRoot original = new VectorSchemaRoot(Arrays.asList(intVector1, intVector2, intVector3)); @@ -195,7 +194,7 @@ public void testRemoveVector() { @Test public void testSlice() { try (final IntVector intVector = new IntVector("intVector", allocator); - final Float4Vector float4Vector = new Float4Vector("float4Vector", allocator)) { + final Float4Vector float4Vector = new Float4Vector("float4Vector", allocator)) { final int numRows = 10; intVector.setValueCount(numRows); float4Vector.setValueCount(numRows); @@ -204,7 +203,8 @@ public void testSlice() { float4Vector.setSafe(i, i + 0.1f); } - final VectorSchemaRoot original = new VectorSchemaRoot(Arrays.asList(intVector, float4Vector)); + final VectorSchemaRoot original = + new VectorSchemaRoot(Arrays.asList(intVector, float4Vector)); for (int sliceIndex = 0; sliceIndex < numRows; sliceIndex++) { for (int sliceLength = 0; sliceIndex + sliceLength <= numRows; sliceLength++) { @@ -229,14 +229,15 @@ public void testSlice() { @Test(expected = IllegalArgumentException.class) public void testSliceWithInvalidParam() { try (final IntVector intVector = new IntVector("intVector", allocator); - final Float4Vector float4Vector = new Float4Vector("float4Vector", allocator)) { + final Float4Vector float4Vector = new Float4Vector("float4Vector", allocator)) { intVector.setValueCount(10); float4Vector.setValueCount(10); for (int i = 0; i < 10; i++) { intVector.setSafe(i, i); float4Vector.setSafe(i, i + 0.1f); } - final VectorSchemaRoot original = new VectorSchemaRoot(Arrays.asList(intVector, float4Vector)); + final VectorSchemaRoot original = + new VectorSchemaRoot(Arrays.asList(intVector, float4Vector)); original.slice(0, 20); } @@ -245,8 +246,8 @@ public void testSliceWithInvalidParam() { @Test public void testEquals() { try (final IntVector intVector1 = new IntVector("intVector1", allocator); - final IntVector intVector2 = new IntVector("intVector2", allocator); - final IntVector intVector3 = new IntVector("intVector3", allocator);) { + final IntVector intVector2 = new IntVector("intVector2", allocator); + final IntVector intVector3 = new IntVector("intVector3", allocator); ) { intVector1.setValueCount(5); for (int i = 0; i < 5; i++) { @@ -256,8 +257,7 @@ public void testEquals() { VectorSchemaRoot root1 = new VectorSchemaRoot(Arrays.asList(intVector1, intVector2, intVector3)); - VectorSchemaRoot root2 = - new VectorSchemaRoot(Arrays.asList(intVector1, intVector2)); + VectorSchemaRoot root2 = new VectorSchemaRoot(Arrays.asList(intVector1, intVector2)); VectorSchemaRoot root3 = new VectorSchemaRoot(Arrays.asList(intVector1, intVector2, intVector3)); @@ -274,8 +274,8 @@ public void testEquals() { @Test public void testApproxEquals() { try (final Float4Vector float4Vector1 = new Float4Vector("floatVector", allocator); - final Float4Vector float4Vector2 = new Float4Vector("floatVector", allocator); - final Float4Vector float4Vector3 = new Float4Vector("floatVector", allocator);) { + final Float4Vector float4Vector2 = new Float4Vector("floatVector", allocator); + final Float4Vector float4Vector3 = new Float4Vector("floatVector", allocator); ) { float4Vector1.setValueCount(5); float4Vector2.setValueCount(5); @@ -287,14 +287,11 @@ public void testApproxEquals() { float4Vector3.set(i, i + epsilon / 2); } - VectorSchemaRoot root1 = - new VectorSchemaRoot(Arrays.asList(float4Vector1)); + VectorSchemaRoot root1 = new VectorSchemaRoot(Arrays.asList(float4Vector1)); - VectorSchemaRoot root2 = - new VectorSchemaRoot(Arrays.asList(float4Vector2)); + VectorSchemaRoot root2 = new VectorSchemaRoot(Arrays.asList(float4Vector2)); - VectorSchemaRoot root3 = - new VectorSchemaRoot(Arrays.asList(float4Vector3)); + VectorSchemaRoot root3 = new VectorSchemaRoot(Arrays.asList(float4Vector3)); assertFalse(root1.approxEquals(root2)); assertTrue(root1.approxEquals(root3)); @@ -307,10 +304,13 @@ public void testApproxEquals() { @Test public void testSchemaSync() { - //create vector schema root + // create vector schema root try (VectorSchemaRoot schemaRoot = createBatch()) { - Schema newSchema = new Schema( - schemaRoot.getFieldVectors().stream().map(vec -> vec.getField()).collect(Collectors.toList())); + Schema newSchema = + new Schema( + schemaRoot.getFieldVectors().stream() + .map(vec -> vec.getField()) + .collect(Collectors.toList())); assertNotEquals(newSchema, schemaRoot.getSchema()); assertTrue(schemaRoot.syncSchema()); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java index eac72f4b2c8..829afa7fc12 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -68,8 +67,8 @@ public void testNullCodec() { final Schema schema = new Schema(Collections.emptyList()); try (final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { root.setRowCount(1); - final VectorUnloader unloader = new VectorUnloader( - root, /*includeNulls*/ true, /*codec*/ null, /*alignBuffers*/ true); + final VectorUnloader unloader = + new VectorUnloader(root, /*includeNulls*/ true, /*codec*/ null, /*alignBuffers*/ true); unloader.getRecordBatch().close(); } } @@ -79,10 +78,10 @@ public void testUnloadLoad() throws IOException { int count = 10000; Schema schema; - try ( - BufferAllocator originalVectorsAllocator = + try (BufferAllocator originalVectorsAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); - NonNullableStructVector parent = NonNullableStructVector.empty("parent", originalVectorsAllocator)) { + NonNullableStructVector parent = + NonNullableStructVector.empty("parent", originalVectorsAllocator)) { // write some data ComplexWriter writer = new ComplexWriterImpl("root", parent); @@ -101,11 +100,10 @@ public void testUnloadLoad() throws IOException { FieldVector root = parent.getChild("root"); schema = new Schema(root.getField().getChildren()); VectorUnloader vectorUnloader = newVectorUnloader(root); - try ( - ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); - BufferAllocator finalVectorsAllocator = allocator.newChildAllocator("final vectors", 0, Integer.MAX_VALUE); - VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator); - ) { + try (ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); + BufferAllocator finalVectorsAllocator = + allocator.newChildAllocator("final vectors", 0, Integer.MAX_VALUE); + VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator); ) { // load it VectorLoader vectorLoader = new VectorLoader(newRoot); @@ -128,10 +126,10 @@ public void testUnloadLoad() throws IOException { public void testUnloadLoadAddPadding() throws IOException { int count = 10000; Schema schema; - try ( - BufferAllocator originalVectorsAllocator = + try (BufferAllocator originalVectorsAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); - NonNullableStructVector parent = NonNullableStructVector.empty("parent", originalVectorsAllocator)) { + NonNullableStructVector parent = + NonNullableStructVector.empty("parent", originalVectorsAllocator)) { // write some data ComplexWriter writer = new ComplexWriterImpl("root", parent); @@ -152,11 +150,10 @@ public void testUnloadLoadAddPadding() throws IOException { FieldVector root = parent.getChild("root"); schema = new Schema(root.getField().getChildren()); VectorUnloader vectorUnloader = newVectorUnloader(root); - try ( - ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); - BufferAllocator finalVectorsAllocator = allocator.newChildAllocator("final vectors", 0, Integer.MAX_VALUE); - VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator); - ) { + try (ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); + BufferAllocator finalVectorsAllocator = + allocator.newChildAllocator("final vectors", 0, Integer.MAX_VALUE); + VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator); ) { List oldBuffers = recordBatch.getBuffers(); List newBuffers = new ArrayList<>(); for (ArrowBuf oldBuffer : oldBuffers) { @@ -175,7 +172,7 @@ public void testUnloadLoadAddPadding() throws IOException { } try (ArrowRecordBatch newBatch = - new ArrowRecordBatch(recordBatch.getLength(), recordBatch.getNodes(), newBuffers);) { + new ArrowRecordBatch(recordBatch.getLength(), recordBatch.getNodes(), newBuffers); ) { // load it VectorLoader vectorLoader = new VectorLoader(newRoot); @@ -200,18 +197,23 @@ public void testUnloadLoadAddPadding() throws IOException { } /** - * The validity buffer can be empty if: - * - all values are defined. - * - all values are null. + * The validity buffer can be empty if: - all values are defined. - all values are null. * * @throws IOException on error */ @Test public void testLoadValidityBuffer() throws IOException { - Schema schema = new Schema(asList( - new Field("intDefined", FieldType.nullable(new ArrowType.Int(32, true)), Collections.emptyList()), - new Field("intNull", FieldType.nullable(new ArrowType.Int(32, true)), Collections.emptyList()) - )); + Schema schema = + new Schema( + asList( + new Field( + "intDefined", + FieldType.nullable(new ArrowType.Int(32, true)), + Collections.emptyList()), + new Field( + "intNull", + FieldType.nullable(new ArrowType.Int(32, true)), + Collections.emptyList()))); int count = 10; ArrowBuf[] values = new ArrowBuf[4]; for (int i = 0; i < 4; i += 2) { @@ -241,12 +243,14 @@ public void testLoadValidityBuffer() throws IOException { * values[3] - data buffer for second vector */ - try ( - ArrowRecordBatch recordBatch = new ArrowRecordBatch(count, asList(new ArrowFieldNode(count, 0), - new ArrowFieldNode(count, count)), asList(values[0], values[1], values[2], values[3])); - BufferAllocator finalVectorsAllocator = allocator.newChildAllocator("final vectors", 0, Integer.MAX_VALUE); - VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator); - ) { + try (ArrowRecordBatch recordBatch = + new ArrowRecordBatch( + count, + asList(new ArrowFieldNode(count, 0), new ArrowFieldNode(count, count)), + asList(values[0], values[1], values[2], values[3])); + BufferAllocator finalVectorsAllocator = + allocator.newChildAllocator("final vectors", 0, Integer.MAX_VALUE); + VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator); ) { // load it VectorLoader vectorLoader = new VectorLoader(newRoot); @@ -287,15 +291,20 @@ public void testLoadValidityBuffer() throws IOException { @Test public void testUnloadLoadDuplicates() throws IOException { int count = 10; - Schema schema = new Schema(asList( - new Field("duplicate", FieldType.nullable(new ArrowType.Int(32, true)), Collections.emptyList()), - new Field("duplicate", FieldType.nullable(new ArrowType.Int(32, true)), Collections.emptyList()) - )); - - try ( - BufferAllocator originalVectorsAllocator = - allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); - ) { + Schema schema = + new Schema( + asList( + new Field( + "duplicate", + FieldType.nullable(new ArrowType.Int(32, true)), + Collections.emptyList()), + new Field( + "duplicate", + FieldType.nullable(new ArrowType.Int(32, true)), + Collections.emptyList()))); + + try (BufferAllocator originalVectorsAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); ) { List sources = new ArrayList<>(); for (Field field : schema.getFields()) { FieldVector vector = field.createVector(originalVectorsAllocator); @@ -311,9 +320,9 @@ public void testUnloadLoadDuplicates() throws IOException { try (VectorSchemaRoot root = new VectorSchemaRoot(schema.getFields(), sources, count)) { VectorUnloader vectorUnloader = new VectorUnloader(root); try (ArrowRecordBatch recordBatch = vectorUnloader.getRecordBatch(); - BufferAllocator finalVectorsAllocator = + BufferAllocator finalVectorsAllocator = allocator.newChildAllocator("final vectors", 0, Integer.MAX_VALUE); - VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator);) { + VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator); ) { // load it VectorLoader vectorLoader = new VectorLoader(newRoot); vectorLoader.load(recordBatch); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/compare/TestRangeEqualsVisitor.java b/java/vector/src/test/java/org/apache/arrow/vector/compare/TestRangeEqualsVisitor.java index ab8c6c63489..57b2647e964 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/compare/TestRangeEqualsVisitor.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/compare/TestRangeEqualsVisitor.java @@ -23,7 +23,6 @@ import java.nio.charset.Charset; import java.util.Arrays; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BigIntVector; @@ -80,7 +79,7 @@ public void terminate() throws Exception { @Test public void testIntVectorEqualsWithNull() { try (final IntVector vector1 = new IntVector("int", allocator); - final IntVector vector2 = new IntVector("int", allocator)) { + final IntVector vector2 = new IntVector("int", allocator)) { setVector(vector1, 1, 2); setVector(vector2, 1, null); @@ -92,8 +91,8 @@ public void testIntVectorEqualsWithNull() { @Test public void testEqualsWithTypeChange() { try (final IntVector vector1 = new IntVector("vector", allocator); - final IntVector vector2 = new IntVector("vector", allocator); - final BigIntVector vector3 = new BigIntVector("vector", allocator)) { + final IntVector vector2 = new IntVector("vector", allocator); + final BigIntVector vector3 = new BigIntVector("vector", allocator)) { setVector(vector1, 1, 2); setVector(vector2, 1, 2); @@ -109,7 +108,7 @@ public void testEqualsWithTypeChange() { @Test public void testBaseFixedWidthVectorRangeEqual() { try (final IntVector vector1 = new IntVector("int", allocator); - final IntVector vector2 = new IntVector("int", allocator)) { + final IntVector vector2 = new IntVector("int", allocator)) { setVector(vector1, 1, 2, 3, 4, 5); setVector(vector2, 11, 2, 3, 4, 55); @@ -122,7 +121,7 @@ public void testBaseFixedWidthVectorRangeEqual() { @Test public void testBaseVariableVectorRangeEquals() { try (final VarCharVector vector1 = new VarCharVector("varchar", allocator); - final VarCharVector vector2 = new VarCharVector("varchar", allocator)) { + final VarCharVector vector2 = new VarCharVector("varchar", allocator)) { setVector(vector1, STR1, STR2, STR3, STR2, STR1); setVector(vector2, STR1, STR2, STR3, STR2, STR1); @@ -135,7 +134,7 @@ public void testBaseVariableVectorRangeEquals() { @Test public void testListVectorWithDifferentChild() { try (final ListVector vector1 = ListVector.empty("list", allocator); - final ListVector vector2 = ListVector.empty("list", allocator);) { + final ListVector vector2 = ListVector.empty("list", allocator); ) { vector1.allocateNew(); vector1.initializeChildrenFromFields( @@ -153,12 +152,12 @@ public void testListVectorWithDifferentChild() { @Test public void testListVectorRangeEquals() { try (final ListVector vector1 = ListVector.empty("list", allocator); - final ListVector vector2 = ListVector.empty("list", allocator);) { + final ListVector vector2 = ListVector.empty("list", allocator); ) { UnionListWriter writer1 = vector1.getWriter(); writer1.allocate(); - //set some values + // set some values writeListVector(writer1, new int[] {1, 2}); writeListVector(writer1, new int[] {3, 4}); writeListVector(writer1, new int[] {5, 6}); @@ -169,7 +168,7 @@ public void testListVectorRangeEquals() { UnionListWriter writer2 = vector2.getWriter(); writer2.allocate(); - //set some values + // set some values writeListVector(writer2, new int[] {0, 0}); writeListVector(writer2, new int[] {3, 4}); writeListVector(writer2, new int[] {5, 6}); @@ -185,16 +184,16 @@ public void testListVectorRangeEquals() { @Test public void testBitVectorRangeEquals() { try (final BitVector vector1 = new BitVector("v1", allocator); - final BitVector vector2 = new BitVector("v2", allocator);) { + final BitVector vector2 = new BitVector("v2", allocator); ) { - boolean[] v1 = new boolean[]{true, false, true, true, true}; - boolean[] v2 = new boolean[]{false, true, true, true, false}; + boolean[] v1 = new boolean[] {true, false, true, true, true}; + boolean[] v2 = new boolean[] {false, true, true, true, false}; vector1.setValueCount(5); - for (int i = 0; i < 5; i ++) { + for (int i = 0; i < 5; i++) { vector1.set(i, v1[i] ? 1 : 0); } vector2.setValueCount(5); - for (int i = 0; i < 5; i ++) { + for (int i = 0; i < 5; i++) { vector2.set(i, v2[i] ? 1 : 0); } @@ -207,12 +206,12 @@ public void testBitVectorRangeEquals() { @Test public void testFixedSizeListVectorRangeEquals() { try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("list", 2, allocator); - final FixedSizeListVector vector2 = FixedSizeListVector.empty("list", 2, allocator);) { + final FixedSizeListVector vector2 = FixedSizeListVector.empty("list", 2, allocator); ) { UnionFixedSizeListWriter writer1 = vector1.getWriter(); writer1.allocate(); - //set some values + // set some values writeFixedSizeListVector(writer1, new int[] {1, 2}); writeFixedSizeListVector(writer1, new int[] {3, 4}); writeFixedSizeListVector(writer1, new int[] {5, 6}); @@ -223,7 +222,7 @@ public void testFixedSizeListVectorRangeEquals() { UnionFixedSizeListWriter writer2 = vector2.getWriter(); writer2.allocate(); - //set some values + // set some values writeFixedSizeListVector(writer2, new int[] {0, 0}); writeFixedSizeListVector(writer2, new int[] {3, 4}); writeFixedSizeListVector(writer2, new int[] {5, 6}); @@ -240,27 +239,35 @@ public void testFixedSizeListVectorRangeEquals() { @Test public void testLargeVariableWidthVectorRangeEquals() { try (final LargeVarCharVector vector1 = new LargeVarCharVector("vector1", allocator); - final LargeVarCharVector vector2 = new LargeVarCharVector("vector2", allocator)) { + final LargeVarCharVector vector2 = new LargeVarCharVector("vector2", allocator)) { setVector(vector1, "aaa", "bbb", "ccc", null, "ddd"); setVector(vector2, "ccc", "aaa", "bbb", null, "ddd"); - RangeEqualsVisitor visitor = new RangeEqualsVisitor(vector1, vector2, - (v1, v2) -> new TypeEqualsVisitor(v2, /*check name*/ false, /*check metadata*/ false).equals(v1)); + RangeEqualsVisitor visitor = + new RangeEqualsVisitor( + vector1, + vector2, + (v1, v2) -> + new TypeEqualsVisitor(v2, /*check name*/ false, /*check metadata*/ false) + .equals(v1)); - assertFalse(visitor.rangeEquals(new Range(/*left start*/ 0, /*right start*/ 0, /*length*/ 1))); + assertFalse( + visitor.rangeEquals(new Range(/*left start*/ 0, /*right start*/ 0, /*length*/ 1))); assertTrue(visitor.rangeEquals(new Range(/*left start*/ 0, /*right start*/ 1, /*length*/ 1))); - assertFalse(visitor.rangeEquals(new Range(/*left start*/ 0, /*right start*/ 0, /*length*/ 3))); + assertFalse( + visitor.rangeEquals(new Range(/*left start*/ 0, /*right start*/ 0, /*length*/ 3))); assertTrue(visitor.rangeEquals(new Range(/*left start*/ 0, /*right start*/ 1, /*length*/ 2))); assertTrue(visitor.rangeEquals(new Range(/*left start*/ 3, /*right start*/ 3, /*length*/ 1))); assertTrue(visitor.rangeEquals(new Range(/*left start*/ 3, /*right start*/ 3, /*length*/ 2))); - assertFalse(visitor.rangeEquals(new Range(/*left start*/ 2, /*right start*/ 2, /*length*/ 2))); + assertFalse( + visitor.rangeEquals(new Range(/*left start*/ 2, /*right start*/ 2, /*length*/ 2))); } } @Test public void testStructVectorRangeEquals() { try (final StructVector vector1 = StructVector.empty("struct", allocator); - final StructVector vector2 = StructVector.empty("struct", allocator);) { + final StructVector vector2 = StructVector.empty("struct", allocator); ) { vector1.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); vector1.addOrGet("f1", FieldType.nullable(new ArrowType.Int(64, true)), BigIntVector.class); vector2.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); @@ -293,9 +300,10 @@ public void testStructVectorRangeEquals() { @Test public void testUnionVectorRangeEquals() { - try (final UnionVector vector1 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); - final UnionVector vector2 = - new UnionVector("union", allocator, /* field type */ null, /* call-back */ null);) { + try (final UnionVector vector1 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); + final UnionVector vector2 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); ) { final NullableUInt4Holder uInt4Holder = new NullableUInt4Holder(); uInt4Holder.value = 10; @@ -331,13 +339,13 @@ public void testUnionVectorRangeEquals() { } /** - * Test comparing two union vectors. - * The two vectors are different in total, but have a range with equal values. + * Test comparing two union vectors. The two vectors are different in total, but have a range with + * equal values. */ @Test public void testUnionVectorSubRangeEquals() { try (final UnionVector vector1 = new UnionVector("union", allocator, null, null); - final UnionVector vector2 = new UnionVector("union", allocator, null, null);) { + final UnionVector vector2 = new UnionVector("union", allocator, null, null); ) { final NullableUInt4Holder uInt4Holder = new NullableUInt4Holder(); uInt4Holder.value = 10; @@ -400,15 +408,19 @@ public void testDenseUnionVectorEquals() { float8Holder.value = 800D; try (DenseUnionVector vector1 = new DenseUnionVector("vector1", allocator, null, null); - DenseUnionVector vector2 = new DenseUnionVector("vector2", allocator, null, null)) { + DenseUnionVector vector2 = new DenseUnionVector("vector2", allocator, null, null)) { vector1.allocateNew(); vector2.allocateNew(); // populate vector1: {100, 200L, null, 400F, 800D} - byte intTypeId = vector1.registerNewTypeId(Field.nullable("int", Types.MinorType.INT.getType())); - byte longTypeId = vector1.registerNewTypeId(Field.nullable("long", Types.MinorType.BIGINT.getType())); - byte floatTypeId = vector1.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); - byte doubleTypeId = vector1.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); + byte intTypeId = + vector1.registerNewTypeId(Field.nullable("int", Types.MinorType.INT.getType())); + byte longTypeId = + vector1.registerNewTypeId(Field.nullable("long", Types.MinorType.BIGINT.getType())); + byte floatTypeId = + vector1.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); + byte doubleTypeId = + vector1.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); vector1.setTypeId(0, intTypeId); vector1.setSafe(0, intHolder); @@ -426,9 +438,12 @@ public void testDenseUnionVectorEquals() { // populate vector2: {400F, null, 200L, null, 400F, 800D, 100} intTypeId = vector2.registerNewTypeId(Field.nullable("int", Types.MinorType.INT.getType())); - longTypeId = vector2.registerNewTypeId(Field.nullable("long", Types.MinorType.BIGINT.getType())); - floatTypeId = vector2.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); - doubleTypeId = vector2.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); + longTypeId = + vector2.registerNewTypeId(Field.nullable("long", Types.MinorType.BIGINT.getType())); + floatTypeId = + vector2.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); + doubleTypeId = + vector2.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); vector2.setTypeId(0, floatTypeId); vector2.setSafe(0, float4Holder); @@ -480,7 +495,7 @@ public void testDenseUnionVectorEquals() { @Test public void testEqualsWithOutTypeCheck() { try (final IntVector intVector = new IntVector("int", allocator); - final ZeroVector zeroVector = new ZeroVector("zero")) { + final ZeroVector zeroVector = new ZeroVector("zero")) { assertTrue(VectorEqualsVisitor.vectorEquals(intVector, zeroVector, null)); assertTrue(VectorEqualsVisitor.vectorEquals(zeroVector, intVector, null)); @@ -490,8 +505,8 @@ public void testEqualsWithOutTypeCheck() { @Test public void testFloat4ApproxEquals() { try (final Float4Vector vector1 = new Float4Vector("float", allocator); - final Float4Vector vector2 = new Float4Vector("float", allocator); - final Float4Vector vector3 = new Float4Vector("float", allocator)) { + final Float4Vector vector2 = new Float4Vector("float", allocator); + final Float4Vector vector3 = new Float4Vector("float", allocator)) { final float epsilon = 1.0E-6f; setVector(vector1, 1.1f, 2.2f); @@ -511,8 +526,8 @@ public void testFloat4ApproxEquals() { @Test public void testFloat8ApproxEquals() { try (final Float8Vector vector1 = new Float8Vector("float", allocator); - final Float8Vector vector2 = new Float8Vector("float", allocator); - final Float8Vector vector3 = new Float8Vector("float", allocator)) { + final Float8Vector vector2 = new Float8Vector("float", allocator); + final Float8Vector vector3 = new Float8Vector("float", allocator)) { final float epsilon = 1.0E-6f; setVector(vector1, 1.1, 2.2); @@ -530,18 +545,30 @@ public void testStructVectorApproxEquals() { try (final StructVector right = StructVector.empty("struct", allocator); final StructVector left1 = StructVector.empty("struct", allocator); final StructVector left2 = StructVector.empty("struct", allocator)) { - right.addOrGet("f0", - FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), Float4Vector.class); - right.addOrGet("f1", - FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), Float8Vector.class); - left1.addOrGet("f0", - FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), Float4Vector.class); - left1.addOrGet("f1", - FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), Float8Vector.class); - left2.addOrGet("f0", - FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), Float4Vector.class); - left2.addOrGet("f1", - FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), Float8Vector.class); + right.addOrGet( + "f0", + FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), + Float4Vector.class); + right.addOrGet( + "f1", + FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), + Float8Vector.class); + left1.addOrGet( + "f0", + FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), + Float4Vector.class); + left1.addOrGet( + "f1", + FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), + Float8Vector.class); + left2.addOrGet( + "f0", + FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), + Float4Vector.class); + left2.addOrGet( + "f1", + FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), + Float8Vector.class); final float epsilon = 1.0E-6f; @@ -571,9 +598,12 @@ public void testStructVectorApproxEquals() { @Test public void testUnionVectorApproxEquals() { - try (final UnionVector right = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); - final UnionVector left1 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); - final UnionVector left2 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null);) { + try (final UnionVector right = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); + final UnionVector left1 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); + final UnionVector left2 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); ) { final NullableFloat4Holder float4Holder = new NullableFloat4Holder(); float4Holder.value = 1.01f; @@ -627,16 +657,18 @@ public void testDenseUnionVectorApproxEquals() { final double doubleEpsilon = 0.02; try (final DenseUnionVector vector1 = new DenseUnionVector("vector1", allocator, null, null); - final DenseUnionVector vector2 = new DenseUnionVector("vector2", allocator, null, null); - final DenseUnionVector vector3 = new DenseUnionVector("vector2", allocator, null, null)) { + final DenseUnionVector vector2 = new DenseUnionVector("vector2", allocator, null, null); + final DenseUnionVector vector3 = new DenseUnionVector("vector2", allocator, null, null)) { vector1.allocateNew(); vector2.allocateNew(); vector3.allocateNew(); // populate vector1: {1.0f, 2.0D} - byte floatTypeId = vector1.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); - byte doubleTypeId = vector1.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); + byte floatTypeId = + vector1.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); + byte doubleTypeId = + vector1.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); float4Holder.value = 1.0f; vector1.setTypeId(0, floatTypeId); @@ -647,8 +679,10 @@ public void testDenseUnionVectorApproxEquals() { vector1.setValueCount(2); // populate vector2: {1.01f, 2.01D} - floatTypeId = vector2.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); - doubleTypeId = vector2.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); + floatTypeId = + vector2.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); + doubleTypeId = + vector2.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); float4Holder.value = 1.01f; vector2.setTypeId(0, floatTypeId); @@ -659,8 +693,10 @@ public void testDenseUnionVectorApproxEquals() { vector2.setValueCount(2); // populate vector3: {1.05f, 2.05D} - floatTypeId = vector3.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); - doubleTypeId = vector3.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); + floatTypeId = + vector3.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); + doubleTypeId = + vector3.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); float4Holder.value = 1.05f; vector3.setTypeId(0, floatTypeId); @@ -674,19 +710,27 @@ public void testDenseUnionVectorApproxEquals() { Range range = new Range(0, 0, 2); // compare vector1 and vector2 - ApproxEqualsVisitor approxEqualsVisitor = new ApproxEqualsVisitor( - vector1, vector2, - new ValueEpsilonEqualizers.Float4EpsilonEqualizer(floatEpsilon), - new ValueEpsilonEqualizers.Float8EpsilonEqualizer(doubleEpsilon), - (v1, v2) -> new TypeEqualsVisitor(v2, /* check name */ false, /* check meta */ true).equals(v1)); + ApproxEqualsVisitor approxEqualsVisitor = + new ApproxEqualsVisitor( + vector1, + vector2, + new ValueEpsilonEqualizers.Float4EpsilonEqualizer(floatEpsilon), + new ValueEpsilonEqualizers.Float8EpsilonEqualizer(doubleEpsilon), + (v1, v2) -> + new TypeEqualsVisitor(v2, /* check name */ false, /* check meta */ true) + .equals(v1)); assertTrue(approxEqualsVisitor.rangeEquals(range)); // compare vector1 and vector3 - approxEqualsVisitor = new ApproxEqualsVisitor( - vector1, vector3, - new ValueEpsilonEqualizers.Float4EpsilonEqualizer(floatEpsilon), - new ValueEpsilonEqualizers.Float8EpsilonEqualizer(doubleEpsilon), - (v1, v2) -> new TypeEqualsVisitor(v2, /* check name */ false, /* check meta */ true).equals(v1)); + approxEqualsVisitor = + new ApproxEqualsVisitor( + vector1, + vector3, + new ValueEpsilonEqualizers.Float4EpsilonEqualizer(floatEpsilon), + new ValueEpsilonEqualizers.Float8EpsilonEqualizer(doubleEpsilon), + (v1, v2) -> + new TypeEqualsVisitor(v2, /* check name */ false, /* check meta */ true) + .equals(v1)); assertFalse(approxEqualsVisitor.rangeEquals(range)); } } @@ -694,8 +738,8 @@ public void testDenseUnionVectorApproxEquals() { @Test public void testListVectorApproxEquals() { try (final ListVector right = ListVector.empty("list", allocator); - final ListVector left1 = ListVector.empty("list", allocator); - final ListVector left2 = ListVector.empty("list", allocator);) { + final ListVector left1 = ListVector.empty("list", allocator); + final ListVector left2 = ListVector.empty("list", allocator); ) { final float epsilon = 1.0E-6f; @@ -739,7 +783,7 @@ private void writeStructVector(NullableStructWriter writer, float value1, double private void writeListVector(UnionListWriter writer, int[] values) { writer.startList(); - for (int v: values) { + for (int v : values) { writer.integer().writeInt(v); } writer.endList(); @@ -747,7 +791,7 @@ private void writeListVector(UnionListWriter writer, int[] values) { private void writeFixedSizeListVector(UnionFixedSizeListWriter writer, int[] values) { writer.startList(); - for (int v: values) { + for (int v : values) { writer.integer().writeInt(v); } writer.endList(); @@ -755,7 +799,7 @@ private void writeFixedSizeListVector(UnionFixedSizeListWriter writer, int[] val private void writeListVector(UnionListWriter writer, double[] values) { writer.startList(); - for (double v: values) { + for (double v : values) { writer.float8().writeFloat8(v); } writer.endList(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/compare/TestTypeEqualsVisitor.java b/java/vector/src/test/java/org/apache/arrow/vector/compare/TestTypeEqualsVisitor.java index c0a3bd89dc1..2f4a6b6785c 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/compare/TestTypeEqualsVisitor.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/compare/TestTypeEqualsVisitor.java @@ -23,7 +23,6 @@ import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BigIntVector; @@ -65,7 +64,7 @@ public void terminate() throws Exception { @Test public void testTypeEqualsWithName() { try (final IntVector right = new IntVector("int", allocator); - final IntVector left1 = new IntVector("int", allocator); + final IntVector left1 = new IntVector("int", allocator); final IntVector left2 = new IntVector("int2", allocator)) { TypeEqualsVisitor visitor = new TypeEqualsVisitor(right); @@ -78,14 +77,14 @@ public void testTypeEqualsWithName() { public void testTypeEqualsWithMetadata() { Map metadata = new HashMap<>(); metadata.put("key1", "value1"); - FieldType typeWithoutMeta = new FieldType(true, new ArrowType.Int(32, true), - null, null); - FieldType typeWithMeta = new FieldType(true, new ArrowType.Int(32, true), - null, metadata); + FieldType typeWithoutMeta = new FieldType(true, new ArrowType.Int(32, true), null, null); + FieldType typeWithMeta = new FieldType(true, new ArrowType.Int(32, true), null, metadata); - try (IntVector right = (IntVector) typeWithoutMeta.createNewSingleVector("int", allocator, null); - IntVector left1 = (IntVector) typeWithoutMeta.createNewSingleVector("int", allocator, null); - IntVector left2 = (IntVector) typeWithMeta.createNewSingleVector("int", allocator, null)) { + try (IntVector right = + (IntVector) typeWithoutMeta.createNewSingleVector("int", allocator, null); + IntVector left1 = + (IntVector) typeWithoutMeta.createNewSingleVector("int", allocator, null); + IntVector left2 = (IntVector) typeWithMeta.createNewSingleVector("int", allocator, null)) { TypeEqualsVisitor visitor = new TypeEqualsVisitor(right); assertTrue(visitor.equals(left1)); @@ -96,8 +95,8 @@ public void testTypeEqualsWithMetadata() { @Test public void testListTypeEquals() { try (final ListVector right = ListVector.empty("list", allocator); - final ListVector left1 = ListVector.empty("list", allocator); - final ListVector left2 = ListVector.empty("list", allocator)) { + final ListVector left1 = ListVector.empty("list", allocator); + final ListVector left2 = ListVector.empty("list", allocator)) { right.addOrGetVector(FieldType.nullable(new ArrowType.Utf8())); left1.addOrGetVector(FieldType.nullable(new ArrowType.Utf8())); @@ -112,8 +111,8 @@ public void testListTypeEquals() { @Test public void testStructTypeEquals() { try (final StructVector right = StructVector.empty("struct", allocator); - final StructVector left1 = StructVector.empty("struct", allocator); - final StructVector left2 = StructVector.empty("struct", allocator)) { + final StructVector left1 = StructVector.empty("struct", allocator); + final StructVector left2 = StructVector.empty("struct", allocator)) { right.addOrGet("child", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class); left1.addOrGet("child", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class); @@ -127,9 +126,12 @@ public void testStructTypeEquals() { @Test public void testUnionTypeEquals() { - try (final UnionVector right = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); - final UnionVector left1 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); - final UnionVector left2 = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null)) { + try (final UnionVector right = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); + final UnionVector left1 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); + final UnionVector left2 = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null)) { right.addVector(new IntVector("int", allocator)); left1.addVector(new IntVector("int", allocator)); @@ -144,15 +146,19 @@ public void testUnionTypeEquals() { @Test public void testDenseUnionTypeEquals() { try (DenseUnionVector vector1 = new DenseUnionVector("vector1", allocator, null, null); - DenseUnionVector vector2 = new DenseUnionVector("vector2", allocator, null, null)) { + DenseUnionVector vector2 = new DenseUnionVector("vector2", allocator, null, null)) { vector1.allocateNew(); vector2.allocateNew(); // set children for vector1 - byte intTypeId = vector1.registerNewTypeId(Field.nullable("int", Types.MinorType.INT.getType())); - byte longTypeId = vector1.registerNewTypeId(Field.nullable("long", Types.MinorType.BIGINT.getType())); - byte floatTypeId = vector1.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); - byte doubleTypeId = vector1.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); + byte intTypeId = + vector1.registerNewTypeId(Field.nullable("int", Types.MinorType.INT.getType())); + byte longTypeId = + vector1.registerNewTypeId(Field.nullable("long", Types.MinorType.BIGINT.getType())); + byte floatTypeId = + vector1.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); + byte doubleTypeId = + vector1.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); vector1.addVector(floatTypeId, new Float4Vector("", allocator)); vector1.addVector(longTypeId, new BigIntVector("", allocator)); @@ -161,9 +167,12 @@ public void testDenseUnionTypeEquals() { // set children for vector2 intTypeId = vector2.registerNewTypeId(Field.nullable("int", Types.MinorType.INT.getType())); - longTypeId = vector2.registerNewTypeId(Field.nullable("long", Types.MinorType.BIGINT.getType())); - floatTypeId = vector2.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); - doubleTypeId = vector2.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); + longTypeId = + vector2.registerNewTypeId(Field.nullable("long", Types.MinorType.BIGINT.getType())); + floatTypeId = + vector2.registerNewTypeId(Field.nullable("float", Types.MinorType.FLOAT4.getType())); + doubleTypeId = + vector2.registerNewTypeId(Field.nullable("double", Types.MinorType.FLOAT8.getType())); // add vectors in a different order vector2.addVector(intTypeId, new IntVector("", allocator)); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/TestDenseUnionBufferSize.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/TestDenseUnionBufferSize.java index 82ef7a479d0..d98677e898e 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/TestDenseUnionBufferSize.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/TestDenseUnionBufferSize.java @@ -35,14 +35,22 @@ public class TestDenseUnionBufferSize { @Test public void testBufferSize() { try (BufferAllocator allocator = new RootAllocator(); - DenseUnionVector duv = new DenseUnionVector("duv", allocator, - FieldType.nullable(new ArrowType.Union(UnionMode.Dense, null)), null)) { + DenseUnionVector duv = + new DenseUnionVector( + "duv", + allocator, + FieldType.nullable(new ArrowType.Union(UnionMode.Dense, null)), + null)) { byte aTypeId = 42; byte bTypeId = 7; - duv.addVector(aTypeId, new IntVector("a", FieldType.notNullable(new ArrowType.Int(32, true)), allocator)); - duv.addVector(bTypeId, new VarBinaryVector("b", FieldType.notNullable(new ArrowType.Binary()), allocator)); + duv.addVector( + aTypeId, + new IntVector("a", FieldType.notNullable(new ArrowType.Int(32, true)), allocator)); + duv.addVector( + bTypeId, + new VarBinaryVector("b", FieldType.notNullable(new ArrowType.Binary()), allocator)); NullableIntHolder intHolder = new NullableIntHolder(); NullableVarBinaryHolder varBinaryHolder = new NullableVarBinaryHolder(); @@ -70,12 +78,15 @@ public void testBufferSize() { long overhead = DenseUnionVector.TYPE_WIDTH + DenseUnionVector.OFFSET_WIDTH; - assertEquals(overhead * count + intVector.getBufferSize() + varBinaryVector.getBufferSize(), - duv.getBufferSize()); - - assertEquals(overhead * (aCount + 1) + intVector.getBufferSizeFor(aCount) + varBinaryVector.getBufferSizeFor(1), - duv.getBufferSizeFor(aCount + 1)); + assertEquals( + overhead * count + intVector.getBufferSize() + varBinaryVector.getBufferSize(), + duv.getBufferSize()); + assertEquals( + overhead * (aCount + 1) + + intVector.getBufferSizeFor(aCount) + + varBinaryVector.getBufferSizeFor(1), + duv.getBufferSizeFor(aCount + 1)); } } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestComplexCopier.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestComplexCopier.java index 29f25170332..f85ca9af1e9 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestComplexCopier.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestComplexCopier.java @@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.math.BigDecimal; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.DecimalVector; @@ -62,7 +61,7 @@ public void terminate() throws Exception { @Test public void testCopyFixedSizeListVector() { try (FixedSizeListVector from = FixedSizeListVector.empty("v", 3, allocator); - FixedSizeListVector to = FixedSizeListVector.empty("v", 3, allocator)) { + FixedSizeListVector to = FixedSizeListVector.empty("v", 3, allocator)) { from.addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())); to.addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())); @@ -90,14 +89,13 @@ public void testCopyFixedSizeListVector() { // validate equals assertTrue(VectorEqualsVisitor.vectorEquals(from, to)); - } } @Test public void testInvalidCopyFixedSizeListVector() { try (FixedSizeListVector from = FixedSizeListVector.empty("v", 3, allocator); - FixedSizeListVector to = FixedSizeListVector.empty("v", 2, allocator)) { + FixedSizeListVector to = FixedSizeListVector.empty("v", 2, allocator)) { from.addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())); to.addOrGetVector(FieldType.nullable(Types.MinorType.INT.getType())); @@ -117,8 +115,8 @@ public void testInvalidCopyFixedSizeListVector() { // copy values FieldReader in = from.getReader(); FieldWriter out = to.getWriter(); - IllegalStateException e = assertThrows(IllegalStateException.class, - () -> ComplexCopier.copy(in, out)); + IllegalStateException e = + assertThrows(IllegalStateException.class, () -> ComplexCopier.copy(in, out)); assertTrue(e.getMessage().contains("greater than listSize")); } } @@ -126,7 +124,7 @@ public void testInvalidCopyFixedSizeListVector() { @Test public void testCopyMapVector() { try (final MapVector from = MapVector.empty("v", allocator, false); - final MapVector to = MapVector.empty("v", allocator, false)) { + final MapVector to = MapVector.empty("v", allocator, false)) { from.allocateNew(); @@ -165,7 +163,7 @@ public void testCopyMapVector() { @Test public void testCopyListVector() { try (ListVector from = ListVector.empty("v", allocator); - ListVector to = ListVector.empty("v", allocator)) { + ListVector to = ListVector.empty("v", allocator)) { UnionListWriter listWriter = from.getWriter(); listWriter.allocate(); @@ -204,14 +202,13 @@ public void testCopyListVector() { // validate equals assertTrue(VectorEqualsVisitor.vectorEquals(from, to)); - } } @Test public void testCopyListVectorToANonEmptyList() { try (ListVector from = ListVector.empty("v", allocator); - ListVector to = ListVector.empty("v", allocator)) { + ListVector to = ListVector.empty("v", allocator)) { UnionListWriter listWriter = from.getWriter(); listWriter.allocate(); @@ -262,7 +259,7 @@ public void testCopyListVectorToANonEmptyList() { @Test public void testCopyListVectorWithNulls() { try (ListVector from = ListVector.empty("v", allocator); - ListVector to = ListVector.empty("v", allocator)) { + ListVector to = ListVector.empty("v", allocator)) { UnionListWriter listWriter = from.getWriter(); listWriter.allocate(); @@ -303,7 +300,7 @@ public void testCopyListVectorWithNulls() { @Test public void testCopyListOfListVectorWithNulls() { try (ListVector from = ListVector.empty("v", allocator); - ListVector to = ListVector.empty("v", allocator);) { + ListVector to = ListVector.empty("v", allocator); ) { UnionListWriter listWriter = from.getWriter(); listWriter.allocate(); @@ -358,7 +355,7 @@ public void testCopyListOfListVectorWithNulls() { @Test public void testCopyListOStructVectorWithNulls() { try (ListVector from = ListVector.empty("v", allocator); - ListVector to = ListVector.empty("v", allocator);) { + ListVector to = ListVector.empty("v", allocator); ) { UnionListWriter listWriter = from.getWriter(); listWriter.allocate(); @@ -408,7 +405,7 @@ public void testCopyListOStructVectorWithNulls() { @Test public void testCopyListOfListOfStructVectorWithNulls() { try (ListVector from = ListVector.empty("v", allocator); - ListVector to = ListVector.empty("v", allocator);) { + ListVector to = ListVector.empty("v", allocator); ) { UnionListWriter listWriter = from.getWriter(); listWriter.allocate(); @@ -485,7 +482,7 @@ public void testCopyListOfListOfStructVectorWithNulls() { @Test public void testMapWithListValue() throws Exception { try (MapVector from = MapVector.empty("map", allocator, false); - MapVector to = MapVector.empty("map", allocator, false)) { + MapVector to = MapVector.empty("map", allocator, false)) { UnionMapWriter mapWriter = from.getWriter(); BaseWriter.ListWriter valueWriter; @@ -573,7 +570,7 @@ public void testMapWithListValue() throws Exception { @Test public void testCopyFixedSizedListOfDecimalsVector() { try (FixedSizeListVector from = FixedSizeListVector.empty("v", 4, allocator); - FixedSizeListVector to = FixedSizeListVector.empty("v", 4, allocator)) { + FixedSizeListVector to = FixedSizeListVector.empty("v", 4, allocator)) { from.addOrGetVector(FieldType.nullable(new ArrowType.Decimal(3, 0, 128))); to.addOrGetVector(FieldType.nullable(new ArrowType.Decimal(3, 0, 128))); @@ -587,17 +584,21 @@ public void testCopyFixedSizedListOfDecimalsVector() { writer.startList(); writer.decimal().writeDecimal(BigDecimal.valueOf(i)); - DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(i * 2), holder.buffer, 0, DecimalVector.TYPE_WIDTH); + DecimalUtility.writeBigDecimalToArrowBuf( + new BigDecimal(i * 2), holder.buffer, 0, DecimalVector.TYPE_WIDTH); holder.start = 0; holder.scale = 0; holder.precision = 3; writer.decimal().write(holder); - DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(i * 3), holder.buffer, 0, DecimalVector.TYPE_WIDTH); + DecimalUtility.writeBigDecimalToArrowBuf( + new BigDecimal(i * 3), holder.buffer, 0, DecimalVector.TYPE_WIDTH); writer.decimal().writeDecimal(0, holder.buffer, arrowType); - writer.decimal().writeBigEndianBytesToDecimal(BigDecimal.valueOf(i * 4).unscaledValue().toByteArray(), - arrowType); + writer + .decimal() + .writeBigEndianBytesToDecimal( + BigDecimal.valueOf(i * 4).unscaledValue().toByteArray(), arrowType); writer.endList(); } @@ -622,7 +623,7 @@ public void testCopyFixedSizedListOfDecimalsVector() { @Test public void testCopyUnionListWithDecimal() { try (ListVector from = ListVector.empty("v", allocator); - ListVector to = ListVector.empty("v", allocator)) { + ListVector to = ListVector.empty("v", allocator)) { UnionListWriter listWriter = from.getWriter(); listWriter.allocate(); @@ -633,8 +634,11 @@ public void testCopyUnionListWithDecimal() { listWriter.decimal().writeDecimal(BigDecimal.valueOf(i * 2)); listWriter.integer().writeInt(i); - listWriter.decimal().writeBigEndianBytesToDecimal(BigDecimal.valueOf(i * 3).unscaledValue().toByteArray(), - new ArrowType.Decimal(3, 0, 128)); + listWriter + .decimal() + .writeBigEndianBytesToDecimal( + BigDecimal.valueOf(i * 3).unscaledValue().toByteArray(), + new ArrowType.Decimal(3, 0, 128)); listWriter.endList(); } @@ -653,14 +657,13 @@ public void testCopyUnionListWithDecimal() { // validate equals assertTrue(VectorEqualsVisitor.vectorEquals(from, to)); - } } @Test public void testCopyStructVector() { try (final StructVector from = StructVector.empty("v", allocator); - final StructVector to = StructVector.empty("v", allocator)) { + final StructVector to = StructVector.empty("v", allocator)) { from.allocateNewSafe(); @@ -674,8 +677,11 @@ public void testCopyStructVector() { innerStructWriter.start(); innerStructWriter.integer("innerint").writeInt(i * 3); innerStructWriter.decimal("innerdec", 0, 38).writeDecimal(BigDecimal.valueOf(i * 4)); - innerStructWriter.decimal("innerdec", 0, 38).writeBigEndianBytesToDecimal(BigDecimal.valueOf(i * 4) - .unscaledValue().toByteArray(), new ArrowType.Decimal(3, 0, 128)); + innerStructWriter + .decimal("innerdec", 0, 38) + .writeBigEndianBytesToDecimal( + BigDecimal.valueOf(i * 4).unscaledValue().toByteArray(), + new ArrowType.Decimal(3, 0, 128)); innerStructWriter.end(); structWriter.end(); } @@ -700,7 +706,7 @@ public void testCopyStructVector() { @Test public void testCopyDecimalVectorWrongScale() { try (FixedSizeListVector from = FixedSizeListVector.empty("v", 3, allocator); - FixedSizeListVector to = FixedSizeListVector.empty("v", 3, allocator)) { + FixedSizeListVector to = FixedSizeListVector.empty("v", 3, allocator)) { from.addOrGetVector(FieldType.nullable(new ArrowType.Decimal(3, 2, 128))); to.addOrGetVector(FieldType.nullable(new ArrowType.Decimal(3, 1, 128))); @@ -718,16 +724,17 @@ public void testCopyDecimalVectorWrongScale() { // copy values FieldReader in = from.getReader(); FieldWriter out = to.getWriter(); - UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, - () -> ComplexCopier.copy(in, out)); - assertTrue(e.getMessage().contains("BigDecimal scale must equal that in the Arrow vector: 2 != 1")); + UnsupportedOperationException e = + assertThrows(UnsupportedOperationException.class, () -> ComplexCopier.copy(in, out)); + assertTrue( + e.getMessage().contains("BigDecimal scale must equal that in the Arrow vector: 2 != 1")); } } @Test public void testCopyStructVectorWithNulls() { try (StructVector from = StructVector.empty("v", allocator); - StructVector to = StructVector.empty("v", allocator)) { + StructVector to = StructVector.empty("v", allocator)) { NullableStructWriter writer = from.getWriter(); @@ -764,7 +771,7 @@ public void testCopyStructVectorWithNulls() { @Test public void testCopyStructOfMap() { try (final StructVector from = StructVector.empty("v", allocator); - final StructVector to = StructVector.empty("v", allocator);) { + final StructVector to = StructVector.empty("v", allocator); ) { from.allocateNew(); @@ -802,7 +809,7 @@ public void testCopyStructOfMap() { @Test public void testCopyMapVectorWithMapValue() { try (final MapVector from = MapVector.empty("v", allocator, false); - final MapVector to = MapVector.empty("v", allocator, false)) { + final MapVector to = MapVector.empty("v", allocator, false)) { from.allocateNew(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java index 4c8c96a0d74..bb68b41af29 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/impl/TestPromotableWriter.java @@ -24,7 +24,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.DirtyRootAllocator; @@ -70,9 +69,10 @@ public void terminate() throws Exception { @Test public void testPromoteToUnion() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); @@ -153,8 +153,11 @@ public void testPromoteToUnion() throws Exception { assertEquals(444413L, ((java.time.Duration) uv.getObject(7)).getSeconds()); assertFalse("8 shouldn't be null", uv.isNull(8)); - assertEquals(18978, - ByteBuffer.wrap(uv.getFixedSizeBinaryVector().get(8)).order(ByteOrder.nativeOrder()).getInt()); + assertEquals( + 18978, + ByteBuffer.wrap(uv.getFixedSizeBinaryVector().get(8)) + .order(ByteOrder.nativeOrder()) + .getInt()); container.clear(); container.allocateNew(); @@ -170,10 +173,14 @@ public void testPromoteToUnion() throws Exception { Field childField1 = container.getField().getChildren().get(0).getChildren().get(0); Field childField2 = container.getField().getChildren().get(0).getChildren().get(1); - assertEquals("Child field should be union type: " + - childField1.getName(), ArrowTypeID.Union, childField1.getType().getTypeID()); - assertEquals("Child field should be decimal type: " + - childField2.getName(), ArrowTypeID.Decimal, childField2.getType().getTypeID()); + assertEquals( + "Child field should be union type: " + childField1.getName(), + ArrowTypeID.Union, + childField1.getType().getTypeID()); + assertEquals( + "Child field should be decimal type: " + childField2.getName(), + ArrowTypeID.Decimal, + childField2.getType().getTypeID()); buf.close(); } @@ -182,9 +189,10 @@ public void testPromoteToUnion() throws Exception { @Test public void testNoPromoteFloat4ToUnionWithNull() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); @@ -193,15 +201,25 @@ public void testNoPromoteFloat4ToUnionWithNull() throws Exception { writer.list("list").endList(); writer.end(); - FieldType childTypeOfListInContainer = container.getField().getChildren().get(0).getChildren().get(0) - .getChildren().get(0).getFieldType(); + FieldType childTypeOfListInContainer = + container + .getField() + .getChildren() + .get(0) + .getChildren() + .get(0) + .getChildren() + .get(0) + .getFieldType(); // create a listvector with same type as list in container to, say, hold a copy // this will be a nullvector ListVector lv = ListVector.empty("name", allocator); lv.addOrGetVector(childTypeOfListInContainer); assertEquals(childTypeOfListInContainer.getType(), Types.MinorType.NULL.getType()); - assertEquals(lv.getChildrenFromFields().get(0).getMinorType().getType(), Types.MinorType.NULL.getType()); + assertEquals( + lv.getChildrenFromFields().get(0).getMinorType().getType(), + Types.MinorType.NULL.getType()); writer.start(); writer.list("list").startList(); @@ -211,14 +229,24 @@ public void testNoPromoteFloat4ToUnionWithNull() throws Exception { container.setValueCount(2); - childTypeOfListInContainer = container.getField().getChildren().get(0).getChildren().get(0) - .getChildren().get(0).getFieldType(); + childTypeOfListInContainer = + container + .getField() + .getChildren() + .get(0) + .getChildren() + .get(0) + .getChildren() + .get(0) + .getFieldType(); // repeat but now the type in container has been changed from null to float // we expect same behaviour from listvector lv.addOrGetVector(childTypeOfListInContainer); assertEquals(childTypeOfListInContainer.getType(), Types.MinorType.FLOAT4.getType()); - assertEquals(lv.getChildrenFromFields().get(0).getMinorType().getType(), Types.MinorType.FLOAT4.getType()); + assertEquals( + lv.getChildrenFromFields().get(0).getMinorType().getType(), + Types.MinorType.FLOAT4.getType()); lv.close(); } @@ -227,9 +255,10 @@ public void testNoPromoteFloat4ToUnionWithNull() throws Exception { @Test public void testNoPromoteTimeStampMilliTZToUnionWithNull() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); @@ -238,15 +267,25 @@ public void testNoPromoteTimeStampMilliTZToUnionWithNull() throws Exception { writer.list("list").endList(); writer.end(); - FieldType childTypeOfListInContainer = container.getField().getChildren().get(0).getChildren().get(0) - .getChildren().get(0).getFieldType(); + FieldType childTypeOfListInContainer = + container + .getField() + .getChildren() + .get(0) + .getChildren() + .get(0) + .getChildren() + .get(0) + .getFieldType(); // create a listvector with same type as list in container to, say, hold a copy // this will be a nullvector ListVector lv = ListVector.empty("name", allocator); lv.addOrGetVector(childTypeOfListInContainer); assertEquals(childTypeOfListInContainer.getType(), Types.MinorType.NULL.getType()); - assertEquals(lv.getChildrenFromFields().get(0).getMinorType().getType(), Types.MinorType.NULL.getType()); + assertEquals( + lv.getChildrenFromFields().get(0).getMinorType().getType(), + Types.MinorType.NULL.getType()); writer.start(); writer.list("list").startList(); @@ -257,24 +296,38 @@ public void testNoPromoteTimeStampMilliTZToUnionWithNull() throws Exception { // Test that we get an exception when the timezone doesn't match holder.timezone = "SomeTimeZone"; - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> writer.list("list").timeStampMilliTZ().write(holder)); - assertEquals("holder.timezone: SomeTimeZone not equal to vector timezone: FakeTimeZone", ex.getMessage()); + IllegalArgumentException ex = + assertThrows( + IllegalArgumentException.class, + () -> writer.list("list").timeStampMilliTZ().write(holder)); + assertEquals( + "holder.timezone: SomeTimeZone not equal to vector timezone: FakeTimeZone", + ex.getMessage()); writer.list("list").endList(); writer.end(); container.setValueCount(2); - childTypeOfListInContainer = container.getField().getChildren().get(0).getChildren().get(0) - .getChildren().get(0).getFieldType(); + childTypeOfListInContainer = + container + .getField() + .getChildren() + .get(0) + .getChildren() + .get(0) + .getChildren() + .get(0) + .getFieldType(); // repeat but now the type in container has been changed from null to float // we expect same behaviour from listvector lv.addOrGetVector(childTypeOfListInContainer); - assertEquals(childTypeOfListInContainer.getType(), + assertEquals( + childTypeOfListInContainer.getType(), new ArrowType.Timestamp(TimeUnit.MILLISECOND, "FakeTimeZone")); - assertEquals(lv.getChildrenFromFields().get(0).getField().getType(), + assertEquals( + lv.getChildrenFromFields().get(0).getField().getType(), new ArrowType.Timestamp(TimeUnit.MILLISECOND, "FakeTimeZone")); lv.close(); @@ -284,9 +337,10 @@ public void testNoPromoteTimeStampMilliTZToUnionWithNull() throws Exception { @Test public void testNoPromoteDurationToUnionWithNull() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); @@ -295,15 +349,25 @@ public void testNoPromoteDurationToUnionWithNull() throws Exception { writer.list("list").endList(); writer.end(); - FieldType childTypeOfListInContainer = container.getField().getChildren().get(0).getChildren().get(0) - .getChildren().get(0).getFieldType(); + FieldType childTypeOfListInContainer = + container + .getField() + .getChildren() + .get(0) + .getChildren() + .get(0) + .getChildren() + .get(0) + .getFieldType(); // create a listvector with same type as list in container to, say, hold a copy // this will be a nullvector ListVector lv = ListVector.empty("name", allocator); lv.addOrGetVector(childTypeOfListInContainer); assertEquals(childTypeOfListInContainer.getType(), Types.MinorType.NULL.getType()); - assertEquals(lv.getChildrenFromFields().get(0).getMinorType().getType(), Types.MinorType.NULL.getType()); + assertEquals( + lv.getChildrenFromFields().get(0).getMinorType().getType(), + Types.MinorType.NULL.getType()); writer.start(); writer.list("list").startList(); @@ -314,24 +378,35 @@ public void testNoPromoteDurationToUnionWithNull() throws Exception { // Test that we get an exception when the unit doesn't match holder.unit = TimeUnit.MICROSECOND; - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> writer.list("list").duration().write(holder)); - assertEquals("holder.unit: MICROSECOND not equal to vector unit: NANOSECOND", ex.getMessage()); + IllegalArgumentException ex = + assertThrows( + IllegalArgumentException.class, () -> writer.list("list").duration().write(holder)); + assertEquals( + "holder.unit: MICROSECOND not equal to vector unit: NANOSECOND", ex.getMessage()); writer.list("list").endList(); writer.end(); container.setValueCount(2); - childTypeOfListInContainer = container.getField().getChildren().get(0).getChildren().get(0) - .getChildren().get(0).getFieldType(); + childTypeOfListInContainer = + container + .getField() + .getChildren() + .get(0) + .getChildren() + .get(0) + .getChildren() + .get(0) + .getFieldType(); // repeat but now the type in container has been changed from null to float // we expect same behaviour from listvector lv.addOrGetVector(childTypeOfListInContainer); - assertEquals(childTypeOfListInContainer.getType(), - new ArrowType.Duration(TimeUnit.NANOSECOND)); - assertEquals(lv.getChildrenFromFields().get(0).getField().getType(), + assertEquals( + childTypeOfListInContainer.getType(), new ArrowType.Duration(TimeUnit.NANOSECOND)); + assertEquals( + lv.getChildrenFromFields().get(0).getField().getType(), new ArrowType.Duration(TimeUnit.NANOSECOND)); lv.close(); @@ -341,9 +416,10 @@ public void testNoPromoteDurationToUnionWithNull() throws Exception { @Test public void testNoPromoteFixedSizeBinaryToUnionWithNull() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); @@ -352,15 +428,25 @@ public void testNoPromoteFixedSizeBinaryToUnionWithNull() throws Exception { writer.list("list").endList(); writer.end(); - FieldType childTypeOfListInContainer = container.getField().getChildren().get(0).getChildren().get(0) - .getChildren().get(0).getFieldType(); + FieldType childTypeOfListInContainer = + container + .getField() + .getChildren() + .get(0) + .getChildren() + .get(0) + .getChildren() + .get(0) + .getFieldType(); // create a listvector with same type as list in container to, say, hold a copy // this will be a nullvector ListVector lv = ListVector.empty("name", allocator); lv.addOrGetVector(childTypeOfListInContainer); assertEquals(childTypeOfListInContainer.getType(), Types.MinorType.NULL.getType()); - assertEquals(lv.getChildrenFromFields().get(0).getMinorType().getType(), Types.MinorType.NULL.getType()); + assertEquals( + lv.getChildrenFromFields().get(0).getMinorType().getType(), + Types.MinorType.NULL.getType()); writer.start(); writer.list("list").startList(); @@ -373,8 +459,10 @@ public void testNoPromoteFixedSizeBinaryToUnionWithNull() throws Exception { // Test that we get an exception when the unit doesn't match holder.byteWidth = 7; - IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> writer.list("list").fixedSizeBinary().write(holder)); + IllegalArgumentException ex = + assertThrows( + IllegalArgumentException.class, + () -> writer.list("list").fixedSizeBinary().write(holder)); assertEquals("holder.byteWidth: 7 not equal to vector byteWidth: 4", ex.getMessage()); writer.list("list").endList(); @@ -382,16 +470,23 @@ public void testNoPromoteFixedSizeBinaryToUnionWithNull() throws Exception { container.setValueCount(2); - childTypeOfListInContainer = container.getField().getChildren().get(0).getChildren().get(0) - .getChildren().get(0).getFieldType(); + childTypeOfListInContainer = + container + .getField() + .getChildren() + .get(0) + .getChildren() + .get(0) + .getChildren() + .get(0) + .getFieldType(); // repeat but now the type in container has been changed from null to float // we expect same behaviour from listvector lv.addOrGetVector(childTypeOfListInContainer); - assertEquals(childTypeOfListInContainer.getType(), - new ArrowType.FixedSizeBinary(4)); - assertEquals(lv.getChildrenFromFields().get(0).getField().getType(), - new ArrowType.FixedSizeBinary(4)); + assertEquals(childTypeOfListInContainer.getType(), new ArrowType.FixedSizeBinary(4)); + assertEquals( + lv.getChildrenFromFields().get(0).getField().getType(), new ArrowType.FixedSizeBinary(4)); lv.close(); buf.close(); @@ -400,9 +495,10 @@ public void testNoPromoteFixedSizeBinaryToUnionWithNull() throws Exception { @Test public void testPromoteLargeVarCharHelpersOnStruct() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); writer.start(); @@ -420,9 +516,10 @@ public void testPromoteLargeVarCharHelpersOnStruct() throws Exception { @Test public void testPromoteVarCharHelpersOnStruct() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); writer.start(); @@ -440,9 +537,10 @@ public void testPromoteVarCharHelpersOnStruct() throws Exception { @Test public void testPromoteVarCharHelpersDirect() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); writer.start(); @@ -462,9 +560,10 @@ public void testPromoteVarCharHelpersDirect() throws Exception { @Test public void testPromoteLargeVarCharHelpersDirect() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); writer.start(); @@ -484,9 +583,10 @@ public void testPromoteLargeVarCharHelpersDirect() throws Exception { @Test public void testPromoteVarBinaryHelpersOnStruct() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); writer.start(); @@ -497,7 +597,9 @@ public void testPromoteVarBinaryHelpersOnStruct() throws Exception { writer.setPosition(2); writer.varBinary("c").writeVarBinary(ByteBuffer.wrap("row3".getBytes())); writer.setPosition(3); - writer.varBinary("c").writeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + writer + .varBinary("c") + .writeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); writer.end(); final VarBinaryVector uv = v.getChild("c", VarBinaryVector.class); @@ -510,9 +612,10 @@ public void testPromoteVarBinaryHelpersOnStruct() throws Exception { @Test public void testPromoteVarBinaryHelpersDirect() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); writer.start(); @@ -538,20 +641,25 @@ public void testPromoteVarBinaryHelpersDirect() throws Exception { @Test public void testPromoteLargeVarBinaryHelpersOnStruct() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); writer.start(); writer.setPosition(0); writer.largeVarBinary("c").writeLargeVarBinary("row1".getBytes()); writer.setPosition(1); - writer.largeVarBinary("c").writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); + writer + .largeVarBinary("c") + .writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); writer.setPosition(2); writer.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes())); writer.setPosition(3); - writer.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + writer + .largeVarBinary("c") + .writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); writer.end(); final LargeVarBinaryVector uv = v.getChild("c", LargeVarBinaryVector.class); @@ -564,9 +672,10 @@ public void testPromoteLargeVarBinaryHelpersOnStruct() throws Exception { @Test public void testPromoteLargeVarBinaryHelpersDirect() throws Exception { - try (final NonNullableStructVector container = NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); - final StructVector v = container.addOrGetStruct("test"); - final PromotableWriter writer = new PromotableWriter(v, container)) { + try (final NonNullableStructVector container = + NonNullableStructVector.empty(EMPTY_SCHEMA_PATH, allocator); + final StructVector v = container.addOrGetStruct("test"); + final PromotableWriter writer = new PromotableWriter(v, container)) { container.allocateNew(); writer.start(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java index e03ce0c056b..90b31208399 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java @@ -26,7 +26,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -146,7 +145,8 @@ public void transferPairSchemaChange() { private NonNullableStructVector populateStructVector(CallBack callBack) { NonNullableStructVector parent = - new NonNullableStructVector("parent", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); + new NonNullableStructVector( + "parent", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack); ComplexWriter writer = new ComplexWriterImpl("root", parent); StructWriter rootWriter = writer.rootAsStruct(); IntWriter intWriter = rootWriter.integer("int"); @@ -163,7 +163,8 @@ private NonNullableStructVector populateStructVector(CallBack callBack) { @Test public void nullableStruct() { - try (NonNullableStructVector structVector = NonNullableStructVector.empty("parent", allocator)) { + try (NonNullableStructVector structVector = + NonNullableStructVector.empty("parent", allocator)) { ComplexWriter writer = new ComplexWriterImpl("root", structVector); StructWriter rootWriter = writer.rootAsStruct(); for (int i = 0; i < COUNT; i++) { @@ -183,11 +184,13 @@ public void nullableStruct() { } /** - * This test is similar to {@link #nullableStruct()} ()} but we get the inner struct writer once at the beginning. + * This test is similar to {@link #nullableStruct()} ()} but we get the inner struct writer once + * at the beginning. */ @Test public void nullableStruct2() { - try (NonNullableStructVector structVector = NonNullableStructVector.empty("parent", allocator)) { + try (NonNullableStructVector structVector = + NonNullableStructVector.empty("parent", allocator)) { ComplexWriter writer = new ComplexWriterImpl("root", structVector); StructWriter rootWriter = writer.rootAsStruct(); StructWriter structWriter = rootWriter.struct("struct"); @@ -337,13 +340,15 @@ public void listDecimalType() { if (j % 4 == 0) { listWriter.writeDecimal(new BigDecimal(j)); } else if (j % 4 == 1) { - DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(j), holder.buffer, 0, DecimalVector.TYPE_WIDTH); + DecimalUtility.writeBigDecimalToArrowBuf( + new BigDecimal(j), holder.buffer, 0, DecimalVector.TYPE_WIDTH); holder.start = 0; holder.scale = 0; holder.precision = 10; listWriter.write(holder); } else if (j % 4 == 2) { - DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(j), holder.buffer, 0, DecimalVector.TYPE_WIDTH); + DecimalUtility.writeBigDecimalToArrowBuf( + new BigDecimal(j), holder.buffer, 0, DecimalVector.TYPE_WIDTH); listWriter.writeDecimal(0, holder.buffer, arrowType); } else { byte[] value = BigDecimal.valueOf(j).unscaledValue().toByteArray(); @@ -507,7 +512,8 @@ public void listScalarTypeNullable() { listReader.setPosition(i); if (i % 2 == 0) { assertTrue("index is set: " + i, listReader.isSet()); - assertEquals("correct length at: " + i, i % 7, ((List) listReader.readObject()).size()); + assertEquals( + "correct length at: " + i, i % 7, ((List) listReader.readObject()).size()); } else { assertFalse("index is not set: " + i, listReader.isSet()); assertNull("index is not set: " + i, listReader.readObject()); @@ -538,7 +544,8 @@ public void listStructType() { listReader.setPosition(i); for (int j = 0; j < i % 7; j++) { listReader.next(); - Assert.assertEquals("record: " + i, j, listReader.reader().reader("int").readInteger().intValue()); + Assert.assertEquals( + "record: " + i, j, listReader.reader().reader("int").readInteger().intValue()); Assert.assertEquals(j, listReader.reader().reader("bigInt").readLong().longValue()); } } @@ -568,7 +575,8 @@ public void listListType() { } /** - * This test is similar to {@link #listListType()} but we get the inner list writer once at the beginning. + * This test is similar to {@link #listListType()} but we get the inner list writer once at the + * beginning. */ @Test public void listListType2() { @@ -635,7 +643,8 @@ public void unionListListType() { } /** - * This test is similar to {@link #unionListListType()} but we get the inner list writer once at the beginning. + * This test is similar to {@link #unionListListType()} but we get the inner list writer once at + * the beginning. */ @Test public void unionListListType2() { @@ -674,7 +683,8 @@ private void checkUnionList(ListVector listVector) { for (int k = 0; k < i % 13; k++) { innerListReader.next(); if (k % 2 == 0) { - Assert.assertEquals("record: " + i, k, innerListReader.reader().readInteger().intValue()); + Assert.assertEquals( + "record: " + i, k, innerListReader.reader().readInteger().intValue()); } else { Assert.assertEquals("record: " + i, k, innerListReader.reader().readLong().longValue()); } @@ -739,7 +749,8 @@ private void checkListMap(ListVector listVector) { @Test public void simpleUnion() throws Exception { List bufs = new ArrayList(); - UnionVector vector = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); + UnionVector vector = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null); UnionWriter unionWriter = new UnionWriter(vector); unionWriter.allocate(); for (int i = 0; i < COUNT; i++) { @@ -846,9 +857,7 @@ public void promotableWriter() { } } - /** - * Even without writing to the writer, the union schema is created correctly. - */ + /** Even without writing to the writer, the union schema is created correctly. */ @Test public void promotableWriterSchema() { try (NonNullableStructVector parent = NonNullableStructVector.empty("parent", allocator)) { @@ -916,14 +925,16 @@ public void structWriterMixedCaseFieldNames() { Assert.assertTrue(fieldNamesCaseSensitive.contains("list_field::$data$::Bit_Field")); // test case-insensitive StructWriter - ComplexWriter writerCaseInsensitive = new ComplexWriterImpl("rootCaseInsensitive", parent, false, false); + ComplexWriter writerCaseInsensitive = + new ComplexWriterImpl("rootCaseInsensitive", parent, false, false); StructWriter rootWriterCaseInsensitive = writerCaseInsensitive.rootAsStruct(); rootWriterCaseInsensitive.bigInt("int_field"); rootWriterCaseInsensitive.bigInt("Int_Field"); rootWriterCaseInsensitive.float4("float_field"); rootWriterCaseInsensitive.float4("Float_Field"); - StructWriter structFieldWriterCaseInsensitive = rootWriterCaseInsensitive.struct("struct_field"); + StructWriter structFieldWriterCaseInsensitive = + rootWriterCaseInsensitive.struct("struct_field"); structFieldWriterCaseInsensitive.varChar("char_field"); structFieldWriterCaseInsensitive.varChar("Char_Field"); ListWriter listFieldWriterCaseInsensitive = rootWriterCaseInsensitive.list("list_field"); @@ -994,9 +1005,10 @@ public void timeStampSecWriter() throws Exception { public void timeStampMilliWriters() throws Exception { // test values final long expectedMillis = 981173106123L; - final LocalDateTime expectedMilliDateTime = LocalDateTime.of(2001, 2, 3, 4, 5, 6, 123 * 1_000_000); + final LocalDateTime expectedMilliDateTime = + LocalDateTime.of(2001, 2, 3, 4, 5, 6, 123 * 1_000_000); - try (NonNullableStructVector parent = NonNullableStructVector.empty("parent", allocator);) { + try (NonNullableStructVector parent = NonNullableStructVector.empty("parent", allocator); ) { // write ComplexWriter writer = new ComplexWriterImpl("root", parent); StructWriter rootWriter = writer.rootAsStruct(); @@ -1050,7 +1062,8 @@ private void checkTimestampTZField(Field field, String name, String tz) { public void timeStampMicroWriters() throws Exception { // test values final long expectedMicros = 981173106123456L; - final LocalDateTime expectedMicroDateTime = LocalDateTime.of(2001, 2, 3, 4, 5, 6, 123456 * 1000); + final LocalDateTime expectedMicroDateTime = + LocalDateTime.of(2001, 2, 3, 4, 5, 6, 123456 * 1000); try (NonNullableStructVector parent = NonNullableStructVector.empty("parent", allocator)) { // write @@ -1140,7 +1153,6 @@ public void timeStampNanoWriters() throws Exception { Assert.assertEquals(expectedNanos, h.value); } } - } @Test @@ -1166,7 +1178,8 @@ public void fixedSizeBinaryWriters() throws Exception { StructWriter rootWriter = writer.rootAsStruct(); String fieldName = "fixedSizeBinary"; - FixedSizeBinaryWriter fixedSizeBinaryWriter = rootWriter.fixedSizeBinary(fieldName, byteWidth); + FixedSizeBinaryWriter fixedSizeBinaryWriter = + rootWriter.fixedSizeBinary(fieldName, byteWidth); for (int i = 0; i < numValues; i++) { fixedSizeBinaryWriter.setPosition(i); fixedSizeBinaryWriter.writeFixedSizeBinary(bufs[i]); @@ -1175,7 +1188,8 @@ public void fixedSizeBinaryWriters() throws Exception { // schema List children = parent.getField().getChildren().get(0).getChildren(); Assert.assertEquals(fieldName, children.get(0).getName()); - Assert.assertEquals(ArrowType.FixedSizeBinary.TYPE_TYPE, children.get(0).getType().getTypeID()); + Assert.assertEquals( + ArrowType.FixedSizeBinary.TYPE_TYPE, children.get(0).getType().getTypeID()); // read StructReader rootReader = new SingleStructReaderImpl(parent).reader("root"); @@ -1335,8 +1349,6 @@ public void testSingleStructWriter1() { } } } - - } @Test @@ -1495,7 +1507,8 @@ public void testListOfListOfListWriterWithNulls() { listReader.reader().reader().next(); Assert.assertEquals(i, listReader.reader().reader().reader().readInteger().intValue()); listReader.reader().reader().next(); - Assert.assertEquals(i * 2, listReader.reader().reader().reader().readInteger().intValue()); + Assert.assertEquals( + i * 2, listReader.reader().reader().reader().readInteger().intValue()); } } } @@ -1685,7 +1698,8 @@ public void structWriterVarCharHelpers() { rootWriter.varChar("c").writeVarChar("row2"); rootWriter.end(); - VarCharVector vector = parent.getChild("root", StructVector.class).getChild("c", VarCharVector.class); + VarCharVector vector = + parent.getChild("root", StructVector.class).getChild("c", VarCharVector.class); assertEquals("row1", vector.getObject(0).toString()); assertEquals("row2", vector.getObject(1).toString()); @@ -1704,8 +1718,8 @@ public void structWriterLargeVarCharHelpers() { rootWriter.largeVarChar("c").writeLargeVarChar("row2"); rootWriter.end(); - LargeVarCharVector vector = parent.getChild("root", StructVector.class).getChild("c", - LargeVarCharVector.class); + LargeVarCharVector vector = + parent.getChild("root", StructVector.class).getChild("c", LargeVarCharVector.class); assertEquals("row1", vector.getObject(0).toString()); assertEquals("row2", vector.getObject(1).toString()); @@ -1725,10 +1739,13 @@ public void structWriterVarBinaryHelpers() { rootWriter.setPosition(2); rootWriter.varBinary("c").writeVarBinary(ByteBuffer.wrap("row3".getBytes())); rootWriter.setPosition(3); - rootWriter.varBinary("c").writeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + rootWriter + .varBinary("c") + .writeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); rootWriter.end(); - VarBinaryVector uv = parent.getChild("root", StructVector.class).getChild("c", VarBinaryVector.class); + VarBinaryVector uv = + parent.getChild("root", StructVector.class).getChild("c", VarBinaryVector.class); assertEquals("row1", new String(uv.get(0))); assertEquals("row2", new String(uv.get(1))); @@ -1746,16 +1763,19 @@ public void structWriterLargeVarBinaryHelpers() { rootWriter.setPosition(0); rootWriter.largeVarBinary("c").writeLargeVarBinary("row1".getBytes()); rootWriter.setPosition(1); - rootWriter.largeVarBinary("c").writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); + rootWriter + .largeVarBinary("c") + .writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); rootWriter.setPosition(2); rootWriter.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes())); rootWriter.setPosition(3); - rootWriter.largeVarBinary("c").writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, - "row4".getBytes().length); + rootWriter + .largeVarBinary("c") + .writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); rootWriter.end(); - LargeVarBinaryVector uv = parent.getChild("root", StructVector.class).getChild("c", - LargeVarBinaryVector.class); + LargeVarBinaryVector uv = + parent.getChild("root", StructVector.class).getChild("c", LargeVarBinaryVector.class); assertEquals("row1", new String(uv.get(0))); assertEquals("row2", new String(uv.get(1))); @@ -1822,7 +1842,8 @@ public void listLargeVarBinaryHelpers() { listWriter.writeLargeVarBinary("row1".getBytes()); listWriter.writeLargeVarBinary("row2".getBytes(), 0, "row2".getBytes().length); listWriter.writeLargeVarBinary(ByteBuffer.wrap("row3".getBytes())); - listWriter.writeLargeVarBinary(ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); + listWriter.writeLargeVarBinary( + ByteBuffer.wrap("row4".getBytes()), 0, "row4".getBytes().length); listWriter.endList(); listWriter.setValueCount(1); assertEquals("row1", new String((byte[]) listVector.getObject(0).get(0))); @@ -1834,7 +1855,8 @@ public void listLargeVarBinaryHelpers() { @Test public void unionWithVarCharAndBinaryHelpers() throws Exception { - try (UnionVector vector = new UnionVector("union", allocator, /* field type */ null, /* call-back */ null)) { + try (UnionVector vector = + new UnionVector("union", allocator, /* field type */ null, /* call-back */ null)) { UnionWriter unionWriter = new UnionWriter(vector); unionWriter.allocate(); unionWriter.start(); @@ -1861,7 +1883,8 @@ public void unionWithVarCharAndBinaryHelpers() throws Exception { unionWriter.setPosition(10); unionWriter.writeLargeVarBinary(ByteBuffer.wrap("row11".getBytes())); unionWriter.setPosition(11); - unionWriter.writeLargeVarBinary(ByteBuffer.wrap("row12".getBytes()), 0, "row12".getBytes().length); + unionWriter.writeLargeVarBinary( + ByteBuffer.wrap("row12".getBytes()), 0, "row12".getBytes().length); unionWriter.end(); assertEquals("row1", new String(vector.getVarCharVector().get(0))); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestSimpleWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestSimpleWriter.java index 27b8f1796ee..0c28c5d6cd2 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestSimpleWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestSimpleWriter.java @@ -18,7 +18,6 @@ package org.apache.arrow.vector.complex.writer; import java.nio.ByteBuffer; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.LargeVarBinaryVector; @@ -52,8 +51,8 @@ public void terminate() throws Exception { @Test public void testWriteByteArrayToVarBinary() throws Exception { try (VarBinaryVector vector = new VarBinaryVector("test", allocator); - VarBinaryWriter writer = new VarBinaryWriterImpl(vector)) { - byte[] input = new byte[] { 0x01, 0x02 }; + VarBinaryWriter writer = new VarBinaryWriterImpl(vector)) { + byte[] input = new byte[] {0x01, 0x02}; writer.writeVarBinary(input); byte[] result = vector.get(0); Assert.assertArrayEquals(input, result); @@ -63,19 +62,19 @@ public void testWriteByteArrayToVarBinary() throws Exception { @Test public void testWriteByteArrayWithOffsetToVarBinary() throws Exception { try (VarBinaryVector vector = new VarBinaryVector("test", allocator); - VarBinaryWriter writer = new VarBinaryWriterImpl(vector)) { - byte[] input = new byte[] { 0x01, 0x02 }; + VarBinaryWriter writer = new VarBinaryWriterImpl(vector)) { + byte[] input = new byte[] {0x01, 0x02}; writer.writeVarBinary(input, 1, 1); byte[] result = vector.get(0); - Assert.assertArrayEquals(new byte[] { 0x02 }, result); + Assert.assertArrayEquals(new byte[] {0x02}, result); } } @Test public void testWriteByteBufferToVarBinary() throws Exception { try (VarBinaryVector vector = new VarBinaryVector("test", allocator); - VarBinaryWriter writer = new VarBinaryWriterImpl(vector)) { - byte[] input = new byte[] { 0x01, 0x02 }; + VarBinaryWriter writer = new VarBinaryWriterImpl(vector)) { + byte[] input = new byte[] {0x01, 0x02}; ByteBuffer buffer = ByteBuffer.wrap(input); writer.writeVarBinary(buffer); byte[] result = vector.get(0); @@ -86,20 +85,20 @@ public void testWriteByteBufferToVarBinary() throws Exception { @Test public void testWriteByteBufferWithOffsetToVarBinary() throws Exception { try (VarBinaryVector vector = new VarBinaryVector("test", allocator); - VarBinaryWriter writer = new VarBinaryWriterImpl(vector)) { - byte[] input = new byte[] { 0x01, 0x02 }; + VarBinaryWriter writer = new VarBinaryWriterImpl(vector)) { + byte[] input = new byte[] {0x01, 0x02}; ByteBuffer buffer = ByteBuffer.wrap(input); writer.writeVarBinary(buffer, 1, 1); byte[] result = vector.get(0); - Assert.assertArrayEquals(new byte[] { 0x02 }, result); + Assert.assertArrayEquals(new byte[] {0x02}, result); } } @Test public void testWriteByteArrayToLargeVarBinary() throws Exception { try (LargeVarBinaryVector vector = new LargeVarBinaryVector("test", allocator); - LargeVarBinaryWriter writer = new LargeVarBinaryWriterImpl(vector)) { - byte[] input = new byte[] { 0x01, 0x02 }; + LargeVarBinaryWriter writer = new LargeVarBinaryWriterImpl(vector)) { + byte[] input = new byte[] {0x01, 0x02}; writer.writeLargeVarBinary(input); byte[] result = vector.get(0); Assert.assertArrayEquals(input, result); @@ -109,19 +108,19 @@ public void testWriteByteArrayToLargeVarBinary() throws Exception { @Test public void testWriteByteArrayWithOffsetToLargeVarBinary() throws Exception { try (LargeVarBinaryVector vector = new LargeVarBinaryVector("test", allocator); - LargeVarBinaryWriter writer = new LargeVarBinaryWriterImpl(vector)) { - byte[] input = new byte[] { 0x01, 0x02 }; + LargeVarBinaryWriter writer = new LargeVarBinaryWriterImpl(vector)) { + byte[] input = new byte[] {0x01, 0x02}; writer.writeLargeVarBinary(input, 1, 1); byte[] result = vector.get(0); - Assert.assertArrayEquals(new byte[] { 0x02 }, result); + Assert.assertArrayEquals(new byte[] {0x02}, result); } } @Test public void testWriteByteBufferToLargeVarBinary() throws Exception { try (LargeVarBinaryVector vector = new LargeVarBinaryVector("test", allocator); - LargeVarBinaryWriter writer = new LargeVarBinaryWriterImpl(vector)) { - byte[] input = new byte[] { 0x01, 0x02 }; + LargeVarBinaryWriter writer = new LargeVarBinaryWriterImpl(vector)) { + byte[] input = new byte[] {0x01, 0x02}; ByteBuffer buffer = ByteBuffer.wrap(input); writer.writeLargeVarBinary(buffer); byte[] result = vector.get(0); @@ -132,19 +131,19 @@ public void testWriteByteBufferToLargeVarBinary() throws Exception { @Test public void testWriteByteBufferWithOffsetToLargeVarBinary() throws Exception { try (LargeVarBinaryVector vector = new LargeVarBinaryVector("test", allocator); - LargeVarBinaryWriter writer = new LargeVarBinaryWriterImpl(vector)) { - byte[] input = new byte[] { 0x01, 0x02 }; + LargeVarBinaryWriter writer = new LargeVarBinaryWriterImpl(vector)) { + byte[] input = new byte[] {0x01, 0x02}; ByteBuffer buffer = ByteBuffer.wrap(input); writer.writeLargeVarBinary(buffer, 1, 1); byte[] result = vector.get(0); - Assert.assertArrayEquals(new byte[] { 0x02 }, result); + Assert.assertArrayEquals(new byte[] {0x02}, result); } } @Test public void testWriteStringToVarChar() throws Exception { try (VarCharVector vector = new VarCharVector("test", allocator); - VarCharWriter writer = new VarCharWriterImpl(vector)) { + VarCharWriter writer = new VarCharWriterImpl(vector)) { String input = "testInput"; writer.writeVarChar(input); String result = vector.getObject(0).toString(); @@ -155,7 +154,7 @@ public void testWriteStringToVarChar() throws Exception { @Test public void testWriteTextToVarChar() throws Exception { try (VarCharVector vector = new VarCharVector("test", allocator); - VarCharWriter writer = new VarCharWriterImpl(vector)) { + VarCharWriter writer = new VarCharWriterImpl(vector)) { String input = "testInput"; writer.writeVarChar(new Text(input)); String result = vector.getObject(0).toString(); @@ -166,7 +165,7 @@ public void testWriteTextToVarChar() throws Exception { @Test public void testWriteStringToLargeVarChar() throws Exception { try (LargeVarCharVector vector = new LargeVarCharVector("test", allocator); - LargeVarCharWriter writer = new LargeVarCharWriterImpl(vector)) { + LargeVarCharWriter writer = new LargeVarCharWriterImpl(vector)) { String input = "testInput"; writer.writeLargeVarChar(input); String result = vector.getObject(0).toString(); @@ -177,7 +176,7 @@ public void testWriteStringToLargeVarChar() throws Exception { @Test public void testWriteTextToLargeVarChar() throws Exception { try (LargeVarCharVector vector = new LargeVarCharVector("test", allocator); - LargeVarCharWriter writer = new LargeVarCharWriterImpl(vector)) { + LargeVarCharWriter writer = new LargeVarCharWriterImpl(vector)) { String input = "testInput"; writer.writeLargeVarChar(new Text(input)); String result = vector.getObject(0).toString(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java index 8663c0c4999..3542689426f 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java @@ -32,7 +32,6 @@ import java.time.ZoneOffset; import java.util.Arrays; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -90,9 +89,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Helps testing the file formats. - */ +/** Helps testing the file formats. */ public class BaseFileTest { private static final Logger LOGGER = LoggerFactory.getLogger(BaseFileTest.class); protected static final int COUNT = 10; @@ -108,13 +105,19 @@ public void tearDown() { allocator.close(); } - - private static short [] uint1Values = new short[]{0, 255, 1, 128, 2}; - private static char [] uint2Values = new char[]{0, Character.MAX_VALUE, 1, Short.MAX_VALUE * 2, 2}; - private static long [] uint4Values = new long[]{0, Integer.MAX_VALUE + 1L, 1, Integer.MAX_VALUE * 2L, 2}; - private static BigInteger[] uint8Values = new BigInteger[]{BigInteger.valueOf(0), - BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)), BigInteger.valueOf(2), - BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(1)), BigInteger.valueOf(2)}; + private static short[] uint1Values = new short[] {0, 255, 1, 128, 2}; + private static char[] uint2Values = + new char[] {0, Character.MAX_VALUE, 1, Short.MAX_VALUE * 2, 2}; + private static long[] uint4Values = + new long[] {0, Integer.MAX_VALUE + 1L, 1, Integer.MAX_VALUE * 2L, 2}; + private static BigInteger[] uint8Values = + new BigInteger[] { + BigInteger.valueOf(0), + BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)), + BigInteger.valueOf(2), + BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(1)), + BigInteger.valueOf(2) + }; protected void writeData(int count, StructVector parent) { ComplexWriter writer = new ComplexWriterImpl("root", parent); @@ -132,11 +135,11 @@ protected void writeData(int count, StructVector parent) { uint1Writer.setPosition(i); // TODO: Fix add safe write methods on uint methods. uint1Writer.setPosition(i); - uint1Writer.writeUInt1((byte) uint1Values[i % uint1Values.length] ); + uint1Writer.writeUInt1((byte) uint1Values[i % uint1Values.length]); uint2Writer.setPosition(i); - uint2Writer.writeUInt2((char) uint2Values[i % uint2Values.length] ); + uint2Writer.writeUInt2((char) uint2Values[i % uint2Values.length]); uint4Writer.setPosition(i); - uint4Writer.writeUInt4((int) uint4Values[i % uint4Values.length] ); + uint4Writer.writeUInt4((int) uint4Values[i % uint4Values.length]); uint8Writer.setPosition(i); uint8Writer.writeUInt8(uint8Values[i % uint8Values.length].longValue()); bigIntWriter.setPosition(i); @@ -147,17 +150,23 @@ protected void writeData(int count, StructVector parent) { writer.setValueCount(count); } - protected void validateContent(int count, VectorSchemaRoot root) { for (int i = 0; i < count; i++) { Assert.assertEquals(i, root.getVector("int").getObject(i)); - Assert.assertEquals((Short) uint1Values[i % uint1Values.length], + Assert.assertEquals( + (Short) uint1Values[i % uint1Values.length], ((UInt1Vector) root.getVector("uint1")).getObjectNoOverflow(i)); - Assert.assertEquals("Failed for index: " + i, (Character) uint2Values[i % uint2Values.length], + Assert.assertEquals( + "Failed for index: " + i, + (Character) uint2Values[i % uint2Values.length], (Character) ((UInt2Vector) root.getVector("uint2")).get(i)); - Assert.assertEquals("Failed for index: " + i, (Long) uint4Values[i % uint4Values.length], + Assert.assertEquals( + "Failed for index: " + i, + (Long) uint4Values[i % uint4Values.length], ((UInt4Vector) root.getVector("uint4")).getObjectNoOverflow(i)); - Assert.assertEquals("Failed for index: " + i, uint8Values[i % uint8Values.length], + Assert.assertEquals( + "Failed for index: " + i, + uint8Values[i % uint8Values.length], ((UInt8Vector) root.getVector("uint8")).getObjectNoOverflow(i)); Assert.assertEquals(Long.valueOf(i), root.getVector("bigInt").getObject(i)); Assert.assertEquals(i == 0 ? Float.NaN : i, root.getVector("float").getObject(i)); @@ -241,27 +250,33 @@ protected void writeDateTimeData(int count, StructVector parent) { DateMilliWriter dateWriter = rootWriter.dateMilli("date"); TimeMilliWriter timeWriter = rootWriter.timeMilli("time"); TimeStampMilliWriter timeStampMilliWriter = rootWriter.timeStampMilli("timestamp-milli"); - TimeStampMilliTZWriter timeStampMilliTZWriter = rootWriter.timeStampMilliTZ("timestamp-milliTZ", "Europe/Paris"); + TimeStampMilliTZWriter timeStampMilliTZWriter = + rootWriter.timeStampMilliTZ("timestamp-milliTZ", "Europe/Paris"); TimeStampNanoWriter timeStampNanoWriter = rootWriter.timeStampNano("timestamp-nano"); for (int i = 0; i < count; i++) { LocalDateTime dt = makeDateTimeFromCount(i); - // Number of days in milliseconds since epoch, stored as 64-bit integer, only date part is used + // Number of days in milliseconds since epoch, stored as 64-bit integer, only date part is + // used dateWriter.setPosition(i); long dateLong = dt.toLocalDate().atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli(); dateWriter.writeDateMilli(dateLong); // Time is a value in milliseconds since midnight, stored as 32-bit integer timeWriter.setPosition(i); - int milliOfDay = (int) java.util.concurrent.TimeUnit.NANOSECONDS.toMillis(dt.toLocalTime().toNanoOfDay()); + int milliOfDay = + (int) java.util.concurrent.TimeUnit.NANOSECONDS.toMillis(dt.toLocalTime().toNanoOfDay()); timeWriter.writeTimeMilli(milliOfDay); // Timestamp as milliseconds since the epoch, stored as 64-bit integer timeStampMilliWriter.setPosition(i); timeStampMilliWriter.writeTimeStampMilli(dt.toInstant(ZoneOffset.UTC).toEpochMilli()); // Timestamp as milliseconds since epoch with timezone timeStampMilliTZWriter.setPosition(i); - timeStampMilliTZWriter.writeTimeStampMilliTZ(dt.atZone(ZoneId.of("Europe/Paris")).toInstant().toEpochMilli()); + timeStampMilliTZWriter.writeTimeStampMilliTZ( + dt.atZone(ZoneId.of("Europe/Paris")).toInstant().toEpochMilli()); // Timestamp as nanoseconds since epoch timeStampNanoWriter.setPosition(i); - long tsNanos = dt.toInstant(ZoneOffset.UTC).toEpochMilli() * 1_000_000 + i; // need to add back in nano val + long tsNanos = + dt.toInstant(ZoneOffset.UTC).toEpochMilli() * 1_000_000 + + i; // need to add back in nano val timeStampNanoWriter.writeTimeStampNano(tsNanos); } writer.setValueCount(count); @@ -281,15 +296,15 @@ protected void validateDateTimeContent(int count, VectorSchemaRoot root) { Object timestampMilliVal = root.getVector("timestamp-milli").getObject(i); Assert.assertEquals(dtMilli, timestampMilliVal); Object timestampMilliTZVal = root.getVector("timestamp-milliTZ").getObject(i); - Assert.assertEquals(dt.atZone(ZoneId.of("Europe/Paris")).toInstant().toEpochMilli(), timestampMilliTZVal); + Assert.assertEquals( + dt.atZone(ZoneId.of("Europe/Paris")).toInstant().toEpochMilli(), timestampMilliTZVal); Object timestampNanoVal = root.getVector("timestamp-nano").getObject(i); Assert.assertEquals(dt, timestampNanoVal); } } protected VectorSchemaRoot writeFlatDictionaryData( - BufferAllocator bufferAllocator, - DictionaryProvider.MapDictionaryProvider provider) { + BufferAllocator bufferAllocator, DictionaryProvider.MapDictionaryProvider provider) { // Define dictionaries and add to provider VarCharVector dictionary1Vector = newVarCharVector("D1", bufferAllocator); @@ -299,7 +314,8 @@ protected VectorSchemaRoot writeFlatDictionaryData( dictionary1Vector.set(2, "baz".getBytes(StandardCharsets.UTF_8)); dictionary1Vector.setValueCount(3); - Dictionary dictionary1 = new Dictionary(dictionary1Vector, new DictionaryEncoding(1L, false, null)); + Dictionary dictionary1 = + new Dictionary(dictionary1Vector, new DictionaryEncoding(1L, false, null)); provider.put(dictionary1); VarCharVector dictionary2Vector = newVarCharVector("D2", bufferAllocator); @@ -309,7 +325,8 @@ protected VectorSchemaRoot writeFlatDictionaryData( dictionary2Vector.set(2, "large".getBytes(StandardCharsets.UTF_8)); dictionary2Vector.setValueCount(3); - Dictionary dictionary2 = new Dictionary(dictionary2Vector, new DictionaryEncoding(2L, false, null)); + Dictionary dictionary2 = + new Dictionary(dictionary2Vector, new DictionaryEncoding(2L, false, null)); provider.put(dictionary2); // Populate the vectors @@ -346,9 +363,11 @@ protected VectorSchemaRoot writeFlatDictionaryData( FieldVector encodedVector2 = (FieldVector) DictionaryEncoder.encode(vector2, dictionary2); vector2.close(); // Done with this vector after encoding - List fields = Arrays.asList(encodedVector1A.getField(), encodedVector1B.getField(), - encodedVector2.getField()); - List vectors = Collections2.asImmutableList(encodedVector1A, encodedVector1B, encodedVector2); + List fields = + Arrays.asList( + encodedVector1A.getField(), encodedVector1B.getField(), encodedVector2.getField()); + List vectors = + Collections2.asImmutableList(encodedVector1A, encodedVector1B, encodedVector2); return new VectorSchemaRoot(fields, vectors, encodedVector1A.getValueCount()); } @@ -418,8 +437,7 @@ protected void validateFlatDictionary(VectorSchemaRoot root, DictionaryProvider } protected VectorSchemaRoot writeNestedDictionaryData( - BufferAllocator bufferAllocator, - DictionaryProvider.MapDictionaryProvider provider) { + BufferAllocator bufferAllocator, DictionaryProvider.MapDictionaryProvider provider) { // Define the dictionary and add to the provider VarCharVector dictionaryVector = newVarCharVector("D2", bufferAllocator); @@ -428,7 +446,8 @@ protected VectorSchemaRoot writeNestedDictionaryData( dictionaryVector.set(1, "bar".getBytes(StandardCharsets.UTF_8)); dictionaryVector.setValueCount(2); - Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(2L, false, null)); + Dictionary dictionary = + new Dictionary(dictionaryVector, new DictionaryEncoding(2L, false, null)); provider.put(dictionary); // Write the vector data using dictionary indices @@ -498,9 +517,11 @@ protected VectorSchemaRoot writeDecimalData(BufferAllocator bufferAllocator) { decimalVector2.setValueCount(count); decimalVector3.setValueCount(count); - List fields = Collections2.asImmutableList(decimalVector1.getField(), decimalVector2.getField(), - decimalVector3.getField()); - List vectors = Collections2.asImmutableList(decimalVector1, decimalVector2, decimalVector3); + List fields = + Collections2.asImmutableList( + decimalVector1.getField(), decimalVector2.getField(), decimalVector3.getField()); + List vectors = + Collections2.asImmutableList(decimalVector1, decimalVector2, decimalVector3); return new VectorSchemaRoot(fields, vectors, count); } @@ -538,7 +559,8 @@ protected VectorSchemaRoot writeNullData(int valueCount) { nullVector1.setValueCount(valueCount); nullVector2.setValueCount(valueCount); - List fields = Collections2.asImmutableList(nullVector1.getField(), nullVector2.getField()); + List fields = + Collections2.asImmutableList(nullVector1.getField(), nullVector2.getField()); List vectors = Collections2.asImmutableList(nullVector1, nullVector2); return new VectorSchemaRoot(fields, vectors, valueCount); } @@ -669,7 +691,8 @@ protected void validateVarBinary(int count, VectorSchemaRoot root) { Assert.assertEquals(binaryVector.getLastSet(), numVarBinaryValues - 1); } - protected void writeBatchData(ArrowWriter writer, IntVector vector, VectorSchemaRoot root) throws IOException { + protected void writeBatchData(ArrowWriter writer, IntVector vector, VectorSchemaRoot root) + throws IOException { writer.start(); vector.setNull(0); @@ -752,7 +775,8 @@ protected VectorSchemaRoot writeMapData(BufferAllocator bufferAllocator) { mapWriter.setValueCount(COUNT); sortedMapWriter.setValueCount(COUNT); - List fields = Collections2.asImmutableList(mapVector.getField(), sortedMapVector.getField()); + List fields = + Collections2.asImmutableList(mapVector.getField(), sortedMapVector.getField()); List vectors = Collections2.asImmutableList(mapVector, sortedMapVector); return new VectorSchemaRoot(fields, vectors, count); } @@ -801,9 +825,12 @@ protected VectorSchemaRoot writeListAsMapData(BufferAllocator bufferAllocator) { ListVector mapEntryList = ListVector.empty("entryList", bufferAllocator); FieldType mapEntryType = new FieldType(false, ArrowType.Struct.INSTANCE, null, null); StructVector mapEntryData = new StructVector("entryData", bufferAllocator, mapEntryType, null); - mapEntryData.addOrGet("myKey", new FieldType(false, new ArrowType.Int(64, true), null), BigIntVector.class); - mapEntryData.addOrGet("myValue", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); - mapEntryList.initializeChildrenFromFields(Collections2.asImmutableList(mapEntryData.getField())); + mapEntryData.addOrGet( + "myKey", new FieldType(false, new ArrowType.Int(64, true), null), BigIntVector.class); + mapEntryData.addOrGet( + "myValue", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); + mapEntryList.initializeChildrenFromFields( + Collections2.asImmutableList(mapEntryData.getField())); UnionListWriter entryWriter = mapEntryList.getWriter(); entryWriter.allocate(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/ITTestIPCWithLargeArrowBuffers.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/ITTestIPCWithLargeArrowBuffers.java index d3c91fd1443..b93b8260472 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/ITTestIPCWithLargeArrowBuffers.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/ITTestIPCWithLargeArrowBuffers.java @@ -28,7 +28,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.Map; - import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BigIntVector; import org.apache.arrow.vector.IntVector; @@ -45,14 +44,14 @@ import org.slf4j.LoggerFactory; /** - * Integration test for reading/writing {@link org.apache.arrow.vector.VectorSchemaRoot} with - * large (more than 2GB) buffers by {@link ArrowReader} and {@link ArrowWriter}.. - * To run this test, please make sure there is at least 8GB free memory, and 8GB - * free.disk space in the system. + * Integration test for reading/writing {@link org.apache.arrow.vector.VectorSchemaRoot} with large + * (more than 2GB) buffers by {@link ArrowReader} and {@link ArrowWriter}.. To run this test, please + * make sure there is at least 8GB free memory, and 8GB free.disk space in the system. */ public class ITTestIPCWithLargeArrowBuffers { - private static final Logger logger = LoggerFactory.getLogger(ITTestIPCWithLargeArrowBuffers.class); + private static final Logger logger = + LoggerFactory.getLogger(ITTestIPCWithLargeArrowBuffers.class); // 4GB buffer size static final long BUFFER_SIZE = 4 * 1024 * 1024 * 1024L; @@ -78,12 +77,13 @@ public class ITTestIPCWithLargeArrowBuffers { private void testWriteLargeArrowData(boolean streamMode) throws IOException { // simulate encoding big int as int try (RootAllocator allocator = new RootAllocator(Long.MAX_VALUE); - BigIntVector dictVector = new BigIntVector("dic vector", allocator); - FileOutputStream out = new FileOutputStream(FILE_NAME); - IntVector encodedVector = (IntVector) ENCODED_VECTOR_FIELD.createVector(allocator)) { + BigIntVector dictVector = new BigIntVector("dic vector", allocator); + FileOutputStream out = new FileOutputStream(FILE_NAME); + IntVector encodedVector = (IntVector) ENCODED_VECTOR_FIELD.createVector(allocator)) { // prepare dictionary provider. - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); Dictionary dictionary = new Dictionary(dictVector, DICTIONARY_ENCODING); provider.put(dictionary); @@ -107,11 +107,14 @@ private void testWriteLargeArrowData(boolean streamMode) throws IOException { // build vector schema root and write data. try (VectorSchemaRoot root = - new VectorSchemaRoot( - Arrays.asList(ENCODED_VECTOR_FIELD), Arrays.asList(encodedVector), ENCODED_VECTOR_SIZE); - ArrowWriter writer = streamMode ? - new ArrowStreamWriter(root, provider, out) : - new ArrowFileWriter(root, provider, out.getChannel())) { + new VectorSchemaRoot( + Arrays.asList(ENCODED_VECTOR_FIELD), + Arrays.asList(encodedVector), + ENCODED_VECTOR_SIZE); + ArrowWriter writer = + streamMode + ? new ArrowStreamWriter(root, provider, out) + : new ArrowFileWriter(root, provider, out.getChannel())) { writer.start(); writer.writeBatch(); writer.end(); @@ -124,10 +127,11 @@ private void testWriteLargeArrowData(boolean streamMode) throws IOException { private void testReadLargeArrowData(boolean streamMode) throws IOException { try (RootAllocator allocator = new RootAllocator(Long.MAX_VALUE); - FileInputStream in = new FileInputStream(FILE_NAME); - ArrowReader reader = streamMode ? - new ArrowStreamReader(in, allocator) : - new ArrowFileReader(in.getChannel(), allocator)) { + FileInputStream in = new FileInputStream(FILE_NAME); + ArrowReader reader = + streamMode + ? new ArrowStreamReader(in, allocator) + : new ArrowFileReader(in.getChannel(), allocator)) { // verify schema Schema readSchema = reader.getVectorSchemaRoot().getSchema(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/MessageSerializerTest.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/MessageSerializerTest.java index 79a4b249a8a..b2f113920df 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/MessageSerializerTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/MessageSerializerTest.java @@ -33,7 +33,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -74,7 +73,7 @@ private int intToByteRoundtrip(int v, byte[] bytes) { @Test public void testIntToBytes() { byte[] bytes = new byte[4]; - int[] values = new int[]{1, 15, 1 << 8, 1 << 16, Integer.MAX_VALUE}; + int[] values = new int[] {1, 15, 1 << 8, 1 << 16, Integer.MAX_VALUE}; for (int v : values) { assertEquals(intToByteRoundtrip(v, bytes), v); } @@ -129,13 +128,12 @@ public void testWriteMessageBufferAligned() throws IOException { public void testSchemaMessageSerialization() throws IOException { Schema schema = testSchema(); ByteArrayOutputStream out = new ByteArrayOutputStream(); - long size = MessageSerializer.serialize( - new WriteChannel(Channels.newChannel(out)), schema); + long size = MessageSerializer.serialize(new WriteChannel(Channels.newChannel(out)), schema); assertEquals(size, out.toByteArray().length); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - Schema deserialized = MessageSerializer.deserializeSchema( - new ReadChannel(Channels.newChannel(in))); + Schema deserialized = + MessageSerializer.deserializeSchema(new ReadChannel(Channels.newChannel(in))); assertEquals(schema, deserialized); assertEquals(1, deserialized.getFields().size()); } @@ -143,32 +141,33 @@ public void testSchemaMessageSerialization() throws IOException { @Test public void testSchemaDictionaryMessageSerialization() throws IOException { DictionaryEncoding dictionary = new DictionaryEncoding(9L, false, new ArrowType.Int(8, true)); - Field field = new Field("test", new FieldType(true, ArrowType.Utf8.INSTANCE, dictionary, null), null); + Field field = + new Field("test", new FieldType(true, ArrowType.Utf8.INSTANCE, dictionary, null), null); Schema schema = new Schema(Collections.singletonList(field)); ByteArrayOutputStream out = new ByteArrayOutputStream(); long size = MessageSerializer.serialize(new WriteChannel(Channels.newChannel(out)), schema); assertEquals(size, out.toByteArray().length); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - Schema deserialized = MessageSerializer.deserializeSchema(new ReadChannel(Channels.newChannel(in))); + Schema deserialized = + MessageSerializer.deserializeSchema(new ReadChannel(Channels.newChannel(in))); assertEquals(schema, deserialized); } - @Rule - public ExpectedException expectedEx = ExpectedException.none(); + @Rule public ExpectedException expectedEx = ExpectedException.none(); @Test public void testSerializeRecordBatchV4() throws IOException { - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; // second half is "undefined" - byte[] values = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + byte[] values = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; BufferAllocator alloc = new RootAllocator(Long.MAX_VALUE); ArrowBuf validityb = buf(alloc, validity); ArrowBuf valuesb = buf(alloc, values); - ArrowRecordBatch batch = new ArrowRecordBatch( - 16, asList(new ArrowFieldNode(16, 8)), asList(validityb, valuesb)); + ArrowRecordBatch batch = + new ArrowRecordBatch(16, asList(new ArrowFieldNode(16, 8)), asList(validityb, valuesb)); // avoid writing legacy ipc format by default IpcOption option = new IpcOption(false, MetadataVersion.V4); @@ -184,16 +183,16 @@ public void testSerializeRecordBatchV4() throws IOException { @Test public void testSerializeRecordBatchV5() throws Exception { - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; // second half is "undefined" - byte[] values = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + byte[] values = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; BufferAllocator alloc = new RootAllocator(Long.MAX_VALUE); ArrowBuf validityb = buf(alloc, validity); ArrowBuf valuesb = buf(alloc, values); - ArrowRecordBatch batch = new ArrowRecordBatch( - 16, asList(new ArrowFieldNode(16, 8)), asList(validityb, valuesb)); + ArrowRecordBatch batch = + new ArrowRecordBatch(16, asList(new ArrowFieldNode(16, 8)), asList(validityb, valuesb)); // avoid writing legacy ipc format by default IpcOption option = new IpcOption(false, MetadataVersion.V5); @@ -214,20 +213,25 @@ public void testSerializeRecordBatchV5() throws Exception { { byte[] validBytes = out.toByteArray(); - byte[] missingBytes = Arrays.copyOfRange(validBytes, /*from=*/0, validBytes.length - 1); + byte[] missingBytes = Arrays.copyOfRange(validBytes, /* from= */ 0, validBytes.length - 1); ByteArrayInputStream in = new ByteArrayInputStream(missingBytes); ReadChannel channel = new ReadChannel(Channels.newChannel(in)); - assertThrows(IOException.class, () -> MessageSerializer.deserializeMessageBatch(channel, alloc)); + assertThrows( + IOException.class, () -> MessageSerializer.deserializeMessageBatch(channel, alloc)); } alloc.close(); } public static Schema testSchema() { - return new Schema(asList(new Field( - "testField", FieldType.nullable(new ArrowType.Int(8, true)), Collections.emptyList()))); + return new Schema( + asList( + new Field( + "testField", + FieldType.nullable(new ArrowType.Int(8, true)), + Collections.emptyList()))); } // Verifies batch contents matching test schema. @@ -243,5 +247,4 @@ public static void verifyBatch(ArrowRecordBatch batch, byte[] validity, byte[] v assertArrayEquals(validity, MessageSerializerTest.array(buffers.get(0))); assertArrayEquals(values, MessageSerializerTest.array(buffers.get(1))); } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowFile.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowFile.java index 4fb58227860..bebe18940ea 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowFile.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowFile.java @@ -31,7 +31,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.Collections2; import org.apache.arrow.vector.FieldVector; @@ -50,8 +49,8 @@ public class TestArrowFile extends BaseFileTest { public void testWrite() throws IOException { File file = new File("target/mytest_write.arrow"); int count = COUNT; - try ( - BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); StructVector parent = StructVector.empty("parent", vectorAllocator)) { writeData(count, parent); write(parent.getChild("root"), file, new ByteArrayOutputStream()); @@ -62,8 +61,8 @@ public void testWrite() throws IOException { public void testWriteComplex() throws IOException { File file = new File("target/mytest_write_complex.arrow"); int count = COUNT; - try ( - BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); StructVector parent = StructVector.empty("parent", vectorAllocator)) { writeComplexData(count, parent); FieldVector root = parent.getChild("root"); @@ -73,14 +72,15 @@ public void testWriteComplex() throws IOException { } /** - * Writes the contents of parents to file. If outStream is non-null, also writes it - * to outStream in the streaming serialized format. + * Writes the contents of parents to file. If outStream is non-null, also writes it to outStream + * in the streaming serialized format. */ private void write(FieldVector parent, File file, OutputStream outStream) throws IOException { VectorSchemaRoot root = new VectorSchemaRoot(parent); try (FileOutputStream fileOutputStream = new FileOutputStream(file); - ArrowFileWriter arrowWriter = new ArrowFileWriter(root, null, fileOutputStream.getChannel());) { + ArrowFileWriter arrowWriter = + new ArrowFileWriter(root, null, fileOutputStream.getChannel()); ) { LOGGER.debug("writing schema: " + root.getSchema()); arrowWriter.start(); arrowWriter.writeBatch(); @@ -124,7 +124,8 @@ public void testFileStreamHasEos() throws IOException { byte[] bytesWithoutMagic = new byte[bytes.length - 8]; System.arraycopy(bytes, 8, bytesWithoutMagic, 0, bytesWithoutMagic.length); - try (ArrowStreamReader reader = new ArrowStreamReader(new ByteArrayInputStream(bytesWithoutMagic), allocator)) { + try (ArrowStreamReader reader = + new ArrowStreamReader(new ByteArrayInputStream(bytesWithoutMagic), allocator)) { assertTrue(reader.loadNextBatch()); // here will throw exception if read footer instead of eos. assertFalse(reader.loadNextBatch()); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowFooter.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowFooter.java index 38c65bddedd..6b6d68e604f 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowFooter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowFooter.java @@ -20,11 +20,11 @@ import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; +import com.google.flatbuffers.FlatBufferBuilder; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.List; - import org.apache.arrow.flatbuf.Footer; import org.apache.arrow.vector.ipc.message.ArrowBlock; import org.apache.arrow.vector.ipc.message.ArrowFooter; @@ -34,17 +34,20 @@ import org.apache.arrow.vector.types.pojo.Schema; import org.junit.Test; -import com.google.flatbuffers.FlatBufferBuilder; - public class TestArrowFooter { @Test public void test() { - Schema schema = new Schema(asList( - new Field("a", FieldType.nullable(new ArrowType.Int(8, true)), Collections.emptyList()) - )); + Schema schema = + new Schema( + asList( + new Field( + "a", + FieldType.nullable(new ArrowType.Int(8, true)), + Collections.emptyList()))); ArrowFooter footer = - new ArrowFooter(schema, Collections.emptyList(), Collections.emptyList()); + new ArrowFooter( + schema, Collections.emptyList(), Collections.emptyList()); ArrowFooter newFooter = roundTrip(footer); assertEquals(footer, newFooter); @@ -55,7 +58,6 @@ public void test() { assertEquals(footer, roundTrip(footer)); } - private ArrowFooter roundTrip(ArrowFooter footer) { FlatBufferBuilder builder = new FlatBufferBuilder(); int i = footer.writeTo(builder); @@ -64,5 +66,4 @@ private ArrowFooter roundTrip(ArrowFooter footer) { ArrowFooter newFooter = new ArrowFooter(Footer.getRootAsFooter(dataBuffer)); return newFooter; } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowReaderWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowReaderWriter.java index 07875b25029..5abe0993488 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowReaderWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowReaderWriter.java @@ -45,7 +45,6 @@ import java.util.Map; import java.util.function.BiFunction; import java.util.stream.Collectors; - import org.apache.arrow.flatbuf.FieldNode; import org.apache.arrow.flatbuf.Message; import org.apache.arrow.flatbuf.RecordBatch; @@ -114,40 +113,51 @@ public void init() { allocator = new RootAllocator(Long.MAX_VALUE); dictionaryVector1 = newVarCharVector("D1", allocator); - setVector(dictionaryVector1, + setVector( + dictionaryVector1, "foo".getBytes(StandardCharsets.UTF_8), "bar".getBytes(StandardCharsets.UTF_8), "baz".getBytes(StandardCharsets.UTF_8)); dictionaryVector2 = newVarCharVector("D2", allocator); - setVector(dictionaryVector2, + setVector( + dictionaryVector2, "aa".getBytes(StandardCharsets.UTF_8), "bb".getBytes(StandardCharsets.UTF_8), "cc".getBytes(StandardCharsets.UTF_8)); dictionaryVector3 = newVarCharVector("D3", allocator); - setVector(dictionaryVector3, + setVector( + dictionaryVector3, "foo".getBytes(StandardCharsets.UTF_8), "bar".getBytes(StandardCharsets.UTF_8), "baz".getBytes(StandardCharsets.UTF_8), "aa".getBytes(StandardCharsets.UTF_8), "bb".getBytes(StandardCharsets.UTF_8), "cc".getBytes(StandardCharsets.UTF_8)); - + dictionaryVector4 = newVector(StructVector.class, "D4", MinorType.STRUCT, allocator); final Map> dictionaryValues4 = new HashMap<>(); dictionaryValues4.put("a", Arrays.asList(1, 2, 3)); dictionaryValues4.put("b", Arrays.asList(4, 5, 6)); setVector(dictionaryVector4, dictionaryValues4); - dictionary1 = new Dictionary(dictionaryVector1, - new DictionaryEncoding(/*id=*/1L, /*ordered=*/false, /*indexType=*/null)); - dictionary2 = new Dictionary(dictionaryVector2, - new DictionaryEncoding(/*id=*/2L, /*ordered=*/false, /*indexType=*/null)); - dictionary3 = new Dictionary(dictionaryVector3, - new DictionaryEncoding(/*id=*/1L, /*ordered=*/false, /*indexType=*/null)); - dictionary4 = new Dictionary(dictionaryVector4, - new DictionaryEncoding(/*id=*/3L, /*ordered=*/false, /*indexType=*/null)); + dictionary1 = + new Dictionary( + dictionaryVector1, + new DictionaryEncoding(/* id= */ 1L, /* ordered= */ false, /* indexType= */ null)); + dictionary2 = + new Dictionary( + dictionaryVector2, + new DictionaryEncoding(/* id= */ 2L, /* ordered= */ false, /* indexType= */ null)); + dictionary3 = + new Dictionary( + dictionaryVector3, + new DictionaryEncoding(/* id= */ 1L, /* ordered= */ false, /* indexType= */ null)); + dictionary4 = + new Dictionary( + dictionaryVector4, + new DictionaryEncoding(/* id= */ 3L, /* ordered= */ false, /* indexType= */ null)); } @After @@ -173,8 +183,13 @@ byte[] array(ArrowBuf buf) { @Test public void test() throws IOException { - Schema schema = new Schema(asList(new Field("testField", FieldType.nullable(new ArrowType.Int(8, true)), - Collections.emptyList()))); + Schema schema = + new Schema( + asList( + new Field( + "testField", + FieldType.nullable(new ArrowType.Int(8, true)), + Collections.emptyList()))); ArrowType type = schema.getFields().get(0).getType(); FieldVector vector = TestUtils.newVector(FieldVector.class, "testField", type, allocator); vector.initializeChildrenFromFields(schema.getFields().get(0).getChildren()); @@ -185,10 +200,11 @@ public void test() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); try (VectorSchemaRoot root = new VectorSchemaRoot(schema.getFields(), asList(vector), 16); - ArrowFileWriter writer = new ArrowFileWriter(root, null, newChannel(out))) { + ArrowFileWriter writer = new ArrowFileWriter(root, null, newChannel(out))) { ArrowBuf validityb = buf(validity); ArrowBuf valuesb = buf(values); - ArrowRecordBatch batch = new ArrowRecordBatch(16, asList(new ArrowFieldNode(16, 8)), asList(validityb, valuesb)); + ArrowRecordBatch batch = + new ArrowRecordBatch(16, asList(new ArrowFieldNode(16, 8)), asList(validityb, valuesb)); VectorLoader loader = new VectorLoader(root); loader.load(batch); writer.writeBatch(); @@ -200,8 +216,9 @@ public void test() throws IOException { byte[] byteArray = out.toByteArray(); - try (SeekableReadChannel channel = new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(byteArray)); - ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { + try (SeekableReadChannel channel = + new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(byteArray)); + ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { Schema readSchema = reader.getVectorSchemaRoot().getSchema(); assertEquals(schema, readSchema); // TODO: dictionaries @@ -249,11 +266,12 @@ public void testWriteReadNullVector() throws IOException { Schema schema = new Schema(asList(nullVector.getField())); ByteArrayOutputStream out = new ByteArrayOutputStream(); - try (VectorSchemaRoot root = new VectorSchemaRoot(schema.getFields(), asList(nullVector), valueCount); + try (VectorSchemaRoot root = + new VectorSchemaRoot(schema.getFields(), asList(nullVector), valueCount); ArrowFileWriter writer = new ArrowFileWriter(root, null, newChannel(out))) { - ArrowRecordBatch batch = new ArrowRecordBatch(valueCount, - asList(new ArrowFieldNode(valueCount, 0)), - Collections.emptyList()); + ArrowRecordBatch batch = + new ArrowRecordBatch( + valueCount, asList(new ArrowFieldNode(valueCount, 0)), Collections.emptyList()); VectorLoader loader = new VectorLoader(root); loader.load(batch); writer.writeBatch(); @@ -261,7 +279,8 @@ public void testWriteReadNullVector() throws IOException { byte[] byteArray = out.toByteArray(); - try (SeekableReadChannel channel = new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(byteArray)); + try (SeekableReadChannel channel = + new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(byteArray)); ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { Schema readSchema = reader.getVectorSchemaRoot().getSchema(); assertEquals(schema, readSchema); @@ -271,14 +290,16 @@ public void testWriteReadNullVector() throws IOException { assertTrue(reader.loadNextBatch()); assertEquals(1, reader.getVectorSchemaRoot().getFieldVectors().size()); - NullVector readNullVector = (NullVector) reader.getVectorSchemaRoot().getFieldVectors().get(0); + NullVector readNullVector = + (NullVector) reader.getVectorSchemaRoot().getFieldVectors().get(0); assertEquals(valueCount, readNullVector.getValueCount()); } } @Test public void testWriteReadWithDictionaries() throws IOException { - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); provider.put(dictionary1); VarCharVector vector1 = newVarCharVector("varchar1", allocator); @@ -306,16 +327,17 @@ public void testWriteReadWithDictionaries() throws IOException { List fields = Arrays.asList(encodedVector1.getField(), encodedVector2.getField()); List vectors = Collections2.asImmutableList(encodedVector1, encodedVector2); - try (VectorSchemaRoot root = new VectorSchemaRoot(fields, vectors, encodedVector1.getValueCount()); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ArrowFileWriter writer = new ArrowFileWriter(root, provider, newChannel(out));) { + try (VectorSchemaRoot root = + new VectorSchemaRoot(fields, vectors, encodedVector1.getValueCount()); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ArrowFileWriter writer = new ArrowFileWriter(root, provider, newChannel(out)); ) { writer.start(); writer.writeBatch(); writer.end(); - try (SeekableReadChannel channel = new SeekableReadChannel( - new ByteArrayReadableSeekableByteChannel(out.toByteArray())); + try (SeekableReadChannel channel = + new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(out.toByteArray())); ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { Schema readSchema = reader.getVectorSchemaRoot().getSchema(); assertEquals(root.getSchema(), readSchema); @@ -345,19 +367,18 @@ public void testWriteReadWithStructDictionaries() throws IOException { List fields = Arrays.asList(encodedVector.getField()); List vectors = Collections2.asImmutableList(encodedVector); - try ( - VectorSchemaRoot root = + try (VectorSchemaRoot root = new VectorSchemaRoot(fields, vectors, encodedVector.getValueCount()); ByteArrayOutputStream out = new ByteArrayOutputStream(); - ArrowFileWriter writer = new ArrowFileWriter(root, provider, newChannel(out));) { + ArrowFileWriter writer = new ArrowFileWriter(root, provider, newChannel(out)); ) { writer.start(); writer.writeBatch(); writer.end(); - try ( - SeekableReadChannel channel = new SeekableReadChannel( - new ByteArrayReadableSeekableByteChannel(out.toByteArray())); + try (SeekableReadChannel channel = + new SeekableReadChannel( + new ByteArrayReadableSeekableByteChannel(out.toByteArray())); ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { final VectorSchemaRoot readRoot = reader.getVectorSchemaRoot(); final Schema readSchema = readRoot.getSchema(); @@ -372,8 +393,9 @@ public void testWriteReadWithStructDictionaries() throws IOException { // Read the encoded vector and check it final FieldVector readEncoded = readRoot.getVector(0); assertEquals(encodedVector.getValueCount(), readEncoded.getValueCount()); - assertTrue(new RangeEqualsVisitor(encodedVector, readEncoded) - .rangeEquals(new Range(0, 0, encodedVector.getValueCount()))); + assertTrue( + new RangeEqualsVisitor(encodedVector, readEncoded) + .rangeEquals(new Range(0, 0, encodedVector.getValueCount()))); // Read the dictionary final Map readDictionaryMap = reader.getDictionaryVectors(); @@ -386,16 +408,18 @@ public void testWriteReadWithStructDictionaries() throws IOException { assertEquals(dictionaryVector4.getValueCount(), readDictionaryVector.getValueCount()); final BiFunction typeComparatorIgnoreName = (v1, v2) -> new TypeEqualsVisitor(v1, false, true).equals(v2); - assertTrue("Dictionary vectors are not equal", - new RangeEqualsVisitor(dictionaryVector4, readDictionaryVector, - typeComparatorIgnoreName) - .rangeEquals(new Range(0, 0, dictionaryVector4.getValueCount()))); + assertTrue( + "Dictionary vectors are not equal", + new RangeEqualsVisitor( + dictionaryVector4, readDictionaryVector, typeComparatorIgnoreName) + .rangeEquals(new Range(0, 0, dictionaryVector4.getValueCount()))); // Assert the decoded vector is correct try (final ValueVector readVector = DictionaryEncoder.decode(readEncoded, readDictionary)) { assertEquals(vector.getValueCount(), readVector.getValueCount()); - assertTrue("Decoded vectors are not equal", + assertTrue( + "Decoded vectors are not equal", new RangeEqualsVisitor(vector, readVector, typeComparatorIgnoreName) .rangeEquals(new Range(0, 0, vector.getValueCount()))); } @@ -407,7 +431,8 @@ public void testWriteReadWithStructDictionaries() throws IOException { @Test public void testEmptyStreamInFileIPC() throws IOException { - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); provider.put(dictionary1); VarCharVector vector = newVarCharVector("varchar", allocator); @@ -425,16 +450,17 @@ public void testEmptyStreamInFileIPC() throws IOException { List fields = Arrays.asList(encodedVector1A.getField()); List vectors = Collections2.asImmutableList(encodedVector1A); - try (VectorSchemaRoot root = new VectorSchemaRoot(fields, vectors, encodedVector1A.getValueCount()); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ArrowFileWriter writer = new ArrowFileWriter(root, provider, newChannel(out))) { + try (VectorSchemaRoot root = + new VectorSchemaRoot(fields, vectors, encodedVector1A.getValueCount()); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ArrowFileWriter writer = new ArrowFileWriter(root, provider, newChannel(out))) { writer.start(); writer.end(); - try (SeekableReadChannel channel = new SeekableReadChannel( - new ByteArrayReadableSeekableByteChannel(out.toByteArray())); - ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { + try (SeekableReadChannel channel = + new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(out.toByteArray())); + ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { Schema readSchema = reader.getVectorSchemaRoot().getSchema(); assertEquals(root.getSchema(), readSchema); assertEquals(1, reader.getDictionaryVectors().size()); @@ -442,13 +468,13 @@ public void testEmptyStreamInFileIPC() throws IOException { assertEquals(0, reader.getRecordBlocks().size()); } } - } @Test public void testEmptyStreamInStreamingIPC() throws IOException { - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); provider.put(dictionary1); VarCharVector vector = newVarCharVector("varchar", allocator); @@ -465,29 +491,30 @@ public void testEmptyStreamInStreamingIPC() throws IOException { List fields = Arrays.asList(encodedVector.getField()); try (VectorSchemaRoot root = - new VectorSchemaRoot(fields, Arrays.asList(encodedVector), encodedVector.getValueCount()); + new VectorSchemaRoot( + fields, Arrays.asList(encodedVector), encodedVector.getValueCount()); ByteArrayOutputStream out = new ByteArrayOutputStream(); ArrowStreamWriter writer = new ArrowStreamWriter(root, provider, newChannel(out))) { writer.start(); writer.end(); - - try (ArrowStreamReader reader = new ArrowStreamReader( - new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator)) { + try (ArrowStreamReader reader = + new ArrowStreamReader( + new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator)) { Schema readSchema = reader.getVectorSchemaRoot().getSchema(); assertEquals(root.getSchema(), readSchema); assertEquals(1, reader.getDictionaryVectors().size()); assertFalse(reader.loadNextBatch()); } } - } @Test public void testDictionaryReplacement() throws Exception { VarCharVector vector1 = newVarCharVector("varchar1", allocator); - setVector(vector1, + setVector( + vector1, "foo".getBytes(StandardCharsets.UTF_8), "bar".getBytes(StandardCharsets.UTF_8), "baz".getBytes(StandardCharsets.UTF_8), @@ -496,7 +523,8 @@ public void testDictionaryReplacement() throws Exception { FieldVector encodedVector1 = (FieldVector) DictionaryEncoder.encode(vector1, dictionary1); VarCharVector vector2 = newVarCharVector("varchar2", allocator); - setVector(vector2, + setVector( + vector2, "foo".getBytes(StandardCharsets.UTF_8), "foo".getBytes(StandardCharsets.UTF_8), "foo".getBytes(StandardCharsets.UTF_8), @@ -504,11 +532,14 @@ public void testDictionaryReplacement() throws Exception { FieldVector encodedVector2 = (FieldVector) DictionaryEncoder.encode(vector2, dictionary1); - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); provider.put(dictionary1); List schemaFields = new ArrayList<>(); - schemaFields.add(DictionaryUtility.toMessageFormat(encodedVector1.getField(), provider, new HashSet<>())); - schemaFields.add(DictionaryUtility.toMessageFormat(encodedVector2.getField(), provider, new HashSet<>())); + schemaFields.add( + DictionaryUtility.toMessageFormat(encodedVector1.getField(), provider, new HashSet<>())); + schemaFields.add( + DictionaryUtility.toMessageFormat(encodedVector2.getField(), provider, new HashSet<>())); Schema schema = new Schema(schemaFields); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); @@ -531,8 +562,9 @@ public void testDictionaryReplacement() throws Exception { // write eos out.writeIntLittleEndian(0); - try (ArrowStreamReader reader = new ArrowStreamReader( - new ByteArrayReadableSeekableByteChannel(outStream.toByteArray()), allocator)) { + try (ArrowStreamReader reader = + new ArrowStreamReader( + new ByteArrayReadableSeekableByteChannel(outStream.toByteArray()), allocator)) { assertEquals(1, reader.getDictionaryVectors().size()); assertTrue(reader.loadNextBatch()); FieldVector dictionaryVector = reader.getDictionaryVectors().get(1L).getVector(); @@ -549,7 +581,8 @@ public void testDictionaryReplacement() throws Exception { @Test public void testDeltaDictionary() throws Exception { VarCharVector vector1 = newVarCharVector("varchar1", allocator); - setVector(vector1, + setVector( + vector1, "foo".getBytes(StandardCharsets.UTF_8), "bar".getBytes(StandardCharsets.UTF_8), "baz".getBytes(StandardCharsets.UTF_8), @@ -558,7 +591,8 @@ public void testDeltaDictionary() throws Exception { FieldVector encodedVector1 = (FieldVector) DictionaryEncoder.encode(vector1, dictionary1); VarCharVector vector2 = newVarCharVector("varchar2", allocator); - setVector(vector2, + setVector( + vector2, "foo".getBytes(StandardCharsets.UTF_8), "aa".getBytes(StandardCharsets.UTF_8), "bb".getBytes(StandardCharsets.UTF_8), @@ -566,12 +600,15 @@ public void testDeltaDictionary() throws Exception { FieldVector encodedVector2 = (FieldVector) DictionaryEncoder.encode(vector2, dictionary3); - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); provider.put(dictionary1); provider.put(dictionary3); List schemaFields = new ArrayList<>(); - schemaFields.add(DictionaryUtility.toMessageFormat(encodedVector1.getField(), provider, new HashSet<>())); - schemaFields.add(DictionaryUtility.toMessageFormat(encodedVector2.getField(), provider, new HashSet<>())); + schemaFields.add( + DictionaryUtility.toMessageFormat(encodedVector1.getField(), provider, new HashSet<>())); + schemaFields.add( + DictionaryUtility.toMessageFormat(encodedVector2.getField(), provider, new HashSet<>())); Schema schema = new Schema(schemaFields); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); @@ -597,8 +634,9 @@ public void testDeltaDictionary() throws Exception { // write eos out.writeIntLittleEndian(0); - try (ArrowStreamReader reader = new ArrowStreamReader( - new ByteArrayReadableSeekableByteChannel(outStream.toByteArray()), allocator)) { + try (ArrowStreamReader reader = + new ArrowStreamReader( + new ByteArrayReadableSeekableByteChannel(outStream.toByteArray()), allocator)) { assertEquals(1, reader.getDictionaryVectors().size()); assertTrue(reader.loadNextBatch()); FieldVector dictionaryVector = reader.getDictionaryVectors().get(1L).getVector(); @@ -610,13 +648,13 @@ public void testDeltaDictionary() throws Exception { vector1.close(); vector2.close(); AutoCloseables.close(closeableList); - } // Tests that the ArrowStreamWriter re-emits dictionaries when they change @Test public void testWriteReadStreamWithDictionaryReplacement() throws Exception { - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); provider.put(dictionary1); String[] batch0 = {"foo", "bar", "baz", "bar", "baz"}; @@ -633,8 +671,9 @@ public void testWriteReadStreamWithDictionaryReplacement() throws Exception { List fields = Arrays.asList(encodedVector1.getField()); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { try (VectorSchemaRoot root = - new VectorSchemaRoot(fields, Arrays.asList(encodedVector1), encodedVector1.getValueCount()); - ArrowStreamWriter writer = new ArrowStreamWriter(root, provider, newChannel(out))) { + new VectorSchemaRoot( + fields, Arrays.asList(encodedVector1), encodedVector1.getValueCount()); + ArrowStreamWriter writer = new ArrowStreamWriter(root, provider, newChannel(out))) { writer.start(); // Write batch with initial data and dictionary @@ -660,8 +699,9 @@ public void testWriteReadStreamWithDictionaryReplacement() throws Exception { writer.end(); } - try (ArrowStreamReader reader = new ArrowStreamReader( - new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator)) { + try (ArrowStreamReader reader = + new ArrowStreamReader( + new ByteArrayReadableSeekableByteChannel(out.toByteArray()), allocator)) { VectorSchemaRoot root = reader.getVectorSchemaRoot(); // Read and verify first batch @@ -670,7 +710,7 @@ public void testWriteReadStreamWithDictionaryReplacement() throws Exception { FieldVector readEncoded1 = root.getVector(0); long dictionaryId = readEncoded1.getField().getDictionary().getId(); try (VarCharVector decodedValues = - (VarCharVector) DictionaryEncoder.decode(readEncoded1, reader.lookup(dictionaryId))) { + (VarCharVector) DictionaryEncoder.decode(readEncoded1, reader.lookup(dictionaryId))) { for (int i = 0; i < batch0.length; ++i) { assertEquals(batch0[i], new String(decodedValues.get(i), StandardCharsets.UTF_8)); } @@ -682,7 +722,7 @@ public void testWriteReadStreamWithDictionaryReplacement() throws Exception { FieldVector readEncoded2 = root.getVector(0); dictionaryId = readEncoded2.getField().getDictionary().getId(); try (VarCharVector decodedValues = - (VarCharVector) DictionaryEncoder.decode(readEncoded2, reader.lookup(dictionaryId))) { + (VarCharVector) DictionaryEncoder.decode(readEncoded2, reader.lookup(dictionaryId))) { for (int i = 0; i < batch1.length; ++i) { assertEquals(batch1[i], new String(decodedValues.get(i), StandardCharsets.UTF_8)); } @@ -696,33 +736,29 @@ public void testWriteReadStreamWithDictionaryReplacement() throws Exception { } private void serializeDictionaryBatch( - WriteChannel out, - Dictionary dictionary, - boolean isDelta, - List closeables) throws IOException { + WriteChannel out, Dictionary dictionary, boolean isDelta, List closeables) + throws IOException { FieldVector dictVector = dictionary.getVector(); - VectorSchemaRoot root = new VectorSchemaRoot( - Collections.singletonList(dictVector.getField()), - Collections.singletonList(dictVector), - dictVector.getValueCount()); + VectorSchemaRoot root = + new VectorSchemaRoot( + Collections.singletonList(dictVector.getField()), + Collections.singletonList(dictVector), + dictVector.getValueCount()); ArrowDictionaryBatch batch = - new ArrowDictionaryBatch(dictionary.getEncoding().getId(), new VectorUnloader(root).getRecordBatch(), isDelta); + new ArrowDictionaryBatch( + dictionary.getEncoding().getId(), new VectorUnloader(root).getRecordBatch(), isDelta); MessageSerializer.serialize(out, batch); closeables.add(batch); closeables.add(root); } private void serializeRecordBatch( - WriteChannel out, - List vectors, - List closeables) throws IOException { + WriteChannel out, List vectors, List closeables) + throws IOException { List fields = vectors.stream().map(v -> v.getField()).collect(Collectors.toList()); - VectorSchemaRoot root = new VectorSchemaRoot( - fields, - vectors, - vectors.get(0).getValueCount()); + VectorSchemaRoot root = new VectorSchemaRoot(fields, vectors, vectors.get(0).getValueCount()); VectorUnloader unloader = new VectorUnloader(root); ArrowRecordBatch batch = unloader.getRecordBatch(); MessageSerializer.serialize(out, batch); @@ -742,10 +778,11 @@ public void testReadInterleavedData() throws IOException { // write dictionary1 FieldVector dictVector1 = dictionary1.getVector(); - VectorSchemaRoot dictRoot1 = new VectorSchemaRoot( - Collections.singletonList(dictVector1.getField()), - Collections.singletonList(dictVector1), - dictVector1.getValueCount()); + VectorSchemaRoot dictRoot1 = + new VectorSchemaRoot( + Collections.singletonList(dictVector1.getField()), + Collections.singletonList(dictVector1), + dictVector1.getValueCount()); ArrowDictionaryBatch dictionaryBatch1 = new ArrowDictionaryBatch(1, new VectorUnloader(dictRoot1).getRecordBatch()); MessageSerializer.serialize(out, dictionaryBatch1); @@ -757,10 +794,11 @@ public void testReadInterleavedData() throws IOException { // write dictionary2 FieldVector dictVector2 = dictionary2.getVector(); - VectorSchemaRoot dictRoot2 = new VectorSchemaRoot( - Collections.singletonList(dictVector2.getField()), - Collections.singletonList(dictVector2), - dictVector2.getValueCount()); + VectorSchemaRoot dictRoot2 = + new VectorSchemaRoot( + Collections.singletonList(dictVector2.getField()), + Collections.singletonList(dictVector2), + dictVector2.getValueCount()); ArrowDictionaryBatch dictionaryBatch2 = new ArrowDictionaryBatch(2, new VectorUnloader(dictRoot2).getRecordBatch()); MessageSerializer.serialize(out, dictionaryBatch2); @@ -773,8 +811,9 @@ public void testReadInterleavedData() throws IOException { // write eos out.writeIntLittleEndian(0); - try (ArrowStreamReader reader = new ArrowStreamReader( - new ByteArrayReadableSeekableByteChannel(outStream.toByteArray()), allocator)) { + try (ArrowStreamReader reader = + new ArrowStreamReader( + new ByteArrayReadableSeekableByteChannel(outStream.toByteArray()), allocator)) { Schema readSchema = reader.getVectorSchemaRoot().getSchema(); assertEquals(encodedSchema, readSchema); assertEquals(2, reader.getDictionaryVectors().size()); @@ -789,7 +828,8 @@ public void testReadInterleavedData() throws IOException { private List createRecordBatches() { List batches = new ArrayList<>(); - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); provider.put(dictionary1); provider.put(dictionary2); @@ -841,11 +881,14 @@ private List createRecordBatches() { rootB.close(); List schemaFields = new ArrayList<>(); - schemaFields.add(DictionaryUtility.toMessageFormat(encodedVectorA1.getField(), provider, new HashSet<>())); - schemaFields.add(DictionaryUtility.toMessageFormat(encodedVectorA2.getField(), provider, new HashSet<>())); + schemaFields.add( + DictionaryUtility.toMessageFormat(encodedVectorA1.getField(), provider, new HashSet<>())); + schemaFields.add( + DictionaryUtility.toMessageFormat(encodedVectorA2.getField(), provider, new HashSet<>())); schema = new Schema(schemaFields); - encodedSchema = new Schema(Arrays.asList(encodedVectorA1.getField(), encodedVectorA2.getField())); + encodedSchema = + new Schema(Arrays.asList(encodedVectorA1.getField(), encodedVectorA2.getField())); return batches; } @@ -858,8 +901,11 @@ public void testLegacyIpcBackwardsCompatibility() throws Exception { vector.setValueCount(valueCount); vector.setSafe(0, 1); vector.setSafe(1, 2); - ArrowRecordBatch batch = new ArrowRecordBatch(valueCount, asList(new ArrowFieldNode(valueCount, 0)), - asList(vector.getValidityBuffer(), vector.getDataBuffer())); + ArrowRecordBatch batch = + new ArrowRecordBatch( + valueCount, + asList(new ArrowFieldNode(valueCount, 0)), + asList(vector.getValidityBuffer(), vector.getDataBuffer())); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); WriteChannel out = new WriteChannel(newChannel(outStream)); @@ -882,7 +928,8 @@ public void testLegacyIpcBackwardsCompatibility() throws Exception { MessageSerializer.serialize(out, schema, option); MessageSerializer.serialize(out, batch); - ReadChannel in2 = new ReadChannel(newChannel(new ByteArrayInputStream(outStream.toByteArray()))); + ReadChannel in2 = + new ReadChannel(newChannel(new ByteArrayInputStream(outStream.toByteArray()))); Schema readSchema2 = MessageSerializer.deserializeSchema(in2); assertEquals(schema, readSchema2); ArrowRecordBatch readBatch2 = MessageSerializer.deserializeRecordBatch(in2, allocator); @@ -900,8 +947,9 @@ public void testChannelReadFully() throws IOException { buf.putInt(200); buf.rewind(); - try (ReadChannel channel = new ReadChannel(Channels.newChannel(new ByteArrayInputStream(buf.array()))); - ArrowBuf arrBuf = allocator.buffer(8)) { + try (ReadChannel channel = + new ReadChannel(Channels.newChannel(new ByteArrayInputStream(buf.array()))); + ArrowBuf arrBuf = allocator.buffer(8)) { arrBuf.setInt(0, 100); arrBuf.writerIndex(4); assertEquals(4, arrBuf.writerIndex()); @@ -921,8 +969,9 @@ public void testChannelReadFullyEos() throws IOException { buf.putInt(10); buf.rewind(); - try (ReadChannel channel = new ReadChannel(Channels.newChannel(new ByteArrayInputStream(buf.array()))); - ArrowBuf arrBuf = allocator.buffer(8)) { + try (ReadChannel channel = + new ReadChannel(Channels.newChannel(new ByteArrayInputStream(buf.array()))); + ArrowBuf arrBuf = allocator.buffer(8)) { int n = channel.readFully(arrBuf.nioBuffer(0, 8)); assertEquals(4, n); @@ -946,13 +995,13 @@ public void testCustomMetaData() throws IOException { metadata.put("key2", "value2"); try (VectorSchemaRoot root = new VectorSchemaRoot(fields, vectors, vector.getValueCount()); ByteArrayOutputStream out = new ByteArrayOutputStream(); - ArrowFileWriter writer = new ArrowFileWriter(root, null, newChannel(out), metadata);) { + ArrowFileWriter writer = new ArrowFileWriter(root, null, newChannel(out), metadata); ) { writer.start(); writer.end(); - try (SeekableReadChannel channel = new SeekableReadChannel( - new ByteArrayReadableSeekableByteChannel(out.toByteArray())); + try (SeekableReadChannel channel = + new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(out.toByteArray())); ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { reader.getVectorSchemaRoot(); @@ -965,9 +1014,8 @@ public void testCustomMetaData() throws IOException { } /** - * This test case covers the case for which the footer size is extremely large - * (much larger than the file size). - * Due to integer overflow, our implementation fails detect the problem, which + * This test case covers the case for which the footer size is extremely large (much larger than + * the file size). Due to integer overflow, our implementation fails detect the problem, which * leads to extremely large memory allocation and eventually causing an OutOfMemoryError. */ @Test @@ -980,18 +1028,22 @@ public void testFileFooterSizeOverflow() { System.arraycopy(magicBytes, 0, data, 0, ArrowMagic.MAGIC_LENGTH); int footerLength = Integer.MAX_VALUE; byte[] footerLengthBytes = - ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(footerLength).array(); + ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(footerLength).array(); int footerOffset = data.length - ArrowMagic.MAGIC_LENGTH - 4; System.arraycopy(footerLengthBytes, 0, data, footerOffset, 4); System.arraycopy(magicBytes, 0, data, footerOffset + 4, ArrowMagic.MAGIC_LENGTH); // test file reader - InvalidArrowFileException e = Assertions.assertThrows(InvalidArrowFileException.class, () -> { - try (SeekableReadChannel channel = new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(data)); - ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { - reader.getVectorSchemaRoot().getSchema(); - } - }); + InvalidArrowFileException e = + Assertions.assertThrows( + InvalidArrowFileException.class, + () -> { + try (SeekableReadChannel channel = + new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(data)); + ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { + reader.getVectorSchemaRoot().getSchema(); + } + }); assertEquals("invalid footer length: " + footerLength, e.getMessage()); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStream.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStream.java index 9348cd3a667..5e799bedd65 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStream.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStream.java @@ -26,7 +26,6 @@ import java.io.IOException; import java.nio.channels.Channels; import java.util.Collections; - import org.apache.arrow.vector.IntVector; import org.apache.arrow.vector.TinyIntVector; import org.apache.arrow.vector.VectorSchemaRoot; @@ -61,11 +60,12 @@ public void testEmptyStream() throws IOException { public void testStreamZeroLengthBatch() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); - try (IntVector vector = new IntVector("foo", allocator);) { + try (IntVector vector = new IntVector("foo", allocator); ) { Schema schema = new Schema(Collections.singletonList(vector.getField())); try (VectorSchemaRoot root = - new VectorSchemaRoot(schema, Collections.singletonList(vector), vector.getValueCount()); - ArrowStreamWriter writer = new ArrowStreamWriter(root, null, Channels.newChannel(os));) { + new VectorSchemaRoot( + schema, Collections.singletonList(vector), vector.getValueCount()); + ArrowStreamWriter writer = new ArrowStreamWriter(root, null, Channels.newChannel(os)); ) { vector.setValueCount(0); root.setRowCount(0); writer.writeBatch(); @@ -75,7 +75,7 @@ public void testStreamZeroLengthBatch() throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(os.toByteArray()); - try (ArrowStreamReader reader = new ArrowStreamReader(in, allocator);) { + try (ArrowStreamReader reader = new ArrowStreamReader(in, allocator); ) { VectorSchemaRoot root = reader.getVectorSchemaRoot(); IntVector vector = (IntVector) root.getFieldVectors().get(0); reader.loadNextBatch(); @@ -128,18 +128,19 @@ public void testReadWrite() throws IOException { public void testReadWriteMultipleBatches() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); - try (IntVector vector = new IntVector("foo", allocator);) { + try (IntVector vector = new IntVector("foo", allocator); ) { Schema schema = new Schema(Collections.singletonList(vector.getField())); try (VectorSchemaRoot root = - new VectorSchemaRoot(schema, Collections.singletonList(vector), vector.getValueCount()); - ArrowStreamWriter writer = new ArrowStreamWriter(root, null, Channels.newChannel(os));) { + new VectorSchemaRoot( + schema, Collections.singletonList(vector), vector.getValueCount()); + ArrowStreamWriter writer = new ArrowStreamWriter(root, null, Channels.newChannel(os)); ) { writeBatchData(writer, vector, root); } } ByteArrayInputStream in = new ByteArrayInputStream(os.toByteArray()); - try (ArrowStreamReader reader = new ArrowStreamReader(in, allocator);) { + try (ArrowStreamReader reader = new ArrowStreamReader(in, allocator); ) { IntVector vector = (IntVector) reader.getVectorSchemaRoot().getFieldVectors().get(0); validateBatchData(reader, vector); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStreamPipe.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStreamPipe.java index 422a63f57f7..018b04ea5bb 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStreamPipe.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestArrowStreamPipe.java @@ -24,14 +24,10 @@ import java.nio.channels.Pipe; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.TinyIntVector; import org.apache.arrow.vector.VectorSchemaRoot; -import org.apache.arrow.vector.ipc.ArrowStreamReader; -import org.apache.arrow.vector.ipc.ArrowStreamWriter; -import org.apache.arrow.vector.ipc.MessageSerializerTest; import org.apache.arrow.vector.types.pojo.Schema; import org.junit.Assert; import org.junit.Test; @@ -46,8 +42,7 @@ private final class WriterThread extends Thread { private final ArrowStreamWriter writer; private final VectorSchemaRoot root; - public WriterThread(int numBatches, WritableByteChannel sinkChannel) - throws IOException { + public WriterThread(int numBatches, WritableByteChannel sinkChannel) throws IOException { this.numBatches = numBatches; BufferAllocator allocator = alloc.newChildAllocator("writer thread", 0, Integer.MAX_VALUE); root = VectorSchemaRoot.create(schema, allocator); @@ -90,33 +85,33 @@ private final class ReaderThread extends Thread { private final BufferAllocator alloc = new RootAllocator(Long.MAX_VALUE); private boolean done = false; - public ReaderThread(ReadableByteChannel sourceChannel) - throws IOException { - reader = new ArrowStreamReader(sourceChannel, alloc) { - - @Override - public boolean loadNextBatch() throws IOException { - if (super.loadNextBatch()) { - batchesRead++; - } else { - done = true; - return false; - } - VectorSchemaRoot root = getVectorSchemaRoot(); - Assert.assertEquals(16, root.getRowCount()); - TinyIntVector vector = (TinyIntVector) root.getFieldVectors().get(0); - Assert.assertEquals((byte) (batchesRead - 1), vector.get(0)); - for (int i = 1; i < 16; i++) { - if (i < 8) { - Assert.assertEquals((byte) (i + 1), vector.get(i)); - } else { - Assert.assertTrue(vector.isNull(i)); + public ReaderThread(ReadableByteChannel sourceChannel) throws IOException { + reader = + new ArrowStreamReader(sourceChannel, alloc) { + + @Override + public boolean loadNextBatch() throws IOException { + if (super.loadNextBatch()) { + batchesRead++; + } else { + done = true; + return false; + } + VectorSchemaRoot root = getVectorSchemaRoot(); + Assert.assertEquals(16, root.getRowCount()); + TinyIntVector vector = (TinyIntVector) root.getFieldVectors().get(0); + Assert.assertEquals((byte) (batchesRead - 1), vector.get(0)); + for (int i = 1; i < 16; i++) { + if (i < 8) { + Assert.assertEquals((byte) (i + 1), vector.get(i)); + } else { + Assert.assertTrue(vector.isNull(i)); + } + } + + return true; } - } - - return true; - } - }; + }; } @Override diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java index 0aa49d9daa0..3cc9e4fb398 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.VectorSchemaRoot; @@ -56,8 +55,8 @@ public void testNoBatches() throws IOException { File file = new File("target/no_batches.json"); try (BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); - StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { BaseWriter.ComplexWriter writer = new ComplexWriterImpl("root", parent); BaseWriter.StructWriter rootWriter = writer.rootAsStruct(); rootWriter.integer("int"); @@ -70,10 +69,9 @@ public void testNoBatches() throws IOException { } // read - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator) - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); } @@ -86,22 +84,21 @@ public void testWriteRead() throws IOException { // write try (BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); - StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { writeData(count, parent); writeJSON(file, new VectorSchemaRoot(parent.getChild("root")), null); } // read - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator) - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateContent(count, root); } } @@ -113,23 +110,22 @@ public void testWriteReadComplexJSON() throws IOException { int count = COUNT; // write - try ( - BufferAllocator originalVectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator originalVectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { writeComplexData(count, parent); writeJSON(file, new VectorSchemaRoot(parent.getChild("root")), null); } // read - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator); - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator); ) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateComplexContent(count, root); } } @@ -139,8 +135,8 @@ public void testWriteReadComplexJSON() throws IOException { public void testWriteComplexJSON() throws IOException { File file = new File("target/mytest_write_complex.json"); int count = COUNT; - try ( - BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); StructVector parent = StructVector.empty("parent", vectorAllocator)) { writeComplexData(count, parent); VectorSchemaRoot root = new VectorSchemaRoot(parent.getChild("root")); @@ -149,20 +145,20 @@ public void testWriteComplexJSON() throws IOException { } } - public void writeJSON(File file, VectorSchemaRoot root, DictionaryProvider provider) throws IOException { + public void writeJSON(File file, VectorSchemaRoot root, DictionaryProvider provider) + throws IOException { JsonFileWriter writer = new JsonFileWriter(file, JsonFileWriter.config().pretty(true)); writer.start(root.getSchema(), provider); writer.write(root); writer.close(); } - @Test public void testWriteReadUnionJSON() throws IOException { File file = new File("target/mytest_write_union.json"); int count = COUNT; - try ( - BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); StructVector parent = StructVector.empty("parent", vectorAllocator)) { writeUnionData(count, parent); printVectors(parent.getChildrenFromFields()); @@ -172,13 +168,14 @@ public void testWriteReadUnionJSON() throws IOException { writeJSON(file, root, null); // read - try (BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE)) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE)) { JsonFileReader reader = new JsonFileReader(file, readerAllocator); Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); - try (VectorSchemaRoot rootFromJson = reader.read();) { + try (VectorSchemaRoot rootFromJson = reader.read(); ) { validateUnionData(count, rootFromJson); Validator.compareVectorSchemaRoot(root, rootFromJson); } @@ -193,8 +190,8 @@ public void testWriteReadDateTimeJSON() throws IOException { int count = COUNT; // write - try ( - BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); StructVector parent = StructVector.empty("parent", vectorAllocator)) { writeDateTimeData(count, parent); @@ -208,15 +205,14 @@ public void testWriteReadDateTimeJSON() throws IOException { } // read - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator) - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateDateTimeContent(count, root); } } @@ -227,9 +223,8 @@ public void testWriteReadDictionaryJSON() throws IOException { File file = new File("target/mytest_dictionary.json"); // write - try ( - BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE) - ) { + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE)) { MapDictionaryProvider provider = new MapDictionaryProvider(); try (VectorSchemaRoot root = writeFlatDictionaryData(vectorAllocator, provider)) { @@ -245,15 +240,14 @@ public void testWriteReadDictionaryJSON() throws IOException { } // read - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator) - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateFlatDictionary(root, reader); } } @@ -267,9 +261,8 @@ public void testWriteReadNestedDictionaryJSON() throws IOException { // [['foo', 'bar'], ['foo'], ['bar']] -> [[0, 1], [0], [1]] // write - try ( - BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE) - ) { + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE)) { MapDictionaryProvider provider = new MapDictionaryProvider(); try (VectorSchemaRoot root = writeNestedDictionaryData(vectorAllocator, provider)) { @@ -285,15 +278,14 @@ public void testWriteReadNestedDictionaryJSON() throws IOException { } // read - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator) - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateNestedDictionary(root, reader); } } @@ -304,7 +296,8 @@ public void testWriteReadDecimalJSON() throws IOException { File file = new File("target/mytest_decimal.json"); // write - try (BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); VectorSchemaRoot root = writeDecimalData(vectorAllocator)) { printVectors(root.getFieldVectors()); validateDecimalData(root); @@ -312,15 +305,14 @@ public void testWriteReadDecimalJSON() throws IOException { } // read - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator) - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateDecimalData(root); } } @@ -332,15 +324,14 @@ public void testSetStructLength() throws IOException { if (!file.exists()) { file = new File("../docs/source/format/integration_json_examples/struct.json"); } - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator) - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { FieldVector vector = root.getVector("struct_nullable"); Assert.assertEquals(7, vector.getValueCount()); } @@ -353,8 +344,8 @@ public void testWriteReadVarBinJSON() throws IOException { int count = COUNT; // write - try ( - BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); StructVector parent = StructVector.empty("parent", vectorAllocator)) { writeVarBinaryData(count, parent); VectorSchemaRoot root = new VectorSchemaRoot(parent.getChild("root")); @@ -363,13 +354,14 @@ public void testWriteReadVarBinJSON() throws IOException { } // read - try (BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateVarBinary(count, root); } } @@ -380,7 +372,8 @@ public void testWriteReadMapJSON() throws IOException { File file = new File("target/mytest_map.json"); // write - try (BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); VectorSchemaRoot root = writeMapData(vectorAllocator)) { printVectors(root.getFieldVectors()); validateMapData(root); @@ -388,13 +381,14 @@ public void testWriteReadMapJSON() throws IOException { } // read - try (BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateMapData(root); } } @@ -406,7 +400,8 @@ public void testWriteReadNullJSON() throws IOException { int valueCount = 10; // write - try (BufferAllocator vectorAllocator = allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); + try (BufferAllocator vectorAllocator = + allocator.newChildAllocator("original vectors", 0, Integer.MAX_VALUE); VectorSchemaRoot root = writeNullData(valueCount)) { printVectors(root.getFieldVectors()); validateNullData(root, valueCount); @@ -414,16 +409,15 @@ public void testWriteReadNullJSON() throws IOException { } // read - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); - JsonFileReader reader = new JsonFileReader(file, readerAllocator) - ) { + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, Integer.MAX_VALUE); + JsonFileReader reader = new JsonFileReader(file, readerAllocator)) { Schema schema = reader.start(); LOGGER.debug("reading schema: " + schema); // initialize vectors - try (VectorSchemaRoot root = reader.read();) { + try (VectorSchemaRoot root = reader.read(); ) { validateNullData(root, valueCount); } } @@ -432,29 +426,45 @@ public void testWriteReadNullJSON() throws IOException { /** Regression test for ARROW-17107. */ @Test public void testRoundtripEmptyVector() throws Exception { - final List fields = Arrays.asList( - Field.nullable("utf8", ArrowType.Utf8.INSTANCE), - Field.nullable("largeutf8", ArrowType.LargeUtf8.INSTANCE), - Field.nullable("binary", ArrowType.Binary.INSTANCE), - Field.nullable("largebinary", ArrowType.LargeBinary.INSTANCE), - Field.nullable("fixedsizebinary", new ArrowType.FixedSizeBinary(2)), - Field.nullable("decimal128", new ArrowType.Decimal(3, 2, 128)), - Field.nullable("decimal128", new ArrowType.Decimal(3, 2, 256)), - new Field("list", FieldType.nullable(ArrowType.List.INSTANCE), - Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), - new Field("largelist", FieldType.nullable(ArrowType.LargeList.INSTANCE), - Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), - new Field("map", FieldType.nullable(new ArrowType.Map(/*keyssorted*/ false)), - Collections.singletonList(new Field("items", FieldType.notNullable(ArrowType.Struct.INSTANCE), - Arrays.asList(Field.notNullable("keys", new ArrowType.Int(32, true)), - Field.nullable("values", new ArrowType.Int(32, true)))))), - new Field("fixedsizelist", FieldType.nullable(new ArrowType.FixedSizeList(2)), - Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), - new Field("denseunion", FieldType.nullable(new ArrowType.Union(UnionMode.Dense, new int[] {0})), - Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), - new Field("sparseunion", FieldType.nullable(new ArrowType.Union(UnionMode.Sparse, new int[] {0})), - Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))) - ); + final List fields = + Arrays.asList( + Field.nullable("utf8", ArrowType.Utf8.INSTANCE), + Field.nullable("largeutf8", ArrowType.LargeUtf8.INSTANCE), + Field.nullable("binary", ArrowType.Binary.INSTANCE), + Field.nullable("largebinary", ArrowType.LargeBinary.INSTANCE), + Field.nullable("fixedsizebinary", new ArrowType.FixedSizeBinary(2)), + Field.nullable("decimal128", new ArrowType.Decimal(3, 2, 128)), + Field.nullable("decimal128", new ArrowType.Decimal(3, 2, 256)), + new Field( + "list", + FieldType.nullable(ArrowType.List.INSTANCE), + Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), + new Field( + "largelist", + FieldType.nullable(ArrowType.LargeList.INSTANCE), + Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), + new Field( + "map", + FieldType.nullable(new ArrowType.Map(/*keyssorted*/ false)), + Collections.singletonList( + new Field( + "items", + FieldType.notNullable(ArrowType.Struct.INSTANCE), + Arrays.asList( + Field.notNullable("keys", new ArrowType.Int(32, true)), + Field.nullable("values", new ArrowType.Int(32, true)))))), + new Field( + "fixedsizelist", + FieldType.nullable(new ArrowType.FixedSizeList(2)), + Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), + new Field( + "denseunion", + FieldType.nullable(new ArrowType.Union(UnionMode.Dense, new int[] {0})), + Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), + new Field( + "sparseunion", + FieldType.nullable(new ArrowType.Union(UnionMode.Sparse, new int[] {0})), + Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true))))); for (final Field field : fields) { final Schema schema = new Schema(Collections.singletonList(field)); @@ -464,7 +474,8 @@ public void testRoundtripEmptyVector() throws Exception { outputFile.deleteOnExit(); // Try with no allocation - try (final JsonFileWriter jsonWriter = new JsonFileWriter(outputFile, JsonFileWriter.config().pretty(true))) { + try (final JsonFileWriter jsonWriter = + new JsonFileWriter(outputFile, JsonFileWriter.config().pretty(true))) { jsonWriter.start(schema, null); jsonWriter.write(root); } catch (Exception e) { @@ -484,7 +495,8 @@ public void testRoundtripEmptyVector() throws Exception { // Try with an explicit allocation root.allocateNew(); root.setRowCount(0); - try (final JsonFileWriter jsonWriter = new JsonFileWriter(outputFile, JsonFileWriter.config().pretty(true))) { + try (final JsonFileWriter jsonWriter = + new JsonFileWriter(outputFile, JsonFileWriter.config().pretty(true))) { jsonWriter.start(schema, null); jsonWriter.write(root); } catch (Exception e) { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestRoundTrip.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestRoundTrip.java index 5f57e90f6ba..7ac5e180526 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestRoundTrip.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestRoundTrip.java @@ -41,7 +41,6 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiConsumer; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.util.Collections2; @@ -96,8 +95,7 @@ public static Collection getWriteOption() { return Arrays.asList( new Object[] {"V4Legacy", legacy}, new Object[] {"V4", version4}, - new Object[] {"V5", IpcOption.DEFAULT} - ); + new Object[] {"V5", IpcOption.DEFAULT}); } @BeforeClass @@ -113,12 +111,12 @@ public static void tearDownClass() { @Test public void testStruct() throws Exception { try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { writeData(COUNT, parent); roundTrip( new VectorSchemaRoot(parent.getChild("root")), - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, validateFileBatches(new int[] {COUNT}, this::validateContent), validateStreamBatches(new int[] {COUNT}, this::validateContent)); @@ -128,12 +126,12 @@ public void testStruct() throws Exception { @Test public void testComplex() throws Exception { try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { writeComplexData(COUNT, parent); roundTrip( new VectorSchemaRoot(parent.getChild("root")), - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, validateFileBatches(new int[] {COUNT}, this::validateComplexContent), validateStreamBatches(new int[] {COUNT}, this::validateComplexContent)); @@ -144,12 +142,12 @@ public void testComplex() throws Exception { public void testMultipleRecordBatches() throws Exception { int[] counts = {10, 5}; try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { writeData(counts[0], parent); roundTrip( new VectorSchemaRoot(parent.getChild("root")), - /* dictionaryProvider */null, + /* dictionaryProvider */ null, (root, writer) -> { writer.start(); parent.allocateNew(); @@ -158,7 +156,8 @@ public void testMultipleRecordBatches() throws Exception { writer.writeBatch(); parent.allocateNew(); - // if we write the same data we don't catch that the metadata is stored in the wrong order. + // if we write the same data we don't catch that the metadata is stored in the wrong + // order. writeData(counts[1], parent); root.setRowCount(counts[1]); writer.writeBatch(); @@ -178,20 +177,26 @@ public void testUnionV4() throws Exception { final ByteArrayOutputStream memoryStream = new ByteArrayOutputStream(); try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { writeUnionData(COUNT, parent); final VectorSchemaRoot root = new VectorSchemaRoot(parent.getChild("root")); - IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { - try (final FileOutputStream fileStream = new FileOutputStream(temp)) { - new ArrowFileWriter(root, null, fileStream.getChannel(), writeOption); - new ArrowStreamWriter(root, null, Channels.newChannel(memoryStream), writeOption); - } - }); + IllegalArgumentException e = + assertThrows( + IllegalArgumentException.class, + () -> { + try (final FileOutputStream fileStream = new FileOutputStream(temp)) { + new ArrowFileWriter(root, null, fileStream.getChannel(), writeOption); + new ArrowStreamWriter(root, null, Channels.newChannel(memoryStream), writeOption); + } + }); assertTrue(e.getMessage(), e.getMessage().contains("Cannot write union with V4 metadata")); - e = assertThrows(IllegalArgumentException.class, () -> { - new ArrowStreamWriter(root, null, Channels.newChannel(memoryStream), writeOption); - }); + e = + assertThrows( + IllegalArgumentException.class, + () -> { + new ArrowStreamWriter(root, null, Channels.newChannel(memoryStream), writeOption); + }); assertTrue(e.getMessage(), e.getMessage().contains("Cannot write union with V4 metadata")); } } @@ -200,14 +205,14 @@ public void testUnionV4() throws Exception { public void testUnionV5() throws Exception { Assume.assumeTrue(writeOption.metadataVersion == MetadataVersion.V5); try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { writeUnionData(COUNT, parent); VectorSchemaRoot root = new VectorSchemaRoot(parent.getChild("root")); validateUnionData(COUNT, root); roundTrip( root, - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, validateFileBatches(new int[] {COUNT}, this::validateUnionData), validateStreamBatches(new int[] {COUNT}, this::validateUnionData)); @@ -216,7 +221,8 @@ public void testUnionV5() throws Exception { @Test public void testTiny() throws Exception { - try (final VectorSchemaRoot root = VectorSchemaRoot.create(MessageSerializerTest.testSchema(), allocator)) { + try (final VectorSchemaRoot root = + VectorSchemaRoot.create(MessageSerializerTest.testSchema(), allocator)) { root.getFieldVectors().get(0).allocateNew(); int count = 16; TinyIntVector vector = (TinyIntVector) root.getFieldVectors().get(0); @@ -228,7 +234,7 @@ public void testTiny() throws Exception { roundTrip( root, - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, validateFileBatches(new int[] {count}, this::validateTinyData), validateStreamBatches(new int[] {count}, this::validateTinyData)); @@ -250,13 +256,34 @@ private void validateTinyData(int count, VectorSchemaRoot root) { @Test public void testMetadata() throws Exception { List childFields = new ArrayList<>(); - childFields.add(new Field("varchar-child", new FieldType(true, ArrowType.Utf8.INSTANCE, null, metadata(1)), null)); - childFields.add(new Field("float-child", - new FieldType(true, new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), null, metadata(2)), null)); - childFields.add(new Field("int-child", new FieldType(false, new ArrowType.Int(32, true), null, metadata(3)), null)); - childFields.add(new Field("list-child", new FieldType(true, ArrowType.List.INSTANCE, null, metadata(4)), - Collections2.asImmutableList(new Field("l1", FieldType.nullable(new ArrowType.Int(16, true)), null)))); - Field field = new Field("meta", new FieldType(true, ArrowType.Struct.INSTANCE, null, metadata(0)), childFields); + childFields.add( + new Field( + "varchar-child", + new FieldType(true, ArrowType.Utf8.INSTANCE, null, metadata(1)), + null)); + childFields.add( + new Field( + "float-child", + new FieldType( + true, + new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), + null, + metadata(2)), + null)); + childFields.add( + new Field( + "int-child", + new FieldType(false, new ArrowType.Int(32, true), null, metadata(3)), + null)); + childFields.add( + new Field( + "list-child", + new FieldType(true, ArrowType.List.INSTANCE, null, metadata(4)), + Collections2.asImmutableList( + new Field("l1", FieldType.nullable(new ArrowType.Int(16, true)), null)))); + Field field = + new Field( + "meta", new FieldType(true, ArrowType.Struct.INSTANCE, null, metadata(0)), childFields); Map metadata = new HashMap<>(); metadata.put("s1", "v1"); metadata.put("s2", "v2"); @@ -264,27 +291,28 @@ public void testMetadata() throws Exception { assertEquals(metadata, originalSchema.getCustomMetadata()); try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector vector = (StructVector) field.createVector(originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector vector = (StructVector) field.createVector(originalVectorAllocator)) { vector.allocateNewSafe(); vector.setValueCount(0); List vectors = Collections2.asImmutableList(vector); VectorSchemaRoot root = new VectorSchemaRoot(originalSchema, vectors, 0); - BiConsumer validate = (count, readRoot) -> { - Schema schema = readRoot.getSchema(); - assertEquals(originalSchema, schema); - assertEquals(originalSchema.getCustomMetadata(), schema.getCustomMetadata()); - Field top = schema.getFields().get(0); - assertEquals(metadata(0), top.getMetadata()); - for (int i = 0; i < 4; i++) { - assertEquals(metadata(i + 1), top.getChildren().get(i).getMetadata()); - } - }; + BiConsumer validate = + (count, readRoot) -> { + Schema schema = readRoot.getSchema(); + assertEquals(originalSchema, schema); + assertEquals(originalSchema.getCustomMetadata(), schema.getCustomMetadata()); + Field top = schema.getFields().get(0); + assertEquals(metadata(0), top.getMetadata()); + for (int i = 0; i < 4; i++) { + assertEquals(metadata(i + 1), top.getChildren().get(i).getMetadata()); + } + }; roundTrip( root, - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, validateFileBatches(new int[] {0}, validate), validateStreamBatches(new int[] {0}, validate)); @@ -303,8 +331,8 @@ public void testFlatDictionary() throws Exception { AtomicInteger numDictionaryBlocksWritten = new AtomicInteger(); MapDictionaryProvider provider = new MapDictionaryProvider(); try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final VectorSchemaRoot root = writeFlatDictionaryData(originalVectorAllocator, provider)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final VectorSchemaRoot root = writeFlatDictionaryData(originalVectorAllocator, provider)) { roundTrip( root, provider, @@ -313,7 +341,8 @@ public void testFlatDictionary() throws Exception { writer.writeBatch(); writer.end(); if (writer instanceof ArrowFileWriter) { - numDictionaryBlocksWritten.set(((ArrowFileWriter) writer).getDictionaryBlocks().size()); + numDictionaryBlocksWritten.set( + ((ArrowFileWriter) writer).getDictionaryBlocks().size()); } }, (fileReader) -> { @@ -346,15 +375,17 @@ public void testNestedDictionary() throws Exception { // data being written: // [['foo', 'bar'], ['foo'], ['bar']] -> [[0, 1], [0], [1]] try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final VectorSchemaRoot root = writeNestedDictionaryData(originalVectorAllocator, provider)) { - CheckedConsumer validateDictionary = (streamReader) -> { - VectorSchemaRoot readRoot = streamReader.getVectorSchemaRoot(); - Schema schema = readRoot.getSchema(); - LOGGER.debug("reading schema: " + schema); - assertTrue(streamReader.loadNextBatch()); - validateNestedDictionary(readRoot, streamReader); - }; + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final VectorSchemaRoot root = + writeNestedDictionaryData(originalVectorAllocator, provider)) { + CheckedConsumer validateDictionary = + (streamReader) -> { + VectorSchemaRoot readRoot = streamReader.getVectorSchemaRoot(); + Schema schema = readRoot.getSchema(); + LOGGER.debug("reading schema: " + schema); + assertTrue(streamReader.loadNextBatch()); + validateNestedDictionary(readRoot, streamReader); + }; roundTrip( root, provider, @@ -363,7 +394,8 @@ public void testNestedDictionary() throws Exception { writer.writeBatch(); writer.end(); if (writer instanceof ArrowFileWriter) { - numDictionaryBlocksWritten.set(((ArrowFileWriter) writer).getDictionaryBlocks().size()); + numDictionaryBlocksWritten.set( + ((ArrowFileWriter) writer).getDictionaryBlocks().size()); } }, validateDictionary, @@ -387,17 +419,22 @@ public void testFixedSizeBinary() throws Exception { } } - BiConsumer validator = (expectedCount, root) -> { - for (int i = 0; i < expectedCount; i++) { - assertArrayEquals(byteValues[i], ((byte[]) root.getVector("fixed-binary").getObject(i))); - } - }; + BiConsumer validator = + (expectedCount, root) -> { + for (int i = 0; i < expectedCount; i++) { + assertArrayEquals( + byteValues[i], ((byte[]) root.getVector("fixed-binary").getObject(i))); + } + }; try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { - FixedSizeBinaryVector fixedSizeBinaryVector = parent.addOrGet("fixed-binary", - FieldType.nullable(new ArrowType.FixedSizeBinary(typeWidth)), FixedSizeBinaryVector.class); + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + FixedSizeBinaryVector fixedSizeBinaryVector = + parent.addOrGet( + "fixed-binary", + FieldType.nullable(new ArrowType.FixedSizeBinary(typeWidth)), + FixedSizeBinaryVector.class); parent.allocateNew(); for (int i = 0; i < count; i++) { fixedSizeBinaryVector.set(i, byteValues[i]); @@ -406,7 +443,7 @@ public void testFixedSizeBinary() throws Exception { roundTrip( new VectorSchemaRoot(parent), - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, validateFileBatches(new int[] {count}, validator), validateStreamBatches(new int[] {count}, validator)); @@ -415,22 +452,31 @@ public void testFixedSizeBinary() throws Exception { @Test public void testFixedSizeList() throws Exception { - BiConsumer validator = (expectedCount, root) -> { - for (int i = 0; i < expectedCount; i++) { - assertEquals(Collections2.asImmutableList(i + 0.1f, i + 10.1f), root.getVector("float-pairs") - .getObject(i)); - assertEquals(i, root.getVector("ints").getObject(i)); - } - }; + BiConsumer validator = + (expectedCount, root) -> { + for (int i = 0; i < expectedCount; i++) { + assertEquals( + Collections2.asImmutableList(i + 0.1f, i + 10.1f), + root.getVector("float-pairs").getObject(i)); + assertEquals(i, root.getVector("ints").getObject(i)); + } + }; try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { - FixedSizeListVector tuples = parent.addOrGet("float-pairs", - FieldType.nullable(new ArrowType.FixedSizeList(2)), FixedSizeListVector.class); - Float4Vector floats = (Float4Vector) tuples.addOrGetVector(FieldType.nullable(Types.MinorType.FLOAT4.getType())) - .getVector(); - IntVector ints = parent.addOrGet("ints", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + FixedSizeListVector tuples = + parent.addOrGet( + "float-pairs", + FieldType.nullable(new ArrowType.FixedSizeList(2)), + FixedSizeListVector.class); + Float4Vector floats = + (Float4Vector) + tuples + .addOrGetVector(FieldType.nullable(Types.MinorType.FLOAT4.getType())) + .getVector(); + IntVector ints = + parent.addOrGet("ints", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); parent.allocateNew(); for (int i = 0; i < COUNT; i++) { tuples.setNotNull(i); @@ -442,7 +488,7 @@ public void testFixedSizeList() throws Exception { roundTrip( new VectorSchemaRoot(parent), - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, validateFileBatches(new int[] {COUNT}, validator), validateStreamBatches(new int[] {COUNT}, validator)); @@ -452,18 +498,18 @@ public void testFixedSizeList() throws Exception { @Test public void testVarBinary() throws Exception { try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final StructVector parent = StructVector.empty("parent", originalVectorAllocator)) { writeVarBinaryData(COUNT, parent); VectorSchemaRoot root = new VectorSchemaRoot(parent.getChild("root")); validateVarBinary(COUNT, root); roundTrip( root, - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, - validateFileBatches(new int[]{COUNT}, this::validateVarBinary), - validateStreamBatches(new int[]{COUNT}, this::validateVarBinary)); + validateFileBatches(new int[] {COUNT}, this::validateVarBinary), + validateStreamBatches(new int[] {COUNT}, this::validateVarBinary)); } } @@ -472,19 +518,21 @@ public void testReadWriteMultipleBatches() throws IOException { File file = new File("target/mytest_nulls_multibatch.arrow"); int numBlocksWritten = 0; - try (IntVector vector = new IntVector("foo", allocator);) { + try (IntVector vector = new IntVector("foo", allocator); ) { Schema schema = new Schema(Collections.singletonList(vector.getField())); try (FileOutputStream fileOutputStream = new FileOutputStream(file); - VectorSchemaRoot root = - new VectorSchemaRoot(schema, Collections.singletonList((FieldVector) vector), vector.getValueCount()); - ArrowFileWriter writer = new ArrowFileWriter(root, null, fileOutputStream.getChannel(), writeOption)) { + VectorSchemaRoot root = + new VectorSchemaRoot( + schema, Collections.singletonList((FieldVector) vector), vector.getValueCount()); + ArrowFileWriter writer = + new ArrowFileWriter(root, null, fileOutputStream.getChannel(), writeOption)) { writeBatchData(writer, vector, root); numBlocksWritten = writer.getRecordBlocks().size(); } } try (FileInputStream fileInputStream = new FileInputStream(file); - ArrowFileReader reader = new ArrowFileReader(fileInputStream.getChannel(), allocator);) { + ArrowFileReader reader = new ArrowFileReader(fileInputStream.getChannel(), allocator); ) { IntVector vector = (IntVector) reader.getVectorSchemaRoot().getFieldVectors().get(0); validateBatchData(reader, vector); assertEquals(numBlocksWritten, reader.getRecordBlocks().size()); @@ -494,34 +542,40 @@ public void testReadWriteMultipleBatches() throws IOException { @Test public void testMap() throws Exception { try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final VectorSchemaRoot root = writeMapData(originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final VectorSchemaRoot root = writeMapData(originalVectorAllocator)) { roundTrip( root, - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, - validateFileBatches(new int[]{root.getRowCount()}, (count, readRoot) -> validateMapData(readRoot)), - validateStreamBatches(new int[]{root.getRowCount()}, (count, readRoot) -> validateMapData(readRoot))); + validateFileBatches( + new int[] {root.getRowCount()}, (count, readRoot) -> validateMapData(readRoot)), + validateStreamBatches( + new int[] {root.getRowCount()}, (count, readRoot) -> validateMapData(readRoot))); } } @Test public void testListAsMap() throws Exception { try (final BufferAllocator originalVectorAllocator = - allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); - final VectorSchemaRoot root = writeListAsMapData(originalVectorAllocator)) { + allocator.newChildAllocator("original vectors", 0, allocator.getLimit()); + final VectorSchemaRoot root = writeListAsMapData(originalVectorAllocator)) { roundTrip( root, - /* dictionaryProvider */null, + /* dictionaryProvider */ null, TestRoundTrip::writeSingleBatch, - validateFileBatches(new int[]{root.getRowCount()}, (count, readRoot) -> validateListAsMapData(readRoot)), - validateStreamBatches(new int[]{root.getRowCount()}, (count, readRoot) -> validateListAsMapData(readRoot))); + validateFileBatches( + new int[] {root.getRowCount()}, (count, readRoot) -> validateListAsMapData(readRoot)), + validateStreamBatches( + new int[] {root.getRowCount()}, + (count, readRoot) -> validateListAsMapData(readRoot))); } } // Generic test helpers - private static void writeSingleBatch(VectorSchemaRoot root, ArrowWriter writer) throws IOException { + private static void writeSingleBatch(VectorSchemaRoot root, ArrowWriter writer) + throws IOException { writer.start(); writer.writeBatch(); writer.end(); @@ -539,7 +593,8 @@ private CheckedConsumer validateFileBatches( assertEquals(counts.length, recordBatches.size()); long previousOffset = 0; for (ArrowBlock rbBlock : recordBatches) { - assertTrue(rbBlock.getOffset() + " > " + previousOffset, rbBlock.getOffset() > previousOffset); + assertTrue( + rbBlock.getOffset() + " > " + previousOffset, rbBlock.getOffset() > previousOffset); previousOffset = rbBlock.getOffset(); arrowReader.loadRecordBatch(rbBlock); assertEquals("RB #" + i, counts[i], root.getRowCount()); @@ -590,34 +645,40 @@ interface CheckedBiConsumer { void accept(T t, U u) throws Exception; } - private void roundTrip(VectorSchemaRoot root, DictionaryProvider provider, - CheckedBiConsumer writer, - CheckedConsumer fileValidator, - CheckedConsumer streamValidator) throws Exception { + private void roundTrip( + VectorSchemaRoot root, + DictionaryProvider provider, + CheckedBiConsumer writer, + CheckedConsumer fileValidator, + CheckedConsumer streamValidator) + throws Exception { final File temp = File.createTempFile("arrow-test-" + name + "-", ".arrow"); temp.deleteOnExit(); final ByteArrayOutputStream memoryStream = new ByteArrayOutputStream(); final Map metadata = new HashMap<>(); metadata.put("foo", "bar"); try (final FileOutputStream fileStream = new FileOutputStream(temp); - final ArrowFileWriter fileWriter = - new ArrowFileWriter(root, provider, fileStream.getChannel(), metadata, writeOption); - final ArrowStreamWriter streamWriter = - new ArrowStreamWriter(root, provider, Channels.newChannel(memoryStream), writeOption)) { + final ArrowFileWriter fileWriter = + new ArrowFileWriter(root, provider, fileStream.getChannel(), metadata, writeOption); + final ArrowStreamWriter streamWriter = + new ArrowStreamWriter(root, provider, Channels.newChannel(memoryStream), writeOption)) { writer.accept(root, fileWriter); writer.accept(root, streamWriter); } - MessageMetadataResult metadataResult = MessageSerializer.readMessage( - new ReadChannel(Channels.newChannel(new ByteArrayInputStream(memoryStream.toByteArray())))); + MessageMetadataResult metadataResult = + MessageSerializer.readMessage( + new ReadChannel( + Channels.newChannel(new ByteArrayInputStream(memoryStream.toByteArray())))); assertNotNull(metadataResult); assertEquals(writeOption.metadataVersion.toFlatbufID(), metadataResult.getMessage().version()); - try ( - BufferAllocator readerAllocator = allocator.newChildAllocator("reader", 0, allocator.getLimit()); + try (BufferAllocator readerAllocator = + allocator.newChildAllocator("reader", 0, allocator.getLimit()); FileInputStream fileInputStream = new FileInputStream(temp); ByteArrayInputStream inputStream = new ByteArrayInputStream(memoryStream.toByteArray()); - ArrowFileReader fileReader = new ArrowFileReader(fileInputStream.getChannel(), readerAllocator); + ArrowFileReader fileReader = + new ArrowFileReader(fileInputStream.getChannel(), readerAllocator); ArrowStreamReader streamReader = new ArrowStreamReader(inputStream, readerAllocator)) { fileValidator.accept(fileReader); streamValidator.accept(streamReader); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestUIntDictionaryRoundTrip.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestUIntDictionaryRoundTrip.java index 6aa7a0c6df5..c254cc5a326 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestUIntDictionaryRoundTrip.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestUIntDictionaryRoundTrip.java @@ -31,7 +31,6 @@ import java.util.Collection; import java.util.Map; import java.util.function.ToIntBiFunction; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.FieldVector; @@ -56,10 +55,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -/** - * Test the round-trip of dictionary encoding, - * with unsigned integer as indices. - */ +/** Test the round-trip of dictionary encoding, with unsigned integer as indices. */ @RunWith(Parameterized.class) public class TestUIntDictionaryRoundTrip { @@ -88,10 +84,13 @@ private byte[] writeData(FieldVector encodedVector) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); VectorSchemaRoot root = new VectorSchemaRoot( - Arrays.asList(encodedVector.getField()), Arrays.asList(encodedVector), encodedVector.getValueCount()); - try (ArrowWriter writer = streamMode ? - new ArrowStreamWriter(root, dictionaryProvider, out) : - new ArrowFileWriter(root, dictionaryProvider, Channels.newChannel(out))) { + Arrays.asList(encodedVector.getField()), + Arrays.asList(encodedVector), + encodedVector.getValueCount()); + try (ArrowWriter writer = + streamMode + ? new ArrowStreamWriter(root, dictionaryProvider, out) + : new ArrowFileWriter(root, dictionaryProvider, Channels.newChannel(out))) { writer.start(); writer.writeBatch(); writer.end(); @@ -106,10 +105,14 @@ private void readData( ToIntBiFunction valGetter, long dictionaryID, int[] expectedIndices, - String[] expectedDictItems) throws IOException { - try (ArrowReader reader = streamMode ? - new ArrowStreamReader(new ByteArrayInputStream(data), allocator) : - new ArrowFileReader(new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(data)), allocator)) { + String[] expectedDictItems) + throws IOException { + try (ArrowReader reader = + streamMode + ? new ArrowStreamReader(new ByteArrayInputStream(data), allocator) + : new ArrowFileReader( + new SeekableReadChannel(new ByteArrayReadableSeekableByteChannel(data)), + allocator)) { // verify schema Schema readSchema = reader.getVectorSchemaRoot().getSchema(); @@ -159,7 +162,7 @@ private ValueVector createEncodedVector(int bitWidth, VarCharVector dictionaryVe public void testUInt1RoundTrip() throws IOException { final int vectorLength = UInt1Vector.MAX_UINT1 & UInt1Vector.PROMOTION_MASK; try (VarCharVector dictionaryVector = new VarCharVector("dictionary", allocator); - UInt1Vector encodedVector1 = (UInt1Vector) createEncodedVector(8, dictionaryVector)) { + UInt1Vector encodedVector1 = (UInt1Vector) createEncodedVector(8, dictionaryVector)) { int[] indices = new int[vectorLength]; String[] dictionaryItems = new String[vectorLength]; for (int i = 0; i < vectorLength; i++) { @@ -171,8 +174,12 @@ public void testUInt1RoundTrip() throws IOException { setVector(dictionaryVector, dictionaryItems); byte[] data = writeData(encodedVector1); readData( - data, encodedVector1.getField(), (vector, index) -> (int) ((UInt1Vector) vector).getValueAsLong(index), - 8L, indices, dictionaryItems); + data, + encodedVector1.getField(), + (vector, index) -> (int) ((UInt1Vector) vector).getValueAsLong(index), + 8L, + indices, + dictionaryItems); } } @@ -180,18 +187,24 @@ public void testUInt1RoundTrip() throws IOException { public void testUInt2RoundTrip() throws IOException { try (VarCharVector dictionaryVector = new VarCharVector("dictionary", allocator); UInt2Vector encodedVector2 = (UInt2Vector) createEncodedVector(16, dictionaryVector)) { - int[] indices = new int[]{1, 3, 5, 7, 9, UInt2Vector.MAX_UINT2}; + int[] indices = new int[] {1, 3, 5, 7, 9, UInt2Vector.MAX_UINT2}; String[] dictItems = new String[UInt2Vector.MAX_UINT2]; for (int i = 0; i < UInt2Vector.MAX_UINT2; i++) { dictItems[i] = String.valueOf(i); } - setVector(encodedVector2, (char) 1, (char) 3, (char) 5, (char) 7, (char) 9, UInt2Vector.MAX_UINT2); + setVector( + encodedVector2, (char) 1, (char) 3, (char) 5, (char) 7, (char) 9, UInt2Vector.MAX_UINT2); setVector(dictionaryVector, dictItems); byte[] data = writeData(encodedVector2); - readData(data, encodedVector2.getField(), (vector, index) -> (int) ((UInt2Vector) vector).getValueAsLong(index), - 16L, indices, dictItems); + readData( + data, + encodedVector2.getField(), + (vector, index) -> (int) ((UInt2Vector) vector).getValueAsLong(index), + 16L, + indices, + dictItems); } } @@ -200,7 +213,7 @@ public void testUInt4RoundTrip() throws IOException { final int dictLength = 10; try (VarCharVector dictionaryVector = new VarCharVector("dictionary", allocator); UInt4Vector encodedVector4 = (UInt4Vector) createEncodedVector(32, dictionaryVector)) { - int[] indices = new int[]{1, 3, 5, 7, 9}; + int[] indices = new int[] {1, 3, 5, 7, 9}; String[] dictItems = new String[dictLength]; for (int i = 0; i < dictLength; i++) { dictItems[i] = String.valueOf(i); @@ -211,8 +224,13 @@ public void testUInt4RoundTrip() throws IOException { setVector(encodedVector4, 1, 3, 5, 7, 9); byte[] data = writeData(encodedVector4); - readData(data, encodedVector4.getField(), (vector, index) -> (int) ((UInt4Vector) vector).getValueAsLong(index), - 32L, indices, dictItems); + readData( + data, + encodedVector4.getField(), + (vector, index) -> (int) ((UInt4Vector) vector).getValueAsLong(index), + 32L, + indices, + dictItems); } } @@ -221,7 +239,7 @@ public void testUInt8RoundTrip() throws IOException { final int dictLength = 10; try (VarCharVector dictionaryVector = new VarCharVector("dictionary", allocator); UInt8Vector encodedVector8 = (UInt8Vector) createEncodedVector(64, dictionaryVector)) { - int[] indices = new int[]{1, 3, 5, 7, 9}; + int[] indices = new int[] {1, 3, 5, 7, 9}; String[] dictItems = new String[dictLength]; for (int i = 0; i < dictLength; i++) { dictItems[i] = String.valueOf(i); @@ -231,16 +249,18 @@ public void testUInt8RoundTrip() throws IOException { setVector(dictionaryVector, dictItems); byte[] data = writeData(encodedVector8); - readData(data, encodedVector8.getField(), (vector, index) -> (int) ((UInt8Vector) vector).getValueAsLong(index), - 64L, indices, dictItems); + readData( + data, + encodedVector8.getField(), + (vector, index) -> (int) ((UInt8Vector) vector).getValueAsLong(index), + 64L, + indices, + dictItems); } } @Parameterized.Parameters(name = "stream mode = {0}") public static Collection getRepeat() { - return Arrays.asList( - new Object[]{true}, - new Object[]{false} - ); + return Arrays.asList(new Object[] {true}, new Object[] {false}); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/message/TestMessageMetadataResult.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/message/TestMessageMetadataResult.java index ee5361547a0..12a4a158a6a 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/message/TestMessageMetadataResult.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/message/TestMessageMetadataResult.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals; import java.nio.ByteBuffer; - import org.junit.Test; public class TestMessageMetadataResult { @@ -28,9 +27,9 @@ public class TestMessageMetadataResult { @Test public void getMessageLength_returnsConstructValue() { // This API is used by spark. - MessageMetadataResult result = new MessageMetadataResult(1, ByteBuffer.allocate(0), - new org.apache.arrow.flatbuf.Message()); + MessageMetadataResult result = + new MessageMetadataResult( + 1, ByteBuffer.allocate(0), new org.apache.arrow.flatbuf.Message()); assertEquals(result.getMessageLength(), 1); } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/pojo/TestConvert.java b/java/vector/src/test/java/org/apache/arrow/vector/pojo/TestConvert.java index 5cc0d080053..2be68be6c28 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/pojo/TestConvert.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/pojo/TestConvert.java @@ -22,12 +22,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import com.google.flatbuffers.FlatBufferBuilder; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.util.Collections2; @@ -48,11 +48,7 @@ import org.apache.arrow.vector.types.pojo.Schema; import org.junit.Test; -import com.google.flatbuffers.FlatBufferBuilder; - -/** - * Test conversion between Flatbuf and Pojo field representations. - */ +/** Test conversion between Flatbuf and Pojo field representations. */ public class TestConvert { @Test @@ -65,7 +61,9 @@ public void simple() { public void complex() { java.util.List children = new ArrayList<>(); children.add(new Field("child1", FieldType.nullable(Utf8.INSTANCE), null)); - children.add(new Field("child2", FieldType.nullable(new FloatingPoint(SINGLE)), Collections.emptyList())); + children.add( + new Field( + "child2", FieldType.nullable(new FloatingPoint(SINGLE)), Collections.emptyList())); Field initialField = new Field("a", FieldType.nullable(Struct.INSTANCE), children); run(initialField); @@ -75,8 +73,9 @@ public void complex() { public void list() throws Exception { java.util.List children = new ArrayList<>(); try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - ListVector writeVector = ListVector.empty("list", allocator); - FixedSizeListVector writeFixedVector = FixedSizeListVector.empty("fixedlist", 5, allocator)) { + ListVector writeVector = ListVector.empty("list", allocator); + FixedSizeListVector writeFixedVector = + FixedSizeListVector.empty("fixedlist", 5, allocator)) { Field listVectorField = writeVector.getField(); children.add(listVectorField); Field listFixedVectorField = writeFixedVector.getField(); @@ -88,7 +87,8 @@ public void list() throws Exception { parent.add(initialField); FlatBufferBuilder builder = new FlatBufferBuilder(); builder.finish(initialField.getField(builder)); - org.apache.arrow.flatbuf.Field flatBufField = org.apache.arrow.flatbuf.Field.getRootAsField(builder.dataBuffer()); + org.apache.arrow.flatbuf.Field flatBufField = + org.apache.arrow.flatbuf.Field.getRootAsField(builder.dataBuffer()); Field finalField = Field.convertField(flatBufField); assertEquals(initialField, finalField); assertFalse(finalField.toString().contains("[DEFAULT]")); @@ -110,7 +110,9 @@ public void list() throws Exception { public void schema() { java.util.List children = new ArrayList<>(); children.add(new Field("child1", FieldType.nullable(Utf8.INSTANCE), null)); - children.add(new Field("child2", FieldType.nullable(new FloatingPoint(SINGLE)), Collections.emptyList())); + children.add( + new Field( + "child2", FieldType.nullable(new FloatingPoint(SINGLE)), Collections.emptyList())); Schema initialSchema = new Schema(children); run(initialSchema); } @@ -119,7 +121,9 @@ public void schema() { public void schemaMetadata() { java.util.List children = new ArrayList<>(); children.add(new Field("child1", FieldType.nullable(Utf8.INSTANCE), null)); - children.add(new Field("child2", FieldType.nullable(new FloatingPoint(SINGLE)), Collections.emptyList())); + children.add( + new Field( + "child2", FieldType.nullable(new FloatingPoint(SINGLE)), Collections.emptyList())); Map metadata = new HashMap<>(); metadata.put("key1", "value1"); metadata.put("key2", "value2"); @@ -131,21 +135,45 @@ public void schemaMetadata() { public void nestedSchema() { java.util.List children = new ArrayList<>(); children.add(new Field("child1", FieldType.nullable(Utf8.INSTANCE), null)); - children.add(new Field("child2", FieldType.nullable(new FloatingPoint(SINGLE)), Collections.emptyList())); - children.add(new Field("child3", FieldType.nullable(new Struct()), Collections2.asImmutableList( - new Field("child3.1", FieldType.nullable(Utf8.INSTANCE), null), - new Field("child3.2", FieldType.nullable(new FloatingPoint(DOUBLE)), Collections.emptyList()) - ))); - children.add(new Field("child4", FieldType.nullable(new List()), Collections2.asImmutableList( - new Field("child4.1", FieldType.nullable(Utf8.INSTANCE), null) - ))); - children.add(new Field("child5", FieldType.nullable( - new Union(UnionMode.Sparse, new int[] {MinorType.TIMESTAMPMILLI.ordinal(), MinorType.FLOAT8.ordinal()})), - Collections2.asImmutableList( - new Field("child5.1", FieldType.nullable(new Timestamp(TimeUnit.MILLISECOND, null)), null), - new Field("child5.2", FieldType.nullable(new FloatingPoint(DOUBLE)), Collections.emptyList()), - new Field("child5.3", FieldType.nullable(new Timestamp(TimeUnit.MILLISECOND, "UTC")), null) - ))); + children.add( + new Field( + "child2", FieldType.nullable(new FloatingPoint(SINGLE)), Collections.emptyList())); + children.add( + new Field( + "child3", + FieldType.nullable(new Struct()), + Collections2.asImmutableList( + new Field("child3.1", FieldType.nullable(Utf8.INSTANCE), null), + new Field( + "child3.2", + FieldType.nullable(new FloatingPoint(DOUBLE)), + Collections.emptyList())))); + children.add( + new Field( + "child4", + FieldType.nullable(new List()), + Collections2.asImmutableList( + new Field("child4.1", FieldType.nullable(Utf8.INSTANCE), null)))); + children.add( + new Field( + "child5", + FieldType.nullable( + new Union( + UnionMode.Sparse, + new int[] {MinorType.TIMESTAMPMILLI.ordinal(), MinorType.FLOAT8.ordinal()})), + Collections2.asImmutableList( + new Field( + "child5.1", + FieldType.nullable(new Timestamp(TimeUnit.MILLISECOND, null)), + null), + new Field( + "child5.2", + FieldType.nullable(new FloatingPoint(DOUBLE)), + Collections.emptyList()), + new Field( + "child5.3", + FieldType.nullable(new Timestamp(TimeUnit.MILLISECOND, "UTC")), + null)))); Schema initialSchema = new Schema(children); run(initialSchema); } @@ -153,7 +181,8 @@ public void nestedSchema() { private void run(Field initialField) { FlatBufferBuilder builder = new FlatBufferBuilder(); builder.finish(initialField.getField(builder)); - org.apache.arrow.flatbuf.Field flatBufField = org.apache.arrow.flatbuf.Field.getRootAsField(builder.dataBuffer()); + org.apache.arrow.flatbuf.Field flatBufField = + org.apache.arrow.flatbuf.Field.getRootAsField(builder.dataBuffer()); Field finalField = Field.convertField(flatBufField); assertEquals(initialField, finalField); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java b/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java index 78f2ee51b89..df22ccd8e19 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.FieldVector; @@ -174,8 +173,7 @@ void testGetVector() { List vectorList = twoIntColumns(allocator); try (Table t = new Table(vectorList)) { assertNotNull(t.getVector(INT_VECTOR_NAME_1)); - assertThrows(IllegalArgumentException.class, - () -> t.getVector("wrong name")); + assertThrows(IllegalArgumentException.class, () -> t.getVector("wrong name")); } } @@ -195,8 +193,7 @@ void getVectorCopyByIndex() { assertEquals(original.getObject(i), copy.getObject(i)); } } - assertThrows(IllegalArgumentException.class, - () -> t.getVector("wrong name")); + assertThrows(IllegalArgumentException.class, () -> t.getVector("wrong name")); } } @@ -215,8 +212,7 @@ void getVectorCopyByName() { assertEquals(original.getObject(i), copy.getObject(i)); } } - assertThrows(IllegalArgumentException.class, - () -> t.getVector("wrong name")); + assertThrows(IllegalArgumentException.class, () -> t.getVector("wrong name")); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/RowTest.java b/java/vector/src/test/java/org/apache/arrow/vector/table/RowTest.java index eb50e866b19..072c55206ba 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/RowTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/RowTest.java @@ -53,7 +53,6 @@ import java.time.Period; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -169,8 +168,7 @@ void testNameNotFound() { try (Table t = new Table(vectorList)) { Row c = t.immutableRow(); c.setPosition(1); - assertThrows(IllegalArgumentException.class, - () -> c.getVarCharObj("wrong name")); + assertThrows(IllegalArgumentException.class, () -> c.getVarCharObj("wrong name")); } } @@ -180,8 +178,7 @@ void testWrongType() { try (Table t = new Table(vectorList)) { Row c = t.immutableRow(); c.setPosition(1); - assertThrows(ClassCastException.class, - () -> c.getVarCharObj(INT_VECTOR_NAME_1)); + assertThrows(ClassCastException.class, () -> c.getVarCharObj(INT_VECTOR_NAME_1)); } } @@ -252,7 +249,8 @@ void getIntervalDay() { IntervalUnit unit = IntervalUnit.DAY_TIME; final FieldType fieldType = FieldType.nullable(new ArrowType.Interval(unit)); - IntervalDayVector intervalDayVector = new IntervalDayVector("intervalDay_vector", fieldType, allocator); + IntervalDayVector intervalDayVector = + new IntervalDayVector("intervalDay_vector", fieldType, allocator); NullableIntervalDayHolder holder1 = new NullableIntervalDayHolder(); NullableIntervalDayHolder holder2 = new NullableIntervalDayHolder(); @@ -329,7 +327,8 @@ void getIntervalYear() { IntervalUnit unit = IntervalUnit.YEAR_MONTH; final FieldType fieldType = FieldType.nullable(new ArrowType.Interval(unit)); - IntervalYearVector intervalYearVector = new IntervalYearVector("intervalYear_vector", fieldType, allocator); + IntervalYearVector intervalYearVector = + new IntervalYearVector("intervalYear_vector", fieldType, allocator); NullableIntervalYearHolder holder1 = new NullableIntervalYearHolder(); NullableIntervalYearHolder holder2 = new NullableIntervalYearHolder(); @@ -737,8 +736,7 @@ void testSimpleStructVector1() { JsonStringHashMap struct = (JsonStringHashMap) c.getStruct(STRUCT_VECTOR_NAME); @SuppressWarnings("unchecked") - JsonStringHashMap struct1 = - (JsonStringHashMap) c.getStruct(0); + JsonStringHashMap struct1 = (JsonStringHashMap) c.getStruct(0); int a = (int) struct.get("struct_int_child"); double b = (double) struct.get("struct_flt_child"); int a1 = (int) struct1.get("struct_int_child"); @@ -792,21 +790,21 @@ void testSimpleDenseUnionVector() { @Test void testExtensionTypeVector() { - TestExtensionType.LocationVector vector = new TestExtensionType.LocationVector("location", allocator); + TestExtensionType.LocationVector vector = + new TestExtensionType.LocationVector("location", allocator); vector.allocateNew(); vector.set(0, 34.073814f, -118.240784f); vector.setValueCount(1); try (VectorSchemaRoot vsr = VectorSchemaRoot.of(vector); - Table table = new Table(vsr)) { + Table table = new Table(vsr)) { Row c = table.immutableRow(); c.setPosition(0); Object object0 = c.getExtensionType("location"); Object object1 = c.getExtensionType(0); assertEquals(object0, object1); @SuppressWarnings("unchecked") - JsonStringHashMap struct0 = - (JsonStringHashMap) object0; + JsonStringHashMap struct0 = (JsonStringHashMap) object0; assertEquals(34.073814f, struct0.get("Latitude")); } } @@ -822,8 +820,7 @@ void testSimpleMapVector1() { List> list = (List>) c.getMap(BIGINT_INT_MAP_VECTOR_NAME); @SuppressWarnings("unchecked") - List> list1 = - (List>) c.getMap(0); + List> list1 = (List>) c.getMap(0); for (int j = 0; j < list1.size(); j++) { assertEquals(list.get(j), list1.get(j)); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/TableTest.java b/java/vector/src/test/java/org/apache/arrow/vector/table/TableTest.java index 539482e510a..ee7e910f5c0 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/TableTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/TableTest.java @@ -26,7 +26,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.FieldVector; @@ -100,7 +99,8 @@ void constructor() { } /** - * Tests construction with an iterable that's not a list (there is a specialty constructor for Lists). + * Tests construction with an iterable that's not a list (there is a specialty constructor for + * Lists). */ @Test void constructor2() { @@ -133,7 +133,7 @@ void copy() { try (Table t = new Table(vectorList)) { assertEquals(2, t.getVectorCount()); try (Table copy = t.copy()) { - for (FieldVector v: t.fieldVectors) { + for (FieldVector v : t.fieldVectors) { FieldVector vCopy = copy.getVector(v.getName()); assertNotNull(vCopy); assertEquals(v.getValueCount(), vCopy.getValueCount()); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java b/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java index cb0b7b8eb6b..65703550c74 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java @@ -22,7 +22,6 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.BigIntVector; import org.apache.arrow.vector.BitVector; @@ -144,8 +143,8 @@ static List intPlusLargeVarcharColumns(BufferAllocator allocator) { /** * Returns a list of two FieldVectors to be used to instantiate Tables for testing. The first - * vector is an IntVector and the second is a VarBinaryVector. Each vector has two values set. - * The large binary vectors values are "one" and "two" encoded with UTF-8 + * vector is an IntVector and the second is a VarBinaryVector. Each vector has two values set. The + * large binary vectors values are "one" and "two" encoded with UTF-8 */ static List intPlusVarBinaryColumns(BufferAllocator allocator) { List vectorList = new ArrayList<>(); @@ -162,8 +161,8 @@ static List intPlusVarBinaryColumns(BufferAllocator allocator) { /** * Returns a list of two FieldVectors to be used to instantiate Tables for testing. The first - * vector is an IntVector and the second is a VarBinaryVector. Each vector has two values set. - * The large binary vectors values are "one" and "two" encoded with UTF-8 + * vector is an IntVector and the second is a VarBinaryVector. Each vector has two values set. The + * large binary vectors values are "one" and "two" encoded with UTF-8 */ static List intPlusLargeVarBinaryColumns(BufferAllocator allocator) { List vectorList = new ArrayList<>(); @@ -180,8 +179,8 @@ static List intPlusLargeVarBinaryColumns(BufferAllocator allocator) /** * Returns a list of two FieldVectors to be used to instantiate Tables for testing. The first - * vector is an IntVector and the second is a FixedSizeBinary vector. Each vector has two values set. - * The large binary vectors values are "one" and "two" encoded with UTF-8 + * vector is an IntVector and the second is a FixedSizeBinary vector. Each vector has two values + * set. The large binary vectors values are "one" and "two" encoded with UTF-8 */ static List intPlusFixedBinaryColumns(BufferAllocator allocator) { List vectorList = new ArrayList<>(); @@ -207,9 +206,10 @@ private static IntVector getSimpleIntVector(BufferAllocator allocator) { /** * Returns a list of fixed-width vectors for testing. It includes + * *

    - *
  1. all integral and floating point types
  2. - *
  3. all basic times and timestamps (second, milli, micro, nano
  4. + *
  5. all integral and floating point types + *
  6. all basic times and timestamps (second, milli, micro, nano *
* * The vector names are based on their type name (e.g. BigIntVector is called "bigInt_vector" @@ -222,8 +222,8 @@ static List fixedWidthVectors(BufferAllocator allocator, int rowCou } /** - * Returns a list of all integral and floating point vectors. - * The vector names are based on their type name (e.g. BigIntVector is called "bigInt_vector" + * Returns a list of all integral and floating point vectors. The vector names are based on their + * type name (e.g. BigIntVector is called "bigInt_vector" */ static List numericVectors( List vectors, BufferAllocator allocator, int rowCount) { @@ -285,8 +285,11 @@ static List intervalVectors(BufferAllocator allocator, int rowCount vectors.add(new IntervalDayVector("intervalDay_vector", allocator)); vectors.add(new IntervalYearVector("intervalYear_vector", allocator)); vectors.add(new IntervalMonthDayNanoVector("intervalMonthDayNano_vector", allocator)); - vectors.add(new DurationVector("duration_vector", - new FieldType(true, new ArrowType.Duration(TimeUnit.SECOND), null), allocator)); + vectors.add( + new DurationVector( + "duration_vector", + new FieldType(true, new ArrowType.Duration(TimeUnit.SECOND), null), + allocator)); vectors.forEach(vec -> GenerateSampleData.generateTestData(vec, rowCount)); return vectors; } @@ -369,9 +372,11 @@ static MapVector simpleMapVector(BufferAllocator allocator) { static List decimalVector(BufferAllocator allocator, int rowCount) { List vectors = new ArrayList<>(); - vectors.add(new DecimalVector("decimal_vector", - new FieldType(true, new ArrowType.Decimal(38, 10, 128), null), - allocator)); + vectors.add( + new DecimalVector( + "decimal_vector", + new FieldType(true, new ArrowType.Decimal(38, 10, 128), null), + allocator)); vectors.forEach(vec -> generateDecimalData((DecimalVector) vec, rowCount)); return vectors; } @@ -433,5 +438,4 @@ private static void generateDecimalData(DecimalVector vector, int valueCount) { } vector.setValueCount(valueCount); } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/test/util/ArrowTestDataUtil.java b/java/vector/src/test/java/org/apache/arrow/vector/test/util/ArrowTestDataUtil.java index 901a09e313f..9015ae207d4 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/test/util/ArrowTestDataUtil.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/test/util/ArrowTestDataUtil.java @@ -21,9 +21,7 @@ import java.nio.file.Paths; import java.util.Objects; -/** - * Utility methods and constants for working with the arrow-testing repo. - */ +/** Utility methods and constants for working with the arrow-testing repo. */ public final class ArrowTestDataUtil { public static final String TEST_DATA_ENV_VAR = "ARROW_TEST_DATA"; public static final String TEST_DATA_PROPERTY = "arrow.test.dataRoot"; @@ -33,11 +31,13 @@ public static Path getTestDataRoot() { if (path == null) { path = System.getProperty(TEST_DATA_PROPERTY); } - return Paths.get(Objects.requireNonNull(path, - String.format("Could not find test data path. Set the environment variable %s or the JVM property %s.", - TEST_DATA_ENV_VAR, TEST_DATA_PROPERTY))); + return Paths.get( + Objects.requireNonNull( + path, + String.format( + "Could not find test data path. Set the environment variable %s or the JVM property %s.", + TEST_DATA_ENV_VAR, TEST_DATA_PROPERTY))); } - private ArrowTestDataUtil() { - } + private ArrowTestDataUtil() {} } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/testing/RandomDataGenerator.java b/java/vector/src/test/java/org/apache/arrow/vector/testing/RandomDataGenerator.java index 4b1094d288b..dff28dde76f 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/testing/RandomDataGenerator.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/testing/RandomDataGenerator.java @@ -20,9 +20,7 @@ import java.util.Random; import java.util.function.Supplier; -/** - * Utility for generating random data. - */ +/** Utility for generating random data. */ public class RandomDataGenerator { static final Random random = new Random(0); @@ -39,6 +37,5 @@ public class RandomDataGenerator { public static final Supplier DOUBLE_GENERATOR = () -> random.nextDouble(); - private RandomDataGenerator() { - } + private RandomDataGenerator() {} } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/testing/TestValueVectorPopulator.java b/java/vector/src/test/java/org/apache/arrow/vector/testing/TestValueVectorPopulator.java index 74257c45ca8..63683fdb785 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/testing/TestValueVectorPopulator.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/testing/TestValueVectorPopulator.java @@ -50,7 +50,6 @@ import org.apache.arrow.vector.VarBinaryVector; import org.apache.arrow.vector.VarCharVector; import org.apache.arrow.vector.compare.VectorEqualsVisitor; -import org.apache.arrow.vector.testing.ValueVectorDataPopulator; import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.FieldType; @@ -75,7 +74,7 @@ public void terminate() throws Exception { @Test public void testPopulateBigIntVector() { try (final BigIntVector vector1 = new BigIntVector("vector", allocator); - final BigIntVector vector2 = new BigIntVector("vector", allocator)) { + final BigIntVector vector2 = new BigIntVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -95,7 +94,7 @@ public void testPopulateBigIntVector() { @Test public void testPopulateBitVector() { try (final BitVector vector1 = new BitVector("vector", allocator); - final BitVector vector2 = new BitVector("vector", allocator)) { + final BitVector vector2 = new BitVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -115,7 +114,7 @@ public void testPopulateBitVector() { @Test public void testPopulateDateDayVector() { try (final DateDayVector vector1 = new DateDayVector("vector", allocator); - final DateDayVector vector2 = new DateDayVector("vector", allocator)) { + final DateDayVector vector2 = new DateDayVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -135,7 +134,7 @@ public void testPopulateDateDayVector() { @Test public void testPopulateDateMilliVector() { try (final DateMilliVector vector1 = new DateMilliVector("vector", allocator); - final DateMilliVector vector2 = new DateMilliVector("vector", allocator)) { + final DateMilliVector vector2 = new DateMilliVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -155,7 +154,7 @@ public void testPopulateDateMilliVector() { @Test public void testPopulateDecimalVector() { try (final DecimalVector vector1 = new DecimalVector("vector", allocator, 10, 3); - final DecimalVector vector2 = new DecimalVector("vector", allocator, 10, 3)) { + final DecimalVector vector2 = new DecimalVector("vector", allocator, 10, 3)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -176,7 +175,7 @@ public void testPopulateDecimalVector() { public void testPopulateDurationVector() { final FieldType fieldType = FieldType.nullable(new ArrowType.Duration(TimeUnit.SECOND)); try (final DurationVector vector1 = new DurationVector("vector", fieldType, allocator); - final DurationVector vector2 = new DurationVector("vector", fieldType, allocator)) { + final DurationVector vector2 = new DurationVector("vector", fieldType, allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -197,7 +196,7 @@ public void testPopulateDurationVector() { @Test public void testPopulateFixedSizeBinaryVector() { try (final FixedSizeBinaryVector vector1 = new FixedSizeBinaryVector("vector", allocator, 5); - final FixedSizeBinaryVector vector2 = new FixedSizeBinaryVector("vector", allocator, 5)) { + final FixedSizeBinaryVector vector2 = new FixedSizeBinaryVector("vector", allocator, 5)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -209,8 +208,18 @@ public void testPopulateFixedSizeBinaryVector() { } vector1.setValueCount(10); - setVector(vector2, null, "test1".getBytes(), null, "test3".getBytes(), null, "test5".getBytes(), null, - "test7".getBytes(), null, "test9".getBytes()); + setVector( + vector2, + null, + "test1".getBytes(), + null, + "test3".getBytes(), + null, + "test5".getBytes(), + null, + "test7".getBytes(), + null, + "test9".getBytes()); assertTrue(VectorEqualsVisitor.vectorEquals(vector1, vector2)); } } @@ -218,7 +227,7 @@ public void testPopulateFixedSizeBinaryVector() { @Test public void testPopulateFloat4Vector() { try (final Float4Vector vector1 = new Float4Vector("vector", allocator); - final Float4Vector vector2 = new Float4Vector("vector", allocator)) { + final Float4Vector vector2 = new Float4Vector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -237,7 +246,7 @@ public void testPopulateFloat4Vector() { @Test public void testPopulateFloat8Vector() { try (final Float8Vector vector1 = new Float8Vector("vector", allocator); - final Float8Vector vector2 = new Float8Vector("vector", allocator)) { + final Float8Vector vector2 = new Float8Vector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -256,7 +265,7 @@ public void testPopulateFloat8Vector() { @Test public void testPopulateIntVector() { try (final IntVector vector1 = new IntVector("vector", allocator); - final IntVector vector2 = new IntVector("vector", allocator)) { + final IntVector vector2 = new IntVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -276,7 +285,7 @@ public void testPopulateIntVector() { @Test public void testPopulateSmallIntVector() { try (final SmallIntVector vector1 = new SmallIntVector("vector", allocator); - final SmallIntVector vector2 = new SmallIntVector("vector", allocator)) { + final SmallIntVector vector2 = new SmallIntVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -288,8 +297,9 @@ public void testPopulateSmallIntVector() { } vector1.setValueCount(10); - ValueVectorDataPopulator.setVector(vector2, null, (short) 1, null, (short) 3, null, (short) 5, - null, (short) 7, null, (short) 9); + ValueVectorDataPopulator.setVector( + vector2, null, (short) 1, null, (short) 3, null, (short) 5, null, (short) 7, null, + (short) 9); assertTrue(VectorEqualsVisitor.vectorEquals(vector1, vector2)); } } @@ -297,7 +307,7 @@ public void testPopulateSmallIntVector() { @Test public void testPopulateIntervalDayVector() { try (final IntervalYearVector vector1 = new IntervalYearVector("vector", allocator); - final IntervalYearVector vector2 = new IntervalYearVector("vector", allocator)) { + final IntervalYearVector vector2 = new IntervalYearVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -317,7 +327,7 @@ public void testPopulateIntervalDayVector() { @Test public void testPopulateTimeMicroVector() { try (final TimeMicroVector vector1 = new TimeMicroVector("vector", allocator); - final TimeMicroVector vector2 = new TimeMicroVector("vector", allocator)) { + final TimeMicroVector vector2 = new TimeMicroVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -355,7 +365,7 @@ public void testPopulateTimeMilliVector() { @Test public void testPopulateTimeNanoVector() { try (final TimeNanoVector vector1 = new TimeNanoVector("vector", allocator); - final TimeNanoVector vector2 = new TimeNanoVector("vector", allocator)) { + final TimeNanoVector vector2 = new TimeNanoVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -374,7 +384,7 @@ public void testPopulateTimeNanoVector() { @Test public void testPopulateTimeSecVector() { try (final TimeSecVector vector1 = new TimeSecVector("vector", allocator); - final TimeSecVector vector2 = new TimeSecVector("vector", allocator)) { + final TimeSecVector vector2 = new TimeSecVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -412,7 +422,7 @@ public void testPopulateTimeStampMicroVector() { @Test public void testPopulateTimeStampMilliVector() { try (final TimeStampMilliVector vector1 = new TimeStampMilliVector("vector", allocator); - final TimeStampMilliVector vector2 = new TimeStampMilliVector("vector", allocator)) { + final TimeStampMilliVector vector2 = new TimeStampMilliVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -450,7 +460,7 @@ public void testPopulateTimeStampNanoVector() { @Test public void testPopulateTimeStampSecVector() { try (final TimeStampSecVector vector1 = new TimeStampSecVector("vector", allocator); - final TimeStampSecVector vector2 = new TimeStampSecVector("vector", allocator)) { + final TimeStampSecVector vector2 = new TimeStampSecVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -469,7 +479,7 @@ public void testPopulateTimeStampSecVector() { @Test public void testPopulateTinyIntVector() { try (final TinyIntVector vector1 = new TinyIntVector("vector", allocator); - final TinyIntVector vector2 = new TinyIntVector("vector", allocator)) { + final TinyIntVector vector2 = new TinyIntVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -480,7 +490,8 @@ public void testPopulateTinyIntVector() { } } vector1.setValueCount(10); - setVector(vector2, null, (byte) 1, null, (byte) 3, null, (byte) 5, null, (byte) 7, null, (byte) 9); + setVector( + vector2, null, (byte) 1, null, (byte) 3, null, (byte) 5, null, (byte) 7, null, (byte) 9); assertTrue(VectorEqualsVisitor.vectorEquals(vector1, vector2)); } } @@ -488,7 +499,7 @@ public void testPopulateTinyIntVector() { @Test public void testPopulateUInt1Vector() { try (final UInt1Vector vector1 = new UInt1Vector("vector", allocator); - final UInt1Vector vector2 = new UInt1Vector("vector", allocator)) { + final UInt1Vector vector2 = new UInt1Vector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -499,7 +510,8 @@ public void testPopulateUInt1Vector() { } } vector1.setValueCount(10); - setVector(vector2, null, (byte) 1, null, (byte) 3, null, (byte) 5, null, (byte) 7, null, (byte) 9); + setVector( + vector2, null, (byte) 1, null, (byte) 3, null, (byte) 5, null, (byte) 7, null, (byte) 9); assertTrue(VectorEqualsVisitor.vectorEquals(vector1, vector2)); } } @@ -507,7 +519,7 @@ public void testPopulateUInt1Vector() { @Test public void testPopulateUInt2Vector() { try (final UInt2Vector vector1 = new UInt2Vector("vector", allocator); - final UInt2Vector vector2 = new UInt2Vector("vector", allocator)) { + final UInt2Vector vector2 = new UInt2Vector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -518,7 +530,8 @@ public void testPopulateUInt2Vector() { } } vector1.setValueCount(10); - setVector(vector2, null, (char) 1, null, (char) 3, null, (char) 5, null, (char) 7, null, (char) 9); + setVector( + vector2, null, (char) 1, null, (char) 3, null, (char) 5, null, (char) 7, null, (char) 9); assertTrue(VectorEqualsVisitor.vectorEquals(vector1, vector2)); } } @@ -526,7 +539,7 @@ public void testPopulateUInt2Vector() { @Test public void testPopulateUInt4Vector() { try (final UInt4Vector vector1 = new UInt4Vector("vector", allocator); - final UInt4Vector vector2 = new UInt4Vector("vector", allocator)) { + final UInt4Vector vector2 = new UInt4Vector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -564,7 +577,7 @@ public void testPopulateUInt8Vector() { @Test public void testPopulateVarBinaryVector() { try (final VarBinaryVector vector1 = new VarBinaryVector("vector", allocator); - final VarBinaryVector vector2 = new VarBinaryVector("vector", allocator)) { + final VarBinaryVector vector2 = new VarBinaryVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { @@ -576,8 +589,18 @@ public void testPopulateVarBinaryVector() { } vector1.setValueCount(10); - setVector(vector2, null, "test1".getBytes(), null, "test3".getBytes(), null, "test5".getBytes(), null, - "test7".getBytes(), null, "test9".getBytes()); + setVector( + vector2, + null, + "test1".getBytes(), + null, + "test3".getBytes(), + null, + "test5".getBytes(), + null, + "test7".getBytes(), + null, + "test9".getBytes()); assertTrue(VectorEqualsVisitor.vectorEquals(vector1, vector2)); } } @@ -585,7 +608,7 @@ public void testPopulateVarBinaryVector() { @Test public void testPopulateVarCharVector() { try (final VarCharVector vector1 = new VarCharVector("vector", allocator); - final VarCharVector vector2 = new VarCharVector("vector", allocator)) { + final VarCharVector vector2 = new VarCharVector("vector", allocator)) { vector1.allocateNew(10); for (int i = 0; i < 10; i++) { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/testing/ValueVectorDataPopulator.java b/java/vector/src/test/java/org/apache/arrow/vector/testing/ValueVectorDataPopulator.java index f9f0357861c..427df2ec180 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/testing/ValueVectorDataPopulator.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/testing/ValueVectorDataPopulator.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; - import org.apache.arrow.vector.BigIntVector; import org.apache.arrow.vector.BitVector; import org.apache.arrow.vector.BitVectorHelper; @@ -70,16 +69,12 @@ import org.apache.arrow.vector.types.Types.MinorType; import org.apache.arrow.vector.types.pojo.FieldType; -/** - * Utility for populating {@link org.apache.arrow.vector.ValueVector}. - */ +/** Utility for populating {@link org.apache.arrow.vector.ValueVector}. */ public class ValueVectorDataPopulator { - private ValueVectorDataPopulator(){} + private ValueVectorDataPopulator() {} - /** - * Populate values for BigIntVector. - */ + /** Populate values for BigIntVector. */ public static void setVector(BigIntVector vector, Long... values) { final int length = values.length; vector.allocateNew(length); @@ -91,9 +86,7 @@ public static void setVector(BigIntVector vector, Long... values) { vector.setValueCount(length); } - /** - * Populate values for BitVector. - */ + /** Populate values for BitVector. */ public static void setVector(BitVector vector, Integer... values) { final int length = values.length; vector.allocateNew(length); @@ -107,6 +100,7 @@ public static void setVector(BitVector vector, Integer... values) { /** * Populate values for DateDayVector. + * * @param values numbers of days since UNIX epoch */ public static void setVector(DateDayVector vector, Integer... values) { @@ -122,6 +116,7 @@ public static void setVector(DateDayVector vector, Integer... values) { /** * Populate values for DateMilliVector. + * * @param values numbers of milliseconds since UNIX epoch */ public static void setVector(DateMilliVector vector, Long... values) { @@ -135,9 +130,7 @@ public static void setVector(DateMilliVector vector, Long... values) { vector.setValueCount(length); } - /** - * Populate values for DecimalVector. - */ + /** Populate values for DecimalVector. */ public static void setVector(DecimalVector vector, Long... values) { final int length = values.length; vector.allocateNew(length); @@ -149,9 +142,7 @@ public static void setVector(DecimalVector vector, Long... values) { vector.setValueCount(length); } - /** - * Populate values for Decimal256Vector. - */ + /** Populate values for Decimal256Vector. */ public static void setVector(Decimal256Vector vector, Long... values) { final int length = values.length; vector.allocateNew(length); @@ -163,9 +154,7 @@ public static void setVector(Decimal256Vector vector, Long... values) { vector.setValueCount(length); } - /** - * Populate values for Decimal256Vector. - */ + /** Populate values for Decimal256Vector. */ public static void setVector(Decimal256Vector vector, BigDecimal... values) { final int length = values.length; vector.allocateNew(length); @@ -179,7 +168,9 @@ public static void setVector(Decimal256Vector vector, BigDecimal... values) { /** * Populate values for DurationVector. - * @param values values of elapsed time in either seconds, milliseconds, microseconds or nanoseconds. + * + * @param values values of elapsed time in either seconds, milliseconds, microseconds or + * nanoseconds. */ public static void setVector(DurationVector vector, Long... values) { final int length = values.length; @@ -192,9 +183,7 @@ public static void setVector(DurationVector vector, Long... values) { vector.setValueCount(length); } - /** - * Populate values for FixedSizeBinaryVector. - */ + /** Populate values for FixedSizeBinaryVector. */ public static void setVector(FixedSizeBinaryVector vector, byte[]... values) { final int length = values.length; vector.allocateNewSafe(); @@ -206,9 +195,7 @@ public static void setVector(FixedSizeBinaryVector vector, byte[]... values) { vector.setValueCount(length); } - /** - * Populate values for Float4Vector. - */ + /** Populate values for Float4Vector. */ public static void setVector(Float4Vector vector, Float... values) { final int length = values.length; vector.allocateNew(length); @@ -220,9 +207,7 @@ public static void setVector(Float4Vector vector, Float... values) { vector.setValueCount(length); } - /** - * Populate values for Float8Vector. - */ + /** Populate values for Float8Vector. */ public static void setVector(Float8Vector vector, Double... values) { final int length = values.length; vector.allocateNew(length); @@ -234,9 +219,7 @@ public static void setVector(Float8Vector vector, Double... values) { vector.setValueCount(length); } - /** - * Populate values for IntVector. - */ + /** Populate values for IntVector. */ public static void setVector(IntVector vector, Integer... values) { final int length = values.length; vector.allocateNew(length); @@ -250,7 +233,9 @@ public static void setVector(IntVector vector, Integer... values) { /** * Populate values for IntervalDayVector. - * @param values holders witch holds days and milliseconds values which represents interval in SQL style. + * + * @param values holders witch holds days and milliseconds values which represents interval in SQL + * style. */ public static void setVector(IntervalDayVector vector, IntervalDayHolder... values) { final int length = values.length; @@ -265,6 +250,7 @@ public static void setVector(IntervalDayVector vector, IntervalDayHolder... valu /** * Populate values for IntervalYearVector. + * * @param values total month intervals in SQL style. */ public static void setVector(IntervalYearVector vector, Integer... values) { @@ -278,9 +264,7 @@ public static void setVector(IntervalYearVector vector, Integer... values) { vector.setValueCount(length); } - /** - * Populate values for SmallIntVector. - */ + /** Populate values for SmallIntVector. */ public static void setVector(SmallIntVector vector, Short... values) { final int length = values.length; vector.allocateNew(length); @@ -294,6 +278,7 @@ public static void setVector(SmallIntVector vector, Short... values) { /** * Populate values for TimeMicroVector. + * * @param values numbers of microseconds since UNIX epoch */ public static void setVector(TimeMicroVector vector, Long... values) { @@ -309,6 +294,7 @@ public static void setVector(TimeMicroVector vector, Long... values) { /** * Populate values for TimeMicroVector. + * * @param values numbers of milliseconds since UNIX epoch */ public static void setVector(TimeMilliVector vector, Integer... values) { @@ -324,6 +310,7 @@ public static void setVector(TimeMilliVector vector, Integer... values) { /** * Populate values for TimeNanoVector. + * * @param values numbers of nanoseconds since UNIX epoch */ public static void setVector(TimeNanoVector vector, Long... values) { @@ -339,6 +326,7 @@ public static void setVector(TimeNanoVector vector, Long... values) { /** * Populate values for TimeSecVector. + * * @param values numbers of seconds since UNIX epoch */ public static void setVector(TimeSecVector vector, Integer... values) { @@ -354,6 +342,7 @@ public static void setVector(TimeSecVector vector, Integer... values) { /** * Populate values for TimeStampMicroTZVector. + * * @param values numbers of microseconds since UNIX epoch */ public static void setVector(TimeStampMicroTZVector vector, Long... values) { @@ -369,6 +358,7 @@ public static void setVector(TimeStampMicroTZVector vector, Long... values) { /** * Populate values for TimeStampMicroVector. + * * @param values numbers of microseconds since UNIX epoch */ public static void setVector(TimeStampMicroVector vector, Long... values) { @@ -384,6 +374,7 @@ public static void setVector(TimeStampMicroVector vector, Long... values) { /** * Populate values for TimeStampMilliTZVector. + * * @param values numbers of milliseconds since UNIX epoch */ public static void setVector(TimeStampMilliTZVector vector, Long... values) { @@ -399,6 +390,7 @@ public static void setVector(TimeStampMilliTZVector vector, Long... values) { /** * Populate values for TimeStampMilliVector. + * * @param values numbers of milliseconds since UNIX epoch */ public static void setVector(TimeStampMilliVector vector, Long... values) { @@ -414,6 +406,7 @@ public static void setVector(TimeStampMilliVector vector, Long... values) { /** * Populate values for TimeStampNanoTZVector. + * * @param values numbers of nanoseconds since UNIX epoch */ public static void setVector(TimeStampNanoTZVector vector, Long... values) { @@ -429,6 +422,7 @@ public static void setVector(TimeStampNanoTZVector vector, Long... values) { /** * Populate values for TimeStampNanoVector. + * * @param values numbers of nanoseconds since UNIX epoch */ public static void setVector(TimeStampNanoVector vector, Long... values) { @@ -444,6 +438,7 @@ public static void setVector(TimeStampNanoVector vector, Long... values) { /** * Populate values for TimeStampSecTZVector. + * * @param values numbers of seconds since UNIX epoch */ public static void setVector(TimeStampSecTZVector vector, Long... values) { @@ -459,6 +454,7 @@ public static void setVector(TimeStampSecTZVector vector, Long... values) { /** * Populate values for TimeStampSecVector. + * * @param values numbers of seconds since UNIX epoch */ public static void setVector(TimeStampSecVector vector, Long... values) { @@ -472,9 +468,7 @@ public static void setVector(TimeStampSecVector vector, Long... values) { vector.setValueCount(length); } - /** - * Populate values for TinyIntVector. - */ + /** Populate values for TinyIntVector. */ public static void setVector(TinyIntVector vector, Byte... values) { final int length = values.length; vector.allocateNew(length); @@ -486,9 +480,7 @@ public static void setVector(TinyIntVector vector, Byte... values) { vector.setValueCount(length); } - /** - * Populate values for UInt1Vector. - */ + /** Populate values for UInt1Vector. */ public static void setVector(UInt1Vector vector, Byte... values) { final int length = values.length; vector.allocateNew(length); @@ -500,9 +492,7 @@ public static void setVector(UInt1Vector vector, Byte... values) { vector.setValueCount(length); } - /** - * Populate values for UInt2Vector. - */ + /** Populate values for UInt2Vector. */ public static void setVector(UInt2Vector vector, Character... values) { final int length = values.length; vector.allocateNew(length); @@ -514,9 +504,7 @@ public static void setVector(UInt2Vector vector, Character... values) { vector.setValueCount(length); } - /** - * Populate values for UInt4Vector. - */ + /** Populate values for UInt4Vector. */ public static void setVector(UInt4Vector vector, Integer... values) { final int length = values.length; vector.allocateNew(length); @@ -528,9 +516,7 @@ public static void setVector(UInt4Vector vector, Integer... values) { vector.setValueCount(length); } - /** - * Populate values for UInt8Vector. - */ + /** Populate values for UInt8Vector. */ public static void setVector(UInt8Vector vector, Long... values) { final int length = values.length; vector.allocateNew(length); @@ -542,9 +528,7 @@ public static void setVector(UInt8Vector vector, Long... values) { vector.setValueCount(length); } - /** - * Populate values for VarBinaryVector. - */ + /** Populate values for VarBinaryVector. */ public static void setVector(VarBinaryVector vector, byte[]... values) { final int length = values.length; vector.allocateNewSafe(); @@ -556,9 +540,7 @@ public static void setVector(VarBinaryVector vector, byte[]... values) { vector.setValueCount(length); } - /** - * Populate values for VarCharVector. - */ + /** Populate values for VarCharVector. */ public static void setVector(VarCharVector vector, byte[]... values) { final int length = values.length; vector.allocateNewSafe(); @@ -570,9 +552,7 @@ public static void setVector(VarCharVector vector, byte[]... values) { vector.setValueCount(length); } - /** - * Populate values for LargeVarCharVector. - */ + /** Populate values for LargeVarCharVector. */ public static void setVector(LargeVarCharVector vector, byte[]... values) { final int length = values.length; vector.allocateNewSafe(); @@ -584,9 +564,7 @@ public static void setVector(LargeVarCharVector vector, byte[]... values) { vector.setValueCount(length); } - /** - * Populate values for VarCharVector. - */ + /** Populate values for VarCharVector. */ public static void setVector(VarCharVector vector, String... values) { final int length = values.length; vector.allocateNewSafe(); @@ -598,9 +576,7 @@ public static void setVector(VarCharVector vector, String... values) { vector.setValueCount(length); } - /** - * Populate values for LargeVarCharVector. - */ + /** Populate values for LargeVarCharVector. */ public static void setVector(LargeVarCharVector vector, String... values) { final int length = values.length; vector.allocateNewSafe(); @@ -612,9 +588,7 @@ public static void setVector(LargeVarCharVector vector, String... values) { vector.setValueCount(length); } - /** - * Populate values for {@link ListVector}. - */ + /** Populate values for {@link ListVector}. */ public static void setVector(ListVector vector, List... values) { vector.allocateNewSafe(); Types.MinorType type = Types.MinorType.INT; @@ -643,9 +617,7 @@ public static void setVector(ListVector vector, List... values) { vector.setValueCount(values.length); } - /** - * Populate values for {@link LargeListVector}. - */ + /** Populate values for {@link LargeListVector}. */ public static void setVector(LargeListVector vector, List... values) { vector.allocateNewSafe(); Types.MinorType type = Types.MinorType.INT; @@ -674,9 +646,7 @@ public static void setVector(LargeListVector vector, List... values) { vector.setValueCount(values.length); } - /** - * Populate values for {@link FixedSizeListVector}. - */ + /** Populate values for {@link FixedSizeListVector}. */ public static void setVector(FixedSizeListVector vector, List... values) { vector.allocateNewSafe(); for (int i = 0; i < values.length; i++) { @@ -708,17 +678,16 @@ public static void setVector(FixedSizeListVector vector, List... values vector.setValueCount(values.length); } - /** - * Populate values for {@link StructVector}. - */ + /** Populate values for {@link StructVector}. */ public static void setVector(StructVector vector, Map> values) { vector.allocateNewSafe(); int valueCount = 0; for (final Entry> entry : values.entrySet()) { // Add the child - final IntVector child = vector.addOrGet(entry.getKey(), - FieldType.nullable(MinorType.INT.getType()), IntVector.class); + final IntVector child = + vector.addOrGet( + entry.getKey(), FieldType.nullable(MinorType.INT.getType()), IntVector.class); // Write the values to the child child.allocateNew(); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java index 084350410a4..7d73af45205 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java @@ -33,7 +33,6 @@ import java.nio.file.StandardOpenOption; import java.util.Collections; import java.util.UUID; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.memory.util.hash.ArrowBufHasher; @@ -55,13 +54,12 @@ import org.junit.Test; public class TestExtensionType { - /** - * Test that a custom UUID type can be round-tripped through a temporary file. - */ + /** Test that a custom UUID type can be round-tripped through a temporary file. */ @Test public void roundtripUuid() throws IOException { ExtensionTypeRegistry.register(new UuidType()); - final Schema schema = new Schema(Collections.singletonList(Field.nullable("a", new UuidType()))); + final Schema schema = + new Schema(Collections.singletonList(Field.nullable("a", new UuidType()))); try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { UUID u1 = UUID.randomUUID(); @@ -73,15 +71,16 @@ public void roundtripUuid() throws IOException { root.setRowCount(2); final File file = File.createTempFile("uuidtest", ".arrow"); - try (final WritableByteChannel channel = FileChannel - .open(Paths.get(file.getAbsolutePath()), StandardOpenOption.WRITE); + try (final WritableByteChannel channel = + FileChannel.open(Paths.get(file.getAbsolutePath()), StandardOpenOption.WRITE); final ArrowFileWriter writer = new ArrowFileWriter(root, null, channel)) { writer.start(); writer.writeBatch(); writer.end(); } - try (final SeekableByteChannel channel = Files.newByteChannel(Paths.get(file.getAbsolutePath())); + try (final SeekableByteChannel channel = + Files.newByteChannel(Paths.get(file.getAbsolutePath())); final ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { reader.loadNextBatch(); final VectorSchemaRoot readerRoot = reader.getVectorSchemaRoot(); @@ -89,12 +88,15 @@ public void roundtripUuid() throws IOException { final Field field = readerRoot.getSchema().getFields().get(0); final UuidType expectedType = new UuidType(); - Assert.assertEquals(field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME), + Assert.assertEquals( + field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME), expectedType.extensionName()); - Assert.assertEquals(field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA), + Assert.assertEquals( + field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA), expectedType.serialize()); - final ExtensionTypeVector deserialized = (ExtensionTypeVector) readerRoot.getFieldVectors().get(0); + final ExtensionTypeVector deserialized = + (ExtensionTypeVector) readerRoot.getFieldVectors().get(0); Assert.assertEquals(vector.getValueCount(), deserialized.getValueCount()); for (int i = 0; i < vector.getValueCount(); i++) { Assert.assertEquals(vector.isNull(i), deserialized.isNull(i)); @@ -106,13 +108,12 @@ public void roundtripUuid() throws IOException { } } - /** - * Test that a custom UUID type can be read as its underlying type. - */ + /** Test that a custom UUID type can be read as its underlying type. */ @Test public void readUnderlyingType() throws IOException { ExtensionTypeRegistry.register(new UuidType()); - final Schema schema = new Schema(Collections.singletonList(Field.nullable("a", new UuidType()))); + final Schema schema = + new Schema(Collections.singletonList(Field.nullable("a", new UuidType()))); try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { UUID u1 = UUID.randomUUID(); @@ -124,8 +125,8 @@ public void readUnderlyingType() throws IOException { root.setRowCount(2); final File file = File.createTempFile("uuidtest", ".arrow"); - try (final WritableByteChannel channel = FileChannel - .open(Paths.get(file.getAbsolutePath()), StandardOpenOption.WRITE); + try (final WritableByteChannel channel = + FileChannel.open(Paths.get(file.getAbsolutePath()), StandardOpenOption.WRITE); final ArrowFileWriter writer = new ArrowFileWriter(root, null, channel)) { writer.start(); writer.writeBatch(); @@ -134,24 +135,32 @@ public void readUnderlyingType() throws IOException { ExtensionTypeRegistry.unregister(new UuidType()); - try (final SeekableByteChannel channel = Files.newByteChannel(Paths.get(file.getAbsolutePath())); + try (final SeekableByteChannel channel = + Files.newByteChannel(Paths.get(file.getAbsolutePath())); final ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { reader.loadNextBatch(); final VectorSchemaRoot readerRoot = reader.getVectorSchemaRoot(); Assert.assertEquals(1, readerRoot.getSchema().getFields().size()); Assert.assertEquals("a", readerRoot.getSchema().getFields().get(0).getName()); - Assert.assertTrue(readerRoot.getSchema().getFields().get(0).getType() instanceof ArrowType.FixedSizeBinary); - Assert.assertEquals(16, - ((ArrowType.FixedSizeBinary) readerRoot.getSchema().getFields().get(0).getType()).getByteWidth()); + Assert.assertTrue( + readerRoot.getSchema().getFields().get(0).getType() + instanceof ArrowType.FixedSizeBinary); + Assert.assertEquals( + 16, + ((ArrowType.FixedSizeBinary) readerRoot.getSchema().getFields().get(0).getType()) + .getByteWidth()); final Field field = readerRoot.getSchema().getFields().get(0); final UuidType expectedType = new UuidType(); - Assert.assertEquals(field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME), + Assert.assertEquals( + field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME), expectedType.extensionName()); - Assert.assertEquals(field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA), + Assert.assertEquals( + field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA), expectedType.serialize()); - final FixedSizeBinaryVector deserialized = (FixedSizeBinaryVector) readerRoot.getFieldVectors().get(0); + final FixedSizeBinaryVector deserialized = + (FixedSizeBinaryVector) readerRoot.getFieldVectors().get(0); Assert.assertEquals(vector.getValueCount(), deserialized.getValueCount()); for (int i = 0; i < vector.getValueCount(); i++) { Assert.assertEquals(vector.isNull(i), deserialized.isNull(i)); @@ -169,26 +178,27 @@ public void readUnderlyingType() throws IOException { @Test public void testNullCheck() { - NullPointerException e = assertThrows(NullPointerException.class, - () -> { - try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); - final ExtensionTypeVector vector = new UuidVector("uuid", allocator, null)) { - vector.getField(); - vector.allocateNewSafe(); - } - }); + NullPointerException e = + assertThrows( + NullPointerException.class, + () -> { + try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); + final ExtensionTypeVector vector = new UuidVector("uuid", allocator, null)) { + vector.getField(); + vector.allocateNewSafe(); + } + }); assertTrue(e.getMessage().contains("underlyingVector cannot be null.")); } - /** - * Test that a custom Location type can be round-tripped through a temporary file. - */ + /** Test that a custom Location type can be round-tripped through a temporary file. */ @Test public void roundtripLocation() throws IOException { ExtensionTypeRegistry.register(new LocationType()); - final Schema schema = new Schema(Collections.singletonList(Field.nullable("location", new LocationType()))); + final Schema schema = + new Schema(Collections.singletonList(Field.nullable("location", new LocationType()))); try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { LocationVector vector = (LocationVector) root.getVector("location"); vector.allocateNew(); vector.set(0, 34.073814f, -118.240784f); @@ -198,28 +208,32 @@ public void roundtripLocation() throws IOException { root.setRowCount(4); final File file = File.createTempFile("locationtest", ".arrow"); - try (final WritableByteChannel channel = FileChannel - .open(Paths.get(file.getAbsolutePath()), StandardOpenOption.WRITE); - final ArrowFileWriter writer = new ArrowFileWriter(root, null, channel)) { + try (final WritableByteChannel channel = + FileChannel.open(Paths.get(file.getAbsolutePath()), StandardOpenOption.WRITE); + final ArrowFileWriter writer = new ArrowFileWriter(root, null, channel)) { writer.start(); writer.writeBatch(); writer.end(); } - try (final SeekableByteChannel channel = Files.newByteChannel(Paths.get(file.getAbsolutePath())); - final ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { + try (final SeekableByteChannel channel = + Files.newByteChannel(Paths.get(file.getAbsolutePath())); + final ArrowFileReader reader = new ArrowFileReader(channel, allocator)) { reader.loadNextBatch(); final VectorSchemaRoot readerRoot = reader.getVectorSchemaRoot(); Assert.assertEquals(root.getSchema(), readerRoot.getSchema()); final Field field = readerRoot.getSchema().getFields().get(0); final LocationType expectedType = new LocationType(); - Assert.assertEquals(field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME), - expectedType.extensionName()); - Assert.assertEquals(field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA), - expectedType.serialize()); + Assert.assertEquals( + field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME), + expectedType.extensionName()); + Assert.assertEquals( + field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA), + expectedType.serialize()); - final ExtensionTypeVector deserialized = (ExtensionTypeVector) readerRoot.getFieldVectors().get(0); + final ExtensionTypeVector deserialized = + (ExtensionTypeVector) readerRoot.getFieldVectors().get(0); Assert.assertTrue(deserialized instanceof LocationVector); Assert.assertEquals(deserialized.getName(), "location"); StructVector deserStruct = (StructVector) deserialized.getUnderlyingVector(); @@ -241,10 +255,12 @@ public void testVectorCompare() { UuidType uuidType = new UuidType(); ExtensionTypeRegistry.register(uuidType); try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE); - UuidVector a1 = (UuidVector) uuidType.getNewVector("a", FieldType.nullable(uuidType), allocator); - UuidVector a2 = (UuidVector) uuidType.getNewVector("a", FieldType.nullable(uuidType), allocator); - UuidVector bb = (UuidVector) uuidType.getNewVector("a", FieldType.nullable(uuidType), allocator) - ) { + UuidVector a1 = + (UuidVector) uuidType.getNewVector("a", FieldType.nullable(uuidType), allocator); + UuidVector a2 = + (UuidVector) uuidType.getNewVector("a", FieldType.nullable(uuidType), allocator); + UuidVector bb = + (UuidVector) uuidType.getNewVector("a", FieldType.nullable(uuidType), allocator)) { UUID u1 = UUID.randomUUID(); UUID u2 = UUID.randomUUID(); @@ -298,7 +314,8 @@ public boolean extensionEquals(ExtensionType other) { @Override public ArrowType deserialize(ArrowType storageType, String serializedData) { if (!storageType.equals(storageType())) { - throw new UnsupportedOperationException("Cannot construct UuidType from underlying type " + storageType); + throw new UnsupportedOperationException( + "Cannot construct UuidType from underlying type " + storageType); } return new UuidType(); } @@ -316,7 +333,8 @@ public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocato static class UuidVector extends ExtensionTypeVector { - public UuidVector(String name, BufferAllocator allocator, FixedSizeBinaryVector underlyingVector) { + public UuidVector( + String name, BufferAllocator allocator, FixedSizeBinaryVector underlyingVector) { super(name, allocator, underlyingVector); } @@ -364,7 +382,8 @@ public boolean extensionEquals(ExtensionType other) { @Override public ArrowType deserialize(ArrowType storageType, String serializedData) { if (!storageType.equals(storageType())) { - throw new UnsupportedOperationException("Cannot construct LocationType from underlying type " + storageType); + throw new UnsupportedOperationException( + "Cannot construct LocationType from underlying type " + storageType); } return new LocationType(); } @@ -384,11 +403,15 @@ public static class LocationVector extends ExtensionTypeVector { private static StructVector buildUnderlyingVector(String name, BufferAllocator allocator) { final StructVector underlyingVector = - new StructVector(name, allocator, FieldType.nullable(ArrowType.Struct.INSTANCE), null); - underlyingVector.addOrGet("Latitude", - FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), Float4Vector.class); - underlyingVector.addOrGet("Longitude", - FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), Float4Vector.class); + new StructVector(name, allocator, FieldType.nullable(ArrowType.Struct.INSTANCE), null); + underlyingVector.addOrGet( + "Latitude", + FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), + Float4Vector.class); + underlyingVector.addOrGet( + "Longitude", + FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), + Float4Vector.class); return underlyingVector; } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestField.java b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestField.java index bc984fa642d..acb697dc061 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestField.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestField.java @@ -26,13 +26,13 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.vector.types.pojo.ArrowType.Int; import org.junit.Test; public class TestField { - private static Field field(String name, boolean nullable, ArrowType type, Map metadata) { + private static Field field( + String name, boolean nullable, ArrowType type, Map metadata) { return new Field(name, new FieldType(nullable, type, null, metadata), Collections.emptyList()); } @@ -41,14 +41,16 @@ public void testMetadata() throws IOException { Map metadata = new HashMap<>(1); metadata.put("testKey", "testValue"); - Schema schema = new Schema(Collections.singletonList( - field("a", false, new Int(8, true), metadata) - )); + Schema schema = + new Schema(Collections.singletonList(field("a", false, new Int(8, true), metadata))); String json = schema.toJson(); Schema actual = Schema.fromJSON(json); - jsonContains(json, "\"" + METADATA_KEY + "\" : \"testKey\"", "\"" + METADATA_VALUE + "\" : \"testValue\""); + jsonContains( + json, + "\"" + METADATA_KEY + "\" : \"testKey\"", + "\"" + METADATA_VALUE + "\" : \"testValue\""); Map actualMetadata = actual.getFields().get(0).getMetadata(); assertEquals(1, actualMetadata.size()); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java index 7b62247c6e1..580f9411d72 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java @@ -27,7 +27,6 @@ import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; - import org.apache.arrow.vector.types.DateUnit; import org.apache.arrow.vector.types.FloatingPointPrecision; import org.apache.arrow.vector.types.IntervalUnit; @@ -63,84 +62,87 @@ private static Field field(String name, ArrowType type, Field... children) { @Test public void testComplex() throws IOException { - Schema schema = new Schema(asList( - field("a", false, new Int(8, true)), - field("b", new Struct(), - field("c", new Int(16, true)), - field("d", new Utf8())), - field("e", new List(), field(null, new Date(DateUnit.MILLISECOND))), - field("f", new FloatingPoint(FloatingPointPrecision.SINGLE)), - field("g", new Timestamp(TimeUnit.MILLISECOND, "UTC")), - field("h", new Timestamp(TimeUnit.MICROSECOND, null)), - field("i", new Interval(IntervalUnit.DAY_TIME)), - field("j", new ArrowType.Duration(TimeUnit.SECOND)) - )); + Schema schema = + new Schema( + asList( + field("a", false, new Int(8, true)), + field("b", new Struct(), field("c", new Int(16, true)), field("d", new Utf8())), + field("e", new List(), field(null, new Date(DateUnit.MILLISECOND))), + field("f", new FloatingPoint(FloatingPointPrecision.SINGLE)), + field("g", new Timestamp(TimeUnit.MILLISECOND, "UTC")), + field("h", new Timestamp(TimeUnit.MICROSECOND, null)), + field("i", new Interval(IntervalUnit.DAY_TIME)), + field("j", new ArrowType.Duration(TimeUnit.SECOND)))); roundTrip(schema); assertEquals( - "Schema, e: List, " + - "f: FloatingPoint(SINGLE), g: Timestamp(MILLISECOND, UTC), h: Timestamp(MICROSECOND, null), " + - "i: Interval(DAY_TIME), j: Duration(SECOND)>", + "Schema, e: List, " + + "f: FloatingPoint(SINGLE), g: Timestamp(MILLISECOND, UTC), h: Timestamp(MICROSECOND, null), " + + "i: Interval(DAY_TIME), j: Duration(SECOND)>", schema.toString()); } @Test public void testAll() throws IOException { - Schema schema = new Schema(asList( - field("a", false, new Null()), - field("b", new Struct(), field("ba", new Null())), - field("c", new List(), field("ca", new Null())), - field("d", new Union(UnionMode.Sparse, new int[] {1, 2, 3}), field("da", new Null())), - field("e", new Int(8, true)), - field("f", new FloatingPoint(FloatingPointPrecision.SINGLE)), - field("g", new Utf8()), - field("h", new Binary()), - field("i", new Bool()), - field("j", new Decimal(5, 5, 128)), - field("k", new Date(DateUnit.DAY)), - field("l", new Date(DateUnit.MILLISECOND)), - field("m", new Time(TimeUnit.SECOND, 32)), - field("n", new Time(TimeUnit.MILLISECOND, 32)), - field("o", new Time(TimeUnit.MICROSECOND, 64)), - field("p", new Time(TimeUnit.NANOSECOND, 64)), - field("q", new Timestamp(TimeUnit.MILLISECOND, "UTC")), - field("r", new Timestamp(TimeUnit.MICROSECOND, null)), - field("s", new Interval(IntervalUnit.DAY_TIME)), - field("t", new FixedSizeBinary(100)), - field("u", new Duration(TimeUnit.SECOND)), - field("v", new Duration(TimeUnit.MICROSECOND)) - )); + Schema schema = + new Schema( + asList( + field("a", false, new Null()), + field("b", new Struct(), field("ba", new Null())), + field("c", new List(), field("ca", new Null())), + field( + "d", new Union(UnionMode.Sparse, new int[] {1, 2, 3}), field("da", new Null())), + field("e", new Int(8, true)), + field("f", new FloatingPoint(FloatingPointPrecision.SINGLE)), + field("g", new Utf8()), + field("h", new Binary()), + field("i", new Bool()), + field("j", new Decimal(5, 5, 128)), + field("k", new Date(DateUnit.DAY)), + field("l", new Date(DateUnit.MILLISECOND)), + field("m", new Time(TimeUnit.SECOND, 32)), + field("n", new Time(TimeUnit.MILLISECOND, 32)), + field("o", new Time(TimeUnit.MICROSECOND, 64)), + field("p", new Time(TimeUnit.NANOSECOND, 64)), + field("q", new Timestamp(TimeUnit.MILLISECOND, "UTC")), + field("r", new Timestamp(TimeUnit.MICROSECOND, null)), + field("s", new Interval(IntervalUnit.DAY_TIME)), + field("t", new FixedSizeBinary(100)), + field("u", new Duration(TimeUnit.SECOND)), + field("v", new Duration(TimeUnit.MICROSECOND)))); roundTrip(schema); } @Test public void testUnion() throws IOException { - Schema schema = new Schema(asList( - field("d", new Union(UnionMode.Sparse, new int[] {1, 2, 3}), field("da", new Null())) - )); + Schema schema = + new Schema( + asList( + field( + "d", + new Union(UnionMode.Sparse, new int[] {1, 2, 3}), + field("da", new Null())))); roundTrip(schema); contains(schema, "Sparse"); } @Test public void testDate() throws IOException { - Schema schema = new Schema(asList( - field("a", new Date(DateUnit.DAY)), - field("b", new Date(DateUnit.MILLISECOND)) - )); + Schema schema = + new Schema( + asList(field("a", new Date(DateUnit.DAY)), field("b", new Date(DateUnit.MILLISECOND)))); roundTrip(schema); - assertEquals( - "Schema", - schema.toString()); + assertEquals("Schema", schema.toString()); } @Test public void testTime() throws IOException { - Schema schema = new Schema(asList( - field("a", new Time(TimeUnit.SECOND, 32)), - field("b", new Time(TimeUnit.MILLISECOND, 32)), - field("c", new Time(TimeUnit.MICROSECOND, 64)), - field("d", new Time(TimeUnit.NANOSECOND, 64)) - )); + Schema schema = + new Schema( + asList( + field("a", new Time(TimeUnit.SECOND, 32)), + field("b", new Time(TimeUnit.MILLISECOND, 32)), + field("c", new Time(TimeUnit.MICROSECOND, 64)), + field("d", new Time(TimeUnit.NANOSECOND, 64)))); roundTrip(schema); assertEquals( "Schema", @@ -149,53 +151,57 @@ public void testTime() throws IOException { @Test public void testTS() throws IOException { - Schema schema = new Schema(asList( - field("a", new Timestamp(TimeUnit.SECOND, "UTC")), - field("b", new Timestamp(TimeUnit.MILLISECOND, "UTC")), - field("c", new Timestamp(TimeUnit.MICROSECOND, "UTC")), - field("d", new Timestamp(TimeUnit.NANOSECOND, "UTC")), - field("e", new Timestamp(TimeUnit.SECOND, null)), - field("f", new Timestamp(TimeUnit.MILLISECOND, null)), - field("g", new Timestamp(TimeUnit.MICROSECOND, null)), - field("h", new Timestamp(TimeUnit.NANOSECOND, null)) - )); + Schema schema = + new Schema( + asList( + field("a", new Timestamp(TimeUnit.SECOND, "UTC")), + field("b", new Timestamp(TimeUnit.MILLISECOND, "UTC")), + field("c", new Timestamp(TimeUnit.MICROSECOND, "UTC")), + field("d", new Timestamp(TimeUnit.NANOSECOND, "UTC")), + field("e", new Timestamp(TimeUnit.SECOND, null)), + field("f", new Timestamp(TimeUnit.MILLISECOND, null)), + field("g", new Timestamp(TimeUnit.MICROSECOND, null)), + field("h", new Timestamp(TimeUnit.NANOSECOND, null)))); roundTrip(schema); assertEquals( - "Schema", + "Schema", schema.toString()); } @Test public void testInterval() throws IOException { - Schema schema = new Schema(asList( - field("a", new Interval(IntervalUnit.YEAR_MONTH)), - field("b", new Interval(IntervalUnit.DAY_TIME)) - )); + Schema schema = + new Schema( + asList( + field("a", new Interval(IntervalUnit.YEAR_MONTH)), + field("b", new Interval(IntervalUnit.DAY_TIME)))); roundTrip(schema); contains(schema, "YEAR_MONTH", "DAY_TIME"); } @Test public void testRoundTripDurationInterval() throws IOException { - Schema schema = new Schema(asList( - field("a", new Duration(TimeUnit.SECOND)), - field("b", new Duration(TimeUnit.MILLISECOND)), - field("c", new Duration(TimeUnit.MICROSECOND)), - field("d", new Duration(TimeUnit.NANOSECOND)) - )); + Schema schema = + new Schema( + asList( + field("a", new Duration(TimeUnit.SECOND)), + field("b", new Duration(TimeUnit.MILLISECOND)), + field("c", new Duration(TimeUnit.MICROSECOND)), + field("d", new Duration(TimeUnit.NANOSECOND)))); roundTrip(schema); contains(schema, "SECOND", "MILLI", "MICRO", "NANO"); } @Test public void testFP() throws IOException { - Schema schema = new Schema(asList( - field("a", new FloatingPoint(FloatingPointPrecision.HALF)), - field("b", new FloatingPoint(FloatingPointPrecision.SINGLE)), - field("c", new FloatingPoint(FloatingPointPrecision.DOUBLE)) - )); + Schema schema = + new Schema( + asList( + field("a", new FloatingPoint(FloatingPointPrecision.HALF)), + field("b", new FloatingPoint(FloatingPointPrecision.SINGLE)), + field("c", new FloatingPoint(FloatingPointPrecision.DOUBLE)))); roundTrip(schema); contains(schema, "HALF", "SINGLE", "DOUBLE"); } @@ -205,44 +211,47 @@ public void testMetadata() throws IOException { Map metadata = new HashMap<>(1); metadata.put("testKey", "testValue"); - java.util.List fields = asList( - field("a", false, new Int(8, true)), - field("b", new Struct(), - field("c", new Int(16, true)), - field("d", new Utf8())), - field("e", new List(), field(null, new Date(DateUnit.MILLISECOND))) - ); + java.util.List fields = + asList( + field("a", false, new Int(8, true)), + field("b", new Struct(), field("c", new Int(16, true)), field("d", new Utf8())), + field("e", new List(), field(null, new Date(DateUnit.MILLISECOND)))); Schema schema = new Schema(fields, metadata); roundTrip(schema); - contains(schema, "\"" + METADATA_KEY + "\" : \"testKey\"", "\"" + METADATA_VALUE + "\" : \"testValue\""); + contains( + schema, + "\"" + METADATA_KEY + "\" : \"testKey\"", + "\"" + METADATA_VALUE + "\" : \"testValue\""); } @Test public void testMessageSerialization() { - Schema schema = new Schema(asList( - field("a", false, new Null()), - field("b", new Struct(), field("ba", new Null())), - field("c", new List(), field("ca", new Null())), - field("d", new Union(UnionMode.Sparse, new int[] {1, 2, 3}), field("da", new Null())), - field("e", new Int(8, true)), - field("f", new FloatingPoint(FloatingPointPrecision.SINGLE)), - field("g", new Utf8()), - field("h", new Binary()), - field("i", new Bool()), - field("j", new Decimal(5, 5, 128)), - field("k", new Date(DateUnit.DAY)), - field("l", new Date(DateUnit.MILLISECOND)), - field("m", new Time(TimeUnit.SECOND, 32)), - field("n", new Time(TimeUnit.MILLISECOND, 32)), - field("o", new Time(TimeUnit.MICROSECOND, 64)), - field("p", new Time(TimeUnit.NANOSECOND, 64)), - field("q", new Timestamp(TimeUnit.MILLISECOND, "UTC")), - field("r", new Timestamp(TimeUnit.MICROSECOND, null)), - field("s", new Interval(IntervalUnit.DAY_TIME)), - field("t", new FixedSizeBinary(100)), - field("u", new Duration(TimeUnit.SECOND)), - field("v", new Duration(TimeUnit.MICROSECOND)) - )); + Schema schema = + new Schema( + asList( + field("a", false, new Null()), + field("b", new Struct(), field("ba", new Null())), + field("c", new List(), field("ca", new Null())), + field( + "d", new Union(UnionMode.Sparse, new int[] {1, 2, 3}), field("da", new Null())), + field("e", new Int(8, true)), + field("f", new FloatingPoint(FloatingPointPrecision.SINGLE)), + field("g", new Utf8()), + field("h", new Binary()), + field("i", new Bool()), + field("j", new Decimal(5, 5, 128)), + field("k", new Date(DateUnit.DAY)), + field("l", new Date(DateUnit.MILLISECOND)), + field("m", new Time(TimeUnit.SECOND, 32)), + field("n", new Time(TimeUnit.MILLISECOND, 32)), + field("o", new Time(TimeUnit.MICROSECOND, 64)), + field("p", new Time(TimeUnit.NANOSECOND, 64)), + field("q", new Timestamp(TimeUnit.MILLISECOND, "UTC")), + field("r", new Timestamp(TimeUnit.MICROSECOND, null)), + field("s", new Interval(IntervalUnit.DAY_TIME)), + field("t", new FixedSizeBinary(100)), + field("u", new Duration(TimeUnit.SECOND)), + field("v", new Duration(TimeUnit.MICROSECOND)))); roundTripMessage(schema); } @@ -264,7 +273,8 @@ private void roundTripMessage(Schema schema) { assertEquals(schema.hashCode(), actual.hashCode()); } - private void validateFieldsHashcode(java.util.List schemaFields, java.util.List actualFields) { + private void validateFieldsHashcode( + java.util.List schemaFields, java.util.List actualFields) { assertEquals(schemaFields.size(), actualFields.size()); if (schemaFields.size() == 0) { return; @@ -289,5 +299,4 @@ private void contains(Schema schema, String... s) { assertTrue(json + " contains " + string, json.contains(string)); } } - } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/DecimalUtilityTest.java b/java/vector/src/test/java/org/apache/arrow/vector/util/DecimalUtilityTest.java index 804092ed94a..4f9c3cbcd7a 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/DecimalUtilityTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/DecimalUtilityTest.java @@ -19,7 +19,6 @@ import java.math.BigDecimal; import java.math.BigInteger; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -27,19 +26,24 @@ import org.junit.Test; public class DecimalUtilityTest { - private static final BigInteger[] MAX_BIG_INT = new BigInteger[]{BigInteger.valueOf(10).pow(38) - .subtract(java.math.BigInteger.ONE), java.math.BigInteger.valueOf(10).pow(76)}; - private static final BigInteger[] MIN_BIG_INT = new BigInteger[]{MAX_BIG_INT[0].multiply(BigInteger.valueOf(-1)), - MAX_BIG_INT[1].multiply(BigInteger.valueOf(-1))}; + private static final BigInteger[] MAX_BIG_INT = + new BigInteger[] { + BigInteger.valueOf(10).pow(38).subtract(java.math.BigInteger.ONE), + java.math.BigInteger.valueOf(10).pow(76) + }; + private static final BigInteger[] MIN_BIG_INT = + new BigInteger[] { + MAX_BIG_INT[0].multiply(BigInteger.valueOf(-1)), + MAX_BIG_INT[1].multiply(BigInteger.valueOf(-1)) + }; @Test public void testSetLongInDecimalArrowBuf() { - int[] byteLengths = new int[]{16, 32}; + int[] byteLengths = new int[] {16, 32}; for (int x = 0; x < 2; x++) { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(byteLengths[x]); - ) { - int [] intValues = new int [] {Integer.MAX_VALUE, Integer.MIN_VALUE, 0}; + ArrowBuf buf = allocator.buffer(byteLengths[x]); ) { + int[] intValues = new int[] {Integer.MAX_VALUE, Integer.MIN_VALUE, 0}; for (int val : intValues) { buf.clear(); DecimalUtility.writeLongToArrowBuf((long) val, buf, 0, byteLengths[x]); @@ -53,30 +57,32 @@ public void testSetLongInDecimalArrowBuf() { @Test public void testSetByteArrayInDecimalArrowBuf() { - int[] byteLengths = new int[]{16, 32}; + int[] byteLengths = new int[] {16, 32}; for (int x = 0; x < 2; x++) { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(byteLengths[x]); - ) { - int [] intValues = new int [] {Integer.MAX_VALUE, Integer.MIN_VALUE, 0}; + ArrowBuf buf = allocator.buffer(byteLengths[x]); ) { + int[] intValues = new int[] {Integer.MAX_VALUE, Integer.MIN_VALUE, 0}; for (int val : intValues) { buf.clear(); - DecimalUtility.writeByteArrayToArrowBuf(BigInteger.valueOf(val).toByteArray(), buf, 0, byteLengths[x]); + DecimalUtility.writeByteArrayToArrowBuf( + BigInteger.valueOf(val).toByteArray(), buf, 0, byteLengths[x]); BigDecimal actual = DecimalUtility.getBigDecimalFromArrowBuf(buf, 0, 0, byteLengths[x]); BigDecimal expected = BigDecimal.valueOf(val); Assert.assertEquals(expected, actual); } - long [] longValues = new long[] {Long.MIN_VALUE, 0 , Long.MAX_VALUE}; + long[] longValues = new long[] {Long.MIN_VALUE, 0, Long.MAX_VALUE}; for (long val : longValues) { buf.clear(); - DecimalUtility.writeByteArrayToArrowBuf(BigInteger.valueOf(val).toByteArray(), buf, 0, byteLengths[x]); + DecimalUtility.writeByteArrayToArrowBuf( + BigInteger.valueOf(val).toByteArray(), buf, 0, byteLengths[x]); BigDecimal actual = DecimalUtility.getBigDecimalFromArrowBuf(buf, 0, 0, byteLengths[x]); BigDecimal expected = BigDecimal.valueOf(val); Assert.assertEquals(expected, actual); } - BigInteger [] decimals = new BigInteger[] {MAX_BIG_INT[x], new BigInteger("0"), MIN_BIG_INT[x]}; + BigInteger[] decimals = + new BigInteger[] {MAX_BIG_INT[x], new BigInteger("0"), MIN_BIG_INT[x]}; for (BigInteger val : decimals) { buf.clear(); DecimalUtility.writeByteArrayToArrowBuf(val.toByteArray(), buf, 0, byteLengths[x]); @@ -90,12 +96,11 @@ public void testSetByteArrayInDecimalArrowBuf() { @Test public void testSetBigDecimalInDecimalArrowBuf() { - int[] byteLengths = new int[]{16, 32}; + int[] byteLengths = new int[] {16, 32}; for (int x = 0; x < 2; x++) { try (BufferAllocator allocator = new RootAllocator(128); - ArrowBuf buf = allocator.buffer(byteLengths[x]); - ) { - int [] intValues = new int [] {Integer.MAX_VALUE, Integer.MIN_VALUE, 0}; + ArrowBuf buf = allocator.buffer(byteLengths[x]); ) { + int[] intValues = new int[] {Integer.MAX_VALUE, Integer.MIN_VALUE, 0}; for (int val : intValues) { buf.clear(); DecimalUtility.writeBigDecimalToArrowBuf(BigDecimal.valueOf(val), buf, 0, byteLengths[x]); @@ -104,7 +109,7 @@ public void testSetBigDecimalInDecimalArrowBuf() { Assert.assertEquals(expected, actual); } - long [] longValues = new long[] {Long.MIN_VALUE, 0 , Long.MAX_VALUE}; + long[] longValues = new long[] {Long.MIN_VALUE, 0, Long.MAX_VALUE}; for (long val : longValues) { buf.clear(); DecimalUtility.writeBigDecimalToArrowBuf(BigDecimal.valueOf(val), buf, 0, byteLengths[x]); @@ -113,7 +118,8 @@ public void testSetBigDecimalInDecimalArrowBuf() { Assert.assertEquals(expected, actual); } - BigInteger [] decimals = new BigInteger[] {MAX_BIG_INT[x], new BigInteger("0"), MIN_BIG_INT[x]}; + BigInteger[] decimals = + new BigInteger[] {MAX_BIG_INT[x], new BigInteger("0"), MIN_BIG_INT[x]}; for (BigInteger val : decimals) { buf.clear(); DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(val), buf, 0, byteLengths[x]); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestDataSizeRoundingUtil.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestDataSizeRoundingUtil.java index 4138ea9d7a1..319980c6542 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestDataSizeRoundingUtil.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestDataSizeRoundingUtil.java @@ -21,9 +21,7 @@ import org.junit.Test; -/** - * Test cases for {@link DataSizeRoundingUtil}. - */ +/** Test cases for {@link DataSizeRoundingUtil}. */ public class TestDataSizeRoundingUtil { @Test diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestElementAddressableVectorIterator.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestElementAddressableVectorIterator.java index 419872225e1..6ccff049f7d 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestElementAddressableVectorIterator.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestElementAddressableVectorIterator.java @@ -29,9 +29,7 @@ import org.junit.Before; import org.junit.Test; -/** - * Test cases for {@link ElementAddressableVectorIterator}. - */ +/** Test cases for {@link ElementAddressableVectorIterator}. */ public class TestElementAddressableVectorIterator { private final int VECTOR_LENGTH = 100; @@ -64,7 +62,8 @@ public void testIterateIntVector() { } // iterate - ElementAddressableVectorIterator it = new ElementAddressableVectorIterator<>(intVector); + ElementAddressableVectorIterator it = + new ElementAddressableVectorIterator<>(intVector); int index = 0; while (it.hasNext()) { ArrowBufPointer pt; @@ -103,7 +102,8 @@ public void testIterateVarCharVector() { } // iterate - ElementAddressableVectorIterator it = new ElementAddressableVectorIterator<>(strVector); + ElementAddressableVectorIterator it = + new ElementAddressableVectorIterator<>(strVector); int index = 0; while (it.hasNext()) { ArrowBufPointer pt; diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestMapWithOrdinal.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestMapWithOrdinal.java index edd5221faf2..0c61cb57949 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestMapWithOrdinal.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestMapWithOrdinal.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue; import java.util.Collection; - import org.junit.Before; import org.junit.Test; diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestMultiMapWithOrdinal.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestMultiMapWithOrdinal.java index ea829060d1c..4bd169272d4 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestMultiMapWithOrdinal.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestMultiMapWithOrdinal.java @@ -54,7 +54,5 @@ public void test() { map.removeAll("z"); Assert.assertEquals(2, map.size()); Assert.assertFalse(map.containsKey("z")); - - } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestReusableByteArray.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestReusableByteArray.java index b11aa5638d6..7de9dfd9df0 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestReusableByteArray.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestReusableByteArray.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.Base64; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -57,7 +56,9 @@ public void testSetByteArrayRepeatedly() { workingBuf.setBytes(0, str.getBytes()); byteArray.set(workingBuf, 0, str.getBytes().length); assertEquals(str.getBytes().length, byteArray.getLength()); - assertArrayEquals(str.getBytes(), Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); + assertArrayEquals( + str.getBytes(), + Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); assertEquals(Base64.getEncoder().encodeToString(str.getBytes()), byteArray.toString()); assertEquals(new ReusableByteArray(str.getBytes()), byteArray); assertEquals(new ReusableByteArray(str.getBytes()).hashCode(), byteArray.hashCode()); @@ -69,7 +70,9 @@ public void testSetByteArrayRepeatedly() { workingBuf.setBytes(0, str2.getBytes()); byteArray.set(workingBuf, 0, str2.getBytes().length); assertEquals(str2.getBytes().length, byteArray.getLength()); - assertArrayEquals(str2.getBytes(), Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); + assertArrayEquals( + str2.getBytes(), + Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); assertEquals(Base64.getEncoder().encodeToString(str2.getBytes()), byteArray.toString()); assertEquals(new ReusableByteArray(str2.getBytes()), byteArray); assertEquals(new ReusableByteArray(str2.getBytes()).hashCode(), byteArray.hashCode()); @@ -85,7 +88,9 @@ public void testSetByteArrayRepeatedly() { workingBuf.setBytes(0, str3.getBytes()); byteArray.set(workingBuf, 0, str3.getBytes().length); assertEquals(str3.getBytes().length, byteArray.getLength()); - assertArrayEquals(str3.getBytes(), Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); + assertArrayEquals( + str3.getBytes(), + Arrays.copyOfRange(byteArray.getBuffer(), 0, (int) byteArray.getLength())); assertEquals(Base64.getEncoder().encodeToString(str3.getBytes()), byteArray.toString()); assertEquals(new ReusableByteArray(str3.getBytes()), byteArray); assertEquals(new ReusableByteArray(str3.getBytes()).hashCode(), byteArray.hashCode()); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestSchemaUtil.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestSchemaUtil.java index 52b65840868..9e77e9fce15 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestSchemaUtil.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestSchemaUtil.java @@ -21,13 +21,11 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; - import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.types.pojo.Schema; -import org.apache.arrow.vector.util.SchemaUtility; import org.junit.Test; public class TestSchemaUtil { @@ -38,11 +36,12 @@ private static Field field(String name, boolean nullable, ArrowType type, Field. @Test public void testSerializationAndDeserialization() throws IOException { - Schema schema = new Schema(asList( - field("a", false, new ArrowType.Null()), - field("b", true, new ArrowType.Utf8()), - field("c", true, new ArrowType.Binary())) - ); + Schema schema = + new Schema( + asList( + field("a", false, new ArrowType.Null()), + field("b", true, new ArrowType.Utf8()), + field("c", true, new ArrowType.Binary()))); byte[] serialized = SchemaUtility.serialize(schema); Schema deserialized = SchemaUtility.deserialize(serialized, new RootAllocator(Long.MAX_VALUE)); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java index ab36ea2fd21..f4fc3a94bba 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BaseValueVector; @@ -57,9 +56,7 @@ import org.junit.Before; import org.junit.Test; -/** - * Test cases for {@link VectorAppender}. - */ +/** Test cases for {@link VectorAppender}. */ public class TestVectorAppender { private BufferAllocator allocator; @@ -80,7 +77,7 @@ public void testAppendFixedWidthVector() { final int length1 = 10; final int length2 = 5; try (IntVector target = new IntVector("", allocator); - IntVector delta = new IntVector("", allocator)) { + IntVector delta = new IntVector("", allocator)) { target.allocateNew(length1); delta.allocateNew(length2); @@ -95,7 +92,8 @@ public void testAppendFixedWidthVector() { try (IntVector expected = new IntVector("expected", allocator)) { expected.allocateNew(); - ValueVectorDataPopulator.setVector(expected, 0, 1, 2, 3, 4, 5, 6, null, 8, 9, null, 11, 12, 13, 14); + ValueVectorDataPopulator.setVector( + expected, 0, 1, 2, 3, 4, 5, 6, null, 8, 9, null, 11, 12, 13, 14); assertVectorsEqual(expected, target); } } @@ -106,7 +104,7 @@ public void testAppendBitVector() { final int length1 = 10; final int length2 = 5; try (BitVector target = new BitVector("", allocator); - BitVector delta = new BitVector("", allocator)) { + BitVector delta = new BitVector("", allocator)) { target.allocateNew(length1); delta.allocateNew(length2); @@ -121,7 +119,8 @@ public void testAppendBitVector() { try (BitVector expected = new BitVector("expected", allocator)) { expected.allocateNew(); - ValueVectorDataPopulator.setVector(expected, 0, 1, 0, 1, 0, 1, 0, null, 0, 1, null, 1, 1, 0, 0); + ValueVectorDataPopulator.setVector( + expected, 0, 1, 0, 1, 0, 1, 0, null, 0, 1, null, 1, 1, 0, 0); assertVectorsEqual(expected, target); } } @@ -130,7 +129,7 @@ public void testAppendBitVector() { @Test public void testAppendEmptyFixedWidthVector() { try (IntVector target = new IntVector("", allocator); - IntVector delta = new IntVector("", allocator)) { + IntVector delta = new IntVector("", allocator)) { ValueVectorDataPopulator.setVector(target, 0, 1, 2, 3, 4, 5, 6, null, 8, 9); @@ -151,12 +150,13 @@ public void testAppendVariableWidthVector() { final int length1 = 10; final int length2 = 5; try (VarCharVector target = new VarCharVector("", allocator); - VarCharVector delta = new VarCharVector("", allocator)) { + VarCharVector delta = new VarCharVector("", allocator)) { target.allocateNew(5, length1); delta.allocateNew(5, length2); - ValueVectorDataPopulator.setVector(target, "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9"); + ValueVectorDataPopulator.setVector( + target, "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9"); ValueVectorDataPopulator.setVector(delta, "a10", "a11", "a12", "a13", null); VectorAppender appender = new VectorAppender(target); @@ -164,8 +164,9 @@ public void testAppendVariableWidthVector() { try (VarCharVector expected = new VarCharVector("expected", allocator)) { expected.allocateNew(); - ValueVectorDataPopulator.setVector(expected, - "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", null); + ValueVectorDataPopulator.setVector( + expected, "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9", "a10", "a11", + "a12", "a13", null); assertVectorsEqual(expected, target); } } @@ -174,16 +175,17 @@ public void testAppendVariableWidthVector() { @Test public void testAppendEmptyVariableWidthVector() { try (VarCharVector target = new VarCharVector("", allocator); - VarCharVector delta = new VarCharVector("", allocator)) { + VarCharVector delta = new VarCharVector("", allocator)) { - ValueVectorDataPopulator.setVector(target, "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9"); + ValueVectorDataPopulator.setVector( + target, "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9"); VectorAppender appender = new VectorAppender(target); delta.accept(appender, null); try (VarCharVector expected = new VarCharVector("expected", allocator)) { - ValueVectorDataPopulator.setVector(expected, - "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9"); + ValueVectorDataPopulator.setVector( + expected, "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9"); assertVectorsEqual(expected, target); } } @@ -215,21 +217,23 @@ public void testAppendLargeVariableWidthVector() { final int length1 = 5; final int length2 = 10; try (LargeVarCharVector target = new LargeVarCharVector("", allocator); - LargeVarCharVector delta = new LargeVarCharVector("", allocator)) { + LargeVarCharVector delta = new LargeVarCharVector("", allocator)) { target.allocateNew(5, length1); delta.allocateNew(5, length2); ValueVectorDataPopulator.setVector(target, "a0", null, "a2", "a3", null); - ValueVectorDataPopulator.setVector(delta, "a5", "a6", "a7", null, null, "a10", "a11", "a12", "a13", null); + ValueVectorDataPopulator.setVector( + delta, "a5", "a6", "a7", null, null, "a10", "a11", "a12", "a13", null); VectorAppender appender = new VectorAppender(target); delta.accept(appender, null); try (LargeVarCharVector expected = new LargeVarCharVector("expected", allocator)) { expected.allocateNew(); - ValueVectorDataPopulator.setVector(expected, - "a0", null, "a2", "a3", null, "a5", "a6", "a7", null, null, "a10", "a11", "a12", "a13", null); + ValueVectorDataPopulator.setVector( + expected, "a0", null, "a2", "a3", null, "a5", "a6", "a7", null, null, "a10", "a11", + "a12", "a13", null); assertVectorsEqual(expected, target); } } @@ -238,7 +242,7 @@ public void testAppendLargeVariableWidthVector() { @Test public void testAppendEmptyLargeVariableWidthVector() { try (LargeVarCharVector target = new LargeVarCharVector("", allocator); - LargeVarCharVector delta = new LargeVarCharVector("", allocator)) { + LargeVarCharVector delta = new LargeVarCharVector("", allocator)) { ValueVectorDataPopulator.setVector(target, "a0", null, "a2", "a3", null); @@ -257,10 +261,11 @@ public void testAppendListVector() { final int length1 = 5; final int length2 = 2; try (ListVector target = ListVector.empty("target", allocator); - ListVector delta = ListVector.empty("delta", allocator)) { + ListVector delta = ListVector.empty("delta", allocator)) { target.allocateNew(); - ValueVectorDataPopulator.setVector(target, + ValueVectorDataPopulator.setVector( + target, Arrays.asList(0, 1), Arrays.asList(2, 3), null, @@ -269,9 +274,8 @@ public void testAppendListVector() { assertEquals(length1, target.getValueCount()); delta.allocateNew(); - ValueVectorDataPopulator.setVector(delta, - Arrays.asList(10, 11, 12, 13, 14), - Arrays.asList(15, 16, 17, 18, 19)); + ValueVectorDataPopulator.setVector( + delta, Arrays.asList(10, 11, 12, 13, 14), Arrays.asList(15, 16, 17, 18, 19)); assertEquals(length2, delta.getValueCount()); VectorAppender appender = new VectorAppender(target); @@ -304,13 +308,10 @@ public void testAppendListVector() { @Test public void testAppendEmptyListVector() { try (ListVector target = ListVector.empty("target", allocator); - ListVector delta = ListVector.empty("delta", allocator)) { + ListVector delta = ListVector.empty("delta", allocator)) { // populate target with data - ValueVectorDataPopulator.setVector(target, - Arrays.asList(0, 1), - Arrays.asList(2, 3), - null, - Arrays.asList(6, 7)); + ValueVectorDataPopulator.setVector( + target, Arrays.asList(0, 1), Arrays.asList(2, 3), null, Arrays.asList(6, 7)); assertEquals(4, target.getValueCount()); // leave delta vector empty and unallocated @@ -338,18 +339,15 @@ public void testAppendEmptyListVector() { @Test public void testAppendFixedSizeListVector() { try (FixedSizeListVector target = FixedSizeListVector.empty("target", 5, allocator); - FixedSizeListVector delta = FixedSizeListVector.empty("delta", 5, allocator)) { + FixedSizeListVector delta = FixedSizeListVector.empty("delta", 5, allocator)) { target.allocateNew(); - ValueVectorDataPopulator.setVector(target, - Arrays.asList(0, 1, 2, 3, 4), - null); + ValueVectorDataPopulator.setVector(target, Arrays.asList(0, 1, 2, 3, 4), null); assertEquals(2, target.getValueCount()); delta.allocateNew(); - ValueVectorDataPopulator.setVector(delta, - Arrays.asList(10, 11, 12, 13, 14), - Arrays.asList(15, 16, 17, 18, 19)); + ValueVectorDataPopulator.setVector( + delta, Arrays.asList(10, 11, 12, 13, 14), Arrays.asList(15, 16, 17, 18, 19)); assertEquals(2, delta.getValueCount()); VectorAppender appender = new VectorAppender(target); @@ -367,11 +365,9 @@ public void testAppendFixedSizeListVector() { @Test public void testAppendEmptyFixedSizeListVector() { try (FixedSizeListVector target = FixedSizeListVector.empty("target", 5, allocator); - FixedSizeListVector delta = FixedSizeListVector.empty("delta", 5, allocator)) { + FixedSizeListVector delta = FixedSizeListVector.empty("delta", 5, allocator)) { - ValueVectorDataPopulator.setVector(target, - Arrays.asList(0, 1, 2, 3, 4), - null); + ValueVectorDataPopulator.setVector(target, Arrays.asList(0, 1, 2, 3, 4), null); assertEquals(2, target.getValueCount()); // leave delta vector empty and unallocated @@ -390,11 +386,9 @@ public void testAppendEmptyFixedSizeListVector() { @Test public void testAppendEmptyLargeListVector() { try (LargeListVector target = LargeListVector.empty("target", allocator); - LargeListVector delta = LargeListVector.empty("delta", allocator)) { + LargeListVector delta = LargeListVector.empty("delta", allocator)) { - ValueVectorDataPopulator.setVector(target, - Arrays.asList(0, 1, 2, 3, 4), - null); + ValueVectorDataPopulator.setVector(target, Arrays.asList(0, 1, 2, 3, 4), null); assertEquals(2, target.getValueCount()); // leave delta vector empty and unallocated @@ -415,18 +409,23 @@ public void testAppendStructVector() { final int length1 = 10; final int length2 = 5; try (final StructVector target = StructVector.empty("target", allocator); - final StructVector delta = StructVector.empty("delta", allocator)) { + final StructVector delta = StructVector.empty("delta", allocator)) { - IntVector targetChild1 = target.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); - VarCharVector targetChild2 = target.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class); + IntVector targetChild1 = + target.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); + VarCharVector targetChild2 = + target.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class); targetChild1.allocateNew(); targetChild2.allocateNew(); ValueVectorDataPopulator.setVector(targetChild1, 0, 1, 2, 3, 4, null, 6, 7, 8, 9); - ValueVectorDataPopulator.setVector(targetChild2, "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9"); + ValueVectorDataPopulator.setVector( + targetChild2, "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9"); target.setValueCount(length1); - IntVector deltaChild1 = delta.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); - VarCharVector deltaChild2 = delta.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class); + IntVector deltaChild1 = + delta.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); + VarCharVector deltaChild2 = + delta.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class); deltaChild1.allocateNew(); deltaChild2.allocateNew(); ValueVectorDataPopulator.setVector(deltaChild1, 10, 11, 12, null, 14); @@ -441,13 +440,15 @@ public void testAppendStructVector() { VarCharVector child2 = (VarCharVector) target.getVectorById(1); try (IntVector expected1 = new IntVector("expected1", allocator); - VarCharVector expected2 = new VarCharVector("expected2", allocator)) { + VarCharVector expected2 = new VarCharVector("expected2", allocator)) { expected1.allocateNew(); expected2.allocateNew(); - ValueVectorDataPopulator.setVector(expected1, 0, 1, 2, 3, 4, null, 6, 7, 8, 9, 10, 11, 12, null, 14); - ValueVectorDataPopulator.setVector(expected2, - "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9", "a10", "a11", "a12", "a13", "a14"); + ValueVectorDataPopulator.setVector( + expected1, 0, 1, 2, 3, 4, null, 6, 7, 8, 9, 10, 11, 12, null, 14); + ValueVectorDataPopulator.setVector( + expected2, "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9", "a10", "a11", + "a12", "a13", "a14"); assertVectorsEqual(expected1, target.getChild("f0")); assertVectorsEqual(expected2, target.getChild("f1")); @@ -458,12 +459,15 @@ public void testAppendStructVector() { @Test public void testAppendEmptyStructVector() { try (final StructVector target = StructVector.empty("target", allocator); - final StructVector delta = StructVector.empty("delta", allocator)) { + final StructVector delta = StructVector.empty("delta", allocator)) { - IntVector targetChild1 = target.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); - VarCharVector targetChild2 = target.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class); + IntVector targetChild1 = + target.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class); + VarCharVector targetChild2 = + target.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class); ValueVectorDataPopulator.setVector(targetChild1, 0, 1, 2, 3, 4, null, 6, 7, 8, 9); - ValueVectorDataPopulator.setVector(targetChild2, "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9"); + ValueVectorDataPopulator.setVector( + targetChild2, "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9"); target.setValueCount(10); // leave delta vector fields empty and unallocated @@ -476,10 +480,10 @@ public void testAppendEmptyStructVector() { assertEquals(10, target.getValueCount()); try (IntVector expected1 = new IntVector("expected1", allocator); - VarCharVector expected2 = new VarCharVector("expected2", allocator)) { + VarCharVector expected2 = new VarCharVector("expected2", allocator)) { ValueVectorDataPopulator.setVector(expected1, 0, 1, 2, 3, 4, null, 6, 7, 8, 9); - ValueVectorDataPopulator.setVector(expected2, - "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9"); + ValueVectorDataPopulator.setVector( + expected2, "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9"); assertVectorsEqual(expected1, target.getChild("f0")); assertVectorsEqual(expected2, target.getChild("f1")); @@ -493,7 +497,7 @@ public void testAppendUnionVector() { final int length2 = 5; try (final UnionVector target = UnionVector.empty("target", allocator); - final UnionVector delta = UnionVector.empty("delta", allocator)) { + final UnionVector delta = UnionVector.empty("delta", allocator)) { // alternating ints and big ints target.setType(0, Types.MinorType.INT); @@ -521,14 +525,52 @@ public void testAppendUnionVector() { targetIntVec.allocateNew(); ValueVectorDataPopulator.setVector( targetIntVec, - 0, null, 1, null, 2, null, 3, null, 4, null, 5, null, 6, null, 7, null, 8, null, 9, null); + 0, + null, + 1, + null, + 2, + null, + 3, + null, + 4, + null, + 5, + null, + 6, + null, + 7, + null, + 8, + null, + 9, + null); assertEquals(length1 * 2, targetIntVec.getValueCount()); BigIntVector targetBigIntVec = target.getBigIntVector(); targetBigIntVec.allocateNew(); ValueVectorDataPopulator.setVector( targetBigIntVec, - null, 0L, null, 1L, null, 2L, null, 3L, null, 4L, null, 5L, null, 6L, null, 7L, null, 8L, null, 9L); + null, + 0L, + null, + 1L, + null, + 2L, + null, + 3L, + null, + 4L, + null, + 5L, + null, + 6L, + null, + 7L, + null, + 8L, + null, + 9L); assertEquals(length1 * 2, targetBigIntVec.getValueCount()); target.setValueCount(length1 * 2); @@ -574,7 +616,7 @@ public void testAppendEmptyUnionVector() { final int length1 = 10; try (final UnionVector target = UnionVector.empty("target", allocator); - final UnionVector delta = UnionVector.empty("delta", allocator)) { + final UnionVector delta = UnionVector.empty("delta", allocator)) { // alternating ints and big ints target.setType(0, Types.MinorType.INT); @@ -601,13 +643,51 @@ public void testAppendEmptyUnionVector() { IntVector targetIntVec = target.getIntVector(); ValueVectorDataPopulator.setVector( targetIntVec, - 0, null, 1, null, 2, null, 3, null, 4, null, 5, null, 6, null, 7, null, 8, null, 9, null); + 0, + null, + 1, + null, + 2, + null, + 3, + null, + 4, + null, + 5, + null, + 6, + null, + 7, + null, + 8, + null, + 9, + null); assertEquals(length1 * 2, targetIntVec.getValueCount()); BigIntVector targetBigIntVec = target.getBigIntVector(); ValueVectorDataPopulator.setVector( targetBigIntVec, - null, 0L, null, 1L, null, 2L, null, 3L, null, 4L, null, 5L, null, 6L, null, 7L, null, 8L, null, 9L); + null, + 0L, + null, + 1L, + null, + 2L, + null, + 3L, + null, + 4L, + null, + 5L, + null, + 6L, + null, + 7L, + null, + 8L, + null, + 9L); assertEquals(length1 * 2, targetBigIntVec.getValueCount()); target.setValueCount(length1 * 2); @@ -653,20 +733,22 @@ private DenseUnionVector getTargetVector() { targetVector.reAlloc(); } - byte intTypeId = targetVector.registerNewTypeId(Field.nullable("", Types.MinorType.INT.getType())); + byte intTypeId = + targetVector.registerNewTypeId(Field.nullable("", Types.MinorType.INT.getType())); targetVector.setTypeId(0, intTypeId); intHolder.value = 1; targetVector.setSafe(0, intHolder); targetVector.setTypeId(1, intTypeId); intHolder.value = 2; targetVector.setSafe(1, intHolder); - byte longTypeId = targetVector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); + byte longTypeId = + targetVector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); targetVector.setTypeId(3, longTypeId); longHolder.value = 10L; targetVector.setSafe(3, longHolder); targetVector.setValueCount(4); - assertVectorValuesEqual(targetVector, new Object[]{1, 2, null, 10L}); + assertVectorValuesEqual(targetVector, new Object[] {1, 2, null, 10L}); return targetVector; } @@ -685,29 +767,32 @@ private DenseUnionVector getDeltaVector() { while (deltaVector.getValueCapacity() < 4) { deltaVector.reAlloc(); } - byte intTypeId = deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.INT.getType())); + byte intTypeId = + deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.INT.getType())); deltaVector.setTypeId(0, intTypeId); intHolder.value = 7; deltaVector.setSafe(0, intHolder); - byte longTypeId = deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); + byte longTypeId = + deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); deltaVector.setTypeId(2, longTypeId); longHolder.value = 8L; deltaVector.setSafe(2, longHolder); - byte floatTypeId = deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); + byte floatTypeId = + deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); deltaVector.setTypeId(3, floatTypeId); floatHolder.value = 9.0f; deltaVector.setSafe(3, floatHolder); deltaVector.setValueCount(4); - assertVectorValuesEqual(deltaVector, new Object[]{7, null, 8L, 9.0f}); + assertVectorValuesEqual(deltaVector, new Object[] {7, null, 8L, 9.0f}); return deltaVector; } @Test public void testAppendDenseUnionVector() { try (DenseUnionVector targetVector = getTargetVector(); - DenseUnionVector deltaVector = getDeltaVector()) { + DenseUnionVector deltaVector = getDeltaVector()) { // append VectorAppender appender = new VectorAppender(targetVector); @@ -717,7 +802,7 @@ public void testAppendDenseUnionVector() { // test reverse append try (DenseUnionVector targetVector = getTargetVector(); - DenseUnionVector deltaVector = getDeltaVector()) { + DenseUnionVector deltaVector = getDeltaVector()) { // append VectorAppender appender = new VectorAppender(deltaVector); @@ -730,13 +815,16 @@ private DenseUnionVector getEmptyDeltaVector() { // create a vector, but leave it empty and uninitialized DenseUnionVector deltaVector = new DenseUnionVector("target vector", allocator, null, null); - byte intTypeId = deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.INT.getType())); + byte intTypeId = + deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.INT.getType())); deltaVector.setTypeId(0, intTypeId); - byte longTypeId = deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); + byte longTypeId = + deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); deltaVector.setTypeId(2, longTypeId); - byte floatTypeId = deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); + byte floatTypeId = + deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); deltaVector.setTypeId(3, floatTypeId); return deltaVector; @@ -745,7 +833,7 @@ private DenseUnionVector getEmptyDeltaVector() { @Test public void testAppendEmptyDenseUnionVector() { try (DenseUnionVector targetVector = getTargetVector(); - DenseUnionVector deltaVector = getEmptyDeltaVector()) { + DenseUnionVector deltaVector = getEmptyDeltaVector()) { // append VectorAppender appender = new VectorAppender(targetVector); @@ -754,9 +842,7 @@ public void testAppendEmptyDenseUnionVector() { } } - /** - * Test appending dense union vectors where the child vectors do not match. - */ + /** Test appending dense union vectors where the child vectors do not match. */ @Test public void testAppendDenseUnionVectorMismatch() { final NullableIntHolder intHolder = new NullableIntHolder(); @@ -768,8 +854,10 @@ public void testAppendDenseUnionVectorMismatch() { final NullableFloat4Holder floatHolder = new NullableFloat4Holder(); floatHolder.isSet = 1; - try (DenseUnionVector targetVector = new DenseUnionVector("target vector" , allocator, null, null); - DenseUnionVector deltaVector = new DenseUnionVector("target vector" , allocator, null, null)) { + try (DenseUnionVector targetVector = + new DenseUnionVector("target vector", allocator, null, null); + DenseUnionVector deltaVector = + new DenseUnionVector("target vector", allocator, null, null)) { targetVector.allocateNew(); deltaVector.allocateNew(); @@ -777,11 +865,13 @@ public void testAppendDenseUnionVectorMismatch() { while (targetVector.getValueCapacity() < 2) { targetVector.reAlloc(); } - byte intTypeId = targetVector.registerNewTypeId(Field.nullable("", Types.MinorType.INT.getType())); + byte intTypeId = + targetVector.registerNewTypeId(Field.nullable("", Types.MinorType.INT.getType())); targetVector.setTypeId(0, intTypeId); intHolder.value = 1; targetVector.setSafe(0, intHolder); - byte longTypeId = targetVector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); + byte longTypeId = + targetVector.registerNewTypeId(Field.nullable("", Types.MinorType.BIGINT.getType())); targetVector.setTypeId(1, longTypeId); longHolder.value = 2L; targetVector.setSafe(1, longHolder); @@ -797,7 +887,8 @@ public void testAppendDenseUnionVectorMismatch() { deltaVector.setTypeId(0, intTypeId); intHolder.value = 3; deltaVector.setSafe(0, intHolder); - byte floatTypeId = deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); + byte floatTypeId = + deltaVector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); deltaVector.setTypeId(1, floatTypeId); floatHolder.value = 5.0f; deltaVector.setSafe(1, floatHolder); @@ -807,8 +898,7 @@ public void testAppendDenseUnionVectorMismatch() { // append VectorAppender appender = new VectorAppender(targetVector); - assertThrows(IllegalArgumentException.class, - () -> deltaVector.accept(appender, null)); + assertThrows(IllegalArgumentException.class, () -> deltaVector.accept(appender, null)); } } @@ -816,15 +906,14 @@ public void testAppendDenseUnionVectorMismatch() { public void testAppendVectorNegative() { final int vectorLength = 10; try (IntVector target = new IntVector("", allocator); - VarCharVector delta = new VarCharVector("", allocator)) { + VarCharVector delta = new VarCharVector("", allocator)) { target.allocateNew(vectorLength); delta.allocateNew(vectorLength); VectorAppender appender = new VectorAppender(target); - assertThrows(IllegalArgumentException.class, - () -> delta.accept(appender, null)); + assertThrows(IllegalArgumentException.class, () -> delta.accept(appender, null)); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorBatchAppender.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorBatchAppender.java index 799c25c0ad7..e90618f8769 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorBatchAppender.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorBatchAppender.java @@ -27,9 +27,7 @@ import org.junit.Before; import org.junit.Test; -/** - * Test cases for {@link VectorBatchAppender}. - */ +/** Test cases for {@link VectorBatchAppender}. */ public class TestVectorBatchAppender { private BufferAllocator allocator; @@ -50,8 +48,8 @@ public void testBatchAppendIntVector() { final int length2 = 5; final int length3 = 7; try (IntVector target = new IntVector("", allocator); - IntVector delta1 = new IntVector("", allocator); - IntVector delta2 = new IntVector("", allocator)) { + IntVector delta1 = new IntVector("", allocator); + IntVector delta2 = new IntVector("", allocator)) { target.allocateNew(length1); delta1.allocateNew(length2); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorSchemaRootAppender.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorSchemaRootAppender.java index 6309d385870..d692029e083 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorSchemaRootAppender.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorSchemaRootAppender.java @@ -32,9 +32,7 @@ import org.junit.Before; import org.junit.Test; -/** - * Test cases for {@link VectorSchemaRootAppender}. - */ +/** Test cases for {@link VectorSchemaRootAppender}. */ public class TestVectorSchemaRootAppender { private BufferAllocator allocator; @@ -56,16 +54,14 @@ public void testVectorSchemaRootAppend() { final int length3 = 2; try (IntVector targetChild1 = new IntVector("t1", allocator); - VarCharVector targetChild2 = new VarCharVector("t2", allocator); - BigIntVector targetChild3 = new BigIntVector("t3", allocator); - - IntVector deltaChildOne1 = new IntVector("do1", allocator); - VarCharVector deltaChildOne2 = new VarCharVector("do2", allocator); - BigIntVector deltaChildOne3 = new BigIntVector("do3", allocator); - - IntVector deltaChildTwo1 = new IntVector("dt1", allocator); - VarCharVector deltaChildTwo2 = new VarCharVector("dt2", allocator); - BigIntVector deltaChildTwo3 = new BigIntVector("dt3", allocator)) { + VarCharVector targetChild2 = new VarCharVector("t2", allocator); + BigIntVector targetChild3 = new BigIntVector("t3", allocator); + IntVector deltaChildOne1 = new IntVector("do1", allocator); + VarCharVector deltaChildOne2 = new VarCharVector("do2", allocator); + BigIntVector deltaChildOne3 = new BigIntVector("do3", allocator); + IntVector deltaChildTwo1 = new IntVector("dt1", allocator); + VarCharVector deltaChildTwo2 = new VarCharVector("dt2", allocator); + BigIntVector deltaChildTwo3 = new BigIntVector("dt3", allocator)) { ValueVectorDataPopulator.setVector(targetChild1, 0, 1, null, 3, 4); ValueVectorDataPopulator.setVector(targetChild2, "zero", "one", null, "three", "four"); @@ -90,13 +86,14 @@ public void testVectorSchemaRootAppend() { assertEquals(3, root1.getFieldVectors().size()); try (IntVector expected1 = new IntVector("", allocator); - VarCharVector expected2 = new VarCharVector("", allocator); - BigIntVector expected3 = new BigIntVector("", allocator)) { + VarCharVector expected2 = new VarCharVector("", allocator); + BigIntVector expected3 = new BigIntVector("", allocator)) { ValueVectorDataPopulator.setVector(expected1, 0, 1, null, 3, 4, 5, 6, 7, null, 9); ValueVectorDataPopulator.setVector( expected2, "zero", "one", null, "three", "four", "five", "six", "seven", null, "nine"); - ValueVectorDataPopulator.setVector(expected3, 0L, 10L, null, 30L, 40L, 50L, 60L, 70L, null, 90L); + ValueVectorDataPopulator.setVector( + expected3, 0L, 10L, null, 30L, 40L, 50L, 60L, 70L, null, 90L); assertVectorsEqual(expected1, root1.getVector(0)); assertVectorsEqual(expected2, root1.getVector(1)); @@ -108,11 +105,10 @@ public void testVectorSchemaRootAppend() { @Test public void testRootWithDifferentChildCounts() { try (IntVector targetChild1 = new IntVector("t1", allocator); - VarCharVector targetChild2 = new VarCharVector("t2", allocator); - BigIntVector targetChild3 = new BigIntVector("t3", allocator); - - IntVector deltaChild1 = new IntVector("d1", allocator); - VarCharVector deltaChild2 = new VarCharVector("d2", allocator)) { + VarCharVector targetChild2 = new VarCharVector("t2", allocator); + BigIntVector targetChild3 = new BigIntVector("t3", allocator); + IntVector deltaChild1 = new IntVector("d1", allocator); + VarCharVector deltaChild2 = new VarCharVector("d2", allocator)) { ValueVectorDataPopulator.setVector(targetChild1, 0, 1, null, 3, 4); ValueVectorDataPopulator.setVector(targetChild2, "zero", "one", null, "three", "four"); @@ -125,20 +121,21 @@ public void testRootWithDifferentChildCounts() { VectorSchemaRoot root2 = VectorSchemaRoot.of(deltaChild1, deltaChild2); root2.setRowCount(3); - IllegalArgumentException exp = assertThrows(IllegalArgumentException.class, - () -> VectorSchemaRootAppender.append(root1, root2)); + IllegalArgumentException exp = + assertThrows( + IllegalArgumentException.class, () -> VectorSchemaRootAppender.append(root1, root2)); - assertEquals("Vector schema roots have different numbers of child vectors.", exp.getMessage()); + assertEquals( + "Vector schema roots have different numbers of child vectors.", exp.getMessage()); } } @Test public void testRootWithDifferentChildTypes() { try (IntVector targetChild1 = new IntVector("t1", allocator); - VarCharVector targetChild2 = new VarCharVector("t2", allocator); - - IntVector deltaChild1 = new IntVector("d1", allocator); - VarCharVector deltaChild2 = new VarCharVector("d2", allocator)) { + VarCharVector targetChild2 = new VarCharVector("t2", allocator); + IntVector deltaChild1 = new IntVector("d1", allocator); + VarCharVector deltaChild2 = new VarCharVector("d2", allocator)) { ValueVectorDataPopulator.setVector(targetChild1, 0, 1, null, 3, 4); ValueVectorDataPopulator.setVector(targetChild2, "zero", "one", null, "three", "four"); @@ -152,8 +149,9 @@ public void testRootWithDifferentChildTypes() { VectorSchemaRoot root2 = VectorSchemaRoot.of(deltaChild2, deltaChild1); root2.setRowCount(3); - IllegalArgumentException exp = assertThrows(IllegalArgumentException.class, - () -> VectorSchemaRootAppender.append(root1, root2)); + IllegalArgumentException exp = + assertThrows( + IllegalArgumentException.class, () -> VectorSchemaRootAppender.append(root1, root2)); assertEquals("Vector schema roots have different schemas.", exp.getMessage()); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVector.java b/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVector.java index 20492036dab..3687e5fbb98 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVector.java @@ -24,7 +24,6 @@ import java.nio.charset.Charset; import java.util.Arrays; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BigIntVector; @@ -75,8 +74,8 @@ public void testBaseFixedWidthVector() { validate(vector); vector.getDataBuffer().capacity(0); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e.getMessage().contains("Not enough capacity for fixed width data buffer")); } } @@ -89,8 +88,8 @@ public void testBaseVariableWidthVector() { validate(vector); vector.getDataBuffer().capacity(0); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e.getMessage().contains("Not enough capacity for data buffer")); } } @@ -103,8 +102,8 @@ public void testBaseLargeVariableWidthVector() { validate(vector); vector.getDataBuffer().capacity(0); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e.getMessage().contains("Not enough capacity for data buffer")); } } @@ -117,8 +116,8 @@ public void testListVector() { validate(vector); vector.getDataVector().setValueCount(3); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e.getMessage().contains("Inner vector does not contain enough elements.")); } } @@ -131,8 +130,8 @@ public void testLargeListVector() { validate(vector); vector.getDataVector().setValueCount(4); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e.getMessage().contains("Inner vector does not contain enough elements.")); } } @@ -145,8 +144,8 @@ public void testFixedSizeListVector() { validate(vector); vector.getDataVector().setValueCount(3); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e.getMessage().contains("Inner vector does not contain enough elements.")); } } @@ -170,16 +169,16 @@ public void testStructVectorRangeEquals() { writer.setValueCount(5); vector.getChild("f0").setValueCount(2); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e.getMessage().contains("Struct vector length not equal to child vector length")); vector.getChild("f0").setValueCount(5); validate(vector); vector.getChild("f0").getDataBuffer().capacity(0); - ValidateUtil.ValidateException e2 = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e2 = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e2.getMessage().contains("Not enough capacity for fixed width data buffer")); } } @@ -206,16 +205,16 @@ public void testUnionVector() { validate(vector); vector.getChildrenFromFields().get(0).setValueCount(1); - ValidateUtil.ValidateException e1 = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e1 = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e1.getMessage().contains("Union vector length not equal to child vector length")); vector.getChildrenFromFields().get(0).setValueCount(2); validate(vector); vector.getChildrenFromFields().get(0).getDataBuffer().capacity(0); - ValidateUtil.ValidateException e2 = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e2 = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e2.getMessage().contains("Not enough capacity for fixed width data buffer")); } } @@ -233,8 +232,10 @@ public void testDenseUnionVector() { float8Holder.value = 2.02f; float8Holder.isSet = 1; - byte float4TypeId = vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); - byte float8TypeId = vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT8.getType())); + byte float4TypeId = + vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); + byte float8TypeId = + vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT8.getType())); vector.setTypeId(0, float4TypeId); vector.setSafe(0, float4Holder); @@ -245,8 +246,8 @@ public void testDenseUnionVector() { validate(vector); vector.getChildrenFromFields().get(0).getDataBuffer().capacity(0); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(vector)); assertTrue(e.getMessage().contains("Not enough capacity for fixed width data buffer")); } } @@ -259,8 +260,8 @@ public void testBaseFixedWidthVectorInstanceMethod() { vector.validate(); vector.getDataBuffer().capacity(0); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> vector.validate()); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> vector.validate()); assertTrue(e.getMessage().contains("Not enough capacity for fixed width data buffer")); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorFull.java b/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorFull.java index ca71a622bb8..be7688e2486 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorFull.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorFull.java @@ -25,7 +25,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -77,9 +76,11 @@ public void testBaseVariableWidthVector() { offsetBuf.setInt(0, 100); offsetBuf.setInt(4, 50); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(vector)); - assertTrue(e.getMessage().contains("The values in positions 0 and 1 of the offset buffer are decreasing")); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector)); + assertTrue( + e.getMessage() + .contains("The values in positions 0 and 1 of the offset buffer are decreasing")); } } @@ -94,9 +95,12 @@ public void testBaseLargeVariableWidthVector() { offsetBuf.setLong(0, 100); offsetBuf.setLong(8, 50); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(vector)); - assertTrue(e.getMessage().contains("The values in positions 0 and 1 of the large offset buffer are decreasing")); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector)); + assertTrue( + e.getMessage() + .contains( + "The values in positions 0 and 1 of the large offset buffer are decreasing")); } } @@ -111,9 +115,11 @@ public void testListVector() { offsetBuf.setInt(0, 100); offsetBuf.setInt(8, 50); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(vector)); - assertTrue(e.getMessage().contains("The values in positions 0 and 1 of the offset buffer are decreasing")); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector)); + assertTrue( + e.getMessage() + .contains("The values in positions 0 and 1 of the offset buffer are decreasing")); } } @@ -128,9 +134,12 @@ public void testLargeListVector() { offsetBuf.setLong(0, 100); offsetBuf.setLong(16, 50); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(vector)); - assertTrue(e.getMessage().contains("The values in positions 0 and 1 of the large offset buffer are decreasing")); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector)); + assertTrue( + e.getMessage() + .contains( + "The values in positions 0 and 1 of the large offset buffer are decreasing")); } } @@ -158,13 +167,16 @@ public void testStructVectorRangeEquals() { offsetBuf.setInt(0, 100); offsetBuf.setInt(8, 50); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(strVector)); - assertTrue(e.getMessage().contains("The values in positions 0 and 1 of the offset buffer are decreasing")); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(strVector)); + assertTrue( + e.getMessage() + .contains("The values in positions 0 and 1 of the offset buffer are decreasing")); - e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(vector)); - assertTrue(e.getMessage().contains("The values in positions 0 and 1 of the offset buffer are decreasing")); + e = assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector)); + assertTrue( + e.getMessage() + .contains("The values in positions 0 and 1 of the offset buffer are decreasing")); } } @@ -192,8 +204,8 @@ public void testUnionVector() { // negative type id vector.getTypeBuffer().setByte(0, -1); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector)); assertTrue(e.getMessage().contains("The type id at position 0 is negative")); } } @@ -211,8 +223,10 @@ public void testDenseUnionVector() { float8Holder.value = 2.02f; float8Holder.isSet = 1; - byte float4TypeId = vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); - byte float8TypeId = vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT8.getType())); + byte float4TypeId = + vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT4.getType())); + byte float8TypeId = + vector.registerNewTypeId(Field.nullable("", Types.MinorType.FLOAT8.getType())); vector.setTypeId(0, float4TypeId); vector.setSafe(0, float4Holder); @@ -229,8 +243,8 @@ public void testDenseUnionVector() { // shrink sub-vector subVector.setValueCount(0); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(vector)); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(vector)); assertTrue(e.getMessage().contains("Dense union vector offset exceeds sub-vector boundary")); } } @@ -246,9 +260,11 @@ public void testBaseVariableWidthVectorInstanceMethod() { offsetBuf.setInt(0, 100); offsetBuf.setInt(4, 50); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - vector::validateFull); - assertTrue(e.getMessage().contains("The values in positions 0 and 1 of the offset buffer are decreasing")); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, vector::validateFull); + assertTrue( + e.getMessage() + .contains("The values in positions 0 and 1 of the offset buffer are decreasing")); } } @@ -256,10 +272,13 @@ public void testBaseVariableWidthVectorInstanceMethod() { public void testValidateVarCharUTF8() { try (final VarCharVector vector = new VarCharVector("v", allocator)) { vector.validateFull(); - setVector(vector, "aaa".getBytes(StandardCharsets.UTF_8), "bbb".getBytes(StandardCharsets.UTF_8), + setVector( + vector, + "aaa".getBytes(StandardCharsets.UTF_8), + "bbb".getBytes(StandardCharsets.UTF_8), new byte[] {(byte) 0xFF, (byte) 0xFE}); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - vector::validateFull); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, vector::validateFull); assertTrue(e.getMessage().contains("UTF")); } } @@ -268,40 +287,47 @@ public void testValidateVarCharUTF8() { public void testValidateLargeVarCharUTF8() { try (final LargeVarCharVector vector = new LargeVarCharVector("v", allocator)) { vector.validateFull(); - setVector(vector, "aaa".getBytes(StandardCharsets.UTF_8), "bbb".getBytes(StandardCharsets.UTF_8), + setVector( + vector, + "aaa".getBytes(StandardCharsets.UTF_8), + "bbb".getBytes(StandardCharsets.UTF_8), new byte[] {(byte) 0xFF, (byte) 0xFE}); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - vector::validateFull); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, vector::validateFull); assertTrue(e.getMessage().contains("UTF")); } } @Test public void testValidateDecimal() { - try (final DecimalVector vector = new DecimalVector(Field.nullable("v", - new ArrowType.Decimal(2, 0, DecimalVector.TYPE_WIDTH * 8)), allocator)) { + try (final DecimalVector vector = + new DecimalVector( + Field.nullable("v", new ArrowType.Decimal(2, 0, DecimalVector.TYPE_WIDTH * 8)), + allocator)) { vector.validateFull(); setVector(vector, 1L); vector.validateFull(); vector.clear(); setVector(vector, Long.MAX_VALUE); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - vector::validateFull); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, vector::validateFull); assertTrue(e.getMessage().contains("Decimal")); } } @Test public void testValidateDecimal256() { - try (final Decimal256Vector vector = new Decimal256Vector(Field.nullable("v", - new ArrowType.Decimal(2, 0, DecimalVector.TYPE_WIDTH * 8)), allocator)) { + try (final Decimal256Vector vector = + new Decimal256Vector( + Field.nullable("v", new ArrowType.Decimal(2, 0, DecimalVector.TYPE_WIDTH * 8)), + allocator)) { vector.validateFull(); setVector(vector, 1L); vector.validateFull(); vector.clear(); setVector(vector, Long.MAX_VALUE); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - vector::validateFull); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, vector::validateFull); assertTrue(e.getMessage().contains("Decimal")); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorSchemaRoot.java b/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorSchemaRoot.java index 1885fb21f17..a997ee2a943 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorSchemaRoot.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorSchemaRoot.java @@ -50,7 +50,7 @@ public void terminate() throws Exception { @Test public void testValidatePositive() { try (IntVector intVector = new IntVector("int vector", allocator); - VarCharVector strVector = new VarCharVector("var char vector", allocator)) { + VarCharVector strVector = new VarCharVector("var char vector", allocator)) { VectorSchemaRoot root = VectorSchemaRoot.of(intVector, strVector); @@ -69,7 +69,7 @@ public void testValidatePositive() { @Test public void testValidateNegative() { try (IntVector intVector = new IntVector("int vector", allocator); - VarCharVector strVector = new VarCharVector("var char vector", allocator)) { + VarCharVector strVector = new VarCharVector("var char vector", allocator)) { VectorSchemaRoot root = VectorSchemaRoot.of(intVector, strVector); @@ -80,12 +80,15 @@ public void testValidateNegative() { root.setRowCount(4); intVector.setValueCount(5); strVector.setValueCount(5); - ValidateUtil.ValidateException e = assertThrows(ValidateUtil.ValidateException.class, - () -> validate(root)); - assertTrue(e.getMessage().contains("Child vector and vector schema root have different value counts")); - e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(root)); - assertTrue(e.getMessage().contains("Child vector and vector schema root have different value counts")); + ValidateUtil.ValidateException e = + assertThrows(ValidateUtil.ValidateException.class, () -> validate(root)); + assertTrue( + e.getMessage() + .contains("Child vector and vector schema root have different value counts")); + e = assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(root)); + assertTrue( + e.getMessage() + .contains("Child vector and vector schema root have different value counts")); // valid problems with the child vector root.setRowCount(5); @@ -93,9 +96,10 @@ public void testValidateNegative() { offsetBuf.setInt(0, 100); offsetBuf.setInt(8, 50); validate(root); - e = assertThrows(ValidateUtil.ValidateException.class, - () -> validateFull(root)); - assertTrue(e.getMessage().contains("The values in positions 0 and 1 of the offset buffer are decreasing")); + e = assertThrows(ValidateUtil.ValidateException.class, () -> validateFull(root)); + assertTrue( + e.getMessage() + .contains("The values in positions 0 and 1 of the offset buffer are decreasing")); } } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorTypeVisitor.java b/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorTypeVisitor.java index 0ddd790d6ff..f9ea39289df 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorTypeVisitor.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/validate/TestValidateVectorTypeVisitor.java @@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.function.Supplier; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.BigIntVector; @@ -74,9 +73,7 @@ import org.junit.Before; import org.junit.Test; -/** - * Test cases for {@link ValidateVectorTypeVisitor}. - */ +/** Test cases for {@link ValidateVectorTypeVisitor}. */ public class TestValidateVectorTypeVisitor { private BufferAllocator allocator; @@ -94,16 +91,18 @@ public void terminate() throws Exception { } private void testPositiveCase(Supplier vectorGenerator) { - try (ValueVector vector = vectorGenerator.get();) { + try (ValueVector vector = vectorGenerator.get(); ) { vector.accept(visitor, null); } } private void testNegativeCase(Supplier vectorGenerator) { try (ValueVector vector = vectorGenerator.get()) { - assertThrows(ValidateUtil.ValidateException.class, () -> { - vector.accept(visitor, null); - }); + assertThrows( + ValidateUtil.ValidateException.class, + () -> { + vector.accept(visitor, null); + }); } } @@ -126,8 +125,10 @@ public void testFixedWidthVectorsPositive() { testPositiveCase(() -> new DateDayVector("vector", allocator)); testPositiveCase(() -> new DateMilliVector("vector", allocator)); - testPositiveCase(() -> new DurationVector( - "vector", FieldType.nullable(new ArrowType.Duration(TimeUnit.SECOND)), allocator)); + testPositiveCase( + () -> + new DurationVector( + "vector", FieldType.nullable(new ArrowType.Duration(TimeUnit.SECOND)), allocator)); // float vectors testPositiveCase(() -> new Float4Vector("vector", allocator)); @@ -160,96 +161,173 @@ public void testFixedWidthVectorsPositive() { public void testFixedWidthVectorsNegative() { // integer vectors testNegativeCase( - () -> new TinyIntVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); + () -> + new TinyIntVector( + "vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); testNegativeCase( - () -> new SmallIntVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); + () -> + new SmallIntVector( + "vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); testNegativeCase( - () -> new BigIntVector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); + () -> + new BigIntVector( + "vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); testNegativeCase( - () -> new BigIntVector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); + () -> + new BigIntVector( + "vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); testNegativeCase( - () -> new UInt1Vector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); + () -> + new UInt1Vector( + "vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); testNegativeCase( - () -> new UInt2Vector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); + () -> + new UInt2Vector( + "vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); testNegativeCase( - () -> new UInt4Vector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); + () -> + new UInt4Vector( + "vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); testNegativeCase( - () -> new UInt8Vector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); + () -> + new UInt8Vector( + "vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); testNegativeCase( - () -> new BitVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); - testNegativeCase( - () -> new DecimalVector("vector", allocator, 30, -16)); + () -> + new BitVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + testNegativeCase(() -> new DecimalVector("vector", allocator, 30, -16)); // date vectors testNegativeCase( - () -> new DateDayVector("vector", FieldType.nullable(Types.MinorType.FLOAT4.getType()), allocator)); + () -> + new DateDayVector( + "vector", FieldType.nullable(Types.MinorType.FLOAT4.getType()), allocator)); testNegativeCase( - () -> new DateMilliVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + () -> + new DateMilliVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); // float pont vectors testNegativeCase( - () -> new Float4Vector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + () -> + new Float4Vector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); testNegativeCase( - () -> new Float8Vector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + () -> + new Float8Vector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); // interval vectors testNegativeCase( - () -> new IntervalDayVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); + () -> + new IntervalDayVector( + "vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); testNegativeCase( - () -> new IntervalYearVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + () -> + new IntervalYearVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); // time vectors testNegativeCase( - () -> new TimeMilliVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + () -> + new TimeMilliVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); testNegativeCase( - () -> new TimeMicroVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + () -> + new TimeMicroVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); testNegativeCase( - () -> new TimeNanoVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + () -> + new TimeNanoVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); testNegativeCase( - () -> new TimeSecVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + () -> + new TimeSecVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); // time stamp vectors - testNegativeCase( - () -> new TimeStampMicroTZVector("vector", allocator, null)); - testNegativeCase( - () -> new TimeStampMicroVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); - testNegativeCase( - () -> new TimeStampMilliTZVector("vector", allocator, null)); - testNegativeCase( - () -> new TimeStampMilliVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); - testNegativeCase( - () -> new TimeStampNanoTZVector("vector", allocator, null)); - testNegativeCase( - () -> new TimeStampNanoVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); - testNegativeCase( - () -> new TimeStampSecTZVector("vector", allocator, null)); - testNegativeCase( - () -> new TimeStampSecVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + testNegativeCase(() -> new TimeStampMicroTZVector("vector", allocator, null)); + testNegativeCase( + () -> + new TimeStampMicroVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + testNegativeCase(() -> new TimeStampMilliTZVector("vector", allocator, null)); + testNegativeCase( + () -> + new TimeStampMilliVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + testNegativeCase(() -> new TimeStampNanoTZVector("vector", allocator, null)); + testNegativeCase( + () -> + new TimeStampNanoVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); + testNegativeCase(() -> new TimeStampSecTZVector("vector", allocator, null)); + testNegativeCase( + () -> + new TimeStampSecVector( + "vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); } @Test public void testDecimalVector() { - testPositiveCase(() -> - new DecimalVector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(10, 10, 128)), allocator)); - testPositiveCase(() -> - new DecimalVector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(38, 10, 128)), allocator)); - testPositiveCase(() -> - new Decimal256Vector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(50, 10, 256)), allocator)); - testPositiveCase(() -> - new Decimal256Vector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(76, 10, 256)), allocator)); - testNegativeCase(() -> - new DecimalVector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(50, 10, 128)), allocator)); - testNegativeCase(() -> - new Decimal256Vector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(100, 10, 256)), allocator)); - testNegativeCase(() -> - new DecimalVector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(0, 10, 128)), allocator)); - testNegativeCase(() -> - new Decimal256Vector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(-1, 10, 256)), allocator)); - testNegativeCase(() -> - new Decimal256Vector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(30, 10, 64)), allocator)); - testNegativeCase(() -> - new Decimal256Vector("dec", FieldType.nullable(ArrowType.Decimal.createDecimal(10, 20, 256)), allocator)); + testPositiveCase( + () -> + new DecimalVector( + "dec", + FieldType.nullable(ArrowType.Decimal.createDecimal(10, 10, 128)), + allocator)); + testPositiveCase( + () -> + new DecimalVector( + "dec", + FieldType.nullable(ArrowType.Decimal.createDecimal(38, 10, 128)), + allocator)); + testPositiveCase( + () -> + new Decimal256Vector( + "dec", + FieldType.nullable(ArrowType.Decimal.createDecimal(50, 10, 256)), + allocator)); + testPositiveCase( + () -> + new Decimal256Vector( + "dec", + FieldType.nullable(ArrowType.Decimal.createDecimal(76, 10, 256)), + allocator)); + testNegativeCase( + () -> + new DecimalVector( + "dec", + FieldType.nullable(ArrowType.Decimal.createDecimal(50, 10, 128)), + allocator)); + testNegativeCase( + () -> + new Decimal256Vector( + "dec", + FieldType.nullable(ArrowType.Decimal.createDecimal(100, 10, 256)), + allocator)); + testNegativeCase( + () -> + new DecimalVector( + "dec", FieldType.nullable(ArrowType.Decimal.createDecimal(0, 10, 128)), allocator)); + testNegativeCase( + () -> + new Decimal256Vector( + "dec", + FieldType.nullable(ArrowType.Decimal.createDecimal(-1, 10, 256)), + allocator)); + testNegativeCase( + () -> + new Decimal256Vector( + "dec", FieldType.nullable(ArrowType.Decimal.createDecimal(30, 10, 64)), allocator)); + testNegativeCase( + () -> + new Decimal256Vector( + "dec", + FieldType.nullable(ArrowType.Decimal.createDecimal(10, 20, 256)), + allocator)); } @Test @@ -261,9 +339,13 @@ public void testVariableWidthVectorsPositive() { @Test public void testVariableWidthVectorsNegative() { testNegativeCase( - () -> new VarCharVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); + () -> + new VarCharVector( + "vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); testNegativeCase( - () -> new VarBinaryVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); + () -> + new VarBinaryVector( + "vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); } @Test @@ -275,9 +357,13 @@ public void testLargeVariableWidthVectorsPositive() { @Test public void testLargeVariableWidthVectorsNegative() { testNegativeCase( - () -> new LargeVarCharVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); + () -> + new LargeVarCharVector( + "vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); testNegativeCase( - () -> new LargeVarBinaryVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); + () -> + new LargeVarBinaryVector( + "vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); } @Test @@ -285,7 +371,9 @@ public void testListVector() { testPositiveCase(() -> ListVector.empty("vector", allocator)); testNegativeCase( - () -> new ListVector("vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); + () -> + new ListVector( + "vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); } @Test @@ -293,7 +381,9 @@ public void testLargeListVector() { testPositiveCase(() -> LargeListVector.empty("vector", allocator)); testNegativeCase( - () -> new LargeListVector("vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); + () -> + new LargeListVector( + "vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); } @Test @@ -306,7 +396,9 @@ public void testStructVector() { testPositiveCase(() -> StructVector.empty("vector", allocator)); testNegativeCase( - () -> new StructVector("vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); + () -> + new StructVector( + "vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); } @Test diff --git a/java/vector/src/test/resources/logback.xml b/java/vector/src/test/resources/logback.xml index f9e449fa67b..30a9eca7285 100644 --- a/java/vector/src/test/resources/logback.xml +++ b/java/vector/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + - - 4.0.0 - - - org.apache.arrow - arrow-java-root - 16.0.0-SNAPSHOT - ../../pom.xml - - - arrow-jdbc - Arrow JDBC Adapter - (Contrib/Experimental)A library for converting JDBC data to Arrow data. - http://maven.apache.org - - - - - - org.apache.arrow - arrow-memory-core - - - - - org.apache.arrow - arrow-memory-netty - runtime - - - - - org.apache.arrow - arrow-vector - ${arrow.vector.classifier} - - - - org.immutables - value - - - - - com.h2database - h2 - 2.2.224 - test - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - test - - - - com.fasterxml.jackson.core - jackson-databind - - - - com.fasterxml.jackson.core - jackson-core - - - - com.fasterxml.jackson.core - jackson-annotations - test - - - - org.assertj - assertj-core - test - - - - - - - jdk11+ - - [11,] - - !m2e.version - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - --add-reads=org.apache.arrow.adapter.jdbc=com.fasterxml.jackson.dataformat.yaml --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED - - - - - - + 4.0.0 + + + org.apache.arrow + arrow-java-root + 16.0.0-SNAPSHOT + ../../pom.xml + + + arrow-jdbc + Arrow JDBC Adapter + (Contrib/Experimental)A library for converting JDBC data to Arrow data. + http://maven.apache.org + + + + + + org.apache.arrow + arrow-memory-core + + + + + org.apache.arrow + arrow-memory-netty + runtime + + + + + org.apache.arrow + arrow-vector + ${arrow.vector.classifier} + + + + org.immutables + value + + + + + com.h2database + h2 + 2.2.224 + test + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + test + + + + com.fasterxml.jackson.core + jackson-databind + + + + com.fasterxml.jackson.core + jackson-core + + + + com.fasterxml.jackson.core + jackson-annotations + test + + + + org.assertj + assertj-core + test + + + + + + + jdk11+ + + [11,] + + !m2e.version + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + --add-reads=org.apache.arrow.adapter.jdbc=com.fasterxml.jackson.dataformat.yaml --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED + + + + + + diff --git a/java/adapter/orc/pom.xml b/java/adapter/orc/pom.xml index 57876bd7c2b..8fe5529db64 100644 --- a/java/adapter/orc/pom.xml +++ b/java/adapter/orc/pom.xml @@ -9,132 +9,130 @@ 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. --> - - 4.0.0 - - - org.apache.arrow - arrow-memory-core - compile - - - org.apache.arrow - arrow-memory-netty - runtime - - - org.apache.arrow - arrow-vector - compile - ${arrow.vector.classifier} - - - org.immutables - value - - - org.apache.orc - orc-core - 1.9.2 - test - - - log4j - log4j - - - org.slf4j - slf4j-log4j12 - - - commons-logging - commons-logging - - - - - org.apache.hadoop - hadoop-client-runtime - 3.3.6 - test - - - commons-logging - commons-logging - - - - - org.apache.hadoop - hadoop-client-api - 3.3.2 - - - org.apache.hadoop - hadoop-common - 3.3.6 - test - - - commons-logging - commons-logging - - - log4j - log4j - - - org.slf4j - slf4j-log4j12 - - - javax.servlet - servlet-api - - - org.slf4j - slf4j-reload4j - - - ch.qos.reload4j - reload4j - - - - - org.apache.hive - hive-storage-api - 2.8.1 - test - - + + 4.0.0 - - org.apache.arrow - arrow-java-root - 16.0.0-SNAPSHOT - ../../pom.xml - + + org.apache.arrow + arrow-java-root + 16.0.0-SNAPSHOT + ../../pom.xml + - org.apache.arrow.orc - arrow-orc - Arrow Orc Adapter - (Experimental/Contrib)A JNI wrapper for the C++ ORC reader implementation. - jar - - ../../../cpp/release-build/ - + org.apache.arrow.orc + arrow-orc + jar + Arrow Orc Adapter + (Experimental/Contrib)A JNI wrapper for the C++ ORC reader implementation. + + ../../../cpp/release-build/ + + + + org.apache.arrow + arrow-memory-core + compile + + + org.apache.arrow + arrow-memory-netty + runtime + + + org.apache.arrow + arrow-vector + ${arrow.vector.classifier} + compile + + + org.immutables + value + + + org.apache.orc + orc-core + 1.9.2 + test + + + log4j + log4j + + + org.slf4j + slf4j-log4j12 + + + commons-logging + commons-logging + + + + + org.apache.hadoop + hadoop-client-runtime + 3.3.6 + test + + + commons-logging + commons-logging + + + + + org.apache.hadoop + hadoop-client-api + 3.3.2 + + + org.apache.hadoop + hadoop-common + 3.3.6 + test + + + commons-logging + commons-logging + + + log4j + log4j + + + org.slf4j + slf4j-log4j12 + + + javax.servlet + servlet-api + + + org.slf4j + slf4j-reload4j + + + ch.qos.reload4j + reload4j + + + + + org.apache.hive + hive-storage-api + 2.8.1 + test + + - - - - ${arrow.cpp.build.dir} - - **/*arrow_orc_jni.* - - - - + + + + ${arrow.cpp.build.dir} + + **/*arrow_orc_jni.* + + + + diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcFieldNode.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcFieldNode.java index 716a1387660..9290521c10b 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcFieldNode.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcFieldNode.java @@ -17,9 +17,7 @@ package org.apache.arrow.adapter.orc; -/** - * Metadata about Vectors/Arrays that is passed via JNI interface. - */ +/** Metadata about Vectors/Arrays that is passed via JNI interface. */ class OrcFieldNode { private final int length; @@ -27,6 +25,7 @@ class OrcFieldNode { /** * Construct a new instance. + * * @param length the number of values written. * @param nullCount the number of null values. */ diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcJniUtils.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcJniUtils.java index 9b599234bdf..21dcfb71c7f 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcJniUtils.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcJniUtils.java @@ -25,23 +25,21 @@ import java.nio.file.StandardCopyOption; import java.util.Locale; -/** - * Helper class for JNI related operations. - */ +/** Helper class for JNI related operations. */ class OrcJniUtils { private static final String LIBRARY_NAME = "arrow_orc_jni"; private static boolean isLoaded = false; private OrcJniUtils() {} - static void loadOrcAdapterLibraryFromJar() - throws IOException, IllegalAccessException { + static void loadOrcAdapterLibraryFromJar() throws IOException, IllegalAccessException { synchronized (OrcJniUtils.class) { if (!isLoaded) { final String libraryToLoad = LIBRARY_NAME + "/" + getNormalizedArch() + "/" + System.mapLibraryName(LIBRARY_NAME); final File libraryFile = - moveFileFromJarToTemp(System.getProperty("java.io.tmpdir"), libraryToLoad, LIBRARY_NAME); + moveFileFromJarToTemp( + System.getProperty("java.io.tmpdir"), libraryToLoad, LIBRARY_NAME); System.load(libraryFile.getAbsolutePath()); isLoaded = true; } @@ -63,11 +61,11 @@ private static String getNormalizedArch() { return arch; } - private static File moveFileFromJarToTemp(final String tmpDir, String libraryToLoad, String libraryName) - throws IOException { + private static File moveFileFromJarToTemp( + final String tmpDir, String libraryToLoad, String libraryName) throws IOException { final File temp = File.createTempFile(tmpDir, libraryName); - try (final InputStream is = OrcReaderJniWrapper.class.getClassLoader() - .getResourceAsStream(libraryToLoad)) { + try (final InputStream is = + OrcReaderJniWrapper.class.getClassLoader().getResourceAsStream(libraryToLoad)) { if (is == null) { throw new FileNotFoundException(libraryToLoad); } else { diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcMemoryJniWrapper.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcMemoryJniWrapper.java index 473e8314243..167481b05a5 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcMemoryJniWrapper.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcMemoryJniWrapper.java @@ -17,9 +17,7 @@ package org.apache.arrow.adapter.orc; -/** - * Wrapper for orc memory allocated by native code. - */ +/** Wrapper for orc memory allocated by native code. */ class OrcMemoryJniWrapper implements AutoCloseable { private final long nativeInstanceId; @@ -32,6 +30,7 @@ class OrcMemoryJniWrapper implements AutoCloseable { /** * Construct a new instance. + * * @param nativeInstanceId unique id of the underlying memory. * @param memoryAddress starting memory address of the underlying memory. * @param size size of the valid data. @@ -46,6 +45,7 @@ class OrcMemoryJniWrapper implements AutoCloseable { /** * Return the size of underlying chunk of memory that has valid data. + * * @return valid data size */ long getSize() { @@ -54,6 +54,7 @@ long getSize() { /** * Return the size of underlying chunk of memory managed by this OrcMemoryJniWrapper. + * * @return underlying memory size */ long getCapacity() { @@ -62,6 +63,7 @@ long getCapacity() { /** * Return the memory address of underlying chunk of memory. + * * @return memory address */ long getMemoryAddress() { diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReader.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReader.java index 648e17e9c37..1c9577ca726 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReader.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReader.java @@ -18,40 +18,39 @@ package org.apache.arrow.adapter.orc; import java.io.IOException; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.ipc.ArrowReader; /** - * Orc Reader that allow accessing orc stripes in Orc file. - * This orc reader basically acts like an ArrowReader iterator that - * iterate over orc stripes. Each stripe will be accessed via an - * ArrowReader. + * Orc Reader that allow accessing orc stripes in Orc file. This orc reader basically acts like an + * ArrowReader iterator that iterate over orc stripes. Each stripe will be accessed via an + * ArrowReader. */ public class OrcReader implements AutoCloseable { private final OrcReaderJniWrapper jniWrapper; private BufferAllocator allocator; - /** - * reference to native reader instance. - */ + /** reference to native reader instance. */ private final long nativeInstanceId; /** * Create an OrcReader that iterate over orc stripes. + * * @param filePath file path to target file, currently only support local file. * @param allocator allocator provided to ArrowReader. * @throws IOException throws exception in case of file not found */ - public OrcReader(String filePath, BufferAllocator allocator) throws IOException, IllegalAccessException { + public OrcReader(String filePath, BufferAllocator allocator) + throws IOException, IllegalAccessException { this.allocator = allocator; this.jniWrapper = OrcReaderJniWrapper.getInstance(); this.nativeInstanceId = jniWrapper.open(filePath); } /** - * Seek to designated row. Invoke NextStripeReader() after seek - * will return stripe reader starting from designated row. + * Seek to designated row. Invoke NextStripeReader() after seek will return stripe reader starting + * from designated row. + * * @param rowNumber the rows number to seek * @return true if seek operation is succeeded */ diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReaderJniWrapper.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReaderJniWrapper.java index ff449c343c4..e66e3270677 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReaderJniWrapper.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReaderJniWrapper.java @@ -19,9 +19,7 @@ import java.io.IOException; -/** - * JNI wrapper for Orc reader. - */ +/** JNI wrapper for Orc reader. */ class OrcReaderJniWrapper { private static volatile OrcReaderJniWrapper INSTANCE; @@ -41,21 +39,24 @@ static OrcReaderJniWrapper getInstance() throws IOException, IllegalAccessExcept /** * Construct a orc file reader over the target file. + * * @param fileName absolute file path of target file - * @return id of the orc reader instance if file opened successfully, - * otherwise return error code * -1. + * @return id of the orc reader instance if file opened successfully, otherwise return error code + * * -1. */ native long open(String fileName); /** * Release resources associated with designated reader instance. + * * @param readerId id of the reader instance. */ native void close(long readerId); /** - * Seek to designated row. Invoke nextStripeReader() after seek - * will return id of stripe reader starting from designated row. + * Seek to designated row. Invoke nextStripeReader() after seek will return id of stripe reader + * starting from designated row. + * * @param readerId id of the reader instance * @param rowNumber the rows number to seek * @return true if seek operation is succeeded @@ -64,6 +65,7 @@ static OrcReaderJniWrapper getInstance() throws IOException, IllegalAccessExcept /** * The number of stripes in the file. + * * @param readerId id of the reader instance * @return number of stripes */ @@ -71,6 +73,7 @@ static OrcReaderJniWrapper getInstance() throws IOException, IllegalAccessExcept /** * Get a stripe level ArrowReader with specified batchSize in each record batch. + * * @param readerId id of the reader instance * @param batchSize the number of rows loaded on each iteration * @return id of the stripe reader instance. diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcRecordBatch.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcRecordBatch.java index a006cacab98..67b62996093 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcRecordBatch.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcRecordBatch.java @@ -20,21 +20,18 @@ import java.util.Arrays; import java.util.List; -/** - * Wrapper for record batch meta and native memory. - */ +/** Wrapper for record batch meta and native memory. */ class OrcRecordBatch { final int length; - /** - * Nodes correspond to the pre-ordered flattened logical schema. - */ + /** Nodes correspond to the pre-ordered flattened logical schema. */ final List nodes; final List buffers; /** * Construct a new instance. + * * @param length number of records included in current batch * @param nodes meta data for each fields * @param buffers buffers for underlying data diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReferenceManager.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReferenceManager.java index fdec337e85d..961608fc60b 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReferenceManager.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReferenceManager.java @@ -18,7 +18,6 @@ package org.apache.arrow.adapter.orc; import java.util.concurrent.atomic.AtomicInteger; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.OwnershipTransferResult; @@ -26,8 +25,8 @@ import org.apache.arrow.util.Preconditions; /** - * A simple reference manager implementation for memory allocated by native code. - * The underlying memory will be released when reference count reach zero. + * A simple reference manager implementation for memory allocated by native code. The underlying + * memory will be released when reference count reach zero. */ public class OrcReferenceManager implements ReferenceManager { private final AtomicInteger bufRefCnt = new AtomicInteger(0); @@ -50,8 +49,8 @@ public boolean release() { @Override public boolean release(int decrement) { - Preconditions.checkState(decrement >= 1, - "ref count decrement should be greater than or equal to 1"); + Preconditions.checkState( + decrement >= 1, "ref count decrement should be greater than or equal to 1"); // decrement the ref count final int refCnt; synchronized (this) { @@ -89,18 +88,21 @@ public ArrowBuf deriveBuffer(ArrowBuf sourceBuffer, long index, long length) { final long derivedBufferAddress = sourceBuffer.memoryAddress() + index; // create new ArrowBuf - final ArrowBuf derivedBuf = new ArrowBuf( + final ArrowBuf derivedBuf = + new ArrowBuf( this, null, length, // length (in bytes) in the underlying memory chunk for this new ArrowBuf - derivedBufferAddress // starting byte address in the underlying memory for this new ArrowBuf, + derivedBufferAddress // starting byte address in the underlying memory for this new + // ArrowBuf, ); return derivedBuf; } @Override - public OwnershipTransferResult transferOwnership(ArrowBuf sourceBuffer, BufferAllocator targetAllocator) { + public OwnershipTransferResult transferOwnership( + ArrowBuf sourceBuffer, BufferAllocator targetAllocator) { throw new UnsupportedOperationException(); } diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcStripeReader.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcStripeReader.java index 484296d92e0..3b60d14ee6f 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcStripeReader.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcStripeReader.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.stream.Collectors; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.ipc.ArrowReader; @@ -33,19 +32,16 @@ import org.apache.arrow.vector.types.pojo.Schema; import org.apache.arrow.vector.util.ByteArrayReadableSeekableByteChannel; -/** - * Orc stripe that load data into ArrowRecordBatch. - */ +/** Orc stripe that load data into ArrowRecordBatch. */ public class OrcStripeReader extends ArrowReader { - /** - * reference to native stripe reader instance. - */ + /** reference to native stripe reader instance. */ private final long nativeInstanceId; /** * Construct a new instance. - * @param nativeInstanceId nativeInstanceId of the stripe reader instance, obtained by - * calling nextStripeReader from OrcReaderJniWrapper + * + * @param nativeInstanceId nativeInstanceId of the stripe reader instance, obtained by calling + * nextStripeReader from OrcReaderJniWrapper * @param allocator memory allocator for accounting. */ OrcStripeReader(long nativeInstanceId, BufferAllocator allocator) { @@ -62,18 +58,20 @@ public boolean loadNextBatch() throws IOException { ArrayList buffers = new ArrayList<>(); for (OrcMemoryJniWrapper buffer : recordBatch.buffers) { - buffers.add(new ArrowBuf( + buffers.add( + new ArrowBuf( new OrcReferenceManager(buffer), null, (int) buffer.getSize(), buffer.getMemoryAddress())); } - loadRecordBatch(new ArrowRecordBatch( + loadRecordBatch( + new ArrowRecordBatch( recordBatch.length, recordBatch.nodes.stream() - .map(buf -> new ArrowFieldNode(buf.getLength(), buf.getNullCount())) - .collect(Collectors.toList()), + .map(buf -> new ArrowFieldNode(buf.getLength(), buf.getNullCount())) + .collect(Collectors.toList()), buffers)); return true; } @@ -83,7 +81,6 @@ public long bytesRead() { return 0; } - @Override protected void closeReadSource() throws IOException { OrcStripeReaderJniWrapper.close(nativeInstanceId); @@ -94,9 +91,8 @@ protected Schema readSchema() throws IOException { byte[] schemaBytes = OrcStripeReaderJniWrapper.getSchema(nativeInstanceId); try (MessageChannelReader schemaReader = - new MessageChannelReader( - new ReadChannel( - new ByteArrayReadableSeekableByteChannel(schemaBytes)), allocator)) { + new MessageChannelReader( + new ReadChannel(new ByteArrayReadableSeekableByteChannel(schemaBytes)), allocator)) { MessageResult result = schemaReader.readNext(); if (result == null) { diff --git a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcStripeReaderJniWrapper.java b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcStripeReaderJniWrapper.java index 1dd96986108..2d68dc45e9a 100644 --- a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcStripeReaderJniWrapper.java +++ b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcStripeReaderJniWrapper.java @@ -17,13 +17,12 @@ package org.apache.arrow.adapter.orc; -/** - * JNI wrapper for orc stripe reader. - */ +/** JNI wrapper for orc stripe reader. */ class OrcStripeReaderJniWrapper { /** * Get the schema of current stripe. + * * @param readerId id of the stripe reader instance. * @return serialized schema. */ @@ -31,14 +30,15 @@ class OrcStripeReaderJniWrapper { /** * Load next record batch. + * * @param readerId id of the stripe reader instance. - * @return loaded record batch, return null when reached - * the end of current stripe. + * @return loaded record batch, return null when reached the end of current stripe. */ static native OrcRecordBatch next(long readerId); /** * Release resources of underlying reader. + * * @param readerId id of the stripe reader instance. */ static native void close(long readerId); diff --git a/java/adapter/orc/src/test/java/org/apache/arrow/adapter/orc/OrcReaderTest.java b/java/adapter/orc/src/test/java/org/apache/arrow/adapter/orc/OrcReaderTest.java index 4153a35a61c..6405c00b286 100644 --- a/java/adapter/orc/src/test/java/org/apache/arrow/adapter/orc/OrcReaderTest.java +++ b/java/adapter/orc/src/test/java/org/apache/arrow/adapter/orc/OrcReaderTest.java @@ -24,8 +24,6 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.util.List; - - import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.IntVector; @@ -45,11 +43,9 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; - public class OrcReaderTest { - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); + @Rule public TemporaryFolder testFolder = new TemporaryFolder(); private static final int MAX_ALLOCATION = 8 * 1024; private static RootAllocator allocator; @@ -64,8 +60,10 @@ public void testOrcJniReader() throws Exception { TypeDescription schema = TypeDescription.fromString("struct"); File testFile = new File(testFolder.getRoot(), "test-orc"); - Writer writer = OrcFile.createWriter(new Path(testFile.getAbsolutePath()), - OrcFile.writerOptions(new Configuration()).setSchema(schema)); + Writer writer = + OrcFile.createWriter( + new Path(testFile.getAbsolutePath()), + OrcFile.writerOptions(new Configuration()).setSchema(schema)); VectorizedRowBatch batch = schema.createRowBatch(); LongColumnVector longColumnVector = (LongColumnVector) batch.cols[0]; BytesColumnVector bytesColumnVector = (BytesColumnVector) batch.cols[1]; diff --git a/java/algorithm/pom.xml b/java/algorithm/pom.xml index 8be2da82438..537dac20aca 100644 --- a/java/algorithm/pom.xml +++ b/java/algorithm/pom.xml @@ -48,6 +48,5 @@ - - + diff --git a/java/bom/pom.xml b/java/bom/pom.xml index f3ecd0cde13..c572eac4467 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -27,7 +27,8 @@ - 2.42.0 + 2.42.0 + 2.30.0 @@ -154,48 +155,6 @@ maven-site-plugin 3.7.1 - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version} - - - - - - - pom.xml - - - ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license - (<configuration|<project) - - - - - - true - 2 - - - true - 2 - - - false - - - - - - spotless-check - - check - - validate - - - @@ -213,4 +172,115 @@ + + + + spotless-jdk11+ + + [11,] + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version.jdk11} + + + + + + + + pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + + + + + + + spotless-jdk8 + + 1.8 + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version.jdk8} + + + + + + + + pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + + + + + + diff --git a/java/c/pom.xml b/java/c/pom.xml index ffd41b62dd6..6711c31ca45 100644 --- a/java/c/pom.xml +++ b/java/c/pom.xml @@ -10,78 +10,78 @@ OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - - arrow-java-root - org.apache.arrow - 16.0.0-SNAPSHOT - - 4.0.0 + 4.0.0 + + org.apache.arrow + arrow-java-root + 16.0.0-SNAPSHOT + - arrow-c-data - Arrow Java C Data Interface - Java implementation of C Data Interface - jar - - ./build - + arrow-c-data + jar + Arrow Java C Data Interface + Java implementation of C Data Interface + + ./build + - - - org.apache.arrow - arrow-vector - compile - ${arrow.vector.classifier} - - - org.apache.arrow - arrow-vector - ${project.version} - test-jar - test - - - org.apache.arrow - arrow-memory-core - compile - - - org.slf4j - slf4j-api - - - org.immutables - value - - - org.apache.arrow - arrow-memory-unsafe - test - - - org.apache.arrow - arrow-format - test - - - com.google.guava - guava - test - - - org.assertj - assertj-core - test - - - - - - ${arrow.c.jni.dist.dir} - - **/*arrow_cdata_jni.* - - - - + + + org.apache.arrow + arrow-vector + ${arrow.vector.classifier} + compile + + + org.apache.arrow + arrow-vector + ${project.version} + test-jar + test + + + org.apache.arrow + arrow-memory-core + compile + + + org.slf4j + slf4j-api + + + org.immutables + value + + + org.apache.arrow + arrow-memory-unsafe + test + + + org.apache.arrow + arrow-format + test + + + com.google.guava + guava + test + + + org.assertj + assertj-core + test + + + + + + ${arrow.c.jni.dist.dir} + + **/*arrow_cdata_jni.* + + + + diff --git a/java/c/src/main/java/module-info.java b/java/c/src/main/java/module-info.java index 0a62c9b9875..48af1bc6b72 100644 --- a/java/c/src/main/java/module-info.java +++ b/java/c/src/main/java/module-info.java @@ -1,19 +1,19 @@ /* * 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. - */ + * 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. + */ open module org.apache.arrow.c { exports org.apache.arrow.c; diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java b/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java index d6479a3ba4c..c99a6f76c3c 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrayExporter.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; - import org.apache.arrow.c.jni.JniWrapper; import org.apache.arrow.c.jni.PrivateData; import org.apache.arrow.memory.ArrowBuf; @@ -33,9 +32,7 @@ import org.apache.arrow.vector.dictionary.DictionaryProvider; import org.apache.arrow.vector.types.pojo.DictionaryEncoding; -/** - * Exporter for {@link ArrowArray}. - */ +/** Exporter for {@link ArrowArray}. */ final class ArrayExporter { private final BufferAllocator allocator; @@ -43,9 +40,7 @@ public ArrayExporter(BufferAllocator allocator) { this.allocator = allocator; } - /** - * Private data structure for exported arrays. - */ + /** Private data structure for exported arrays. */ static class ExportedArrayPrivateData implements PrivateData { ArrowBuf buffers_ptrs; List buffers; diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrayImporter.java b/java/c/src/main/java/org/apache/arrow/c/ArrayImporter.java index 7132887ddee..cc4545ad3c6 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrayImporter.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrayImporter.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.Preconditions; @@ -34,9 +33,7 @@ import org.apache.arrow.vector.ipc.message.ArrowFieldNode; import org.apache.arrow.vector.types.pojo.DictionaryEncoding; -/** - * Importer for {@link ArrowArray}. - */ +/** Importer for {@link ArrowArray}. */ final class ArrayImporter { private static final int MAX_IMPORT_RECURSION_LEVEL = 64; @@ -47,7 +44,8 @@ final class ArrayImporter { private ReferenceCountedArrowArray underlyingAllocation; private int recursionLevel; - ArrayImporter(BufferAllocator allocator, FieldVector vector, DictionaryProvider dictionaryProvider) { + ArrayImporter( + BufferAllocator allocator, FieldVector vector, DictionaryProvider dictionaryProvider) { this.allocator = Preconditions.checkNotNull(allocator); this.vector = Preconditions.checkNotNull(vector); this.dictionaryProvider = dictionaryProvider; @@ -78,7 +76,9 @@ private void importChild(ArrayImporter parent, ArrowArray src) { ArrowArray.Snapshot snapshot = src.snapshot(); checkState(snapshot.release != NULL, "Cannot import released ArrowArray"); recursionLevel = parent.recursionLevel + 1; - checkState(recursionLevel <= MAX_IMPORT_RECURSION_LEVEL, "Recursion level in ArrowArray struct exceeded"); + checkState( + recursionLevel <= MAX_IMPORT_RECURSION_LEVEL, + "Recursion level in ArrowArray struct exceeded"); // Child buffers will keep the entire parent import alive. underlyingAllocation = parent.underlyingAllocation; doImport(snapshot); @@ -86,14 +86,19 @@ private void importChild(ArrayImporter parent, ArrowArray src) { private void doImport(ArrowArray.Snapshot snapshot) { // First import children (required for reconstituting parent array data) - long[] children = NativeUtil.toJavaArray(snapshot.children, checkedCastToInt(snapshot.n_children)); + long[] children = + NativeUtil.toJavaArray(snapshot.children, checkedCastToInt(snapshot.n_children)); if (children != null && children.length > 0) { List childVectors = vector.getChildrenFromFields(); - checkState(children.length == childVectors.size(), "ArrowArray struct has %s children (expected %s)", - children.length, childVectors.size()); + checkState( + children.length == childVectors.size(), + "ArrowArray struct has %s children (expected %s)", + children.length, + childVectors.size()); for (int i = 0; i < children.length; i++) { checkState(children[i] != NULL, "ArrowArray struct has NULL child at position %s", i); - ArrayImporter childImporter = new ArrayImporter(allocator, childVectors.get(i), dictionaryProvider); + ArrayImporter childImporter = + new ArrayImporter(allocator, childVectors.get(i), dictionaryProvider); childImporter.importChild(this, ArrowArray.wrap(children[i])); } } @@ -109,16 +114,18 @@ private void doImport(ArrowArray.Snapshot snapshot) { // reset the dictionary vector to the initial state dictionary.getVector().clear(); - ArrayImporter dictionaryImporter = new ArrayImporter(allocator, dictionary.getVector(), dictionaryProvider); + ArrayImporter dictionaryImporter = + new ArrayImporter(allocator, dictionary.getVector(), dictionaryProvider); dictionaryImporter.importChild(this, ArrowArray.wrap(snapshot.dictionary)); } // Import main data ArrowFieldNode fieldNode = new ArrowFieldNode(snapshot.length, snapshot.null_count); - long[] bufferPointers = NativeUtil.toJavaArray(snapshot.buffers, checkedCastToInt(snapshot.n_buffers)); + long[] bufferPointers = + NativeUtil.toJavaArray(snapshot.buffers, checkedCastToInt(snapshot.n_buffers)); - try (final BufferImportTypeVisitor visitor = new BufferImportTypeVisitor( - allocator, underlyingAllocation, fieldNode, bufferPointers)) { + try (final BufferImportTypeVisitor visitor = + new BufferImportTypeVisitor(allocator, underlyingAllocation, fieldNode, bufferPointers)) { final List buffers; if (bufferPointers == null || bufferPointers.length == 0) { buffers = Collections.emptyList(); @@ -128,7 +135,11 @@ private void doImport(ArrowArray.Snapshot snapshot) { vector.loadFieldBuffers(fieldNode, buffers); } catch (Exception e) { throw new IllegalArgumentException( - "Could not load buffers for field " + vector.getField() + ". error message: " + e.getMessage(), e); + "Could not load buffers for field " + + vector.getField() + + ". error message: " + + e.getMessage(), + e); } } } diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrayStreamExporter.java b/java/c/src/main/java/org/apache/arrow/c/ArrayStreamExporter.java index 2c5ca08e717..2c47287a4cd 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrayStreamExporter.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrayStreamExporter.java @@ -21,16 +21,13 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.nio.charset.StandardCharsets; - import org.apache.arrow.c.jni.JniWrapper; import org.apache.arrow.c.jni.PrivateData; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.ipc.ArrowReader; import org.apache.arrow.vector.types.pojo.Schema; -/** - * Utility to export an {@link ArrowReader} as an ArrowArrayStream. - */ +/** Utility to export an {@link ArrowReader} as an ArrowArrayStream. */ final class ArrayStreamExporter { private final BufferAllocator allocator; @@ -38,9 +35,7 @@ final class ArrayStreamExporter { this.allocator = allocator; } - /** - * Java-side state for the exported stream. - */ + /** Java-side state for the exported stream. */ static class ExportedArrayStreamPrivateData implements PrivateData { final BufferAllocator allocator; final ArrowReader reader; diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrowArray.java b/java/c/src/main/java/org/apache/arrow/c/ArrowArray.java index a538852f47c..c1f301e7f9c 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrowArray.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrowArray.java @@ -22,7 +22,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; - import org.apache.arrow.c.jni.JniWrapper; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; @@ -32,9 +31,9 @@ /** * C Data Interface ArrowArray. - *

- * Represents a wrapper for the following C structure: - * + * + *

Represents a wrapper for the following C structure: + * *

  * struct ArrowArray {
  *     // Array data description
@@ -46,7 +45,7 @@
  *     const void** buffers;
  *     struct ArrowArray** children;
  *     struct ArrowArray* dictionary;
- * 
+ *
  *     // Release callback
  *     void (*release)(struct ArrowArray*);
  *     // Opaque producer-specific data
@@ -60,9 +59,7 @@ public class ArrowArray implements BaseStruct {
 
   private ArrowBuf data;
 
-  /**
-   * Snapshot of the ArrowArray raw data.
-   */
+  /** Snapshot of the ArrowArray raw data. */
   public static class Snapshot {
     public long length;
     public long null_count;
@@ -75,9 +72,7 @@ public static class Snapshot {
     public long release;
     public long private_data;
 
-    /**
-     * Initialize empty ArrowArray snapshot.
-     */
+    /** Initialize empty ArrowArray snapshot. */
     public Snapshot() {
       length = NULL;
       null_count = NULL;
@@ -94,21 +89,22 @@ public Snapshot() {
 
   /**
    * Create ArrowArray from an existing memory address.
-   * 

- * The resulting ArrowArray does not own the memory. - * + * + *

The resulting ArrowArray does not own the memory. + * * @param memoryAddress Memory address to wrap * @return A new ArrowArray instance */ public static ArrowArray wrap(long memoryAddress) { - return new ArrowArray(new ArrowBuf(ReferenceManager.NO_OP, null, ArrowArray.SIZE_OF, memoryAddress)); + return new ArrowArray( + new ArrowBuf(ReferenceManager.NO_OP, null, ArrowArray.SIZE_OF, memoryAddress)); } /** * Create ArrowArray by allocating memory. - *

- * The resulting ArrowArray owns the memory. - * + * + *

The resulting ArrowArray owns the memory. + * * @param allocator Allocator for memory allocations * @return A new ArrowArray instance */ @@ -123,9 +119,7 @@ public static ArrowArray allocateNew(BufferAllocator allocator) { this.data = data; } - /** - * Mark the array as released. - */ + /** Mark the array as released. */ public void markReleased() { directBuffer().putLong(INDEX_RELEASE_CALLBACK, NULL); } @@ -156,12 +150,13 @@ boolean isClosed() { } private ByteBuffer directBuffer() { - return MemoryUtil.directBuffer(memoryAddress(), ArrowArray.SIZE_OF).order(ByteOrder.nativeOrder()); + return MemoryUtil.directBuffer(memoryAddress(), ArrowArray.SIZE_OF) + .order(ByteOrder.nativeOrder()); } /** * Take a snapshot of the ArrowArray raw values. - * + * * @return snapshot */ public Snapshot snapshot() { @@ -180,12 +175,18 @@ public Snapshot snapshot() { return snapshot; } - /** - * Write values from Snapshot to the underlying ArrowArray memory buffer. - */ + /** Write values from Snapshot to the underlying ArrowArray memory buffer. */ public void save(Snapshot snapshot) { - directBuffer().putLong(snapshot.length).putLong(snapshot.null_count).putLong(snapshot.offset) - .putLong(snapshot.n_buffers).putLong(snapshot.n_children).putLong(snapshot.buffers).putLong(snapshot.children) - .putLong(snapshot.dictionary).putLong(snapshot.release).putLong(snapshot.private_data); + directBuffer() + .putLong(snapshot.length) + .putLong(snapshot.null_count) + .putLong(snapshot.offset) + .putLong(snapshot.n_buffers) + .putLong(snapshot.n_children) + .putLong(snapshot.buffers) + .putLong(snapshot.children) + .putLong(snapshot.dictionary) + .putLong(snapshot.release) + .putLong(snapshot.private_data); } } diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrowArrayStream.java b/java/c/src/main/java/org/apache/arrow/c/ArrowArrayStream.java index caf1f2fe965..73064a70732 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrowArrayStream.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrowArrayStream.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; - import org.apache.arrow.c.jni.CDataJniException; import org.apache.arrow.c.jni.JniWrapper; import org.apache.arrow.memory.ArrowBuf; @@ -33,8 +32,8 @@ /** * C Stream Interface ArrowArrayStream. - *

- * Represents a wrapper for the following C structure: + * + *

Represents a wrapper for the following C structure: * *

  * struct ArrowArrayStream {
@@ -52,9 +51,7 @@ public class ArrowArrayStream implements BaseStruct {
 
   private ArrowBuf data;
 
-  /**
-   * Snapshot of the ArrowArrayStream raw data.
-   */
+  /** Snapshot of the ArrowArrayStream raw data. */
   public static class Snapshot {
     public long get_schema;
     public long get_next;
@@ -62,9 +59,7 @@ public static class Snapshot {
     public long release;
     public long private_data;
 
-    /**
-     * Initialize empty ArrowArray snapshot.
-     */
+    /** Initialize empty ArrowArray snapshot. */
     public Snapshot() {
       get_schema = NULL;
       get_next = NULL;
@@ -76,20 +71,21 @@ public Snapshot() {
 
   /**
    * Create ArrowArrayStream from an existing memory address.
-   * 

- * The resulting ArrowArrayStream does not own the memory. + * + *

The resulting ArrowArrayStream does not own the memory. * * @param memoryAddress Memory address to wrap * @return A new ArrowArrayStream instance */ public static ArrowArrayStream wrap(long memoryAddress) { - return new ArrowArrayStream(new ArrowBuf(ReferenceManager.NO_OP, null, ArrowArrayStream.SIZE_OF, memoryAddress)); + return new ArrowArrayStream( + new ArrowBuf(ReferenceManager.NO_OP, null, ArrowArrayStream.SIZE_OF, memoryAddress)); } /** * Create ArrowArrayStream by allocating memory. - *

- * The resulting ArrowArrayStream owns the memory. + * + *

The resulting ArrowArrayStream owns the memory. * * @param allocator Allocator for memory allocations * @return A new ArrowArrayStream instance @@ -105,9 +101,7 @@ public static ArrowArrayStream allocateNew(BufferAllocator allocator) { this.data = data; } - /** - * Mark the array as released. - */ + /** Mark the array as released. */ public void markReleased() { directBuffer().putLong(INDEX_RELEASE_CALLBACK, NULL); } @@ -126,6 +120,7 @@ public void release() { /** * Get the schema of the stream. + * * @param schema The ArrowSchema struct to output to * @throws IOException if the stream returns an error */ @@ -140,6 +135,7 @@ public void getSchema(ArrowSchema schema) throws IOException { /** * Get the next batch in the stream. + * * @param array The ArrowArray struct to output to * @throws IOException if the stream returns an error */ @@ -161,7 +157,8 @@ public void close() { } private ByteBuffer directBuffer() { - return MemoryUtil.directBuffer(memoryAddress(), ArrowArrayStream.SIZE_OF).order(ByteOrder.nativeOrder()); + return MemoryUtil.directBuffer(memoryAddress(), ArrowArrayStream.SIZE_OF) + .order(ByteOrder.nativeOrder()); } /** @@ -180,9 +177,7 @@ public ArrowArrayStream.Snapshot snapshot() { return snapshot; } - /** - * Write values from Snapshot to the underlying ArrowArrayStream memory buffer. - */ + /** Write values from Snapshot to the underlying ArrowArrayStream memory buffer. */ public void save(ArrowArrayStream.Snapshot snapshot) { directBuffer() .putLong(snapshot.get_schema) diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrowArrayStreamReader.java b/java/c/src/main/java/org/apache/arrow/c/ArrowArrayStreamReader.java index b39a3be9b84..024149a8b66 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrowArrayStreamReader.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrowArrayStreamReader.java @@ -24,15 +24,12 @@ import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.dictionary.Dictionary; import org.apache.arrow.vector.ipc.ArrowReader; import org.apache.arrow.vector.types.pojo.Schema; -/** - * An implementation of an {@link ArrowReader} backed by an ArrowArrayStream. - */ +/** An implementation of an {@link ArrowReader} backed by an ArrowArrayStream. */ final class ArrowArrayStreamReader extends ArrowReader { private final ArrowArrayStream ownedStream; private final CDataDictionaryProvider provider; @@ -53,7 +50,8 @@ final class ArrowArrayStreamReader extends ArrowReader { @Override public Map getDictionaryVectors() { - return provider.getDictionaryIds().stream().collect(Collectors.toMap(Function.identity(), provider::lookup)); + return provider.getDictionaryIds().stream() + .collect(Collectors.toMap(Function.identity(), provider::lookup)); } @Override diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java b/java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java index b34ce7d5a52..e8141939a82 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java +++ b/java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java @@ -22,7 +22,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; - import org.apache.arrow.c.jni.JniWrapper; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; @@ -31,9 +30,9 @@ /** * C Data Interface ArrowSchema. - *

- * Represents a wrapper for the following C structure: - * + * + *

Represents a wrapper for the following C structure: + * *

  * struct ArrowSchema {
  *     // Array type description
@@ -44,11 +43,11 @@
  *     int64_t n_children;
  *     struct ArrowSchema** children;
  *     struct ArrowSchema* dictionary;
- *      
+ *
  *     // Release callback
  *     void (*release)(struct ArrowSchema*);
  *     // Opaque producer-specific data
- *     void* private_data; 
+ *     void* private_data;
  * };
  * 
*/ @@ -57,9 +56,7 @@ public class ArrowSchema implements BaseStruct { private ArrowBuf data; - /** - * Snapshot of the ArrowSchema raw data. - */ + /** Snapshot of the ArrowSchema raw data. */ public static class Snapshot { public long format; public long name; @@ -71,9 +68,7 @@ public static class Snapshot { public long release; public long private_data; - /** - * Initialize empty ArrowSchema snapshot. - */ + /** Initialize empty ArrowSchema snapshot. */ public Snapshot() { format = NULL; name = NULL; @@ -89,21 +84,22 @@ public Snapshot() { /** * Create ArrowSchema from an existing memory address. - *

- * The resulting ArrowSchema does not own the memory. - * + * + *

The resulting ArrowSchema does not own the memory. + * * @param memoryAddress Memory address to wrap * @return A new ArrowSchema instance */ public static ArrowSchema wrap(long memoryAddress) { - return new ArrowSchema(new ArrowBuf(ReferenceManager.NO_OP, null, ArrowSchema.SIZE_OF, memoryAddress)); + return new ArrowSchema( + new ArrowBuf(ReferenceManager.NO_OP, null, ArrowSchema.SIZE_OF, memoryAddress)); } /** * Create ArrowSchema by allocating memory. - *

- * The resulting ArrowSchema owns the memory. - * + * + *

The resulting ArrowSchema owns the memory. + * * @param allocator Allocator for memory allocations * @return A new ArrowSchema instance */ @@ -137,12 +133,13 @@ public void close() { } private ByteBuffer directBuffer() { - return MemoryUtil.directBuffer(memoryAddress(), ArrowSchema.SIZE_OF).order(ByteOrder.nativeOrder()); + return MemoryUtil.directBuffer(memoryAddress(), ArrowSchema.SIZE_OF) + .order(ByteOrder.nativeOrder()); } /** * Take a snapshot of the ArrowSchema raw values. - * + * * @return snapshot */ public Snapshot snapshot() { @@ -160,12 +157,17 @@ public Snapshot snapshot() { return snapshot; } - /** - * Write values from Snapshot to the underlying ArrowSchema memory buffer. - */ + /** Write values from Snapshot to the underlying ArrowSchema memory buffer. */ public void save(Snapshot snapshot) { - directBuffer().putLong(snapshot.format).putLong(snapshot.name).putLong(snapshot.metadata).putLong(snapshot.flags) - .putLong(snapshot.n_children).putLong(snapshot.children).putLong(snapshot.dictionary).putLong(snapshot.release) + directBuffer() + .putLong(snapshot.format) + .putLong(snapshot.name) + .putLong(snapshot.metadata) + .putLong(snapshot.flags) + .putLong(snapshot.n_children) + .putLong(snapshot.children) + .putLong(snapshot.dictionary) + .putLong(snapshot.release) .putLong(snapshot.private_data); } } diff --git a/java/c/src/main/java/org/apache/arrow/c/BaseStruct.java b/java/c/src/main/java/org/apache/arrow/c/BaseStruct.java index d90fe817589..139f02b099b 100644 --- a/java/c/src/main/java/org/apache/arrow/c/BaseStruct.java +++ b/java/c/src/main/java/org/apache/arrow/c/BaseStruct.java @@ -17,27 +17,23 @@ package org.apache.arrow.c; -/** - * Base interface for C Data Interface structures. - */ +/** Base interface for C Data Interface structures. */ public interface BaseStruct extends AutoCloseable { /** * Get memory address. - * + * * @return Memory address */ long memoryAddress(); /** * Call the release callback of an ArrowArray. - *

- * This function must not be called for child arrays. + * + *

This function must not be called for child arrays. */ void release(); - /** - * Close to release the main buffer. - */ + /** Close to release the main buffer. */ @Override void close(); } diff --git a/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java b/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java index cd2a464f4fa..70f2ca24357 100644 --- a/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java +++ b/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.AutoCloseables; @@ -55,9 +54,7 @@ import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.util.DataSizeRoundingUtil; -/** - * Import buffers from a C Data Interface struct. - */ +/** Import buffers from a C Data Interface struct. */ class BufferImportTypeVisitor implements ArrowType.ArrowTypeVisitor>, AutoCloseable { private final BufferAllocator allocator; private final ReferenceCountedArrowArray underlyingAllocation; @@ -65,8 +62,11 @@ class BufferImportTypeVisitor implements ArrowType.ArrowTypeVisitor imported; - BufferImportTypeVisitor(BufferAllocator allocator, ReferenceCountedArrowArray underlyingAllocation, - ArrowFieldNode fieldNode, long[] buffers) { + BufferImportTypeVisitor( + BufferAllocator allocator, + ReferenceCountedArrowArray underlyingAllocation, + ArrowFieldNode fieldNode, + long[] buffers) { this.allocator = allocator; this.underlyingAllocation = underlyingAllocation; this.fieldNode = fieldNode; @@ -82,14 +82,18 @@ public void close() throws Exception { @VisibleForTesting ArrowBuf importBuffer(ArrowType type, int index, long capacity) { checkState( - buffers.length > index, - "Expected at least %s buffers for type %s, but found %s", index + 1, type, buffers.length); + buffers.length > index, + "Expected at least %s buffers for type %s, but found %s", + index + 1, + type, + buffers.length); long bufferPtr = buffers[index]; if (bufferPtr == NULL) { // C array may be NULL but only accept that if expected capacity is zero too if (capacity != 0) { - throw new IllegalStateException(String.format("Buffer %s for type %s cannot be null", index, type)); + throw new IllegalStateException( + String.format("Buffer %s for type %s cannot be null", index, type)); } else { // no data in the C array, return an empty buffer return allocator.getEmpty(); @@ -123,18 +127,24 @@ private ArrowBuf importData(ArrowType type, long capacity) { private ArrowBuf maybeImportBitmap(ArrowType type) { checkState( buffers.length > 0, - "Expected at least %s buffers for type %s, but found %s", 1, type, buffers.length); + "Expected at least %s buffers for type %s, but found %s", + 1, + type, + buffers.length); if (buffers[0] == NULL) { return null; } - return importFixedBits(type, 0, /*bitsPerSlot=*/1); + return importFixedBits(type, 0, /*bitsPerSlot=*/ 1); } @Override public List visit(ArrowType.Null type) { checkState( buffers.length == 0, - "Expected %s buffers for type %s, but found %s", 0, type, buffers.length); + "Expected %s buffers for type %s, but found %s", + 0, + type, + buffers.length); return Collections.emptyList(); } @@ -150,7 +160,8 @@ public List visit(ArrowType.List type) { @Override public List visit(ArrowType.LargeList type) { - return Arrays.asList(maybeImportBitmap(type), importOffsets(type, LargeListVector.OFFSET_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importOffsets(type, LargeListVector.OFFSET_WIDTH)); } @Override @@ -164,7 +175,8 @@ public List visit(ArrowType.Union type) { case Sparse: return Collections.singletonList(importFixedBytes(type, 0, UnionVector.TYPE_WIDTH)); case Dense: - return Arrays.asList(importFixedBytes(type, 0, DenseUnionVector.TYPE_WIDTH), + return Arrays.asList( + importFixedBytes(type, 0, DenseUnionVector.TYPE_WIDTH), importFixedBytes(type, 1, DenseUnionVector.OFFSET_WIDTH)); default: throw new UnsupportedOperationException("Importing buffers for union type: " + type); @@ -185,11 +197,14 @@ public List visit(ArrowType.Int type) { public List visit(ArrowType.FloatingPoint type) { switch (type.getPrecision()) { case HALF: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, /*bytesPerSlot=*/2)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, /*bytesPerSlot=*/ 2)); case SINGLE: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, Float4Vector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, Float4Vector.TYPE_WIDTH)); case DOUBLE: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, Float8Vector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, Float8Vector.TYPE_WIDTH)); default: throw new UnsupportedOperationException("Importing buffers for type: " + type); } @@ -202,7 +217,10 @@ public List visit(ArrowType.Utf8 type) { final int end = offsets.getInt(fieldNode.getLength() * (long) VarCharVector.OFFSET_WIDTH); checkState( end >= start, - "Offset buffer for type %s is malformed: start: %s, end: %s", type, start, end); + "Offset buffer for type %s is malformed: start: %s, end: %s", + type, + start, + end); final int len = end - start; offsets.getReferenceManager().retain(); return Arrays.asList(maybeImportBitmap(type), offsets, importData(type, len)); @@ -213,10 +231,14 @@ public List visit(ArrowType.Utf8 type) { public List visit(ArrowType.LargeUtf8 type) { try (ArrowBuf offsets = importOffsets(type, LargeVarCharVector.OFFSET_WIDTH)) { final long start = offsets.getLong(0); - final long end = offsets.getLong(fieldNode.getLength() * (long) LargeVarCharVector.OFFSET_WIDTH); + final long end = + offsets.getLong(fieldNode.getLength() * (long) LargeVarCharVector.OFFSET_WIDTH); checkState( end >= start, - "Offset buffer for type %s is malformed: start: %s, end: %s", type, start, end); + "Offset buffer for type %s is malformed: start: %s, end: %s", + type, + start, + end); final long len = end - start; offsets.getReferenceManager().retain(); return Arrays.asList(maybeImportBitmap(type), offsets, importData(type, len)); @@ -230,7 +252,10 @@ public List visit(ArrowType.Binary type) { final int end = offsets.getInt(fieldNode.getLength() * (long) VarBinaryVector.OFFSET_WIDTH); checkState( end >= start, - "Offset buffer for type %s is malformed: start: %s, end: %s", type, start, end); + "Offset buffer for type %s is malformed: start: %s, end: %s", + type, + start, + end); final int len = end - start; offsets.getReferenceManager().retain(); return Arrays.asList(maybeImportBitmap(type), offsets, importData(type, len)); @@ -242,10 +267,14 @@ public List visit(ArrowType.LargeBinary type) { try (ArrowBuf offsets = importOffsets(type, LargeVarBinaryVector.OFFSET_WIDTH)) { final long start = offsets.getLong(0); // TODO: need better tests to cover the failure when I forget to multiply by offset width - final long end = offsets.getLong(fieldNode.getLength() * (long) LargeVarBinaryVector.OFFSET_WIDTH); + final long end = + offsets.getLong(fieldNode.getLength() * (long) LargeVarBinaryVector.OFFSET_WIDTH); checkState( end >= start, - "Offset buffer for type %s is malformed: start: %s, end: %s", type, start, end); + "Offset buffer for type %s is malformed: start: %s, end: %s", + type, + start, + end); final long len = end - start; offsets.getReferenceManager().retain(); return Arrays.asList(maybeImportBitmap(type), offsets, importData(type, len)); @@ -259,7 +288,7 @@ public List visit(ArrowType.FixedSizeBinary type) { @Override public List visit(ArrowType.Bool type) { - return Arrays.asList(maybeImportBitmap(type), importFixedBits(type, 1, /*bitsPerSlot=*/1)); + return Arrays.asList(maybeImportBitmap(type), importFixedBits(type, 1, /*bitsPerSlot=*/ 1)); } @Override @@ -271,9 +300,11 @@ public List visit(ArrowType.Decimal type) { public List visit(ArrowType.Date type) { switch (type.getUnit()) { case DAY: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, DateDayVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, DateDayVector.TYPE_WIDTH)); case MILLISECOND: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, DateMilliVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, DateMilliVector.TYPE_WIDTH)); default: throw new UnsupportedOperationException("Importing buffers for type: " + type); } @@ -283,13 +314,17 @@ public List visit(ArrowType.Date type) { public List visit(ArrowType.Time type) { switch (type.getUnit()) { case SECOND: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, TimeSecVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, TimeSecVector.TYPE_WIDTH)); case MILLISECOND: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, TimeMilliVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, TimeMilliVector.TYPE_WIDTH)); case MICROSECOND: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, TimeMicroVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, TimeMicroVector.TYPE_WIDTH)); case NANOSECOND: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, TimeNanoVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, TimeNanoVector.TYPE_WIDTH)); default: throw new UnsupportedOperationException("Importing buffers for type: " + type); } @@ -297,18 +332,23 @@ public List visit(ArrowType.Time type) { @Override public List visit(ArrowType.Timestamp type) { - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, TimeStampVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, TimeStampVector.TYPE_WIDTH)); } @Override public List visit(ArrowType.Interval type) { switch (type.getUnit()) { case YEAR_MONTH: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, IntervalYearVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, IntervalYearVector.TYPE_WIDTH)); case DAY_TIME: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, IntervalDayVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, IntervalDayVector.TYPE_WIDTH)); case MONTH_DAY_NANO: - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, IntervalMonthDayNanoVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), + importFixedBytes(type, 1, IntervalMonthDayNanoVector.TYPE_WIDTH)); default: throw new UnsupportedOperationException("Importing buffers for type: " + type); } @@ -316,6 +356,7 @@ public List visit(ArrowType.Interval type) { @Override public List visit(ArrowType.Duration type) { - return Arrays.asList(maybeImportBitmap(type), importFixedBytes(type, 1, DurationVector.TYPE_WIDTH)); + return Arrays.asList( + maybeImportBitmap(type), importFixedBytes(type, 1, DurationVector.TYPE_WIDTH)); } } diff --git a/java/c/src/main/java/org/apache/arrow/c/CDataDictionaryProvider.java b/java/c/src/main/java/org/apache/arrow/c/CDataDictionaryProvider.java index 4a84f11704c..4e520a69b26 100644 --- a/java/c/src/main/java/org/apache/arrow/c/CDataDictionaryProvider.java +++ b/java/c/src/main/java/org/apache/arrow/c/CDataDictionaryProvider.java @@ -20,22 +20,19 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; - import org.apache.arrow.vector.dictionary.Dictionary; import org.apache.arrow.vector.dictionary.DictionaryProvider; /** * A DictionaryProvider that is used in C Data Interface for imports. - *

- * CDataDictionaryProvider is similar to - * {@link DictionaryProvider.MapDictionaryProvider} with a key difference that - * the dictionaries are owned by the provider so it must eventually be closed. - *

- * The typical usage is to create the CDataDictionaryProvider and pass it to - * {@link Data#importField} or {@link Data#importSchema} to allocate empty - * dictionaries based on the information in {@link ArrowSchema}. Then you can - * re-use the same dictionary provider in any function that imports an - * {@link ArrowArray} that has the same schema. + * + *

CDataDictionaryProvider is similar to {@link DictionaryProvider.MapDictionaryProvider} with a + * key difference that the dictionaries are owned by the provider so it must eventually be closed. + * + *

The typical usage is to create the CDataDictionaryProvider and pass it to {@link + * Data#importField} or {@link Data#importSchema} to allocate empty dictionaries based on the + * information in {@link ArrowSchema}. Then you can re-use the same dictionary provider in any + * function that imports an {@link ArrowArray} that has the same schema. */ public class CDataDictionaryProvider implements DictionaryProvider, AutoCloseable { @@ -69,5 +66,4 @@ public void close() { } map.clear(); } - } diff --git a/java/c/src/main/java/org/apache/arrow/c/Data.java b/java/c/src/main/java/org/apache/arrow/c/Data.java index c90ce7604d6..2d2a03b81f9 100644 --- a/java/c/src/main/java/org/apache/arrow/c/Data.java +++ b/java/c/src/main/java/org/apache/arrow/c/Data.java @@ -35,76 +35,78 @@ /** * Functions for working with the C data interface. - *

- * This API is EXPERIMENTAL. Note that currently only 64bit systems are - * supported. + * + *

This API is EXPERIMENTAL. Note that currently only 64bit systems are supported. */ public final class Data { - private Data() { - } + private Data() {} /** * Export Java Field using the C data interface format. - * + * * @param allocator Buffer allocator for allocating C data interface fields - * @param field Field object to export - * @param provider Dictionary provider for dictionary encoded fields (optional) - * @param out C struct where to export the field + * @param field Field object to export + * @param provider Dictionary provider for dictionary encoded fields (optional) + * @param out C struct where to export the field */ - public static void exportField(BufferAllocator allocator, Field field, DictionaryProvider provider, ArrowSchema out) { + public static void exportField( + BufferAllocator allocator, Field field, DictionaryProvider provider, ArrowSchema out) { SchemaExporter exporter = new SchemaExporter(allocator); exporter.export(out, field, provider); } /** * Export Java Schema using the C data interface format. - * + * * @param allocator Buffer allocator for allocating C data interface fields - * @param schema Schema object to export - * @param provider Dictionary provider for dictionary encoded fields (optional) - * @param out C struct where to export the field + * @param schema Schema object to export + * @param provider Dictionary provider for dictionary encoded fields (optional) + * @param out C struct where to export the field */ - public static void exportSchema(BufferAllocator allocator, Schema schema, DictionaryProvider provider, - ArrowSchema out) { + public static void exportSchema( + BufferAllocator allocator, Schema schema, DictionaryProvider provider, ArrowSchema out) { // Convert to a struct field equivalent to the input schema - FieldType fieldType = new FieldType(false, new ArrowType.Struct(), null, schema.getCustomMetadata()); + FieldType fieldType = + new FieldType(false, new ArrowType.Struct(), null, schema.getCustomMetadata()); Field field = new Field("", fieldType, schema.getFields()); exportField(allocator, field, provider, out); } /** * Export Java FieldVector using the C data interface format. - *

- * The resulting ArrowArray struct keeps the array data and buffers alive until - * its release callback is called by the consumer. - * + * + *

The resulting ArrowArray struct keeps the array data and buffers alive until its release + * callback is called by the consumer. + * * @param allocator Buffer allocator for allocating C data interface fields - * @param vector Vector object to export - * @param provider Dictionary provider for dictionary encoded vectors - * (optional) - * @param out C struct where to export the array + * @param vector Vector object to export + * @param provider Dictionary provider for dictionary encoded vectors (optional) + * @param out C struct where to export the array */ - public static void exportVector(BufferAllocator allocator, FieldVector vector, DictionaryProvider provider, - ArrowArray out) { + public static void exportVector( + BufferAllocator allocator, FieldVector vector, DictionaryProvider provider, ArrowArray out) { exportVector(allocator, vector, provider, out, null); } /** * Export Java FieldVector using the C data interface format. - *

- * The resulting ArrowArray struct keeps the array data and buffers alive until - * its release callback is called by the consumer. - * + * + *

The resulting ArrowArray struct keeps the array data and buffers alive until its release + * callback is called by the consumer. + * * @param allocator Buffer allocator for allocating C data interface fields - * @param vector Vector object to export - * @param provider Dictionary provider for dictionary encoded vectors - * (optional) - * @param out C struct where to export the array + * @param vector Vector object to export + * @param provider Dictionary provider for dictionary encoded vectors (optional) + * @param out C struct where to export the array * @param outSchema C struct where to export the array type (optional) */ - public static void exportVector(BufferAllocator allocator, FieldVector vector, DictionaryProvider provider, - ArrowArray out, ArrowSchema outSchema) { + public static void exportVector( + BufferAllocator allocator, + FieldVector vector, + DictionaryProvider provider, + ArrowArray out, + ArrowSchema outSchema) { if (outSchema != null) { exportField(allocator, vector.getField(), provider, outSchema); } @@ -114,97 +116,97 @@ public static void exportVector(BufferAllocator allocator, FieldVector vector, D } /** - * Export the current contents of a Java Table using the C data - * interface format. - *

- * The table is exported as if it were a struct array. The - * resulting ArrowArray struct keeps the record batch data and buffers alive - * until its release callback is called by the consumer. + * Export the current contents of a Java Table using the C data interface format. + * + *

The table is exported as if it were a struct array. The resulting ArrowArray struct keeps + * the record batch data and buffers alive until its release callback is called by the consumer. * * @param allocator Buffer allocator for allocating C data interface fields - * @param table Table to export - * @param out C struct where to export the record batch + * @param table Table to export + * @param out C struct where to export the record batch */ public static void exportTable(BufferAllocator allocator, Table table, ArrowArray out) { exportTable(allocator, table, table.getDictionaryProvider(), out, null); } /** - * Export the current contents of a Java Table using the C data - * interface format. - *

- * The table is exported as if it were a struct array. The - * resulting ArrowArray struct keeps the record batch data and buffers alive - * until its release callback is called by the consumer. + * Export the current contents of a Java Table using the C data interface format. + * + *

The table is exported as if it were a struct array. The resulting ArrowArray struct keeps + * the record batch data and buffers alive until its release callback is called by the consumer. * * @param allocator Buffer allocator for allocating C data interface fields - * @param table Table to export - * @param provider Dictionary provider for dictionary encoded vectors - * (optional) - * @param out C struct where to export the record batch + * @param table Table to export + * @param provider Dictionary provider for dictionary encoded vectors (optional) + * @param out C struct where to export the record batch */ - public static void exportTable(BufferAllocator allocator, Table table, - DictionaryProvider provider, ArrowArray out) { + public static void exportTable( + BufferAllocator allocator, Table table, DictionaryProvider provider, ArrowArray out) { exportTable(allocator, table, provider, out, null); } /** * Export the current contents of a Java Table using the C data interface format. - *

- * The table is exported as if it were a struct array. The - * resulting ArrowArray struct keeps the record batch data and buffers alive - * until its release callback is called by the consumer. + * + *

The table is exported as if it were a struct array. The resulting ArrowArray struct keeps + * the record batch data and buffers alive until its release callback is called by the consumer. * * @param allocator Buffer allocator for allocating C data interface fields - * @param table Table to export - * @param provider Dictionary provider for dictionary encoded vectors - * (optional) - * @param out C struct where to export the record batch + * @param table Table to export + * @param provider Dictionary provider for dictionary encoded vectors (optional) + * @param out C struct where to export the record batch * @param outSchema C struct where to export the record batch schema (optional) */ - public static void exportTable(BufferAllocator allocator, Table table, - DictionaryProvider provider, ArrowArray out, ArrowSchema outSchema) { + public static void exportTable( + BufferAllocator allocator, + Table table, + DictionaryProvider provider, + ArrowArray out, + ArrowSchema outSchema) { try (VectorSchemaRoot root = table.toVectorSchemaRoot()) { exportVectorSchemaRoot(allocator, root, provider, out, outSchema); } } /** - * Export the current contents of a Java VectorSchemaRoot using the C data - * interface format. - *

- * The vector schema root is exported as if it were a struct array. The - * resulting ArrowArray struct keeps the record batch data and buffers alive - * until its release callback is called by the consumer. + * Export the current contents of a Java VectorSchemaRoot using the C data interface format. + * + *

The vector schema root is exported as if it were a struct array. The resulting ArrowArray + * struct keeps the record batch data and buffers alive until its release callback is called by + * the consumer. * * @param allocator Buffer allocator for allocating C data interface fields - * @param vsr Vector schema root to export - * @param provider Dictionary provider for dictionary encoded vectors - * (optional) - * @param out C struct where to export the record batch + * @param vsr Vector schema root to export + * @param provider Dictionary provider for dictionary encoded vectors (optional) + * @param out C struct where to export the record batch */ - public static void exportVectorSchemaRoot(BufferAllocator allocator, VectorSchemaRoot vsr, - DictionaryProvider provider, ArrowArray out) { + public static void exportVectorSchemaRoot( + BufferAllocator allocator, + VectorSchemaRoot vsr, + DictionaryProvider provider, + ArrowArray out) { exportVectorSchemaRoot(allocator, vsr, provider, out, null); } /** - * Export the current contents of a Java VectorSchemaRoot using the C data - * interface format. - *

- * The vector schema root is exported as if it were a struct array. The - * resulting ArrowArray struct keeps the record batch data and buffers alive - * until its release callback is called by the consumer. - * + * Export the current contents of a Java VectorSchemaRoot using the C data interface format. + * + *

The vector schema root is exported as if it were a struct array. The resulting ArrowArray + * struct keeps the record batch data and buffers alive until its release callback is called by + * the consumer. + * * @param allocator Buffer allocator for allocating C data interface fields - * @param vsr Vector schema root to export - * @param provider Dictionary provider for dictionary encoded vectors - * (optional) - * @param out C struct where to export the record batch + * @param vsr Vector schema root to export + * @param provider Dictionary provider for dictionary encoded vectors (optional) + * @param out C struct where to export the record batch * @param outSchema C struct where to export the record batch schema (optional) */ - public static void exportVectorSchemaRoot(BufferAllocator allocator, VectorSchemaRoot vsr, - DictionaryProvider provider, ArrowArray out, ArrowSchema outSchema) { + public static void exportVectorSchemaRoot( + BufferAllocator allocator, + VectorSchemaRoot vsr, + DictionaryProvider provider, + ArrowArray out, + ArrowSchema outSchema) { if (outSchema != null) { exportSchema(allocator, vsr.getSchema(), provider, outSchema); } @@ -220,27 +222,30 @@ public static void exportVectorSchemaRoot(BufferAllocator allocator, VectorSchem /** * Export a reader as an ArrowArrayStream using the C Stream Interface. + * * @param allocator Buffer allocator for allocating C data interface fields * @param reader Reader to export * @param out C struct to export the stream */ - public static void exportArrayStream(BufferAllocator allocator, ArrowReader reader, ArrowArrayStream out) { + public static void exportArrayStream( + BufferAllocator allocator, ArrowReader reader, ArrowArrayStream out) { new ArrayStreamExporter(allocator).export(out, reader); } /** * Import Java Field from the C data interface. - *

- * The given ArrowSchema struct is released (as per the C data interface - * specification), even if this function fails. - * + * + *

The given ArrowSchema struct is released (as per the C data interface specification), even + * if this function fails. + * * @param allocator Buffer allocator for allocating dictionary vectors - * @param schema C data interface struct representing the field [inout] - * @param provider A dictionary provider will be initialized with empty - * dictionary vectors (optional) + * @param schema C data interface struct representing the field [inout] + * @param provider A dictionary provider will be initialized with empty dictionary vectors + * (optional) * @return Imported field object */ - public static Field importField(BufferAllocator allocator, ArrowSchema schema, CDataDictionaryProvider provider) { + public static Field importField( + BufferAllocator allocator, ArrowSchema schema, CDataDictionaryProvider provider) { try { SchemaImporter importer = new SchemaImporter(allocator); return importer.importField(schema, provider); @@ -252,36 +257,41 @@ public static Field importField(BufferAllocator allocator, ArrowSchema schema, C /** * Import Java Schema from the C data interface. - *

- * The given ArrowSchema struct is released (as per the C data interface - * specification), even if this function fails. - * + * + *

The given ArrowSchema struct is released (as per the C data interface specification), even + * if this function fails. + * * @param allocator Buffer allocator for allocating dictionary vectors - * @param schema C data interface struct representing the field - * @param provider A dictionary provider will be initialized with empty - * dictionary vectors (optional) + * @param schema C data interface struct representing the field + * @param provider A dictionary provider will be initialized with empty dictionary vectors + * (optional) * @return Imported schema object */ - public static Schema importSchema(BufferAllocator allocator, ArrowSchema schema, CDataDictionaryProvider provider) { + public static Schema importSchema( + BufferAllocator allocator, ArrowSchema schema, CDataDictionaryProvider provider) { Field structField = importField(allocator, schema, provider); if (structField.getType().getTypeID() != ArrowTypeID.Struct) { - throw new IllegalArgumentException("Cannot import schema: ArrowSchema describes non-struct type"); + throw new IllegalArgumentException( + "Cannot import schema: ArrowSchema describes non-struct type"); } return new Schema(structField.getChildren(), structField.getMetadata()); } /** * Import Java vector from the C data interface. - *

- * The ArrowArray struct has its contents moved (as per the C data interface - * specification) to a private object held alive by the resulting array. - * + * + *

The ArrowArray struct has its contents moved (as per the C data interface specification) to + * a private object held alive by the resulting array. + * * @param allocator Buffer allocator - * @param array C data interface struct holding the array data - * @param vector Imported vector object [out] - * @param provider Dictionary provider to load dictionary vectors to (optional) + * @param array C data interface struct holding the array data + * @param vector Imported vector object [out] + * @param provider Dictionary provider to load dictionary vectors to (optional) */ - public static void importIntoVector(BufferAllocator allocator, ArrowArray array, FieldVector vector, + public static void importIntoVector( + BufferAllocator allocator, + ArrowArray array, + FieldVector vector, DictionaryProvider provider) { ArrayImporter importer = new ArrayImporter(allocator, vector, provider); importer.importArray(array); @@ -289,18 +299,21 @@ public static void importIntoVector(BufferAllocator allocator, ArrowArray array, /** * Import Java vector and its type from the C data interface. - *

- * The ArrowArray struct has its contents moved (as per the C data interface - * specification) to a private object held alive by the resulting vector. The - * ArrowSchema struct is released, even if this function fails. - * + * + *

The ArrowArray struct has its contents moved (as per the C data interface specification) to + * a private object held alive by the resulting vector. The ArrowSchema struct is released, even + * if this function fails. + * * @param allocator Buffer allocator for allocating the output FieldVector - * @param array C data interface struct holding the array data - * @param schema C data interface struct holding the array type - * @param provider Dictionary provider to load dictionary vectors to (optional) + * @param array C data interface struct holding the array data + * @param schema C data interface struct holding the array type + * @param provider Dictionary provider to load dictionary vectors to (optional) * @return Imported vector object */ - public static FieldVector importVector(BufferAllocator allocator, ArrowArray array, ArrowSchema schema, + public static FieldVector importVector( + BufferAllocator allocator, + ArrowArray array, + ArrowSchema schema, CDataDictionaryProvider provider) { Field field = importField(allocator, schema, provider); FieldVector vector = field.createVector(allocator); @@ -310,20 +323,22 @@ public static FieldVector importVector(BufferAllocator allocator, ArrowArray arr /** * Import record batch from the C data interface into vector schema root. - * - * The ArrowArray struct has its contents moved (as per the C data interface - * specification) to a private object held alive by the resulting vector schema - * root. - * - * The schema of the vector schema root must match the input array (undefined - * behavior otherwise). - * + * + *

The ArrowArray struct has its contents moved (as per the C data interface specification) to + * a private object held alive by the resulting vector schema root. + * + *

The schema of the vector schema root must match the input array (undefined behavior + * otherwise). + * * @param allocator Buffer allocator - * @param array C data interface struct holding the record batch data - * @param root vector schema root to load into - * @param provider Dictionary provider to load dictionary vectors to (optional) + * @param array C data interface struct holding the record batch data + * @param root vector schema root to load into + * @param provider Dictionary provider to load dictionary vectors to (optional) */ - public static void importIntoVectorSchemaRoot(BufferAllocator allocator, ArrowArray array, VectorSchemaRoot root, + public static void importIntoVectorSchemaRoot( + BufferAllocator allocator, + ArrowArray array, + VectorSchemaRoot root, DictionaryProvider provider) { try (StructVector structVector = StructVector.emptyWithDuplicates("", allocator)) { structVector.initializeChildrenFromFields(root.getSchema().getFields()); @@ -338,43 +353,46 @@ public static void importIntoVectorSchemaRoot(BufferAllocator allocator, ArrowAr /** * Import Java vector schema root from a C data interface Schema. - * - * The type represented by the ArrowSchema struct must be a struct type array. - * - * The ArrowSchema struct is released, even if this function fails. - * + * + *

The type represented by the ArrowSchema struct must be a struct type array. + * + *

The ArrowSchema struct is released, even if this function fails. + * * @param allocator Buffer allocator for allocating the output VectorSchemaRoot - * @param schema C data interface struct holding the record batch schema - * @param provider Dictionary provider to load dictionary vectors to (optional) + * @param schema C data interface struct holding the record batch schema + * @param provider Dictionary provider to load dictionary vectors to (optional) * @return Imported vector schema root */ - public static VectorSchemaRoot importVectorSchemaRoot(BufferAllocator allocator, ArrowSchema schema, - CDataDictionaryProvider provider) { + public static VectorSchemaRoot importVectorSchemaRoot( + BufferAllocator allocator, ArrowSchema schema, CDataDictionaryProvider provider) { return importVectorSchemaRoot(allocator, null, schema, provider); } /** * Import Java vector schema root from the C data interface. - * - * The type represented by the ArrowSchema struct must be a struct type array. - * - * The ArrowArray struct has its contents moved (as per the C data interface - * specification) to a private object held alive by the resulting record batch. - * The ArrowSchema struct is released, even if this function fails. - * - * Prefer {@link #importIntoVectorSchemaRoot} for loading array data while - * reusing the same vector schema root. - * + * + *

The type represented by the ArrowSchema struct must be a struct type array. + * + *

The ArrowArray struct has its contents moved (as per the C data interface specification) to + * a private object held alive by the resulting record batch. The ArrowSchema struct is released, + * even if this function fails. + * + *

Prefer {@link #importIntoVectorSchemaRoot} for loading array data while reusing the same + * vector schema root. + * * @param allocator Buffer allocator for allocating the output VectorSchemaRoot - * @param array C data interface struct holding the record batch data - * (optional) - * @param schema C data interface struct holding the record batch schema - * @param provider Dictionary provider to load dictionary vectors to (optional) + * @param array C data interface struct holding the record batch data (optional) + * @param schema C data interface struct holding the record batch schema + * @param provider Dictionary provider to load dictionary vectors to (optional) * @return Imported vector schema root */ - public static VectorSchemaRoot importVectorSchemaRoot(BufferAllocator allocator, ArrowArray array, ArrowSchema schema, + public static VectorSchemaRoot importVectorSchemaRoot( + BufferAllocator allocator, + ArrowArray array, + ArrowSchema schema, CDataDictionaryProvider provider) { - VectorSchemaRoot vsr = VectorSchemaRoot.create(importSchema(allocator, schema, provider), allocator); + VectorSchemaRoot vsr = + VectorSchemaRoot.create(importSchema(allocator, schema, provider), allocator); if (array != null) { importIntoVectorSchemaRoot(allocator, array, vsr, provider); } @@ -383,6 +401,7 @@ public static VectorSchemaRoot importVectorSchemaRoot(BufferAllocator allocator, /** * Import an ArrowArrayStream as an {@link ArrowReader}. + * * @param allocator Buffer allocator for allocating the output data. * @param stream C stream interface struct to import. * @return Imported reader diff --git a/java/c/src/main/java/org/apache/arrow/c/Flags.java b/java/c/src/main/java/org/apache/arrow/c/Flags.java index 744b4695ac3..ff52e2a0eaa 100644 --- a/java/c/src/main/java/org/apache/arrow/c/Flags.java +++ b/java/c/src/main/java/org/apache/arrow/c/Flags.java @@ -21,16 +21,13 @@ import org.apache.arrow.vector.types.pojo.ArrowType.ArrowTypeID; import org.apache.arrow.vector.types.pojo.Field; -/** - * Flags as defined in the C data interface specification. - */ +/** Flags as defined in the C data interface specification. */ final class Flags { static final int ARROW_FLAG_DICTIONARY_ORDERED = 1; static final int ARROW_FLAG_NULLABLE = 2; static final int ARROW_FLAG_MAP_KEYS_SORTED = 4; - private Flags() { - } + private Flags() {} static long forField(Field field) { long flags = 0L; diff --git a/java/c/src/main/java/org/apache/arrow/c/Format.java b/java/c/src/main/java/org/apache/arrow/c/Format.java index 2875e46f749..e462cb3c725 100644 --- a/java/c/src/main/java/org/apache/arrow/c/Format.java +++ b/java/c/src/main/java/org/apache/arrow/c/Format.java @@ -19,7 +19,6 @@ import java.util.Arrays; import java.util.stream.Collectors; - import org.apache.arrow.util.Preconditions; import org.apache.arrow.vector.types.DateUnit; import org.apache.arrow.vector.types.FloatingPointPrecision; @@ -30,13 +29,11 @@ import org.apache.arrow.vector.types.pojo.ArrowType.ExtensionType; /** - * Conversion between {@link ArrowType} and string formats, as per C data - * interface specification. + * Conversion between {@link ArrowType} and string formats, as per C data interface specification. */ final class Format { - private Format() { - } + private Format() {} static String asString(ArrowType arrowType) { if (arrowType instanceof ExtensionType) { @@ -49,102 +46,112 @@ static String asString(ArrowType arrowType) { return "z"; case Bool: return "b"; - case Date: { - ArrowType.Date type = (ArrowType.Date) arrowType; - switch (type.getUnit()) { - case DAY: - return "tdD"; - case MILLISECOND: - return "tdm"; - default: - throw new UnsupportedOperationException( - String.format("Date type with unit %s is unsupported", type.getUnit())); + case Date: + { + ArrowType.Date type = (ArrowType.Date) arrowType; + switch (type.getUnit()) { + case DAY: + return "tdD"; + case MILLISECOND: + return "tdm"; + default: + throw new UnsupportedOperationException( + String.format("Date type with unit %s is unsupported", type.getUnit())); + } } - } - case Decimal: { - ArrowType.Decimal type = (ArrowType.Decimal) arrowType; - if (type.getBitWidth() == 128) { - return String.format("d:%d,%d", type.getPrecision(), type.getScale()); + case Decimal: + { + ArrowType.Decimal type = (ArrowType.Decimal) arrowType; + if (type.getBitWidth() == 128) { + return String.format("d:%d,%d", type.getPrecision(), type.getScale()); + } + return String.format( + "d:%d,%d,%d", type.getPrecision(), type.getScale(), type.getBitWidth()); } - return String.format("d:%d,%d,%d", type.getPrecision(), type.getScale(), type.getBitWidth()); - } - case Duration: { - ArrowType.Duration type = (ArrowType.Duration) arrowType; - switch (type.getUnit()) { - case SECOND: - return "tDs"; - case MILLISECOND: - return "tDm"; - case MICROSECOND: - return "tDu"; - case NANOSECOND: - return "tDn"; - default: - throw new UnsupportedOperationException( - String.format("Duration type with unit %s is unsupported", type.getUnit())); + case Duration: + { + ArrowType.Duration type = (ArrowType.Duration) arrowType; + switch (type.getUnit()) { + case SECOND: + return "tDs"; + case MILLISECOND: + return "tDm"; + case MICROSECOND: + return "tDu"; + case NANOSECOND: + return "tDn"; + default: + throw new UnsupportedOperationException( + String.format("Duration type with unit %s is unsupported", type.getUnit())); + } } - } - case FixedSizeBinary: { - ArrowType.FixedSizeBinary type = (ArrowType.FixedSizeBinary) arrowType; - return String.format("w:%d", type.getByteWidth()); - } - case FixedSizeList: { - ArrowType.FixedSizeList type = (ArrowType.FixedSizeList) arrowType; - return String.format("+w:%d", type.getListSize()); - } - case FloatingPoint: { - ArrowType.FloatingPoint type = (ArrowType.FloatingPoint) arrowType; - switch (type.getPrecision()) { - case HALF: - return "e"; - case SINGLE: - return "f"; - case DOUBLE: - return "g"; - default: - throw new UnsupportedOperationException( - String.format("FloatingPoint type with precision %s is unsupported", type.getPrecision())); + case FixedSizeBinary: + { + ArrowType.FixedSizeBinary type = (ArrowType.FixedSizeBinary) arrowType; + return String.format("w:%d", type.getByteWidth()); } - } - case Int: { - String format; - ArrowType.Int type = (ArrowType.Int) arrowType; - switch (type.getBitWidth()) { - case Byte.SIZE: - format = "C"; - break; - case Short.SIZE: - format = "S"; - break; - case Integer.SIZE: - format = "I"; - break; - case Long.SIZE: - format = "L"; - break; - default: - throw new UnsupportedOperationException( - String.format("Int type with bitwidth %d is unsupported", type.getBitWidth())); + case FixedSizeList: + { + ArrowType.FixedSizeList type = (ArrowType.FixedSizeList) arrowType; + return String.format("+w:%d", type.getListSize()); } - if (type.getIsSigned()) { - format = format.toLowerCase(); + case FloatingPoint: + { + ArrowType.FloatingPoint type = (ArrowType.FloatingPoint) arrowType; + switch (type.getPrecision()) { + case HALF: + return "e"; + case SINGLE: + return "f"; + case DOUBLE: + return "g"; + default: + throw new UnsupportedOperationException( + String.format( + "FloatingPoint type with precision %s is unsupported", type.getPrecision())); + } } - return format; - } - case Interval: { - ArrowType.Interval type = (ArrowType.Interval) arrowType; - switch (type.getUnit()) { - case DAY_TIME: - return "tiD"; - case YEAR_MONTH: - return "tiM"; - case MONTH_DAY_NANO: - return "tin"; - default: - throw new UnsupportedOperationException( - String.format("Interval type with unit %s is unsupported", type.getUnit())); + case Int: + { + String format; + ArrowType.Int type = (ArrowType.Int) arrowType; + switch (type.getBitWidth()) { + case Byte.SIZE: + format = "C"; + break; + case Short.SIZE: + format = "S"; + break; + case Integer.SIZE: + format = "I"; + break; + case Long.SIZE: + format = "L"; + break; + default: + throw new UnsupportedOperationException( + String.format("Int type with bitwidth %d is unsupported", type.getBitWidth())); + } + if (type.getIsSigned()) { + format = format.toLowerCase(); + } + return format; + } + case Interval: + { + ArrowType.Interval type = (ArrowType.Interval) arrowType; + switch (type.getUnit()) { + case DAY_TIME: + return "tiD"; + case YEAR_MONTH: + return "tiM"; + case MONTH_DAY_NANO: + return "tin"; + default: + throw new UnsupportedOperationException( + String.format("Interval type with unit %s is unsupported", type.getUnit())); + } } - } case LargeBinary: return "Z"; case LargeList: @@ -159,47 +166,54 @@ static String asString(ArrowType arrowType) { return "n"; case Struct: return "+s"; - case Time: { - ArrowType.Time type = (ArrowType.Time) arrowType; - if (type.getUnit() == TimeUnit.SECOND && type.getBitWidth() == 32) { - return "tts"; - } else if (type.getUnit() == TimeUnit.MILLISECOND && type.getBitWidth() == 32) { - return "ttm"; - } else if (type.getUnit() == TimeUnit.MICROSECOND && type.getBitWidth() == 64) { - return "ttu"; - } else if (type.getUnit() == TimeUnit.NANOSECOND && type.getBitWidth() == 64) { - return "ttn"; - } else { - throw new UnsupportedOperationException(String.format("Time type with unit %s and bitwidth %d is unsupported", - type.getUnit(), type.getBitWidth())); - } - } - case Timestamp: { - String format; - ArrowType.Timestamp type = (ArrowType.Timestamp) arrowType; - switch (type.getUnit()) { - case SECOND: - format = "tss"; - break; - case MILLISECOND: - format = "tsm"; - break; - case MICROSECOND: - format = "tsu"; - break; - case NANOSECOND: - format = "tsn"; - break; - default: + case Time: + { + ArrowType.Time type = (ArrowType.Time) arrowType; + if (type.getUnit() == TimeUnit.SECOND && type.getBitWidth() == 32) { + return "tts"; + } else if (type.getUnit() == TimeUnit.MILLISECOND && type.getBitWidth() == 32) { + return "ttm"; + } else if (type.getUnit() == TimeUnit.MICROSECOND && type.getBitWidth() == 64) { + return "ttu"; + } else if (type.getUnit() == TimeUnit.NANOSECOND && type.getBitWidth() == 64) { + return "ttn"; + } else { throw new UnsupportedOperationException( - String.format("Timestamp type with unit %s is unsupported", type.getUnit())); + String.format( + "Time type with unit %s and bitwidth %d is unsupported", + type.getUnit(), type.getBitWidth())); + } + } + case Timestamp: + { + String format; + ArrowType.Timestamp type = (ArrowType.Timestamp) arrowType; + switch (type.getUnit()) { + case SECOND: + format = "tss"; + break; + case MILLISECOND: + format = "tsm"; + break; + case MICROSECOND: + format = "tsu"; + break; + case NANOSECOND: + format = "tsn"; + break; + default: + throw new UnsupportedOperationException( + String.format("Timestamp type with unit %s is unsupported", type.getUnit())); + } + String timezone = type.getTimezone(); + return String.format("%s:%s", format, timezone == null ? "" : timezone); } - String timezone = type.getTimezone(); - return String.format("%s:%s", format, timezone == null ? "" : timezone); - } case Union: ArrowType.Union type = (ArrowType.Union) arrowType; - String typeIDs = Arrays.stream(type.getTypeIds()).mapToObj(String::valueOf).collect(Collectors.joining(",")); + String typeIDs = + Arrays.stream(type.getTypeIds()) + .mapToObj(String::valueOf) + .collect(Collectors.joining(",")); switch (type.getMode()) { case Dense: return String.format("+ud:%s", typeIDs); @@ -214,7 +228,8 @@ static String asString(ArrowType arrowType) { case NONE: throw new IllegalArgumentException("Arrow type ID is NONE"); default: - throw new UnsupportedOperationException(String.format("Unknown type id %s", arrowType.getTypeID())); + throw new UnsupportedOperationException( + String.format("Unknown type id %s", arrowType.getTypeID())); } } @@ -295,21 +310,24 @@ static ArrowType asType(String format, long flags) if (parts.length == 2) { return parseComplexFormat(parts[0], parts[1]); } - throw new UnsupportedOperationException(String.format("Format %s is not supported", format)); + throw new UnsupportedOperationException( + String.format("Format %s is not supported", format)); } } private static ArrowType parseComplexFormat(String format, String payload) throws NumberFormatException, UnsupportedOperationException, IllegalStateException { switch (format) { - case "d": { - int[] parts = payloadToIntArray(payload); - Preconditions.checkState(parts.length == 2 || parts.length == 3, "Format %s:%s is illegal", format, payload); - int precision = parts[0]; - int scale = parts[1]; - Integer bitWidth = (parts.length == 3) ? parts[2] : null; - return ArrowType.Decimal.createDecimal(precision, scale, bitWidth); - } + case "d": + { + int[] parts = payloadToIntArray(payload); + Preconditions.checkState( + parts.length == 2 || parts.length == 3, "Format %s:%s is illegal", format, payload); + int precision = parts[0]; + int scale = parts[1]; + Integer bitWidth = (parts.length == 3) ? parts[2] : null; + return ArrowType.Decimal.createDecimal(precision, scale, bitWidth); + } case "w": return new ArrowType.FixedSizeBinary(Integer.parseInt(payload)); case "+w": @@ -327,7 +345,8 @@ private static ArrowType parseComplexFormat(String format, String payload) case "tsn": return new ArrowType.Timestamp(TimeUnit.NANOSECOND, payloadToTimezone(payload)); default: - throw new UnsupportedOperationException(String.format("Format %s:%s is not supported", format, payload)); + throw new UnsupportedOperationException( + String.format("Format %s:%s is not supported", format, payload)); } } diff --git a/java/c/src/main/java/org/apache/arrow/c/Metadata.java b/java/c/src/main/java/org/apache/arrow/c/Metadata.java index b81b24fe4ce..d378ca315eb 100644 --- a/java/c/src/main/java/org/apache/arrow/c/Metadata.java +++ b/java/c/src/main/java/org/apache/arrow/c/Metadata.java @@ -27,18 +27,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.util.MemoryUtil; -/** - * Encode and decode metadata. - */ +/** Encode and decode metadata. */ final class Metadata { - private Metadata() { - } + private Metadata() {} static ArrowBuf encode(BufferAllocator allocator, Map metadata) { if (metadata == null || metadata.size() == 0) { @@ -57,7 +53,8 @@ static ArrowBuf encode(BufferAllocator allocator, Map metadata) } ArrowBuf result = allocator.buffer(totalSize); - ByteBuffer writer = MemoryUtil.directBuffer(result.memoryAddress(), totalSize).order(ByteOrder.nativeOrder()); + ByteBuffer writer = + MemoryUtil.directBuffer(result.memoryAddress(), totalSize).order(ByteOrder.nativeOrder()); writer.putInt(metadata.size()); for (byte[] buffer : buffers) { writer.putInt(buffer.length); @@ -71,7 +68,8 @@ static Map decode(long bufferAddress) { return null; } - ByteBuffer reader = MemoryUtil.directBuffer(bufferAddress, Integer.MAX_VALUE).order(ByteOrder.nativeOrder()); + ByteBuffer reader = + MemoryUtil.directBuffer(bufferAddress, Integer.MAX_VALUE).order(ByteOrder.nativeOrder()); int size = reader.getInt(); checkState(size >= 0, "Metadata size must not be negative"); diff --git a/java/c/src/main/java/org/apache/arrow/c/NativeUtil.java b/java/c/src/main/java/org/apache/arrow/c/NativeUtil.java index ba65fd80c41..ebbd736c8c0 100644 --- a/java/c/src/main/java/org/apache/arrow/c/NativeUtil.java +++ b/java/c/src/main/java/org/apache/arrow/c/NativeUtil.java @@ -21,24 +21,20 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.util.MemoryUtil; -/** - * Utility functions for working with native memory. - */ +/** Utility functions for working with native memory. */ public final class NativeUtil { public static final byte NULL = 0; static final int MAX_STRING_LENGTH = Short.MAX_VALUE; - private NativeUtil() { - } + private NativeUtil() {} /** * Convert a pointer to a null terminated string into a Java String. - * + * * @param cstringPtr pointer to C string * @return Converted string */ @@ -46,7 +42,8 @@ public static String toJavaString(long cstringPtr) { if (cstringPtr == NULL) { return null; } - ByteBuffer reader = MemoryUtil.directBuffer(cstringPtr, MAX_STRING_LENGTH).order(ByteOrder.nativeOrder()); + ByteBuffer reader = + MemoryUtil.directBuffer(cstringPtr, MAX_STRING_LENGTH).order(ByteOrder.nativeOrder()); int length = 0; while (reader.get() != NULL) { @@ -60,9 +57,9 @@ public static String toJavaString(long cstringPtr) { /** * Convert a native array pointer (void**) to Java array of pointers. - * + * * @param arrayPtr Array pointer - * @param size Array size + * @param size Array size * @return Array of pointer values as longs */ public static long[] toJavaArray(long arrayPtr, int size) { @@ -74,7 +71,8 @@ public static long[] toJavaArray(long arrayPtr, int size) { } long[] result = new long[size]; - ByteBuffer reader = MemoryUtil.directBuffer(arrayPtr, Long.BYTES * size).order(ByteOrder.nativeOrder()); + ByteBuffer reader = + MemoryUtil.directBuffer(arrayPtr, Long.BYTES * size).order(ByteOrder.nativeOrder()); for (int i = 0; i < size; i++) { result[i] = reader.getLong(); } @@ -83,9 +81,9 @@ public static long[] toJavaArray(long arrayPtr, int size) { /** * Convert Java string to a null terminated string. - * + * * @param allocator Buffer allocator for allocating the native string - * @param string Input String to convert + * @param string Input String to convert * @return Buffer with a null terminated string or null if the input is null */ public static ArrowBuf toNativeString(BufferAllocator allocator, String string) { @@ -102,7 +100,7 @@ public static ArrowBuf toNativeString(BufferAllocator allocator, String string) /** * Close a buffer if it's not null. - * + * * @param buf Buffer to close */ public static void closeBuffer(ArrowBuf buf) { @@ -113,7 +111,7 @@ public static void closeBuffer(ArrowBuf buf) { /** * Get the address of a buffer or {@value #NULL} if the input buffer is null. - * + * * @param buf Buffer to get the address of * @return Memory address or {@value #NULL} */ @@ -125,9 +123,8 @@ public static long addressOrNull(ArrowBuf buf) { } /** - * Get the address of a C Data Interface struct or {@value #NULL} if the input - * struct is null. - * + * Get the address of a C Data Interface struct or {@value #NULL} if the input struct is null. + * * @param struct C Data Interface struct to get the address of * @return Memory address or {@value #NULL} */ @@ -137,5 +134,4 @@ public static long addressOrNull(BaseStruct struct) { } return struct.memoryAddress(); } - } diff --git a/java/c/src/main/java/org/apache/arrow/c/ReferenceCountedArrowArray.java b/java/c/src/main/java/org/apache/arrow/c/ReferenceCountedArrowArray.java index f09f14817b6..9a14543801c 100644 --- a/java/c/src/main/java/org/apache/arrow/c/ReferenceCountedArrowArray.java +++ b/java/c/src/main/java/org/apache/arrow/c/ReferenceCountedArrowArray.java @@ -18,7 +18,6 @@ package org.apache.arrow.c; import java.util.concurrent.atomic.AtomicInteger; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.ForeignAllocation; @@ -26,10 +25,11 @@ /** * The owner of an imported C Data Interface array. * - *

There is a fundamental mismatch here between memory allocation schemes: AllocationManager represents a single - * allocation (= a single address and length). But an ArrowArray combines multiple allocations behind a single - * deallocation callback. This class bridges the two by tracking a reference count, so that the single callback - * can be managed by multiple {@link ForeignAllocation} instances. + *

There is a fundamental mismatch here between memory allocation schemes: AllocationManager + * represents a single allocation (= a single address and length). But an ArrowArray combines + * multiple allocations behind a single deallocation callback. This class bridges the two by + * tracking a reference count, so that the single callback can be managed by multiple {@link + * ForeignAllocation} instances. */ final class ReferenceCountedArrowArray { private final ArrowArray array; @@ -57,18 +57,21 @@ void release() { } /** - * Create an ArrowBuf wrapping a buffer from this ArrowArray associated with the given BufferAllocator. + * Create an ArrowBuf wrapping a buffer from this ArrowArray associated with the given + * BufferAllocator. * - *

This method is "unsafe" because there is no validation of the given capacity or address. If the returned - * buffer is not freed, a memory leak will occur. + *

This method is "unsafe" because there is no validation of the given capacity or address. If + * the returned buffer is not freed, a memory leak will occur. */ - ArrowBuf unsafeAssociateAllocation(BufferAllocator trackingAllocator, long capacity, long memoryAddress) { + ArrowBuf unsafeAssociateAllocation( + BufferAllocator trackingAllocator, long capacity, long memoryAddress) { retain(); - return trackingAllocator.wrapForeignAllocation(new ForeignAllocation(capacity, memoryAddress) { - @Override - protected void release0() { - ReferenceCountedArrowArray.this.release(); - } - }); + return trackingAllocator.wrapForeignAllocation( + new ForeignAllocation(capacity, memoryAddress) { + @Override + protected void release0() { + ReferenceCountedArrowArray.this.release(); + } + }); } } diff --git a/java/c/src/main/java/org/apache/arrow/c/SchemaExporter.java b/java/c/src/main/java/org/apache/arrow/c/SchemaExporter.java index 04d41a4e4f9..36c9e4eab55 100644 --- a/java/c/src/main/java/org/apache/arrow/c/SchemaExporter.java +++ b/java/c/src/main/java/org/apache/arrow/c/SchemaExporter.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; - import org.apache.arrow.c.jni.JniWrapper; import org.apache.arrow.c.jni.PrivateData; import org.apache.arrow.memory.ArrowBuf; @@ -33,9 +32,7 @@ import org.apache.arrow.vector.types.pojo.DictionaryEncoding; import org.apache.arrow.vector.types.pojo.Field; -/** - * Exporter for {@link ArrowSchema}. - */ +/** Exporter for {@link ArrowSchema}. */ final class SchemaExporter { private final BufferAllocator allocator; @@ -43,9 +40,7 @@ public SchemaExporter(BufferAllocator allocator) { this.allocator = allocator; } - /** - * Private data structure for exported schemas. - */ + /** Private data structure for exported schemas. */ static class ExportedSchemaPrivateData implements PrivateData { ArrowBuf format; ArrowBuf name; diff --git a/java/c/src/main/java/org/apache/arrow/c/SchemaImporter.java b/java/c/src/main/java/org/apache/arrow/c/SchemaImporter.java index 09a6afafa0a..e66d6fffdad 100644 --- a/java/c/src/main/java/org/apache/arrow/c/SchemaImporter.java +++ b/java/c/src/main/java/org/apache/arrow/c/SchemaImporter.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.dictionary.Dictionary; import org.apache.arrow.vector.types.pojo.ArrowType; @@ -37,9 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Importer for {@link ArrowSchema}. - */ +/** Importer for {@link ArrowSchema}. */ final class SchemaImporter { private static final Logger logger = LoggerFactory.getLogger(SchemaImporter.class); @@ -56,8 +53,11 @@ Field importField(ArrowSchema schema, CDataDictionaryProvider provider) { return importField(schema, provider, 0); } - private Field importField(ArrowSchema schema, CDataDictionaryProvider provider, int recursionLevel) { - checkState(recursionLevel <= MAX_IMPORT_RECURSION_LEVEL, "Recursion level in ArrowSchema struct exceeded"); + private Field importField( + ArrowSchema schema, CDataDictionaryProvider provider, int recursionLevel) { + checkState( + recursionLevel <= MAX_IMPORT_RECURSION_LEVEL, + "Recursion level in ArrowSchema struct exceeded"); ArrowSchema.Snapshot snapshot = schema.snapshot(); checkState(snapshot.release != NULL, "Cannot import released ArrowSchema"); @@ -71,7 +71,8 @@ private Field importField(ArrowSchema schema, CDataDictionaryProvider provider, if (metadata != null && metadata.containsKey(ExtensionType.EXTENSION_METADATA_KEY_NAME)) { final String extensionName = metadata.get(ExtensionType.EXTENSION_METADATA_KEY_NAME); - final String extensionMetadata = metadata.getOrDefault(ExtensionType.EXTENSION_METADATA_KEY_METADATA, ""); + final String extensionMetadata = + metadata.getOrDefault(ExtensionType.EXTENSION_METADATA_KEY_METADATA, ""); ExtensionType extensionType = ExtensionTypeRegistry.lookup(extensionName); if (extensionType != null) { arrowType = extensionType.deserialize(arrowType, extensionMetadata); @@ -96,7 +97,8 @@ private Field importField(ArrowSchema schema, CDataDictionaryProvider provider, FieldType fieldType = new FieldType(nullable, arrowType, dictionaryEncoding, metadata); List children = null; - long[] childrenIds = NativeUtil.toJavaArray(snapshot.children, checkedCastToInt(snapshot.n_children)); + long[] childrenIds = + NativeUtil.toJavaArray(snapshot.children, checkedCastToInt(snapshot.n_children)); if (childrenIds != null && childrenIds.length > 0) { children = new ArrayList<>(childrenIds.length); for (long childAddress : childrenIds) { diff --git a/java/c/src/main/java/org/apache/arrow/c/StructVectorLoader.java b/java/c/src/main/java/org/apache/arrow/c/StructVectorLoader.java index d9afd0189d8..a1e11b5f91b 100644 --- a/java/c/src/main/java/org/apache/arrow/c/StructVectorLoader.java +++ b/java/c/src/main/java/org/apache/arrow/c/StructVectorLoader.java @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.util.Collections2; @@ -38,17 +37,15 @@ import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.Schema; -/** - * Loads buffers into {@link StructVector}. - */ +/** Loads buffers into {@link StructVector}. */ public class StructVectorLoader { private final Schema schema; private final CompressionCodec.Factory factory; /** - * A flag indicating if decompression is needed. This will affect the behavior - * of releasing buffers. + * A flag indicating if decompression is needed. This will affect the behavior of releasing + * buffers. */ private boolean decompressionNeeded; @@ -64,7 +61,7 @@ public StructVectorLoader(Schema schema) { /** * Construct with a schema and a compression codec factory. * - * @param schema buffers are added based on schema. + * @param schema buffers are added based on schema. * @param factory the factory to create codec. */ public StructVectorLoader(Schema schema, CompressionCodec.Factory factory) { @@ -74,9 +71,8 @@ public StructVectorLoader(Schema schema, CompressionCodec.Factory factory) { /** * Loads the record batch into the struct vector. - * - *

- * This will not close the record batch. + * + *

This will not close the record batch. * * @param recordBatch the batch to load */ @@ -86,22 +82,31 @@ public StructVector load(BufferAllocator allocator, ArrowRecordBatch recordBatch Iterator buffers = recordBatch.getBuffers().iterator(); Iterator nodes = recordBatch.getNodes().iterator(); - CompressionUtil.CodecType codecType = CompressionUtil.CodecType - .fromCompressionType(recordBatch.getBodyCompression().getCodec()); + CompressionUtil.CodecType codecType = + CompressionUtil.CodecType.fromCompressionType(recordBatch.getBodyCompression().getCodec()); decompressionNeeded = codecType != CompressionUtil.CodecType.NO_COMPRESSION; - CompressionCodec codec = decompressionNeeded ? factory.createCodec(codecType) : NoCompressionCodec.INSTANCE; + CompressionCodec codec = + decompressionNeeded ? factory.createCodec(codecType) : NoCompressionCodec.INSTANCE; for (FieldVector fieldVector : result.getChildrenFromFields()) { loadBuffers(fieldVector, fieldVector.getField(), buffers, nodes, codec); } - result.loadFieldBuffers(new ArrowFieldNode(recordBatch.getLength(), 0), Collections.singletonList(null)); + result.loadFieldBuffers( + new ArrowFieldNode(recordBatch.getLength(), 0), Collections.singletonList(null)); if (nodes.hasNext() || buffers.hasNext()) { - throw new IllegalArgumentException("not all nodes and buffers were consumed. nodes: " + - Collections2.toList(nodes).toString() + " buffers: " + Collections2.toList(buffers).toString()); + throw new IllegalArgumentException( + "not all nodes and buffers were consumed. nodes: " + + Collections2.toList(nodes).toString() + + " buffers: " + + Collections2.toList(buffers).toString()); } return result; } - private void loadBuffers(FieldVector vector, Field field, Iterator buffers, Iterator nodes, + private void loadBuffers( + FieldVector vector, + Field field, + Iterator buffers, + Iterator nodes, CompressionCodec codec) { checkArgument(nodes.hasNext(), "no more field nodes for field %s and vector %s", field, vector); ArrowFieldNode fieldNode = nodes.next(); @@ -111,7 +116,8 @@ private void loadBuffers(FieldVector vector, Field field, Iterator buf ArrowBuf nextBuf = buffers.next(); // for vectors without nulls, the buffer is empty, so there is no need to // decompress it. - ArrowBuf bufferToAdd = nextBuf.writerIndex() > 0 ? codec.decompress(vector.getAllocator(), nextBuf) : nextBuf; + ArrowBuf bufferToAdd = + nextBuf.writerIndex() > 0 ? codec.decompress(vector.getAllocator(), nextBuf) : nextBuf; ownBuffers.add(bufferToAdd); if (decompressionNeeded) { // decompression performed @@ -132,8 +138,10 @@ private void loadBuffers(FieldVector vector, Field field, Iterator buf List children = field.getChildren(); if (children.size() > 0) { List childrenFromFields = vector.getChildrenFromFields(); - checkArgument(children.size() == childrenFromFields.size(), - "should have as many children as in the schema: found %s expected %s", childrenFromFields.size(), + checkArgument( + children.size() == childrenFromFields.size(), + "should have as many children as in the schema: found %s expected %s", + childrenFromFields.size(), children.size()); for (int i = 0; i < childrenFromFields.size(); i++) { Field child = children.get(i); diff --git a/java/c/src/main/java/org/apache/arrow/c/StructVectorUnloader.java b/java/c/src/main/java/org/apache/arrow/c/StructVectorUnloader.java index aa6d9b4d0f6..7131f900f15 100644 --- a/java/c/src/main/java/org/apache/arrow/c/StructVectorUnloader.java +++ b/java/c/src/main/java/org/apache/arrow/c/StructVectorUnloader.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.TypeLayout; @@ -30,10 +29,7 @@ import org.apache.arrow.vector.ipc.message.ArrowFieldNode; import org.apache.arrow.vector.ipc.message.ArrowRecordBatch; -/** - * Helper class that handles converting a {@link StructVector} to a - * {@link ArrowRecordBatch}. - */ +/** Helper class that handles converting a {@link StructVector} to a {@link ArrowRecordBatch}. */ public class StructVectorUnloader { private final StructVector root; @@ -41,9 +37,7 @@ public class StructVectorUnloader { private final CompressionCodec codec; private final boolean alignBuffers; - /** - * Constructs a new instance of the given struct vector. - */ + /** Constructs a new instance of the given struct vector. */ public StructVectorUnloader(StructVector root) { this(root, true, NoCompressionCodec.INSTANCE, true); } @@ -51,11 +45,9 @@ public StructVectorUnloader(StructVector root) { /** * Constructs a new instance. * - * @param root The struct vector to serialize to an - * {@link ArrowRecordBatch}. - * @param includeNullCount Controls whether null count is copied to the - * {@link ArrowRecordBatch} - * @param alignBuffers Controls if buffers get aligned to 8-byte boundaries. + * @param root The struct vector to serialize to an {@link ArrowRecordBatch}. + * @param includeNullCount Controls whether null count is copied to the {@link ArrowRecordBatch} + * @param alignBuffers Controls if buffers get aligned to 8-byte boundaries. */ public StructVectorUnloader(StructVector root, boolean includeNullCount, boolean alignBuffers) { this(root, includeNullCount, NoCompressionCodec.INSTANCE, alignBuffers); @@ -64,16 +56,13 @@ public StructVectorUnloader(StructVector root, boolean includeNullCount, boolean /** * Constructs a new instance. * - * @param root The struct vector to serialize to an - * {@link ArrowRecordBatch}. - * @param includeNullCount Controls whether null count is copied to the - * {@link ArrowRecordBatch} - * @param codec the codec for compressing data. If it is null, then - * no compression is needed. - * @param alignBuffers Controls if buffers get aligned to 8-byte boundaries. + * @param root The struct vector to serialize to an {@link ArrowRecordBatch}. + * @param includeNullCount Controls whether null count is copied to the {@link ArrowRecordBatch} + * @param codec the codec for compressing data. If it is null, then no compression is needed. + * @param alignBuffers Controls if buffers get aligned to 8-byte boundaries. */ - public StructVectorUnloader(StructVector root, boolean includeNullCount, CompressionCodec codec, - boolean alignBuffers) { + public StructVectorUnloader( + StructVector root, boolean includeNullCount, CompressionCodec codec, boolean alignBuffers) { this.root = root; this.includeNullCount = includeNullCount; this.codec = codec; @@ -81,8 +70,8 @@ public StructVectorUnloader(StructVector root, boolean includeNullCount, Compres } /** - * Performs the depth first traversal of the Vectors to create an - * {@link ArrowRecordBatch} suitable for serialization. + * Performs the depth first traversal of the Vectors to create an {@link ArrowRecordBatch} + * suitable for serialization. */ public ArrowRecordBatch getRecordBatch() { List nodes = new ArrayList<>(); @@ -90,17 +79,24 @@ public ArrowRecordBatch getRecordBatch() { for (FieldVector vector : root.getChildrenFromFields()) { appendNodes(vector, nodes, buffers); } - return new ArrowRecordBatch(root.getValueCount(), nodes, buffers, CompressionUtil.createBodyCompression(codec), + return new ArrowRecordBatch( + root.getValueCount(), + nodes, + buffers, + CompressionUtil.createBodyCompression(codec), alignBuffers); } private void appendNodes(FieldVector vector, List nodes, List buffers) { - nodes.add(new ArrowFieldNode(vector.getValueCount(), includeNullCount ? vector.getNullCount() : -1)); + nodes.add( + new ArrowFieldNode(vector.getValueCount(), includeNullCount ? vector.getNullCount() : -1)); List fieldBuffers = vector.getFieldBuffers(); int expectedBufferCount = TypeLayout.getTypeBufferCount(vector.getField().getType()); if (fieldBuffers.size() != expectedBufferCount) { - throw new IllegalArgumentException(String.format("wrong number of buffers for field %s in vector %s. found: %s", - vector.getField(), vector.getClass().getSimpleName(), fieldBuffers)); + throw new IllegalArgumentException( + String.format( + "wrong number of buffers for field %s in vector %s. found: %s", + vector.getField(), vector.getClass().getSimpleName(), fieldBuffers)); } for (ArrowBuf buf : fieldBuffers) { buffers.add(codec.compress(vector.getAllocator(), buf)); diff --git a/java/c/src/main/java/org/apache/arrow/c/jni/CDataJniException.java b/java/c/src/main/java/org/apache/arrow/c/jni/CDataJniException.java index bebd434f3db..01d8f1a6447 100644 --- a/java/c/src/main/java/org/apache/arrow/c/jni/CDataJniException.java +++ b/java/c/src/main/java/org/apache/arrow/c/jni/CDataJniException.java @@ -17,9 +17,7 @@ package org.apache.arrow.c.jni; -/** - * An exception raised by the JNI side of the C Data bridge. - */ +/** An exception raised by the JNI side of the C Data bridge. */ public final class CDataJniException extends Exception { private final int errno; @@ -28,18 +26,13 @@ public CDataJniException(int errno, String message) { this.errno = errno; } - /** - * The original error code returned from C. - */ + /** The original error code returned from C. */ public int getErrno() { return errno; } @Override public String toString() { - return "CDataJniException{" + - "errno=" + errno + - ", message=" + getMessage() + - '}'; + return "CDataJniException{" + "errno=" + errno + ", message=" + getMessage() + '}'; } } diff --git a/java/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java b/java/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java index ef9f432cf00..fdc7f5493fa 100644 --- a/java/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java +++ b/java/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java @@ -30,11 +30,10 @@ import java.util.Locale; import java.util.Set; -/** - * The JniLoader for C Data Interface API's native implementation. - */ +/** The JniLoader for C Data Interface API's native implementation. */ public class JniLoader { - private static final JniLoader INSTANCE = new JniLoader(Collections.singletonList("arrow_cdata_jni")); + private static final JniLoader INSTANCE = + new JniLoader(Collections.singletonList("arrow_cdata_jni")); public static JniLoader get() { return INSTANCE; @@ -50,9 +49,7 @@ private boolean finished() { return librariesToLoad.isEmpty(); } - /** - * If required JNI libraries are not loaded, then load them. - */ + /** If required JNI libraries are not loaded, then load them. */ public void ensureLoaded() { if (finished()) { return; @@ -82,9 +79,11 @@ private void load(String name) { final String libraryToLoad = name + "/" + getNormalizedArch() + "/" + System.mapLibraryName(name); try { - File temp = File.createTempFile("jnilib-", ".tmp", new File(System.getProperty("java.io.tmpdir"))); + File temp = + File.createTempFile("jnilib-", ".tmp", new File(System.getProperty("java.io.tmpdir"))); temp.deleteOnExit(); - try (final InputStream is = JniWrapper.class.getClassLoader().getResourceAsStream(libraryToLoad)) { + try (final InputStream is = + JniWrapper.class.getClassLoader().getResourceAsStream(libraryToLoad)) { if (is == null) { throw new FileNotFoundException(libraryToLoad); } diff --git a/java/c/src/main/java/org/apache/arrow/c/jni/JniWrapper.java b/java/c/src/main/java/org/apache/arrow/c/jni/JniWrapper.java index eb299b65f00..82574572393 100644 --- a/java/c/src/main/java/org/apache/arrow/c/jni/JniWrapper.java +++ b/java/c/src/main/java/org/apache/arrow/c/jni/JniWrapper.java @@ -17,9 +17,7 @@ package org.apache.arrow.c.jni; -/** - * JniWrapper for C Data Interface API implementation. - */ +/** JniWrapper for C Data Interface API implementation. */ public class JniWrapper { private static final JniWrapper INSTANCE = new JniWrapper(); @@ -41,9 +39,11 @@ private JniWrapper() { public native void releaseArray(long memoryAddress); - public native void getNextArrayStream(long streamAddress, long arrayAddress) throws CDataJniException; + public native void getNextArrayStream(long streamAddress, long arrayAddress) + throws CDataJniException; - public native void getSchemaArrayStream(long streamAddress, long arrayAddress) throws CDataJniException; + public native void getSchemaArrayStream(long streamAddress, long arrayAddress) + throws CDataJniException; public native void releaseArrayStream(long memoryAddress); diff --git a/java/c/src/main/java/org/apache/arrow/c/jni/PrivateData.java b/java/c/src/main/java/org/apache/arrow/c/jni/PrivateData.java index e6336cc6477..f4585946e26 100644 --- a/java/c/src/main/java/org/apache/arrow/c/jni/PrivateData.java +++ b/java/c/src/main/java/org/apache/arrow/c/jni/PrivateData.java @@ -21,8 +21,8 @@ /** * Interface for Java objects stored in C data interface private data. - *

- * This interface is used for exported structures. + * + *

This interface is used for exported structures. */ public interface PrivateData extends Closeable { diff --git a/java/c/src/test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java b/java/c/src/test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java index 4a0a966ba1f..956f36ad37c 100644 --- a/java/c/src/test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java @@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.ReferenceManager; @@ -59,42 +58,56 @@ void afterEach() { void importBuffer() throws Exception { // Note values are all dummy values here try (BufferImportTypeVisitor notEmptyDataVisitor = - new BufferImportTypeVisitor(allocator, dummyHandle, new ArrowFieldNode(/* length= */ 1, 0), new long[]{0})) { + new BufferImportTypeVisitor( + allocator, dummyHandle, new ArrowFieldNode(/* length= */ 1, 0), new long[] {0})) { // Too few buffers - assertThrows(IllegalStateException.class, () -> notEmptyDataVisitor.importBuffer(new ArrowType.Bool(), 1, 1)); + assertThrows( + IllegalStateException.class, + () -> notEmptyDataVisitor.importBuffer(new ArrowType.Bool(), 1, 1)); // Null where one isn't expected - assertThrows(IllegalStateException.class, () -> notEmptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 1)); + assertThrows( + IllegalStateException.class, + () -> notEmptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 1)); // Expected capacity not zero but c array ptr is NULL (zero) - assertThrows(IllegalStateException.class, () -> notEmptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 1)); + assertThrows( + IllegalStateException.class, + () -> notEmptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 1)); // Expected capacity is zero and c array ptr is NULL (zero) - assertThat(notEmptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 0)).isEqualTo(allocator.getEmpty()); + assertThat(notEmptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 0)) + .isEqualTo(allocator.getEmpty()); } try (BufferImportTypeVisitor emptyDataVisitor = - new BufferImportTypeVisitor(allocator, dummyHandle, new ArrowFieldNode(/* length= */ 0, 0), new long[]{0})) { + new BufferImportTypeVisitor( + allocator, dummyHandle, new ArrowFieldNode(/* length= */ 0, 0), new long[] {0})) { // Too few buffers - assertThrows(IllegalStateException.class, () -> emptyDataVisitor.importBuffer(new ArrowType.Bool(), 1, 1)); + assertThrows( + IllegalStateException.class, + () -> emptyDataVisitor.importBuffer(new ArrowType.Bool(), 1, 1)); // Expected capacity not zero but c array ptr is NULL (zero) - assertThrows(IllegalStateException.class, () -> emptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 1)); + assertThrows( + IllegalStateException.class, + () -> emptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 1)); // Expected capacity is zero and c array ptr is NULL (zero) - assertThat(emptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 0)).isEqualTo(allocator.getEmpty()); + assertThat(emptyDataVisitor.importBuffer(new ArrowType.Bool(), 0, 0)) + .isEqualTo(allocator.getEmpty()); } } - @Test void cleanupAfterFailure() throws Exception { // Note values are all dummy values here long address = MemoryUtil.UNSAFE.allocateMemory(16); try (BufferImportTypeVisitor visitor = - new BufferImportTypeVisitor(allocator, dummyHandle, new ArrowFieldNode(0, 0), new long[] {address})) { + new BufferImportTypeVisitor( + allocator, dummyHandle, new ArrowFieldNode(0, 0), new long[] {address})) { // This fails, but only after we've already imported a buffer. assertThrows(IllegalStateException.class, () -> visitor.visit(new ArrowType.Int(32, true))); } finally { @@ -111,7 +124,7 @@ void bufferAssociatedWithAllocator() throws Exception { long baseline = allocator.getAllocatedMemory(); ArrowFieldNode fieldNode = new ArrowFieldNode(fieldLength, 0); try (BufferImportTypeVisitor visitor = - new BufferImportTypeVisitor(allocator, dummyHandle, fieldNode, new long[] {0, address})) { + new BufferImportTypeVisitor(allocator, dummyHandle, fieldNode, new long[] {0, address})) { List buffers = visitor.visit(new ArrowType.Int(32, true)); assertThat(buffers).hasSize(2); assertThat(buffers.get(0)).isNull(); diff --git a/java/c/src/test/java/org/apache/arrow/c/DictionaryTest.java b/java/c/src/test/java/org/apache/arrow/c/DictionaryTest.java index d892781756e..04a28513ae7 100644 --- a/java/c/src/test/java/org/apache/arrow/c/DictionaryTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/DictionaryTest.java @@ -24,11 +24,6 @@ import java.io.IOException; import java.nio.channels.Channels; import java.util.Collections; - -import org.apache.arrow.c.ArrowArray; -import org.apache.arrow.c.ArrowSchema; -import org.apache.arrow.c.CDataDictionaryProvider; -import org.apache.arrow.c.Data; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.util.AutoCloseables; import org.apache.arrow.vector.FieldVector; @@ -75,14 +70,19 @@ void roundtrip(FieldVector vector, DictionaryProvider provider, Class clazz) // Consumer imports vector try (CDataDictionaryProvider cDictionaryProvider = new CDataDictionaryProvider(); - FieldVector imported = Data.importVector(allocator, consumerArrowArray, consumerArrowSchema, - cDictionaryProvider);) { - assertTrue(clazz.isInstance(imported), String.format("expected %s but was %s", clazz, imported.getClass())); - assertTrue(VectorEqualsVisitor.vectorEquals(vector, imported), "vectors are not equivalent"); + FieldVector imported = + Data.importVector( + allocator, consumerArrowArray, consumerArrowSchema, cDictionaryProvider); ) { + assertTrue( + clazz.isInstance(imported), + String.format("expected %s but was %s", clazz, imported.getClass())); + assertTrue( + VectorEqualsVisitor.vectorEquals(vector, imported), "vectors are not equivalent"); for (long id : cDictionaryProvider.getDictionaryIds()) { ValueVector exportedDictionaryVector = provider.lookup(id).getVector(); ValueVector importedDictionaryVector = cDictionaryProvider.lookup(id).getVector(); - assertTrue(VectorEqualsVisitor.vectorEquals(exportedDictionaryVector, importedDictionaryVector), + assertTrue( + VectorEqualsVisitor.vectorEquals(exportedDictionaryVector, importedDictionaryVector), String.format("Dictionary vectors for ID %d are not equivalent", id)); } } @@ -91,7 +91,8 @@ void roundtrip(FieldVector vector, DictionaryProvider provider, Class clazz) @Test public void testWithDictionary() throws Exception { - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); // create dictionary and provider final VarCharVector dictVector = new VarCharVector("dict", allocator); dictVector.allocateNewSafe(); @@ -100,7 +101,8 @@ public void testWithDictionary() throws Exception { dictVector.setSafe(2, "cc".getBytes()); dictVector.setValueCount(3); - Dictionary dictionary = new Dictionary(dictVector, new DictionaryEncoding(0L, false, /* indexType= */null)); + Dictionary dictionary = + new Dictionary(dictVector, new DictionaryEncoding(0L, false, /* indexType= */ null)); provider.put(dictionary); // create vector and encode it @@ -129,29 +131,37 @@ public void testRoundtripMultipleBatches() throws IOException { // Load first batch reader.loadNextBatch(); // Producer fills consumer schema structure - Data.exportSchema(allocator, reader.getVectorSchemaRoot().getSchema(), reader, consumerArrowSchema); + Data.exportSchema( + allocator, reader.getVectorSchemaRoot().getSchema(), reader, consumerArrowSchema); // Consumer loads it as an empty vector schema root try (CDataDictionaryProvider consumerDictionaryProvider = new CDataDictionaryProvider(); - VectorSchemaRoot consumerRoot = Data.importVectorSchemaRoot(allocator, consumerArrowSchema, - consumerDictionaryProvider)) { + VectorSchemaRoot consumerRoot = + Data.importVectorSchemaRoot( + allocator, consumerArrowSchema, consumerDictionaryProvider)) { do { try (ArrowArray consumerArray = ArrowArray.allocateNew(allocator)) { // Producer exports next data - Data.exportVectorSchemaRoot(allocator, reader.getVectorSchemaRoot(), reader, consumerArray); + Data.exportVectorSchemaRoot( + allocator, reader.getVectorSchemaRoot(), reader, consumerArray); // Consumer loads next data - Data.importIntoVectorSchemaRoot(allocator, consumerArray, consumerRoot, consumerDictionaryProvider); + Data.importIntoVectorSchemaRoot( + allocator, consumerArray, consumerRoot, consumerDictionaryProvider); // Roundtrip validation - assertTrue(consumerRoot.equals(reader.getVectorSchemaRoot()), "vector schema roots are not equivalent"); + assertTrue( + consumerRoot.equals(reader.getVectorSchemaRoot()), + "vector schema roots are not equivalent"); for (long id : consumerDictionaryProvider.getDictionaryIds()) { ValueVector exportedDictionaryVector = reader.lookup(id).getVector(); - ValueVector importedDictionaryVector = consumerDictionaryProvider.lookup(id).getVector(); - assertTrue(VectorEqualsVisitor.vectorEquals(exportedDictionaryVector, importedDictionaryVector), + ValueVector importedDictionaryVector = + consumerDictionaryProvider.lookup(id).getVector(); + assertTrue( + VectorEqualsVisitor.vectorEquals( + exportedDictionaryVector, importedDictionaryVector), String.format("Dictionary vectors for ID %d are not equivalent", id)); } } - } - while (reader.loadNextBatch()); + } while (reader.loadNextBatch()); } } } @@ -161,7 +171,8 @@ private ArrowStreamReader createMultiBatchReader() throws IOException { try (final VarCharVector dictVector = new VarCharVector("dict", allocator); IntVector vector = new IntVector("foo", allocator)) { // create dictionary and provider - DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider(); + DictionaryProvider.MapDictionaryProvider provider = + new DictionaryProvider.MapDictionaryProvider(); dictVector.allocateNewSafe(); dictVector.setSafe(0, "aa".getBytes()); dictVector.setSafe(1, "bb".getBytes()); @@ -169,14 +180,16 @@ private ArrowStreamReader createMultiBatchReader() throws IOException { dictVector.setSafe(3, "dd".getBytes()); dictVector.setSafe(4, "ee".getBytes()); dictVector.setValueCount(5); - Dictionary dictionary = new Dictionary(dictVector, new DictionaryEncoding(0L, false, /* indexType= */null)); + Dictionary dictionary = + new Dictionary(dictVector, new DictionaryEncoding(0L, false, /* indexType= */ null)); provider.put(dictionary); Schema schema = new Schema(Collections.singletonList(vector.getField())); - try ( - VectorSchemaRoot root = new VectorSchemaRoot(schema, Collections.singletonList(vector), - vector.getValueCount()); - ArrowStreamWriter writer = new ArrowStreamWriter(root, provider, Channels.newChannel(os));) { + try (VectorSchemaRoot root = + new VectorSchemaRoot( + schema, Collections.singletonList(vector), vector.getValueCount()); + ArrowStreamWriter writer = + new ArrowStreamWriter(root, provider, Channels.newChannel(os)); ) { writer.start(); @@ -215,5 +228,4 @@ private ArrowStreamReader createMultiBatchReader() throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(os.toByteArray()); return new ArrowStreamReader(in, allocator); } - } diff --git a/java/c/src/test/java/org/apache/arrow/c/FlagsTest.java b/java/c/src/test/java/org/apache/arrow/c/FlagsTest.java index 35f836f71f5..31af2dbd456 100644 --- a/java/c/src/test/java/org/apache/arrow/c/FlagsTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/FlagsTest.java @@ -20,8 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; - -import org.apache.arrow.c.Flags; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.DictionaryEncoding; import org.apache.arrow.vector.types.pojo.Field; @@ -31,46 +29,66 @@ public class FlagsTest { @Test public void testForFieldNullableOrderedDict() { - FieldType fieldType = new FieldType(true, ArrowType.Binary.INSTANCE, - new DictionaryEncoding(123L, true, new ArrowType.Int(8, true))); + FieldType fieldType = + new FieldType( + true, + ArrowType.Binary.INSTANCE, + new DictionaryEncoding(123L, true, new ArrowType.Int(8, true))); - assertEquals(Flags.ARROW_FLAG_DICTIONARY_ORDERED | Flags.ARROW_FLAG_NULLABLE, + assertEquals( + Flags.ARROW_FLAG_DICTIONARY_ORDERED | Flags.ARROW_FLAG_NULLABLE, Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); } @Test public void testForFieldOrderedDict() { - FieldType fieldType = new FieldType(false, ArrowType.Binary.INSTANCE, - new DictionaryEncoding(123L, true, new ArrowType.Int(8, true))); - assertEquals(Flags.ARROW_FLAG_DICTIONARY_ORDERED, Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); + FieldType fieldType = + new FieldType( + false, + ArrowType.Binary.INSTANCE, + new DictionaryEncoding(123L, true, new ArrowType.Int(8, true))); + assertEquals( + Flags.ARROW_FLAG_DICTIONARY_ORDERED, + Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); } @Test public void testForFieldNullableDict() { - FieldType fieldType = new FieldType(true, ArrowType.Binary.INSTANCE, - new DictionaryEncoding(123L, false, new ArrowType.Int(8, true))); - assertEquals(Flags.ARROW_FLAG_NULLABLE, Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); + FieldType fieldType = + new FieldType( + true, + ArrowType.Binary.INSTANCE, + new DictionaryEncoding(123L, false, new ArrowType.Int(8, true))); + assertEquals( + Flags.ARROW_FLAG_NULLABLE, Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); } @Test public void testForFieldNullable() { FieldType fieldType = new FieldType(true, ArrowType.Binary.INSTANCE, null); - assertEquals(Flags.ARROW_FLAG_NULLABLE, Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); + assertEquals( + Flags.ARROW_FLAG_NULLABLE, Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); } @Test public void testForFieldNullableOrderedSortedMap() { ArrowType.Map type = new ArrowType.Map(true); - FieldType fieldType = new FieldType(true, type, new DictionaryEncoding(123L, true, new ArrowType.Int(8, true))); - assertEquals(Flags.ARROW_FLAG_DICTIONARY_ORDERED | Flags.ARROW_FLAG_NULLABLE | Flags.ARROW_FLAG_MAP_KEYS_SORTED, + FieldType fieldType = + new FieldType(true, type, new DictionaryEncoding(123L, true, new ArrowType.Int(8, true))); + assertEquals( + Flags.ARROW_FLAG_DICTIONARY_ORDERED + | Flags.ARROW_FLAG_NULLABLE + | Flags.ARROW_FLAG_MAP_KEYS_SORTED, Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); } @Test public void testForFieldNullableOrderedMap() { ArrowType.Map type = new ArrowType.Map(false); - FieldType fieldType = new FieldType(true, type, new DictionaryEncoding(123L, true, new ArrowType.Int(8, true))); - assertEquals(Flags.ARROW_FLAG_DICTIONARY_ORDERED | Flags.ARROW_FLAG_NULLABLE, + FieldType fieldType = + new FieldType(true, type, new DictionaryEncoding(123L, true, new ArrowType.Int(8, true))); + assertEquals( + Flags.ARROW_FLAG_DICTIONARY_ORDERED | Flags.ARROW_FLAG_NULLABLE, Flags.forField(new Field("Name", fieldType, new ArrayList<>()))); } } diff --git a/java/c/src/test/java/org/apache/arrow/c/FormatTest.java b/java/c/src/test/java/org/apache/arrow/c/FormatTest.java index 1f7f86b36f6..1489254ccda 100644 --- a/java/c/src/test/java/org/apache/arrow/c/FormatTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/FormatTest.java @@ -21,8 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.apache.arrow.c.Flags; -import org.apache.arrow.c.Format; import org.apache.arrow.vector.types.DateUnit; import org.apache.arrow.vector.types.FloatingPointPrecision; import org.apache.arrow.vector.types.IntervalUnit; @@ -71,22 +69,33 @@ public void testAsString() { assertEquals("ttm", Format.asString(new ArrowType.Time(TimeUnit.MILLISECOND, 32))); assertEquals("ttu", Format.asString(new ArrowType.Time(TimeUnit.MICROSECOND, 64))); assertEquals("ttn", Format.asString(new ArrowType.Time(TimeUnit.NANOSECOND, 64))); - assertEquals("tss:Timezone", Format.asString(new ArrowType.Timestamp(TimeUnit.SECOND, "Timezone"))); - assertEquals("tsm:Timezone", Format.asString(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "Timezone"))); - assertEquals("tsu:Timezone", Format.asString(new ArrowType.Timestamp(TimeUnit.MICROSECOND, "Timezone"))); - assertEquals("tsn:Timezone", Format.asString(new ArrowType.Timestamp(TimeUnit.NANOSECOND, "Timezone"))); - assertEquals("+us:1,1,1", Format.asString(new ArrowType.Union(UnionMode.Sparse, new int[] { 1, 1, 1 }))); - assertEquals("+ud:1,1,1", Format.asString(new ArrowType.Union(UnionMode.Dense, new int[] { 1, 1, 1 }))); + assertEquals( + "tss:Timezone", Format.asString(new ArrowType.Timestamp(TimeUnit.SECOND, "Timezone"))); + assertEquals( + "tsm:Timezone", Format.asString(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "Timezone"))); + assertEquals( + "tsu:Timezone", Format.asString(new ArrowType.Timestamp(TimeUnit.MICROSECOND, "Timezone"))); + assertEquals( + "tsn:Timezone", Format.asString(new ArrowType.Timestamp(TimeUnit.NANOSECOND, "Timezone"))); + assertEquals( + "+us:1,1,1", Format.asString(new ArrowType.Union(UnionMode.Sparse, new int[] {1, 1, 1}))); + assertEquals( + "+ud:1,1,1", Format.asString(new ArrowType.Union(UnionMode.Dense, new int[] {1, 1, 1}))); assertEquals("u", Format.asString(new ArrowType.Utf8())); - assertThrows(UnsupportedOperationException.class, () -> Format.asString(new ArrowType.Int(1, true))); - assertThrows(UnsupportedOperationException.class, () -> Format.asString(new ArrowType.Time(TimeUnit.SECOND, 1))); - assertThrows(UnsupportedOperationException.class, + assertThrows( + UnsupportedOperationException.class, () -> Format.asString(new ArrowType.Int(1, true))); + assertThrows( + UnsupportedOperationException.class, + () -> Format.asString(new ArrowType.Time(TimeUnit.SECOND, 1))); + assertThrows( + UnsupportedOperationException.class, () -> Format.asString(new ArrowType.Time(TimeUnit.MILLISECOND, 64))); } @Test - public void testAsType() throws IllegalStateException, NumberFormatException, UnsupportedOperationException { + public void testAsType() + throws IllegalStateException, NumberFormatException, UnsupportedOperationException { assertTrue(Format.asType("n", 0L) instanceof ArrowType.Null); assertTrue(Format.asType("b", 0L) instanceof ArrowType.Bool); assertEquals(new ArrowType.Int(Byte.SIZE, true), Format.asType("c", 0L)); @@ -98,8 +107,10 @@ public void testAsType() throws IllegalStateException, NumberFormatException, Un assertEquals(new ArrowType.Int(Long.SIZE, true), Format.asType("l", 0L)); assertEquals(new ArrowType.Int(Long.SIZE, false), Format.asType("L", 0L)); assertEquals(new ArrowType.FloatingPoint(FloatingPointPrecision.HALF), Format.asType("e", 0L)); - assertEquals(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), Format.asType("f", 0L)); - assertEquals(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), Format.asType("g", 0L)); + assertEquals( + new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), Format.asType("f", 0L)); + assertEquals( + new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), Format.asType("g", 0L)); assertTrue(Format.asType("z", 0L) instanceof ArrowType.Binary); assertTrue(Format.asType("Z", 0L) instanceof ArrowType.LargeBinary); assertTrue(Format.asType("u", 0L) instanceof ArrowType.Utf8); @@ -126,12 +137,21 @@ public void testAsType() throws IllegalStateException, NumberFormatException, Un assertEquals(new ArrowType.Decimal(9, 1, 1), Format.asType("d:9,1,1", 0L)); assertEquals(new ArrowType.FixedSizeBinary(1), Format.asType("w:1", 0L)); assertEquals(new ArrowType.FixedSizeList(3), Format.asType("+w:3", 0L)); - assertEquals(new ArrowType.Union(UnionMode.Dense, new int[] { 1, 1, 1 }), Format.asType("+ud:1,1,1", 0L)); - assertEquals(new ArrowType.Union(UnionMode.Sparse, new int[] { 1, 1, 1 }), Format.asType("+us:1,1,1", 0L)); - assertEquals(new ArrowType.Timestamp(TimeUnit.SECOND, "Timezone"), Format.asType("tss:Timezone", 0L)); - assertEquals(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "Timezone"), Format.asType("tsm:Timezone", 0L)); - assertEquals(new ArrowType.Timestamp(TimeUnit.MICROSECOND, "Timezone"), Format.asType("tsu:Timezone", 0L)); - assertEquals(new ArrowType.Timestamp(TimeUnit.NANOSECOND, "Timezone"), Format.asType("tsn:Timezone", 0L)); + assertEquals( + new ArrowType.Union(UnionMode.Dense, new int[] {1, 1, 1}), Format.asType("+ud:1,1,1", 0L)); + assertEquals( + new ArrowType.Union(UnionMode.Sparse, new int[] {1, 1, 1}), Format.asType("+us:1,1,1", 0L)); + assertEquals( + new ArrowType.Timestamp(TimeUnit.SECOND, "Timezone"), Format.asType("tss:Timezone", 0L)); + assertEquals( + new ArrowType.Timestamp(TimeUnit.MILLISECOND, "Timezone"), + Format.asType("tsm:Timezone", 0L)); + assertEquals( + new ArrowType.Timestamp(TimeUnit.MICROSECOND, "Timezone"), + Format.asType("tsu:Timezone", 0L)); + assertEquals( + new ArrowType.Timestamp(TimeUnit.NANOSECOND, "Timezone"), + Format.asType("tsn:Timezone", 0L)); assertThrows(UnsupportedOperationException.class, () -> Format.asType("Format", 0L)); assertThrows(UnsupportedOperationException.class, () -> Format.asType(":", 0L)); diff --git a/java/c/src/test/java/org/apache/arrow/c/MetadataTest.java b/java/c/src/test/java/org/apache/arrow/c/MetadataTest.java index 1d9703b1a87..05bea762d5a 100644 --- a/java/c/src/test/java/org/apache/arrow/c/MetadataTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/MetadataTest.java @@ -23,9 +23,6 @@ import java.nio.ByteOrder; import java.util.HashMap; import java.util.Map; - -import org.apache.arrow.c.Metadata; -import org.apache.arrow.c.NativeUtil; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.memory.util.LargeMemoryUtil; @@ -48,11 +45,17 @@ static void beforeAll() { metadata.put("key2", "bar"); if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { - encoded = new byte[] { 2, 0, 0, 0, 4, 0, 0, 0, 'k', 'e', 'y', '1', 0, 0, 0, 0, 4, 0, 0, 0, 'k', 'e', 'y', '2', 3, - 0, 0, 0, 'b', 'a', 'r' }; + encoded = + new byte[] { + 2, 0, 0, 0, 4, 0, 0, 0, 'k', 'e', 'y', '1', 0, 0, 0, 0, 4, 0, 0, 0, 'k', 'e', 'y', '2', + 3, 0, 0, 0, 'b', 'a', 'r' + }; } else { - encoded = new byte[] { 0, 0, 0, 2, 0, 0, 0, 4, 'k', 'e', 'y', '1', 0, 0, 0, 0, 0, 0, 0, 4, 'k', 'e', 'y', '2', 0, - 0, 0, 3, 'b', 'a', 'r' }; + encoded = + new byte[] { + 0, 0, 0, 2, 0, 0, 0, 4, 'k', 'e', 'y', '1', 0, 0, 0, 0, 0, 0, 0, 4, 'k', 'e', 'y', '2', + 0, 0, 0, 3, 'b', 'a', 'r' + }; } } @@ -70,7 +73,8 @@ public void tearDown() { public void testEncode() { try (ArrowBuf buffer = Metadata.encode(allocator, metadata)) { int totalSize = LargeMemoryUtil.checkedCastToInt(buffer.readableBytes()); - ByteBuffer reader = MemoryUtil.directBuffer(buffer.memoryAddress(), totalSize).order(ByteOrder.nativeOrder()); + ByteBuffer reader = + MemoryUtil.directBuffer(buffer.memoryAddress(), totalSize).order(ByteOrder.nativeOrder()); byte[] result = new byte[totalSize]; reader.get(result); assertArrayEquals(encoded, result); @@ -100,5 +104,4 @@ public void testDecodeEmpty() { Map decoded = Metadata.decode(NativeUtil.NULL); assertNull(decoded); } - } diff --git a/java/c/src/test/java/org/apache/arrow/c/NativeUtilTest.java b/java/c/src/test/java/org/apache/arrow/c/NativeUtilTest.java index f46a0128c86..b39c84d5640 100644 --- a/java/c/src/test/java/org/apache/arrow/c/NativeUtilTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/NativeUtilTest.java @@ -22,8 +22,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; - -import org.apache.arrow.c.NativeUtil; import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.memory.util.LargeMemoryUtil; @@ -49,10 +47,11 @@ public void tearDown() { @Test public void testString() { String javaString = "abc"; - byte[] nativeString = new byte[] { 97, 98, 99, 0 }; + byte[] nativeString = new byte[] {97, 98, 99, 0}; try (ArrowBuf buffer = NativeUtil.toNativeString(allocator, javaString)) { int totalSize = LargeMemoryUtil.checkedCastToInt(buffer.readableBytes()); - ByteBuffer reader = MemoryUtil.directBuffer(buffer.memoryAddress(), totalSize).order(ByteOrder.nativeOrder()); + ByteBuffer reader = + MemoryUtil.directBuffer(buffer.memoryAddress(), totalSize).order(ByteOrder.nativeOrder()); byte[] result = new byte[totalSize]; reader.get(result); assertArrayEquals(nativeString, result); @@ -63,7 +62,7 @@ public void testString() { @Test public void testToJavaArray() { - long[] nativeArray = new long[] { 1, 2, 3 }; + long[] nativeArray = new long[] {1, 2, 3}; try (ArrowBuf buffer = allocator.buffer(Long.BYTES * nativeArray.length, null)) { for (long value : nativeArray) { buffer.writeLong(value); @@ -78,5 +77,4 @@ public void testToZeroJavaArray() { long[] actual = NativeUtil.toJavaArray(0xDEADBEEF, 0); assertEquals(0, actual.length); } - } diff --git a/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java b/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java index fe070400ad9..b069bc59bb6 100644 --- a/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java @@ -34,7 +34,6 @@ import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -134,7 +133,8 @@ FieldVector vectorRoundtrip(FieldVector vector) { } // Consumer imports vector - FieldVector imported = Data.importVector(childAllocator, consumerArrowArray, consumerArrowSchema, null); + FieldVector imported = + Data.importVector(childAllocator, consumerArrowArray, consumerArrowSchema, null); if (!(imported instanceof NullVector)) { assertEquals(childAllocator, imported.getAllocator()); } @@ -165,7 +165,9 @@ VectorSchemaRoot vectorSchemaRootRoundtrip(VectorSchemaRoot root) { boolean roundtrip(FieldVector vector, Class clazz) { try (ValueVector imported = vectorRoundtrip(vector)) { - assertTrue(clazz.isInstance(imported), String.format("expected %s but was %s", clazz, imported.getClass())); + assertTrue( + clazz.isInstance(imported), + String.format("expected %s but was %s", clazz, imported.getClass())); return VectorEqualsVisitor.vectorEquals(vector, imported); } } @@ -292,7 +294,7 @@ public void testZeroVectorEquals() { @Test public void testFixedSizeBinaryVector() { try (final FixedSizeBinaryVector vector = new FixedSizeBinaryVector("v", allocator, 2)) { - setVector(vector, new byte[] { 0b0000, 0b0001 }, new byte[] { 0b0010, 0b0011 }); + setVector(vector, new byte[] {0b0000, 0b0001}, new byte[] {0b0010, 0b0011}); assertTrue(roundtrip(vector, FixedSizeBinaryVector.class)); } } @@ -535,8 +537,11 @@ public void testLargeVarCharVector() { @Test public void testListVector() { try (final ListVector vector = ListVector.empty("v", allocator)) { - setVector(vector, Arrays.stream(new int[] { 1, 2 }).boxed().collect(Collectors.toList()), - Arrays.stream(new int[] { 3, 4 }).boxed().collect(Collectors.toList()), new ArrayList()); + setVector( + vector, + Arrays.stream(new int[] {1, 2}).boxed().collect(Collectors.toList()), + Arrays.stream(new int[] {3, 4}).boxed().collect(Collectors.toList()), + new ArrayList()); assertTrue(roundtrip(vector, ListVector.class)); } } @@ -552,8 +557,11 @@ public void testEmptyListVector() { @Test public void testLargeListVector() { try (final LargeListVector vector = LargeListVector.empty("v", allocator)) { - setVector(vector, Arrays.stream(new int[] { 1, 2 }).boxed().collect(Collectors.toList()), - Arrays.stream(new int[] { 3, 4 }).boxed().collect(Collectors.toList()), new ArrayList()); + setVector( + vector, + Arrays.stream(new int[] {1, 2}).boxed().collect(Collectors.toList()), + Arrays.stream(new int[] {3, 4}).boxed().collect(Collectors.toList()), + new ArrayList()); assertTrue(roundtrip(vector, LargeListVector.class)); } } @@ -561,8 +569,10 @@ public void testLargeListVector() { @Test public void testFixedSizeListVector() { try (final FixedSizeListVector vector = FixedSizeListVector.empty("v", 2, allocator)) { - setVector(vector, Arrays.stream(new int[] { 1, 2 }).boxed().collect(Collectors.toList()), - Arrays.stream(new int[] { 3, 4 }).boxed().collect(Collectors.toList())); + setVector( + vector, + Arrays.stream(new int[] {1, 2}).boxed().collect(Collectors.toList()), + Arrays.stream(new int[] {3, 4}).boxed().collect(Collectors.toList())); assertTrue(roundtrip(vector, FixedSizeListVector.class)); } } @@ -613,8 +623,8 @@ public void testUnionVector() { public void testStructVector() { try (final StructVector vector = StructVector.empty("v", allocator)) { Map> data = new HashMap<>(); - data.put("col_1", Arrays.stream(new int[] { 1, 2 }).boxed().collect(Collectors.toList())); - data.put("col_2", Arrays.stream(new int[] { 3, 4 }).boxed().collect(Collectors.toList())); + data.put("col_1", Arrays.stream(new int[] {1, 2}).boxed().collect(Collectors.toList())); + data.put("col_2", Arrays.stream(new int[] {3, 4}).boxed().collect(Collectors.toList())); setVector(vector, data); assertTrue(roundtrip(vector, StructVector.class)); } @@ -623,7 +633,8 @@ public void testStructVector() { @Test public void testExtensionTypeVector() { ExtensionTypeRegistry.register(new UuidType()); - final Schema schema = new Schema(Collections.singletonList(Field.nullable("a", new UuidType()))); + final Schema schema = + new Schema(Collections.singletonList(Field.nullable("a", new UuidType()))); try (final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { // Fill with data UUID u1 = UUID.randomUUID(); @@ -642,8 +653,12 @@ public void testExtensionTypeVector() { final Field field = importedRoot.getSchema().getFields().get(0); final UuidType expectedType = new UuidType(); - assertEquals(field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME), expectedType.extensionName()); - assertEquals(field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA), expectedType.serialize()); + assertEquals( + field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_NAME), + expectedType.extensionName()); + assertEquals( + field.getMetadata().get(ExtensionType.EXTENSION_METADATA_KEY_METADATA), + expectedType.serialize()); final UuidVector deserialized = (UuidVector) importedRoot.getFieldVectors().get(0); assertEquals(vector.getValueCount(), deserialized.getValueCount()); @@ -674,7 +689,8 @@ public void testVectorSchemaRoot() { } } // Consumer imports vector - imported = Data.importVectorSchemaRoot(allocator, consumerArrowArray, consumerArrowSchema, null); + imported = + Data.importVectorSchemaRoot(allocator, consumerArrowArray, consumerArrowSchema, null); } // Ensure that imported VectorSchemaRoot is valid even after C Data Interface @@ -686,7 +702,8 @@ public void testVectorSchemaRoot() { } /** - * Tests exporting Table and importing back to VSR. Importing back to Table is not supported at present. + * Tests exporting Table and importing back to VSR. Importing back to Table is not supported at + * present. */ @Test public void testTable() { @@ -695,8 +712,7 @@ public void testTable() { // Consumer allocates empty structures try (ArrowSchema consumerArrowSchema = ArrowSchema.allocateNew(allocator); ArrowArray consumerArrowArray = ArrowArray.allocateNew(allocator)) { - try ( - VectorSchemaRoot vsr = createTestVSR(); + try (VectorSchemaRoot vsr = createTestVSR(); Table table = new Table(vsr)) { // Producer creates structures from existing memory pointers try (ArrowSchema arrowSchema = ArrowSchema.wrap(consumerArrowSchema.memoryAddress()); @@ -706,7 +722,8 @@ public void testTable() { } } // Consumer imports vector - imported = Data.importVectorSchemaRoot(allocator, consumerArrowArray, consumerArrowSchema, null); + imported = + Data.importVectorSchemaRoot(allocator, consumerArrowArray, consumerArrowSchema, null); } // Ensure that imported VectorSchemaRoot is valid even after C Data Interface @@ -728,10 +745,11 @@ public void testVectorSchemaRootWithDuplicatedFieldNames() { try (VectorSchemaRoot testVSR1 = createTestVSR(); VectorSchemaRoot testVSR2 = createTestVSR()) { // Merge two VSRs to produce duplicated field names - final VectorSchemaRoot vsr = new VectorSchemaRoot( - Stream.concat( - testVSR1.getFieldVectors().stream(), - testVSR2.getFieldVectors().stream()).collect(Collectors.toList())); + final VectorSchemaRoot vsr = + new VectorSchemaRoot( + Stream.concat( + testVSR1.getFieldVectors().stream(), testVSR2.getFieldVectors().stream()) + .collect(Collectors.toList())); // Producer creates structures from existing memory pointers try (ArrowSchema arrowSchema = ArrowSchema.wrap(consumerArrowSchema.memoryAddress()); ArrowArray arrowArray = ArrowArray.wrap(consumerArrowArray.memoryAddress())) { @@ -740,17 +758,19 @@ public void testVectorSchemaRootWithDuplicatedFieldNames() { } } // Consumer imports vector - imported = Data.importVectorSchemaRoot(allocator, consumerArrowArray, consumerArrowSchema, null); + imported = + Data.importVectorSchemaRoot(allocator, consumerArrowArray, consumerArrowSchema, null); } // Ensure that imported VectorSchemaRoot is valid even after C Data Interface // structures are closed try (VectorSchemaRoot testVSR1 = createTestVSR(); VectorSchemaRoot testVSR2 = createTestVSR()) { - final VectorSchemaRoot original = new VectorSchemaRoot( - Stream.concat( - testVSR1.getFieldVectors().stream(), - testVSR2.getFieldVectors().stream()).collect(Collectors.toList())); + final VectorSchemaRoot original = + new VectorSchemaRoot( + Stream.concat( + testVSR1.getFieldVectors().stream(), testVSR2.getFieldVectors().stream()) + .collect(Collectors.toList())); assertTrue(imported.equals(original)); } imported.close(); @@ -758,10 +778,14 @@ public void testVectorSchemaRootWithDuplicatedFieldNames() { @Test public void testSchema() { - Field decimalField = new Field("inner1", FieldType.nullable(new ArrowType.Decimal(19, 4, 128)), null); + Field decimalField = + new Field("inner1", FieldType.nullable(new ArrowType.Decimal(19, 4, 128)), null); Field strField = new Field("inner2", FieldType.nullable(new ArrowType.Utf8()), null); - Field itemField = new Field("col1", FieldType.nullable(new ArrowType.Struct()), - Arrays.asList(decimalField, strField)); + Field itemField = + new Field( + "col1", + FieldType.nullable(new ArrowType.Struct()), + Arrays.asList(decimalField, strField)); Field intField = new Field("col2", FieldType.nullable(new ArrowType.Int(32, true)), null); Schema schema = new Schema(Arrays.asList(itemField, intField)); // Consumer allocates empty ArrowSchema @@ -810,9 +834,12 @@ public void testImportReleasedArray() { consumerArrowArray.markReleased(); // Consumer tried to imports vector but fails - Exception e = assertThrows(IllegalStateException.class, () -> { - Data.importVector(allocator, consumerArrowArray, consumerArrowSchema, null); - }); + Exception e = + assertThrows( + IllegalStateException.class, + () -> { + Data.importVector(allocator, consumerArrowArray, consumerArrowSchema, null); + }); assertEquals("Cannot import released ArrowArray", e.getMessage()); } @@ -861,7 +888,8 @@ public boolean extensionEquals(ExtensionType other) { @Override public ArrowType deserialize(ArrowType storageType, String serializedData) { if (!storageType.equals(storageType())) { - throw new UnsupportedOperationException("Cannot construct UuidType from underlying type " + storageType); + throw new UnsupportedOperationException( + "Cannot construct UuidType from underlying type " + storageType); } return new UuidType(); } @@ -879,7 +907,8 @@ public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocato static class UuidVector extends ExtensionTypeVector { - public UuidVector(String name, BufferAllocator allocator, FixedSizeBinaryVector underlyingVector) { + public UuidVector( + String name, BufferAllocator allocator, FixedSizeBinaryVector underlyingVector) { super(name, allocator, underlyingVector); } diff --git a/java/c/src/test/java/org/apache/arrow/c/StreamTest.java b/java/c/src/test/java/org/apache/arrow/c/StreamTest.java index 68d4fc2a81e..c3064b76f8f 100644 --- a/java/c/src/test/java/org/apache/arrow/c/StreamTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/StreamTest.java @@ -30,7 +30,6 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.apache.arrow.util.AutoCloseables; @@ -70,7 +69,8 @@ public void tearDown() { @Test public void testRoundtripInts() throws Exception { - final Schema schema = new Schema(Collections.singletonList(Field.nullable("ints", new ArrowType.Int(32, true)))); + final Schema schema = + new Schema(Collections.singletonList(Field.nullable("ints", new ArrowType.Int(32, true)))); final List batches = new ArrayList<>(); try (final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final IntVector ints = (IntVector) root.getVector(0); @@ -97,8 +97,11 @@ public void testRoundtripInts() throws Exception { @Test public void roundtripStrings() throws Exception { - final Schema schema = new Schema(Arrays.asList(Field.nullable("ints", new ArrowType.Int(32, true)), - Field.nullable("strs", new ArrowType.Utf8()))); + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("ints", new ArrowType.Int(32, true)), + Field.nullable("strs", new ArrowType.Utf8()))); final List batches = new ArrayList<>(); try (final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final IntVector ints = (IntVector) root.getVector(0); @@ -136,11 +139,16 @@ public void roundtripStrings() throws Exception { public void roundtripDictionary() throws Exception { final ArrowType.Int indexType = new ArrowType.Int(32, true); final DictionaryEncoding encoding = new DictionaryEncoding(0L, false, indexType); - final Schema schema = new Schema(Collections.singletonList( - new Field("dict", new FieldType(/*nullable=*/true, indexType, encoding), Collections.emptyList()))); + final Schema schema = + new Schema( + Collections.singletonList( + new Field( + "dict", + new FieldType(/*nullable=*/ true, indexType, encoding), + Collections.emptyList()))); final List batches = new ArrayList<>(); try (final CDataDictionaryProvider provider = new CDataDictionaryProvider(); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final VarCharVector dictionary = new VarCharVector("values", allocator); dictionary.allocateNew(); dictionary.setSafe(0, "foo".getBytes(StandardCharsets.UTF_8)); @@ -173,22 +181,27 @@ public void roundtripDictionary() throws Exception { @Test public void importReleasedStream() { try (final ArrowArrayStream stream = ArrowArrayStream.allocateNew(allocator)) { - Exception e = assertThrows(IllegalStateException.class, () -> Data.importArrayStream(allocator, stream)); + Exception e = + assertThrows( + IllegalStateException.class, () -> Data.importArrayStream(allocator, stream)); assertThat(e).hasMessageContaining("Cannot import released ArrowArrayStream"); } } @Test public void getNextError() throws Exception { - final Schema schema = new Schema(Collections.singletonList(Field.nullable("ints", new ArrowType.Int(32, true)))); + final Schema schema = + new Schema(Collections.singletonList(Field.nullable("ints", new ArrowType.Int(32, true)))); final List batches = new ArrayList<>(); - try (final ArrowReader source = new InMemoryArrowReader(allocator, schema, batches, - new DictionaryProvider.MapDictionaryProvider()) { - @Override - public boolean loadNextBatch() throws IOException { - throw new IOException("Failed to load batch!"); - } - }; final ArrowArrayStream stream = ArrowArrayStream.allocateNew(allocator)) { + try (final ArrowReader source = + new InMemoryArrowReader( + allocator, schema, batches, new DictionaryProvider.MapDictionaryProvider()) { + @Override + public boolean loadNextBatch() throws IOException { + throw new IOException("Failed to load batch!"); + } + }; + final ArrowArrayStream stream = ArrowArrayStream.allocateNew(allocator)) { Data.exportArrayStream(allocator, source, stream); try (final ArrowReader reader = Data.importArrayStream(allocator, stream)) { assertThat(reader.getVectorSchemaRoot().getSchema()).isEqualTo(schema); @@ -201,15 +214,18 @@ public boolean loadNextBatch() throws IOException { @Test public void getSchemaError() throws Exception { - final Schema schema = new Schema(Collections.singletonList(Field.nullable("ints", new ArrowType.Int(32, true)))); + final Schema schema = + new Schema(Collections.singletonList(Field.nullable("ints", new ArrowType.Int(32, true)))); final List batches = new ArrayList<>(); - try (final ArrowReader source = new InMemoryArrowReader(allocator, schema, batches, - new DictionaryProvider.MapDictionaryProvider()) { - @Override - protected Schema readSchema() { - throw new IllegalArgumentException("Failed to read schema!"); - } - }; final ArrowArrayStream stream = ArrowArrayStream.allocateNew(allocator)) { + try (final ArrowReader source = + new InMemoryArrowReader( + allocator, schema, batches, new DictionaryProvider.MapDictionaryProvider()) { + @Override + protected Schema readSchema() { + throw new IllegalArgumentException("Failed to read schema!"); + } + }; + final ArrowArrayStream stream = ArrowArrayStream.allocateNew(allocator)) { Data.exportArrayStream(allocator, source, stream); try (final ArrowReader reader = Data.importArrayStream(allocator, stream)) { final IOException e = assertThrows(IOException.class, reader::getVectorSchemaRoot); @@ -219,11 +235,12 @@ protected Schema readSchema() { } } - void roundtrip(Schema schema, List batches, DictionaryProvider provider) throws Exception { + void roundtrip(Schema schema, List batches, DictionaryProvider provider) + throws Exception { ArrowReader source = new InMemoryArrowReader(allocator, schema, batches, provider); try (final ArrowArrayStream stream = ArrowArrayStream.allocateNew(allocator); - final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { + final VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator)) { final VectorLoader loader = new VectorLoader(root); Data.exportArrayStream(allocator, source, stream); @@ -260,24 +277,24 @@ void roundtrip(Schema schema, List batches) throws Exception { private static void assertVectorsEqual(FieldVector expected, FieldVector actual) { assertThat(actual.getField().getType()).isEqualTo(expected.getField().getType()); assertThat(actual.getValueCount()).isEqualTo(expected.getValueCount()); - final Range range = new Range(/*leftStart=*/0, /*rightStart=*/0, expected.getValueCount()); - assertThat(new RangeEqualsVisitor(expected, actual) - .rangeEquals(range)) + final Range range = new Range(/*leftStart=*/ 0, /*rightStart=*/ 0, expected.getValueCount()); + assertThat(new RangeEqualsVisitor(expected, actual).rangeEquals(range)) .as("Vectors were not equal.\nExpected: %s\nGot: %s", expected, actual) .isTrue(); } - /** - * An ArrowReader backed by a fixed list of batches. - */ + /** An ArrowReader backed by a fixed list of batches. */ static class InMemoryArrowReader extends ArrowReader { private final Schema schema; private final List batches; private final DictionaryProvider provider; private int nextBatch; - InMemoryArrowReader(BufferAllocator allocator, Schema schema, List batches, - DictionaryProvider provider) { + InMemoryArrowReader( + BufferAllocator allocator, + Schema schema, + List batches, + DictionaryProvider provider) { super(allocator); this.schema = schema; this.batches = batches; @@ -297,7 +314,8 @@ public Set getDictionaryIds() { @Override public Map getDictionaryVectors() { - return getDictionaryIds().stream().collect(Collectors.toMap(Function.identity(), this::lookup)); + return getDictionaryIds().stream() + .collect(Collectors.toMap(Function.identity(), this::lookup)); } @Override diff --git a/java/dataset/pom.xml b/java/dataset/pom.xml index 8723fafa8da..b34a5485593 100644 --- a/java/dataset/pom.xml +++ b/java/dataset/pom.xml @@ -9,216 +9,213 @@ 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. --> - - - arrow-java-root - org.apache.arrow - 16.0.0-SNAPSHOT - - 4.0.0 + + 4.0.0 + + org.apache.arrow + arrow-java-root + 16.0.0-SNAPSHOT + - arrow-dataset - Arrow Java Dataset - Java implementation of Arrow Dataset API/Framework - jar - - ../../../cpp/release-build/ - 2.5.0 - 1.11.0 - 1.11.3 - + arrow-dataset + jar + Arrow Java Dataset + Java implementation of Arrow Dataset API/Framework + + ../../../cpp/release-build/ + 2.5.0 + 1.11.0 + 1.11.3 + - - - org.apache.arrow - arrow-vector - compile - ${arrow.vector.classifier} - - - org.apache.arrow - arrow-memory-core - compile - - - org.apache.arrow - arrow-c-data - compile - - - org.immutables - value - - - org.apache.arrow - arrow-memory-netty - test - - - org.apache.parquet - parquet-avro - ${parquet.version} - test - - - org.apache.avro - avro - ${avro.version} - test - - - org.apache.parquet - parquet-hadoop - ${parquet.version} - test - - - org.apache.arrow - arrow-vector - ${project.version} - test - tests - - - org.apache.hadoop - hadoop-common - ${dep.hadoop.version} - test - - - commons-logging - commons-logging - - - javax.servlet - servlet-api - - - log4j - log4j - - - org.slf4j - slf4j-log4j12 - - - - - com.google.guava - guava - test - - - com.fasterxml.jackson.core - jackson-databind - test - - - org.apache.arrow.orc - arrow-orc - ${project.version} - test - - - org.apache.orc - orc-core - 1.9.2 - test - - - log4j - log4j - - - org.slf4j - slf4j-log4j12 - - - commons-logging - commons-logging - - - - - org.apache.hive - hive-storage-api - 2.8.1 - test - - - commons-io - commons-io - 2.7 - test - - - - - - ${arrow.cpp.build.dir} - - **/*arrow_dataset_jni.* - - - + + + org.apache.arrow + arrow-vector + ${arrow.vector.classifier} + compile + + + org.apache.arrow + arrow-memory-core + compile + + + org.apache.arrow + arrow-c-data + compile + + + org.immutables + value + + + org.apache.arrow + arrow-memory-netty + test + + + org.apache.parquet + parquet-avro + ${parquet.version} + test + + + org.apache.avro + avro + ${avro.version} + test + + + org.apache.parquet + parquet-hadoop + ${parquet.version} + test + + + org.apache.arrow + arrow-vector + ${project.version} + tests + test + + + org.apache.hadoop + hadoop-common + ${dep.hadoop.version} + test + + + commons-logging + commons-logging + + + javax.servlet + servlet-api + + + log4j + log4j + + + org.slf4j + slf4j-log4j12 + + + + + com.google.guava + guava + test + + + com.fasterxml.jackson.core + jackson-databind + test + + + org.apache.arrow.orc + arrow-orc + ${project.version} + test + + + org.apache.orc + orc-core + 1.9.2 + test + + + log4j + log4j + + + org.slf4j + slf4j-log4j12 + + + commons-logging + commons-logging + + + + + org.apache.hive + hive-storage-api + 2.8.1 + test + + + commons-io + commons-io + 2.7 + test + + + + + + ${arrow.cpp.build.dir} + + **/*arrow_dataset_jni.* + + + + + + maven-surefire-plugin + + false + + ${project.basedir}/../../testing/data + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} + ../../cpp/src/jni/dataset/proto + + + + + compile + test-compile + + + + + + + + + + jdk11+ + + [11,] + + !m2e.version + + + - - maven-surefire-plugin - - false - - ${project.basedir}/../../testing/data - - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.6.1 - - com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} - - ../../cpp/src/jni/dataset/proto - - - - - compile - test-compile - - - - + + org.apache.maven.plugins + maven-surefire-plugin + + false + + ${project.basedir}/../../testing/data + + --add-reads=org.apache.arrow.dataset=com.fasterxml.jackson.databind --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED + + - - - - - jdk11+ - - [11,] - - !m2e.version - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - false - - ${project.basedir}/../../testing/data - - --add-reads=org.apache.arrow.dataset=com.fasterxml.jackson.databind --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED - - - - - - + + + diff --git a/java/dataset/src/main/java/module-info.java b/java/dataset/src/main/java/module-info.java index 1672d12ffec..3092281a97e 100644 --- a/java/dataset/src/main/java/module-info.java +++ b/java/dataset/src/main/java/module-info.java @@ -1,20 +1,20 @@ /* - * 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. - */ +* 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. +*/ open module org.apache.arrow.dataset { exports org.apache.arrow.dataset.file; diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/file/DatasetFileWriter.java b/java/dataset/src/main/java/org/apache/arrow/dataset/file/DatasetFileWriter.java index b2369b853ad..9265c5e8b79 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/file/DatasetFileWriter.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/file/DatasetFileWriter.java @@ -36,15 +36,27 @@ public class DatasetFileWriter { * @param uri target file uri * @param maxPartitions maximum partitions to be included in written files * @param partitionColumns columns used to partition output files. Empty to disable partitioning - * @param baseNameTemplate file name template used to make partitions. E.g. "dat_{i}", i is current partition - * ID around all written files. + * @param baseNameTemplate file name template used to make partitions. E.g. "dat_{i}", i is + * current partition ID around all written files. */ - public static void write(BufferAllocator allocator, ArrowReader reader, FileFormat format, String uri, - String[] partitionColumns, int maxPartitions, String baseNameTemplate) { + public static void write( + BufferAllocator allocator, + ArrowReader reader, + FileFormat format, + String uri, + String[] partitionColumns, + int maxPartitions, + String baseNameTemplate) { try (final ArrowArrayStream stream = ArrowArrayStream.allocateNew(allocator)) { Data.exportArrayStream(allocator, reader, stream); - JniWrapper.get().writeFromScannerToFile(stream.memoryAddress(), - format.id(), uri, partitionColumns, maxPartitions, baseNameTemplate); + JniWrapper.get() + .writeFromScannerToFile( + stream.memoryAddress(), + format.id(), + uri, + partitionColumns, + maxPartitions, + baseNameTemplate); } } @@ -55,7 +67,8 @@ public static void write(BufferAllocator allocator, ArrowReader reader, FileForm * @param format target file format * @param uri target file uri */ - public static void write(BufferAllocator allocator, ArrowReader reader, FileFormat format, String uri) { + public static void write( + BufferAllocator allocator, ArrowReader reader, FileFormat format, String uri) { write(allocator, reader, format, uri, new String[0], 1024, "data_{i}"); } } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/file/FileFormat.java b/java/dataset/src/main/java/org/apache/arrow/dataset/file/FileFormat.java index 70a1faab79e..64cfeeb3903 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/file/FileFormat.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/file/FileFormat.java @@ -17,9 +17,7 @@ package org.apache.arrow.dataset.file; -/** - * File format definitions. - */ +/** File format definitions. */ public enum FileFormat { PARQUET(0), ARROW_IPC(1), diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/file/FileSystemDatasetFactory.java b/java/dataset/src/main/java/org/apache/arrow/dataset/file/FileSystemDatasetFactory.java index aa315690592..a2fe8daf974 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/file/FileSystemDatasetFactory.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/file/FileSystemDatasetFactory.java @@ -21,18 +21,16 @@ import org.apache.arrow.dataset.jni.NativeMemoryPool; import org.apache.arrow.memory.BufferAllocator; -/** - * Java binding of the C++ FileSystemDatasetFactory. - */ +/** Java binding of the C++ FileSystemDatasetFactory. */ public class FileSystemDatasetFactory extends NativeDatasetFactory { - public FileSystemDatasetFactory(BufferAllocator allocator, NativeMemoryPool memoryPool, FileFormat format, - String uri) { + public FileSystemDatasetFactory( + BufferAllocator allocator, NativeMemoryPool memoryPool, FileFormat format, String uri) { super(allocator, memoryPool, createNative(format, uri)); } - public FileSystemDatasetFactory(BufferAllocator allocator, NativeMemoryPool memoryPool, FileFormat format, - String[] uris) { + public FileSystemDatasetFactory( + BufferAllocator allocator, NativeMemoryPool memoryPool, FileFormat format, String[] uris) { super(allocator, memoryPool, createNative(format, uris)); } @@ -43,5 +41,4 @@ private static long createNative(FileFormat format, String uri) { private static long createNative(FileFormat format, String[] uris) { return JniWrapper.get().makeFileSystemDatasetFactory(uris, format.id()); } - } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/file/JniWrapper.java b/java/dataset/src/main/java/org/apache/arrow/dataset/file/JniWrapper.java index c3a1a4e58a1..3a7756cc434 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/file/JniWrapper.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/file/JniWrapper.java @@ -31,8 +31,7 @@ public static JniWrapper get() { return INSTANCE; } - private JniWrapper() { - } + private JniWrapper() {} /** * Create FileSystemDatasetFactory and return its native pointer. The pointer is pointing to a @@ -65,14 +64,14 @@ private JniWrapper() { * @param uri target file uri * @param partitionColumns columns used to partition output files * @param maxPartitions maximum partitions to be included in written files - * @param baseNameTemplate file name template used to make partitions. E.g. "dat_{i}", i is current partition - * ID around all written files. + * @param baseNameTemplate file name template used to make partitions. E.g. "dat_{i}", i is + * current partition ID around all written files. */ - public native void writeFromScannerToFile(long streamAddress, - long fileFormat, - String uri, - String[] partitionColumns, - int maxPartitions, - String baseNameTemplate); - + public native void writeFromScannerToFile( + long streamAddress, + long fileFormat, + String uri, + String[] partitionColumns, + int maxPartitions, + String baseNameTemplate); } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/DirectReservationListener.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/DirectReservationListener.java index 3922e90335d..7792ad458da 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/DirectReservationListener.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/DirectReservationListener.java @@ -20,12 +20,11 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicLong; - import org.apache.arrow.util.VisibleForTesting; /** - * Reserving Java direct memory bytes from java.nio.Bits. Used by Java Dataset API's C++ memory - * pool implementation. This makes memory allocated by the pool to be controlled by JVM option + * Reserving Java direct memory bytes from java.nio.Bits. Used by Java Dataset API's C++ memory pool + * implementation. This makes memory allocated by the pool to be controlled by JVM option * "-XX:MaxDirectMemorySize". */ public class DirectReservationListener implements ReservationListener { @@ -40,10 +39,12 @@ private DirectReservationListener() { methodUnreserve = this.getDeclaredMethodBaseOnJDKVersion(classBits, "unreserveMemory"); methodUnreserve.setAccessible(true); } catch (Exception e) { - final RuntimeException failure = new RuntimeException( - "Failed to initialize DirectReservationListener. When starting Java you must include " + - "`--add-opens=java.base/java.nio=org.apache.arrow.dataset,org.apache.arrow.memory.core,ALL-UNNAMED` " + - "(See https://arrow.apache.org/docs/java/install.html)", e); + final RuntimeException failure = + new RuntimeException( + "Failed to initialize DirectReservationListener. When starting Java you must include " + + "`--add-opens=java.base/java.nio=org.apache.arrow.dataset,org.apache.arrow.memory.core,ALL-UNNAMED` " + + "(See https://arrow.apache.org/docs/java/install.html)", + e); failure.printStackTrace(); throw failure; } @@ -55,14 +56,13 @@ public static DirectReservationListener instance() { return INSTANCE; } - /** - * Reserve bytes by invoking java.nio.java.Bitjava.nio.Bitss#reserveMemory. - */ + /** Reserve bytes by invoking java.nio.java.Bitjava.nio.Bitss#reserveMemory. */ @Override public void reserve(long size) { try { if (size > Integer.MAX_VALUE) { - throw new IllegalArgumentException("reserve size should not be larger than Integer.MAX_VALUE (0x7fffffff)"); + throw new IllegalArgumentException( + "reserve size should not be larger than Integer.MAX_VALUE (0x7fffffff)"); } methodReserve.invoke(null, (int) size, (int) size); } catch (Exception e) { @@ -70,14 +70,13 @@ public void reserve(long size) { } } - /** - * Unreserve bytes by invoking java.nio.java.Bitjava.nio.Bitss#unreserveMemory. - */ + /** Unreserve bytes by invoking java.nio.java.Bitjava.nio.Bitss#unreserveMemory. */ @Override public void unreserve(long size) { try { if (size > Integer.MAX_VALUE) { - throw new IllegalArgumentException("unreserve size should not be larger than Integer.MAX_VALUE (0x7fffffff)"); + throw new IllegalArgumentException( + "unreserve size should not be larger than Integer.MAX_VALUE (0x7fffffff)"); } methodUnreserve.invoke(null, (int) size, (int) size); } catch (Exception e) { @@ -85,9 +84,7 @@ public void unreserve(long size) { } } - /** - * Get current reservation of jVM direct memory. Visible for testing. - */ + /** Get current reservation of jVM direct memory. Visible for testing. */ @VisibleForTesting public long getCurrentDirectMemReservation() { try { @@ -110,7 +107,9 @@ public long getCurrentDirectMemReservation() { } /** - * Get the given method via reflection, searching for different signatures based on the Java version. + * Get the given method via reflection, searching for different signatures based on the Java + * version. + * * @param classBits The java.nio.Bits class. * @param name The method being requested. * @return The method object. diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniExceptionDescriber.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniExceptionDescriber.java index a14e35b7a83..6a20daab0eb 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniExceptionDescriber.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniExceptionDescriber.java @@ -20,16 +20,13 @@ import java.io.PrintWriter; import java.io.StringWriter; -/** - * For native code to invoke to convert a java/lang/Throwable to jstring. - */ +/** For native code to invoke to convert a java/lang/Throwable to jstring. */ class JniExceptionDescriber { - private JniExceptionDescriber() { - } + private JniExceptionDescriber() {} /** - * Convert a java/lang/Throwable to jstring. See codes in arrow::dataset::jni::CheckException - * for more details. + * Convert a java/lang/Throwable to jstring. See codes in arrow::dataset::jni::CheckException for + * more details. * * @param throwable the exception instance. * @return a String including error message and stack trace of the exception. diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniLoader.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniLoader.java index cf2f8fe29e8..62cb540e23d 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniLoader.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniLoader.java @@ -30,12 +30,11 @@ import java.util.Locale; import java.util.Set; -/** - * The JniLoader for Dataset API's native implementation. - */ +/** The JniLoader for Dataset API's native implementation. */ public final class JniLoader { - private static final JniLoader INSTANCE = new JniLoader(Collections.singletonList("arrow_dataset_jni")); + private static final JniLoader INSTANCE = + new JniLoader(Collections.singletonList("arrow_dataset_jni")); public static JniLoader get() { return INSTANCE; @@ -51,9 +50,7 @@ private boolean finished() { return librariesToLoad.isEmpty(); } - /** - * If required JNI libraries are not loaded, then load them. - */ + /** If required JNI libraries are not loaded, then load them. */ public void ensureLoaded() { if (finished()) { return; @@ -65,7 +62,8 @@ public void ensureLoaded() { private synchronized void loadRemaining() { // The method is protected by a mutex via synchronized, if more than one thread race to call // loadRemaining, at same time only one will do the actual loading and the others will wait for - // the mutex to be acquired then check on the remaining list: if there are libraries that were not + // the mutex to be acquired then check on the remaining list: if there are libraries that were + // not // successfully loaded then the mutex owner will try to load them again. if (finished()) { return; @@ -81,10 +79,11 @@ private void load(String name) { final String libraryToLoad = name + "/" + getNormalizedArch() + "/" + System.mapLibraryName(name); try { - File temp = File.createTempFile("jnilib-", ".tmp", new File(System.getProperty("java.io.tmpdir"))); + File temp = + File.createTempFile("jnilib-", ".tmp", new File(System.getProperty("java.io.tmpdir"))); temp.deleteOnExit(); - try (final InputStream is - = JniWrapper.class.getClassLoader().getResourceAsStream(libraryToLoad)) { + try (final InputStream is = + JniWrapper.class.getClassLoader().getResourceAsStream(libraryToLoad)) { if (is == null) { throw new FileNotFoundException(libraryToLoad); } @@ -112,6 +111,11 @@ private String getNormalizedArch() { } private void ensureS3FinalizedOnShutdown() { - Runtime.getRuntime().addShutdownHook(new Thread(() -> { JniWrapper.get().ensureS3Finalized(); })); + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + JniWrapper.get().ensureS3Finalized(); + })); } } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniWrapper.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniWrapper.java index 637a3e8f22a..791d88a68e9 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniWrapper.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/JniWrapper.java @@ -19,9 +19,7 @@ import java.nio.ByteBuffer; -/** - * JNI wrapper for Dataset API's native implementation. - */ +/** JNI wrapper for Dataset API's native implementation. */ public class JniWrapper { private static final JniWrapper INSTANCE = new JniWrapper(); @@ -31,8 +29,7 @@ public static JniWrapper get() { return INSTANCE; } - private JniWrapper() { - } + private JniWrapper() {} /** * Release the DatasetFactory by destroying its reference held by JNI wrapper. @@ -70,17 +67,21 @@ private JniWrapper() { * Create Scanner from a Dataset and get the native pointer of the Dataset. * * @param datasetId the native pointer of the arrow::dataset::Dataset instance. - * @param columns desired column names. - * Columns not in this list will not be emitted when performing scan operation. Null equals - * to "all columns". + * @param columns desired column names. Columns not in this list will not be emitted when + * performing scan operation. Null equals to "all columns". * @param substraitProjection substrait extended expression to evaluate for project new columns * @param substraitFilter substrait extended expression to evaluate for apply filter * @param batchSize batch size of scanned record batches. * @param memoryPool identifier of memory pool used in the native scanner. * @return the native pointer of the arrow::dataset::Scanner instance. */ - public native long createScanner(long datasetId, String[] columns, ByteBuffer substraitProjection, - ByteBuffer substraitFilter, long batchSize, long memoryPool); + public native long createScanner( + long datasetId, + String[] columns, + ByteBuffer substraitProjection, + ByteBuffer substraitFilter, + long batchSize, + long memoryPool); /** * Get a serialized schema from native instance of a Scanner. @@ -102,8 +103,8 @@ public native long createScanner(long datasetId, String[] columns, ByteBuffer su * Read next record batch from the specified scanner. * * @param scannerId the native pointer of the arrow::dataset::Scanner instance. - * @param arrowArray pointer to an empty {@link org.apache.arrow.c.ArrowArray} struct to - * store C++ side record batch that conforms to C data interface. + * @param arrowArray pointer to an empty {@link org.apache.arrow.c.ArrowArray} struct to store C++ + * side record batch that conforms to C data interface. * @return true if valid record batch is returned; false if stream ended. */ public native boolean nextRecordBatch(long scannerId, long arrowArray); @@ -116,8 +117,8 @@ public native long createScanner(long datasetId, String[] columns, ByteBuffer su public native void releaseBuffer(long bufferId); /** - * Ensure the S3 APIs are shutdown, but only if not already done. If the S3 APIs are uninitialized, - * then this is a noop. + * Ensure the S3 APIs are shutdown, but only if not already done. If the S3 APIs are + * uninitialized, then this is a noop. */ public native void ensureS3Finalized(); } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeContext.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeContext.java index 7f6dfbc028f..18e88b5aeb8 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeContext.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeContext.java @@ -19,9 +19,7 @@ import org.apache.arrow.memory.BufferAllocator; -/** - * Context for relevant classes of NativeDataset. - */ +/** Context for relevant classes of NativeDataset. */ public class NativeContext { private final BufferAllocator allocator; private final NativeMemoryPool memoryPool; @@ -37,16 +35,12 @@ public NativeContext(BufferAllocator allocator, NativeMemoryPool memoryPool) { this.memoryPool = memoryPool; } - /** - * Returns the allocator which is in use. - */ + /** Returns the allocator which is in use. */ public BufferAllocator getAllocator() { return allocator; } - /** - * Returns the native memory pool. - */ + /** Returns the native memory pool. */ public NativeMemoryPool getMemoryPool() { return memoryPool; } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeDataset.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeDataset.java index d9abad9971c..92bfb1e6291 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeDataset.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeDataset.java @@ -20,9 +20,7 @@ import org.apache.arrow.dataset.scanner.ScanOptions; import org.apache.arrow.dataset.source.Dataset; -/** - * Native implementation of {@link Dataset}. - */ +/** Native implementation of {@link Dataset}. */ public class NativeDataset implements Dataset { private final NativeContext context; @@ -41,10 +39,15 @@ public synchronized NativeScanner newScan(ScanOptions options) { throw new NativeInstanceReleasedException(); } - long scannerId = JniWrapper.get().createScanner(datasetId, options.getColumns().orElse(null), - options.getSubstraitProjection().orElse(null), - options.getSubstraitFilter().orElse(null), - options.getBatchSize(), context.getMemoryPool().getNativeInstanceId()); + long scannerId = + JniWrapper.get() + .createScanner( + datasetId, + options.getColumns().orElse(null), + options.getSubstraitProjection().orElse(null), + options.getSubstraitFilter().orElse(null), + options.getBatchSize(), + context.getMemoryPool().getNativeInstanceId()); return new NativeScanner(context, scannerId); } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeDatasetFactory.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeDatasetFactory.java index 993d44fa26f..9130eb64765 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeDatasetFactory.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeDatasetFactory.java @@ -18,15 +18,12 @@ package org.apache.arrow.dataset.jni; import java.io.IOException; - import org.apache.arrow.dataset.source.DatasetFactory; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.types.pojo.Schema; import org.apache.arrow.vector.util.SchemaUtility; -/** - * Native implementation of {@link DatasetFactory}. - */ +/** Native implementation of {@link DatasetFactory}. */ public class NativeDatasetFactory implements DatasetFactory { private final long datasetFactoryId; private final NativeMemoryPool memoryPool; @@ -37,17 +34,19 @@ public class NativeDatasetFactory implements DatasetFactory { /** * Constructor. * - * @param allocator a context allocator associated with this factory. Any buffer that will be created natively will - * be then bound to this allocator. - * @param memoryPool the native memory pool associated with this factory. Any buffer created natively should request - * for memory spaces from this memory pool. This is a mapped instance of c++ arrow::MemoryPool. - * @param datasetFactoryId an ID, at the same time the native pointer of the underlying native instance of this - * factory. Make sure in c++ side the pointer is pointing to the shared pointer wrapping - * the actual instance so we could successfully decrease the reference count once - * {@link #close} is called. + * @param allocator a context allocator associated with this factory. Any buffer that will be + * created natively will be then bound to this allocator. + * @param memoryPool the native memory pool associated with this factory. Any buffer created + * natively should request for memory spaces from this memory pool. This is a mapped instance + * of c++ arrow::MemoryPool. + * @param datasetFactoryId an ID, at the same time the native pointer of the underlying native + * instance of this factory. Make sure in c++ side the pointer is pointing to the shared + * pointer wrapping the actual instance so we could successfully decrease the reference count + * once {@link #close} is called. * @see #close() */ - public NativeDatasetFactory(BufferAllocator allocator, NativeMemoryPool memoryPool, long datasetFactoryId) { + public NativeDatasetFactory( + BufferAllocator allocator, NativeMemoryPool memoryPool, long datasetFactoryId) { this.allocator = allocator; this.memoryPool = memoryPool; this.datasetFactoryId = datasetFactoryId; @@ -82,7 +81,8 @@ public NativeDataset finish(Schema schema) { if (closed) { throw new NativeInstanceReleasedException(); } - return new NativeDataset(new NativeContext(allocator, memoryPool), + return new NativeDataset( + new NativeContext(allocator, memoryPool), JniWrapper.get().createDataset(datasetFactoryId, serialized)); } } catch (IOException e) { @@ -90,9 +90,7 @@ public NativeDataset finish(Schema schema) { } } - /** - * Close this factory by release the pointer of the native instance. - */ + /** Close this factory by release the pointer of the native instance. */ @Override public synchronized void close() { if (closed) { diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeInstanceReleasedException.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeInstanceReleasedException.java index 3231ca23abe..629ec898b4d 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeInstanceReleasedException.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeInstanceReleasedException.java @@ -17,9 +17,7 @@ package org.apache.arrow.dataset.jni; -/** - * Thrown if trying to operate on a native instance that is already released. - */ +/** Thrown if trying to operate on a native instance that is already released. */ public class NativeInstanceReleasedException extends RuntimeException { public NativeInstanceReleasedException() { super("Native instance has been released"); diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeMemoryPool.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeMemoryPool.java index e20e1e351c5..3339c4c9067 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeMemoryPool.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeMemoryPool.java @@ -17,9 +17,7 @@ package org.apache.arrow.dataset.jni; -/** - * C++ memory pool(arrow::MemoryPool)'s Java mapped instance. - */ +/** C++ memory pool(arrow::MemoryPool)'s Java mapped instance. */ public class NativeMemoryPool implements AutoCloseable { private final long nativeInstanceId; @@ -27,34 +25,28 @@ private NativeMemoryPool(long nativeInstanceId) { this.nativeInstanceId = nativeInstanceId; } - /** - * Get the default memory pool. This will return arrow::default_memory_pool() directly. - */ + /** Get the default memory pool. This will return arrow::default_memory_pool() directly. */ public static NativeMemoryPool getDefault() { JniLoader.get().ensureLoaded(); return new NativeMemoryPool(getDefaultMemoryPool()); } /** - * Create a listenable memory pool (see also: arrow::ReservationListenableMemoryPool) with - * a specific listener. All buffers created from the memory pool should take enough reservation - * from the listener in advance. + * Create a listenable memory pool (see also: arrow::ReservationListenableMemoryPool) with a + * specific listener. All buffers created from the memory pool should take enough reservation from + * the listener in advance. */ public static NativeMemoryPool createListenable(ReservationListener listener) { JniLoader.get().ensureLoaded(); return new NativeMemoryPool(createListenableMemoryPool(listener)); } - /** - * Return native instance ID of this memory pool. - */ + /** Return native instance ID of this memory pool. */ public long getNativeInstanceId() { return nativeInstanceId; } - /** - * Get current allocated bytes. - */ + /** Get current allocated bytes. */ public long getBytesAllocated() { return bytesAllocated(nativeInstanceId); } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeScanTask.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeScanTask.java index 7747dd60340..cd17348fb0d 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeScanTask.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeScanTask.java @@ -21,17 +21,16 @@ import org.apache.arrow.vector.ipc.ArrowReader; /** - * Native implementation of {@link ScanTask}. Currently RecordBatches are iterated directly by the scanner - * id via {@link JniWrapper}, thus we allow only one-time execution of method {@link #execute()}. If a re-scan - * operation is expected, call {@link NativeDataset#newScan} to create a new scanner instance. + * Native implementation of {@link ScanTask}. Currently RecordBatches are iterated directly by the + * scanner id via {@link JniWrapper}, thus we allow only one-time execution of method {@link + * #execute()}. If a re-scan operation is expected, call {@link NativeDataset#newScan} to create a + * new scanner instance. */ @Deprecated public class NativeScanTask implements ScanTask { private final NativeScanner scanner; - /** - * Constructor. - */ + /** Constructor. */ public NativeScanTask(NativeScanner scanner) { this.scanner = scanner; } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeScanner.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeScanner.java index 8ca8e5cf50e..574ea075a5f 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeScanner.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/NativeScanner.java @@ -23,7 +23,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; - import org.apache.arrow.c.ArrowArray; import org.apache.arrow.c.Data; import org.apache.arrow.dataset.scanner.Scanner; @@ -36,9 +35,9 @@ import org.apache.arrow.vector.util.SchemaUtility; /** - * Native implementation of {@link Scanner}. Note that it currently emits only a single scan task of type - * {@link NativeScanTask}, which is internally a combination of all scan task instances returned by the - * native scanner. + * Native implementation of {@link Scanner}. Note that it currently emits only a single scan task of + * type {@link NativeScanTask}, which is internally a combination of all scan task instances + * returned by the native scanner. */ public class NativeScanner implements Scanner { @@ -61,8 +60,9 @@ ArrowReader execute() { throw new NativeInstanceReleasedException(); } if (!executed.compareAndSet(false, true)) { - throw new UnsupportedOperationException("NativeScanner cannot be executed more than once. Consider creating " + - "new scanner instead"); + throw new UnsupportedOperationException( + "NativeScanner cannot be executed more than once. Consider creating " + + "new scanner instead"); } return new NativeReader(context.getAllocator()); } @@ -73,8 +73,8 @@ public ArrowReader scanBatches() { throw new NativeInstanceReleasedException(); } if (!executed.compareAndSet(false, true)) { - throw new UnsupportedOperationException("NativeScanner can only be executed once. Create a " + - "new scanner instead"); + throw new UnsupportedOperationException( + "NativeScanner can only be executed once. Create a " + "new scanner instead"); } return new NativeReader(context.getAllocator()); } @@ -95,7 +95,8 @@ public Schema schema() { if (closed) { throw new NativeInstanceReleasedException(); } - return SchemaUtility.deserialize(JniWrapper.get().getSchemaFromScanner(scannerId), context.getAllocator()); + return SchemaUtility.deserialize( + JniWrapper.get().getSchemaFromScanner(scannerId), context.getAllocator()); } catch (IOException e) { throw new RuntimeException(e); } finally { @@ -117,9 +118,7 @@ public void close() { } } - /** - * {@link ArrowReader} implementation for NativeDataset. - */ + /** {@link ArrowReader} implementation for NativeDataset. */ public class NativeReader extends ArrowReader { private NativeReader(BufferAllocator allocator) { diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/ReservationListener.java b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/ReservationListener.java index f1ffdd2acbd..858bba2020d 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/jni/ReservationListener.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/jni/ReservationListener.java @@ -17,9 +17,7 @@ package org.apache.arrow.dataset.jni; -/** - * Listener of buffer memory reservation. Used by native datasets. - */ +/** Listener of buffer memory reservation. Used by native datasets. */ public interface ReservationListener { /** @@ -29,8 +27,6 @@ public interface ReservationListener { */ void reserve(long size); - /** - * Unreserve bytes. - */ + /** Unreserve bytes. */ void unreserve(long size); } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ArrowScannerReader.java b/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ArrowScannerReader.java index 417ba837a3b..e5853500c56 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ArrowScannerReader.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ArrowScannerReader.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.util.Iterator; - import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.VectorLoader; import org.apache.arrow.vector.VectorUnloader; @@ -28,10 +27,7 @@ import org.apache.arrow.vector.ipc.message.ArrowRecordBatch; import org.apache.arrow.vector.types.pojo.Schema; -/** - * An implementation of {@link ArrowReader} that reads - * the dataset from {@link Scanner}. - */ +/** An implementation of {@link ArrowReader} that reads the dataset from {@link Scanner}. */ public class ArrowScannerReader extends ArrowReader { private final Scanner scanner; @@ -93,8 +89,7 @@ public boolean loadNextBatch() throws IOException { } VectorLoader loader = new VectorLoader(this.getVectorSchemaRoot()); - VectorUnloader unloader = - new VectorUnloader(currentReader.getVectorSchemaRoot()); + VectorUnloader unloader = new VectorUnloader(currentReader.getVectorSchemaRoot()); try (ArrowRecordBatch recordBatch = unloader.getRecordBatch()) { loader.load(recordBatch); } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ScanOptions.java b/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ScanOptions.java index 995d05ac3b3..1579771e863 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ScanOptions.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ScanOptions.java @@ -19,12 +19,9 @@ import java.nio.ByteBuffer; import java.util.Optional; - import org.apache.arrow.util.Preconditions; -/** - * Options used during scanning. - */ +/** Options used during scanning. */ public class ScanOptions { private final long batchSize; private final Optional columns; @@ -33,27 +30,35 @@ public class ScanOptions { /** * Constructor. - * @param columns Projected columns. Empty for scanning all columns. - * @param batchSize Maximum row number of each returned {@link org.apache.arrow.vector.ipc.message.ArrowRecordBatch} * + * @param columns Projected columns. Empty for scanning all columns. + * @param batchSize Maximum row number of each returned {@link + * org.apache.arrow.vector.ipc.message.ArrowRecordBatch} * @deprecated Deprecated. Use {@link #ScanOptions(long, Optional)} instead. */ @Deprecated public ScanOptions(String[] columns, long batchSize) { - this(batchSize, Optional.of(columns).map(present -> { - if (present.length == 0) { - // Backwards compatibility: See ARROW-13257, in the new constructor, we now use null to scan for all columns. - return null; - } - return present; - })); + this( + batchSize, + Optional.of(columns) + .map( + present -> { + if (present.length == 0) { + // Backwards compatibility: See ARROW-13257, in the new constructor, we now use + // null to scan for all columns. + return null; + } + return present; + })); } /** * Constructor. - * @param batchSize Maximum row number of each returned {@link org.apache.arrow.vector.ipc.message.ArrowRecordBatch} - * @param columns (Optional) Projected columns. {@link Optional#empty()} for scanning all columns. Otherwise, - * Only columns present in the Array will be scanned. + * + * @param batchSize Maximum row number of each returned {@link + * org.apache.arrow.vector.ipc.message.ArrowRecordBatch} + * @param columns (Optional) Projected columns. {@link Optional#empty()} for scanning all columns. + * Otherwise, Only columns present in the Array will be scanned. */ public ScanOptions(long batchSize, Optional columns) { Preconditions.checkNotNull(columns); @@ -83,9 +88,7 @@ public Optional getSubstraitFilter() { return substraitFilter; } - /** - * Builder for Options used during scanning. - */ + /** Builder for Options used during scanning. */ public static class Builder { private final long batchSize; private Optional columns; @@ -94,7 +97,9 @@ public static class Builder { /** * Constructor. - * @param batchSize Maximum row number of each returned {@link org.apache.arrow.vector.ipc.message.ArrowRecordBatch} + * + * @param batchSize Maximum row number of each returned {@link + * org.apache.arrow.vector.ipc.message.ArrowRecordBatch} */ public Builder(long batchSize) { this.batchSize = batchSize; diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ScanTask.java b/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ScanTask.java index 16b8aeefb61..5a6058cb6c4 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ScanTask.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/ScanTask.java @@ -18,19 +18,15 @@ package org.apache.arrow.dataset.scanner; import java.io.Reader; - import org.apache.arrow.vector.ipc.ArrowReader; /** - * Read record batches from a range of a single data fragment. A - * ScanTask is meant to be a unit of work to be dispatched. The implementation - * must be thread and concurrent safe. + * Read record batches from a range of a single data fragment. A ScanTask is meant to be a unit of + * work to be dispatched. The implementation must be thread and concurrent safe. */ @Deprecated public interface ScanTask extends AutoCloseable { - /** - * Execute this ScanTask and return a {@link Reader} instance. - */ + /** Execute this ScanTask and return a {@link Reader} instance. */ ArrowReader execute(); } diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/Scanner.java b/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/Scanner.java index 43749b7db8e..c066d266cf4 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/Scanner.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/scanner/Scanner.java @@ -20,9 +20,7 @@ import org.apache.arrow.vector.ipc.ArrowReader; import org.apache.arrow.vector.types.pojo.Schema; -/** - * A high level interface for scanning data over dataset. - */ +/** A high level interface for scanning data over dataset. */ public interface Scanner extends AutoCloseable { /** @@ -35,8 +33,8 @@ public interface Scanner extends AutoCloseable { /** * Perform the scan operation. * - * @return a iterable set of {@link ScanTask}s. Each task is considered independent and it is allowed - * to execute the tasks concurrently to gain better performance. + * @return a iterable set of {@link ScanTask}s. Each task is considered independent and it is + * allowed to execute the tasks concurrently to gain better performance. * @deprecated use {@link #scanBatches()} instead. */ @Deprecated diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/source/Dataset.java b/java/dataset/src/main/java/org/apache/arrow/dataset/source/Dataset.java index ce193581f40..da5b721ac8b 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/source/Dataset.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/source/Dataset.java @@ -20,9 +20,7 @@ import org.apache.arrow.dataset.scanner.ScanOptions; import org.apache.arrow.dataset.scanner.Scanner; -/** - * A container of Fragments which are the internal iterable unit of read data. - */ +/** A container of Fragments which are the internal iterable unit of read data. */ public interface Dataset extends AutoCloseable { /** diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/source/DatasetFactory.java b/java/dataset/src/main/java/org/apache/arrow/dataset/source/DatasetFactory.java index 46b8545d662..88ea08bf51e 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/source/DatasetFactory.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/source/DatasetFactory.java @@ -20,9 +20,8 @@ import org.apache.arrow.vector.types.pojo.Schema; /** - * DatasetFactory provides a way to inspect a Dataset potential - * schema before materializing it. Thus, the user can peek the schema for - * data sources and decide on a unified schema. + * DatasetFactory provides a way to inspect a Dataset potential schema before materializing it. + * Thus, the user can peek the schema for data sources and decide on a unified schema. */ public interface DatasetFactory extends AutoCloseable { @@ -34,8 +33,8 @@ public interface DatasetFactory extends AutoCloseable { Schema inspect(); /** - * Create a Dataset with auto-inferred schema. Which means, the schema of the resulting Dataset will be - * the same with calling {@link #inspect()} manually. + * Create a Dataset with auto-inferred schema. Which means, the schema of the resulting Dataset + * will be the same with calling {@link #inspect()} manually. * * @return the Dataset instance */ diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/substrait/AceroSubstraitConsumer.java b/java/dataset/src/main/java/org/apache/arrow/dataset/substrait/AceroSubstraitConsumer.java index d5a29ad4e93..44ff9d7ed53 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/substrait/AceroSubstraitConsumer.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/substrait/AceroSubstraitConsumer.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; - import org.apache.arrow.c.ArrowArrayStream; import org.apache.arrow.c.Data; import org.apache.arrow.memory.BufferAllocator; @@ -30,8 +29,8 @@ import org.apache.arrow.vector.ipc.ArrowReader; /** - * Class to expose Java Substrait API for end users, currently operations supported are only to Consume Substrait Plan - * in Plan format (JSON) or Binary format (ByteBuffer). + * Class to expose Java Substrait API for end users, currently operations supported are only to + * Consume Substrait Plan in Plan format (JSON) or Binary format (ByteBuffer). */ public final class AceroSubstraitConsumer { private final BufferAllocator allocator; @@ -54,11 +53,13 @@ public ArrowReader runQuery(String plan) throws Exception { * Run Substrait plan. * * @param plan The JSON Substrait plan. - * @param namedTables A mapping of named tables referenced by the plan to an ArrowReader providing the data - * for the table. Contains the Table Name to Query as a Key and ArrowReader as a Value. - *

{@code ArrowReader nationReader = scanner.scanBatches();
+   * @param namedTables A mapping of named tables referenced by the plan to an ArrowReader providing
+   *     the data for the table. Contains the Table Name to Query as a Key and ArrowReader as a
+   *     Value.
+   *     
{@code ArrowReader nationReader = scanner.scanBatches();
    * Map namedTables = new HashMap<>();
    * namedTables.put("NATION", nationReader);}
+ * * @return the ArrowReader to iterate for record batches. */ public ArrowReader runQuery(String plan, Map namedTables) throws Exception { @@ -68,7 +69,7 @@ public ArrowReader runQuery(String plan, Map namedTables) t /** * Run Substrait plan. * - * @param plan the binary Substrait plan. + * @param plan the binary Substrait plan. * @return the ArrowReader to iterate for record batches. */ public ArrowReader runQuery(ByteBuffer plan) throws Exception { @@ -76,56 +77,51 @@ public ArrowReader runQuery(ByteBuffer plan) throws Exception { } /** - * Read binary Substrait plan, execute and return an ArrowReader to read Schema and ArrowRecordBatches. + * Read binary Substrait plan, execute and return an ArrowReader to read Schema and + * ArrowRecordBatches. * - * @param plan the binary Substrait plan. - * @param namedTables A mapping of named tables referenced by the plan to an ArrowReader providing the data - * for the table. Contains the Table Name to Query as a Key and ArrowReader as a Value. - *
{@code ArrowReader nationReader = scanner.scanBatches();
+   * @param plan the binary Substrait plan.
+   * @param namedTables A mapping of named tables referenced by the plan to an ArrowReader providing
+   *     the data for the table. Contains the Table Name to Query as a Key and ArrowReader as a
+   *     Value.
+   *     
{@code ArrowReader nationReader = scanner.scanBatches();
    * Map namedTables = new HashMap<>();
    * namedTables.put("NATION", nationReader);}
+ * * @return the ArrowReader to iterate for record batches. */ - public ArrowReader runQuery(ByteBuffer plan, Map namedTables) throws Exception { + public ArrowReader runQuery(ByteBuffer plan, Map namedTables) + throws Exception { return execute(plan, namedTables); } private ArrowReader execute(String plan, Map namedTables) throws Exception { List arrowArrayStream = new ArrayList<>(); - try ( - ArrowArrayStream streamOutput = ArrowArrayStream.allocateNew(this.allocator) - ) { + try (ArrowArrayStream streamOutput = ArrowArrayStream.allocateNew(this.allocator)) { String[] mapTableToMemoryAddress = getMapTableToMemoryAddress(namedTables, arrowArrayStream); - JniWrapper.get().executeSerializedPlan( - plan, - mapTableToMemoryAddress, - streamOutput.memoryAddress() - ); + JniWrapper.get() + .executeSerializedPlan(plan, mapTableToMemoryAddress, streamOutput.memoryAddress()); return Data.importArrayStream(this.allocator, streamOutput); } finally { AutoCloseables.close(arrowArrayStream); } } - private ArrowReader execute(ByteBuffer plan, Map namedTables) throws Exception { + private ArrowReader execute(ByteBuffer plan, Map namedTables) + throws Exception { List arrowArrayStream = new ArrayList<>(); - try ( - ArrowArrayStream streamOutput = ArrowArrayStream.allocateNew(this.allocator) - ) { + try (ArrowArrayStream streamOutput = ArrowArrayStream.allocateNew(this.allocator)) { String[] mapTableToMemoryAddress = getMapTableToMemoryAddress(namedTables, arrowArrayStream); - JniWrapper.get().executeSerializedPlan( - plan, - mapTableToMemoryAddress, - streamOutput.memoryAddress() - ); + JniWrapper.get() + .executeSerializedPlan(plan, mapTableToMemoryAddress, streamOutput.memoryAddress()); return Data.importArrayStream(this.allocator, streamOutput); } finally { AutoCloseables.close(arrowArrayStream); } } - private String[] getMapTableToMemoryAddress(Map mapTableToArrowReader, - List listStreamInput) { + private String[] getMapTableToMemoryAddress( + Map mapTableToArrowReader, List listStreamInput) { String[] mapTableToMemoryAddress = new String[mapTableToArrowReader.size() * 2]; ArrowArrayStream streamInput; int pos = 0; diff --git a/java/dataset/src/main/java/org/apache/arrow/dataset/substrait/JniWrapper.java b/java/dataset/src/main/java/org/apache/arrow/dataset/substrait/JniWrapper.java index 5cb68f85146..436abee6351 100644 --- a/java/dataset/src/main/java/org/apache/arrow/dataset/substrait/JniWrapper.java +++ b/java/dataset/src/main/java/org/apache/arrow/dataset/substrait/JniWrapper.java @@ -18,12 +18,13 @@ package org.apache.arrow.dataset.substrait; import java.nio.ByteBuffer; - import org.apache.arrow.dataset.jni.JniLoader; /** - * Class that contains Native methods to call Acero C++ Substrait API. It internally depends on C++ function - * arrow::engine::ExecuteSerializedPlan. Currently supported input parameters supported are: + * Class that contains Native methods to call Acero C++ Substrait API. It internally depends on C++ + * function arrow::engine::ExecuteSerializedPlan. Currently supported input parameters supported + * are: + * *
  * - arrow::Buffer: Substrait Plan (JSON or Binary format).
  * - arrow::engine::ConversionOptions: Mapping for arrow::engine::NamedTableProvider.
@@ -32,8 +33,7 @@
 final class JniWrapper {
   private static final JniWrapper INSTANCE = new JniWrapper();
 
-  private JniWrapper() {
-  }
+  private JniWrapper() {}
 
   public static JniWrapper get() {
     JniLoader.get().ensureLoaded();
@@ -41,33 +41,34 @@ public static JniWrapper get() {
   }
 
   /**
-   * Consume the JSON Substrait Plan that contains Named Tables and export the RecordBatchReader into
-   * C-Data Interface ArrowArrayStream.
+   * Consume the JSON Substrait Plan that contains Named Tables and export the RecordBatchReader
+   * into C-Data Interface ArrowArrayStream.
    *
    * @param planInput the JSON Substrait plan.
-   * @param mapTableToMemoryAddressInput the mapping name of Tables Name on position `i` and theirs Memory Address
-   *                                     representation on `i+1` position linearly.
-   * 
{@code String[] mapTableToMemoryAddress = new String[2];
+   * @param mapTableToMemoryAddressInput the mapping name of Tables Name on position `i` and theirs
+   *     Memory Address representation on `i+1` position linearly.
+   *     
{@code String[] mapTableToMemoryAddress = new String[2];
    * mapTableToMemoryAddress[0]="NATION";
    * mapTableToMemoryAddress[1]="140650250895360";}
- * @param memoryAddressOutput the memory address where RecordBatchReader is exported. * + * @param memoryAddressOutput the memory address where RecordBatchReader is exported. */ - public native void executeSerializedPlan(String planInput, String[] mapTableToMemoryAddressInput, - long memoryAddressOutput); + public native void executeSerializedPlan( + String planInput, String[] mapTableToMemoryAddressInput, long memoryAddressOutput); /** - * Consume the binary Substrait Plan that contains Named Tables and export the RecordBatchReader into - * C-Data Interface ArrowArrayStream. + * Consume the binary Substrait Plan that contains Named Tables and export the RecordBatchReader + * into C-Data Interface ArrowArrayStream. * * @param planInput the binary Substrait plan. - * @param mapTableToMemoryAddressInput the mapping name of Tables Name on position `i` and theirs Memory Address - * representation on `i+1` position linearly. - *
{@code String[] mapTableToMemoryAddress = new String[2];
+   * @param mapTableToMemoryAddressInput the mapping name of Tables Name on position `i` and theirs
+   *     Memory Address representation on `i+1` position linearly.
+   *     
{@code String[] mapTableToMemoryAddress = new String[2];
    * mapTableToMemoryAddress[0]="NATION";
    * mapTableToMemoryAddress[1]="140650250895360";}
+ * * @param memoryAddressOutput the memory address where RecordBatchReader is exported. */ - public native void executeSerializedPlan(ByteBuffer planInput, String[] mapTableToMemoryAddressInput, - long memoryAddressOutput); + public native void executeSerializedPlan( + ByteBuffer planInput, String[] mapTableToMemoryAddressInput, long memoryAddressOutput); } diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/OrcWriteSupport.java b/java/dataset/src/test/java/org/apache/arrow/dataset/OrcWriteSupport.java index c49612995ee..66c117d6322 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/OrcWriteSupport.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/OrcWriteSupport.java @@ -18,7 +18,6 @@ package org.apache.arrow.dataset; import java.io.IOException; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector; @@ -28,8 +27,10 @@ import org.apache.orc.Writer; public class OrcWriteSupport { - public static void writeTempFile(TypeDescription orcSchema, Path path, Integer[] values) throws IOException { - Writer writer = OrcFile.createWriter(path, OrcFile.writerOptions(new Configuration()).setSchema(orcSchema)); + public static void writeTempFile(TypeDescription orcSchema, Path path, Integer[] values) + throws IOException { + Writer writer = + OrcFile.createWriter(path, OrcFile.writerOptions(new Configuration()).setSchema(orcSchema)); VectorizedRowBatch batch = orcSchema.createRowBatch(); LongColumnVector longColumnVector = (LongColumnVector) batch.cols[0]; for (int idx = 0; idx < values.length; idx++) { diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/ParquetWriteSupport.java b/java/dataset/src/test/java/org/apache/arrow/dataset/ParquetWriteSupport.java index 2352a65e8fb..90ac0b3b76a 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/ParquetWriteSupport.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/ParquetWriteSupport.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.List; import java.util.Random; - import org.apache.arrow.util.Preconditions; import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; @@ -32,9 +31,7 @@ import org.apache.parquet.avro.AvroParquetWriter; import org.apache.parquet.hadoop.ParquetWriter; -/** - * Utility class for writing Parquet files using Avro based tools. - */ +/** Utility class for writing Parquet files using Avro based tools. */ public class ParquetWriteSupport implements AutoCloseable { private final String path; @@ -45,39 +42,42 @@ public class ParquetWriteSupport implements AutoCloseable { private final GenericRecordListBuilder recordListBuilder = new GenericRecordListBuilder(); private final Random random = new Random(); - public ParquetWriteSupport(String schemaName, File outputFolder) throws Exception { avroSchema = getSchema(schemaName); path = outputFolder.getPath() + "/" + "generated-" + random.nextLong() + ".parquet"; uri = "file://" + path; - writer = AvroParquetWriter - .builder(new org.apache.hadoop.fs.Path(path)) - .withSchema(avroSchema) - .build(); + writer = + AvroParquetWriter.builder(new org.apache.hadoop.fs.Path(path)) + .withSchema(avroSchema) + .build(); } public static Schema getSchema(String schemaName) throws Exception { try { - // Attempt to use JDK 9 behavior of getting the module then the resource stream from the module. + // Attempt to use JDK 9 behavior of getting the module then the resource stream from the + // module. // Note that this code is caller-sensitive. Method getModuleMethod = Class.class.getMethod("getModule"); Object module = getModuleMethod.invoke(ParquetWriteSupport.class); - Method getResourceAsStreamFromModule = module.getClass().getMethod("getResourceAsStream", String.class); - try (InputStream is = (InputStream) getResourceAsStreamFromModule.invoke(module, "/avroschema/" + schemaName)) { - return new Schema.Parser() - .parse(is); + Method getResourceAsStreamFromModule = + module.getClass().getMethod("getResourceAsStream", String.class); + try (InputStream is = + (InputStream) getResourceAsStreamFromModule.invoke(module, "/avroschema/" + schemaName)) { + return new Schema.Parser().parse(is); } } catch (NoSuchMethodException ex) { // Use JDK8 behavior. - try (InputStream is = ParquetWriteSupport.class.getResourceAsStream("/avroschema/" + schemaName)) { + try (InputStream is = + ParquetWriteSupport.class.getResourceAsStream("/avroschema/" + schemaName)) { return new Schema.Parser().parse(is); } } } - public static ParquetWriteSupport writeTempFile(String schemaName, File outputFolder, - Object... values) throws Exception { - try (final ParquetWriteSupport writeSupport = new ParquetWriteSupport(schemaName, outputFolder)) { + public static ParquetWriteSupport writeTempFile( + String schemaName, File outputFolder, Object... values) throws Exception { + try (final ParquetWriteSupport writeSupport = + new ParquetWriteSupport(schemaName, outputFolder)) { writeSupport.writeRecords(values); return writeSupport; } @@ -123,8 +123,8 @@ public void close() throws Exception { public class GenericRecordListBuilder { public final List createRecordList(Object... values) { final int fieldCount = avroSchema.getFields().size(); - Preconditions.checkArgument(values.length % fieldCount == 0, - "arg count of values should be divide by field number"); + Preconditions.checkArgument( + values.length % fieldCount == 0, "arg count of values should be divide by field number"); final List recordList = new ArrayList<>(); for (int i = 0; i < values.length / fieldCount; i++) { final GenericRecord record = new GenericData.Record(avroSchema); diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/TestAllTypes.java b/java/dataset/src/test/java/org/apache/arrow/dataset/TestAllTypes.java index 13b24745234..56eb032e34f 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/TestAllTypes.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/TestAllTypes.java @@ -28,7 +28,6 @@ import java.util.Collections; import java.util.List; import java.util.Objects; - import org.apache.arrow.dataset.file.DatasetFileWriter; import org.apache.arrow.dataset.file.FileFormat; import org.apache.arrow.memory.BufferAllocator; @@ -84,56 +83,72 @@ public class TestAllTypes extends TestDataset { - @ClassRule - public static final TemporaryFolder TMP = new TemporaryFolder(); + @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); private VectorSchemaRoot generateAllTypesVector(BufferAllocator allocator) { // Notes: // - Float16 is not supported by Java. // - IntervalMonthDayNano is not supported by Parquet. - // - Map (GH-38250) and SparseUnion are resulting in serialization errors when writing with the Dataset API. - // "Unhandled type for Arrow to Parquet schema conversion" errors: IntervalDay, IntervalYear, DenseUnion + // - Map (GH-38250) and SparseUnion are resulting in serialization errors when writing with the + // Dataset API. + // "Unhandled type for Arrow to Parquet schema conversion" errors: IntervalDay, IntervalYear, + // DenseUnion List childFields = new ArrayList<>(); - childFields.add(new Field("int-child", - new FieldType(false, new ArrowType.Int(32, true), null, null), null)); - Field structField = new Field("struct", - new FieldType(true, ArrowType.Struct.INSTANCE, null, null), childFields); - Field[] fields = new Field[] { - Field.nullablePrimitive("null", ArrowType.Null.INSTANCE), - Field.nullablePrimitive("bool", ArrowType.Bool.INSTANCE), - Field.nullablePrimitive("int8", new ArrowType.Int(8, true)), - Field.nullablePrimitive("int16", new ArrowType.Int(16, true)), - Field.nullablePrimitive("int32", new ArrowType.Int(32, true)), - Field.nullablePrimitive("int64", new ArrowType.Int(64, true)), - Field.nullablePrimitive("uint8", new ArrowType.Int(8, false)), - Field.nullablePrimitive("uint16", new ArrowType.Int(16, false)), - Field.nullablePrimitive("uint32", new ArrowType.Int(32, false)), - Field.nullablePrimitive("uint64", new ArrowType.Int(64, false)), - Field.nullablePrimitive("float32", new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), - Field.nullablePrimitive("float64", new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), - Field.nullablePrimitive("utf8", ArrowType.Utf8.INSTANCE), - Field.nullablePrimitive("binary", ArrowType.Binary.INSTANCE), - Field.nullablePrimitive("largeutf8", ArrowType.LargeUtf8.INSTANCE), - Field.nullablePrimitive("largebinary", ArrowType.LargeBinary.INSTANCE), - Field.nullablePrimitive("fixed_size_binary", new ArrowType.FixedSizeBinary(1)), - Field.nullablePrimitive("date_ms", new ArrowType.Date(DateUnit.MILLISECOND)), - Field.nullablePrimitive("time_ms", new ArrowType.Time(TimeUnit.MILLISECOND, 32)), - Field.nullablePrimitive("timestamp_ms", new ArrowType.Timestamp(TimeUnit.MILLISECOND, null)), - Field.nullablePrimitive("timestamptz_ms", new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC")), - Field.nullablePrimitive("time_ns", new ArrowType.Time(TimeUnit.NANOSECOND, 64)), - Field.nullablePrimitive("timestamp_ns", new ArrowType.Timestamp(TimeUnit.NANOSECOND, null)), - Field.nullablePrimitive("timestamptz_ns", new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC")), - Field.nullablePrimitive("duration", new ArrowType.Duration(TimeUnit.MILLISECOND)), - Field.nullablePrimitive("decimal128", new ArrowType.Decimal(10, 2, 128)), - Field.nullablePrimitive("decimal256", new ArrowType.Decimal(10, 2, 256)), - new Field("list", FieldType.nullable(ArrowType.List.INSTANCE), - Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), - new Field("largelist", FieldType.nullable(ArrowType.LargeList.INSTANCE), - Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), - new Field("fixedsizelist", FieldType.nullable(new ArrowType.FixedSizeList(2)), - Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), - structField - }; + childFields.add( + new Field( + "int-child", new FieldType(false, new ArrowType.Int(32, true), null, null), null)); + Field structField = + new Field( + "struct", new FieldType(true, ArrowType.Struct.INSTANCE, null, null), childFields); + Field[] fields = + new Field[] { + Field.nullablePrimitive("null", ArrowType.Null.INSTANCE), + Field.nullablePrimitive("bool", ArrowType.Bool.INSTANCE), + Field.nullablePrimitive("int8", new ArrowType.Int(8, true)), + Field.nullablePrimitive("int16", new ArrowType.Int(16, true)), + Field.nullablePrimitive("int32", new ArrowType.Int(32, true)), + Field.nullablePrimitive("int64", new ArrowType.Int(64, true)), + Field.nullablePrimitive("uint8", new ArrowType.Int(8, false)), + Field.nullablePrimitive("uint16", new ArrowType.Int(16, false)), + Field.nullablePrimitive("uint32", new ArrowType.Int(32, false)), + Field.nullablePrimitive("uint64", new ArrowType.Int(64, false)), + Field.nullablePrimitive( + "float32", new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), + Field.nullablePrimitive( + "float64", new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), + Field.nullablePrimitive("utf8", ArrowType.Utf8.INSTANCE), + Field.nullablePrimitive("binary", ArrowType.Binary.INSTANCE), + Field.nullablePrimitive("largeutf8", ArrowType.LargeUtf8.INSTANCE), + Field.nullablePrimitive("largebinary", ArrowType.LargeBinary.INSTANCE), + Field.nullablePrimitive("fixed_size_binary", new ArrowType.FixedSizeBinary(1)), + Field.nullablePrimitive("date_ms", new ArrowType.Date(DateUnit.MILLISECOND)), + Field.nullablePrimitive("time_ms", new ArrowType.Time(TimeUnit.MILLISECOND, 32)), + Field.nullablePrimitive( + "timestamp_ms", new ArrowType.Timestamp(TimeUnit.MILLISECOND, null)), + Field.nullablePrimitive( + "timestamptz_ms", new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC")), + Field.nullablePrimitive("time_ns", new ArrowType.Time(TimeUnit.NANOSECOND, 64)), + Field.nullablePrimitive( + "timestamp_ns", new ArrowType.Timestamp(TimeUnit.NANOSECOND, null)), + Field.nullablePrimitive( + "timestamptz_ns", new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC")), + Field.nullablePrimitive("duration", new ArrowType.Duration(TimeUnit.MILLISECOND)), + Field.nullablePrimitive("decimal128", new ArrowType.Decimal(10, 2, 128)), + Field.nullablePrimitive("decimal256", new ArrowType.Decimal(10, 2, 256)), + new Field( + "list", + FieldType.nullable(ArrowType.List.INSTANCE), + Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), + new Field( + "largelist", + FieldType.nullable(ArrowType.LargeList.INSTANCE), + Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), + new Field( + "fixedsizelist", + FieldType.nullable(new ArrowType.FixedSizeList(2)), + Collections.singletonList(Field.nullable("items", new ArrowType.Int(32, true)))), + structField + }; VectorSchemaRoot root = VectorSchemaRoot.create(new Schema(Arrays.asList(fields)), allocator); root.allocateNew(); root.setRowCount(2); @@ -197,7 +212,8 @@ private VectorSchemaRoot generateAllTypesVector(BufferAllocator allocator) { ((DurationVector) root.getVector("duration")).set(1, 0); ((DecimalVector) root.getVector("decimal128")).set(1, 0); ((Decimal256Vector) root.getVector("decimal256")).set(1, 0); - UnionFixedSizeListWriter fixedListWriter = ((FixedSizeListVector) root.getVector("fixedsizelist")).getWriter(); + UnionFixedSizeListWriter fixedListWriter = + ((FixedSizeListVector) root.getVector("fixedsizelist")).getWriter(); fixedListWriter.allocate(); fixedListWriter.setPosition(1); fixedListWriter.startList(); @@ -211,7 +227,8 @@ private VectorSchemaRoot generateAllTypesVector(BufferAllocator allocator) { listWriter.integer().writeInt(1); listWriter.endList(); - UnionLargeListWriter largeListWriter = ((LargeListVector) root.getVector("largelist")).getWriter(); + UnionLargeListWriter largeListWriter = + ((LargeListVector) root.getVector("largelist")).getWriter(); largeListWriter.allocate(); largeListWriter.setPosition(1); largeListWriter.startList(); @@ -223,11 +240,9 @@ private VectorSchemaRoot generateAllTypesVector(BufferAllocator allocator) { } private byte[] serializeFile(VectorSchemaRoot root) { - try ( - ByteArrayOutputStream out = new ByteArrayOutputStream(); + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); WritableByteChannel channel = Channels.newChannel(out); - ArrowStreamWriter writer = new ArrowStreamWriter(root, null, channel) - ) { + ArrowStreamWriter writer = new ArrowStreamWriter(root, null, channel)) { writer.start(); writer.writeBatch(); writer.end(); @@ -246,15 +261,18 @@ public void testAllTypesParquet() throws Exception { TMP.create(); final File writtenFolder = TMP.newFolder(); final String writtenParquet = writtenFolder.toURI().toString(); - DatasetFileWriter.write(rootAllocator(), reader, FileFormat.PARQUET, - writtenParquet); + DatasetFileWriter.write(rootAllocator(), reader, FileFormat.PARQUET, writtenParquet); - // Load the reference file from the test resources and write to a temporary file on the OS. - String referenceFile = ArrowTestDataUtil.getTestDataRoot() - .resolve("parquet") - .resolve("alltypes-java.parquet") - .toUri().toString(); - assertParquetFileEquals(referenceFile, + // Load the reference file from the test resources and write to a temporary file on the + // OS. + String referenceFile = + ArrowTestDataUtil.getTestDataRoot() + .resolve("parquet") + .resolve("alltypes-java.parquet") + .toUri() + .toString(); + assertParquetFileEquals( + referenceFile, Objects.requireNonNull(writtenFolder.listFiles())[0].toURI().toString()); } } diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/TestDataset.java b/java/dataset/src/test/java/org/apache/arrow/dataset/TestDataset.java index cafa63b7880..1740f56c5f4 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/TestDataset.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/TestDataset.java @@ -26,7 +26,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; - import org.apache.arrow.dataset.file.FileFormat; import org.apache.arrow.dataset.file.FileSystemDatasetFactory; import org.apache.arrow.dataset.jni.NativeMemoryPool; @@ -49,7 +48,6 @@ import org.junit.Assert; import org.junit.Before; - public abstract class TestDataset { private BufferAllocator allocator = null; @@ -67,7 +65,8 @@ protected BufferAllocator rootAllocator() { return allocator; } - protected List collectResultFromFactory(DatasetFactory factory, ScanOptions options) { + protected List collectResultFromFactory( + DatasetFactory factory, ScanOptions options) { final Dataset dataset = factory.finish(); final Scanner scanner = dataset.newScan(options); try { @@ -108,17 +107,20 @@ protected Schema inferResultSchemaFromFactory(DatasetFactory factory, ScanOption } protected void assertParquetFileEquals(String expectedURI, String actualURI) throws Exception { - final FileSystemDatasetFactory expectedFactory = new FileSystemDatasetFactory( - rootAllocator(), NativeMemoryPool.getDefault(), FileFormat.PARQUET, expectedURI); - final FileSystemDatasetFactory actualFactory = new FileSystemDatasetFactory( - rootAllocator(), NativeMemoryPool.getDefault(), FileFormat.PARQUET, actualURI); - List expectedBatches = collectResultFromFactory(expectedFactory, - new ScanOptions(new String[0], 100)); - List actualBatches = collectResultFromFactory(actualFactory, - new ScanOptions(new String[0], 100)); - try ( - VectorSchemaRoot expectVsr = VectorSchemaRoot.create(expectedFactory.inspect(), rootAllocator()); - VectorSchemaRoot actualVsr = VectorSchemaRoot.create(actualFactory.inspect(), rootAllocator())) { + final FileSystemDatasetFactory expectedFactory = + new FileSystemDatasetFactory( + rootAllocator(), NativeMemoryPool.getDefault(), FileFormat.PARQUET, expectedURI); + final FileSystemDatasetFactory actualFactory = + new FileSystemDatasetFactory( + rootAllocator(), NativeMemoryPool.getDefault(), FileFormat.PARQUET, actualURI); + List expectedBatches = + collectResultFromFactory(expectedFactory, new ScanOptions(new String[0], 100)); + List actualBatches = + collectResultFromFactory(actualFactory, new ScanOptions(new String[0], 100)); + try (VectorSchemaRoot expectVsr = + VectorSchemaRoot.create(expectedFactory.inspect(), rootAllocator()); + VectorSchemaRoot actualVsr = + VectorSchemaRoot.create(actualFactory.inspect(), rootAllocator())) { // fast-fail by comparing metadata Assert.assertEquals(expectedBatches.toString(), actualBatches.toString()); @@ -150,7 +152,8 @@ protected List collect(Iterable iterable) { } protected Stream stream(Iterator iterator) { - return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); + return StreamSupport.stream( + Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); } protected List collect(Iterator iterator) { diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/TextBasedWriteSupport.java b/java/dataset/src/test/java/org/apache/arrow/dataset/TextBasedWriteSupport.java index 43f96f6d4d6..8f5cb0c87c5 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/TextBasedWriteSupport.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/TextBasedWriteSupport.java @@ -29,11 +29,19 @@ public class TextBasedWriteSupport { private final Random random = new Random(); public TextBasedWriteSupport(File outputFolder, String fileExtension) throws URISyntaxException { - uri = new URI("file", outputFolder.getPath() + File.separator + - "generated-" + random.nextLong() + fileExtension, null); + uri = + new URI( + "file", + outputFolder.getPath() + + File.separator + + "generated-" + + random.nextLong() + + fileExtension, + null); } - public static TextBasedWriteSupport writeTempFile(File outputFolder, String fileExtension, String... values) + public static TextBasedWriteSupport writeTempFile( + File outputFolder, String fileExtension, String... values) throws URISyntaxException, IOException { TextBasedWriteSupport writer = new TextBasedWriteSupport(outputFolder, fileExtension); try (FileWriter addValues = new FileWriter(new File(writer.uri), true)) { diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestDatasetFileWriter.java b/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestDatasetFileWriter.java index 86797c165b2..d1c9f8f9313 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestDatasetFileWriter.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestDatasetFileWriter.java @@ -23,7 +23,6 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; - import org.apache.arrow.dataset.ParquetWriteSupport; import org.apache.arrow.dataset.TestDataset; import org.apache.arrow.dataset.jni.NativeMemoryPool; @@ -39,58 +38,70 @@ public class TestDatasetFileWriter extends TestDataset { - @ClassRule - public static final TemporaryFolder TMP = new TemporaryFolder(); + @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); public static final String AVRO_SCHEMA_USER = "user.avsc"; @Test public void testParquetWriteSimple() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), - 1, "a", 2, "b", 3, "c", 2, "d"); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 2, "b", 3, "c", 2, "d"); String sampleParquet = writeSupport.getOutputURI(); ScanOptions options = new ScanOptions(new String[0], 100); final File writtenFolder = TMP.newFolder(); final String writtenParquet = writtenFolder.toURI().toString(); - try (FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, sampleParquet); - final Dataset dataset = factory.finish(); - final Scanner scanner = dataset.newScan(options); - final ArrowScannerReader reader = new ArrowScannerReader(scanner, rootAllocator()); - ) { + try (FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), NativeMemoryPool.getDefault(), FileFormat.PARQUET, sampleParquet); + final Dataset dataset = factory.finish(); + final Scanner scanner = dataset.newScan(options); + final ArrowScannerReader reader = new ArrowScannerReader(scanner, rootAllocator()); ) { DatasetFileWriter.write(rootAllocator(), reader, FileFormat.PARQUET, writtenParquet); - assertParquetFileEquals(sampleParquet, Objects.requireNonNull(writtenFolder.listFiles())[0].toURI().toString()); + assertParquetFileEquals( + sampleParquet, Objects.requireNonNull(writtenFolder.listFiles())[0].toURI().toString()); } } @Test public void testParquetWriteWithPartitions() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), - 1, "a", 2, "b", 3, "c", 2, "d"); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 2, "b", 3, "c", 2, "d"); String sampleParquet = writeSupport.getOutputURI(); ScanOptions options = new ScanOptions(new String[0], 100); final File writtenFolder = TMP.newFolder(); final String writtenParquet = writtenFolder.toURI().toString(); - try (FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, sampleParquet); - final Dataset dataset = factory.finish(); - final Scanner scanner = dataset.newScan(options); - final ArrowScannerReader reader = new ArrowScannerReader(scanner, rootAllocator()); - ) { - DatasetFileWriter.write(rootAllocator(), reader, - FileFormat.PARQUET, writtenParquet, new String[]{"id", "name"}, - 100, "data_{i}"); - final Set expectedOutputFiles = new HashSet<>( - Arrays.asList("id=1/name=a/data_0", "id=2/name=b/data_0", "id=3/name=c/data_0", "id=2/name=d/data_0")); - final Set outputFiles = FileUtils.listFiles(writtenFolder, null, true) - .stream() - .map(file -> { - return writtenFolder.toURI().relativize(file.toURI()).toString(); - }) - .collect(Collectors.toSet()); + try (FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), NativeMemoryPool.getDefault(), FileFormat.PARQUET, sampleParquet); + final Dataset dataset = factory.finish(); + final Scanner scanner = dataset.newScan(options); + final ArrowScannerReader reader = new ArrowScannerReader(scanner, rootAllocator()); ) { + DatasetFileWriter.write( + rootAllocator(), + reader, + FileFormat.PARQUET, + writtenParquet, + new String[] {"id", "name"}, + 100, + "data_{i}"); + final Set expectedOutputFiles = + new HashSet<>( + Arrays.asList( + "id=1/name=a/data_0", + "id=2/name=b/data_0", + "id=3/name=c/data_0", + "id=2/name=d/data_0")); + final Set outputFiles = + FileUtils.listFiles(writtenFolder, null, true).stream() + .map( + file -> { + return writtenFolder.toURI().relativize(file.toURI()).toString(); + }) + .collect(Collectors.toSet()); Assert.assertEquals(expectedOutputFiles, outputFiles); } } } - diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDataset.java b/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDataset.java index 6ca559ee2d7..8ed8f316727 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDataset.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDataset.java @@ -22,6 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertThrows; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.primitives.Primitives; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -36,7 +38,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; - import org.apache.arrow.dataset.OrcWriteSupport; import org.apache.arrow.dataset.ParquetWriteSupport; import org.apache.arrow.dataset.TextBasedWriteSupport; @@ -68,22 +69,23 @@ import org.junit.jupiter.api.Assertions; import org.junit.rules.TemporaryFolder; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.primitives.Primitives; - public class TestFileSystemDataset extends TestNativeDataset { - @ClassRule - public static final TemporaryFolder TMP = new TemporaryFolder(); + @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); public static final String AVRO_SCHEMA_USER = "user.avsc"; @Test public void testBaseParquetRead() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); ScanOptions options = new ScanOptions(100); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); @@ -103,15 +105,19 @@ public void testBaseParquetRead() throws Exception { @Test public void testMultipleParquetReadFromUris() throws Exception { - ParquetWriteSupport writeSupport1 = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), - 1, "a"); - ParquetWriteSupport writeSupport2 = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), - 2, "b"); + ParquetWriteSupport writeSupport1 = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + ParquetWriteSupport writeSupport2 = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 2, "b"); String expectedJsonUnordered = "[[1,\"a\"],[2,\"b\"]]"; ScanOptions options = new ScanOptions(1); - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, new String[]{writeSupport1.getOutputURI(), writeSupport2.getOutputURI()}); + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + new String[] {writeSupport1.getOutputURI(), writeSupport2.getOutputURI()}); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); @@ -124,33 +130,50 @@ public void testMultipleParquetReadFromUris() throws Exception { AutoCloseables.close(factory); } - @Test public void testMultipleParquetInvalidUri() throws Exception { - RuntimeException exc = assertThrows(RuntimeException.class, - () -> new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, new String[]{"https://example.com", "file:///test/location"})); - Assertions.assertEquals("Unrecognized filesystem type in URI: https://example.com", exc.getMessage()); + RuntimeException exc = + assertThrows( + RuntimeException.class, + () -> + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + new String[] {"https://example.com", "file:///test/location"})); + Assertions.assertEquals( + "Unrecognized filesystem type in URI: https://example.com", exc.getMessage()); } @Test public void testMultipleParquetMultipleFilesystemTypes() throws Exception { - RuntimeException exc = assertThrows(RuntimeException.class, - () -> new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, new String[]{"file:///test/location", "s3:///test/bucket/file" })); + RuntimeException exc = + assertThrows( + RuntimeException.class, + () -> + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + new String[] {"file:///test/location", "s3:///test/bucket/file"})); Assertions.assertTrue( - exc.getMessage().startsWith("The filesystem expected a URI with one of the schemes (file) but received s3" - ) - ); + exc.getMessage() + .startsWith( + "The filesystem expected a URI with one of the schemes (file) but received s3")); } @Test public void testParquetProjectSingleColumn() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); - ScanOptions options = new ScanOptions(100, Optional.of(new String[]{"id"})); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); + ScanOptions options = new ScanOptions(100, Optional.of(new String[] {"id"})); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); org.apache.avro.Schema expectedSchema = truncateAvroSchema(writeSupport.getAvroSchema(), 0, 1); @@ -160,12 +183,10 @@ public void testParquetProjectSingleColumn() throws Exception { assertEquals("id", schema.getFields().get(0).getName()); assertEquals(Types.MinorType.INT.getType(), schema.getFields().get(0).getType()); assertEquals(1, datum.size()); - checkParquetReadResult(schema, - Collections.singletonList( - new GenericRecordBuilder( - expectedSchema) - .set("id", 1) - .build()), datum); + checkParquetReadResult( + schema, + Collections.singletonList(new GenericRecordBuilder(expectedSchema).set("id", 1).build()), + datum); AutoCloseables.close(datum); AutoCloseables.close(factory); @@ -173,12 +194,17 @@ public void testParquetProjectSingleColumn() throws Exception { @Test public void testParquetBatchSize() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), - 1, "a", 2, "b", 3, "c"); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 2, "b", 3, "c"); ScanOptions options = new ScanOptions(1); - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); @@ -194,15 +220,19 @@ public void testParquetBatchSize() throws Exception { @Test public void testParquetDirectoryRead() throws Exception { final File outputFolder = TMP.newFolder(); - ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, outputFolder, - 1, "a", 2, "b", 3, "c"); - ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, outputFolder, - 4, "e", 5, "f", 6, "g", 7, "h"); - String expectedJsonUnordered = "[[1,\"a\"],[2,\"b\"],[3,\"c\"],[4,\"e\"],[5,\"f\"],[6,\"g\"],[7,\"h\"]]"; + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, outputFolder, 1, "a", 2, "b", 3, "c"); + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, outputFolder, 4, "e", 5, "f", 6, "g", 7, "h"); + String expectedJsonUnordered = + "[[1,\"a\"],[2,\"b\"],[3,\"c\"],[4,\"e\"],[5,\"f\"],[6,\"g\"],[7,\"h\"]]"; ScanOptions options = new ScanOptions(new String[0], 1); - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, outputFolder.toURI().toString()); + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + outputFolder.toURI().toString()); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); @@ -216,33 +246,41 @@ public void testParquetDirectoryRead() throws Exception { @Test public void testEmptyProjectSelectsZeroColumns() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); ScanOptions options = new ScanOptions(100, Optional.of(new String[0])); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); - org.apache.avro.Schema expectedSchema = org.apache.avro.Schema.createRecord(Collections.emptyList()); + org.apache.avro.Schema expectedSchema = + org.apache.avro.Schema.createRecord(Collections.emptyList()); assertScanBatchesProduced(factory, options); assertEquals(0, schema.getFields().size()); assertEquals(1, datum.size()); - checkParquetReadResult(schema, - Collections.singletonList( - new GenericRecordBuilder( - expectedSchema) - .build()), datum); + checkParquetReadResult( + schema, Collections.singletonList(new GenericRecordBuilder(expectedSchema).build()), datum); AutoCloseables.close(datum); } @Test public void testNullProjectSelectsAllColumns() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); ScanOptions options = new ScanOptions(100, Optional.empty()); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); @@ -261,35 +299,46 @@ public void testNullProjectSelectsAllColumns() throws Exception { @Test public void testNoErrorWhenCloseAgain() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); - - assertDoesNotThrow(() -> { - NativeDataset dataset = factory.finish(); - dataset.close(); - dataset.close(); - }); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); + + assertDoesNotThrow( + () -> { + NativeDataset dataset = factory.finish(); + dataset.close(); + dataset.close(); + }); AutoCloseables.close(factory); } @Test public void testErrorThrownWhenScanBatchesAgain() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); NativeDataset dataset = factory.finish(); ScanOptions options = new ScanOptions(100); NativeScanner scanner = dataset.newScan(options); List datum = collectTaskData(scanner); AutoCloseables.close(datum); - UnsupportedOperationException uoe = assertThrows(UnsupportedOperationException.class, - scanner::scanBatches); - Assertions.assertEquals("NativeScanner can only be executed once. Create a new scanner instead", - uoe.getMessage()); + UnsupportedOperationException uoe = + assertThrows(UnsupportedOperationException.class, scanner::scanBatches); + Assertions.assertEquals( + "NativeScanner can only be executed once. Create a new scanner instead", uoe.getMessage()); AutoCloseables.close(scanner, dataset, factory); } @@ -297,10 +346,15 @@ public void testErrorThrownWhenScanBatchesAgain() throws Exception { @Test public void testScanBatchesInOtherThread() throws Exception { ExecutorService executor = Executors.newSingleThreadExecutor(); - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); NativeDataset dataset = factory.finish(); ScanOptions options = new ScanOptions(100); NativeScanner scanner = dataset.newScan(options); @@ -312,10 +366,15 @@ public void testScanBatchesInOtherThread() throws Exception { @Test public void testErrorThrownWhenScanBatchesAfterScannerClose() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); NativeDataset dataset = factory.finish(); ScanOptions options = new ScanOptions(100); NativeScanner scanner = dataset.newScan(options); @@ -327,10 +386,15 @@ public void testErrorThrownWhenScanBatchesAfterScannerClose() throws Exception { @Test public void testErrorThrownWhenReadAfterNativeReaderClose() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); - - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); NativeDataset dataset = factory.finish(); ScanOptions options = new ScanOptions(100); NativeScanner scanner = dataset.newScan(options); @@ -344,10 +408,12 @@ public void testErrorThrownWhenReadAfterNativeReaderClose() throws Exception { @Test public void testBaseArrowIpcRead() throws Exception { File dataFile = TMP.newFile(); - Schema sourceSchema = new Schema(Collections.singletonList(Field.nullable("ints", new ArrowType.Int(32, true)))); + Schema sourceSchema = + new Schema(Collections.singletonList(Field.nullable("ints", new ArrowType.Int(32, true)))); try (VectorSchemaRoot root = VectorSchemaRoot.create(sourceSchema, rootAllocator()); - FileOutputStream sink = new FileOutputStream(dataFile); - ArrowFileWriter writer = new ArrowFileWriter(root, /*dictionaryProvider=*/null, sink.getChannel())) { + FileOutputStream sink = new FileOutputStream(dataFile); + ArrowFileWriter writer = + new ArrowFileWriter(root, /* dictionaryProvider= */ null, sink.getChannel())) { IntVector ints = (IntVector) root.getVector(0); ints.setSafe(0, 0); ints.setSafe(1, 1024); @@ -359,8 +425,9 @@ public void testBaseArrowIpcRead() throws Exception { } String arrowDataURI = dataFile.toURI().toString(); - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.ARROW_IPC, arrowDataURI); + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), NativeMemoryPool.getDefault(), FileFormat.ARROW_IPC, arrowDataURI); ScanOptions options = new ScanOptions(100); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); @@ -384,11 +451,13 @@ public void testBaseOrcRead() throws Exception { TypeDescription orcSchema = TypeDescription.fromString("struct"); Path path = new Path(basePath, dataName); - OrcWriteSupport.writeTempFile(orcSchema, path, new Integer[]{Integer.MIN_VALUE, Integer.MAX_VALUE}); + OrcWriteSupport.writeTempFile( + orcSchema, path, new Integer[] {Integer.MIN_VALUE, Integer.MAX_VALUE}); String orcDatasetUri = new File(basePath, dataName).toURI().toString(); - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.ORC, orcDatasetUri); + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), NativeMemoryPool.getDefault(), FileFormat.ORC, orcDatasetUri); ScanOptions options = new ScanOptions(100); Schema schema = inferResultSchemaFromFactory(factory, options); List datum = collectResultFromFactory(factory, options); @@ -407,14 +476,18 @@ public void testBaseOrcRead() throws Exception { @Test public void testBaseCsvRead() throws Exception { - TextBasedWriteSupport writeSupport = TextBasedWriteSupport.writeTempFile( + TextBasedWriteSupport writeSupport = + TextBasedWriteSupport.writeTempFile( TMP.newFolder(), ".csv", "Name,Language", "Juno,Java", "Peter,Python", "Celin,C++"); - String expectedJsonUnordered = "[[\"Juno\", \"Java\"], [\"Peter\", \"Python\"], [\"Celin\", \"C++\"]]"; + String expectedJsonUnordered = + "[[\"Juno\", \"Java\"], [\"Peter\", \"Python\"], [\"Celin\", \"C++\"]]"; ScanOptions options = new ScanOptions(100); - try ( - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.CSV, writeSupport.getOutputURI()) - ) { + try (FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.CSV, + writeSupport.getOutputURI())) { List datum = collectResultFromFactory(factory, options); Schema schema = inferResultSchemaFromFactory(factory, options); @@ -431,17 +504,20 @@ public void testBaseCsvRead() throws Exception { @Test public void testBaseJsonRead() throws Exception { - TextBasedWriteSupport writeSupport = TextBasedWriteSupport.writeTempFile( - TMP.newFolder(), ".json", - "{\"Type\": \"Compiled\", \"Language\": \"Java\"}", - "{\"Type\": \"Interpreted\", \"Language\": \"Python\"}"); - String expectedJsonUnordered = "[[\"Compiled\", \"Java\"], " + - "[\"Interpreted\", \"Python\"]]"; + TextBasedWriteSupport writeSupport = + TextBasedWriteSupport.writeTempFile( + TMP.newFolder(), + ".json", + "{\"Type\": \"Compiled\", \"Language\": \"Java\"}", + "{\"Type\": \"Interpreted\", \"Language\": \"Python\"}"); + String expectedJsonUnordered = "[[\"Compiled\", \"Java\"], " + "[\"Interpreted\", \"Python\"]]"; ScanOptions options = new ScanOptions(100); - try ( - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.JSON, writeSupport.getOutputURI()) - ) { + try (FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.JSON, + writeSupport.getOutputURI())) { List datum = collectResultFromFactory(factory, options); Schema schema = inferResultSchemaFromFactory(factory, options); @@ -457,8 +533,8 @@ public void testBaseJsonRead() throws Exception { } } - private void checkParquetReadResult(Schema schema, String expectedJson, List actual) - throws IOException { + private void checkParquetReadResult( + Schema schema, String expectedJson, List actual) throws IOException { final ObjectMapper json = new ObjectMapper(); final Set expectedSet = json.readValue(expectedJson, Set.class); final Set> actualSet = new HashSet<>(); @@ -482,14 +558,15 @@ private void checkParquetReadResult(Schema schema, String expectedJson, List expected, List actual) { - assertEquals(expected.size(), actual.stream() - .mapToInt(ArrowRecordBatch::getLength) - .sum()); + private void checkParquetReadResult( + Schema schema, List expected, List actual) { + assertEquals(expected.size(), actual.stream().mapToInt(ArrowRecordBatch::getLength).sum()); final int fieldCount = schema.getFields().size(); LinkedList expectedRemovable = new LinkedList<>(expected); try (VectorSchemaRoot vsr = VectorSchemaRoot.create(schema, rootAllocator())) { @@ -503,8 +580,7 @@ private void checkParquetReadResult(Schema schema, List expected, for (int j = 0; j < batchRowCount; j++) { Object object = vector.getObject(j); Object expectedObject = expectedRemovable.get(j).get(i); - assertEquals(Objects.toString(expectedObject), - Objects.toString(object)); + assertEquals(Objects.toString(expectedObject), Objects.toString(object)); } } for (int i = 0; i < batchRowCount; i++) { @@ -515,11 +591,15 @@ private void checkParquetReadResult(Schema schema, List expected, } } - private org.apache.avro.Schema truncateAvroSchema(org.apache.avro.Schema schema, int from, int to) { + private org.apache.avro.Schema truncateAvroSchema( + org.apache.avro.Schema schema, int from, int to) { List fields = schema.getFields().subList(from, to); return org.apache.avro.Schema.createRecord( fields.stream() - .map(f -> new org.apache.avro.Schema.Field(f.name(), f.schema(), f.doc(), f.defaultVal(), f.order())) + .map( + f -> + new org.apache.avro.Schema.Field( + f.name(), f.schema(), f.doc(), f.defaultVal(), f.order())) .collect(Collectors.toList())); } } diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDatasetFactory.java b/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDatasetFactory.java index bddf96b5ec9..69b07d42e90 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDatasetFactory.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/file/TestFileSystemDatasetFactory.java @@ -29,20 +29,31 @@ public class TestFileSystemDatasetFactory { @Test public void testErrorHandling() { - RuntimeException e = assertThrows(RuntimeException.class, () -> { - new FileSystemDatasetFactory(new RootAllocator(Long.MAX_VALUE), NativeMemoryPool.getDefault(), - FileFormat.NONE, "file:///NON_EXIST_FILE"); - }); + RuntimeException e = + assertThrows( + RuntimeException.class, + () -> { + new FileSystemDatasetFactory( + new RootAllocator(Long.MAX_VALUE), + NativeMemoryPool.getDefault(), + FileFormat.NONE, + "file:///NON_EXIST_FILE"); + }); assertEquals("illegal file format id: -1", e.getMessage()); } @Test public void testCloseAgain() { - assertDoesNotThrow(() -> { - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(new RootAllocator(Long.MAX_VALUE), - NativeMemoryPool.getDefault(), FileFormat.PARQUET, "file:///NON_EXIST_FILE"); - factory.close(); - factory.close(); - }); + assertDoesNotThrow( + () -> { + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + new RootAllocator(Long.MAX_VALUE), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + "file:///NON_EXIST_FILE"); + factory.close(); + factory.close(); + }); } } diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/jni/TestReservationListener.java b/java/dataset/src/test/java/org/apache/arrow/dataset/jni/TestReservationListener.java index fa42f7ee7cd..d839f1a0c2d 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/jni/TestReservationListener.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/jni/TestReservationListener.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.concurrent.atomic.AtomicLong; - import org.apache.arrow.dataset.ParquetWriteSupport; import org.apache.arrow.dataset.TestDataset; import org.apache.arrow.dataset.file.FileFormat; @@ -35,18 +34,18 @@ public class TestReservationListener extends TestDataset { - @ClassRule - public static final TemporaryFolder TMP = new TemporaryFolder(); + @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); public static final String AVRO_SCHEMA_USER = "user.avsc"; @Test public void testDirectReservationListener() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); NativeMemoryPool pool = NativeMemoryPool.createListenable(DirectReservationListener.instance()); - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), - pool, FileFormat.PARQUET, - writeSupport.getOutputURI()); + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), pool, FileFormat.PARQUET, writeSupport.getOutputURI()); ScanOptions options = new ScanOptions(100); long initReservation = DirectReservationListener.instance().getCurrentDirectMemReservation(); List datum = collectResultFromFactory(factory, options); @@ -60,22 +59,25 @@ public void testDirectReservationListener() throws Exception { @Test public void testCustomReservationListener() throws Exception { - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); final AtomicLong reserved = new AtomicLong(0L); - ReservationListener listener = new ReservationListener() { - @Override - public void reserve(long size) { - reserved.getAndAdd(size); - } + ReservationListener listener = + new ReservationListener() { + @Override + public void reserve(long size) { + reserved.getAndAdd(size); + } - @Override - public void unreserve(long size) { - reserved.getAndAdd(-size); - } - }; + @Override + public void unreserve(long size) { + reserved.getAndAdd(-size); + } + }; NativeMemoryPool pool = NativeMemoryPool.createListenable(listener); - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), - pool, FileFormat.PARQUET, writeSupport.getOutputURI()); + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), pool, FileFormat.PARQUET, writeSupport.getOutputURI()); ScanOptions options = new ScanOptions(100); long initReservation = reserved.get(); List datum = collectResultFromFactory(factory, options); @@ -90,27 +92,33 @@ public void unreserve(long size) { @Test public void testErrorThrownFromReservationListener() throws Exception { final String errorMessage = "ERROR_MESSAGE"; - ParquetWriteSupport writeSupport = ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a"); final AtomicLong reserved = new AtomicLong(0L); - ReservationListener listener = new ReservationListener() { - @Override - public void reserve(long size) { - throw new IllegalArgumentException(errorMessage); - } + ReservationListener listener = + new ReservationListener() { + @Override + public void reserve(long size) { + throw new IllegalArgumentException(errorMessage); + } - @Override - public void unreserve(long size) { - // no-op - } - }; + @Override + public void unreserve(long size) { + // no-op + } + }; NativeMemoryPool pool = NativeMemoryPool.createListenable(listener); - FileSystemDatasetFactory factory = new FileSystemDatasetFactory(rootAllocator(), - pool, FileFormat.PARQUET, writeSupport.getOutputURI()); + FileSystemDatasetFactory factory = + new FileSystemDatasetFactory( + rootAllocator(), pool, FileFormat.PARQUET, writeSupport.getOutputURI()); ScanOptions options = new ScanOptions(100); long initReservation = reserved.get(); - Assertions.assertThrows(IllegalArgumentException.class, () -> { - collectResultFromFactory(factory, options); - }, errorMessage); + Assertions.assertThrows( + IllegalArgumentException.class, + () -> { + collectResultFromFactory(factory, options); + }, + errorMessage); long reservation = reserved.get(); AutoCloseables.close(pool); long finalReservation = reserved.get(); diff --git a/java/dataset/src/test/java/org/apache/arrow/dataset/substrait/TestAceroSubstraitConsumer.java b/java/dataset/src/test/java/org/apache/arrow/dataset/substrait/TestAceroSubstraitConsumer.java index 0fba72892cd..14248fb420c 100644 --- a/java/dataset/src/test/java/org/apache/arrow/dataset/substrait/TestAceroSubstraitConsumer.java +++ b/java/dataset/src/test/java/org/apache/arrow/dataset/substrait/TestAceroSubstraitConsumer.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; - import org.apache.arrow.dataset.ParquetWriteSupport; import org.apache.arrow.dataset.TestDataset; import org.apache.arrow.dataset.file.FileFormat; @@ -51,33 +50,42 @@ public class TestAceroSubstraitConsumer extends TestDataset { - @ClassRule - public static final TemporaryFolder TMP = new TemporaryFolder(); + @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder(); public static final String AVRO_SCHEMA_USER = "user.avsc"; @Test public void testRunQueryLocalFiles() throws Exception { - //Query: - //SELECT id, name FROM Users - //Isthmus: - //./isthmus-macOS-0.7.0 -c "CREATE TABLE USERS ( id INT NOT NULL, name VARCHAR(150));" "SELECT id, name FROM Users" - //VARCHAR(150) -> is mapping to -> {ARROW:extension:name=varchar, ARROW:extension:metadata=varchar{length:150}} + // Query: + // SELECT id, name FROM Users + // Isthmus: + // ./isthmus-macOS-0.7.0 -c "CREATE TABLE USERS ( id INT NOT NULL, name VARCHAR(150));" "SELECT + // id, name FROM Users" + // VARCHAR(150) -> is mapping to -> {ARROW:extension:name=varchar, + // ARROW:extension:metadata=varchar{length:150}} Map metadataName = new HashMap<>(); metadataName.put("ARROW:extension:name", "varchar"); metadataName.put("ARROW:extension:metadata", "varchar{length:150}"); - final Schema schema = new Schema(Arrays.asList( - Field.nullable("ID", new ArrowType.Int(32, true)), - new Field("NAME", new FieldType(true, new ArrowType.Utf8(), null, metadataName), null) - ), Collections.emptyMap()); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 11, "b", 21, "c"); - try (ArrowReader arrowReader = new AceroSubstraitConsumer(rootAllocator()) - .runQuery( - new String(Files.readAllBytes(Paths.get(TestAceroSubstraitConsumer.class.getClassLoader() - .getResource("substrait/local_files_users.json").toURI()))).replace("FILENAME_PLACEHOLDER", - writeSupport.getOutputURI()) - ) - ) { + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("ID", new ArrowType.Int(32, true)), + new Field( + "NAME", new FieldType(true, new ArrowType.Utf8(), null, metadataName), null)), + Collections.emptyMap()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 11, "b", 21, "c"); + try (ArrowReader arrowReader = + new AceroSubstraitConsumer(rootAllocator()) + .runQuery( + new String( + Files.readAllBytes( + Paths.get( + TestAceroSubstraitConsumer.class + .getClassLoader() + .getResource("substrait/local_files_users.json") + .toURI()))) + .replace("FILENAME_PLACEHOLDER", writeSupport.getOutputURI()))) { assertEquals(schema, arrowReader.getVectorSchemaRoot().getSchema()); int rowcount = 0; while (arrowReader.loadNextBatch()) { @@ -89,31 +97,43 @@ public void testRunQueryLocalFiles() throws Exception { @Test public void testRunQueryNamedTable() throws Exception { - //Query: - //SELECT id, name FROM Users - //Isthmus: - //./isthmus-macOS-0.7.0 -c "CREATE TABLE USERS ( id INT NOT NULL, name VARCHAR(150));" "SELECT id, name FROM Users" - final Schema schema = new Schema(Arrays.asList( - Field.nullable("ID", new ArrowType.Int(32, true)), - Field.nullable("NAME", new ArrowType.Utf8()) - ), Collections.emptyMap()); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 11, "b", 21, "c"); + // Query: + // SELECT id, name FROM Users + // Isthmus: + // ./isthmus-macOS-0.7.0 -c "CREATE TABLE USERS ( id INT NOT NULL, name VARCHAR(150));" "SELECT + // id, name FROM Users" + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("ID", new ArrowType.Int(32, true)), + Field.nullable("NAME", new ArrowType.Utf8())), + Collections.emptyMap()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 11, "b", 21, "c"); ScanOptions options = new ScanOptions(/*batchSize*/ 32768); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); Dataset dataset = datasetFactory.finish(); Scanner scanner = dataset.newScan(options); - ArrowReader reader = scanner.scanBatches() - ) { + ArrowReader reader = scanner.scanBatches()) { Map mapTableToArrowReader = new HashMap<>(); mapTableToArrowReader.put("USERS", reader); - try (ArrowReader arrowReader = new AceroSubstraitConsumer(rootAllocator()).runQuery( - new String(Files.readAllBytes(Paths.get(TestAceroSubstraitConsumer.class.getClassLoader() - .getResource("substrait/named_table_users.json").toURI()))), - mapTableToArrowReader - )) { + try (ArrowReader arrowReader = + new AceroSubstraitConsumer(rootAllocator()) + .runQuery( + new String( + Files.readAllBytes( + Paths.get( + TestAceroSubstraitConsumer.class + .getClassLoader() + .getResource("substrait/named_table_users.json") + .toURI()))), + mapTableToArrowReader)) { assertEquals(schema, arrowReader.getVectorSchemaRoot().getSchema()); assertEquals(arrowReader.getVectorSchemaRoot().getSchema(), schema); int rowcount = 0; @@ -127,31 +147,43 @@ public void testRunQueryNamedTable() throws Exception { @Test(expected = RuntimeException.class) public void testRunQueryNamedTableWithException() throws Exception { - //Query: - //SELECT id, name FROM Users - //Isthmus: - //./isthmus-macOS-0.7.0 -c "CREATE TABLE USERS ( id INT NOT NULL, name VARCHAR(150));" "SELECT id, name FROM Users" - final Schema schema = new Schema(Arrays.asList( - Field.nullable("ID", new ArrowType.Int(32, true)), - Field.nullable("NAME", new ArrowType.Utf8()) - ), Collections.emptyMap()); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 11, "b", 21, "c"); + // Query: + // SELECT id, name FROM Users + // Isthmus: + // ./isthmus-macOS-0.7.0 -c "CREATE TABLE USERS ( id INT NOT NULL, name VARCHAR(150));" "SELECT + // id, name FROM Users" + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("ID", new ArrowType.Int(32, true)), + Field.nullable("NAME", new ArrowType.Utf8())), + Collections.emptyMap()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 11, "b", 21, "c"); ScanOptions options = new ScanOptions(/*batchSize*/ 32768); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); Dataset dataset = datasetFactory.finish(); Scanner scanner = dataset.newScan(options); - ArrowReader reader = scanner.scanBatches() - ) { + ArrowReader reader = scanner.scanBatches()) { Map mapTableToArrowReader = new HashMap<>(); mapTableToArrowReader.put("USERS_INVALID_MAP", reader); - try (ArrowReader arrowReader = new AceroSubstraitConsumer(rootAllocator()).runQuery( - new String(Files.readAllBytes(Paths.get(TestAceroSubstraitConsumer.class.getClassLoader() - .getResource("substrait/named_table_users.json").toURI()))), - mapTableToArrowReader - )) { + try (ArrowReader arrowReader = + new AceroSubstraitConsumer(rootAllocator()) + .runQuery( + new String( + Files.readAllBytes( + Paths.get( + TestAceroSubstraitConsumer.class + .getClassLoader() + .getResource("substrait/named_table_users.json") + .toURI()))), + mapTableToArrowReader)) { assertEquals(schema, arrowReader.getVectorSchemaRoot().getSchema()); int rowcount = 0; while (arrowReader.loadNextBatch()) { @@ -164,38 +196,43 @@ public void testRunQueryNamedTableWithException() throws Exception { @Test public void testRunBinaryQueryNamedTable() throws Exception { - //Query: - //SELECT id, name FROM Users - //Isthmus: - //./isthmus-macOS-0.7.0 -c "CREATE TABLE USERS ( id INT NOT NULL, name VARCHAR(150));" "SELECT id, name FROM Users" - final Schema schema = new Schema(Arrays.asList( - Field.nullable("ID", new ArrowType.Int(32, true)), - Field.nullable("NAME", new ArrowType.Utf8()) - ), Collections.emptyMap()); + // Query: + // SELECT id, name FROM Users + // Isthmus: + // ./isthmus-macOS-0.7.0 -c "CREATE TABLE USERS ( id INT NOT NULL, name VARCHAR(150));" "SELECT + // id, name FROM Users" + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("ID", new ArrowType.Int(32, true)), + Field.nullable("NAME", new ArrowType.Utf8())), + Collections.emptyMap()); // Base64.getEncoder().encodeToString(plan.toByteArray()); String binaryPlan = - "Gl8SXQpROk8KBhIECgICAxIvCi0KAgoAEh4KAklECgROQU1FEhIKBCoCEAEKC" + - "LIBBQiWARgBGAI6BwoFVVNFUlMaCBIGCgISACIAGgoSCAoEEgIIASIAEgJJRBIETkFNRQ=="; - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 11, "b", 21, "c"); + "Gl8SXQpROk8KBhIECgICAxIvCi0KAgoAEh4KAklECgROQU1FEhIKBCoCEAEKC" + + "LIBBQiWARgBGAI6BwoFVVNFUlMaCBIGCgISACIAGgoSCAoEEgIIASIAEgJJRBIETkFNRQ=="; + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, TMP.newFolder(), 1, "a", 11, "b", 21, "c"); ScanOptions options = new ScanOptions(/*batchSize*/ 32768); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); Dataset dataset = datasetFactory.finish(); Scanner scanner = dataset.newScan(options); - ArrowReader reader = scanner.scanBatches() - ) { + ArrowReader reader = scanner.scanBatches()) { // map table to reader Map mapTableToArrowReader = new HashMap<>(); mapTableToArrowReader.put("USERS", reader); // get binary plan ByteBuffer substraitPlan = getByteBuffer(binaryPlan); // run query - try (ArrowReader arrowReader = new AceroSubstraitConsumer(rootAllocator()).runQuery( - substraitPlan, - mapTableToArrowReader - )) { + try (ArrowReader arrowReader = + new AceroSubstraitConsumer(rootAllocator()) + .runQuery(substraitPlan, mapTableToArrowReader)) { assertEquals(schema, arrowReader.getVectorSchemaRoot().getSchema()); int rowcount = 0; while (arrowReader.loadNextBatch()) { @@ -208,134 +245,218 @@ public void testRunBinaryQueryNamedTable() throws Exception { @Test public void testRunExtendedExpressionsFilter() throws Exception { - final Schema schema = new Schema(Arrays.asList( - Field.nullable("id", new ArrowType.Int(32, true)), - Field.nullable("name", new ArrowType.Utf8()) - ), null); + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("id", new ArrowType.Int(32, true)), + Field.nullable("name", new ArrowType.Utf8())), + null); // Substrait Extended Expression: Filter: // Expression 01: WHERE ID < 20 - String base64EncodedSubstraitFilter = "Ch4IARIaL2Z1bmN0aW9uc19jb21wYXJpc29uLnlhbWwSEhoQCAIQAhoKbHQ6YW55X2F" + - "ueRo3ChwaGggCGgQKAhABIggaBhIECgISACIGGgQKAigUGhdmaWx0ZXJfaWRfbG93ZXJfdGhhbl8yMCIaCgJJRAoETkFNRRIOCgQqAhA" + - "BCgRiAhABGAI="; + String base64EncodedSubstraitFilter = + "Ch4IARIaL2Z1bmN0aW9uc19jb21wYXJpc29uLnlhbWwSEhoQCAIQAhoKbHQ6YW55X2F" + + "ueRo3ChwaGggCGgQKAhABIggaBhIECgISACIGGgQKAigUGhdmaWx0ZXJfaWRfbG93ZXJfdGhhbl8yMCIaCgJJRAoETkFNRRIOCgQqAhA" + + "BCgRiAhABGAI="; ByteBuffer substraitExpressionFilter = getByteBuffer(base64EncodedSubstraitFilter); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 19, "value_19", 1, "value_1", - 11, "value_11", 21, "value_21", 45, "value_45"); - ScanOptions options = new ScanOptions.Builder(/*batchSize*/ 32768) - .columns(Optional.empty()) - .substraitFilter(substraitExpressionFilter) - .build(); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, + TMP.newFolder(), + 19, + "value_19", + 1, + "value_1", + 11, + "value_11", + 21, + "value_21", + 45, + "value_45"); + ScanOptions options = + new ScanOptions.Builder(/*batchSize*/ 32768) + .columns(Optional.empty()) + .substraitFilter(substraitExpressionFilter) + .build(); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); Dataset dataset = datasetFactory.finish(); Scanner scanner = dataset.newScan(options); - ArrowReader reader = scanner.scanBatches() - ) { + ArrowReader reader = scanner.scanBatches()) { assertEquals(schema.getFields(), reader.getVectorSchemaRoot().getSchema().getFields()); int rowcount = 0; while (reader.loadNextBatch()) { rowcount += reader.getVectorSchemaRoot().getRowCount(); assertTrue(reader.getVectorSchemaRoot().getVector("id").toString().equals("[19, 1, 11]")); - assertTrue(reader.getVectorSchemaRoot().getVector("name").toString() - .equals("[value_19, value_1, value_11]")); + assertTrue( + reader + .getVectorSchemaRoot() + .getVector("name") + .toString() + .equals("[value_19, value_1, value_11]")); } assertEquals(3, rowcount); } } @Test - public void testRunExtendedExpressionsFilterWithProjectionsInsteadOfFilterException() throws Exception { - final Schema schema = new Schema(Arrays.asList( - Field.nullable("id", new ArrowType.Int(32, true)), - Field.nullable("name", new ArrowType.Utf8()) - ), null); + public void testRunExtendedExpressionsFilterWithProjectionsInsteadOfFilterException() + throws Exception { + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("id", new ArrowType.Int(32, true)), + Field.nullable("name", new ArrowType.Utf8())), + null); // Substrait Extended Expression: Project New Column: // Expression ADD: id + 2 // Expression CONCAT: name + '-' + name - String base64EncodedSubstraitFilter = "Ch4IARIaL2Z1bmN0aW9uc19hcml0aG1ldGljLnlhbWwSERoPCAEaC2FkZDppM" + - "zJfaTMyEhQaEggCEAEaDGNvbmNhdDp2Y2hhchoxChoaGBoEKgIQASIIGgYSBAoCEgAiBhoECgIoAhoTYWRkX3R3b190b19jb2x1" + - "bW5fYRpGCi0aKwgBGgRiAhABIgoaCBIGCgQSAggBIgkaBwoFYgMgLSAiChoIEgYKBBICCAEaFWNvbmNhdF9jb2x1bW5fYV9hbmR" + - "fYiIaCgJJRAoETkFNRRIOCgQqAhABCgRiAhABGAI="; + String base64EncodedSubstraitFilter = + "Ch4IARIaL2Z1bmN0aW9uc19hcml0aG1ldGljLnlhbWwSERoPCAEaC2FkZDppM" + + "zJfaTMyEhQaEggCEAEaDGNvbmNhdDp2Y2hhchoxChoaGBoEKgIQASIIGgYSBAoCEgAiBhoECgIoAhoTYWRkX3R3b190b19jb2x1" + + "bW5fYRpGCi0aKwgBGgRiAhABIgoaCBIGCgQSAggBIgkaBwoFYgMgLSAiChoIEgYKBBICCAEaFWNvbmNhdF9jb2x1bW5fYV9hbmR" + + "fYiIaCgJJRAoETkFNRRIOCgQqAhABCgRiAhABGAI="; ByteBuffer substraitExpressionFilter = getByteBuffer(base64EncodedSubstraitFilter); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 19, "value_19", 1, "value_1", - 11, "value_11", 21, "value_21", 45, "value_45"); - ScanOptions options = new ScanOptions.Builder(/*batchSize*/ 32768) - .columns(Optional.empty()) - .substraitFilter(substraitExpressionFilter) - .build(); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); - Dataset dataset = datasetFactory.finish() - ) { + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, + TMP.newFolder(), + 19, + "value_19", + 1, + "value_1", + 11, + "value_11", + 21, + "value_21", + 45, + "value_45"); + ScanOptions options = + new ScanOptions.Builder(/*batchSize*/ 32768) + .columns(Optional.empty()) + .substraitFilter(substraitExpressionFilter) + .build(); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); + Dataset dataset = datasetFactory.finish()) { Exception e = assertThrows(RuntimeException.class, () -> dataset.newScan(options)); - assertTrue(e.getMessage().startsWith("There is no filter expression in the expression provided")); + assertTrue( + e.getMessage().startsWith("There is no filter expression in the expression provided")); } } @Test public void testRunExtendedExpressionsFilterWithEmptyFilterException() throws Exception { - final Schema schema = new Schema(Arrays.asList( - Field.nullable("id", new ArrowType.Int(32, true)), - Field.nullable("name", new ArrowType.Utf8()) - ), null); + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("id", new ArrowType.Int(32, true)), + Field.nullable("name", new ArrowType.Utf8())), + null); String base64EncodedSubstraitFilter = ""; ByteBuffer substraitExpressionFilter = getByteBuffer(base64EncodedSubstraitFilter); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 19, "value_19", 1, "value_1", - 11, "value_11", 21, "value_21", 45, "value_45"); - ScanOptions options = new ScanOptions.Builder(/*batchSize*/ 32768) - .columns(Optional.empty()) - .substraitFilter(substraitExpressionFilter) - .build(); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); - Dataset dataset = datasetFactory.finish() - ) { + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, + TMP.newFolder(), + 19, + "value_19", + 1, + "value_1", + 11, + "value_11", + 21, + "value_21", + 45, + "value_45"); + ScanOptions options = + new ScanOptions.Builder(/*batchSize*/ 32768) + .columns(Optional.empty()) + .substraitFilter(substraitExpressionFilter) + .build(); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); + Dataset dataset = datasetFactory.finish()) { Exception e = assertThrows(RuntimeException.class, () -> dataset.newScan(options)); - assertTrue(e.getMessage().contains("no anonymous struct type was provided to which names could be attached.")); + assertTrue( + e.getMessage() + .contains("no anonymous struct type was provided to which names could be attached.")); } } @Test public void testRunExtendedExpressionsProjection() throws Exception { - final Schema schema = new Schema(Arrays.asList( - Field.nullable("add_two_to_column_a", new ArrowType.Int(32, true)), - Field.nullable("concat_column_a_and_b", new ArrowType.Utf8()) - ), null); + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("add_two_to_column_a", new ArrowType.Int(32, true)), + Field.nullable("concat_column_a_and_b", new ArrowType.Utf8())), + null); // Substrait Extended Expression: Project New Column: // Expression ADD: id + 2 // Expression CONCAT: name + '-' + name - String binarySubstraitExpressionProject = "Ch4IARIaL2Z1bmN0aW9uc19hcml0aG1ldGljLnlhbWwSERoPCAEaC2FkZDppM" + - "zJfaTMyEhQaEggCEAEaDGNvbmNhdDp2Y2hhchoxChoaGBoEKgIQASIIGgYSBAoCEgAiBhoECgIoAhoTYWRkX3R3b190b19jb2x1" + - "bW5fYRpGCi0aKwgBGgRiAhABIgoaCBIGCgQSAggBIgkaBwoFYgMgLSAiChoIEgYKBBICCAEaFWNvbmNhdF9jb2x1bW5fYV9hbmR" + - "fYiIaCgJJRAoETkFNRRIOCgQqAhABCgRiAhABGAI="; + String binarySubstraitExpressionProject = + "Ch4IARIaL2Z1bmN0aW9uc19hcml0aG1ldGljLnlhbWwSERoPCAEaC2FkZDppM" + + "zJfaTMyEhQaEggCEAEaDGNvbmNhdDp2Y2hhchoxChoaGBoEKgIQASIIGgYSBAoCEgAiBhoECgIoAhoTYWRkX3R3b190b19jb2x1" + + "bW5fYRpGCi0aKwgBGgRiAhABIgoaCBIGCgQSAggBIgkaBwoFYgMgLSAiChoIEgYKBBICCAEaFWNvbmNhdF9jb2x1bW5fYV9hbmR" + + "fYiIaCgJJRAoETkFNRRIOCgQqAhABCgRiAhABGAI="; ByteBuffer substraitExpressionProject = getByteBuffer(binarySubstraitExpressionProject); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 19, "value_19", 1, "value_1", - 11, "value_11", 21, "value_21", 45, "value_45"); - ScanOptions options = new ScanOptions.Builder(/*batchSize*/ 32768) - .columns(Optional.empty()) - .substraitProjection(substraitExpressionProject) - .build(); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, + TMP.newFolder(), + 19, + "value_19", + 1, + "value_1", + 11, + "value_11", + 21, + "value_21", + 45, + "value_45"); + ScanOptions options = + new ScanOptions.Builder(/*batchSize*/ 32768) + .columns(Optional.empty()) + .substraitProjection(substraitExpressionProject) + .build(); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); Dataset dataset = datasetFactory.finish(); Scanner scanner = dataset.newScan(options); - ArrowReader reader = scanner.scanBatches() - ) { + ArrowReader reader = scanner.scanBatches()) { assertEquals(schema.getFields(), reader.getVectorSchemaRoot().getSchema().getFields()); int rowcount = 0; while (reader.loadNextBatch()) { - assertTrue(reader.getVectorSchemaRoot().getVector("add_two_to_column_a").toString() - .equals("[21, 3, 13, 23, 47]")); - assertTrue(reader.getVectorSchemaRoot().getVector("concat_column_a_and_b").toString() - .equals("[value_19 - value_19, value_1 - value_1, value_11 - value_11, " + - "value_21 - value_21, value_45 - value_45]")); + assertTrue( + reader + .getVectorSchemaRoot() + .getVector("add_two_to_column_a") + .toString() + .equals("[21, 3, 13, 23, 47]")); + assertTrue( + reader + .getVectorSchemaRoot() + .getVector("concat_column_a_and_b") + .toString() + .equals( + "[value_19 - value_19, value_1 - value_1, value_11 - value_11, " + + "value_21 - value_21, value_45 - value_45]")); rowcount += reader.getVectorSchemaRoot().getRowCount(); } assertEquals(5, rowcount); @@ -343,35 +464,55 @@ public void testRunExtendedExpressionsProjection() throws Exception { } @Test - public void testRunExtendedExpressionsProjectionWithFilterInsteadOfProjectionException() throws Exception { - final Schema schema = new Schema(Arrays.asList( - Field.nullable("filter_id_lower_than_20", new ArrowType.Bool()) - ), null); + public void testRunExtendedExpressionsProjectionWithFilterInsteadOfProjectionException() + throws Exception { + final Schema schema = + new Schema( + Arrays.asList(Field.nullable("filter_id_lower_than_20", new ArrowType.Bool())), null); // Substrait Extended Expression: Filter: // Expression 01: WHERE ID < 20 - String binarySubstraitExpressionFilter = "Ch4IARIaL2Z1bmN0aW9uc19jb21wYXJpc29uLnlhbWwSEhoQCAIQAhoKbHQ6YW55X2F" + - "ueRo3ChwaGggCGgQKAhABIggaBhIECgISACIGGgQKAigUGhdmaWx0ZXJfaWRfbG93ZXJfdGhhbl8yMCIaCgJJRAoETkFNRRIOCgQqAhA" + - "BCgRiAhABGAI="; + String binarySubstraitExpressionFilter = + "Ch4IARIaL2Z1bmN0aW9uc19jb21wYXJpc29uLnlhbWwSEhoQCAIQAhoKbHQ6YW55X2F" + + "ueRo3ChwaGggCGgQKAhABIggaBhIECgISACIGGgQKAigUGhdmaWx0ZXJfaWRfbG93ZXJfdGhhbl8yMCIaCgJJRAoETkFNRRIOCgQqAhA" + + "BCgRiAhABGAI="; ByteBuffer substraitExpressionFilter = getByteBuffer(binarySubstraitExpressionFilter); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 19, "value_19", 1, "value_1", - 11, "value_11", 21, "value_21", 45, "value_45"); - ScanOptions options = new ScanOptions.Builder(/*batchSize*/ 32768) - .columns(Optional.empty()) - .substraitProjection(substraitExpressionFilter) - .build(); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, + TMP.newFolder(), + 19, + "value_19", + 1, + "value_1", + 11, + "value_11", + 21, + "value_21", + 45, + "value_45"); + ScanOptions options = + new ScanOptions.Builder(/*batchSize*/ 32768) + .columns(Optional.empty()) + .substraitProjection(substraitExpressionFilter) + .build(); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); Dataset dataset = datasetFactory.finish(); Scanner scanner = dataset.newScan(options); - ArrowReader reader = scanner.scanBatches() - ) { + ArrowReader reader = scanner.scanBatches()) { assertEquals(schema.getFields(), reader.getVectorSchemaRoot().getSchema().getFields()); int rowcount = 0; while (reader.loadNextBatch()) { - assertTrue(reader.getVectorSchemaRoot().getVector("filter_id_lower_than_20").toString() - .equals("[true, true, true, false, false]")); + assertTrue( + reader + .getVectorSchemaRoot() + .getVector("filter_id_lower_than_20") + .toString() + .equals("[true, true, true, false, false]")); rowcount += reader.getVectorSchemaRoot().getRowCount(); } assertEquals(5, rowcount); @@ -380,71 +521,115 @@ public void testRunExtendedExpressionsProjectionWithFilterInsteadOfProjectionExc @Test public void testRunExtendedExpressionsProjectionWithEmptyProjectionException() throws Exception { - final Schema schema = new Schema(Arrays.asList( - Field.nullable("id", new ArrowType.Int(32, true)), - Field.nullable("name", new ArrowType.Utf8()) - ), null); + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("id", new ArrowType.Int(32, true)), + Field.nullable("name", new ArrowType.Utf8())), + null); String base64EncodedSubstraitFilter = ""; ByteBuffer substraitExpressionProjection = getByteBuffer(base64EncodedSubstraitFilter); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 19, "value_19", 1, "value_1", - 11, "value_11", 21, "value_21", 45, "value_45"); - ScanOptions options = new ScanOptions.Builder(/*batchSize*/ 32768) - .columns(Optional.empty()) - .substraitProjection(substraitExpressionProjection) - .build(); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); - Dataset dataset = datasetFactory.finish() - ) { + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, + TMP.newFolder(), + 19, + "value_19", + 1, + "value_1", + 11, + "value_11", + 21, + "value_21", + 45, + "value_45"); + ScanOptions options = + new ScanOptions.Builder(/*batchSize*/ 32768) + .columns(Optional.empty()) + .substraitProjection(substraitExpressionProjection) + .build(); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); + Dataset dataset = datasetFactory.finish()) { Exception e = assertThrows(RuntimeException.class, () -> dataset.newScan(options)); - assertTrue(e.getMessage().contains("no anonymous struct type was provided to which names could be attached.")); + assertTrue( + e.getMessage() + .contains("no anonymous struct type was provided to which names could be attached.")); } } @Test public void testRunExtendedExpressionsProjectAndFilter() throws Exception { - final Schema schema = new Schema(Arrays.asList( - Field.nullable("add_two_to_column_a", new ArrowType.Int(32, true)), - Field.nullable("concat_column_a_and_b", new ArrowType.Utf8()) - ), null); + final Schema schema = + new Schema( + Arrays.asList( + Field.nullable("add_two_to_column_a", new ArrowType.Int(32, true)), + Field.nullable("concat_column_a_and_b", new ArrowType.Utf8())), + null); // Substrait Extended Expression: Project New Column: // Expression ADD: id + 2 // Expression CONCAT: name + '-' + name - String binarySubstraitExpressionProject = "Ch4IARIaL2Z1bmN0aW9uc19hcml0aG1ldGljLnlhbWwSERoPCAEaC2FkZDppM" + - "zJfaTMyEhQaEggCEAEaDGNvbmNhdDp2Y2hhchoxChoaGBoEKgIQASIIGgYSBAoCEgAiBhoECgIoAhoTYWRkX3R3b190b19jb2x1" + - "bW5fYRpGCi0aKwgBGgRiAhABIgoaCBIGCgQSAggBIgkaBwoFYgMgLSAiChoIEgYKBBICCAEaFWNvbmNhdF9jb2x1bW5fYV9hbmR" + - "fYiIaCgJJRAoETkFNRRIOCgQqAhABCgRiAhABGAI="; + String binarySubstraitExpressionProject = + "Ch4IARIaL2Z1bmN0aW9uc19hcml0aG1ldGljLnlhbWwSERoPCAEaC2FkZDppM" + + "zJfaTMyEhQaEggCEAEaDGNvbmNhdDp2Y2hhchoxChoaGBoEKgIQASIIGgYSBAoCEgAiBhoECgIoAhoTYWRkX3R3b190b19jb2x1" + + "bW5fYRpGCi0aKwgBGgRiAhABIgoaCBIGCgQSAggBIgkaBwoFYgMgLSAiChoIEgYKBBICCAEaFWNvbmNhdF9jb2x1bW5fYV9hbmR" + + "fYiIaCgJJRAoETkFNRRIOCgQqAhABCgRiAhABGAI="; ByteBuffer substraitExpressionProject = getByteBuffer(binarySubstraitExpressionProject); // Substrait Extended Expression: Filter: // Expression 01: WHERE ID < 20 - String base64EncodedSubstraitFilter = "Ch4IARIaL2Z1bmN0aW9uc19jb21wYXJpc29uLnlhbWwSEhoQCAIQAhoKbHQ6YW55X2F" + - "ueRo3ChwaGggCGgQKAhABIggaBhIECgISACIGGgQKAigUGhdmaWx0ZXJfaWRfbG93ZXJfdGhhbl8yMCIaCgJJRAoETkFNRRIOCgQqAhA" + - "BCgRiAhABGAI="; + String base64EncodedSubstraitFilter = + "Ch4IARIaL2Z1bmN0aW9uc19jb21wYXJpc29uLnlhbWwSEhoQCAIQAhoKbHQ6YW55X2F" + + "ueRo3ChwaGggCGgQKAhABIggaBhIECgISACIGGgQKAigUGhdmaWx0ZXJfaWRfbG93ZXJfdGhhbl8yMCIaCgJJRAoETkFNRRIOCgQqAhA" + + "BCgRiAhABGAI="; ByteBuffer substraitExpressionFilter = getByteBuffer(base64EncodedSubstraitFilter); - ParquetWriteSupport writeSupport = ParquetWriteSupport - .writeTempFile(AVRO_SCHEMA_USER, TMP.newFolder(), 19, "value_19", 1, "value_1", - 11, "value_11", 21, "value_21", 45, "value_45"); - ScanOptions options = new ScanOptions.Builder(/*batchSize*/ 32768) - .columns(Optional.empty()) - .substraitProjection(substraitExpressionProject) - .substraitFilter(substraitExpressionFilter) - .build(); - try ( - DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator(), NativeMemoryPool.getDefault(), - FileFormat.PARQUET, writeSupport.getOutputURI()); + ParquetWriteSupport writeSupport = + ParquetWriteSupport.writeTempFile( + AVRO_SCHEMA_USER, + TMP.newFolder(), + 19, + "value_19", + 1, + "value_1", + 11, + "value_11", + 21, + "value_21", + 45, + "value_45"); + ScanOptions options = + new ScanOptions.Builder(/*batchSize*/ 32768) + .columns(Optional.empty()) + .substraitProjection(substraitExpressionProject) + .substraitFilter(substraitExpressionFilter) + .build(); + try (DatasetFactory datasetFactory = + new FileSystemDatasetFactory( + rootAllocator(), + NativeMemoryPool.getDefault(), + FileFormat.PARQUET, + writeSupport.getOutputURI()); Dataset dataset = datasetFactory.finish(); Scanner scanner = dataset.newScan(options); - ArrowReader reader = scanner.scanBatches() - ) { + ArrowReader reader = scanner.scanBatches()) { assertEquals(schema.getFields(), reader.getVectorSchemaRoot().getSchema().getFields()); int rowcount = 0; while (reader.loadNextBatch()) { - assertTrue(reader.getVectorSchemaRoot().getVector("add_two_to_column_a").toString() - .equals("[21, 3, 13]")); - assertTrue(reader.getVectorSchemaRoot().getVector("concat_column_a_and_b").toString() - .equals("[value_19 - value_19, value_1 - value_1, value_11 - value_11]")); + assertTrue( + reader + .getVectorSchemaRoot() + .getVector("add_two_to_column_a") + .toString() + .equals("[21, 3, 13]")); + assertTrue( + reader + .getVectorSchemaRoot() + .getVector("concat_column_a_and_b") + .toString() + .equals("[value_19 - value_19, value_1 - value_1, value_11 - value_11]")); rowcount += reader.getVectorSchemaRoot().getRowCount(); } assertEquals(3, rowcount); diff --git a/java/flight/flight-core/pom.xml b/java/flight/flight-core/pom.xml index 01ecbf96a36..afc4d13f478 100644 --- a/java/flight/flight-core/pom.xml +++ b/java/flight/flight-core/pom.xml @@ -12,16 +12,16 @@ 4.0.0 - arrow-flight org.apache.arrow + arrow-flight 16.0.0-SNAPSHOT ../pom.xml flight-core + jar Arrow Flight Core (Experimental)An RPC mechanism for transferring ValueVectors. - jar 1 @@ -116,7 +116,7 @@ javax.annotation javax.annotation-api - + org.immutables value @@ -138,13 +138,6 @@ - - - kr.motd.maven - os-maven-plugin - 1.7.0 - - maven-surefire-plugin @@ -163,15 +156,15 @@ Using a newer version up to at least 3.5.1 will cause issues in the arrow-tools tests looking up FlatBuffer dependencies. - --> + --> 3.2.4 shade-main - package shade + package true shaded @@ -188,16 +181,16 @@ - + shade-ext - package shade + package true shaded-ext @@ -219,7 +212,7 @@ - + @@ -238,25 +231,25 @@ src + + compile + compile-custom + ${basedir}/../../../format/ ${project.build.directory}/generated-sources/protobuf + + + test compile compile-custom - - - test ${basedir}/src/test/protobuf ${project.build.directory}/generated-test-sources//protobuf - - compile - compile-custom - @@ -267,10 +260,10 @@ analyze - verify analyze-only + verify io.netty:netty-tcnative-boringssl-static:* @@ -279,17 +272,18 @@ - + + org.codehaus.mojo build-helper-maven-plugin 1.9.1 add-generated-sources-to-classpath - generate-sources add-source + generate-sources ${project.build.directory}/generated-sources/protobuf @@ -309,14 +303,21 @@ make-assembly - package single + package + + + kr.motd.maven + os-maven-plugin + 1.7.0 + + diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java index 16c55f6804e..0b0fbf05909 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java @@ -478,7 +478,8 @@ public void testProtobufSchemaCompatibility() throws Exception { // Should have no body buffers Assertions.assertFalse(message.getBufs().iterator().hasNext()); final Flight.FlightData protobufData = - arrowMessageToProtobuf(marshaller, message).toBuilder() + arrowMessageToProtobuf(marshaller, message) + .toBuilder() .setDataBody(ByteString.EMPTY) .build(); Assertions.assertEquals(0, protobufData.getDataBody().size()); diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java index 2f02a25e64d..b924a22388c 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java @@ -135,8 +135,7 @@ public Runnable acceptPut( CallContext context, FlightStream flightStream, StreamListener ackStream) { return () -> { try (VectorSchemaRoot root = flightStream.getRoot()) { - while (flightStream.next()) { - ; + while (flightStream.next()) {; } } }; diff --git a/java/flight/flight-integration-tests/pom.xml b/java/flight/flight-integration-tests/pom.xml index 944c624d630..5f9654e700a 100644 --- a/java/flight/flight-integration-tests/pom.xml +++ b/java/flight/flight-integration-tests/pom.xml @@ -9,73 +9,72 @@ 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. --> - - 4.0.0 - - arrow-flight - org.apache.arrow - 16.0.0-SNAPSHOT - ../pom.xml - + + 4.0.0 + + org.apache.arrow + arrow-flight + 16.0.0-SNAPSHOT + ../pom.xml + - flight-integration-tests - Arrow Flight Integration Tests - Integration tests for Flight RPC. - jar + flight-integration-tests + jar + Arrow Flight Integration Tests + Integration tests for Flight RPC. - - - org.apache.arrow - arrow-vector - - - org.apache.arrow - arrow-memory-core - - - org.apache.arrow - flight-core - - - org.apache.arrow - flight-sql - - - com.google.protobuf - protobuf-java - - - commons-cli - commons-cli - 1.6.0 - - - org.slf4j - slf4j-api - - + + + org.apache.arrow + arrow-vector + + + org.apache.arrow + arrow-memory-core + + + org.apache.arrow + flight-core + + + org.apache.arrow + flight-sql + + + com.google.protobuf + protobuf-java + + + commons-cli + commons-cli + 1.6.0 + + + org.slf4j + slf4j-api + + - - - - maven-assembly-plugin - 3.0.0 - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - - - + + + + maven-assembly-plugin + 3.0.0 + + + jar-with-dependencies + + + + + make-assembly + + single + + package + + + + + diff --git a/java/flight/flight-sql-jdbc-core/pom.xml b/java/flight/flight-sql-jdbc-core/pom.xml index b38b76a72de..613d65a55d0 100644 --- a/java/flight/flight-sql-jdbc-core/pom.xml +++ b/java/flight/flight-sql-jdbc-core/pom.xml @@ -9,167 +9,165 @@ 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. --> - - - arrow-flight - org.apache.arrow - 16.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - flight-sql-jdbc-core - Arrow Flight SQL JDBC Driver Core - Core implementation of JDBC driver based on Arrow Flight SQL. - jar - https://arrow.apache.org - - - ${project.parent.groupId}:${project.parent.artifactId} - ${project.parent.version} - ${project.name} - ${project.version} - - - - - org.apache.arrow - flight-core - - - io.netty - netty-transport-native-kqueue - - - io.netty - netty-transport-native-epoll - - - - - - - org.apache.arrow - arrow-memory-core - - - - - org.apache.arrow - arrow-memory-netty - runtime - - - - - org.apache.arrow - arrow-vector - ${arrow.vector.classifier} - - - - com.google.guava - guava - - - - org.slf4j - slf4j-api - runtime - - - - com.google.protobuf - protobuf-java - - - - org.hamcrest - hamcrest-core - 1.3 - test - - - - commons-io - commons-io - 2.7 - test - - - - org.mockito - mockito-core - ${mockito.core.version} - test - - - - org.mockito - mockito-inline - ${mockito.inline.version} - test - - - - io.netty - netty-common - - - - org.apache.arrow - flight-sql - ${project.version} - - - - org.apache.calcite.avatica - avatica - 1.24.0 - - - - org.bouncycastle - bcpkix-jdk15on - 1.70 - - - - - - - src/main/resources - - - - - maven-surefire-plugin - - false - - ${project.basedir}/../../../testing/data - - - - - org.codehaus.mojo - properties-maven-plugin - 1.1.0 - - - write-project-properties-to-file - generate-resources - - write-project-properties - - - src/main/resources/properties/flight.properties - - - - - - + + 4.0.0 + + org.apache.arrow + arrow-flight + 16.0.0-SNAPSHOT + ../pom.xml + + + flight-sql-jdbc-core + jar + Arrow Flight SQL JDBC Driver Core + Core implementation of JDBC driver based on Arrow Flight SQL. + https://arrow.apache.org + + + ${project.parent.groupId}:${project.parent.artifactId} + ${project.parent.version} + ${project.name} + ${project.version} + + + + + org.apache.arrow + flight-core + + + io.netty + netty-transport-native-kqueue + + + io.netty + netty-transport-native-epoll + + + + + + + org.apache.arrow + arrow-memory-core + + + + + org.apache.arrow + arrow-memory-netty + runtime + + + + + org.apache.arrow + arrow-vector + ${arrow.vector.classifier} + + + + com.google.guava + guava + + + + org.slf4j + slf4j-api + runtime + + + + com.google.protobuf + protobuf-java + + + + org.hamcrest + hamcrest-core + 1.3 + test + + + + commons-io + commons-io + 2.7 + test + + + + org.mockito + mockito-core + ${mockito.core.version} + test + + + + org.mockito + mockito-inline + ${mockito.inline.version} + test + + + + io.netty + netty-common + + + + org.apache.arrow + flight-sql + ${project.version} + + + + org.apache.calcite.avatica + avatica + 1.24.0 + + + + org.bouncycastle + bcpkix-jdk15on + 1.70 + + + + + + + src/main/resources + + + + + maven-surefire-plugin + + false + + ${project.basedir}/../../../testing/data + + + + + org.codehaus.mojo + properties-maven-plugin + 1.1.0 + + + write-project-properties-to-file + + write-project-properties + + generate-resources + + src/main/resources/properties/flight.properties + + + + + + diff --git a/java/flight/flight-sql-jdbc-driver/pom.xml b/java/flight/flight-sql-jdbc-driver/pom.xml index bcd5848f8b6..b52f3e6a504 100644 --- a/java/flight/flight-sql-jdbc-driver/pom.xml +++ b/java/flight/flight-sql-jdbc-driver/pom.xml @@ -9,230 +9,228 @@ 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. --> - - - arrow-flight - org.apache.arrow - 16.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - flight-sql-jdbc-driver - Arrow Flight SQL JDBC Driver - A JDBC driver based on Arrow Flight SQL. - jar - https://arrow.apache.org - - - - - org.hamcrest - hamcrest-core - 1.3 - test - - - - org.apache.arrow - flight-sql-jdbc-core - runtime - - - - org.bouncycastle - bcpkix-jdk15on - 1.70 - runtime - - - - - org.apache.arrow - arrow-memory-core - runtime - - - - org.apache.arrow - flight-sql - runtime - - - - org.mockito - mockito-core - ${mockito.core.version} - test - - - - org.mockito - mockito-inline - ${mockito.inline.version} - test - - - - org.apache.arrow - flight-core - - - io.netty - netty-transport-native-kqueue - - - io.netty - netty-transport-native-epoll - - - runtime - - - - org.slf4j - slf4j-api - runtime - - - - io.netty - netty-common - runtime - - - - joda-time - joda-time - 2.12.6 - runtime - - - - org.apache.calcite.avatica - avatica - 1.24.0 - runtime - - - - com.google.protobuf - protobuf-java - runtime - - - - org.apache.arrow - arrow-vector - ${arrow.vector.classifier} - runtime - - - - com.google.guava - guava - runtime - - - - commons-io - commons-io - 2.7 - test - - - - - - - maven-surefire-plugin - - false - - ${project.basedir}/../../../testing/data - - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - false - false - false - - - *:* - - - - - com. - cfjd.com. - - com.sun.** - - - - org. - cfjd.org. - - org.apache.arrow.driver.jdbc.** - org.slf4j.** - - org.apache.arrow.flight.name - org.apache.arrow.flight.version - org.apache.arrow.flight.jdbc-driver.name - org.apache.arrow.flight.jdbc-driver.version - - - - io. - cfjd.io. - - - - META-INF.native.libnetty_ - META-INF.native.libcfjd_netty_ - - - META-INF.native.netty_ - META-INF.native.cfjd_netty_ - - - - - - - - org.apache.calcite.avatica:* - - META-INF/services/java.sql.Driver - - - - *:* - - **/*.SF - **/*.RSA - **/*.DSA - META-INF/native/libio_grpc_netty* - META-INF/native/io_grpc_netty_shaded* - - - - - - - - - + + 4.0.0 + + org.apache.arrow + arrow-flight + 16.0.0-SNAPSHOT + ../pom.xml + + + flight-sql-jdbc-driver + jar + Arrow Flight SQL JDBC Driver + A JDBC driver based on Arrow Flight SQL. + https://arrow.apache.org + + + + + org.hamcrest + hamcrest-core + 1.3 + test + + + + org.apache.arrow + flight-sql-jdbc-core + runtime + + + + org.bouncycastle + bcpkix-jdk15on + 1.70 + runtime + + + + + org.apache.arrow + arrow-memory-core + runtime + + + + org.apache.arrow + flight-sql + runtime + + + + org.mockito + mockito-core + ${mockito.core.version} + test + + + + org.mockito + mockito-inline + ${mockito.inline.version} + test + + + + org.apache.arrow + flight-core + runtime + + + io.netty + netty-transport-native-kqueue + + + io.netty + netty-transport-native-epoll + + + + + + org.slf4j + slf4j-api + runtime + + + + io.netty + netty-common + runtime + + + + joda-time + joda-time + 2.12.6 + runtime + + + + org.apache.calcite.avatica + avatica + 1.24.0 + runtime + + + + com.google.protobuf + protobuf-java + runtime + + + + org.apache.arrow + arrow-vector + ${arrow.vector.classifier} + runtime + + + + com.google.guava + guava + runtime + + + + commons-io + commons-io + 2.7 + test + + + + + + + maven-surefire-plugin + + false + + ${project.basedir}/../../../testing/data + + + + + org.apache.maven.plugins + maven-shade-plugin + + + + shade + + package + + false + false + false + + + *:* + + + + + com. + cfjd.com. + + com.sun.** + + + + org. + cfjd.org. + + org.apache.arrow.driver.jdbc.** + org.slf4j.** + + org.apache.arrow.flight.name + org.apache.arrow.flight.version + org.apache.arrow.flight.jdbc-driver.name + org.apache.arrow.flight.jdbc-driver.version + + + + io. + cfjd.io. + + + + META-INF.native.libnetty_ + META-INF.native.libcfjd_netty_ + + + META-INF.native.netty_ + META-INF.native.cfjd_netty_ + + + + + + + + org.apache.calcite.avatica:* + + META-INF/services/java.sql.Driver + + + + *:* + + **/*.SF + **/*.RSA + **/*.DSA + META-INF/native/libio_grpc_netty* + META-INF/native/io_grpc_netty_shaded* + + + + + + + + + diff --git a/java/flight/flight-sql/pom.xml b/java/flight/flight-sql/pom.xml index a0598f70b95..f74a8b514a4 100644 --- a/java/flight/flight-sql/pom.xml +++ b/java/flight/flight-sql/pom.xml @@ -12,16 +12,16 @@ 4.0.0 - arrow-flight org.apache.arrow + arrow-flight 16.0.0-SNAPSHOT ../pom.xml flight-sql + jar Arrow Flight SQL (Experimental)Contains utility classes to expose Flight SQL semantics for clients and servers over Arrow Flight - jar 1 diff --git a/java/flight/pom.xml b/java/flight/pom.xml index 2f777ab42b7..b7afab9a79d 100644 --- a/java/flight/pom.xml +++ b/java/flight/pom.xml @@ -9,59 +9,54 @@ 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. --> - - - arrow-java-root - org.apache.arrow - 16.0.0-SNAPSHOT - - 4.0.0 + + 4.0.0 + + org.apache.arrow + arrow-java-root + 16.0.0-SNAPSHOT + + arrow-flight - Arrow Flight - arrow-flight + pom - pom + Arrow Flight - - flight-core - flight-sql - flight-sql-jdbc-core - flight-sql-jdbc-driver - flight-integration-tests - + + flight-core + flight-sql + flight-sql-jdbc-core + flight-sql-jdbc-driver + flight-integration-tests + - - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.6.1 - - - com.google.protobuf:protoc:${dep.protobuf-bom.version}:exe:${os.detected.classifier} - - grpc-java - io.grpc:protoc-gen-grpc-java:${dep.grpc-bom.version}:exe:${os.detected.classifier} - - - - - - + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + com.google.protobuf:protoc:${dep.protobuf-bom.version}:exe:${os.detected.classifier} + grpc-java + io.grpc:protoc-gen-grpc-java:${dep.grpc-bom.version}:exe:${os.detected.classifier} + + + + + - - - pin-mockito-jdk8 - - 1.8 - - - 4.11.0 - 5.2.0 - - - + + + pin-mockito-jdk8 + + 1.8 + + + 4.11.0 + 5.2.0 + + + diff --git a/java/format/pom.xml b/java/format/pom.xml index cc9fa9fa95e..5f089e676ee 100644 --- a/java/format/pom.xml +++ b/java/format/pom.xml @@ -10,18 +10,18 @@ OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -4.0.0 + 4.0.0 - - arrow-java-root - org.apache.arrow - 16.0.0-SNAPSHOT - + + org.apache.arrow + arrow-java-root + 16.0.0-SNAPSHOT + -arrow-format -jar -Arrow Format -Generated Java files from the IPC Flatbuffer definitions. + arrow-format + jar + Arrow Format + Generated Java files from the IPC Flatbuffer definitions. @@ -30,10 +30,9 @@ - + - - + - + diff --git a/java/maven/module-info-compiler-maven-plugin/pom.xml b/java/maven/module-info-compiler-maven-plugin/pom.xml index 37d14ad412d..8509aa8a501 100644 --- a/java/maven/module-info-compiler-maven-plugin/pom.xml +++ b/java/maven/module-info-compiler-maven-plugin/pom.xml @@ -9,9 +9,7 @@ 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. --> - + 4.0.0 org.apache.arrow.maven.plugins @@ -72,7 +70,8 @@ - + + maven-clean-plugin diff --git a/java/maven/pom.xml b/java/maven/pom.xml index b558f188ec3..2b68c1b2324 100644 --- a/java/maven/pom.xml +++ b/java/maven/pom.xml @@ -18,8 +18,8 @@ org.apache.arrow.maven.plugins arrow-maven-plugins 16.0.0-SNAPSHOT - Arrow Maven Plugins pom + Arrow Maven Plugins module-info-compiler-maven-plugin @@ -27,23 +27,29 @@ true - 2.42.0 + 2.42.0 + 2.30.0 + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.5.0 + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + org.apache.rat apache-rat-plugin - - - rat-checks - validate - - check - - - false @@ -88,6 +94,15 @@ **/*.idea/** + + + rat-checks + + check + + validate + + @@ -125,7 +140,6 @@ - org.apache.maven.plugins maven-resources-plugin @@ -150,10 +164,10 @@ validate_java_and_maven_version - verify enforce + verify false @@ -165,10 +179,10 @@ avoid_bad_dependencies - verify enforce + verify @@ -189,13 +203,28 @@ pl.project13.maven git-commit-id-plugin 4.0.5 + + + dd.MM.yyyy '@' HH:mm:ss z + false + false + true + false + + false + false + 7 + -dirty + true + + for-jars - true revision + true target/classes/arrow-git.properties @@ -211,21 +240,6 @@ - - - dd.MM.yyyy '@' HH:mm:ss z - false - false - true - false - - false - false - 7 - -dirty - true - - @@ -234,10 +248,10 @@ 2.7.10 - package makeBom + package @@ -248,19 +262,19 @@ org.apache.maven.plugins maven-assembly-plugin + + + src + + - package single + package - - - src - - @@ -271,80 +285,7 @@ org.apache.maven.plugins maven-site-plugin - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version} - - - - - - - src/main/**/*.xml - src/test/**/*.xml - **/pom.xml - - - ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license - (<configuration|<project) - - - - - - true - 2 - - - true - 2 - - - - ${maven.multiModuleProjectDirectory}/spotless/asf-java.license - (package|import) - - - - - true - 2 - - - true - 2 - - - false - - - - - - spotless-check - - check - - validate - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 3.5.0 - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - - @@ -361,4 +302,150 @@ + + + + spotless-jdk11+ + + [11,] + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version.jdk11} + + + + + + + + src/main/**/*.xml + src/test/**/*.xml + **/pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + true + 2 + + + true + 2 + + + + + ${maven.multiModuleProjectDirectory}/spotless/asf-java.license + (package|import) + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + + + + + + + spotless-jdk8 + + 1.8 + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version.jdk8} + + + + + + + + src/main/**/*.xml + src/test/**/*.xml + **/pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + true + 2 + + + true + 2 + + + + + ${maven.multiModuleProjectDirectory}/spotless/asf-java.license + (package|import) + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + + + + + diff --git a/java/memory/memory-core/pom.xml b/java/memory/memory-core/pom.xml index 2a92d032942..2c7212cea55 100644 --- a/java/memory/memory-core/pom.xml +++ b/java/memory/memory-core/pom.xml @@ -10,12 +10,12 @@ OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + 4.0.0 - arrow-memory org.apache.arrow + arrow-memory 16.0.0-SNAPSHOT - 4.0.0 arrow-memory-core @@ -96,10 +96,10 @@ opens-tests - test test + test -Dfoo=bar @@ -133,12 +133,15 @@ 8 UTF-8 - -Xmaxerrs + -Xmaxerrs + 10000 -Xmaxwarns 10000 - -AskipDefs=.*Test - -AatfDoNotCache + -AskipDefs=.*Test + + -AatfDoNotCache + diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationManager.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationManager.java index 3b18ccb6ade..e6e70a6247e 100644 --- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationManager.java +++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationManager.java @@ -75,7 +75,8 @@ protected AllocationManager(BufferAllocator accountingAllocator) { this.owningLedger = associate(accountingAllocator, false); } - @Nullable BufferLedger getOwningLedger() { + @Nullable + BufferLedger getOwningLedger() { return owningLedger; } diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java index 4c67b4bfc58..4ab3cf6737a 100644 --- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java +++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java @@ -158,7 +158,8 @@ BufferAllocator newChildAllocator( * * @return parent allocator */ - @Nullable BufferAllocator getParentAllocator(); + @Nullable + BufferAllocator getParentAllocator(); /** * Returns the set of child allocators. diff --git a/java/memory/memory-netty-buffer-patch/pom.xml b/java/memory/memory-netty-buffer-patch/pom.xml index 97b224e9ccc..53e6ba6a9d2 100644 --- a/java/memory/memory-netty-buffer-patch/pom.xml +++ b/java/memory/memory-netty-buffer-patch/pom.xml @@ -9,15 +9,13 @@ 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. --> - + + 4.0.0 - arrow-memory org.apache.arrow + arrow-memory 16.0.0-SNAPSHOT - 4.0.0 arrow-memory-netty-buffer-patch Arrow Memory - Netty Buffer diff --git a/java/memory/memory-netty/pom.xml b/java/memory/memory-netty/pom.xml index 9b20e1bde2a..1466adae41d 100644 --- a/java/memory/memory-netty/pom.xml +++ b/java/memory/memory-netty/pom.xml @@ -10,12 +10,12 @@ OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + 4.0.0 - arrow-memory org.apache.arrow + arrow-memory 16.0.0-SNAPSHOT - 4.0.0 arrow-memory-netty Arrow Memory - Netty diff --git a/java/memory/memory-unsafe/pom.xml b/java/memory/memory-unsafe/pom.xml index 07a140e5945..da4a5fe3223 100644 --- a/java/memory/memory-unsafe/pom.xml +++ b/java/memory/memory-unsafe/pom.xml @@ -10,18 +10,17 @@ OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + 4.0.0 - arrow-memory org.apache.arrow + arrow-memory 16.0.0-SNAPSHOT - 4.0.0 arrow-memory-unsafe Arrow Memory - Unsafe Allocator and utils for allocating memory in Arrow based on sun.misc.Unsafe - org.apache.arrow diff --git a/java/memory/pom.xml b/java/memory/pom.xml index c91e16fb17d..647a64bd075 100644 --- a/java/memory/pom.xml +++ b/java/memory/pom.xml @@ -17,8 +17,8 @@ 16.0.0-SNAPSHOT arrow-memory - Arrow Memory pom + Arrow Memory memory-core diff --git a/java/performance/pom.xml b/java/performance/pom.xml index 8986197f5b1..d30ac7934be 100644 --- a/java/performance/pom.xml +++ b/java/performance/pom.xml @@ -10,207 +10,207 @@ OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - 4.0.0 - - arrow-java-root - org.apache.arrow - 16.0.0-SNAPSHOT - - arrow-performance - jar - Arrow Performance Benchmarks - JMH Performance benchmarks for other Arrow libraries. + 4.0.0 + + org.apache.arrow + arrow-java-root + 16.0.0-SNAPSHOT + + arrow-performance + jar + Arrow Performance Benchmarks + JMH Performance benchmarks for other Arrow libraries. - - - org.openjdk.jmh - jmh-core - ${jmh.version} - test - - - org.openjdk.jmh - jmh-generator-annprocess - ${jmh.version} - provided - - - org.apache.arrow - arrow-vector - ${arrow.vector.classifier} - test - - - org.apache.arrow - arrow-memory-core - test - - - org.apache.arrow - arrow-memory-netty - test - - - org.apache.avro - avro - ${dep.avro.version} - test - - - org.apache.arrow - arrow-avro - test - - - com.h2database - h2 - 2.2.224 - test - - - org.apache.arrow - arrow-jdbc - test - - - org.apache.arrow - arrow-algorithm - test - - + + UTF-8 + 1.21 + 1.8 + benchmarks + true + .* + 1 + + 5 + 5 + + jmh-result.json + json + - - UTF-8 - 1.21 - 1.8 - benchmarks - true - .* - 1 - - 5 - 5 - - jmh-result.json - json - + + + org.openjdk.jmh + jmh-core + ${jmh.version} + test + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + provided + + + org.apache.arrow + arrow-vector + ${arrow.vector.classifier} + test + + + org.apache.arrow + arrow-memory-core + test + + + org.apache.arrow + arrow-memory-netty + test + + + org.apache.avro + avro + ${dep.avro.version} + test + + + org.apache.arrow + arrow-avro + test + + + com.h2database + h2 + 2.2.224 + test + + + org.apache.arrow + arrow-jdbc + test + + + org.apache.arrow + arrow-algorithm + test + + - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${javac.target} - ${javac.target} - ${javac.target} - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - ${uberjar.name} - - - org.openjdk.jmh.Main - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - run-java-benchmarks - integration-test - - exec - - - - - ${skip.perf.benchmarks} - test - java - - -classpath - - org.openjdk.jmh.Main - ${benchmark.filter} - -f - ${benchmark.forks} - -jvmArgs - ${benchmark.jvmargs} - -wi - ${benchmark.warmups} - -i - ${benchmark.runs} - ${benchmark.list} - -rff - ${benchmark.resultfile} - -rf - ${benchmark.resultformat} - - - - - - - - maven-clean-plugin - 2.5 - - - maven-deploy-plugin - 3.1.1 - - - maven-install-plugin - 3.1.1 - - - maven-jar-plugin - 3.3.0 - - - maven-javadoc-plugin - 3.6.3 - - - maven-resources-plugin - 3.3.1 - - - maven-source-plugin - 2.2.1 - - - maven-surefire-plugin - 3.2.3 - - - - + + + + + maven-clean-plugin + 2.5 + + + maven-deploy-plugin + 3.1.1 + + + maven-install-plugin + 3.1.1 + + + maven-jar-plugin + 3.3.0 + + + maven-javadoc-plugin + 3.6.3 + + + maven-resources-plugin + 3.3.1 + + + maven-source-plugin + 2.2.1 + + + maven-surefire-plugin + 3.2.3 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${javac.target} + ${javac.target} + ${javac.target} + + + + org.apache.maven.plugins + maven-shade-plugin + + + + shade + + package + + ${uberjar.name} + + + org.openjdk.jmh.Main + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + ${skip.perf.benchmarks} + test + java + + -classpath + + org.openjdk.jmh.Main + ${benchmark.filter} + -f + ${benchmark.forks} + -jvmArgs + ${benchmark.jvmargs} + -wi + ${benchmark.warmups} + -i + ${benchmark.runs} + ${benchmark.list} + -rff + ${benchmark.resultfile} + -rf + ${benchmark.resultformat} + + + + + run-java-benchmarks + + exec + + integration-test + + + + + diff --git a/java/pom.xml b/java/pom.xml index 9dd0301a7f7..22a8acf9ddc 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -27,38 +27,6 @@ Apache Arrow is open source, in-memory columnar data structures and low-overhead messaging https://arrow.apache.org/ - - ${project.build.directory}/generated-sources - 1.9.0 - 5.10.1 - 2.0.11 - 33.0.0-jre - 4.1.106.Final - 1.60.0 - 3.23.1 - 2.16.0 - 3.3.6 - 23.5.26 - 1.11.3 - - 2 - true - 9+181-r4173-1 - 2.24.0 - 3.11.0 - 5.5.0 - 5.2.0 - 3.42.0 - 2.42.0 - - - - scm:git:https://github.com/apache/arrow.git - scm:git:https://github.com/apache/arrow.git - https://github.com/apache/arrow - apache-arrow-2.0.0 - - Developer List @@ -82,355 +50,233 @@ - + + maven + bom + format + memory + vector + tools + adapter/jdbc + flight + performance + algorithm + adapter/avro + compression + - + + scm:git:https://github.com/apache/arrow.git + scm:git:https://github.com/apache/arrow.git + apache-arrow-2.0.0 + https://github.com/apache/arrow + Jira https://issues.apache.org/jira/browse/arrow - - - - - kr.motd.maven - os-maven-plugin - 1.7.0 - - + + ${project.build.directory}/generated-sources + 1.9.0 + 5.10.1 + 2.0.11 + 33.0.0-jre + 4.1.106.Final + 1.60.0 + 3.23.1 + 2.16.0 + 3.3.6 + 23.5.26 + 1.11.3 + + 2 + true + 9+181-r4173-1 + 2.24.0 + 3.11.0 + 5.5.0 + 5.2.0 + 3.42.0 + 2.42.0 + 2.30.0 + - - - org.apache.rat - apache-rat-plugin - - - rat-checks - validate - - check - - - - - false - - **/dependency-reduced-pom.xml - **/*.log - **/*.css - **/*.js - **/*.md - **/*.eps - **/*.json - **/*.seq - **/*.parquet - **/*.sql - **/arrow-git.properties - **/*.csv - **/*.csvh - **/*.csvh-test - **/*.tsv - **/*.txt - **/*.ssv - **/arrow-*.conf - **/.buildpath - **/*.proto - **/*.fmpp - **/target/** - **/*.tdd - **/*.project - **/TAGS - **/*.checkstyle - **/.classpath - **/.factorypath - **/.settings/** - .*/** - **/*.patch - **/*.pb.cc - **/*.pb.h - **/*.linux - **/client/build/** - **/*.tbl - **/*.iml - **/flight.properties - **/*.idea/** - - - + + + + + org.apache.arrow + arrow-bom + ${project.version} + pom + import + + + org.checkerframework + checker-qual + ${checker.framework.version} + + + com.google.flatbuffers + flatbuffers-java + ${dep.fbs.version} + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + org.slf4j + slf4j-api + ${dep.slf4j.version} + + + javax.annotation + javax.annotation-api + 1.3.2 + + + org.assertj + assertj-core + 3.24.2 + test + + + org.immutables + value + 2.10.0 + provided + + + org.hamcrest + hamcrest + 2.2 + + + com.fasterxml.jackson + jackson-bom + ${dep.jackson-bom.version} + pom + import + + + com.google.guava + guava-bom + ${dep.guava-bom.version} + pom + import + + + io.netty + netty-bom + ${dep.netty-bom.version} + pom + import + + + io.grpc + grpc-bom + ${dep.grpc-bom.version} + pom + import + + + com.google.protobuf + protobuf-bom + ${dep.protobuf-bom.version} + pom + import + + + - - org.apache.maven.plugins - maven-jar-plugin - - - **/logging.properties - **/logback-test.xml - **/logback.out.xml - **/logback.xml - - - true - - true - true - - - org.apache.arrow - ${username} - https://arrow.apache.org/ - - - - - - - test-jar - - - true - - - - + + + + org.slf4j + jul-to-slf4j + ${dep.slf4j.version} + test + + + org.slf4j + jcl-over-slf4j + ${dep.slf4j.version} + test + - - org.apache.maven.plugins - maven-resources-plugin - - UTF-8 - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - 2048m - false - true - - - - maven-enforcer-plugin - - - validate_java_and_maven_version - verify - - enforce - - false - - - - [3.3.0,4) - - - - - - avoid_bad_dependencies - verify - - enforce - - - - - - commons-logging - javax.servlet:servlet-api - org.mortbay.jetty:servlet-api - org.mortbay.jetty:servlet-api-2.5 - log4j:log4j - - - - - - - - - pl.project13.maven - git-commit-id-plugin - 4.0.5 - - - for-jars - true - - revision - - - target/classes/arrow-git.properties - - - - for-source-tarball - - revision - - false - - ./arrow-git.properties - - - + + org.slf4j + log4j-over-slf4j + ${dep.slf4j.version} + test + - - dd.MM.yyyy '@' HH:mm:ss z - false - false - true - false - - false - false - 7 - -dirty - true - - - - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version} - - - - - - - - src/main/**/*.xml - src/test/**/*.xml - **/pom.xml - - - ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license - (<configuration|<project) - - - - - - src/**/Preconditions.java - src/main/codegen/**/*.* - src/main/java/org/apache/arrow/flatbuf/*.java - - - true - 2 - - - true - 2 - - - - - ${maven.multiModuleProjectDirectory}/spotless/asf-java.license - (package|import) - - - - - true - 2 - - - true - 2 - - - false - - - - - - spotless-check - - check - - validate - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - analyze - verify - - analyze-only - - - true - true - - - javax.annotation:javax.annotation-api:* - org.apache.hadoop:hadoop-client-api - org.checkerframework:checker-qual - - - - - - - org.cyclonedx - cyclonedx-maven-plugin - 2.7.10 - - - package - - makeBom - - - - - - org.apache.arrow.maven.plugins - module-info-compiler-maven-plugin - - - default-compile - - compile - - - - default-testCompile - - testCompile - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 3.0.0 - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - + + org.junit.jupiter + junit-jupiter-engine + ${dep.junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${dep.junit.jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${dep.junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${dep.junit.jupiter.version} + test + + + + junit + junit + 4.13.1 + test + + + org.mockito + mockito-junit-jupiter + 2.25.1 + test + + + ch.qos.logback + logback-classic + 1.3.14 + test + + + de.huxhorn.lilith + de.huxhorn.lilith.logback.appender.multiplex-classic + 0.9.44 + test + - - - + + + + + + + + + + + org.apache.maven.plugins maven-dependency-plugin - - org.apache.arrow - arrow-bom - ${project.version} - pom - import - - - org.checkerframework - checker-qual - ${checker.framework.version} - - - com.google.flatbuffers - flatbuffers-java - ${dep.fbs.version} - - - com.google.code.findbugs - jsr305 - 3.0.2 - - - org.slf4j - slf4j-api - ${dep.slf4j.version} - - - javax.annotation - javax.annotation-api - 1.3.2 - - - org.assertj - assertj-core - 3.24.2 - test - - - org.immutables - value - 2.10.0 - provided - - - org.hamcrest - hamcrest - 2.2 - - - com.fasterxml.jackson - jackson-bom - ${dep.jackson-bom.version} - pom - import - - - com.google.guava - guava-bom - ${dep.guava-bom.version} - pom - import - - - io.netty - netty-bom - ${dep.netty-bom.version} - pom - import - - - io.grpc - grpc-bom - ${dep.grpc-bom.version} - pom - import - - - com.google.protobuf - protobuf-bom - ${dep.protobuf-bom.version} - pom - import - - - - - - - org.slf4j - jul-to-slf4j - ${dep.slf4j.version} - test - - - - org.slf4j - jcl-over-slf4j - ${dep.slf4j.version} - test - + + + org.apache.rat + apache-rat-plugin + + false + + **/dependency-reduced-pom.xml + **/*.log + **/*.css + **/*.js + **/*.md + **/*.eps + **/*.json + **/*.seq + **/*.parquet + **/*.sql + **/arrow-git.properties + **/*.csv + **/*.csvh + **/*.csvh-test + **/*.tsv + **/*.txt + **/*.ssv + **/arrow-*.conf + **/.buildpath + **/*.proto + **/*.fmpp + **/target/** + **/*.tdd + **/*.project + **/TAGS + **/*.checkstyle + **/.classpath + **/.factorypath + **/.settings/** + .*/** + **/*.patch + **/*.pb.cc + **/*.pb.h + **/*.linux + **/client/build/** + **/*.tbl + **/*.iml + **/flight.properties + **/*.idea/** + + + + + rat-checks + + check + + validate + + + - - org.slf4j - log4j-over-slf4j - ${dep.slf4j.version} - test - + + org.apache.maven.plugins + maven-jar-plugin + + + **/logging.properties + **/logback-test.xml + **/logback.out.xml + **/logback.xml + + + true + + true + true + + + org.apache.arrow + ${username} + https://arrow.apache.org/ + + + + + + + test-jar + + + true + + + + - - org.junit.jupiter - junit-jupiter-engine - ${dep.junit.jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-api - ${dep.junit.jupiter.version} - test - - - org.junit.vintage - junit-vintage-engine - ${dep.junit.jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-params - ${dep.junit.jupiter.version} - test - - - - junit - junit - 4.13.1 - test - - - org.mockito - mockito-junit-jupiter - 2.25.1 - test - - - ch.qos.logback - logback-classic - 1.3.14 - test - - - de.huxhorn.lilith - de.huxhorn.lilith.logback.appender.multiplex-classic - 0.9.44 - test - + + org.apache.maven.plugins + maven-resources-plugin + + UTF-8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + 2048m + false + true + + + + maven-enforcer-plugin + + + validate_java_and_maven_version + + enforce + + verify + false + + + + [3.3.0,4) + + + + + + avoid_bad_dependencies + + enforce + + verify + + + + + commons-logging + javax.servlet:servlet-api + org.mortbay.jetty:servlet-api + org.mortbay.jetty:servlet-api-2.5 + log4j:log4j + + + + + + + + + pl.project13.maven + git-commit-id-plugin + 4.0.5 - + + dd.MM.yyyy '@' HH:mm:ss z + false + false + true + false + + false + false + 7 + -dirty + true + + + + + for-jars + + revision + + true + + target/classes/arrow-git.properties + + + + for-source-tarball + + revision + + false + + ./arrow-git.properties + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + analyze + + analyze-only + + verify + + true + true + + + javax.annotation:javax.annotation-api:* + org.apache.hadoop:hadoop-client-api + org.checkerframework:checker-qual + + + + + + + org.cyclonedx + cyclonedx-maven-plugin + 2.7.10 + + + + makeBom + + package + + + + + org.apache.arrow.maven.plugins + module-info-compiler-maven-plugin + + + default-compile + + compile + + + + default-testCompile + + testCompile + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + + + + kr.motd.maven + os-maven-plugin + 1.7.0 + + + @@ -804,25 +751,29 @@ org.apache.maven.plugins maven-javadoc-plugin 3.6.3 + + + **/module-info.java + + - - + + + + javadoc - + + aggregate - false + aggregate + false - - - **/module-info.java - - org.apache.maven.plugins @@ -837,21 +788,6 @@ - - maven - bom - format - memory - vector - tools - adapter/jdbc - flight - performance - algorithm - adapter/avro - compression - - java-nodoclint @@ -895,9 +831,9 @@ error-prone-jdk8 1.8 @@ -1020,11 +956,12 @@ 0.8.11 - false + report + false @@ -1066,35 +1003,31 @@ cdata-cmake - generate-resources exec + generate-resources cmake - - -S java + -S java -B java-jni -DARROW_JAVA_JNI_ENABLE_C=ON -DARROW_JAVA_JNI_ENABLE_DEFAULT=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX=${arrow.c.jni.dist.dir} - + -DCMAKE_INSTALL_PREFIX=${arrow.c.jni.dist.dir} ../ cdata-build - generate-resources exec + generate-resources cmake - - --build java-jni --target install --config Release - + --build java-jni --target install --config Release ../ @@ -1127,14 +1060,13 @@ jni-cpp-cmake - generate-resources exec + generate-resources cmake - - -S cpp + -S cpp -B cpp-jni -DARROW_BUILD_SHARED=OFF -DARROW_CSV=${ARROW_DATASET} @@ -1152,37 +1084,33 @@ -DARROW_USE_CCACHE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=java-dist - -DCMAKE_UNITY_BUILD=ON - + -DCMAKE_UNITY_BUILD=ON ../ ${cpp.dependencies.builded} jni-cpp-build - generate-resources exec + generate-resources cmake - - --build cpp-jni --target install --config Release - + --build cpp-jni --target install --config Release ../ ${cpp.dependencies.builded} jni-cmake - generate-resources exec + generate-resources cmake - - -S java + -S java -B java-jni -DARROW_JAVA_JNI_ENABLE_C=${ARROW_JAVA_JNI_ENABLE_C} -DARROW_JAVA_JNI_ENABLE_DATASET=${ARROW_JAVA_JNI_ENABLE_DATASET} @@ -1194,22 +1122,19 @@ -DCMAKE_INSTALL_PREFIX=${arrow.dataset.jni.dist.dir} -DCMAKE_PREFIX_PATH=${project.basedir}/../java-dist/lib/${os.detected.arch}/cmake -DProtobuf_USE_STATIC_LIBS=ON - -DProtobuf_ROOT=${project.basedir}/../cpp-jni/protobuf_ep-install - + -DProtobuf_ROOT=${project.basedir}/../cpp-jni/protobuf_ep-install ../ jni-build - generate-resources exec + generate-resources cmake - - --build java-jni --target install --config Release - + --build java-jni --target install --config Release ../ @@ -1242,14 +1167,13 @@ jni-cpp-cmake - generate-resources exec + generate-resources cmake - - -S cpp + -S cpp -B cpp-jni -DARROW_BUILD_SHARED=OFF -DARROW_CSV=${ARROW_DATASET} @@ -1271,37 +1195,33 @@ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=java-dist -DCMAKE_UNITY_BUILD=ON - -GNinja - + -GNinja ../ ${cpp.dependencies.builded} jni-cpp-build - generate-resources exec + generate-resources ninja - - install - + install ../cpp-jni ${cpp.dependencies.builded} jni-cmake - generate-resources exec + generate-resources cmake - - -S java + -S java -B java-jni -DARROW_JAVA_JNI_ENABLE_C=${ARROW_JAVA_JNI_ENABLE_C} -DARROW_JAVA_JNI_ENABLE_DATASET=${ARROW_JAVA_JNI_ENABLE_DATASET} @@ -1311,22 +1231,19 @@ -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${arrow.dataset.jni.dist.dir} - -DCMAKE_PREFIX_PATH=${project.basedir}/../java-dist/lib/${os.detected.arch}/cmake - + -DCMAKE_PREFIX_PATH=${project.basedir}/../java-dist/lib/${os.detected.arch}/cmake ../ jni-build - generate-resources exec + generate-resources cmake - - --build java-jni --target install --config Release - + --build java-jni --target install --config Release ../ @@ -1335,6 +1252,160 @@ + + + spotless-jdk11+ + + [11,] + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version.jdk11} + + + + + + + + src/main/**/*.xml + src/test/**/*.xml + **/pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + src/**/Preconditions.java + src/main/codegen/**/*.* + src/main/java/org/apache/arrow/flatbuf/*.java + + + true + 2 + + + true + 2 + + + + + ${maven.multiModuleProjectDirectory}/spotless/asf-java.license + (package|import) + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + + + + + + + spotless-jdk8 + + 1.8 + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version.jdk8} + + + + + + + + src/main/**/*.xml + src/test/**/*.xml + **/pom.xml + + + ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license + (<configuration|<project) + + + + + + src/**/Preconditions.java + src/main/codegen/**/*.* + src/main/java/org/apache/arrow/flatbuf/*.java + + + true + 2 + + + true + 2 + + + + + ${maven.multiModuleProjectDirectory}/spotless/asf-java.license + (package|import) + + + + + true + 2 + + + true + 2 + + + false + + + + + + spotless-check + + check + + validate + + + + + + diff --git a/java/tools/pom.xml b/java/tools/pom.xml index 7ebf64c21ef..b13bf560e07 100644 --- a/java/tools/pom.xml +++ b/java/tools/pom.xml @@ -10,98 +10,98 @@ OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - 4.0.0 - - org.apache.arrow - arrow-java-root - 16.0.0-SNAPSHOT - - arrow-tools - Arrow Tools - Java applications for working with Arrow ValueVectors. + 4.0.0 + + org.apache.arrow + arrow-java-root + 16.0.0-SNAPSHOT + + arrow-tools + Arrow Tools + Java applications for working with Arrow ValueVectors. - - - org.apache.arrow - arrow-memory-core - - - org.apache.arrow - arrow-vector - ${arrow.vector.classifier} - - - org.apache.arrow - arrow-compression - - - org.immutables - value - - - com.google.guava - guava - test - - - commons-cli - commons-cli - 1.6.0 - - - ch.qos.logback - logback-classic - 1.3.14 - runtime - - - com.fasterxml.jackson.core - jackson-core - - - com.fasterxml.jackson.core - jackson-databind - - - org.slf4j - slf4j-api - - - org.apache.arrow - arrow-memory-netty - runtime - - - org.apache.arrow - arrow-vector - ${project.version} - tests - test-jar - test - - + + + org.apache.arrow + arrow-memory-core + + + org.apache.arrow + arrow-vector + ${arrow.vector.classifier} + + + org.apache.arrow + arrow-compression + + + org.immutables + value + + + com.google.guava + guava + test + + + commons-cli + commons-cli + 1.6.0 + + + ch.qos.logback + logback-classic + 1.3.14 + runtime + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + org.slf4j + slf4j-api + + + org.apache.arrow + arrow-memory-netty + runtime + + + org.apache.arrow + arrow-vector + ${project.version} + tests + test-jar + test + + - - - - maven-assembly-plugin - 3.0.0 - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - - - + + + + maven-assembly-plugin + 3.0.0 + + + jar-with-dependencies + + + + + make-assembly + + single + + package + + + + + diff --git a/java/vector/pom.xml b/java/vector/pom.xml index ae4459d6621..596c3bcb682 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -83,15 +83,15 @@ - apache - apache - https://repo.maven.apache.org/maven2/ true false + apache + apache + https://repo.maven.apache.org/maven2/ @@ -99,12 +99,45 @@ + codegen ${basedir}/src/main/codegen - codegen + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.drill.tools + drill-fmpp-maven-plugin + [1.0,) + + generate + + + + + false + true + + + + + + + + + @@ -122,10 +155,10 @@ run-unsafe - test test + test org.apache.arrow:arrow-memory-netty @@ -138,12 +171,13 @@ maven-resources-plugin - + + copy-fmpp-resources - initialize copy-resources + initialize ${project.build.directory}/codegen @@ -156,17 +190,18 @@ - + + org.apache.drill.tools drill-fmpp-maven-plugin 1.5.0 generate-fmpp - generate-sources generate + generate-sources src/main/codegen/config.fmpp ${project.build.directory}/generated-sources @@ -183,14 +218,14 @@ Using a newer version up to at least 3.5.1 will cause issues in the arrow-tools tests looking up FlatBuffer dependencies. - --> + --> 3.2.4 - package shade + package @@ -213,44 +248,9 @@ - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.drill.tools - drill-fmpp-maven-plugin - [1.0,) - - generate - - - - - false - true - - - - - - - - - - - - - - - - - pom.xml - - - ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license - (<configuration|<project) - - - - - - true - 2 - - - true - 2 - - - false - - - - - - spotless-check - - check - - validate - - - - - - diff --git a/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java b/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java index 70f2ca24357..44ea851863d 100644 --- a/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java +++ b/java/c/src/main/java/org/apache/arrow/c/BufferImportTypeVisitor.java @@ -134,7 +134,7 @@ private ArrowBuf maybeImportBitmap(ArrowType type) { if (buffers[0] == NULL) { return null; } - return importFixedBits(type, 0, /*bitsPerSlot=*/ 1); + return importFixedBits(type, 0, /* bitsPerSlot= */ 1); } @Override @@ -198,7 +198,7 @@ public List visit(ArrowType.FloatingPoint type) { switch (type.getPrecision()) { case HALF: return Arrays.asList( - maybeImportBitmap(type), importFixedBytes(type, 1, /*bytesPerSlot=*/ 2)); + maybeImportBitmap(type), importFixedBytes(type, 1, /* bytesPerSlot= */ 2)); case SINGLE: return Arrays.asList( maybeImportBitmap(type), importFixedBytes(type, 1, Float4Vector.TYPE_WIDTH)); @@ -288,7 +288,7 @@ public List visit(ArrowType.FixedSizeBinary type) { @Override public List visit(ArrowType.Bool type) { - return Arrays.asList(maybeImportBitmap(type), importFixedBits(type, 1, /*bitsPerSlot=*/ 1)); + return Arrays.asList(maybeImportBitmap(type), importFixedBits(type, 1, /* bitsPerSlot= */ 1)); } @Override diff --git a/java/c/src/test/java/org/apache/arrow/c/StreamTest.java b/java/c/src/test/java/org/apache/arrow/c/StreamTest.java index c3064b76f8f..46aefa3af4c 100644 --- a/java/c/src/test/java/org/apache/arrow/c/StreamTest.java +++ b/java/c/src/test/java/org/apache/arrow/c/StreamTest.java @@ -144,7 +144,7 @@ public void roundtripDictionary() throws Exception { Collections.singletonList( new Field( "dict", - new FieldType(/*nullable=*/ true, indexType, encoding), + new FieldType(/* nullable= */ true, indexType, encoding), Collections.emptyList()))); final List batches = new ArrayList<>(); try (final CDataDictionaryProvider provider = new CDataDictionaryProvider(); @@ -277,7 +277,8 @@ void roundtrip(Schema schema, List batches) throws Exception { private static void assertVectorsEqual(FieldVector expected, FieldVector actual) { assertThat(actual.getField().getType()).isEqualTo(expected.getField().getType()); assertThat(actual.getValueCount()).isEqualTo(expected.getValueCount()); - final Range range = new Range(/*leftStart=*/ 0, /*rightStart=*/ 0, expected.getValueCount()); + final Range range = + new Range(/* leftStart= */ 0, /* rightStart= */ 0, expected.getValueCount()); assertThat(new RangeEqualsVisitor(expected, actual).rangeEquals(range)) .as("Vectors were not equal.\nExpected: %s\nGot: %s", expected, actual) .isTrue(); diff --git a/java/dev/checkstyle/checkstyle.license b/java/dev/checkstyle/checkstyle.license deleted file mode 100644 index 3e7c6c26f55..00000000000 --- a/java/dev/checkstyle/checkstyle.license +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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. - */ diff --git a/java/dev/checkstyle/checkstyle.xml b/java/dev/checkstyle/checkstyle.xml deleted file mode 100644 index c27f382ddda..00000000000 --- a/java/dev/checkstyle/checkstyle.xml +++ /dev/null @@ -1,280 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/dev/checkstyle/suppressions.xml b/java/dev/checkstyle/suppressions.xml deleted file mode 100644 index 585985bf32d..00000000000 --- a/java/dev/checkstyle/suppressions.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java index 0b0fbf05909..16c55f6804e 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java @@ -478,8 +478,7 @@ public void testProtobufSchemaCompatibility() throws Exception { // Should have no body buffers Assertions.assertFalse(message.getBufs().iterator().hasNext()); final Flight.FlightData protobufData = - arrowMessageToProtobuf(marshaller, message) - .toBuilder() + arrowMessageToProtobuf(marshaller, message).toBuilder() .setDataBody(ByteString.EMPTY) .build(); Assertions.assertEquals(0, protobufData.getDataBody().size()); diff --git a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java index b924a22388c..2f02a25e64d 100644 --- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java +++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java @@ -135,7 +135,8 @@ public Runnable acceptPut( CallContext context, FlightStream flightStream, StreamListener ackStream) { return () -> { try (VectorSchemaRoot root = flightStream.getRoot()) { - while (flightStream.next()) {; + while (flightStream.next()) { + ; } } }; diff --git a/java/maven/pom.xml b/java/maven/pom.xml index 2b68c1b2324..3e903b2c9f5 100644 --- a/java/maven/pom.xml +++ b/java/maven/pom.xml @@ -375,77 +375,5 @@ - - - spotless-jdk8 - - 1.8 - - - - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version.jdk8} - - - - - - - - src/main/**/*.xml - src/test/**/*.xml - **/pom.xml - - - ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license - (<configuration|<project) - - - - - - true - 2 - - - true - 2 - - - - - ${maven.multiModuleProjectDirectory}/spotless/asf-java.license - (package|import) - - - - - true - 2 - - - true - 2 - - - false - - - - - - spotless-check - - check - - validate - - - - - - diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationManager.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationManager.java index e6e70a6247e..3b18ccb6ade 100644 --- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationManager.java +++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationManager.java @@ -75,8 +75,7 @@ protected AllocationManager(BufferAllocator accountingAllocator) { this.owningLedger = associate(accountingAllocator, false); } - @Nullable - BufferLedger getOwningLedger() { + @Nullable BufferLedger getOwningLedger() { return owningLedger; } diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java index 4ab3cf6737a..4c67b4bfc58 100644 --- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java +++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java @@ -158,8 +158,7 @@ BufferAllocator newChildAllocator( * * @return parent allocator */ - @Nullable - BufferAllocator getParentAllocator(); + @Nullable BufferAllocator getParentAllocator(); /** * Returns the set of child allocators. diff --git a/java/pom.xml b/java/pom.xml index 22a8acf9ddc..8367e322350 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -1329,83 +1329,6 @@ - - - spotless-jdk8 - - 1.8 - - - - - com.diffplug.spotless - spotless-maven-plugin - ${spotless.version.jdk8} - - - - - - - - src/main/**/*.xml - src/test/**/*.xml - **/pom.xml - - - ${maven.multiModuleProjectDirectory}/spotless/asf-xml.license - (<configuration|<project) - - - - - - src/**/Preconditions.java - src/main/codegen/**/*.* - src/main/java/org/apache/arrow/flatbuf/*.java - - - true - 2 - - - true - 2 - - - - - ${maven.multiModuleProjectDirectory}/spotless/asf-java.license - (package|import) - - - - - true - 2 - - - true - 2 - - - false - - - - - - spotless-check - - check - - validate - - - - - - From b6d012523c3d1627851bde20944401114259d9c6 Mon Sep 17 00:00:00 2001 From: david dali susanibar arce Date: Mon, 29 Jan 2024 21:43:37 -0500 Subject: [PATCH 7/8] fix: adding SPotless maven documentation --- docs/source/developers/java/development.rst | 64 ++++++++++++++++++--- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/docs/source/developers/java/development.rst b/docs/source/developers/java/development.rst index 261cd5702ae..e4980ba4845 100644 --- a/docs/source/developers/java/development.rst +++ b/docs/source/developers/java/development.rst @@ -110,15 +110,65 @@ integration tests, you would do: Code Style ========== -Code style is enforced with Checkstyle. The configuration is located at `checkstyle`_. -You can also just check the style without building the project. -This checks the code style of all source code under the current directory or from within an individual module. +The current Java code styles are configured as follows: +- Indent: Tabs & spaces (2 spaces per tab) +- Google Java Format: Reformats Java source code to comply with `Google Java Style`_. +- Configure license headers for Java & XML files + +Java code style is checked by `Spotless`_ during the build, and the continuous integration build will verify +that changes adhere to the style guide. + +.. code-block:: xml + + + + ... + + + + ... + + + + + ... + + + ... + + + +Automatically fixing code style issues +-------------------------------------- + +- You can also just check the style without building the project with `mvn spotless:check`. +- The Java code style can be corrected from the command line by using the following commands: `mvn spotless:apply`. + +.. code-block:: bash + + user@machine repo % mvn spotless:check + [ERROR] > The following files had format violations: + [ERROR] src\main\java\com\diffplug\gradle\spotless\FormatExtension.java + [ERROR] -\t\t····if·(targets.length·==·0)·{ + [ERROR] +\t\tif·(targets.length·==·0)·{ + [ERROR] Run 'mvn spotless:apply' to fix these violations. + user@machine repo % mvn spotless:apply + [INFO] BUILD SUCCESS + user@machine repo % mvn spotless:check + [INFO] BUILD SUCCESS + +Code Formatter for Intellij IDEA and Eclipse +-------------------------------------------- + +Follow the instructions for: +- `Eclipse`_ +- `IntelliJ`_ -.. code-block:: - - $ mvn checkstyle:check .. _benchmark: https://github.com/ursacomputing/benchmarks .. _archery: https://github.com/apache/arrow/blob/main/dev/conbench_envs/README.md#L188 .. _conbench: https://github.com/conbench/conbench -.. _checkstyle: https://github.com/apache/arrow/blob/main/java/dev/checkstyle/checkstyle.xml +.. _Spotless: https://github.com/diffplug/spotless +.. _Google Java Style: https://google.github.io/styleguide/javaguide.html +.. _Eclipse: https://github.com/google/google-java-format?tab=readme-ov-file#eclipse +.. _IntelliJ: https://github.com/google/google-java-format?tab=readme-ov-file#intellij-android-studio-and-other-jetbrains-ides \ No newline at end of file From a0194a2cd145beb8f845604b36fe982500ec888e Mon Sep 17 00:00:00 2001 From: david dali susanibar arce Date: Mon, 29 Jan 2024 21:54:22 -0500 Subject: [PATCH 8/8] fix: clean code --- docs/source/developers/java/development.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/developers/java/development.rst b/docs/source/developers/java/development.rst index e4980ba4845..c993d024003 100644 --- a/docs/source/developers/java/development.rst +++ b/docs/source/developers/java/development.rst @@ -111,6 +111,7 @@ Code Style ========== The current Java code styles are configured as follows: + - Indent: Tabs & spaces (2 spaces per tab) - Google Java Format: Reformats Java source code to comply with `Google Java Style`_. - Configure license headers for Java & XML files @@ -161,6 +162,7 @@ Code Formatter for Intellij IDEA and Eclipse -------------------------------------------- Follow the instructions for: + - `Eclipse`_ - `IntelliJ`_