Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
feriki opened this issue Jul 3, 2024 · 3 comments

Comments

@feriki
Copy link

feriki commented Jul 3, 2024

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

@xiaofan-luan
Copy link
Contributor

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

@xiaofan-luan
Copy link
Contributor

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;
}

@yhmo
Copy link
Contributor

yhmo commented Aug 19, 2024

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants