cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [cassandra] clohfink commented on a change in pull request #246: Abstract Virtual Table for very large result sets for CASSANDRA-14629
Date Mon, 21 Oct 2019 19:06:12 GMT
clohfink commented on a change in pull request #246: Abstract Virtual Table for very large
result sets for CASSANDRA-14629
URL: https://github.com/apache/cassandra/pull/246#discussion_r337188963
 
 

 ##########
 File path: test/unit/org/apache/cassandra/cql3/validation/entities/VirtualTableTest.java
 ##########
 @@ -116,97 +138,147 @@ public DataSet data()
             }
         };
         VirtualTable vt2 = new WritableVirtualTable(KS_NAME, VT2_NAME);
+        TableMetadata vt3metadata = TableMetadata.builder(KS_NAME, "vt3")
+                .kind(TableMetadata.Kind.VIRTUAL)
+                .partitioner(new LocalPartitioner(UTF8Type.instance))
+                .addPartitionKeyColumn("pk", UTF8Type.instance)
+                .addClusteringColumn("c", UTF8Type.instance)
+                .addRegularColumn("v1", Int32Type.instance)
+                .addRegularColumn("v2", LongType.instance)
+                .build();
+        final List<DecoratedKey> vt3keys = Lists.newArrayList(
+                makeKey(vt3metadata, "pk1"),
+                makeKey(vt3metadata, "pk2"));
+
+        VirtualTable vt3 = new AbstractIteratingTable(vt3metadata)
+        {
+            protected Iterator<DecoratedKey> getPartitionKeys(DataRange dataRange)
+            {
+                return vt3keys.iterator();
+            }
 
-        VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(vt1,
vt2)));
+            protected Iterator<Row> getRows(boolean isReversed, DecoratedKey key, RegularAndStaticColumns
columns)
+            {
+                String value = metadata.partitionKeyType.getString(key.getKey());
+                int pk = Integer.parseInt(value.substring(2));
+                List<Row> rows = Lists.newArrayList(
+                        row("c1").add("v1", 10 * pk + 1).add("v2", (long) (10 * pk + 1)).build(columns),
+                        row("c2").add("v1", 10 * pk + 2).add("v2", (long) (10 * pk + 2)).build(columns),
+                        row("c3").add("v1", 10 * pk + 3).add("v2", (long) (10 * pk + 3)).build(columns));
+                if (isReversed)
+                {
+                    Collections.reverse(rows);
+                }
+                return rows.iterator();
+            }
+
+            protected boolean hasKey(DecoratedKey partitionKey)
+            {
+                return vt3keys.contains(partitionKey);
+            }
+        };
+
+        VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(vt1,
vt2, vt3)));
 
         CQLTester.setUpClass();
     }
 
