KExasol is a custom database driver for Exasol implemented in Kotlin (JVM).
It offers unique features compared to standard JDBC driver:
- based on native WebSocket API;
- takes advantage of modern I/O libraries: Okio, OkHttp, Moshi;
- efficient data transport via CSV streaming;
- read and write data in parallel processes with linear scaling;
- network traffic compression;
- rich SQL query formatting with named and typed placeholders;
KExasol encourages best practices that are specific for Exasol distributed architecture and massively parallel data processing. It will help you to fully leverage capabilities of this analytical DBMS.
- Exasol >= 6.0
- Kotlin >= 1.4
- Java >= 8
Add JitPack Maven repository to build.gradle.kts
:
repositories {
...
maven { setUrl("https://jitpack.io") }
}
Add dependency:
implementation("com.github.badoo:kexasol:0.2.1")
Run basic query:
val exa = ExaConnectionOptions(dsn = "<host:port>", user = "sys", password = "exasol").connect()
exa.use {
val st = exa.execute("SELECT user_name, created FROM exa_all_users LIMIT 5")
st.forEach { row ->
println(row)
}
}
Read data via CSV streaming:
val exa = ExaConnectionOptions(dsn = "<host:port>", user = "sys", password = "exasol").connect()
exa.use {
exa.streamExportReader("EXA_ALL_USERS", columns = listOf("USER_NAME", "CREATED")) { reader ->
reader.forEach { row ->
println(row.getString("USER_NAME"))
println(row.getLocalDateTime("CREATED"))
}
}
}
Create a new table and import some data in transaction:
val exa = ExaConnectionOptions(dsn = "<host:port>", user = "sys", password = "exasol").connect()
val cols = listOf("USER_ID", "USER_NAME", "IS_ACTIVE")
val data = listOf<List<Any?>>(
listOf(1L, "Alice", true),
listOf(2L, "Bob", false),
listOf(3L, "Cindy", null),
)
exa.use {
exa.setAutocommit(false)
exa.execute("CREATE SCHEMA IF NOT EXISTS kexasol_test")
exa.execute("""
CREATE OR REPLACE TABLE test_table
(
user_id DECIMAL(9,0),
user_name VARCHAR(255),
is_active BOOLEAN
)
""")
val importSt = exa.streamImportIterator("test_table", cols, data.iterator())
println("IMPORT affected rows: ${importSt.rowCount}")
exa.commit()
}
Check other examples and best practices.
Vitaly Markov, 2020
Enjoy!
Copyright 2020 Badoo
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.