Skip to content

Instantly share code, notes, and snippets.

@loganlinn
Last active July 16, 2020 17:51
Show Gist options
  • Save loganlinn/ea96156ff6652e5d71698436ddb1aabe to your computer and use it in GitHub Desktop.
Save loganlinn/ea96156ff6652e5d71698436ddb1aabe to your computer and use it in GitHub Desktop.
Beginnings of ClickHouse <> JetBrains/Exposed integration
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.vendors.DataTypeProvider
import org.jetbrains.exposed.sql.vendors.FunctionProvider
import org.jetbrains.exposed.sql.vendors.VendorDialect
import java.util.*
object ClickHouseDataTypeProvider : DataTypeProvider() {
override fun binaryType(): String = "String"
override fun binaryType(length: Int): String = "FixedString($length)"
override fun blobType(): String = "String"
override fun booleanType(): String = "Int8"
override fun byteType(): String = "Int8"
override fun dateTimeType(): String = "DateTime"
override fun doubleType(): String = "Float64"
override fun floatType(): String = "Float32"
override fun integerAutoincType(): String = error("Auto-incrementing column is not supported")
override fun integerType(): String = "Int32"
override fun longAutoincType(): String = error("Auto-incrementing column is not supported")
override fun longType(): String = "Int64"
override fun shortType(): String = "Int16"
override fun textType(): String = "String"
override fun uintegerType(): String = "UInt32"
override fun ulongType(): String = "UInt64"
override fun ushortType(): String = "UInt16"
override fun uuidToDB(value: UUID): Any = super.uuidToDB(value)
override fun uuidType(): String = "UUID"
}
object ClickHouseFunctionProvider : FunctionProvider() {
}
open class ClickHouseDialect : VendorDialect(dialectName, ClickHouseDataTypeProvider, ClickHouseFunctionProvider) {
companion object {
const val dialectName: String = "clickhouse"
/**
* Registers this dialect with [Database.registerDialect]
*/
fun register() {
Database.registerDialect(dialectName, ::ClickHouseDialect)
}
}
}
import org.jetbrains.exposed.sql.Table
object SystemColumns : Table("columns") {
val database = varchar("database", Int.MAX_VALUE)
val table = varchar("table", Int.MAX_VALUE)
val name = varchar("name", Int.MAX_VALUE)
val type = varchar("type", Int.MAX_VALUE)
val position = integer("position")
val comment = varchar("comment", Int.MAX_VALUE)
val isInPartitionKey = bool("is_in_partition_key")
val isInSortingKey = bool("is_in_sorting_key")
val isInPrimaryKey = bool("is_in_primary_key")
val isInSamplingKey = bool("is_in_sampling_key")
val compressionCodec = varchar("compression_codec", Int.MAX_VALUE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment