yifan-c commented on code in PR #2824:
URL: https://github.com/apache/cassandra/pull/2824#discussion_r1365973153
##########
test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java:
##########
@@ -1233,6 +1235,77 @@ public void testWriteWithTimestampsAndTtl() throws
Exception
assertFalse(iter.hasNext());
}
+ @Test
+ public void testWriteWithSorted() throws Exception
+ {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
+ .forTable(schema)
+ .using("INSERT INTO " +
qualifiedTable +
+ " (k, v) VALUES
(?,text_as_blob(?))" )
+ .sorted()
+ .build();
+ int rowCount = 10_000;
+ for (int i = 0; i < rowCount; i++)
+ {
+ writer.addRow(i, UUID.randomUUID().toString());
+ }
+ writer.close();
+ loadSSTables(dataDir, keyspace);
+
+ UntypedResultSet resultSet = QueryProcessor.executeInternal("SELECT *
FROM " + qualifiedTable);
+ assertEquals(rowCount, resultSet.size());
+ Iterator<UntypedResultSet.Row> iter = resultSet.iterator();
+ for (int i = 0; i < rowCount; i++)
+ {
+ UntypedResultSet.Row row = iter.next();
+ assertEquals(i, row.getInt("k"));
+ }
+ }
+
+ @Test
+ public void testWriteWithSortedAndMaxSize() throws Exception
+ {
+ String schema = "CREATE TABLE " + qualifiedTable + " ("
+ + " k int PRIMARY KEY,"
+ + " v blob )";
+ CQLSSTableWriter writer = CQLSSTableWriter.builder()
+ .inDirectory(dataDir)
+ .forTable(schema)
+ .using("INSERT INTO " +
qualifiedTable +
+ " (k, v) VALUES
(?,text_as_blob(?))" )
+ .sorted()
+
.withMaxSSTableSizeInMiBForSorted(1)
+ .build();
+ int rowCount = 30_000;
+ // Max SSTable size is 1 MiB
+ // 30_000 rows should take 30_000 * (4 + 37) = 1.17 MiB > 1 MiB
+ for (int i = 0; i < rowCount; i++)
+ {
+ writer.addRow(i, UUID.randomUUID().toString());
+ }
+ writer.close();
+
+ File[] dataFiles = dataDir.list(f ->
f.name().endsWith(BigFormat.Components.DATA.type.repr));
Review Comment:
Improved the accuracy
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]