public final class QueryBuilder extends Object
Statement.getRoutingKey(com.datastax.driver.core.ProtocolVersion, com.datastax.driver.core.CodecRegistry)
method only when a
TableMetadata
is provided to the builder.
It is thus advised to do so if a TokenAwarePolicy
is in use.
The provider builders perform very little validation of the built query.
There is thus no guarantee that a built query is valid, and it is
definitively possible to create invalid queries.
Note that it could be convenient to use an 'import static' to bring the static methods of
this class into scope.Modifier and Type | Method and Description |
---|---|
static Assignment |
add(String name,
Object value)
Adds a value to a set column.
|
static Assignment |
addAll(String name,
BindMarker set)
Adds a set of values to a set column.
|
static Assignment |
addAll(String name,
Set<?> set)
Adds a set of values to a set column.
|
static Object |
alias(Object column,
String alias)
Creates an alias for a given column.
|
static Assignment |
append(String name,
Object value)
Append a value to a list column.
|
static Assignment |
appendAll(String name,
BindMarker list)
Append a list of values to a list column.
|
static Assignment |
appendAll(String name,
List<?> list)
Append a list of values to a list column.
|
static Ordering |
asc(String columnName)
Ascending ordering for the provided column.
|
static Object |
avg(Object column)
Creates an
avg(x) built-in function call. |
static Batch |
batch(RegularStatement... statements)
Builds a new
BATCH query on the provided statements. |
static BindMarker |
bindMarker()
An object representing an anonymous bind marker (a question mark).
|
static BindMarker |
bindMarker(String name)
An object representing a named bind marker.
|
static Object |
cast(Object column,
DataType dataType)
Creates a Cast of a column using the given dataType.
|
static Object |
column(String name)
Declares that the name in argument should be treated as a column name.
|
static Clause |
contains(String name,
Object value)
Creates a "contains"
WHERE clause stating the provided column must contain
the value provided. |
static Clause |
containsKey(String name,
Object key)
Creates a "contains key"
WHERE clause stating the provided column must contain
the key provided. |
static Object |
count(Object column)
Creates a
count(x) built-in function call. |
static Assignment |
decr(String name)
Decrementation of a counter column.
|
static Assignment |
decr(String name,
BindMarker value)
Decrementation of a counter column by a provided value.
|
static Assignment |
decr(String name,
long value)
Decrementation of a counter column by a provided value.
|
static Delete.Selection |
delete()
Starts building a new
DELETE query. |
static Delete.Builder |
delete(String... columns)
Starts building a new
DELETE query that deletes the provided names. |
static Ordering |
desc(String columnName)
Descending ordering for the provided column.
|
static Assignment |
discard(String name,
Object value)
Discard a value from a list column.
|
static Assignment |
discardAll(String name,
BindMarker list)
Discard a list of values to a list column.
|
static Assignment |
discardAll(String name,
List<?> list)
Discard a list of values to a list column.
|
static Clause |
eq(Iterable<String> names,
Iterable<?> values)
Creates an "equal"
WHERE clause for a group of clustering columns. |
static Clause |
eq(String name,
Object value)
Creates an "equal"
WHERE clause stating the provided column must be
equal to the provided value. |
static Object |
fcall(String name,
Object... parameters)
Creates a function call.
|
static Object |
fromJson(Object json)
Creates a
fromJson() function call. |
static Clause |
gt(Iterable<String> names,
Iterable<?> values)
Creates a "greater than"
WHERE clause for a group of clustering columns. |
static Clause |
gt(String name,
Object value)
Creates a "greater than"
WHERE clause stating the provided column must
be greater to the provided value. |
static Clause |
gte(Iterable<String> names,
Iterable<?> values)
Creates a "greater than or equal"
WHERE clause for a group of clustering columns. |
static Clause |
gte(String name,
Object value)
Creates a "greater than or equal"
WHERE clause stating the provided
column must be greater than or equal to the provided value. |
static Clause |
in(Iterable<String> names,
Iterable<?> values)
Creates an "in"
WHERE clause for a group of clustering columns (a.k.a. |
static Clause |
in(String name,
Iterable<?> values)
Create an "in"
WHERE clause stating the provided column must be equal
to one of the provided values. |
static Clause |
in(String name,
Object... values)
Create an "in"
WHERE clause stating the provided column must be equal
to one of the provided values. |
static Assignment |
incr(String name)
Incrementation of a counter column.
|
static Assignment |
incr(String name,
BindMarker value)
Incrementation of a counter column by a provided value.
|
static Assignment |
incr(String name,
long value)
Incrementation of a counter column by a provided value.
|
static Insert |
insertInto(String table)
Starts building a new
INSERT query. |
static Insert |
insertInto(String keyspace,
String table)
Starts building a new
INSERT query. |
static Insert |
insertInto(TableMetadata table)
Starts building a new
INSERT query. |
static Clause |
like(String name,
Object value)
Creates a "like"
WHERE clause stating that the provided column must be equal to the provided value. |
static Clause |
lt(Iterable<String> names,
Iterable<?> values)
Creates a "lesser than"
WHERE clause for a group of clustering columns. |
static Clause |
lt(String name,
Object value)
Creates a "lesser than"
WHERE clause stating the provided column must be less than
the provided value. |
static Clause |
lte(Iterable<String> names,
Iterable<?> values)
Creates a "lesser than or equal"
WHERE clause for a group of clustering columns. |
static Clause |
lte(String name,
Object value)
Creates a "lesser than or equal"
WHERE clause stating the provided column must
be lesser than or equal to the provided value. |
static Object |
max(Object column)
Creates a
max(x) built-in function call. |
static Object |
min(Object column)
Creates a
min(x) built-in function call. |
static Clause |
ne(Iterable<String> names,
Iterable<?> values)
Creates an "not equal"
WHERE clause for a group of clustering columns. |
static Clause |
ne(String name,
Object value)
Creates a "not equal"
WHERE clause stating the provided column must be
different from the provided value. |
static Clause |
notNull(String name)
Creates an "IS NOT NULL"
WHERE clause for the provided column. |
static Object |
now()
Creates a
now() function call. |
static Object |
path(String... segments)
Creates a path composed of the given path
segments . |
static Assignment |
prepend(String name,
Object value)
Prepend a value to a list column.
|
static Assignment |
prependAll(String name,
BindMarker list)
Prepend a list of values to a list column.
|
static Assignment |
prependAll(String name,
List<?> list)
Prepend a list of values to a list column.
|
static Assignment |
put(String name,
Object key,
Object value)
Puts a new key/value pair to a map column.
|
static Assignment |
putAll(String name,
BindMarker map)
Puts a map of new key/value pairs to a map column.
|
static Assignment |
putAll(String name,
Map<?,?> map)
Puts a map of new key/value pairs to a map column.
|
static String |
quote(String columnName)
Quotes a column name to make it case sensitive.
|
static Object |
raw(String str)
Protects a value from any interpretation by the query builder.
|
static Assignment |
remove(String name,
Object value)
Remove a value from a set column.
|
static Assignment |
removeAll(String name,
BindMarker set)
Remove a set of values from a set column.
|
static Assignment |
removeAll(String name,
Set<?> set)
Remove a set of values from a set column.
|
static Select.Selection |
select()
Starts building a new
SELECT query. |
static Select.Builder |
select(Object... columns)
Starts building a new
SELECT query that selects the provided names. |
static Select.Builder |
select(String... columns)
Starts building a new
SELECT query that selects the provided names. |
static Assignment |
set(Object name,
Object value)
Advanced "set" assignment of a value to a column or a
UDT field. |
static Assignment |
set(String name,
Object value)
Simple "set" assignment of a value to a column.
|
static Assignment |
setIdx(String name,
int idx,
Object value)
Sets a list column value by index.
|
static Object |
sum(Object column)
Creates a
sum(x) built-in function call. |
static Using |
timestamp(BindMarker marker)
Option to prepare the timestamp (in microseconds) for a modification query (insert, update or delete).
|
static Using |
timestamp(long timestamp)
Option to set the timestamp for a modification query (insert, update or delete).
|
static Object |
toJson(Object column)
Creates a
toJson() function call. |
static Object |
token(Object... values)
Returns a generic
token function call. |
static String |
token(String... columnNames)
The token of column names.
|
static String |
token(String columnName)
The token of a column name.
|
static Truncate |
truncate(String table)
Creates a new
TRUNCATE query. |
static Truncate |
truncate(String keyspace,
String table)
Creates a new
TRUNCATE query. |
static Truncate |
truncate(TableMetadata table)
Creates a new
TRUNCATE query. |
static Using |
ttl(BindMarker marker)
Option to prepare the ttl (in seconds) for a modification query (insert, update or delete).
|
static Using |
ttl(int ttl)
Option to set the ttl for a modification query (insert, update or delete).
|
static Batch |
unloggedBatch(RegularStatement... statements)
Builds a new
UNLOGGED BATCH query on the provided statements. |
static Update |
update(String table)
Starts building a new
UPDATE query. |
static Update |
update(String keyspace,
String table)
Starts building a new
UPDATE query. |
static Update |
update(TableMetadata table)
Starts building a new
UPDATE query. |
static Object |
uuid()
Creates a
uuid() function call. |
public static Select.Builder select(String... columns)
SELECT
query that selects the provided names.
Note that select(c1, c2)
is just a shortcut for select().column(c1).column(c2)
.columns
- the columns names that should be selected by the query.SELECT
query (you will need to provide at
least a FROM
clause to complete the query).public static Select.Builder select(Object... columns)
SELECT
query that selects the provided names.
Note that select(c1, c2)
is just a shortcut for select().column(c1).column(c2)
.columns
- the columns names that should be selected by the query.SELECT
query (you will need to provide at
least a FROM
clause to complete the query).public static Select.Selection select()
SELECT
query.SELECT
query (you will need to provide a
column selection and at least a FROM
clause to complete the query).public static Insert insertInto(String table)
INSERT
query.table
- the name of the table in which to insert.INSERT
query.public static Insert insertInto(String keyspace, String table)
INSERT
query.keyspace
- the name of the keyspace to use.table
- the name of the table to insert into.INSERT
query.public static Insert insertInto(TableMetadata table)
INSERT
query.table
- the name of the table to insert into.INSERT
query.public static Update update(String table)
UPDATE
query.table
- the name of the table to update.UPDATE
query (at least a SET
and a WHERE
clause needs to be provided to complete the query).public static Update update(String keyspace, String table)
UPDATE
query.keyspace
- the name of the keyspace to use.table
- the name of the table to update.UPDATE
query (at least a SET
and a WHERE
clause needs to be provided to complete the query).public static Update update(TableMetadata table)
UPDATE
query.table
- the name of the table to update.UPDATE
query (at least a SET
and a WHERE
clause needs to be provided to complete the query).public static Delete.Builder delete(String... columns)
DELETE
query that deletes the provided names.columns
- the columns names that should be deleted by the query.DELETE
query (At least a FROM
and a WHERE
clause needs to be provided to complete the query).public static Delete.Selection delete()
DELETE
query.DELETE
query (you will need to provide a
column selection and at least a FROM
and a WHERE
clause to complete the
query).public static Batch batch(RegularStatement... statements)
BATCH
query on the provided statements.
This method will build a logged batch (this is the default in CQL3). To
create unlogged batches, use unloggedBatch(com.datastax.driver.core.RegularStatement...)
. Also note that
for convenience, if the provided statements are counter statements, this
method will create a COUNTER
batch even though COUNTER batches are never
logged (so for counters, using this method is effectively equivalent to
using unloggedBatch(com.datastax.driver.core.RegularStatement...)
).statements
- the statements to batch.RegularStatement
that batch statements
.public static Batch unloggedBatch(RegularStatement... statements)
UNLOGGED BATCH
query on the provided statements.
Compared to logged batches (the default), unlogged batch don't
use the distributed batch log server side and as such are not
guaranteed to be atomic. In other words, if an unlogged batch
timeout, some of the batched statements may have been persisted
while some have not. Unlogged batch will however be slightly
faster than logged batch.
If the statements added to the batch are counter statements, the
resulting batch will be a COUNTER
one.statements
- the statements to batch.RegularStatement
that batch statements
without
using the batch log.public static Truncate truncate(String table)
TRUNCATE
query.table
- the name of the table to truncate.public static Truncate truncate(String keyspace, String table)
TRUNCATE
query.keyspace
- the name of the keyspace to use.table
- the name of the table to truncate.public static Truncate truncate(TableMetadata table)
TRUNCATE
query.table
- the table to truncate.public static String quote(String columnName)
columnName
- the column name to quote.Metadata.quote(String)
public static String token(String columnName)
columnName
- the column name to take the token of."token(" + columnName + ")"
.public static String token(String... columnNames)
columnNames
- the column names to take the token of.public static Object token(Object... values)
token
function call.values
- the arguments of the token
function.token
function call.public static Clause eq(String name, Object value)
WHERE
clause stating the provided column must be
equal to the provided value.name
- the column namevalue
- the valuepublic static Clause eq(Iterable<String> names, Iterable<?> values)
WHERE
clause for a group of clustering columns.
For instance, eq(Arrays.asList("a", "b"), Arrays.asList(2, "test"))
will generate the CQL WHERE
clause (a, b) = (2, 'test')
.
Please note that this variant is only supported starting with Cassandra 2.0.6.names
- the column namesvalues
- the valuesIllegalArgumentException
- if names.size() != values.size()
.public static Clause ne(String name, Object value)
WHERE
clause stating the provided column must be
different from the provided value.name
- the column namevalue
- the valuepublic static Clause ne(Iterable<String> names, Iterable<?> values)
WHERE
clause for a group of clustering columns.
For instance, eq(Arrays.asList("a", "b"), Arrays.asList(2, "test"))
will generate the CQL WHERE
clause (a, b) != (2, 'test')
.names
- the column namesvalues
- the valuesIllegalArgumentException
- if names.size() != values.size()
.public static Clause notNull(String name)
WHERE
clause for the provided column.name
- the column namepublic static Clause like(String name, Object value)
WHERE
clause stating that the provided column must be equal to the provided value.name
- the column name.value
- the value.public static Clause in(String name, Object... values)
WHERE
clause stating the provided column must be equal
to one of the provided values.name
- the column namevalues
- the valuespublic static Clause in(String name, Iterable<?> values)
WHERE
clause stating the provided column must be equal
to one of the provided values.name
- the column namevalues
- the valuespublic static Clause in(Iterable<String> names, Iterable<?> values)
WHERE
clause for a group of clustering columns (a.k.a. "multi-column IN restriction").
For instance, in(Arrays.asList("a", "b"), Arrays.asList(Arrays.asList(1, "foo"), Arrays.asList(2, "bar")))
will generate the CQL WHERE
clause (a, b) IN ((1, 'foo'), (2, 'bar'))
.
Each element in values
must be either an iterable
containing exactly as many values
as there are columns to match in names
,
or a bind marker
– in which case, that marker is to be considered as
a placeholder for one whole tuple of values to match.
Please note that this variant is only supported starting with Cassandra 2.0.9.names
- the column namesvalues
- the valuesIllegalArgumentException
- if the size of any tuple in values
is not equal to names.size()
,
or if values
contains elements that are neither lists
nor bind markers
.public static Clause contains(String name, Object value)
WHERE
clause stating the provided column must contain
the value provided.name
- the column namevalue
- the valuepublic static Clause containsKey(String name, Object key)
WHERE
clause stating the provided column must contain
the key provided.name
- the column namekey
- the keypublic static Clause lt(String name, Object value)
WHERE
clause stating the provided column must be less than
the provided value.name
- the column namevalue
- the valuepublic static Clause lt(Iterable<String> names, Iterable<?> values)
WHERE
clause for a group of clustering columns.
For instance, lt(Arrays.asList("a", "b"), Arrays.asList(2, "test"))
will generate the CQL WHERE
clause (a, b) < (2, 'test')
.
Please note that this variant is only supported starting with Cassandra 2.0.6.names
- the column namesvalues
- the valuesIllegalArgumentException
- if names.size() != values.size()
.public static Clause lte(String name, Object value)
WHERE
clause stating the provided column must
be lesser than or equal to the provided value.name
- the column namevalue
- the valuepublic static Clause lte(Iterable<String> names, Iterable<?> values)
WHERE
clause for a group of clustering columns.
For instance, lte(Arrays.asList("a", "b"), Arrays.asList(2, "test"))
will generate the CQL WHERE
clause (a, b) <e; (2, 'test')
.
Please note that this variant is only supported starting with Cassandra 2.0.6.names
- the column namesvalues
- the valuesIllegalArgumentException
- if names.size() != values.size()
.public static Clause gt(String name, Object value)
WHERE
clause stating the provided column must
be greater to the provided value.name
- the column namevalue
- the valuepublic static Clause gt(Iterable<String> names, Iterable<?> values)
WHERE
clause for a group of clustering columns.
For instance, gt(Arrays.asList("a", "b"), Arrays.asList(2, "test"))
will generate the CQL WHERE
clause (a, b) > (2, 'test')
.
Please note that this variant is only supported starting with Cassandra 2.0.6.names
- the column namesvalues
- the valuesIllegalArgumentException
- if names.size() != values.size()
.public static Clause gte(String name, Object value)
WHERE
clause stating the provided
column must be greater than or equal to the provided value.name
- the column namevalue
- the valuepublic static Clause gte(Iterable<String> names, Iterable<?> values)
WHERE
clause for a group of clustering columns.
For instance, gte(Arrays.asList("a", "b"), Arrays.asList(2, "test"))
will generate the CQL WHERE
clause (a, b) >e; (2, 'test')
.
Please note that this variant is only supported starting with Cassandra 2.0.6.names
- the column namesvalues
- the valuesIllegalArgumentException
- if names.size() != values.size()
.public static Ordering asc(String columnName)
columnName
- the column namepublic static Ordering desc(String columnName)
columnName
- the column namepublic static Using timestamp(long timestamp)
timestamp
- the timestamp (in microseconds) to use.IllegalArgumentException
- if timestamp < 0
.public static Using timestamp(BindMarker marker)
marker
- bind marker to use for the timestamp.public static Using ttl(int ttl)
ttl
- the ttl (in seconds) to use.IllegalArgumentException
- if ttl < 0
.public static Using ttl(BindMarker marker)
marker
- bind marker to use for the ttl.public static Assignment set(String name, Object value)
name = valueThe column name will only be quoted if it contains special characters, as in:
"a name that contains spaces" = valueOtherwise, if you want to force case sensitivity, use
quote(String)
:
set(quote("aCaseSensitiveName"), value)This method won't work to set UDT fields; use
set(Object, Object)
with a
path
instead:
set(path("udt", "field"), value)
name
- the column namevalue
- the value to assignpublic static Assignment set(Object name, Object value)
UDT
field.
This method is seldom preferable to set(String, Object)
; it is only useful:
path(String...)
):
set(path("udt", "field"), value)
raw(String)
).
There is no practical usage for this the time of writing, but it will serve as a workaround if new features are
added to Cassandra and you're using a older driver version that is not yet aware of them:
set(raw("some custom string"), value)
name
is String
, this method is equivalent to set(String, Object)
.name
- the column or UDT field namevalue
- the value to assignpublic static Assignment incr(String name)
name = name + 1
.name
- the column name to incrementpublic static Assignment incr(String name, long value)
name = name + value
.name
- the column name to incrementvalue
- the value by which to incrementpublic static Assignment incr(String name, BindMarker value)
name = name + value
.name
- the column name to incrementvalue
- a bind marker representing the value by which to incrementpublic static Assignment decr(String name)
name = name - 1
.name
- the column name to decrementpublic static Assignment decr(String name, long value)
name = name - value
.name
- the column name to decrementvalue
- the value by which to decrementpublic static Assignment decr(String name, BindMarker value)
name = name - value
.name
- the column name to decrementvalue
- a bind marker representing the value by which to decrementpublic static Assignment prepend(String name, Object value)
name = [ value ] + name
.name
- the column name (must be of type list).value
- the value to prepend. Using a BindMarker here is not supported.
To use a BindMarker use QueryBuilder#prependAll
with a
singleton list.public static Assignment prependAll(String name, List<?> list)
name = list + name
.name
- the column name (must be of type list).list
- the list of values to prepend.public static Assignment prependAll(String name, BindMarker list)
name = list + name
.name
- the column name (must be of type list).list
- a bind marker representing the list of values to prepend.public static Assignment append(String name, Object value)
name = name + [value]
.name
- the column name (must be of type list).value
- the value to append. Using a BindMarker here is not supported.
To use a BindMarker use QueryBuilder#appendAll
with a
singleton list.public static Assignment appendAll(String name, List<?> list)
name = name + list
.name
- the column name (must be of type list).list
- the list of values to appendpublic static Assignment appendAll(String name, BindMarker list)
name = name + list
.name
- the column name (must be of type list).list
- a bind marker representing the list of values to appendpublic static Assignment discard(String name, Object value)
name = name - [value]
.name
- the column name (must be of type list).value
- the value to discard. Using a BindMarker here is not supported.
To use a BindMarker use QueryBuilder#discardAll
with a singleton list.public static Assignment discardAll(String name, List<?> list)
name = name - list
.name
- the column name (must be of type list).list
- the list of values to discardpublic static Assignment discardAll(String name, BindMarker list)
name = name - list
.name
- the column name (must be of type list).list
- a bind marker representing the list of values to discardpublic static Assignment setIdx(String name, int idx, Object value)
name[idx] = value
.name
- the column name (must be of type list).idx
- the index to setvalue
- the value to setpublic static Assignment add(String name, Object value)
name = name + {value}
.name
- the column name (must be of type set).value
- the value to add. Using a BindMarker here is not supported.
To use a BindMarker use QueryBuilder#addAll
with a
singleton set.public static Assignment addAll(String name, Set<?> set)
name = name + set
.name
- the column name (must be of type set).set
- the set of values to appendpublic static Assignment addAll(String name, BindMarker set)
name = name + set
.name
- the column name (must be of type set).set
- a bind marker representing the set of values to appendpublic static Assignment remove(String name, Object value)
name = name - {value}
.name
- the column name (must be of type set).value
- the value to remove. Using a BindMarker here is not supported.
To use a BindMarker use QueryBuilder#removeAll
with a singleton set.public static Assignment removeAll(String name, Set<?> set)
name = name - set
.name
- the column name (must be of type set).set
- the set of values to removepublic static Assignment removeAll(String name, BindMarker set)
name = name - set
.name
- the column name (must be of type set).set
- a bind marker representing the set of values to removepublic static Assignment put(String name, Object key, Object value)
name[key] = value
.name
- the column name (must be of type map).key
- the key to putvalue
- the value to putpublic static Assignment putAll(String name, Map<?,?> map)
name = name + map
.name
- the column name (must be of type map).map
- the map of key/value pairs to putpublic static Assignment putAll(String name, BindMarker map)
name = name + map
.name
- the column name (must be of type map).map
- a bind marker representing the map of key/value pairs to putpublic static BindMarker bindMarker()
Insert i = QueryBuilder.insertInto("test").value("k", 0)
.value("c", QueryBuilder.bindMarker());
PreparedStatement p = session.prepare(i.toString());
public static BindMarker bindMarker(String name)
Insert i = QueryBuilder.insertInto("test").value("k", 0)
.value("c", QueryBuilder.bindMarker("c_val"));
PreparedStatement p = session.prepare(i.toString());
Please note that named bind makers are only supported starting with Cassandra 2.0.1.name
- the name for the bind marker.name
.public static Object raw(String str)
Code | Resulting query string |
---|---|
select().from("t").where(eq("c", "C'est la vie!")); | "SELECT * FROM t WHERE c='C''est la vie!';" |
select().from("t").where(eq("c", raw("C'est la vie!"))); | "SELECT * FROM t WHERE c=C'est la vie!;" |
select().from("t").where(eq("c", raw("'C'est la vie!'"))); | "SELECT * FROM t WHERE c='C'est la vie!';" |
select().from("t").where(eq("c", "now()")); | "SELECT * FROM t WHERE c='now()';" |
select().from("t").where(eq("c", raw("now()"))); | "SELECT * FROM t WHERE c=now();" |
str
- the raw value to use as a stringpublic static Object fcall(String name, Object... parameters)
name
- the name of the function to call.parameters
- the parameters for the function.public static Object cast(Object column, DataType dataType)
column
- the column to cast.dataType
- the data type to cast to.public static Object now()
now()
function call.public static Object uuid()
uuid()
function call.public static Object column(String name)
Select.Selection.fcall(java.lang.String, java.lang.Object...)
when a
function should apply to a column name, not a string value.name
- the name of the column.public static Object path(String... segments)
segments
.
All provided path segments will be concatenated together with dots.
If any segment contains an identifier that needs quoting,
caller code is expected to call quote(String)
prior to
invoking this method.
This method is currently only useful when accessing individual fields of a
user-defined type
(UDT),
which is only possible since CASSANDRA-7423.
Note that currently nested UDT fields are not supported and
will be rejected by the server as a
syntax error
.segments
- the segments of the path to create.public static Object fromJson(Object json)
fromJson()
function call.
Support for JSON functions has been added in Cassandra 2.2.
The fromJson()
function is similar to INSERT JSON
statements,
but applies to a single column value instead of the entire row, and
converts a JSON object into the normal Cassandra column value.
It may be used in INSERT
and UPDATE
statements,
but NOT in the selection clause of a SELECT
statement.
The provided object can be of the following types:
SELECT JSON
statement on the same table.
Note that it is not possible to insert function calls nor bind markers in a JSON string.bind marker
. In this case, the statement is meant to be prepared
and no JSON string will be appended to the query string, only a bind marker for the whole JSON parameter.codec
is registered with the
CodecRegistry
in use. This allows the usage of JSON libraries, such
as the Java API for JSON processing,
the popular Jackson library, or
Google's Gson library, for instance.foo"'bar
should be inserted in the JSON string
as "foo\"''bar"
.json
- the JSON string, or a bind marker, or a JSON object handled by a specific codec
.public static Object toJson(Object column)
toJson()
function call.
This is a shortcut for fcall("toJson", QueryBuilder.column(name))
.
Support for JSON functions has been added in Cassandra 2.2.
The toJson()
function is similar to SELECT JSON
statements,
but applies to a single column value instead of the entire row,
and produces a JSON-encoded string representing the normal Cassandra column value.
It may only be used in the selection clause of a SELECT
statement.column
- the column to retrieve JSON from.public static Object alias(Object column, String alias)
select(Object...)
.column
- The column to create an alias for.alias
- The column alias.public static Object count(Object column)
count(x)
built-in function call.public static Object max(Object column)
max(x)
built-in function call.public static Object min(Object column)
min(x)
built-in function call.public static Object sum(Object column)
sum(x)
built-in function call.Copyright © 2012–2018. All rights reserved.