Package org.apache.cassandra.db.filter
Class ColumnFilter
java.lang.Object
org.apache.cassandra.db.filter.ColumnFilter
- Direct Known Subclasses:
ColumnFilter.SelectionColumnFilter,ColumnFilter.WildCardColumnFilter
Represents which (non-PK) columns (and optionally which sub-part of a column for complex columns) are selected
by a query.
We distinguish 2 sets of columns in practice: the _fetched_ columns, which are the columns that we (may, see
below) need to fetch internally, and the _queried_ columns, which are the columns that the user has selected
in its request.
The reason for distinguishing those 2 sets is that due to the CQL semantic (see #6588 for more details), we
often need to internally fetch all regular columns or all columns for the queried table, but can still do some
optimizations for those columns that are not directly queried by the user (see #10657 for more details).
Note that in practice:
- the _queried_ columns set is always included in the _fetched_ one.
- whenever those sets are different, the _fetched_ columns can contain either all the regular columns and
the static columns queried by the user or all the regular and static columns. If the query is a partition level
query (no restrictions on clustering or regular columns) all the static columns will need to be fetched as
some data will need to be returned to the user if the partition has no row but some static data. For all the
other scenarios only the regular columns are required.
- in the special case of a
SELECT * query, we want to query all columns, and _fetched_ == _queried.
As this is a common case, we special case it by using a specific subclass for it.
For complex columns, this class optionally allows to specify a subset of the cells to query for each column.
We can either select individual cells by path name, or a slice of them. Note that this is a sub-selection of
_queried_ cells, so if _fetched_ != _queried_, then the cell selected by this sub-selection are considered
queried and the other ones are considered fetched (and if a column has some sub-selection, it must be a queried
column, which is actually enforced by the Builder below).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder for aColumnFilterobject.static classColumnFiltersub-class for queries with selected columns.static classstatic classstatic classColumnFiltersub-class for wildcard queries. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ColumnFilterall(TableMetadata metadata) A filter that includes all columns for the provided table.abstract booleanWhether _fetched_ == _queried_ for this filter, and so if theisQueried()methods can returnfalsefor some column/cell.static ColumnFilter.BuilderallRegularColumnsBuilder(TableMetadata metadata, boolean returnStaticContentOnPartitionWithNoRows) Returns aColumnFilterbuilder that fetches all regular columns or all columns (and queries the columns added to the builder, or everything if no column is added).abstract booleanfetchedCellIsQueried(ColumnMetadata column, CellPath path) Whether the provided complex cell (identified by its column and path), which is assumed to be _fetched_ by this filter, is also _queried_ by the user.abstract booleanfetchedColumnIsQueried(ColumnMetadata column) Whether the provided column, which is assumed to be _fetched_ by this filter (so the caller must guarantee thatfetches(column) == true, is also _queried_ by the user.abstract RegularAndStaticColumnsThe columns that needs to be fetched internally for this filter.abstract booleanfetches(ColumnMetadata column) Whether the provided column is fetched by this filter.abstract booleanfetchesAllColumns(boolean isStatic) Whether all the (regular or static) columns are fetched by this filter.booleanChecks if thisColumnFilteris for a wildcard query.abstract ColumnFilter.TesternewTester(ColumnMetadata column) Creates a newTesterto efficiently test the inclusion of cells of complex columncolumn.abstract RegularAndStaticColumnsThe columns actually queried by the user.static ColumnFilterselection(RegularAndStaticColumns columns) A filter that only fetches/queries the provided columns.static ColumnFilterselection(TableMetadata metadata, RegularAndStaticColumns queried, boolean returnStaticContentOnPartitionWithNoRows) A filter that fetches all columns for the provided table, but returns only the queried ones.static ColumnFilter.BuilderReturns aColumnFilterbuilder that only fetches the columns/cells added to the builder.protected abstract com.google.common.collect.SortedSetMultimap<ColumnIdentifier,ColumnSubselection> Returns the sub-selections ornullif there are none.abstract StringReturns the CQL string corresponding to thisColumnFilter.
-
Field Details
-
NONE
-
serializer
-
-
Constructor Details
-
ColumnFilter
public ColumnFilter()
-
-
Method Details
-
all
A filter that includes all columns for the provided table. -
selection
A filter that only fetches/queries the provided columns.Note that this shouldn't be used for CQL queries in general as all columns should be queried to preserve CQL semantic (see class javadoc). This is ok for some internal queries however (and for #6588 if/when we implement it).
-
selection
public static ColumnFilter selection(TableMetadata metadata, RegularAndStaticColumns queried, boolean returnStaticContentOnPartitionWithNoRows) A filter that fetches all columns for the provided table, but returns only the queried ones. -
fetchedColumns
The columns that needs to be fetched internally for this filter.- Returns:
- the columns to fetch for this filter.
-
queriedColumns
The columns actually queried by the user.Note that this is in general not all the columns that are fetched internally (see
fetchedColumns()). -
fetchesAllColumns
public abstract boolean fetchesAllColumns(boolean isStatic) Whether all the (regular or static) columns are fetched by this filter.Note that this method is meant as an optimization but a negative return shouldn't be relied upon strongly: this can return
falsebut still have all the columns fetches if those were manually selected by the user. The goal here is to cheaply avoid filtering things on wildcard queries, as those are common.- Parameters:
isStatic- whether to check for static columns or not. Iftrue, the method returns if all static columns are fetched, otherwise it checks regular columns.
-
allFetchedColumnsAreQueried
public abstract boolean allFetchedColumnsAreQueried()Whether _fetched_ == _queried_ for this filter, and so if theisQueried()methods can returnfalsefor some column/cell. -
fetches
Whether the provided column is fetched by this filter. -
fetchedColumnIsQueried
Whether the provided column, which is assumed to be _fetched_ by this filter (so the caller must guarantee thatfetches(column) == true, is also _queried_ by the user. !WARNING! please be sure to understand the difference between _fetched_ and _queried_ columns that this class made before using this method. If unsure, you probably want to use thefetches(org.apache.cassandra.schema.ColumnMetadata)method. -
fetchedCellIsQueried
Whether the provided complex cell (identified by its column and path), which is assumed to be _fetched_ by this filter, is also _queried_ by the user. !WARNING! please be sure to understand the difference between _fetched_ and _queried_ columns that this class made before using this method. If unsure, you probably want to use thefetches(org.apache.cassandra.schema.ColumnMetadata)method. -
newTester
Creates a newTesterto efficiently test the inclusion of cells of complex columncolumn.- Parameters:
column- for complex column for which to create a tester.- Returns:
- the created tester or
nullif all the cells from the provided column are queried.
-
isWildcard
public boolean isWildcard()Checks if thisColumnFilteris for a wildcard query.- Returns:
trueif thisColumnFilteris for a wildcard query,falseotherwise.
-
toCQLString
Returns the CQL string corresponding to thisColumnFilter.- Returns:
- the CQL string corresponding to this
ColumnFilter.
-
subSelections
protected abstract com.google.common.collect.SortedSetMultimap<ColumnIdentifier,ColumnSubselection> subSelections()Returns the sub-selections ornullif there are none.- Returns:
- the sub-selections or
nullif there are none
-
allRegularColumnsBuilder
public static ColumnFilter.Builder allRegularColumnsBuilder(TableMetadata metadata, boolean returnStaticContentOnPartitionWithNoRows) Returns aColumnFilterbuilder that fetches all regular columns or all columns (and queries the columns added to the builder, or everything if no column is added).- Parameters:
metadata- the table metadatareturnStaticContentOnPartitionWithNoRows-trueif the query must return static contents if the partition has no row,falseotherwise.
-
selectionBuilder
Returns aColumnFilterbuilder that only fetches the columns/cells added to the builder.
-