Skip to content

Commit 41e95b8

Browse files
esadekianmcook
andauthored
Add Kotlin examples (#105)
* Add Kotlin examples * Remove Gradle Wrapper * Fix README formatting * Remove orphaned files * Add Kotlin to generate-readmes config * Add Kotlin Quack example --------- Co-authored-by: Emil Sadek <esadek@users.noreply.github.com> Co-authored-by: Ian Cook <ianmcook@gmail.com>
1 parent 1bf60a6 commit 41e95b8

174 files changed

Lines changed: 5088 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/data/languages.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"go": "Go",
44
"java": "Java",
55
"javascript": "JavaScript",
6+
"kotlin": "Kotlin",
67
"cpp": "C++",
78
"r": "R",
89
"rust": "Rust"

‎.github/workflows/generate-readmes.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ on:
2929
- 'cpp/**'
3030
- 'go/**'
3131
- 'java/**'
32+
- 'kotlin/**'
3233
- 'python/**'
3334
- 'r/**'
3435
- 'rust/**'

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ node_modules
88
package-lock.json
99
javascript/node-packages/
1010
.pixi
11+
.gradle
12+
.kotlin
13+
build

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Simple examples showing how to use ADBC to connect, run a query, and return the
3333
- [Go](./go)
3434
- [Java](./java)
3535
- [JavaScript](./javascript)
36+
- [Kotlin](./kotlin)
3637
- [Python](./python)
3738
- [R](./r)
3839
- [Rust](./rust)

‎kotlin/README.md‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!--
2+
Copyright 2026 Columnar Technologies Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<!--
18+
⚠️ DO NOT EDIT THIS FILE MANUALLY ⚠️
19+
This file is auto-generated by .github/scripts/generate_readmes.py
20+
To update, modify .github/data/databases.json or .github/data/languages.json
21+
-->
22+
23+
# Kotlin ADBC Quickstarts
24+
25+
Simple Kotlin examples showing how to use ADBC to connect, run a query, and return the results.
26+
27+
## Source systems covered
28+
29+
- [Google BigQuery](./bigquery)
30+
- [ClickHouse](./clickhouse)
31+
- [Databricks](./databricks)
32+
- [DuckDB-compatible systems](./duckdb)
33+
- [DuckDB](./duckdb/duckdb)
34+
- [MotherDuck](./duckdb/motherduck)
35+
- [Exasol](./exasol)
36+
- [Apache Arrow Flight SQL-compatible systems](./flightsql)
37+
- [Apache Doris](./flightsql/doris)
38+
- [Dremio](./flightsql/dremio)
39+
- [GizmoSQL](./flightsql/gizmosql)
40+
- [InfluxDB](./flightsql/influxdb)
41+
- [StarRocks](./flightsql/starrocks)
42+
- [Microsoft SQL Server](./mssql)
43+
- [MySQL-compatible systems](./mysql)
44+
- [MariaDB](./mysql/mariadb)
45+
- [MySQL](./mysql/mysql)
46+
- [TiDB](./mysql/tidb)
47+
- [Vitess](./mysql/vitess)
48+
- [Oracle Database](./oracle)
49+
- [PostgreSQL-compatible systems](./postgresql)
50+
- [Citus](./postgresql/citus)
51+
- [CockroachDB](./postgresql/cockroachdb)
52+
- [CrateDB](./postgresql/cratedb)
53+
- [Neon](./postgresql/neon)
54+
- [ParadeDB](./postgresql/paradedb)
55+
- [PostgreSQL](./postgresql/postgresql)
56+
- [TimescaleDB](./postgresql/timescaledb)
57+
- [Yellowbrick](./postgresql/yellowbrick)
58+
- [YugabyteDB](./postgresql/yugabytedb)
59+
- [Quack](./quack)
60+
- [Amazon Redshift](./redshift)
61+
- [SingleStore](./singlestore)
62+
- [Snowflake](./snowflake)
63+
- [SQLite](./sqlite)
64+
- [Teradata](./teradata)
65+
- [Trino](./trino)
66+
67+
## Instructions
68+
69+
Each subdirectory contains its own README with specific instructions.

‎kotlin/bigquery/README.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!--
2+
Copyright 2026 Columnar Technologies Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
# Connecting Kotlin and BigQuery with ADBC
18+
19+
## Instructions
20+
21+
### Prerequisites
22+
23+
1. [Install Gradle](https://docs.gradle.org/current/userguide/installation.html)
24+
25+
1. [Install dbc](https://docs.columnar.tech/dbc/getting_started/installation/)
26+
27+
1. [Install Google Cloud CLI](https://cloud.google.com/sdk/docs/install)
28+
29+
1. [Create a Google account](https://accounts.google.com) or be able to log in to an existing one
30+
31+
### Set up BigQuery
32+
33+
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
34+
35+
1. Run this command in your terminal to log in with the Google Cloud CLI:
36+
37+
```sh
38+
gcloud auth application-default login
39+
```
40+
41+
### Connect to BigQuery
42+
43+
1. Install the BigQuery ADBC driver:
44+
45+
```sh
46+
dbc install bigquery
47+
```
48+
49+
1. Customize the `main` function in `Main.kt`
50+
- Change the connection arguments in `params`
51+
- Change the value of the `adbc.bigquery.sql.project_id` argument to match the project ID you recorded in the earlier step
52+
- Change the value of `adbc.bigquery.sql.dataset_id`, or keep it as is to use the public Shakespeare dataset
53+
- If you changed the dataset, also change the SQL SELECT statement in `stmt.setSqlQuery`
54+
55+
1. Run the Kotlin program:
56+
57+
```sh
58+
gradle run
59+
```

‎kotlin/bigquery/build.gradle.kts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
plugins {
2+
kotlin("jvm") version "2.3.21"
3+
application
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
val arrowVersion = "18.3.0"
11+
val adbcVersion = "0.21.0"
12+
13+
dependencies {
14+
implementation("org.apache.arrow:arrow-memory-core:$arrowVersion")
15+
implementation("org.apache.arrow:arrow-memory-netty:$arrowVersion")
16+
implementation("org.apache.arrow:arrow-vector:$arrowVersion")
17+
implementation("org.apache.arrow.adbc:adbc-core:$adbcVersion")
18+
implementation("org.apache.arrow.adbc:adbc-driver-manager:$adbcVersion")
19+
implementation("org.apache.arrow.adbc:adbc-driver-jni:$adbcVersion")
20+
implementation("org.slf4j:slf4j-nop:2.0.16")
21+
}
22+
23+
application {
24+
mainClass.set("MainKt")
25+
applicationDefaultJvmArgs =
26+
listOf(
27+
"--add-opens=java.base/java.nio=ALL-UNNAMED",
28+
"--enable-native-access=ALL-UNNAMED",
29+
"--sun-misc-unsafe-memory-access=allow",
30+
)
31+
}

‎kotlin/bigquery/gradle.properties‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.configuration-cache=true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "adbc-quickstart-bigquery"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2026 Columnar Technologies Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import org.apache.arrow.adbc.driver.jni.JniDriver
18+
import org.apache.arrow.adbc.drivermanager.AdbcDriverManager
19+
import org.apache.arrow.memory.RootAllocator
20+
21+
private const val DRIVER_FACTORY = "org.apache.arrow.adbc.driver.jni.JniDriverFactory"
22+
23+
fun main() {
24+
val params = mutableMapOf<String, Any>()
25+
JniDriver.PARAM_DRIVER.set(params, "bigquery")
26+
params["adbc.bigquery.sql.project_id"] = "my-gcp-project"
27+
params["adbc.bigquery.sql.dataset_id"] = "bigquery-public-data"
28+
29+
RootAllocator().use { allocator ->
30+
AdbcDriverManager.getInstance().connect(DRIVER_FACTORY, allocator, params).use { db ->
31+
db.connect().use { conn ->
32+
conn.createStatement().use { stmt ->
33+
stmt.setSqlQuery(
34+
"""
35+
SELECT word, corpus FROM bigquery-public-data.samples.shakespeare
36+
WHERE word_count = 1 ORDER BY RAND() LIMIT 5;
37+
""".trimIndent(),
38+
)
39+
stmt.executeQuery().use { result ->
40+
val reader = result.reader
41+
while (reader.loadNextBatch()) {
42+
println(reader.vectorSchemaRoot.contentToTSVString())
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)