-
Notifications
You must be signed in to change notification settings - Fork 25
Home
Please note: The code inside this project has not been benchmarked, tested in extreme circumstances and has not been tested by any security specialist. Use at your own discretion. Therefor, even when we are using this software in our products in production, we advise not to use this tool in production yourself, until your Q/A & security specialist have done an audit of this library.
The clickhouse-dsl of this project offers a full-featured DSL that allows to compose most Clickhouse statements. During development not much attention has been going into INSERT statements, but SELECT statements are fully supported, including complex joins, aggregating queries, merging functions etc. as well as methods to build up your database schema from the Table definitions that should be provided to use this DSL.
1. Set up your dependencies
In build.sbt add the following:
"com.crobox.clickhouse" %% "client" % ClickhouseClientVersion,
"com.crobox.clickhouse" %% "dsl" % ClickhouseClientVersion,
2. Define table schemas
for the tables that you wish to use in the DSL
package crobox.reporting.core.schema
import java.util.UUID
import com.crobox.clickhouse.dsl._
import com.crobox.clickhouse.dsl.schemabuilder._
object Actions {
object ActionsTable extends Table {
override val name: String = "actions"
val actionId = NativeColumn[UUID]("action_id")
val actionType = NativeColumn[String]("action_type")
val subActions = NativeColumn[Seq[String]]("child_ids", ColumnType.Array(ColumnType.String))
val valid = NativeColumn[Boolean]("promoted", ColumnType.Boolean)
override val columns: List[NativeColumn[_]] = List(actionId,
actionType,
subActions,
valid)
}
}
- Use the DSL
import com.crobox.clickhouse.dsl._
implicit val tokenizerDatabase: TokenizerModule.Database = "default"
val clickCountQry: OperationalQuery = select(uniq(actionId)) from ActionsTable where(actionType isEq "click")
val parsedClickCountQry: String = clickhouseTokenizer.toSql(query.internalQuery)
//val parsedClickCountQry = "SELECT uniq(action_id) FROM default.actions WHERE action_type = \"click\" FORMAT JSON"
The current documentation is quite slim around the dsl. After the quick setup the most meaningful way to understand it would be to read the tests
- More documentation
- Insert statement support
Any help is greatly appreciated
Todo pages:
- Table schemas
- SELECT statements
- Simple SELECT
- DISTINCT
- Inner queries
- JOIN
- GROUP
- Array operators
- Aggregation operators (e.g. uniqState, uniqMerge)
- COMPOSING of multiple queries
- Composition operators
<+:
,+
and:+>
- Composition operators
- Using custom types in the DSL
- Explaining the query parsing process
- The QueryValue typeclass