1

I tried run this query with 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);
        }

And i faced with this error:

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 = ?
                                                     ^

What should i do to fix this?Is there any type casting available?

Update:

My table schema:

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)
);
Ali Zeinali
  • 551
  • 4
  • 16
  • What's the table schema ? Did you recently do an alter table or drop+create table ? – dh YB Feb 04 '20 at 12:37
  • I updated my question with table schema and yes i did drop+create. – Ali Zeinali Feb 04 '20 at 14:47
  • apparently there is a `CAST()` function https://docs.yugabyte.com/latest/api/ycql/expr_fcall/#cast-function , https://docs.yugabyte.com/latest/develop/learn/strings-and-text/#casting – devio Feb 04 '20 at 20:45
  • Track issue that is fixing this: https://github.com/yugabyte/yugabyte-db/issues/3559 – dh YB Feb 05 '20 at 07:26
  • As a workaround, you can execute a query with hardcoded parameters. With string formating: `UPDATE messaging_db.dialog SET unreadCount = unreadCount + 1 WHERE userId = 2 AND longPeerId = 3;` – dh YB Feb 07 '20 at 08:20
  • Yeah It work as a temporary solution. But it has a problem which is i have to create Statement each time i want to query. – Ali Zeinali Feb 07 '20 at 09:45

1 Answers1

0

As a workaround, you can execute a query with hardcoded parameters. With string formating:

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

Reproduced from 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;");
  }

Exception:

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

Tracking issue: github.com/yugabyte/yugabyte-db/issues/3559

dh YB
  • 965
  • 3
  • 10
Oleg-YB
  • 1
  • 1