Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

jasonliu0704 avatar image
jasonliu0704 asked Erick Ramirez answered

Is it possible to see the actual queries built with prepared and bound statements?

SO I am using the datastax java driver session to build CQL query using preparedStatement and boundedStatement and use session to execute it. https://docs.datastax.com/en/developer/java-driver/3.0/manual/statements/prepared/

Is there is way to check the actual CQL query the builder build during unit test without run a embedded or cassandra node in the JVM?

I have check simulacron which works for simple statement but doesn't work for prepared statement as it doesn't maintain any internal state for the data and the schema of a table.

thanks

java driver
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

Older version

Have a look at QueryLogger in Java driver 3.x which has the ability to log all executed statements:

Cluster cluster = ...
QueryLogger queryLogger = QueryLogger.builder()
    .withConstantThreshold(...)
    .withMaxQueryStringLength(...)
    .build();
cluster.register(queryLogger);

The usual caveats apply such as watch out for large query strings.

For more info, see Logging in Java driver 3.0. See the examples in the API docs.

Note that I've referenced 3.0 based on the link you provided. If you're writing a new app, we recommend that you use the latest 4.x series instead.

Current releases

Java driver 4.x uses request logger to log all requests. Here is an example for enabling it via a configuration file:

datastax-java-driver.advanced.request-tracker {
  class = RequestLogger

  logs {
    success.enabled = true

    slow {
      threshold = 1 second
      enabled = true
    }

    error.enabled = tr
    max-query-length = 500
    show-values = true
    max-value-length = 50
    max-values = 50
    show-stack-traces = true
}

For details, see Request Logger. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.