Search code examples
jsoncassandracqlcql3datastax-java-driver

Is there a way to perform "SELECT JSON ..." with the QueryBuilder in the CQL drivers?


I dug through datastax's QueryBuilder source code and I can't find a way to a query like:

select JSON * from myTable;

Also, it would be fairly easy to make a subclass to do this, but that is thwarted by the package protection of the constructors in com.datastax.driver.core.querybuilder.Select.

Is there any way to do this query?


Solution

  • Right now it's not possible but you will be able to use a new select().raw() method to inject arbitrary string like "JSON *".

    See the resolution of this JIRA: https://datastax-oss.atlassian.net/browse/JAVA-1086


    Added new syntax:

    select()
        .cast(fcall("writetime", column("country")), DataType.text())
        .from("artists").limit(2);
    

    I also exposed the raw method in the top-level API, so this will serve as a workaround for this kind of issue in the future:

    select = select().raw("CAST(writetime(country) AS text)").from("artists").limit(2);