yifan-c commented on code in PR #4457:
URL: https://github.com/apache/cassandra/pull/4457#discussion_r2488013284


##########
test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java:
##########
@@ -1690,6 +1697,111 @@ public void testConstraintViolation() throws Exception
         }
     }
 
+    @Test
+    public void testWritingWithZstdDictionaryWhenUsingInvalidCompressor()
+    {
+        // the compressor is not dictionary-aware so we will fail
+        final String schema = "CREATE TABLE " + qualifiedTable + " ("
+                              + "  k int,"
+                              + "  v1 text,"
+                              + "  PRIMARY KEY (k)"
+                              + ") WITH compression = {'class': 
'ZstdCompressor'}";
+
+        assertThatThrownBy(() -> CQLSSTableWriter.builder()
+                                                 .inDirectory(dataDir)
+                                                 .forTable(schema)
+                                                 .using("INSERT INTO " + 
keyspace + '.' + table + " (k, v1) VALUES (?, ?)")
+                                                 // does not matter, we will 
fail anyway
+                                                 
.withCompressionDictionary(new ZstdCompressionDictionary(new DictId(ZSTD, 1), 
new byte[0]))
+                                                 .build())
+        .hasMessage("Table's compressor can not accept any dictionary: 
{chunk_length_in_kb=16, class=org.apache.cassandra.io.compress.ZstdCompressor}")
+        .isInstanceOf(IllegalStateException.class);
+    }
+
+    @Test
+    public void testWritingWithZstdDictionary() throws Exception
+    {
+        final String schema = "CREATE TABLE " + qualifiedTable + " ("
+                              + "  k int,"
+                              + "  v1 text,"
+                              + "  PRIMARY KEY (k)"
+                              + ") WITH compression = {'class': 
'ZstdDictionaryCompressor'}";
+
+        CompressionDictionary dictionary = 
DictionaryHelper.trainDictionary(keyspace, table);
+
+        CQLSSTableWriter writer = CQLSSTableWriter.builder()
+                                                  .inDirectory(dataDir)
+                                                  .forTable(schema)
+                                                  .using("INSERT INTO " + 
keyspace + '.' + table + " (k, v1) VALUES (?, ?)")
+                                                  
.withCompressionDictionary(dictionary)
+                                                  .build();
+
+        for (int i = 0; i < 500; i++)
+        {
+            writer.addRow(i, DictionaryHelper.INSTANCE.getRandomSample());
+        }
+
+        writer.close();
+
+        loadSSTables(dataDir, keyspace, table);
+
+        if (verifyDataAfterLoading)
+        {
+            UntypedResultSet resultSet = 
QueryProcessor.executeInternal("SELECT * FROM " + qualifiedTable);
+            assertNotNull(resultSet);
+            Iterator<UntypedResultSet.Row> iter = resultSet.iterator();
+            for (int i = 0; i < 500; i++)
+            {
+                UntypedResultSet.Row row = iter.next();
+                assertEquals(i, row.getInt("k"));
+                assertNotNull(row.getString("v1"));
+            }
+        }
+    }
+
+    /**
+     * Simple generator of random data for Zstd compression dictionary and 
dictionary trainer.
+     */
+    private static class DictionaryHelper
+    {
+        public static final DictionaryHelper INSTANCE = new DictionaryHelper();
+        private static final Random random = new Random();
+
+        private static final String[] dates = new String[] 
{"2025-10-20","2025-10-19","2025-10-18","2025-10-17","2025-10-16"};
+        private static final String[] times = new String[] 
{"11:00:01","11:00:2","11:00:03","11:00:04","11:00:05"};

Review Comment:
   It is not critical at all. But looks like we removed an extra 0 this time :p
   
   `"11:00:2"`



-- 
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]

Reply via email to