-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclickhouse-client-test.sc
28 lines (24 loc) · 1.08 KB
/
clickhouse-client-test.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
interp.load.ivy("ru.yandex.clickhouse" % "clickhouse-jdbc" % "0.3.1")
@
import scala.collection.JavaConverters._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.language.implicitConversions
import ru.yandex.clickhouse._
import ru.yandex.clickhouse.settings.ClickHouseProperties
import ru.yandex.clickhouse.settings.ClickHouseQueryParam
val url = "jdbc:clickhouse://localhost:8123/default"
val properties = new ClickHouseProperties()
// set connection options - see more defined in ClickHouseConnectionSettings
properties.setClientName("Agent #1")
properties.setSessionId("default-session-id")
properties.setUser("default")
properties.setPassword("")
val dataSource = new ClickHouseDataSource(url, properties)
val sql = "select * from visits"
val additionalDBParams = Map(ClickHouseQueryParam.SESSION_ID -> "new-session-id")
// set request options, which will override the default ones in ClickHouseProperties
val conn = dataSource.getConnection()
val stmt = conn.createStatement()
val rs = stmt.executeQuery(sql, additionalDBParams.asJava)
println(rs)