milvus-sdk-java icon indicating copy to clipboard operation
milvus-sdk-java copied to clipboard

使用milvus java sdk的QueryIterator出现报错:id > \Q123456\, error: line 1:12 token recognition error at: '\'

Open feriki opened this issue 1 year ago • 3 comments

看起来是io.milvus.orm.iterator.QueryIterator#setupNextExpr方法导致的,使用的milvus-sdk-java版本是2.3.6,如图 21

feriki avatar Jul 03 '24 02:07 feriki

I thought we can not just append something to string. @MrPresent-Han please help on it

xiaofan-luan avatar Jul 05 '24 06:07 xiaofan-luan

public static byte[] incrementBytes(byte[] value) {
    if (value == null || value.length == 0) {
        throw new IllegalArgumentException("Input byte array cannot be null or empty");
    }

    byte[] newValue = value.clone();
    boolean carry = true;
    int index = newValue.length - 1;

    while (carry && index >= 0) {
        if (newValue[index] == (byte) 0xFF) {
            newValue[index] = 0;
            index--;
        } else {
            newValue[index]++;
            carry = false;
        }
    }

    // If carry is still true, this means we have overflowed beyond the most significant byte
    if (carry) {
        byte[] extendedValue = new byte[newValue.length + 1];
        System.arraycopy(newValue, 0, extendedValue, 1, newValue.length);
        extendedValue[0] = 1; // Add a new leading byte
        return extendedValue;
    }

    return newValue;
}

xiaofan-luan avatar Jul 05 '24 07:07 xiaofan-luan

python也有类似的问题,处理varchar中带有 双引号,单引号,转义符 的情况都有些问题。目前queryIterator无法处理。在setupNextExpr方法中使用String.replace的方式把双引号和单引号转义,可以部分修复这个问题。但是包含转义符的字符串我觉得似乎无解。

而query()/search()处理这些特殊符号需要特别的写法。比如某个Varchar字段,插入如下字符串:

"\Q1234"
如果想用query过滤,得这么写 collection.query(expr="\\\\Q1234")

""Q1234"
如果想用query过滤,得这么写 collection.query(expr="\\"Q1234")

"'Q1234"
如果想用query过滤,得这么写 collection.query(expr="\'Q1234")

yhmo avatar Aug 19 '24 10:08 yhmo