簡體   English   中英

Java代碼中的cassandra更新表

[英]cassandra update table from java code

我正在嘗試在Cassandra中為表實現各種分區。 我的基本思想是為每一行分配一些磁盤號,然后根據其磁盤號將其置於各種視圖中。 對於RoundRobin參與,這就是我正在做的事情:

System.out.println("\n\nRR PARTITIONING\n\n");
    results = session.execute("select * from user;");
    int i=0, disk_no=0, total_disks=4;
    for(Row row: results)
    {
        String emailid = row.getString("email");
        disk_no = i++%total_disks;
        session.execute("update user set disk_no="+disk_no+" where email="+emailid+";");

        System.out.println("Disk "+disk_no+ ": "+ row.getString("firstname")+" "+row.getString("lastname")+" "+ row.getInt("age"));
    }
    session.execute("create materialized view RRDisk0 as select * from user where disk_no =0 and email is not null;");
    session.execute("create materialized view RRDisk1 as select * from user where disk_no =1 and email is not null;");
    session.execute("create materialized view RRDisk2 as select * from user where disk_no =2 and email is not null;");
    session.execute("create materialized view RRDisk3 as select * from user where disk_no =3 and email is not null;");

我面臨的錯誤說:

Exception in thread "main" com.datastax.driver.core.exceptions.SyntaxError: line 1:44 no viable alternative at character '@'

請幫幫我,我從兩個小時以來一直在努力,無法找出問題所在。

您忘記在更新查詢中引用 emailid值。 應該是:

`session.execute("update user set disk_no="+disk_no+" where email='"+emailid+"';");`

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM