Skip to content

badoo/kexasol

Repository files navigation

Build Status Release

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.

Quick links

System requirements

  • Exasol >= 6.0
  • Kotlin >= 1.4
  • Java >= 8

Getting started

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.

Created by

Vitaly Markov, 2020

Enjoy!

License

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.

About

Exasol database driver implemented in Kotlin (JVM). It is based on native WebSocket API, supports parallel CSV streaming and compression.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages