问题
Using Couchbase Java DSL, a query using "fish/piraña"
gives a parse-error, but with "fish/piranha"
, there is no parse-error.
I had thought that the x()
method would correctly wrap the non-ASCII Unicode string.
Using N1ql directly, this does work with any field name (except blank) or field value:
parameterized("SELECT * from
" + bucket.name() + "WHERE
" + fieldName + "= $v", placeholders))
How can this be done using the Java Query DSL?
String species "fish/pira\u00f1a" ;
Expression expForType = x("species").eq(x(species));
OffsetPath statement = select("*").from(i(bucket.name())).where(expForType);
N1qlQuery q = N1qlQuery.simple(statement);
N1qlQueryResult result = bucket.query(q);
回答1:
So, it works via N1QL:
N1qlParams params = N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS).adhoc(true);
ParameterizedN1qlQuery query = N1qlQuery.parameterized("Select * from `quicktask` where species = 'fish/pira\u00f1a' ", JsonObject.create(), params);
System.out.println(quickProcessHistoryRepository.getCouchbaseOperations().getCouchbaseBucket().query(query));
I'm still trying to understand the behavior via SDK, I will update this answer as soon as I find the issue.
回答2:
Documentation says it supports unicode.
https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/literals.html
Strings can be either Unicode characters or escaped characters.
回答3:
Json strings can have unicode characters.
insert into default values ("f1",{"name":"fish/pira\u00f1a"});
select * from default where name = "fish/pira\u00f1a";
"results": [
{
"default": {
"name": "fish/piraña"
}
}
]
Collation (ORDER BY, indexing, ....) and data types comparison are based on byte comparison not based on unicode character. If unicode character is single/fixed byte it will work but if the data is variable multi-bytes may not work because comparison is based on byte comparison.
来源:https://stackoverflow.com/questions/55323027/in-couchbase-java-query-dsl-how-do-i-filter-for-field-values-that-are-not-ascii