public interface OngoingSelection
SELECT count(*), sku, price...
).Modifier and Type | Method and Description |
---|---|
default Select |
add(Selector left,
Selector right)
Selects the sum of two arguments, as in
SELECT col1 + col2 . |
default Select |
all()
Selects all columns, as in
SELECT * . |
Select |
as(CqlIdentifier alias)
Aliases the last added selector, as in
SELECT count(*) AS total . |
default Select |
as(String alias)
Shortcut for
as(CqlIdentifier.fromCql(alias)) |
default Select |
cast(Selector selector,
DataType targetType)
Casts a selector to a type, as in
SELECT CAST(a AS double) . |
default Select |
column(CqlIdentifier columnId)
Selects a particular column by its CQL identifier.
|
default Select |
column(String columnName)
Shortcut for
column(CqlIdentifier.fromCql(columnName)) |
default Select |
columns(CqlIdentifier... columnIds)
Var-arg equivalent of
columnsIds(Iterable) . |
default Select |
columns(Iterable<String> columnNames)
Convenience method to select multiple simple columns at once, as in
SELECT a,b,c . |
default Select |
columns(String... columnNames)
Var-arg equivalent of
columns(Iterable) . |
default Select |
columnsIds(Iterable<CqlIdentifier> columnIds)
Convenience method to select multiple simple columns at once, as in
SELECT a,b,c . |
default Select |
countAll()
Selects the count of all returned rows, as in
SELECT count(*) . |
default Select |
divide(Selector left,
Selector right)
Selects the quotient of two arguments, as in
SELECT col1 / col2 . |
default Select |
element(CqlIdentifier collectionId,
Term index)
Shortcut for element selection when the target collection is a simple column.
|
default Select |
element(Selector collection,
Term index)
Selects an element in a collection column, as in
SELECT m['key'] . |
default Select |
element(String collectionName,
Term index)
Shortcut for
element(CqlIdentifier.fromCql(collectionName), index) . |
default Select |
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).
|
default Select |
field(Selector udt,
CqlIdentifier fieldId)
Selects a field inside of a UDT column, as in
SELECT user.name . |
default Select |
field(Selector udt,
String fieldName)
Shortcut for
field(udt,
CqlIdentifier.fromCql(fieldName)) . |
default Select |
field(String udtColumnName,
String fieldName)
|
default Select |
function(CqlIdentifier keyspaceId,
CqlIdentifier functionId,
Iterable<Selector> arguments)
Selects the result of a function call, as is
SELECT f(a,b) |
default Select |
function(CqlIdentifier keyspaceId,
CqlIdentifier functionId,
Selector... arguments)
Var-arg equivalent of
function(CqlIdentifier,CqlIdentifier, Iterable) . |
default Select |
function(CqlIdentifier functionId,
Iterable<Selector> arguments)
Selects the result of a function call, as is
SELECT f(a,b) |
default Select |
function(CqlIdentifier functionId,
Selector... arguments)
Var-arg equivalent of
function(CqlIdentifier, Iterable) . |
default Select |
function(String functionName,
Iterable<Selector> arguments)
Shortcut for
function(CqlIdentifier.fromCql(functionName), arguments) . |
default Select |
function(String functionName,
Selector... arguments)
Var-arg equivalent of
function(String, Iterable) . |
default Select |
function(String keyspaceName,
String functionName,
Iterable<Selector> arguments)
|
default Select |
function(String keyspaceName,
String functionName,
Selector... arguments)
Var-arg equivalent of
function(String, String, Iterable) . |
default Select |
listOf(Iterable<Selector> elementSelectors)
Selects a group of elements as a list, as in
SELECT [a,b,c] . |
default Select |
listOf(Selector... elementSelectors)
Var-arg equivalent of
listOf(Iterable) . |
default Select |
literal(Object value)
Selects literal value, as in
WHERE k = 1 . |
default Select |
literal(Object value,
CodecRegistry codecRegistry)
Selects a literal value, as in
WHERE k = 1 . |
default <T> Select |
literal(T value,
TypeCodec<T> codec)
Selects a literal value, as in
WHERE k = 1 . |
default Select |
mapOf(Map<Selector,Selector> elementSelectors)
Selects a group of elements as a map, as in
SELECT {a:b,c:d} . |
default Select |
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} . |
default Select |
multiply(Selector left,
Selector right)
Selects the product of two arguments, as in
SELECT col1 * col2 . |
default Select |
negate(Selector argument)
Selects the opposite of an argument, as in
SELECT -col1 . |
default Select |
range(CqlIdentifier collectionId,
Term left,
Term right)
Shortcut for slice selection when the target collection is a simple column.
|
default Select |
range(Selector collection,
Term left,
Term right)
Selects a slice in a collection column, as in
SELECT s[4..8] . |
default Select |
range(String collectionName,
Term left,
Term right)
|
default Select |
raw(String rawExpression)
Selects an arbitrary expression expressed as a raw string.
|
default Select |
remainder(Selector left,
Selector right)
Selects the remainder of two arguments, as in
SELECT col1 % col2 . |
Select |
selector(Selector selector)
Adds a selector.
|
Select |
selectors(Iterable<Selector> additionalSelectors)
Adds multiple selectors at once.
|
default Select |
selectors(Selector... additionalSelectors)
Var-arg equivalent of
selectors(Iterable) . |
default Select |
setOf(Iterable<Selector> elementSelectors)
Selects a group of elements as a set, as in
SELECT {a,b,c} . |
default Select |
setOf(Selector... elementSelectors)
Var-arg equivalent of
setOf(Iterable) . |
default Select |
subtract(Selector left,
Selector right)
Selects the difference of two terms, as in
SELECT col1 - col2 . |
default Select |
toDate(CqlIdentifier columnId)
Shortcut to select the result of the built-in
toDate function. |
default Select |
toDate(String columnName)
Shortcut for
toDate(CqlIdentifier.fromCql(columnName)) . |
default Select |
toTimestamp(CqlIdentifier columnId)
Shortcut to select the result of the built-in
toTimestamp function. |
default Select |
toTimestamp(String columnName)
Shortcut for
toTimestamp(CqlIdentifier.fromCql(columnName)) . |
default Select |
toUnixTimestamp(CqlIdentifier columnId)
Shortcut to select the result of the built-in
toUnixTimestamp function. |
default Select |
toUnixTimestamp(String columnName)
Shortcut for
toUnixTimestamp(CqlIdentifier.fromCql(columnName)) . |
default Select |
ttl(CqlIdentifier columnId)
Shortcut to select the result of the built-in
ttl function, as in SELECT
ttl(c) . |
default Select |
ttl(String columnName)
Shortcut for
ttl(CqlIdentifier.fromCql(columnName)) . |
default Select |
tupleOf(Iterable<Selector> elementSelectors)
Selects a group of elements as a tuple, as in
SELECT (a,b,c) . |
default Select |
tupleOf(Selector... elementSelectors)
Var-arg equivalent of
tupleOf(Iterable) . |
default Select |
typeHint(Selector selector,
DataType targetType)
Provides a type hint for a selector, as in
SELECT (double)1/3 . |
default Select |
writeTime(CqlIdentifier columnId)
Shortcut to select the result of the built-in
writetime function, as in SELECT
writetime(c) . |
default Select |
writeTime(String columnName)
Shortcut for
writeTime(CqlIdentifier.fromCql(columnName)) . |
@NonNull Select selector(@NonNull Selector selector)
To create the argument, use one of the factory methods in Selector
, for example
column
. This type also provides shortcuts to create and
add the selector in one call, for example column(CqlIdentifier)
for selector(Selector.column(...))
.
If you add multiple selectors as once, consider selectors(Iterable)
as a more
efficient alternative.
@NonNull Select selectors(@NonNull Iterable<Selector> additionalSelectors)
This is slightly more efficient than adding the selectors one by one (since the underlying implementation of this object is immutable).
To create the arguments, use one of the factory methods in Selector
, for example
column
.
IllegalArgumentException
- if one of the selectors is Selector.all()
(*
can only be used on its own).selector(Selector)
@NonNull default Select selectors(@NonNull Selector... additionalSelectors)
selectors(Iterable)
.@NonNull default Select all()
SELECT *
.
This will clear any previously configured selector. Similarly, if any other selector is added later, it will cancel this one.
This is a shortcut for selector(Selector.all())
.
Selector.all()
@NonNull default Select countAll()
SELECT count(*)
.
This is a shortcut for selector(Selector.countAll())
.
Selector.countAll()
@NonNull default Select column(@NonNull CqlIdentifier columnId)
This is a shortcut for selector(Selector.column(columnId))
.
Selector.column(CqlIdentifier)
@NonNull default Select column(@NonNull String columnName)
column(CqlIdentifier.fromCql(columnName))
@NonNull default Select columnsIds(@NonNull Iterable<CqlIdentifier> columnIds)
SELECT a,b,c
.
This is the same as calling column(CqlIdentifier)
for each element.
@NonNull default Select columns(@NonNull CqlIdentifier... columnIds)
columnsIds(Iterable)
.@NonNull default Select columns(@NonNull Iterable<String> columnNames)
SELECT a,b,c
.
This is the same as calling column(String)
for each element.
@NonNull default Select columns(@NonNull String... columnNames)
columns(Iterable)
.@NonNull default Select add(@NonNull Selector left, @NonNull Selector right)
SELECT col1 + col2
.
This is available in Cassandra 4 and above.
This is a shortcut for selector(Selector.add(left, right))
.
Selector.add(Selector, Selector)
@NonNull default Select subtract(@NonNull Selector left, @NonNull Selector right)
SELECT col1 - col2
.
This is available in Cassandra 4 and above.
This is a shortcut for selector(Selector.subtract(left, right))
.
Selector.subtract(Selector, Selector)
@NonNull default Select multiply(@NonNull Selector left, @NonNull Selector right)
SELECT col1 * col2
.
This is available in Cassandra 4 and above.
This is a shortcut for selector(Selector.multiply(left, right))
.
The arguments will be parenthesized if they are instances of Selector.add(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector)
or Selector.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.
Selector.multiply(Selector, Selector)
@NonNull default Select divide(@NonNull Selector left, @NonNull Selector right)
SELECT col1 / col2
.
This is available in Cassandra 4 and above.
This is a shortcut for selector(Selector.divide(left, right))
.
The arguments will be parenthesized if they are instances of Selector.add(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector)
or Selector.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.
Selector.divide(Selector, Selector)
@NonNull default Select remainder(@NonNull Selector left, @NonNull Selector right)
SELECT col1 % col2
.
This is available in Cassandra 4 and above.
This is a shortcut for selector(Selector.remainder(left,
right))
.
The arguments will be parenthesized if they are instances of Selector.add(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector)
or Selector.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.
Selector.remainder(Selector, Selector)
@NonNull default Select negate(@NonNull Selector argument)
SELECT -col1
.
This is available in Cassandra 4 and above.
This is a shortcut for selector(Selector.negate(argument))
.
The argument will be parenthesized if it is an instance of Selector.add(com.datastax.oss.driver.api.querybuilder.select.Selector, com.datastax.oss.driver.api.querybuilder.select.Selector)
or Selector.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.
Selector.negate(Selector)
@NonNull default Select field(@NonNull Selector udt, @NonNull CqlIdentifier fieldId)
SELECT user.name
.
This is a shortcut for selector(Selector.field(udt, fieldId))
.
Selector.field(Selector, CqlIdentifier)
@NonNull default Select field(@NonNull Selector udt, @NonNull String fieldName)
field(udt,
CqlIdentifier.fromCql(fieldName))
.@NonNull default Select field(@NonNull CqlIdentifier udtColumnId, @NonNull CqlIdentifier fieldId)
In other words, this is a shortcut for {field(QueryBuilder.column(udtColumnId), fieldId)
.
@NonNull default Select field(@NonNull String udtColumnName, @NonNull String fieldName)
Selector.field(String, String)
@NonNull default Select element(@NonNull Selector collection, @NonNull Term index)
SELECT m['key']
.
As of Cassandra 4, this is only allowed for map and set columns.
This is a shortcut for selector(Selector.element(collection,
index))
.
Selector.element(Selector, Term)
@NonNull default Select element(@NonNull CqlIdentifier collectionId, @NonNull Term index)
In other words, this is the equivalent of element(QueryBuilder.column(collection), index)
.
Selector.element(CqlIdentifier, Term)
@NonNull default Select element(@NonNull String collectionName, @NonNull Term index)
element(CqlIdentifier.fromCql(collectionName), index)
.Selector.element(String, Term)
@NonNull default Select 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.
This is a shortcut for selector(Selector.range(collection, left,
right))
.
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.Selector.range(Selector, Term, Term)
@NonNull default Select range(@NonNull CqlIdentifier collectionId, @Nullable Term left, @Nullable Term right)
In other words, this is the equivalent of range(Selector, Term, Term)
range(Selector.column(collectionId), left, right)}.
@NonNull default Select range(@NonNull String collectionName, @Nullable Term left, @Nullable Term right)
Selector.range(String, Term, Term)
@NonNull default Select 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).
This is a shortcut for selector(Selector.listOf(elementSelectors))
.
IllegalArgumentException
- if any of the selectors is aliased.Selector.listOf(Iterable)
@NonNull default Select listOf(@NonNull Selector... elementSelectors)
listOf(Iterable)
.@NonNull default Select 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).
This is a shortcut for selector(Selector.setOf(elementSelectors))
.
IllegalArgumentException
- if any of the selectors is aliased.Selector.setOf(Iterable)
@NonNull default Select setOf(@NonNull Selector... elementSelectors)
setOf(Iterable)
.@NonNull default Select tupleOf(@NonNull Iterable<Selector> elementSelectors)
SELECT (a,b,c)
.
None of the selectors should be aliased (the query builder checks this at runtime).
This is a shortcut for selector(Selector.tupleOf(elementSelectors))
.
IllegalArgumentException
- if any of the selectors is aliased.Selector.tupleOf(Iterable)
@NonNull default Select tupleOf(@NonNull Selector... elementSelectors)
tupleOf(Iterable)
.@NonNull default Select 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.
This is a shortcut for selector(Selector.mapOf(elementSelectors))
.
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.Selector.mapOf(Map)
@NonNull default Select mapOf(@NonNull Map<Selector,Selector> elementSelectors, @NonNull DataType keyType, @NonNull 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)
.
This is a shortcut for selector(Selector.mapOf(elementSelectors,
keyType, valueType))
.
@NonNull default Select typeHint(@NonNull Selector selector, @NonNull DataType targetType)
SELECT (double)1/3
.
Use the constants and static methods in DataTypes
to create the data type.
This is a shortcut for selector(Selector.typeHint(selector,
targetType))
.
Selector.typeHint(Selector, DataType)
@NonNull default Select 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).
This is a shortcut for selector(Selector.function(functionId,
arguments))
.
IllegalArgumentException
- if any of the selectors is aliased.Selector.function(CqlIdentifier, Iterable)
@NonNull default Select function(@NonNull CqlIdentifier functionId, @NonNull Selector... arguments)
function(CqlIdentifier, Iterable)
.@NonNull default Select function(@NonNull String functionName, @NonNull Iterable<Selector> arguments)
function(CqlIdentifier.fromCql(functionName), arguments)
.Selector.function(String, Iterable)
@NonNull default Select function(@NonNull String functionName, @NonNull Selector... arguments)
function(String, Iterable)
.Selector.function(String, Selector...)
@NonNull default Select function(@Nullable CqlIdentifier keyspaceId, @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).
This is a shortcut for selector(Selector.function(keyspaceId,
functionId, arguments))
.
IllegalArgumentException
- if any of the selectors is aliased.Selector.function(CqlIdentifier, CqlIdentifier, Iterable)
@NonNull default Select function(@Nullable CqlIdentifier keyspaceId, @NonNull CqlIdentifier functionId, @NonNull Selector... arguments)
function(CqlIdentifier,CqlIdentifier, Iterable)
.@NonNull default Select function(@Nullable String keyspaceName, @NonNull String functionName, @NonNull Iterable<Selector> arguments)
@NonNull default Select function(@Nullable String keyspaceName, @NonNull String functionName, @NonNull Selector... arguments)
function(String, String, Iterable)
.@NonNull default Select writeTime(@NonNull CqlIdentifier columnId)
writetime
function, as in SELECT
writetime(c)
.Selector.writeTime(CqlIdentifier)
@NonNull default Select writeTime(@NonNull String columnName)
writeTime(CqlIdentifier.fromCql(columnName))
.Selector.writeTime(String)
@NonNull default Select ttl(@NonNull CqlIdentifier columnId)
ttl
function, as in SELECT
ttl(c)
.Selector.ttl(CqlIdentifier)
@NonNull default Select ttl(@NonNull String columnName)
ttl(CqlIdentifier.fromCql(columnName))
.Selector.ttl(String)
@NonNull default Select 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)
.
This is a shortcut for selector(Selector.function(keyspaceId,
functionId, arguments))
.
IllegalArgumentException
- if the selector is aliased.Selector.cast(Selector, DataType)
@NonNull default Select toDate(@NonNull CqlIdentifier columnId)
toDate
function.Selector.toDate(CqlIdentifier)
@NonNull default Select toDate(@NonNull String columnName)
toDate(CqlIdentifier.fromCql(columnName))
.@NonNull default Select toTimestamp(@NonNull CqlIdentifier columnId)
toTimestamp
function.Selector.toTimestamp(CqlIdentifier)
@NonNull default Select toTimestamp(@NonNull String columnName)
toTimestamp(CqlIdentifier.fromCql(columnName))
.@NonNull default Select toUnixTimestamp(@NonNull CqlIdentifier columnId)
toUnixTimestamp
function.Selector.toUnixTimestamp(CqlIdentifier)
@NonNull default Select toUnixTimestamp(@NonNull String columnName)
toUnixTimestamp(CqlIdentifier.fromCql(columnName))
.@NonNull default Select literal(@Nullable Object value)
WHERE k = 1
.
This method can process any type for which there is a default Java to CQL mapping, namely:
primitive types (Integer=>int, Long=>bigint, String=>text, etc.
), and collections,
tuples, and user defined types thereof.
A null argument will be rendered as NULL
.
For custom mappings, use literal(Object, CodecRegistry)
or literal(Object,
TypeCodec)
.
CodecNotFoundException
- if there is no default CQL mapping for the Java type of value
.QueryBuilder.literal(Object)
@NonNull default Select literal(@Nullable Object value, @NonNull CodecRegistry codecRegistry)
WHERE k = 1
.
This is an alternative to literal(Object)
for custom type mappings. The provided
registry should contain a codec that can format the value. Typically, this will be your
session's registry, which is accessible via session.getContext().getCodecRegistry()
.
CodecNotFoundException
- if codecRegistry
does not contain any codec that can
handle value
.AttachmentPoint.getCodecRegistry()
,
QueryBuilder.literal(Object, CodecRegistry)
@NonNull default <T> Select literal(@Nullable T value, @Nullable TypeCodec<T> codec)
WHERE k = 1
.
This is an alternative to literal(Object)
for custom type mappings. The value will
be turned into a string with TypeCodec.format(Object)
, and inlined in the query.
QueryBuilder.literal(Object, TypeCodec)
@NonNull default Select raw(@NonNull String rawExpression)
The contents will be appended to the query as-is, without any syntax checking or escaping. This method should be used with caution, as it's possible to generate invalid CQL that will fail at execution time; on the other hand, it can be used as a workaround to handle new CQL features that are not yet covered by the query builder.
This is a shortcut for selector(QueryBuilder.raw(rawExpression))
.
@NonNull Select as(@NonNull CqlIdentifier alias)
SELECT count(*) AS total
.
It is the caller's responsibility to ensure that this method is called at most once after each selector, and that this selector can legally be aliased:
countAll().as("total1").as("total2")
), the last
alias will override the previous ones.
all()
, an IllegalStateException
is thrown.
raw(String)
selector that already defines an alias, the
query will fail at runtime.
@NonNull default Select as(@NonNull String alias)
as(CqlIdentifier.fromCql(alias))
Copyright © 2017–2022. All rights reserved.