ifesdjeen commented on code in PR #4375:
URL: https://github.com/apache/cassandra/pull/4375#discussion_r2378587304
##########
src/java/org/apache/cassandra/db/filter/ColumnFilter.java:
##########
@@ -305,6 +305,11 @@ public boolean isWildcard()
return false;
}
+ /**
+ * Rebinds matching columns into a new filter; ignores any missing but
fails if any are a different type
+ */
+ public abstract ColumnFilter rebind(TableMetadata newTable);
Review Comment:
Seems like a dangerous feature to generally expose. Could we add an assert
that this is for virtual tables only, and add a comment that this is not for
general use?
##########
src/java/org/apache/cassandra/db/filter/ColumnFilter.java:
##########
@@ -779,6 +790,17 @@ public Tester newTester(ColumnMetadata column)
return new
Tester(fetchingStrategy.fetchesAllColumns(column.isStatic()), s.iterator());
}
+ @Override
+ public ColumnFilter rebind(TableMetadata newTable)
+ {
+ RegularAndStaticColumns queried = ColumnFilter.rebind(newTable,
this.queried);
+ RegularAndStaticColumns fetched = this.queried == this.fetched ?
queried : ColumnFilter.rebind(newTable, this.fetched);
+ SortedSetMultimap<ColumnIdentifier, ColumnSubselection>
subSelections = this.subSelections;
+ if (subSelections != null)
+ subSelections = TreeMultimap.create(subSelections);
Review Comment:
Could you elaborate, why we need to re-wrap this? I thought this should be
effectively immutable.
##########
src/java/org/apache/cassandra/db/virtual/RemoteToLocalVirtualTable.java:
##########
@@ -0,0 +1,609 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.db.virtual;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NavigableSet;
+import java.util.function.Function;
+
+import accord.utils.Invariants;
+import org.apache.cassandra.cql3.Operator;
+import org.apache.cassandra.db.BufferClusteringBound;
+import org.apache.cassandra.db.Clustering;
+import org.apache.cassandra.db.ClusteringBound;
+import org.apache.cassandra.db.ClusteringPrefix;
+import org.apache.cassandra.db.DataRange;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.DeletionInfo;
+import org.apache.cassandra.db.PartitionPosition;
+import org.apache.cassandra.db.PartitionRangeReadCommand;
+import org.apache.cassandra.db.RangeTombstone;
+import org.apache.cassandra.db.ReadCommand;
+import org.apache.cassandra.db.ReadResponse;
+import org.apache.cassandra.db.SinglePartitionReadCommand;
+import org.apache.cassandra.db.Slice;
+import org.apache.cassandra.db.Slices;
+import org.apache.cassandra.db.TruncateRequest;
+import org.apache.cassandra.db.filter.ClusteringIndexFilter;
+import org.apache.cassandra.db.filter.ClusteringIndexSliceFilter;
+import org.apache.cassandra.db.filter.ColumnFilter;
+import org.apache.cassandra.db.filter.DataLimits;
+import org.apache.cassandra.db.filter.IndexHints;
+import org.apache.cassandra.db.filter.RowFilter;
+import org.apache.cassandra.db.marshal.ByteBufferAccessor;
+import org.apache.cassandra.db.marshal.CompositeType;
+import org.apache.cassandra.db.marshal.Int32Type;
+import org.apache.cassandra.db.partitions.PartitionUpdate;
+import org.apache.cassandra.db.partitions.UnfilteredPartitionIterator;
+import org.apache.cassandra.db.rows.BTreeRow;
+import org.apache.cassandra.db.rows.Cell;
+import org.apache.cassandra.db.rows.ColumnData;
+import org.apache.cassandra.db.rows.Row;
+import org.apache.cassandra.db.rows.Unfiltered;
+import org.apache.cassandra.db.rows.UnfilteredRowIterator;
+import org.apache.cassandra.dht.AbstractBounds;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.exceptions.RequestFailure;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.apache.cassandra.net.Message;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.net.RequestCallback;
+import org.apache.cassandra.net.Verb;
+import org.apache.cassandra.schema.ColumnMetadata;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.tcm.ClusterMetadata;
+import org.apache.cassandra.tcm.membership.NodeId;
+import org.apache.cassandra.utils.btree.BTree;
+import org.apache.cassandra.utils.concurrent.AsyncPromise;
+import org.apache.cassandra.utils.concurrent.Promise;
+import org.apache.cassandra.utils.concurrent.SyncPromise;
+
+import static org.apache.cassandra.db.ClusteringBound.BOTTOM;
+import static org.apache.cassandra.db.ClusteringBound.TOP;
+import static org.apache.cassandra.db.ClusteringBound.boundKind;
+import static org.apache.cassandra.db.ReadCommand.PotentialTxnConflicts.ALLOW;
+import static org.apache.cassandra.db.virtual.VirtualTable.Sorted.SORTED;
+
+public class RemoteToLocalVirtualTable extends AbstractLazyVirtualTable
+{
+ private static final int MAX_CONCURRENCY = 8;
+ final TableMetadata local;
+ final boolean allowFilteringImplicitly;
+ final boolean allowFilteringLocalPartitionKeysImplicitly;
+
+ public RemoteToLocalVirtualTable(String keyspace, VirtualTable
virtualTable)
+ {
+ super(wrap(keyspace, virtualTable.name(), virtualTable.metadata()),
virtualTable instanceof AbstractLazyVirtualTable ? ((AbstractLazyVirtualTable)
virtualTable).onTimeout() : OnTimeout.FAIL, virtualTable.sorted(), SORTED);
+ this.local = virtualTable.metadata();
+ this.allowFilteringImplicitly =
virtualTable.allowFilteringImplicitly();
+ this.allowFilteringLocalPartitionKeysImplicitly =
virtualTable.allowFilteringPrimaryKeysImplicitly();
+ }
+
+ @Override
+ public boolean allowFilteringImplicitly()
+ {
+ return allowFilteringImplicitly;
+ }
+
+ @Override
+ public boolean allowFilteringPrimaryKeysImplicitly()
+ {
+ return true;
+ }
+
+ private static TableMetadata wrap(String keyspace, String name,
TableMetadata local)
+ {
+ if (local.partitionKeyColumns().size() != 1 &&
!(local.partitionKeyType instanceof CompositeType))
+ throw new IllegalArgumentException("Underlying table must have a
single partition key, else use CompositeType for its partitioner");
+ TableMetadata.Builder builder = TableMetadata.builder(keyspace, name);
+ builder.partitioner(new LocalPartitioner(Int32Type.instance));
+ builder.addPartitionKeyColumn("node_id", Int32Type.instance);
+ for (ColumnMetadata cm : local.partitionKeyColumns())
+ builder.addClusteringColumn(cm.name, cm.type, cm.getMask(),
cm.getColumnConstraints());
+ for (ColumnMetadata cm : local.clusteringColumns())
+ builder.addClusteringColumn(cm.name, cm.type, cm.getMask(),
cm.getColumnConstraints());
+ // we don't add static columns as they can't be modelled correctly
with the insertion of a prefix partition column
+ for (ColumnMetadata cm : local.regularColumns())
+ {
+ if (!cm.isComplex())
Review Comment:
Should e maybe throw in case of complex columns? I know we're not using them
anywhere, but maybe worth to throw in case we have intention for this to be
used elsewhere.
--
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]