This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new bdbbafd Sketch out ADBC Java APIs (#12)
bdbbafd is described below
commit bdbbafd46dbeaabbd71724c985d9fbd7aa3d9990
Author: David Li <[email protected]>
AuthorDate: Mon Jun 13 10:32:31 2022 -0400
Sketch out ADBC Java APIs (#12)
---
.github/workflows/java.yml | 56 ++++++
.gitignore | 1 +
.pre-commit-config.yaml | 7 +
java/core/pom.xml | 48 +++++
.../org/apache/arrow/adbc/core/AdbcConnection.java | 23 +++
.../org/apache/arrow/adbc/core/AdbcDatabase.java | 24 +++
.../org/apache/arrow/adbc/core/AdbcDriver.java | 24 +++
.../org/apache/arrow/adbc/core/AdbcException.java | 33 ++++
.../org/apache/arrow/adbc/core/AdbcStatement.java | 95 ++++++++++
.../arrow/adbc/core/PartitionDescriptor.java | 64 +++++++
java/driver-manager/pom.xml | 43 +++++
.../adbc/drivermanager/AdbcDriverManager.java | 72 +++++++
java/driver/derby/pom.xml | 75 ++++++++
.../arrow/adbc/driver/derby/DerbyConnection.java | 43 +++++
.../arrow/adbc/driver/derby/DerbyDatabase.java | 68 +++++++
.../arrow/adbc/driver/derby/DerbyDriver.java | 41 ++++
.../arrow/adbc/driver/derby/DerbyStatement.java | 206 +++++++++++++++++++++
.../arrow/adbc/driver/derby/JdbcArrowReader.java | 91 +++++++++
.../arrow/adbc/driver/derby/DerbyDatabaseTest.java | 101 ++++++++++
java/pom.xml | 162 ++++++++++++++++
20 files changed, 1277 insertions(+)
diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml
new file mode 100644
index 0000000..c823639
--- /dev/null
+++ b/.github/workflows/java.yml
@@ -0,0 +1,56 @@
+# 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.
+
+name: Java
+
+on:
+ pull_request:
+ branches:
+ - main
+ paths:
+ - "java/**"
+ - ".github/workflows/java.yml"
+ push:
+ paths:
+ - "java/**"
+ - ".github/workflows/java.yml"
+
+concurrency:
+ group: ${{ github.repository }}-${{ github.ref }}-${{ github.workflow }}
+ cancel-in-progress: true
+
+jobs:
+ java:
+ name: "Java ${{ matrix.java }}/Linux"
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ java: ['8', '11']
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+ - uses: actions/setup-java@v3
+ with:
+ cache: "maven"
+ distribution: "temurin"
+ java-version: ${{ matrix.java }}
+ - name: Build/Test
+ run: |
+ cd java
+ mvn install
diff --git a/.gitignore b/.gitignore
index 1406c30..7925456 100644
--- a/.gitignore
+++ b/.gitignore
@@ -87,3 +87,4 @@ cpp/Brewfile.lock.json
java-dist/
java-native-c/
java-native-cpp/
+target/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 5703e30..ae1de97 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -24,6 +24,7 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
+ - id: check-xml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
@@ -38,3 +39,9 @@ repos:
hooks:
- id: cmake-format
args: [--in-place]
+ - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
+ rev: v2.3.0
+ hooks:
+ - id: pretty-format-java
+ args: [--autofix]
+ types_or: [java]
diff --git a/java/core/pom.xml b/java/core/pom.xml
new file mode 100644
index 0000000..6e88f15
--- /dev/null
+++ b/java/core/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>arrow-adbc-java-root</artifactId>
+ <groupId>org.apache.arrow.adbc</groupId>
+ <version>9.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>adbc-core</artifactId>
+ <packaging>jar</packaging>
+ <name>Arrow ADBC Core</name>
+ <description>The core API for ADBC.</description>
+
+ <dependencies>
+ <!-- Arrow -->
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-memory-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-vector</artifactId>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git
a/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcConnection.java
b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcConnection.java
new file mode 100644
index 0000000..22bf6fa
--- /dev/null
+++ b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcConnection.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+package org.apache.arrow.adbc.core;
+
+/** A connection to a {@link AdbcDatabase}. */
+public interface AdbcConnection extends AutoCloseable {
+ /** Create a new statement that can be executed. */
+ AdbcStatement createStatement() throws AdbcException;
+}
diff --git
a/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcDatabase.java
b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcDatabase.java
new file mode 100644
index 0000000..ce34aeb
--- /dev/null
+++ b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcDatabase.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.adbc.core;
+
+/** An instance of a database (e.g. a handle to an in-memory database). */
+public interface AdbcDatabase extends AutoCloseable {
+ /** Create a new connection to the database. */
+ AdbcConnection connect() throws AdbcException;
+}
diff --git a/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcDriver.java
b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcDriver.java
new file mode 100644
index 0000000..619353c
--- /dev/null
+++ b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcDriver.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.adbc.core;
+
+import java.util.Map;
+
+public interface AdbcDriver {
+ AdbcDatabase connect(Map<String, String> parameters) throws AdbcException;
+}
diff --git
a/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcException.java
b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcException.java
new file mode 100644
index 0000000..f0845c1
--- /dev/null
+++ b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+package org.apache.arrow.adbc.core;
+
+public class AdbcException extends Exception {
+ public AdbcException() {}
+
+ public AdbcException(String message) {
+ super(message);
+ }
+
+ public AdbcException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public AdbcException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git
a/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcStatement.java
b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcStatement.java
new file mode 100644
index 0000000..dbba624
--- /dev/null
+++ b/java/core/src/main/java/org/apache/arrow/adbc/core/AdbcStatement.java
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.adbc.core;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.List;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.ipc.ArrowReader;
+
+public interface AdbcStatement extends AutoCloseable {
+ /**
+ * The name of the target table for a bulk insert.
+ *
+ * @see #setOption(String, String)
+ */
+ String INGEST_OPTION_TARGET_TABLE = "adbc.ingest.target_table";
+
+ /** Set a generic query option. */
+ default void setOption(String key, String value) {
+ throw new UnsupportedOperationException("Unsupported option " + key);
+ }
+
+ /**
+ * Set a SQL query to be executed on this statement.
+ *
+ * @param query The SQL query.
+ */
+ default void setSqlQuery(String query) {
+ throw new UnsupportedOperationException("Statement does not support SQL
queries");
+ }
+
+ /**
+ * Set a Substrait plan to be executed on this statement.
+ *
+ * @param plan The serialized Substrait plan.
+ */
+ default void setSubstraitPlan(ByteBuffer plan) {
+ throw new UnsupportedOperationException("Statement does not support
Substrait plans");
+ }
+
+ /** Bind this statement to a VectorSchemaRoot to provide parameter
values/bulk data ingestion. */
+ default void bind(VectorSchemaRoot root) {
+ throw new UnsupportedOperationException("Statement does not support bind");
+ }
+
+ /** Execute the query. */
+ void execute() throws AdbcException;
+
+ /**
+ * Get the result of executing a query.
+ *
+ * <p>Must be called after {@link #execute()}.
+ *
+ * @throws IllegalStateException if the statement has not been executed.
+ */
+ ArrowReader getArrowReader() throws AdbcException;
+
+ /**
+ * Get a list of partitions of the result set.
+ *
+ * <p>These can be serialized and deserialized for parallel and/or
distributed fetching.
+ *
+ * <p>Must be called after {@link #execute()}.
+ *
+ * @throws IllegalStateException if the statement has not been executed.
+ * @return The list of descriptors, or an empty list if unsupported.
+ */
+ default List<PartitionDescriptor> getPartitionDescriptors() {
+ // TODO: throw UnsupportedOperationException instead?
+ return Collections.emptyList();
+ }
+
+ /**
+ * Turn this statement into a prepared statement.
+ *
+ * <p>Call {@link #execute()} to execute the statement.
+ */
+ void prepare() throws AdbcException;
+}
diff --git
a/java/core/src/main/java/org/apache/arrow/adbc/core/PartitionDescriptor.java
b/java/core/src/main/java/org/apache/arrow/adbc/core/PartitionDescriptor.java
new file mode 100644
index 0000000..b625bf6
--- /dev/null
+++
b/java/core/src/main/java/org/apache/arrow/adbc/core/PartitionDescriptor.java
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.arrow.adbc.core;
+
+import java.nio.ByteBuffer;
+import java.util.Objects;
+
+/** An opaque descriptor for a part of a potentially distributed or
partitioned result set. */
+public final class PartitionDescriptor {
+ private final String friendlyName;
+ private final ByteBuffer descriptor;
+
+ public PartitionDescriptor(final String friendlyName, final ByteBuffer
descriptor) {
+ this.friendlyName = friendlyName;
+ this.descriptor = Objects.requireNonNull(descriptor);
+ }
+
+ public ByteBuffer getDescriptor() {
+ return descriptor;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ PartitionDescriptor that = (PartitionDescriptor) o;
+ return Objects.equals(friendlyName, that.friendlyName)
+ && getDescriptor().equals(that.getDescriptor());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(friendlyName, getDescriptor());
+ }
+
+ @Override
+ public String toString() {
+ return "PartitionDescriptor{"
+ + "friendlyName='"
+ + friendlyName
+ + '\''
+ + ", descriptor="
+ + descriptor
+ + '}';
+ }
+}
diff --git a/java/driver-manager/pom.xml b/java/driver-manager/pom.xml
new file mode 100644
index 0000000..97d1575
--- /dev/null
+++ b/java/driver-manager/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>arrow-adbc-java-root</artifactId>
+ <groupId>org.apache.arrow.adbc</groupId>
+ <version>9.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>adbc-driver-manager</artifactId>
+ <packaging>jar</packaging>
+ <name>Arrow ADBC Driver Manager</name>
+ <description>A driver manager for ADBC.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.arrow.adbc</groupId>
+ <artifactId>adbc-core</artifactId>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git
a/java/driver-manager/src/main/java/org/apache/arrow/adbc/drivermanager/AdbcDriverManager.java
b/java/driver-manager/src/main/java/org/apache/arrow/adbc/drivermanager/AdbcDriverManager.java
new file mode 100644
index 0000000..f253e7c
--- /dev/null
+++
b/java/driver-manager/src/main/java/org/apache/arrow/adbc/drivermanager/AdbcDriverManager.java
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.adbc.drivermanager;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.arrow.adbc.core.AdbcDatabase;
+import org.apache.arrow.adbc.core.AdbcDriver;
+import org.apache.arrow.adbc.core.AdbcException;
+
+public final class AdbcDriverManager {
+ private static final AdbcDriverManager INSTANCE = new AdbcDriverManager();
+
+ private final ConcurrentMap<String, AdbcDriver> drivers;
+
+ public AdbcDriverManager() {
+ drivers = new ConcurrentHashMap<>();
+ }
+
+ /**
+ * Connect to a database.
+ *
+ * @param driverName The driver to use.
+ * @param parameters Parameters for the driver.
+ * @return The AdbcDatabase instance.
+ * @throws AdbcException if the driver was not found or if connection fails.
+ */
+ public AdbcDatabase connect(String driverName, Map<String, String>
parameters)
+ throws AdbcException {
+ final AdbcDriver driver = lookupDriver(driverName);
+ if (driver == null) {
+ throw new AdbcException("Driver not found for '" + driverName + "'");
+ }
+ return driver.connect(parameters);
+ }
+
+ /**
+ * Lookup a registered driver.
+ *
+ * @param driverName The driver to lookup.
+ * @return The driver instance, or null if not found.
+ */
+ public AdbcDriver lookupDriver(String driverName) {
+ return drivers.get(driverName);
+ }
+
+ public void registerDriver(String driverName, AdbcDriver driver) {
+ if (drivers.putIfAbsent(driverName, driver) != null) {
+ throw new IllegalStateException("Driver already registered for '" +
driverName + "'");
+ }
+ }
+
+ public static AdbcDriverManager getInstance() {
+ return INSTANCE;
+ }
+}
diff --git a/java/driver/derby/pom.xml b/java/driver/derby/pom.xml
new file mode 100644
index 0000000..f0f357a
--- /dev/null
+++ b/java/driver/derby/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>arrow-adbc-java-root</artifactId>
+ <groupId>org.apache.arrow.adbc</groupId>
+ <version>9.0.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>adbc-driver-derby</artifactId>
+ <packaging>jar</packaging>
+ <name>Arrow ADBC Core</name>
+ <description>An example ADBC driver based on Apache Derby.</description>
+
+ <dependencies>
+ <!-- Arrow -->
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-memory-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-vector</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.arrow.adbc</groupId>
+ <artifactId>adbc-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow.adbc</groupId>
+ <artifactId>adbc-driver-manager</artifactId>
+ </dependency>
+
+ <!-- Derby -->
+ <!-- Cannot upgrade beyond this version for Java 8 support -->
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.14.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derbytools</artifactId>
+ <version>10.14.2.0</version>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git
a/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyConnection.java
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyConnection.java
new file mode 100644
index 0000000..4dd3a5a
--- /dev/null
+++
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyConnection.java
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+package org.apache.arrow.adbc.driver.derby;
+
+import java.sql.Connection;
+import org.apache.arrow.adbc.core.AdbcConnection;
+import org.apache.arrow.adbc.core.AdbcException;
+import org.apache.arrow.adbc.core.AdbcStatement;
+import org.apache.arrow.memory.BufferAllocator;
+
+public class DerbyConnection implements AdbcConnection {
+ private final BufferAllocator allocator;
+ private final Connection connection;
+
+ DerbyConnection(BufferAllocator allocator, Connection connection) {
+ this.allocator = allocator;
+ this.connection = connection;
+ }
+
+ @Override
+ public AdbcStatement createStatement() throws AdbcException {
+ return new DerbyStatement(allocator, connection);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connection.close();
+ }
+}
diff --git
a/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyDatabase.java
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyDatabase.java
new file mode 100644
index 0000000..b8fd4f5
--- /dev/null
+++
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyDatabase.java
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.adbc.driver.derby;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import org.apache.arrow.adbc.core.AdbcConnection;
+import org.apache.arrow.adbc.core.AdbcDatabase;
+import org.apache.arrow.adbc.core.AdbcException;
+import org.apache.arrow.memory.BufferAllocator;
+
+/** An instance of a database (e.g. a handle to an in-memory database). */
+public final class DerbyDatabase implements AdbcDatabase {
+ private final BufferAllocator allocator;
+ private final String target;
+ private final Connection connection;
+
+ DerbyDatabase(BufferAllocator allocator, final String target) throws
AdbcException {
+ try {
+ new org.apache.derby.jdbc.EmbeddedDriver();
+
+ this.allocator = allocator;
+ this.target = target;
+ this.connection = DriverManager.getConnection(target + ";create=true");
+ } catch (SQLException e) {
+ throw new AdbcException(e);
+ }
+ }
+
+ @Override
+ public AdbcConnection connect() throws AdbcException {
+ final Connection connection;
+ try {
+ connection = DriverManager.getConnection(target);
+ } catch (SQLException e) {
+ throw new AdbcException(e);
+ }
+ // TODO: better naming of child allocator
+ return new DerbyConnection(
+ allocator.newChildAllocator("derby-connection", 0,
allocator.getLimit()), connection);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connection.close();
+ }
+
+ @Override
+ public String toString() {
+ return "DerbyDatabase{" + "target='" + target + '\'' + '}';
+ }
+}
diff --git
a/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyDriver.java
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyDriver.java
new file mode 100644
index 0000000..446a109
--- /dev/null
+++
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyDriver.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.arrow.adbc.driver.derby;
+
+import java.util.Map;
+import org.apache.arrow.adbc.core.AdbcDatabase;
+import org.apache.arrow.adbc.core.AdbcDriver;
+import org.apache.arrow.adbc.core.AdbcException;
+import org.apache.arrow.adbc.drivermanager.AdbcDriverManager;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+
+public enum DerbyDriver implements AdbcDriver {
+ INSTANCE;
+
+ private final BufferAllocator allocator;
+
+ DerbyDriver() {
+ allocator = new RootAllocator();
+
AdbcDriverManager.getInstance().registerDriver("org.apache.arrow.adbc.driver.derby",
this);
+ }
+
+ @Override
+ public AdbcDatabase connect(Map<String, String> parameters) throws
AdbcException {
+ return new DerbyDatabase(allocator, "jdbc:derby:" +
parameters.get("path"));
+ }
+}
diff --git
a/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyStatement.java
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyStatement.java
new file mode 100644
index 0000000..6abd69e
--- /dev/null
+++
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/DerbyStatement.java
@@ -0,0 +1,206 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.adbc.driver.derby;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.Objects;
+import org.apache.arrow.adbc.core.AdbcException;
+import org.apache.arrow.adbc.core.AdbcStatement;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.ipc.ArrowReader;
+import org.apache.arrow.vector.types.pojo.Field;
+
+public class DerbyStatement implements AdbcStatement {
+ private final BufferAllocator allocator;
+ private final Connection connection;
+
+ // State for SQL queries
+ private String sqlQuery;
+ private ResultSet resultSet;
+ // State for bulk ingest
+ private String bulkTargetTable;
+ private VectorSchemaRoot bindRoot;
+
+ DerbyStatement(BufferAllocator allocator, Connection connection) {
+ this.allocator = allocator;
+ this.connection = connection;
+ this.sqlQuery = null;
+ }
+
+ @Override
+ public void setOption(String key, String value) {
+ if (AdbcStatement.INGEST_OPTION_TARGET_TABLE.equals(key)) {
+ bulkTargetTable = Objects.requireNonNull(value);
+ sqlQuery = null;
+ return;
+ }
+ AdbcStatement.super.setOption(key, value);
+ }
+
+ @Override
+ public void setSqlQuery(String query) {
+ bulkTargetTable = null;
+ sqlQuery = query;
+ }
+
+ @Override
+ public void bind(VectorSchemaRoot root) {
+ bindRoot = root;
+ }
+
+ @Override
+ public void execute() throws AdbcException {
+ if (bulkTargetTable != null) {
+ executeBulk();
+ } else if (sqlQuery != null) {
+ executeSqlQuery();
+ } else {
+ throw new IllegalStateException("Must setSqlQuery first");
+ }
+ }
+
+ private void executeBulk() throws AdbcException {
+ if (bindRoot == null) {
+ throw new IllegalStateException("Must bind() before bulk insert");
+ }
+
+ // TODO: also create the table
+ final StringBuilder create = new StringBuilder("CREATE TABLE ");
+ create.append(bulkTargetTable);
+ create.append(" (");
+ for (int col = 0; col < bindRoot.getFieldVectors().size(); col++) {
+ if (col > 0) {
+ create.append(", ");
+ }
+ final Field field = bindRoot.getVector(col).getField();
+ create.append(field.getName());
+ switch (field.getType().getTypeID()) {
+ case Null:
+ case Struct:
+ case List:
+ case LargeList:
+ case FixedSizeList:
+ case Union:
+ case Map:
+ throw new UnsupportedOperationException("Type " + field);
+ case Int:
+ // TODO:
+ create.append(" INT");
+ break;
+ case FloatingPoint:
+ case Utf8:
+ case LargeUtf8:
+ case Binary:
+ case LargeBinary:
+ case FixedSizeBinary:
+ case Bool:
+ case Decimal:
+ case Date:
+ case Time:
+ case Timestamp:
+ case Interval:
+ case Duration:
+ case NONE:
+ throw new UnsupportedOperationException("Type " + field);
+ }
+ }
+ create.append(")");
+
+ try (final Statement statement = connection.createStatement()) {
+ statement.execute(create.toString());
+ } catch (SQLException e) {
+ throw new AdbcException(e);
+ }
+
+ // XXX: potential injection
+ final StringBuilder insert = new StringBuilder("INSERT INTO ");
+ insert.append(bulkTargetTable);
+ insert.append(" VALUES (");
+ for (int col = 0; col < bindRoot.getFieldVectors().size(); col++) {
+ if (col > 0) {
+ insert.append(", ");
+ }
+ insert.append("?");
+ }
+ insert.append(")");
+
+ try (final PreparedStatement statement =
connection.prepareStatement(insert.toString())) {
+ statement.clearBatch();
+ for (int row = 0; row < bindRoot.getRowCount(); row++) {
+ for (int col = 0; col < bindRoot.getFieldVectors().size(); col++) {
+ final int parameterIndex = col + 1;
+ final FieldVector vector = bindRoot.getVector(col);
+ if (vector instanceof IntVector) {
+ if (vector.isNull(row)) {
+ statement.setNull(parameterIndex, Types.BIGINT);
+ } else {
+ statement.setLong(parameterIndex, ((IntVector) vector).get(row));
+ }
+ } else {
+ throw new UnsupportedOperationException("Unsupported Arrow type: "
+ vector.getField());
+ }
+ }
+ statement.addBatch();
+ }
+ statement.executeBatch();
+ } catch (SQLException e) {
+ throw new AdbcException(e);
+ }
+ }
+
+ private void executeSqlQuery() throws AdbcException {
+ try {
+ if (resultSet != null) {
+ resultSet.close();
+ }
+ final Statement statement =
+ connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
+ resultSet = statement.executeQuery(sqlQuery);
+ } catch (SQLException e) {
+ throw new AdbcException(e);
+ }
+ }
+
+ @Override
+ public ArrowReader getArrowReader() throws AdbcException {
+ if (resultSet == null) {
+ throw new IllegalStateException("Must call execute() before
getArrowIterator()");
+ }
+ final JdbcArrowReader reader = new JdbcArrowReader(allocator, resultSet);
+ resultSet = null;
+ return reader;
+ }
+
+ @Override
+ public void prepare() {}
+
+ @Override
+ public void close() throws Exception {
+ if (resultSet != null) {
+ resultSet.close();
+ }
+ }
+}
diff --git
a/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/JdbcArrowReader.java
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/JdbcArrowReader.java
new file mode 100644
index 0000000..bf6b76a
--- /dev/null
+++
b/java/driver/derby/src/main/java/org/apache/arrow/adbc/driver/derby/JdbcArrowReader.java
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+package org.apache.arrow.adbc.driver.derby;
+
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import org.apache.arrow.adapter.jdbc.ArrowVectorIterator;
+import org.apache.arrow.adapter.jdbc.JdbcToArrow;
+import org.apache.arrow.adapter.jdbc.JdbcToArrowConfig;
+import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder;
+import org.apache.arrow.adapter.jdbc.JdbcToArrowUtils;
+import org.apache.arrow.adbc.core.AdbcException;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.VectorUnloader;
+import org.apache.arrow.vector.ipc.ArrowReader;
+import org.apache.arrow.vector.ipc.message.ArrowRecordBatch;
+import org.apache.arrow.vector.types.pojo.Schema;
+
+public class JdbcArrowReader extends ArrowReader {
+ private final ArrowVectorIterator delegate;
+ private final Schema schema;
+ private long bytesRead;
+
+ JdbcArrowReader(BufferAllocator allocator, ResultSet resultSet) throws
AdbcException {
+ super(allocator);
+ try {
+ this.delegate = JdbcToArrow.sqlToArrowVectorIterator(resultSet,
allocator);
+ } catch (SQLException | IOException e) {
+ throw new AdbcException(e);
+ }
+ final JdbcToArrowConfig config =
+ new JdbcToArrowConfigBuilder()
+ .setAllocator(allocator)
+ .setCalendar(JdbcToArrowUtils.getUtcCalendar())
+ .build();
+ try {
+ this.schema =
JdbcToArrowUtils.jdbcToArrowSchema(resultSet.getMetaData(), config);
+ } catch (SQLException e) {
+ throw new AdbcException(e);
+ }
+ this.bytesRead = 0;
+
+ try {
+ this.ensureInitialized();
+ } catch (IOException e) {
+ throw new AdbcException(e);
+ }
+ }
+
+ @Override
+ public boolean loadNextBatch() {
+ if (!delegate.hasNext()) return false;
+ final VectorSchemaRoot root = delegate.next();
+ final VectorUnloader unloader = new VectorUnloader(root);
+ final ArrowRecordBatch recordBatch = unloader.getRecordBatch();
+ bytesRead += recordBatch.computeBodyLength();
+ loadRecordBatch(recordBatch);
+ return true;
+ }
+
+ @Override
+ public long bytesRead() {
+ return bytesRead;
+ }
+
+ @Override
+ protected void closeReadSource() {
+ delegate.close();
+ }
+
+ @Override
+ protected Schema readSchema() {
+ return schema;
+ }
+}
diff --git
a/java/driver/derby/src/test/java/org/apache/arrow/adbc/driver/derby/DerbyDatabaseTest.java
b/java/driver/derby/src/test/java/org/apache/arrow/adbc/driver/derby/DerbyDatabaseTest.java
new file mode 100644
index 0000000..3bf6459
--- /dev/null
+++
b/java/driver/derby/src/test/java/org/apache/arrow/adbc/driver/derby/DerbyDatabaseTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+package org.apache.arrow.adbc.driver.derby;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.arrow.adbc.core.AdbcConnection;
+import org.apache.arrow.adbc.core.AdbcDatabase;
+import org.apache.arrow.adbc.core.AdbcStatement;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.ipc.ArrowReader;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.arrow.vector.types.pojo.Schema;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+class DerbyDatabaseTest {
+ @Test
+ void simpleQuery(@TempDir Path tempDir) throws Exception {
+ final Map<String, String> parameters = new HashMap<>();
+ parameters.put("path", tempDir.toString() + "/db");
+ try (final AdbcDatabase database =
DerbyDriver.INSTANCE.connect(parameters);
+ final AdbcConnection connection = database.connect();
+ final AdbcStatement statement = connection.createStatement()) {
+ statement.setSqlQuery("SELECT * FROM SYS.SYSTABLES");
+ statement.execute();
+ try (final ArrowReader reader = statement.getArrowReader()) {
+ assertThat(reader.loadNextBatch()).isTrue();
+ }
+ }
+ }
+
+ @Test
+ void bulkInsert(@TempDir Path tempDir) throws Exception {
+ final Map<String, String> parameters = new HashMap<>();
+ parameters.put("path", tempDir.toString() + "/db");
+ final Schema schema =
+ new Schema(
+ Collections.singletonList(
+ Field.nullable("ints", new ArrowType.Int(32, /*signed=*/
true))));
+ try (final BufferAllocator allocator = new RootAllocator();
+ final AdbcDatabase database = DerbyDriver.INSTANCE.connect(parameters);
+ final AdbcConnection connection = database.connect()) {
+ try (final AdbcStatement statement = connection.createStatement();
+ final VectorSchemaRoot ingest = VectorSchemaRoot.create(schema,
allocator)) {
+ statement.setOption(AdbcStatement.INGEST_OPTION_TARGET_TABLE, "foo");
+ statement.bind(ingest);
+ final IntVector ints = (IntVector) ingest.getVector(0);
+ ints.allocateNew(4);
+ ints.setSafe(0, 0);
+ ints.setSafe(1, 1);
+ ints.setSafe(2, 2);
+ ints.setSafe(3, 3);
+ ingest.setRowCount(4);
+ statement.execute();
+ }
+
+ try (final AdbcStatement statement = connection.createStatement()) {
+ statement.setSqlQuery("SELECT * FROM foo");
+ statement.execute();
+
+ try (final ArrowReader reader = statement.getArrowReader()) {
+ assertThat(reader.loadNextBatch()).isTrue();
+ final FieldVector vector = reader.getVectorSchemaRoot().getVector(0);
+ assertThat(vector).isInstanceOf(IntVector.class);
+ assertThat(vector.getValueCount()).isEqualTo(4);
+ final IntVector ints = (IntVector) vector;
+ for (int i = 0; i < 4; i++) {
+ assertThat(ints.isNull(i)).isFalse();
+ assertThat(ints.get(i)).isEqualTo(i);
+ }
+ assertThat(reader.loadNextBatch()).isFalse();
+ }
+ }
+ }
+ }
+}
diff --git a/java/pom.xml b/java/pom.xml
new file mode 100644
index 0000000..5e11b85
--- /dev/null
+++ b/java/pom.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>18</version>
+ </parent>
+
+ <groupId>org.apache.arrow.adbc</groupId>
+ <artifactId>arrow-adbc-java-root</artifactId>
+ <version>9.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>Apache Arrow ADBC Java Root POM</name>
+ <description>Apache Arrow is open source, in-memory columnar data structures
and low-overhead messaging</description>
+ <url>https://arrow.apache.org/</url>
+
+ <properties>
+ <dep.arrow.version>8.0.0</dep.arrow.version>
+ </properties>
+
+ <scm>
+ <connection>scm:git:https://github.com/apache/arrow-adbc.git</connection>
+
<developerConnection>scm:git:https://github.com/apache/arrow-adbc.git</developerConnection>
+ <url>https://github.com/apache/arrow-adbc</url>
+ </scm>
+
+ <mailingLists>
+ <mailingList>
+ <name>Developer List</name>
+ <subscribe>[email protected]</subscribe>
+ <unsubscribe>[email protected]</unsubscribe>
+ <post>[email protected]</post>
+ <archive>https://mail-archives.apache.org/mod_mbox/arrow-dev/</archive>
+ </mailingList>
+ <mailingList>
+ <name>Commits List</name>
+ <subscribe>[email protected]</subscribe>
+ <unsubscribe>[email protected]</unsubscribe>
+ <post>[email protected]</post>
+
<archive>https://mail-archives.apache.org/mod_mbox/arrow-commits/</archive>
+ </mailingList>
+ <mailingList>
+ <name>Issues List</name>
+ <subscribe>[email protected]</subscribe>
+ <unsubscribe>[email protected]</unsubscribe>
+
<archive>https://mail-archives.apache.org/mod_mbox/arrow-issues/</archive>
+ </mailingList>
+ </mailingLists>
+
+ <issueManagement>
+ <system>Jira</system>
+ <url>https://issues.apache.org/jira/browse/arrow</url>
+ </issueManagement>
+
+ <modules>
+ <module>core</module>
+ <module>driver/derby</module>
+ <module>driver-manager</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Arrow -->
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-jdbc</artifactId>
+ <version>${dep.arrow.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-memory-core</artifactId>
+ <version>${dep.arrow.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow</groupId>
+ <artifactId>arrow-vector</artifactId>
+ <version>${dep.arrow.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.arrow.adbc</groupId>
+ <artifactId>adbc-core</artifactId>
+ <version>9.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.arrow.adbc</groupId>
+ <artifactId>adbc-driver-manager</artifactId>
+ <version>9.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.23.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>5.8.2</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.0.0-M7</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.10.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>rat-checks</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>