{"record":{"id":"ee502050766a8e29","repo":"apache/cassandra","slug":"metadata-does-not-support-filtering-by-token-o","errorCode":null,"errorMessage":"metadata + \" does not support filtering by token or incomplete partition keys\"","messagePattern":"metadata \\+ \" does not support filtering by token or incomplete partition keys\"","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/RemoteToLocalVirtualTable.java","lineNumber":153,"sourceCode":"            builder.addRegularColumn(cm.name, cm.type, cm.getMask(), cm.getColumnConstraints());\n        }\n        builder.kind(TableMetadata.Kind.VIRTUAL);\n        return builder.build();\n    }\n\n    @Override\n    protected void collect(PartitionsCollector collector)\n    {\n        ClusterMetadata cm = ClusterMetadata.current();\n        NavigableSet<NodeId> matchingIds = cm.directory.peerIds();\n        DataRange dataRange = collector.dataRange();\n        AbstractBounds<PartitionPosition> bounds = dataRange.keyRange();\n        {\n            NodeId start = null;\n            if (!bounds.left.isMinimum())\n            {\n                if (!(bounds.left instanceof DecoratedKey))\n                    throw new InvalidRequestException(metadata + \" does not support filtering by token or incomplete partition keys\");\n                start = new NodeId(Int32Type.instance.compose(((DecoratedKey) bounds.left).getKey()));\n            }\n            NodeId end = null;\n            if (!bounds.right.isMinimum())\n            {\n                if (!(bounds.right instanceof DecoratedKey))\n                    throw new InvalidRequestException(metadata + \" does not support filtering by token or incomplete partition keys\");\n                end = new NodeId(Int32Type.instance.compose(((DecoratedKey) bounds.right).getKey()));\n            }\n            if (start != null && end != null) matchingIds = matchingIds.subSet(start, bounds.isStartInclusive(), end, bounds.isEndInclusive());\n            else if (start != null) matchingIds = matchingIds.tailSet(start, bounds.isStartInclusive());\n            else if (end != null) matchingIds = matchingIds.headSet(end, bounds.isEndInclusive());\n        }\n        if (dataRange.isReversed())\n            matchingIds = matchingIds.descendingSet();\n\n        RowFilter rowFilter = rebind(local, collector.rowFilter());\n        ColumnFilter columnFilter = ColumnFilter.rebindVirtual(collector.columnFilter(), local);","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/RemoteToLocalVirtualTable.java#L135-L171","documentation":"RemoteToLocalVirtualTable only supports lookups by complete, decorated partition keys. When the DataRange's bound is a token (not a DecoratedKey) — meaning the query filtered by token() or an incomplete partition key — collect() throws InvalidRequestException because it cannot reconstruct a NodeId from the bound.","triggerScenarios":"`SELECT ... FROM <remote_to_local virtual table> WHERE token(id) > X;` or restricting only part of a composite partition key, causing bounds.left/right to be a token bound rather than a DecoratedKey.","commonSituations":"Token-range paging patterns copied from normal table queries; queries restricting a prefix of a composite partition key; tooling that pages virtual tables by token for parallelism.","solutions":["Query with full partition key equality: `WHERE pk_col1 = ... [AND pk_col2 = ...]` covering the entire key.","Avoid token() predicates on this virtual table.","If scanning is required, iterate keys from the source table and query the virtual table per key."],"exampleFix":"// before\nSELECT * FROM system_views.remote_to_local WHERE token(id) > -9223372036854775808;\n// after\nSELECT * FROM system_views.remote_to_local WHERE id = 42;","handlingStrategy":"validation","validationCode":"// Require full partition-key equality, no token() predicates\nif (cql.contains(\"token(\"))\n    throw new IllegalArgumentException(\"token filtering is not supported on remote_to_local virtual tables\");\n// and ensure all partition key columns have equality restrictions","typeGuard":null,"tryCatchPattern":"try { rs = session.execute(query); }\ncatch (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException e) {\n    if (e.getMessage().contains(\"does not support filtering by token\")) { /* rewrite with full-key equality */ }\n    else throw e;\n}","preventionTips":["Query remote_to_local virtual tables only by complete partition key equality.","Do not apply token() or partial composite-key filters.","Iterate source-table keys and query per key when full scans are needed."],"tags":["cassandra","virtual-table","token","partition-key"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}