You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2021/07/23 21:29:50 UTC

[GitHub] [cassandra] alex-ninja commented on a change in pull request #1117: CASSANDRA-16806. Allow TRUNCATE to work on Virtual Tables if the implementation allows it.

alex-ninja commented on a change in pull request #1117:
URL: https://github.com/apache/cassandra/pull/1117#discussion_r675874045



##########
File path: test/unit/org/apache/cassandra/cql3/validation/entities/VirtualTableTest.java
##########
@@ -317,6 +365,32 @@ public void testModifications() throws Throwable
                              "INSERT INTO test_virtual_ks.vt2 (key, value) VALUES ('pk2', 22) IF NOT EXISTS");
     }
 
+    @Test
+    public void testTruncationOnTruncatableTable() throws Throwable
+    {
+        // check for existing records
+        assertRows(execute("SELECT * FROM test_virtual_ks.vt4"),
+                row("pk1", 1),
+                row("pk2", 2));
+
+        // truncate
+        execute("TRUNCATE test_virtual_ks.vt4");
+
+        // check that truncation is applied
+        assertEmpty(execute("SELECT * FROM test_virtual_ks.vt4"));
+    }
+
+    @Test
+    public void testInvalidDMLOperations() throws Throwable

Review comment:
       I moved truncation test from `testInvalidDDLOperations` to `testInvalidDMLOperations` because `TRUNCATE` is a DML operation. Also I added a test for `INSERT` into read-only VT - it was missing.

##########
File path: doc/source/new/virtualtables.rst
##########
@@ -42,11 +42,12 @@ Virtual tables and virtual keyspaces are quite different from regular tables and
 - Virtual tables are not replicated
 - Virtual tables are local only and non distributed
 - Virtual tables have no associated SSTables
+- Virtual tables support ``TRUNCATE`` only if the underlaying implementation allows it
 - Consistency level of the queries sent virtual tables are ignored
-- Virtual tables are managed by Cassandra and a user cannot run  DDL to create new virtual tables or DML to modify existing virtual       tables

Review comment:
       ``TRUNCATE`` is a DML

##########
File path: test/unit/org/apache/cassandra/cql3/validation/entities/VirtualTableTest.java
##########
@@ -317,6 +365,32 @@ public void testModifications() throws Throwable
                              "INSERT INTO test_virtual_ks.vt2 (key, value) VALUES ('pk2', 22) IF NOT EXISTS");
     }
 
+    @Test
+    public void testTruncationOnTruncatableTable() throws Throwable

Review comment:
       This is a unit test to cover the actual change.

##########
File path: test/unit/org/apache/cassandra/cql3/validation/entities/VirtualTableTest.java
##########
@@ -118,16 +147,15 @@ public DataSet data()
         };
         VirtualTable vt2 = new WritableVirtualTable(KS_NAME, VT2_NAME);
 
-        TableMetadata vt3Metadata =
-        TableMetadata.builder(KS_NAME, VT3_NAME)

Review comment:
       It was badly formatted.

##########
File path: test/unit/org/apache/cassandra/cql3/validation/entities/VirtualTableTest.java
##########
@@ -88,17 +89,45 @@ public void apply(PartitionUpdate update)
         }
     }
 
+    private abstract static class TruncatableVirtualTable extends AbstractVirtualTable
+    {
+        private boolean isTruncated = false;
+
+        TruncatableVirtualTable(TableMetadata metadata)
+        {
+            super(metadata);
+        }
+
+        @Override
+        public DataSet data()
+        {
+            if (isTruncated)

Review comment:
       Just a simple way to emulate truncation. Theoretically I could use a collection, smth like that:
   ```
   TruncatableVirtualTable(TableMetadata metadata, Map<String, Integer> refToCleanupData) 
   
   public void truncate()
   {
           refToCleanupData.clear();
   }
   ```
   ```
   Map<String, Integer> truncatableData = <some data>;
   VirtualTable vt4 = new TruncatableVirtualTable(vt4Metadata, truncatableData)
   {
   
       public DataSet data()
       {
               SimpleDataSet data = new SimpleDataSet(metadata());
               truncatableData.forEach((key, value) -> data.row(key).column("value", value));
               return data;
       }
   
   }
   ```
   
   This way looks more similar to a real use case. Please, let me know if this one is more preferable for a unit test.

##########
File path: test/unit/org/apache/cassandra/cql3/validation/entities/VirtualTableTest.java
##########
@@ -88,17 +89,45 @@ public void apply(PartitionUpdate update)
         }
     }
 
+    private abstract static class TruncatableVirtualTable extends AbstractVirtualTable
+    {
+        private boolean isTruncated = false;
+
+        TruncatableVirtualTable(TableMetadata metadata)
+        {
+            super(metadata);
+        }
+
+        @Override
+        public DataSet data()
+        {
+            if (isTruncated)
+            {
+                return new SimpleDataSet(metadata());
+            }
+
+            return truncatableData();
+        }
+
+        abstract protected DataSet truncatableData();
+
+        @Override
+        public void truncate()
+        {
+            isTruncated = true;
+        }
+    }
+
     @BeforeClass
     public static void setUpClass()
     {
-        TableMetadata vt1Metadata =
-        TableMetadata.builder(KS_NAME, VT1_NAME)

Review comment:
       It was badly formatted.




-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org