Interface Selector
-
- All Superinterfaces:
CqlSnippet
public interface Selector extends CqlSnippet
A selected element in a SELECT query.To build instances of this type, use the factory methods, such as
column,function, etc.They are used as arguments to the
selectorsmethod, for example:selectFrom("foo").selectors(Selector.column("bar"), Selector.column("baz")) // SELECT bar,baz FROM fooThere are also shortcuts in the fluent API when you build a statement, for example:
selectFrom("foo").column("bar").column("baz") // SELECT bar,baz FROM foo
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static Selectoradd(Selector left, Selector right)Selects the sum of two arguments, as inSELECT col1 + col2.static Selectorall()Selects all columns, as inSELECT *.Selectoras(com.datastax.oss.driver.api.core.CqlIdentifier alias)Aliases the selector, as inSELECT count(*) AS total.default Selectoras(String alias)Shortcut foras(CqlIdentifier.fromCql(alias))static Selectorcast(Selector selector, com.datastax.oss.driver.api.core.type.DataType targetType)Casts a selector to a type, as inSELECT CAST(a AS double).static Selectorcolumn(com.datastax.oss.driver.api.core.CqlIdentifier columnId)Selects a particular column by its CQL identifier.static Selectorcolumn(String columnName)Shortcut forcolumn(CqlIdentifier.fromCql(columnName))static SelectorcountAll()Selects the count of all returned rows, as inSELECT count(*).static Selectordivide(Selector left, Selector right)Selects the quotient of two arguments, as inSELECT col1 / col2.static Selectorelement(com.datastax.oss.driver.api.core.CqlIdentifier collectionId, Term index)Shortcut for element selection when the target collection is a simple column.static Selectorelement(Selector collection, Term index)Selects an element in a collection column, as inSELECT m['key'].static Selectorelement(String collectionName, Term index)Shortcut forelement(CqlIdentifier.fromCql(collectionName), index).static Selectorfield(com.datastax.oss.driver.api.core.CqlIdentifier udtColumnId, com.datastax.oss.driver.api.core.CqlIdentifier fieldId)Shortcut to select a UDT field when the UDT is a simple column (as opposed to a more complex selection, like a nested UDT).static Selectorfield(Selector udt, com.datastax.oss.driver.api.core.CqlIdentifier fieldId)Selects a field inside of a UDT column, as inSELECT user.name.static Selectorfield(Selector udt, String fieldName)Shortcut forgetUdtField(udt, CqlIdentifier.fromCql(fieldName)).static Selectorfield(String udtColumnName, String fieldName)static Selectorfunction(com.datastax.oss.driver.api.core.CqlIdentifier keyspaceId, com.datastax.oss.driver.api.core.CqlIdentifier functionId, Selector... arguments)Var-arg equivalent offunction(CqlIdentifier, CqlIdentifier, Iterable).static Selectorfunction(com.datastax.oss.driver.api.core.CqlIdentifier keyspaceId, com.datastax.oss.driver.api.core.CqlIdentifier functionId, Iterable<Selector> arguments)Selects the result of a function call, as isSELECT ks.f(a,b)static Selectorfunction(com.datastax.oss.driver.api.core.CqlIdentifier functionId, Selector... arguments)Var-arg equivalent offunction(CqlIdentifier, Iterable).static Selectorfunction(com.datastax.oss.driver.api.core.CqlIdentifier functionId, Iterable<Selector> arguments)Selects the result of a function call, as isSELECT f(a,b)static Selectorfunction(String functionName, Selector... arguments)Var-arg equivalent offunction(String, Iterable).static Selectorfunction(String functionName, Iterable<Selector> arguments)Shortcut forfunction(CqlIdentifier.fromCql(functionName), arguments).static Selectorfunction(String keyspaceName, String functionName, Selector... arguments)Var-arg equivalent offunction(String, String, Iterable).static Selectorfunction(String keyspaceName, String functionName, Iterable<Selector> arguments)Shortcut forfunction(CqlIdentifier, CqlIdentifier, Iterable)function(CqlIdentifier.fromCql(functionName), arguments)}.com.datastax.oss.driver.api.core.CqlIdentifiergetAlias()static SelectorlistOf(Selector... elementSelectors)Var-arg equivalent oflistOf(Iterable).static SelectorlistOf(Iterable<Selector> elementSelectors)Selects a group of elements as a list, as inSELECT [a,b,c].static SelectormapOf(Map<Selector,Selector> elementSelectors)Selects a group of elements as a map, as inSELECT {a:b,c:d}.static SelectormapOf(Map<Selector,Selector> elementSelectors, com.datastax.oss.driver.api.core.type.DataType keyType, com.datastax.oss.driver.api.core.type.DataType valueType)Selects a group of elements as a map and force the resulting map type, as inSELECT (map<int,text>){a:b,c:d}.static Selectormultiply(Selector left, Selector right)Selects the product of two arguments, as inSELECT col1 * col2.static Selectornegate(Selector argument)Selects the opposite of an argument, as inSELECT -col1.static Selectorrange(com.datastax.oss.driver.api.core.CqlIdentifier collectionId, Term left, Term right)Shortcut for slice selection when the target collection is a simple column.static Selectorrange(Selector collection, Term left, Term right)Selects a slice in a collection column, as inSELECT s[4..8].static Selectorrange(String collectionName, Term left, Term right)static Selectorremainder(Selector left, Selector right)Selects the remainder of two arguments, as inSELECT col1 % col2.static SelectorsetOf(Selector... elementSelectors)Var-arg equivalent ofsetOf(Iterable).static SelectorsetOf(Iterable<Selector> elementSelectors)Selects a group of elements as a set, as inSELECT {a,b,c}.static Selectorsubtract(Selector left, Selector right)Selects the difference of two arguments, as inSELECT col1 - col2.static SelectortoDate(com.datastax.oss.driver.api.core.CqlIdentifier columnId)Shortcut to select the result of the built-intoDatefunction on a simple column.static SelectortoDate(String columnName)Shortcut fortoDate(CqlIdentifier.fromCql(columnName)).static SelectortoTimestamp(com.datastax.oss.driver.api.core.CqlIdentifier columnId)Shortcut to select the result of the built-intoTimestampfunction on a simple column.static SelectortoTimestamp(String columnName)Shortcut fortoTimestamp(CqlIdentifier.fromCql(columnName)).static SelectortoUnixTimestamp(com.datastax.oss.driver.api.core.CqlIdentifier columnId)Shortcut to select the result of the built-intoUnixTimestampfunction on a simple column.static SelectortoUnixTimestamp(String columnName)Shortcut fortoUnixTimestamp(CqlIdentifier.fromCql(columnName)).static Selectorttl(com.datastax.oss.driver.api.core.CqlIdentifier columnId)Shortcut to select the result of the built-inttlfunction, as inSELECT ttl(c).static Selectorttl(String columnName)Shortcut forttl(CqlIdentifier.fromCql(columnName)).static SelectortupleOf(Selector... elementSelectors)Var-arg equivalent oftupleOf(Iterable).static SelectortupleOf(Iterable<Selector> elementSelectors)Selects a group of elements as a tuple, as inSELECT (a,b,c).static SelectortypeHint(Selector selector, com.datastax.oss.driver.api.core.type.DataType targetType)Provides a type hint for a selector, as inSELECT (double)1/3.static SelectorwriteTime(com.datastax.oss.driver.api.core.CqlIdentifier columnId)Shortcut to select the result of the built-inwritetimefunction, as inSELECT writetime(c).static SelectorwriteTime(String columnName)Shortcut forwriteTime(CqlIdentifier.fromCql(columnName)).-
Methods inherited from interface com.datastax.oss.driver.api.querybuilder.CqlSnippet
appendTo
-
-
-
-
Method Detail
-
all
@NonNull static Selector all()
Selects all columns, as inSELECT *.
-
countAll
@NonNull static Selector countAll()
Selects the count of all returned rows, as inSELECT count(*).
-
column
@NonNull static Selector column(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier columnId)
Selects a particular column by its CQL identifier.
-
column
@NonNull static Selector column(@NonNull String columnName)
Shortcut forcolumn(CqlIdentifier.fromCql(columnName))
-
add
@NonNull static Selector add(@NonNull Selector left, @NonNull Selector right)
Selects the sum of two arguments, as inSELECT col1 + col2.This is available in Cassandra 4 and above.
-
subtract
@NonNull static Selector subtract(@NonNull Selector left, @NonNull Selector right)
Selects the difference of two arguments, as inSELECT col1 - col2.This is available in Cassandra 4 and above.
-
multiply
@NonNull static Selector multiply(@NonNull Selector left, @NonNull Selector right)
Selects the product of two arguments, as inSELECT col1 * col2.This is available in Cassandra 4 and above.
The arguments will be parenthesized if they are instances of
add(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector)orsubtract(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector). If they are raw selectors, you might have to parenthesize them yourself.
-
divide
@NonNull static Selector divide(@NonNull Selector left, @NonNull Selector right)
Selects the quotient of two arguments, as inSELECT col1 / col2.This is available in Cassandra 4 and above.
The arguments will be parenthesized if they are instances of
add(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector)orsubtract(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector). If they are raw selectors, you might have to parenthesize them yourself.
-
remainder
@NonNull static Selector remainder(@NonNull Selector left, @NonNull Selector right)
Selects the remainder of two arguments, as inSELECT col1 % col2.This is available in Cassandra 4 and above.
The arguments will be parenthesized if they are instances of
add(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector)orsubtract(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector). If they are raw selectors, you might have to parenthesize them yourself.
-
negate
@NonNull static Selector negate(@NonNull Selector argument)
Selects the opposite of an argument, as inSELECT -col1.This is available in Cassandra 4 and above.
The argument will be parenthesized if it is an instance of
add(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector)orsubtract(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector). If it is a raw selector, you might have to parenthesize it yourself.
-
field
@NonNull static Selector field(@NonNull Selector udt, @NonNull com.datastax.oss.driver.api.core.CqlIdentifier fieldId)
Selects a field inside of a UDT column, as inSELECT user.name.
-
field
@NonNull static Selector field(@NonNull Selector udt, @NonNull String fieldName)
Shortcut forgetUdtField(udt, CqlIdentifier.fromCql(fieldName)).
-
field
@NonNull static Selector field(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier udtColumnId, @NonNull com.datastax.oss.driver.api.core.CqlIdentifier fieldId)
Shortcut to select a UDT field when the UDT is a simple column (as opposed to a more complex selection, like a nested UDT).
-
element
@NonNull static Selector element(@NonNull Selector collection, @NonNull Term index)
Selects an element in a collection column, as inSELECT m['key'].As of Cassandra 4, this is only allowed in SELECT for map and set columns. DELETE accepts list elements as well.
-
element
@NonNull static Selector element(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier collectionId, @NonNull Term index)
Shortcut for element selection when the target collection is a simple column.In other words, this is the equivalent of
element(column(collectionId), index).
-
element
@NonNull static Selector element(@NonNull String collectionName, @NonNull Term index)
Shortcut forelement(CqlIdentifier.fromCql(collectionName), index).
-
range
@NonNull static Selector range(@NonNull Selector collection, @Nullable Term left, @Nullable Term right)
Selects a slice in a collection column, as inSELECT s[4..8].As of Cassandra 4, this is only allowed for set and map columns. Those collections are ordered, the elements (or keys in the case of a map), will be compared to the bounds for inclusions. Either bound can be unspecified, but not both.
- Parameters:
left- the left bound (inclusive). Can benullto indicate that the slice is only right-bound.right- the right bound (inclusive). Can benullto indicate that the slice is only left-bound.
-
range
@NonNull static Selector range(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier collectionId, @Nullable Term left, @Nullable Term right)
Shortcut for slice selection when the target collection is a simple column.In other words, this is the equivalent of
range(Selector, Term, Term)range(column(collectionId), left, right)}.
-
range
@NonNull static Selector range(@NonNull String collectionName, @Nullable Term left, @Nullable Term right)
-
listOf
@NonNull static Selector listOf(@NonNull Iterable<Selector> elementSelectors)
Selects a group of elements as a list, as inSELECT [a,b,c].None of the selectors should be aliased (the query builder checks this at runtime), and they should all produce the same data type (the query builder can't check this, so the query will fail at execution time).
- Throws:
IllegalArgumentException- if any of the selectors is aliased.
-
listOf
@NonNull static Selector listOf(@NonNull Selector... elementSelectors)
Var-arg equivalent oflistOf(Iterable).
-
setOf
@NonNull static Selector setOf(@NonNull Iterable<Selector> elementSelectors)
Selects a group of elements as a set, as inSELECT {a,b,c}.None of the selectors should be aliased (the query builder checks this at runtime), and they should all produce the same data type (the query builder can't check this, so the query will fail at execution time).
- Throws:
IllegalArgumentException- if any of the selectors is aliased.
-
setOf
@NonNull static Selector setOf(@NonNull Selector... elementSelectors)
Var-arg equivalent ofsetOf(Iterable).
-
tupleOf
@NonNull static Selector tupleOf(@NonNull Iterable<Selector> elementSelectors)
Selects a group of elements as a tuple, as inSELECT (a,b,c).None of the selectors should be aliased (the query builder checks this at runtime).
- Throws:
IllegalArgumentException- if any of the selectors is aliased.
-
tupleOf
@NonNull static Selector tupleOf(@NonNull Selector... elementSelectors)
Var-arg equivalent oftupleOf(Iterable).
-
mapOf
@NonNull static Selector mapOf(@NonNull Map<Selector,Selector> elementSelectors)
Selects a group of elements as a map, as inSELECT {a:b,c:d}.None of the selectors should be aliased (the query builder checks this at runtime). In addition, all key selectors should produce the same type, and all value selectors as well (the key and value types can be different); the query builder can't check this, so the query will fail at execution time if the types are not uniform.
Note that Cassandra often has trouble inferring the exact map type. This will manifest as the error message:
Cannot infer type for term xxx in selection clause (try using a cast to force a type)
If you run into this, consider providing the types explicitly withmapOf(Map, DataType, DataType).- Throws:
IllegalArgumentException- if any of the selectors is aliased.
-
mapOf
@NonNull static Selector mapOf(@NonNull Map<Selector,Selector> elementSelectors, @Nullable com.datastax.oss.driver.api.core.type.DataType keyType, @Nullable com.datastax.oss.driver.api.core.type.DataType valueType)
Selects a group of elements as a map and force the resulting map type, as inSELECT (map<int,text>){a:b,c:d}.To create the data types, use the constants and static methods in
DataTypes, orQueryBuilder.udt(CqlIdentifier).- See Also:
mapOf(Map)
-
typeHint
@NonNull static Selector typeHint(@NonNull Selector selector, @NonNull com.datastax.oss.driver.api.core.type.DataType targetType)
Provides a type hint for a selector, as inSELECT (double)1/3.To create the data type, use the constants and static methods in
DataTypes, orQueryBuilder.udt(CqlIdentifier).
-
function
@NonNull static Selector function(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier functionId, @NonNull Iterable<Selector> arguments)
Selects the result of a function call, as isSELECT f(a,b)None of the arguments should be aliased (the query builder checks this at runtime).
- Throws:
IllegalArgumentException- if any of the selectors is aliased.
-
function
@NonNull static Selector function(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier functionId, @NonNull Selector... arguments)
Var-arg equivalent offunction(CqlIdentifier, Iterable).
-
function
@NonNull static Selector function(@NonNull String functionName, @NonNull Iterable<Selector> arguments)
Shortcut forfunction(CqlIdentifier.fromCql(functionName), arguments).
-
function
@NonNull static Selector function(@NonNull String functionName, @NonNull Selector... arguments)
Var-arg equivalent offunction(String, Iterable).
-
function
@NonNull static Selector function(@Nullable com.datastax.oss.driver.api.core.CqlIdentifier keyspaceId, @NonNull com.datastax.oss.driver.api.core.CqlIdentifier functionId, @NonNull Iterable<Selector> arguments)
Selects the result of a function call, as isSELECT ks.f(a,b)None of the arguments should be aliased (the query builder checks this at runtime).
- Throws:
IllegalArgumentException- if any of the selectors is aliased.
-
function
@NonNull static Selector function(@Nullable com.datastax.oss.driver.api.core.CqlIdentifier keyspaceId, @NonNull com.datastax.oss.driver.api.core.CqlIdentifier functionId, @NonNull Selector... arguments)
Var-arg equivalent offunction(CqlIdentifier, CqlIdentifier, Iterable).
-
function
@NonNull static Selector function(@Nullable String keyspaceName, @NonNull String functionName, @NonNull Iterable<Selector> arguments)
Shortcut forfunction(CqlIdentifier, CqlIdentifier, Iterable)function(CqlIdentifier.fromCql(functionName), arguments)}.
-
function
@NonNull static Selector function(@Nullable String keyspaceName, @NonNull String functionName, @NonNull Selector... arguments)
Var-arg equivalent offunction(String, String, Iterable).
-
writeTime
@NonNull static Selector writeTime(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier columnId)
Shortcut to select the result of the built-inwritetimefunction, as inSELECT writetime(c).
-
writeTime
@NonNull static Selector writeTime(@NonNull String columnName)
Shortcut forwriteTime(CqlIdentifier.fromCql(columnName)).
-
ttl
@NonNull static Selector ttl(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier columnId)
Shortcut to select the result of the built-inttlfunction, as inSELECT ttl(c).
-
ttl
@NonNull static Selector ttl(@NonNull String columnName)
Shortcut forttl(CqlIdentifier.fromCql(columnName)).
-
cast
@NonNull static Selector cast(@NonNull Selector selector, @NonNull com.datastax.oss.driver.api.core.type.DataType targetType)
Casts a selector to a type, as inSELECT CAST(a AS double).To create the data type, use the constants and static methods in
DataTypes, orQueryBuilder.udt(CqlIdentifier).- Throws:
IllegalArgumentException- if the selector is aliased.
-
toDate
@NonNull static Selector toDate(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier columnId)
Shortcut to select the result of the built-intoDatefunction on a simple column.
-
toDate
@NonNull static Selector toDate(@NonNull String columnName)
Shortcut fortoDate(CqlIdentifier.fromCql(columnName)).
-
toTimestamp
@NonNull static Selector toTimestamp(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier columnId)
Shortcut to select the result of the built-intoTimestampfunction on a simple column.
-
toTimestamp
@NonNull static Selector toTimestamp(@NonNull String columnName)
Shortcut fortoTimestamp(CqlIdentifier.fromCql(columnName)).
-
toUnixTimestamp
@NonNull static Selector toUnixTimestamp(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier columnId)
Shortcut to select the result of the built-intoUnixTimestampfunction on a simple column.
-
toUnixTimestamp
@NonNull static Selector toUnixTimestamp(@NonNull String columnName)
Shortcut fortoUnixTimestamp(CqlIdentifier.fromCql(columnName)).
-
as
@NonNull Selector as(@NonNull com.datastax.oss.driver.api.core.CqlIdentifier alias)
Aliases the selector, as inSELECT count(*) AS total.
-
as
@NonNull default Selector as(@NonNull String alias)
Shortcut foras(CqlIdentifier.fromCql(alias))
-
getAlias
@Nullable com.datastax.oss.driver.api.core.CqlIdentifier getAlias()
- Returns:
- null if the selector is not aliased.
-
-