Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/data/languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"go": "Go",
"java": "Java",
"javascript": "JavaScript",
"kotlin": "Kotlin",
"cpp": "C++",
"r": "R",
"rust": "Rust"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ node_modules
package-lock.json
javascript/node-packages/
.pixi
.gradle
.kotlin
build
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Simple examples showing how to use ADBC to connect, run a query, and return the
- [Go](./go)
- [Java](./java)
- [JavaScript](./javascript)
- [Kotlin](./kotlin)
- [Python](./python)
- [R](./r)
- [Rust](./rust)
Expand Down
68 changes: 68 additions & 0 deletions kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!--
Copyright 2026 Columnar Technologies Inc.

Licensed 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.
-->

<!--
⚠️ DO NOT EDIT THIS FILE MANUALLY ⚠️
This file is auto-generated by .github/scripts/generate_readmes.py
To update, modify .github/data/databases.json or .github/data/languages.json
-->

# Kotlin ADBC Quickstarts

Simple Kotlin examples showing how to use ADBC to connect, run a query, and return the results.

## Source systems covered

- [Google BigQuery](./bigquery)
- [ClickHouse](./clickhouse)
- [Databricks](./databricks)
- [DuckDB-compatible systems](./duckdb)
- [DuckDB](./duckdb/duckdb)
- [MotherDuck](./duckdb/motherduck)
- [Exasol](./exasol)
- [Apache Arrow Flight SQL-compatible systems](./flightsql)
- [Apache Doris](./flightsql/doris)
- [Dremio](./flightsql/dremio)
- [GizmoSQL](./flightsql/gizmosql)
- [InfluxDB](./flightsql/influxdb)
- [StarRocks](./flightsql/starrocks)
- [Microsoft SQL Server](./mssql)
- [MySQL-compatible systems](./mysql)
- [MariaDB](./mysql/mariadb)
- [MySQL](./mysql/mysql)
- [TiDB](./mysql/tidb)
- [Vitess](./mysql/vitess)
- [Oracle Database](./oracle)
- [PostgreSQL-compatible systems](./postgresql)
- [Citus](./postgresql/citus)
- [CockroachDB](./postgresql/cockroachdb)
- [CrateDB](./postgresql/cratedb)
- [Neon](./postgresql/neon)
- [ParadeDB](./postgresql/paradedb)
- [PostgreSQL](./postgresql/postgresql)
- [TimescaleDB](./postgresql/timescaledb)
- [Yellowbrick](./postgresql/yellowbrick)
- [YugabyteDB](./postgresql/yugabytedb)
- [Amazon Redshift](./redshift)
- [SingleStore](./singlestore)
- [Snowflake](./snowflake)
- [SQLite](./sqlite)
- [Teradata](./teradata)
- [Trino](./trino)

## Instructions

Each subdirectory contains its own README with specific instructions.
59 changes: 59 additions & 0 deletions kotlin/bigquery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--
Copyright 2026 Columnar Technologies Inc.

Licensed 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.
-->

# Connecting Kotlin and BigQuery with ADBC

## Instructions

### Prerequisites

