1

我尝试使用 yugabyte-cassandra-driver (C#) 运行此查询:

        public async Task IncreaseUnread(int userId, long peerId, int count)
        {
            var statement = await Session.PrepareAsync("UPDATE messaging_db.dialog SET unreadCount = unreadCount + ? WHERE userId = ? AND longPeerId = ?");
            var bounded = statement.Bind(count, userId, peerId);

            await Session.ExecuteAsync(bounded);
        }

我遇到了这个错误:

Cassandra.InvalidQueryException: Invalid Function Call. Failed calling '+(int,anytype)'. Found too many matches for builtin function '+'
UPDATE messaging_db.dialog SET unreadCount = unreadCount + ? WHERE userId = ? AND longPeerId = ?
                                                     ^

我应该怎么做才能解决这个问题?是否有可用的类型转换?

更新:

我的表架构:

CREATE TABLE IF NOT EXISTS messaging_db.dialog(
    userId INT,
    longPeerId BIGINT,
    topMessageId INT,
    readInboxMaxId INT,
    readOutboxMaxId INT,
    unreadCount INT,
    unreadMentionCount INT,
    pts INT,
    draft TEXT,
    pinned BOOLEAN,
    unreadMark BOOLEAN,
    modificationTime TIMESTAMP,
    PRIMARY KEY((userId), longPeerId)
);
4

1 回答 1

0

作为一种解决方法,您可以使用硬编码参数执行查询。使用字符串格式:

UPDATE messaging_db.dialog SET unreadCount = unreadCount + 1 WHERE userId = 2 AND longPeerId = 3;

转载自Java:

 @Test
  public void testPrepare() throws Exception {
    session.execute("CREATE TABLE dialog(userId INT PRIMARY KEY, unreadCount INT);");
    session.execute("insert into dialog (userId, unreadCount) values (100, 1);");
    String stmt = "UPDATE dialog SET unreadCount = unreadCount + ? WHERE userId = 10;";
    PreparedStatement prep = session.prepare(stmt);
    session.execute(prep.bind(2));
    assertQueryRowsUnordered("select * from dialog;", "Row[100, 3]");
    session.execute("drop table dialog;");
  }

例外:

[ERROR] testPrepare(org.yb.cql.TestPrepareExecute)  Time elapsed: 9.713 s  <<< ERROR!
com.datastax.driver.core.exceptions.InvalidQueryException: 
Invalid Function Call. Failed calling '+(int,anytype)'. Found too many matches for builtin function '+'
UPDATE dialog SET unreadCount = unreadCount + ? WHERE userId = 10;
                                            ^
 (ql error -214)

跟踪问题:github.com/yugabyte/yugabyte-db/issues/3559

于 2020-02-04T16:27:52.490 回答