2013-10-10 57 views
0

我想使用datastax驅動程序將地圖插入cassandra。該地圖具有價值語法錯誤:沒有可行的替代方法「@」

英特爾(R)酷睿(TM)睿i5-2520M CPU @ 2.50GHz

如果我嘗試使用查詢生成器插入我得到的語法錯誤,說明沒有可行的字符值爲「@」。

如果我直接使用insert語句構造cql3註釋並將該構造映射爲字符串,則會插入它。關於這個問題的任何想法

+1

編輯您的問題以包含代碼,這將更容易發現問題。 –

回答

1

(修改) 您是否在添加值時使用了Map類型?以下是添加包含地圖列的行的幾種方法。也許最後一個例子是你正在嘗試的?字符串的使用僅用於調試,因此您可以看到每種情況下創建的字符串。

 session.execute("DROP TABLE imdb.mapper;"); 

     String value = "Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz"; 

     session.execute("CREATE TABLE imdb.mapper (id int, maptest map<int,text>, PRIMARY KEY(id));"); 
     session.execute("INSERT into imdb.mapper (id,maptest) VALUES (0,{});"); 
     System.out.println("Row inserted with empty map"); 

     session.execute(QueryBuilder.update("imdb","mapper").with(QueryBuilder.put("maptest", 5, value)). 
       where(QueryBuilder.eq("id", 0))); 
     System.out.println("Map updated with QueryBuilder"); 

     String s1 = "INSERT into imdb.mapper (id,maptest) VALUES (1,{1 : \'Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz\'});"; 
     System.out.println(s1); 
     session.execute(s1); 
     System.out.println("Row inserted as string"); 

     String s2 = "INSERT into imdb.mapper (id,maptest) VALUES (2,{1 : '"+value+"'});"; 
     System.out.println(s2); 
     session.execute(s2); 
     System.out.println("Row inserted as strings"); 

     Map<Integer,String> m = new HashMap<Integer,String>(); 
     m.put(1, value); 
     String s3= QueryBuilder.insertInto("imdb", "mapper").value("id", 3) 
       .value("maptest", m).toString() ; 


     System.out.println("S="+s3); 
     session.execute(s3); 
     System.out.println("Row inserted as QueryBuilder"); 
+0

我直接插入一個地圖對象。那時候,我正面臨着這個問題 – Ananth

相關問題