Details
-
Bug
-
Status: Open
-
Normal
-
Resolution: Unresolved
-
None
-
Linux
-
Normal
Description
Scenario : Need to read CSV, Write SSTable using CQLSSTableWriter and load it to the keyspace. Explained here . That was not working so tried a simple test case available herehttps://github.com/apache/cassandra/blob/cassandra-3.11/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java#L378
Which did not worked either. Following is what i tried.
Created cql_keyspace3 with below table and types.
CREATE TYPE cql_keyspace3.tuple2 (a int, b int); CREATE TYPE cql_keyspace3.tuple3 (a int, b int, c int) CREATE TABLE cql_keyspace3.table3 ( k int, v1 list<frozen<tuple2>>, v2 frozen<tuple3>, PRIMARY KEY (k));
ran code
final String KS = "cql_keyspace3"; final String TABLE = "table3"; final String schema = "CREATE TABLE " + KS + "." + TABLE + " (" + " k int," + " v1 list<frozen<tuple2>>," + " v2 frozen<tuple3>," + " PRIMARY KEY (k)" + ")"; File tempdir = Files.createTempDir(); File dataDir = new File(tempdir.getAbsolutePath() + File.separator + KS + File.separator + TABLE); System.out.println(dataDir); assert dataDir.mkdirs(); CQLSSTableWriter writer = CQLSSTableWriter.builder().inDirectory(dataDir) .withType("CREATE TYPE " + KS + ".tuple2 (a int, b int)") .withType("CREATE TYPE " + KS + ".tuple3 (a int, b int, c int)").forTable(schema) .using("INSERT INTO " + KS + "." + TABLE + " (k, v1, v2) " + "VALUES (?, ?, ?)").build(); UserType tuple2Type = writer.getUDType("tuple2"); UserType tuple3Type = writer.getUDType("tuple3"); for (int i = 0; i < 100; i++) { writer.addRow(i, ImmutableList.builder().add(tuple2Type.newValue().setInt("a", i * 10).setInt("b", i * 20)) .add(tuple2Type.newValue().setInt("a", i * 30).setInt("b", i * 40)).build(), tuple3Type.newValue().setInt("a", i * 100).setInt("b", i * 200).setInt("c", i * 300)); } writer.close();
It generated sstable in "/tmp/1498224996687-0/cql_keyspace3" dir
Loaded data using following command
/tmp/1498224996687-0/cql_keyspace3 $ sstableloader -d localhost table3-e6e0fa61581911e78be6a72ebce4c745/ Established connection to initial hosts Opening sstables and calculating sections to stream Streaming relevant part of /tmp/1498224996687-0/cql_keyspace3/table3-e6e0fa61581911e78be6a72ebce4c745/mc-2-big-Data.db to [localhost/127.0.0.1] progress: [localhost/127.0.0.1]0:1/1 100% total: 100% 1.060KiB/s (avg: 1.060KiB/s) progress: [localhost/127.0.0.1]0:1/1 100% total: 100% 0.000KiB/s (avg: 0.984KiB/s) Summary statistics: Connections per host : 1 Total files transferred : 1 Total bytes transferred : 5.572KiB Total duration : 5668 ms Average transfer rate : 0.982KiB/s Peak transfer rate : 1.060KiB/s
k | v1 | v2 |
---|---|---|
92 | [{a:920,b:1840}, {a:2760,b:3680}] |
find full result in attached snapshot.
Please let me know which version of cassandra I should which can allow me to load reseverd types, collections, UDT from sstable create using CQLSSTableWriter.