public interface Selector extends CqlSnippet
To build instances of this type, use the factory methods, such as column
, function
, etc.
They are used as arguments to the selectors
method, for example:
selectFrom("foo").selectors(Selector.column("bar"), Selector.column("baz"))
// SELECT bar,baz FROM foo
There 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
Modifier and Type | Method and Description |
---|---|
static Selector |
add(Selector left,
Selector right)
Selects the sum of two arguments, as in
SELECT col1 + col2 . |
static Selector |
all()
Selects all columns, as in
SELECT * . |
Selector |
as(CqlIdentifier alias)
Aliases the selector, as in
SELECT count(*) AS total . |
default Selector |
as(String alias)
Shortcut for
as(CqlIdentifier.fromCql(alias)) |
static Selector |
cast(Selector selector,
DataType targetType)
Casts a selector to a type, as in
SELECT CAST(a AS double) . |
static Selector |
column(CqlIdentifier columnId)
Selects a particular column by its CQL identifier.
|
static Selector |
column(String columnName)
Shortcut for
column(CqlIdentifier.fromCql(columnName)) |
static Selector |
countAll()
Selects the count of all returned rows, as in
SELECT count(*) . |
static Selector |
divide(Selector left,
Selector right)
Selects the quotient of two arguments, as in
SELECT col1 / col2 . |
static Selector |
element(CqlIdentifier collectionId,
Term index)
Shortcut for element selection when the target collection is a simple column.
|
static Selector |
element(Selector collection,
Term index)
Selects an element in a collection column, as in
SELECT m['key'] . |
static Selector |
element(String collectionName,
Term index)
Shortcut for
element(CqlIdentifier.fromCql(collectionName), index) . |
static Selector |
field(CqlIdentifier udtColumnId,
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 Selector |
field(Selector udt,
CqlIdentifier fieldId)
Selects a field inside of a UDT column, as in
SELECT user.name . |
static Selector |
field(Selector udt,
String fieldName)
Shortcut for
getUdtField(udt,
CqlIdentifier.fromCql(fieldName)) . |
static Selector |
field(String udtColumnName,
String fieldName)
|
static Selector |
function(CqlIdentifier keyspaceId,
CqlIdentifier functionId,
Iterable<Selector> arguments)
Selects the result of a function call, as is
SELECT ks.f(a,b) |
static Selector |
function(CqlIdentifier keyspaceId,
CqlIdentifier functionId,
Selector... arguments)
Var-arg equivalent of
function(CqlIdentifier, CqlIdentifier, Iterable) . |
static Selector |
function(CqlIdentifier functionId,
Iterable<Selector> arguments)
Selects the result of a function call, as is
SELECT f(a,b) |
static Selector |
function(CqlIdentifier functionId,
Selector... arguments)
Var-arg equivalent of
function(CqlIdentifier, Iterable) . |
static Selector |
function(String functionName,
Iterable<Selector> arguments)
Shortcut for
function(CqlIdentifier.fromCql(functionName), arguments) . |
static Selector |
function(String functionName,
Selector... arguments)
Var-arg equivalent of
function(String, Iterable) . |
static Selector |
function(String keyspaceName,
String functionName,
Iterable<Selector> arguments)
Shortcut for
function(CqlIdentifier, CqlIdentifier, Iterable)
function(CqlIdentifier.fromCql(functionName), arguments)}. |
static Selector |
function(String keyspaceName,
String functionName,
Selector... arguments)
Var-arg equivalent of
function(String, String, Iterable) . |
CqlIdentifier |
getAlias() |
static Selector |
listOf(Iterable<Selector> elementSelectors)
Selects a group of elements as a list, as in
SELECT [a,b,c] . |
static Selector |
listOf(Selector... elementSelectors)
Var-arg equivalent of
listOf(Iterable) . |
static Selector |
mapOf(Map<Selector,Selector> elementSelectors)
Selects a group of elements as a map, as in
SELECT {a:b,c:d} . |
static Selector |
mapOf(Map<Selector,Selector> elementSelectors,
DataType keyType,
DataType valueType)
Selects a group of elements as a map and force the resulting map type, as in
SELECT
(map<int,text>){a:b,c:d} . |
static Selector |
multiply(Selector left,
Selector right)
Selects the product of two arguments, as in
SELECT col1 * col2 . |
static Selector |
negate(Selector argument)
Selects the opposite of an argument, as in
SELECT -col1 . |
static Selector |
range(CqlIdentifier collectionId,
Term left,
Term right)
Shortcut for slice selection when the target collection is a simple column.
|
static Selector |
range(Selector collection,
Term left,
Term right)
Selects a slice in a collection column, as in
SELECT s[4..8] . |
static Selector |
range(String collectionName,
Term left,
Term right)
|
static Selector |
remainder(Selector left,
Selector right)
Selects the remainder of two arguments, as in
SELECT col1 % col2 . |
static Selector |
setOf(Iterable<Selector> elementSelectors)
Selects a group of elements as a set, as in
SELECT {a,b,c} . |
static Selector |
setOf(Selector... elementSelectors)
Var-arg equivalent of
setOf(Iterable) . |
static Selector |
subtract(Selector left,
Selector right)
Selects the difference of two arguments, as in
SELECT col1 - col2 . |
static Selector |
toDate(CqlIdentifier columnId)
Shortcut to select the result of the built-in
toDate function on a simple column. |
static Selector |
toDate(String columnName)
Shortcut for
toDate(CqlIdentifier.fromCql(columnName)) . |
static Selector |
toTimestamp(CqlIdentifier columnId)
Shortcut to select the result of the built-in
toTimestamp function on a simple column. |
static Selector |
toTimestamp(String columnName)
Shortcut for
toTimestamp(CqlIdentifier.fromCql(columnName)) . |
static Selector |
toUnixTimestamp(CqlIdentifier columnId)
Shortcut to select the result of the built-in
toUnixTimestamp function on a simple
column. |
static Selector |
toUnixTimestamp(String columnName)
Shortcut for
toUnixTimestamp(CqlIdentifier.fromCql(columnName)) . |
static Selector |
ttl(CqlIdentifier columnId)
Shortcut to select the result of the built-in
ttl function, as in SELECT
ttl(c) . |
static Selector |
ttl(String columnName)
Shortcut for
ttl(CqlIdentifier.fromCql(columnName)) . |
static Selector |
tupleOf(Iterable<Selector> elementSelectors)
Selects a group of elements as a tuple, as in
SELECT (a,b,c) . |
static Selector |
tupleOf(Selector... elementSelectors)
Var-arg equivalent of
tupleOf(Iterable) . |
static Selector |
typeHint(Selector selector,
DataType targetType)
Provides a type hint for a selector, as in
SELECT (double)1/3 . |
static Selector |
writeTime(CqlIdentifier columnId)
Shortcut to select the result of the built-in
writetime function, as in SELECT
writetime(c) . |
static Selector |
writeTime(String columnName)
Shortcut for
writeTime(CqlIdentifier.fromCql(columnName)) . |
appendTo
@NonNull static Selector all()
SELECT *
.@NonNull static Selector countAll()
SELECT count(*)
.@NonNull static Selector column(@NonNull CqlIdentifier columnId)
@NonNull static Selector column(@NonNull String columnName)
column(CqlIdentifier.fromCql(columnName))
@NonNull static Selector add(@NonNull Selector left, @NonNull Selector right)
SELECT col1 + col2
.
This is available in Cassandra 4 and above.
@NonNull static Selector subtract(@NonNull Selector left, @NonNull Selector right)
SELECT col1 - col2
.
This is available in Cassandra 4 and above.
@NonNull static Selector multiply(@NonNull Selector left, @NonNull Selector right)
SELECT 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)
or subtract(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.
@NonNull static Selector divide(@NonNull Selector left, @NonNull Selector right)
SELECT 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)
or subtract(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.
@NonNull static Selector remainder(@NonNull Selector left, @NonNull Selector right)
SELECT 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)
or subtract(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.
@NonNull static Selector negate(@NonNull Selector argument)
SELECT -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)
or subtract(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.
@NonNull static Selector field(@NonNull Selector udt, @NonNull CqlIdentifier fieldId)
SELECT user.name
.@NonNull static Selector field(@NonNull Selector udt, @NonNull String fieldName)
getUdtField(udt,
CqlIdentifier.fromCql(fieldName))
.@NonNull static Selector field(@NonNull CqlIdentifier udtColumnId, @NonNull CqlIdentifier fieldId)
@NonNull static Selector element(@NonNull Selector collection, @NonNull Term index)
SELECT m['key']
.
As of Cassandra 4, this is only allowed in SELECT for map and set columns. DELETE accepts list elements as well.
@NonNull static Selector element(@NonNull CqlIdentifier collectionId, @NonNull Term index)
In other words, this is the equivalent of element(column(collectionId), index)
.
@NonNull static Selector element(@NonNull String collectionName, @NonNull Term index)
element(CqlIdentifier.fromCql(collectionName), index)
.@NonNull static Selector range(@NonNull Selector collection, @Nullable Term left, @Nullable Term right)
SELECT 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.
left
- the left bound (inclusive). Can be null
to indicate that the slice is only
right-bound.right
- the right bound (inclusive). Can be null
to indicate that the slice is
only left-bound.@NonNull static Selector range(@NonNull CqlIdentifier collectionId, @Nullable Term left, @Nullable Term right)
In other words, this is the equivalent of range(Selector, Term, Term)
range(column(collectionId), left, right)}.
@NonNull static Selector range(@NonNull String collectionName, @Nullable Term left, @Nullable Term right)
@NonNull static Selector listOf(@NonNull Iterable<Selector> elementSelectors)
SELECT [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).
IllegalArgumentException
- if any of the selectors is aliased.@NonNull static Selector listOf(@NonNull Selector... elementSelectors)
listOf(Iterable)
.@NonNull static Selector setOf(@NonNull Iterable<Selector> elementSelectors)
SELECT {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).
IllegalArgumentException
- if any of the selectors is aliased.@NonNull static Selector setOf(@NonNull Selector... elementSelectors)
setOf(Iterable)
.@NonNull static Selector tupleOf(@NonNull Iterable<Selector> elementSelectors)
SELECT (a,b,c)
.
None of the selectors should be aliased (the query builder checks this at runtime).
IllegalArgumentException
- if any of the selectors is aliased.@NonNull static Selector tupleOf(@NonNull Selector... elementSelectors)
tupleOf(Iterable)
.@NonNull static Selector mapOf(@NonNull Map<Selector,Selector> elementSelectors)
SELECT {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 with
mapOf(Map, DataType,
DataType)
.IllegalArgumentException
- if any of the selectors is aliased.@NonNull static Selector mapOf(@NonNull Map<Selector,Selector> elementSelectors, @Nullable DataType keyType, @Nullable DataType valueType)
SELECT
(map<int,text>){a:b,c:d}
.
To create the data types, use the constants and static methods in DataTypes
, or
QueryBuilder.udt(CqlIdentifier)
.
mapOf(Map)
@NonNull static Selector typeHint(@NonNull Selector selector, @NonNull DataType targetType)
SELECT (double)1/3
.
To create the data type, use the constants and static methods in DataTypes
, or
QueryBuilder.udt(CqlIdentifier)
.
@NonNull static Selector function(@NonNull CqlIdentifier functionId, @NonNull Iterable<Selector> arguments)
SELECT f(a,b)
None of the arguments should be aliased (the query builder checks this at runtime).
IllegalArgumentException
- if any of the selectors is aliased.@NonNull static Selector function(@NonNull CqlIdentifier functionId, @NonNull Selector... arguments)
function(CqlIdentifier, Iterable)
.@NonNull static Selector function(@NonNull String functionName, @NonNull Iterable<Selector> arguments)
function(CqlIdentifier.fromCql(functionName), arguments)
.@NonNull static Selector function(@NonNull String functionName, @NonNull Selector... arguments)
function(String, Iterable)
.@NonNull static Selector function(@Nullable CqlIdentifier keyspaceId, @NonNull CqlIdentifier functionId, @NonNull Iterable<Selector> arguments)
SELECT ks.f(a,b)
None of the arguments should be aliased (the query builder checks this at runtime).
IllegalArgumentException
- if any of the selectors is aliased.@NonNull static Selector function(@Nullable CqlIdentifier keyspaceId, @NonNull CqlIdentifier functionId, @NonNull Selector... arguments)
function(CqlIdentifier, CqlIdentifier, Iterable)
.@NonNull static Selector function(@Nullable String keyspaceName, @NonNull String functionName, @NonNull Iterable<Selector> arguments)
function(CqlIdentifier, CqlIdentifier, Iterable)
function(CqlIdentifier.fromCql(functionName), arguments)}.@NonNull static Selector function(@Nullable String keyspaceName, @NonNull String functionName, @NonNull Selector... arguments)
function(String, String, Iterable)
.@NonNull static Selector writeTime(@NonNull CqlIdentifier columnId)
writetime
function, as in SELECT
writetime(c)
.@NonNull static Selector writeTime(@NonNull String columnName)
writeTime(CqlIdentifier.fromCql(columnName))
.@NonNull static Selector ttl(@NonNull CqlIdentifier columnId)
ttl
function, as in SELECT
ttl(c)
.@NonNull static Selector ttl(@NonNull String columnName)
ttl(CqlIdentifier.fromCql(columnName))
.@NonNull static Selector cast(@NonNull Selector selector, @NonNull DataType targetType)
SELECT CAST(a AS double)
.
To create the data type, use the constants and static methods in DataTypes
, or
QueryBuilder.udt(CqlIdentifier)
.
IllegalArgumentException
- if the selector is aliased.@NonNull static Selector toDate(@NonNull CqlIdentifier columnId)
toDate
function on a simple column.@NonNull static Selector toDate(@NonNull String columnName)
toDate(CqlIdentifier.fromCql(columnName))
.@NonNull static Selector toTimestamp(@NonNull CqlIdentifier columnId)
toTimestamp
function on a simple column.@NonNull static Selector toTimestamp(@NonNull String columnName)
toTimestamp(CqlIdentifier.fromCql(columnName))
.@NonNull static Selector toUnixTimestamp(@NonNull CqlIdentifier columnId)
toUnixTimestamp
function on a simple
column.@NonNull static Selector toUnixTimestamp(@NonNull String columnName)
toUnixTimestamp(CqlIdentifier.fromCql(columnName))
.@NonNull Selector as(@NonNull CqlIdentifier alias)
SELECT count(*) AS total
.@NonNull default Selector as(@NonNull String alias)
as(CqlIdentifier.fromCql(alias))
@Nullable CqlIdentifier getAlias()
Copyright © 2017–2023. All rights reserved.