首页 文章

Cassandra 3.4 Java LIKE运算符

提问于
浏览
3

Cassandra 3.4现在通过自定义索引提供LIKE运算符 .

它在我的测试示例中使用cqlsh与 SELECT * FROM table WHERE indexed_column LIKE '%VALU%' 之类的工作正常 . 我已经 Build 了一个索引,它的功能完美无缺 .

如何在具有动态值的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 [?];)

1 回答

  • 4

    这是3.4中的错误,通过CASSANDRA-11456在C * 3.6中修复,因为您无法为LIKE运算符上的值提供绑定标记(?) . 如果你升级到Cassandra 3.6,这应该工作 .

相关问题