Cassandra 3.4 Java LIKE 运算符
Cassandra 3.4 Java LIKE operator
Cassandra 3.4 现在通过自定义索引提供 LIKE 运算符。
在我使用 cqlsh 和 SELECT * FROM table WHERE indexed_column LIKE '%VALU%'
之类的测试示例中,它工作正常。我已经建立了一个索引,并且一切正常。
如何在具有动态值的 Java 驱动程序(我使用的是版本 3.0.2)中执行此操作?我的查询使用 QueryBuilder 并在使用像这样的文字值时使用 PreparedStatements(PS 示例,但 QueryBuilder 也适用于文字值):
PreparedStatement ps = PreparedStatement("SELECT * FROM table WHERE indexed_column LIKE '%VALU%'");
但如果我想使用?在 QueryBuilder 或使用 PreparedStatements 中绑定一个值(例如绑定“%VAL%”)。例如
PreparedStatement ps = PreparedStatement("SELECT * FROM table WHERE indexed_column LIKE ?");
BoundStatement boundStatement = new BoundStatement(ps);
cassandraSession.execute(boundStatement.bind('%VAL%');
我收到以下错误:
com.datastax.driver.core.exceptions.SyntaxError: line 1:53 mismatched input '?' expecting STRING_LITERAL (...test.table WHERE indexed_column LIKE [?];)
这是 3.4 中的一个错误,已通过 CASSANDRA-11456 在 C* 3.6 中修复,因为您无法为 LIKE 运算符上的值提供绑定标记 (?)。如果您升级到 Cassandra 3.6,这应该可以工作。
Cassandra 3.4 现在通过自定义索引提供 LIKE 运算符。
在我使用 cqlsh 和 SELECT * FROM table WHERE indexed_column LIKE '%VALU%'
之类的测试示例中,它工作正常。我已经建立了一个索引,并且一切正常。
如何在具有动态值的 Java 驱动程序(我使用的是版本 3.0.2)中执行此操作?我的查询使用 QueryBuilder 并在使用像这样的文字值时使用 PreparedStatements(PS 示例,但 QueryBuilder 也适用于文字值):
PreparedStatement ps = PreparedStatement("SELECT * FROM table WHERE indexed_column LIKE '%VALU%'");
但如果我想使用?在 QueryBuilder 或使用 PreparedStatements 中绑定一个值(例如绑定“%VAL%”)。例如
PreparedStatement ps = PreparedStatement("SELECT * FROM table WHERE indexed_column LIKE ?");
BoundStatement boundStatement = new BoundStatement(ps);
cassandraSession.execute(boundStatement.bind('%VAL%');
我收到以下错误:
com.datastax.driver.core.exceptions.SyntaxError: line 1:53 mismatched input '?' expecting STRING_LITERAL (...test.table WHERE indexed_column LIKE [?];)
这是 3.4 中的一个错误,已通过 CASSANDRA-11456 在 C* 3.6 中修复,因为您无法为 LIKE 运算符上的值提供绑定标记 (?)。如果您升级到 Cassandra 3.6,这应该可以工作。