crobox / clickhouse-scala-client

Clickhouse Scala Client with Reactive Streams support
GNU Lesser General Public License v3.0
112 stars 25 forks source link

Not sure how to use the client #137

Open k3rnL opened 2 years ago

k3rnL commented 2 years ago

Hello,

I tried to copy paste the example from the readme, but it turns out that it's not enough. I hardly suggest to update the doc and put at least one fully working example.

Right now, I'am able to run the program, but nothing special happens, it seems that some thread are hanging as the program does not exit at end of main:

val config: Config = ConfigFactory.parseString(
    """
      |crobox.clickhouse.client {
      |    connection: {
      |        type = "single-host",
      |        host = "localhost",
      |        port = 8123
      |    }
      |    maximum-frame-length = 100000
      |    retries = 3
      |}
      |""".stripMargin)

  implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global

  val client = new ClickhouseClient(Some(config))
  client.query("SEECT 1 + 1").map(result => {
    println(s"Got query result $result")
  })

This code don't print anything

lwolters commented 2 years ago

Hi k3rnL.

Thanks for reaching out to us. Running your example, i clearly see the following stacktrace:

09:53:45.200 [ScalaTest-run-running-ClickhouseClientTest2] INFO com.crobox.clickhouse.ClickhouseClient - Starting Clickhouse Client connecting to SingleHostBalancer(http://localhost:8123) 09:53:45.215 [ScalaTest-run-running-ClickhouseClientTest2] ERROR com.crobox.clickhouse.ClickhouseClient - Can't determine Clickhouse Server Version. Falling back to: ClickhouseServerVersion(List(21, 8, 14)). Error: String: 2: No configuration setting found for key 'settings' com.typesafe.config.ConfigException$Missing: String: 2: No configuration setting found for key 'settings' at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:156) at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:149) at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:176) at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:188) at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:193) at com.typesafe.config.impl.SimpleConfig.getObject(SimpleConfig.java:268) at com.typesafe.config.impl.SimpleConfig.getConfig(SimpleConfig.java:274) at com.typesafe.config.impl.SimpleConfig.getConfig(SimpleConfig.java:41) at com.crobox.clickhouse.internal.QuerySettings.withFallback(QuerySettings.scala:38) at com.crobox.clickhouse.internal.ClickhouseQueryBuilder.toRequest(ClickhouseQueryBuilder.scala:28) at com.crobox.clickhouse.internal.ClickhouseQueryBuilder.toRequest$(ClickhouseQueryBuilder.scala:23) at com.crobox.clickhouse.ClickhouseClient.toRequest(ClickhouseClient.scala:23) at com.crobox.clickhouse.internal.ClickHouseExecutor.$anonfun$executeRequestInternal$3(ClickHouseExecutor.scala:117) at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470) at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:63) at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:100) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94) at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:100) at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:49) at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:48) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

I think this has to be with the way you're loading the config; not sure if the default client config (containing all defaults) is loaded correctly when you use the 'parseString' method

This error doesn't show up if you use: ConfigFactory.load() instead of ConfigFactory.parseString(...). Could you try to use this ConfigFactory method along with a reference.conf file or something similar ?

Feel feel to reach out to me

k3rnL commented 2 years ago

Ohh okay, you load your default conf like this, but Akka also is doing so. I understand now. I'm not used to use Hooch like this. Usually I default the conf using "withFallback" to ensure that where ever the conf come from, I have the default values.

Anyway, my conf object seems fine now, I didn't get your exception, but just in case I fixed this. But the program is still hanging.

image

edit: Oh ! But I see your logs, and seems that slf4j is logging well for you. I guess I don't get the Exception because of this, you have a dependencies that I don't have to make slf4j works.