-    @Test
-    public void testQueries() throws Throwable
+    public void testQueries(String table) throws Throwable
     {
-        assertRowsNet(executeNet("SELECT * FROM test_virtual_ks.vt1 WHERE pk = 'UNKNOWN'"));
+        assertRowsNet(executeNet("SELECT * FROM test_virtual_ks."+table+" WHERE pk = 'UNKNOWN'"));
 
-        assertRowsNet(executeNet("SELECT * FROM test_virtual_ks.vt1 WHERE pk = 'pk1' AND
c = 'UNKNOWN'"));
+        assertRowsNet(executeNet("SELECT * FROM test_virtual_ks."+table+" WHERE pk = 'pk1'
AND c = 'UNKNOWN'"));
 
         // Test DISTINCT query
-        assertRowsNet(executeNet("SELECT DISTINCT pk FROM test_virtual_ks.vt1"),
+        assertRowsNet(executeNet("SELECT DISTINCT pk FROM test_virtual_ks."+table),
                       row("pk1"),
                       row("pk2"));
 
-        assertRowsNet(executeNet("SELECT DISTINCT pk FROM test_virtual_ks.vt1 WHERE token(pk)
> token('pk1')"),
+        assertRowsNet(executeNet("SELECT DISTINCT pk FROM test_virtual_ks."+table+" WHERE
token(pk) > token('pk1')"),
                       row("pk2"));
 
         // Test single partition queries
-        assertRowsNet(executeNet("SELECT v1, v2 FROM test_virtual_ks.vt1 WHERE pk = 'pk1'
AND c = 'c1'"),
+        assertRowsNet(executeNet("SELECT v1, v2 FROM test_virtual_ks."+table+" WHERE pk =
'pk1' AND c = 'c1'"),
                       row(11, 11L));
 
-        assertRowsNet(executeNet("SELECT c, v1, v2 FROM test_virtual_ks.vt1 WHERE pk = 'pk1'
AND c IN ('c1', 'c2')"),
+        assertRowsNet(executeNet("SELECT c, v1, v2 FROM test_virtual_ks."+table+" WHERE pk
= 'pk1' AND c IN ('c1', 'c2')"),
                       row("c1", 11, 11L),
                       row("c2", 12, 12L));
 
-        assertRowsNet(executeNet("SELECT c, v1, v2 FROM test_virtual_ks.vt1 WHERE pk = 'pk1'
AND c IN ('c2', 'c1') ORDER BY c DESC"),
+        assertRowsNet(executeNet("SELECT c, v1, v2 FROM test_virtual_ks."+table+" WHERE pk
= 'pk1' AND c IN ('c2', 'c1') ORDER BY c DESC"),
                       row("c2", 12, 12L),
                       row("c1", 11, 11L));
 
         // Test multi-partition queries
-        assertRows(execute("SELECT * FROM test_virtual_ks.vt1 WHERE pk IN ('pk2', 'pk1')
AND c IN ('c2', 'c1')"),
+        assertRows(execute("SELECT * FROM test_virtual_ks."+table+" WHERE pk IN ('pk2', 'pk1')
AND c IN ('c2', 'c1')"),
                    row("pk1", "c1", 11, 11L),
                    row("pk1", "c2", 12, 12L),
                    row("pk2", "c1", 21, 21L),
                    row("pk2", "c2", 22, 22L));
 
-        assertRows(execute("SELECT pk, c, v1 FROM test_virtual_ks.vt1 WHERE pk IN ('pk2',
'pk1') AND c IN ('c2', 'c1') ORDER BY c DESC"),
+        assertRows(execute("SELECT pk, c, v1 FROM test_virtual_ks."+table+" WHERE pk IN ('pk2',
'pk1') AND c IN ('c2', 'c1') ORDER BY c DESC"),
                    row("pk1", "c2", 12),
                    row("pk2", "c2", 22),
                    row("pk1", "c1", 11),
                    row("pk2", "c1", 21));
 
-        assertRows(execute("SELECT pk, c, v1 FROM test_virtual_ks.vt1 WHERE pk IN ('pk2',
'pk1') AND c IN ('c2', 'c1') ORDER BY c DESC LIMIT 1"),
+        assertRows(execute("SELECT pk, c, v1 FROM test_virtual_ks."+table+" WHERE pk IN ('pk2',
'pk1') AND c IN ('c2', 'c1') ORDER BY c DESC LIMIT 1"),
                    row("pk1", "c2", 12));
 
-        assertRows(execute("SELECT c, v1, v2 FROM test_virtual_ks.vt1 WHERE pk IN ('pk2',
'pk1') AND c IN ('c2', 'c1' , 'c3') ORDER BY c DESC PER PARTITION LIMIT 1"),
+        assertRows(execute("SELECT c, v1, v2 FROM test_virtual_ks."+table+" WHERE pk IN ('pk2',
'pk1') AND c IN ('c2', 'c1' , 'c3') ORDER BY c DESC PER PARTITION LIMIT 1"),
                    row("c3", 13, 13L),
                    row("c3", 23, 23L));
 
-        assertRows(execute("SELECT count(*) FROM test_virtual_ks.vt1 WHERE pk IN ('pk2',
'pk1') AND c IN ('c2', 'c1')"),
+        assertRows(execute("SELECT count(*) FROM test_virtual_ks."+table+" WHERE pk IN ('pk2',
'pk1') AND c IN ('c2', 'c1')"),
                    row(4L));
 
         for (int pageSize = 1; pageSize < 5; pageSize++)
         {
-            assertRowsNet(executeNetWithPaging("SELECT pk, c, v1, v2 FROM test_virtual_ks.vt1
WHERE pk IN ('pk2', 'pk1') AND c IN ('c2', 'c1')", pageSize),
+            assertRowsNet(executeNetWithPaging("SELECT pk, c, v1, v2 FROM test_virtual_ks."+table+"
WHERE pk IN ('pk2', 'pk1') AND c IN ('c2', 'c1')", pageSize),
                           row("pk1", "c1", 11, 11L),
                           row("pk1", "c2", 12, 12L),
                           row("pk2", "c1", 21, 21L),
                           row("pk2", "c2", 22, 22L));
 
-            assertRowsNet(executeNetWithPaging("SELECT * FROM test_virtual_ks.vt1 WHERE pk
IN ('pk2', 'pk1') AND c IN ('c2', 'c1') LIMIT 2", pageSize),
+            assertRowsNet(executeNetWithPaging("SELECT * FROM test_virtual_ks."+table+" WHERE
pk IN ('pk2', 'pk1') AND c IN ('c2', 'c1') LIMIT 2", pageSize),
                           row("pk1", "c1", 11, 11L),
                           row("pk1", "c2", 12, 12L));
 
-            assertRowsNet(executeNetWithPaging("SELECT count(*) FROM test_virtual_ks.vt1
WHERE pk IN ('pk2', 'pk1') AND c IN ('c2', 'c1')", pageSize),
+            assertRowsNet(executeNetWithPaging("SELECT count(*) FROM test_virtual_ks."+table+"
WHERE pk IN ('pk2', 'pk1') AND c IN ('c2', 'c1')", pageSize),
                           row(4L));
         }
 
         // Test range queries
         for (int pageSize = 1; pageSize < 4; pageSize++)
         {
-            assertRowsNet(executeNetWithPaging("SELECT * FROM test_virtual_ks.vt1 WHERE token(pk)
< token('pk2') AND c IN ('c2', 'c1') ALLOW FILTERING", pageSize),
+            assertRowsNet(executeNetWithPaging("SELECT * FROM test_virtual_ks."+table+" WHERE
token(pk) < token('pk2') AND c IN ('c2', 'c1') ALLOW FILTERING", pageSize),
                           row("pk1", "c1", 11, 11L),
                           row("pk1", "c2", 12, 12L));
 
-            assertRowsNet(executeNetWithPaging("SELECT * FROM test_virtual_ks.vt1 WHERE token(pk)
< token('pk2') AND c IN ('c2', 'c1') LIMIT 1 ALLOW FILTERING", pageSize),
+            assertRowsNet(executeNetWithPaging("SELECT * FROM test_virtual_ks."+table+" WHERE
token(pk) < token('pk2') AND c IN ('c2', 'c1') LIMIT 1 ALLOW FILTERING", pageSize),
                           row("pk1", "c1", 11, 11L));
 
-            assertRowsNet(executeNetWithPaging("SELECT * FROM test_virtual_ks.vt1 WHERE token(pk)
<= token('pk2') AND c > 'c1' PER PARTITION LIMIT 1 ALLOW FILTERING", pageSize),
+            assertRowsNet(executeNetWithPaging("SELECT * FROM test_virtual_ks."+table+" WHERE
token(pk) <= token('pk2') AND c > 'c1' PER PARTITION LIMIT 1 ALLOW FILTERING", pageSize),
                           row("pk1", "c2", 12, 12L),
                           row("pk2", "c2", 22, 22L));
 
-            assertRowsNet(executeNetWithPaging("SELECT count(*) FROM test_virtual_ks.vt1
WHERE token(pk) = token('pk2') AND c < 'c3' ALLOW FILTERING", pageSize),
+            assertRowsNet(executeNetWithPaging("SELECT count(*) FROM test_virtual_ks."+table+"
WHERE token(pk) = token('pk2') AND c < 'c3' ALLOW FILTERING", pageSize),
 
 Review comment:
   Im pushing code fixes based on other feedback but I will work on some more tests around
that and allocations

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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


Mime
View raw message