0

I am trying to insert a map into cassandra using datastax driver . The map has value

Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz

If i try to use the Query Builder to insert the value i get the Syntax error stating no viable character for "@".

If i directly construct the cql3 comment with insert statement and construct the map as a string, it gets inserted. Any idea on this problem

Ananth
  • 971
  • 9
  • 23

1 Answers1

1

(revised) Are you using a Map type when adding the value? Below are several ways of adding a row that contains a map column. Perhaps the last example is what you are trying? The use of strings is just for debugging so you can see the string that is created in each case.

       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");
martinvr
  • 171
  • 3