1. [Install Gradle](https://docs.gradle.org/current/userguide/installation.html)

1. [Install dbc](https://docs.columnar.tech/dbc/getting_started/installation/)

1. [Install Google Cloud CLI](https://cloud.google.com/sdk/docs/install)

1. [Create a Google account](https://accounts.google.com) or be able to log in to an existing one

### Set up BigQuery

1. Log into the [Google Cloud Console](https://console.cloud.google.com/) and create project or locate an existing project and record the project ID for use in a later step

1. Run this command in your terminal to log in with the Google Cloud CLI:

```sh
gcloud auth application-default login
```

### Connect to BigQuery

1. Install the BigQuery ADBC driver:

```sh
dbc install bigquery
```

1. Customize the `main` function in `Main.kt`
- Change the connection arguments in `params`
- Change the value of the `adbc.bigquery.sql.project_id` argument to match the project ID you recorded in the earlier step
- Change the value of `adbc.bigquery.sql.dataset_id`, or keep it as is to use the public Shakespeare dataset
- If you changed the dataset, also change the SQL SELECT statement in `stmt.setSqlQuery`

1. Run the Kotlin program:

```sh
gradle run
```
31 changes: 31 additions & 0 deletions kotlin/bigquery/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
kotlin("jvm") version "2.3.21"
application
}

repositories {
mavenCentral()
}

val arrowVersion = "18.3.0"
val adbcVersion = "0.21.0"

dependencies {
implementation("org.apache.arrow:arrow-memory-core:$arrowVersion")
implementation("org.apache.arrow:arrow-memory-netty:$arrowVersion")
implementation("org.apache.arrow:arrow-vector:$arrowVersion")
implementation("org.apache.arrow.adbc:adbc-core:$adbcVersion")
implementation("org.apache.arrow.adbc:adbc-driver-manager:$adbcVersion")
implementation("org.apache.arrow.adbc:adbc-driver-jni:$adbcVersion")
implementation("org.slf4j:slf4j-nop:2.0.16")
}

application {
mainClass.set("MainKt")
applicationDefaultJvmArgs =
listOf(
"--add-opens=java.base/java.nio=ALL-UNNAMED",
"--enable-native-access=ALL-UNNAMED",
"--sun-misc-unsafe-memory-access=allow",
)
}
1 change: 1 addition & 0 deletions kotlin/bigquery/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.configuration-cache=true
1 change: 1 addition & 0 deletions kotlin/bigquery/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "adbc-quickstart-bigquery"
49 changes: 49 additions & 0 deletions kotlin/bigquery/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2026 Columnar Technologies Inc.
*
* Licensed 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.
*/

import org.apache.arrow.adbc.driver.jni.JniDriver
import org.apache.arrow.adbc.drivermanager.AdbcDriverManager
import org.apache.arrow.memory.RootAllocator

private const val DRIVER_FACTORY = "org.apache.arrow.adbc.driver.jni.JniDriverFactory"

fun main() {
val params = mutableMapOf<String, Any>()
JniDriver.PARAM_DRIVER.set(params, "bigquery")
params["adbc.bigquery.sql.project_id"] = "my-gcp-project"
params["adbc.bigquery.sql.dataset_id"] = "bigquery-public-data"

RootAllocator().use { allocator ->
AdbcDriverManager.getInstance().connect(DRIVER_FACTORY, allocator, params).use { db ->
db.connect().use { conn ->
conn.createStatement().use { stmt ->
stmt.setSqlQuery(
"""
SELECT word, corpus FROM bigquery-public-data.samples.shakespeare
WHERE word_count = 1 ORDER BY RAND() LIMIT 5;
""".trimIndent(),
)
stmt.executeQuery().use { result ->
val reader = result.reader
while (reader.loadNextBatch()) {
println(reader.vectorSchemaRoot.contentToTSVString())
}
}
}
}
}
}
}
65 changes: 65 additions & 0 deletions kotlin/clickhouse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!--
Copyright 2026 Columnar Technologies Inc.

Licensed 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.
-->

# Connecting Kotlin and ClickHouse with ADBC

## Instructions

> [!TIP]
> If you already have a ClickHouse instance running, skip the steps to set up and clean up ClickHouse.

### Prerequisites

1. [Install Gradle](https://docs.gradle.org/current/userguide/installation.html)

1. [Install dbc](https://docs.columnar.tech/dbc/getting_started/installation/)

### Set up ClickHouse

1. [Install Docker](https://docs.docker.com/get-started/get-docker/)

1. Start a ClickHouse instance:

```sh
docker run -d --rm --name some-clickhouse-server -p 8123:8123 -e CLICKHOUSE_USER=user -e CLICKHOUSE_PASSWORD=pass clickhouse/clickhouse-server
```

### Connect to ClickHouse

1. Install the ClickHouse ADBC driver:

```sh
dbc install clickhouse --pre
```

1. Customize the `main` function in `Main.kt`
- Change the connection arguments in `params`
- Format `uri` according to the [ClickHouse HTTP interface](https://clickhouse.com/docs/interfaces/http), or keep it as is
- If you changed which database you're connecting to, also change the SQL SELECT statement in `stmt.setSqlQuery`

1. Run the Kotlin program:

```sh
gradle run
```

### Clean up

Stop the Docker container running ClickHouse:

```sh
docker stop some-clickhouse-server
```
31 changes: 31 additions & 0 deletions kotlin/clickhouse/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
kotlin("jvm") version "2.3.21"
application
}

repositories {
mavenCentral()
}

val arrowVersion = "18.3.0"
val adbcVersion = "0.21.0"

dependencies {
implementation("org.apache.arrow:arrow-memory-core:$arrowVersion")
implementation("org.apache.arrow:arrow-memory-netty:$arrowVersion")
implementation("org.apache.arrow:arrow-vector:$arrowVersion")
implementation("org.apache.arrow.adbc:adbc-core:$adbcVersion")
implementation("org.apache.arrow.adbc:adbc-driver-manager:$adbcVersion")
implementation("org.apache.arrow.adbc:adbc-driver-jni:$adbcVersion")
implementation("org.slf4j:slf4j-nop:2.0.16")
}

application {
mainClass.set("MainKt")
applicationDefaultJvmArgs =
listOf(
"--add-opens=java.base/java.nio=ALL-UNNAMED",
"--enable-native-access=ALL-UNNAMED",
"--sun-misc-unsafe-memory-access=allow",
)
}
1 change: 1 addition & 0 deletions kotlin/clickhouse/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.configuration-cache=true
1 change: 1 addition & 0 deletions kotlin/clickhouse/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "adbc-quickstart-clickhouse"
45 changes: 45 additions & 0 deletions kotlin/clickhouse/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2026 Columnar Technologies Inc.
*
* Licensed 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.
*/

import org.apache.arrow.adbc.driver.jni.JniDriver
import org.apache.arrow.adbc.drivermanager.AdbcDriverManager
import org.apache.arrow.memory.RootAllocator

private const val DRIVER_FACTORY = "org.apache.arrow.adbc.driver.jni.JniDriverFactory"

fun main() {
val params = mutableMapOf<String, Any>()
JniDriver.PARAM_DRIVER.set(params, "clickhouse")
params["uri"] = "http://localhost:8123"
params["username"] = "user"
params["password"] = "pass"

RootAllocator().use { allocator ->
AdbcDriverManager.getInstance().connect(DRIVER_FACTORY, allocator, params).use { db ->
db.connect().use { conn ->
conn.createStatement().use { stmt ->
stmt.setSqlQuery("SELECT version()")
stmt.executeQuery().use { result ->
val reader = result.reader
while (reader.loadNextBatch()) {
println(reader.vectorSchemaRoot.contentToTSVString())
}
}
}
}
}
}
}
Loading