Class QueryBuilder

    • Method Detail

      • select

        public static Select.Builder select​(String... columns)
        Starts building a new SELECT query that selects the provided names.

        Note that select(c1, c2) is just a shortcut for select().column(c1).column(c2).

        Parameters:
        columns - the columns names that should be selected by the query.
        Returns:
        an in-construction SELECT query (you will need to provide at least a FROM clause to complete the query).
      • select

        public static Select.Builder select​(Object... columns)
        Starts building a new SELECT query that selects the provided names.

        Note that select(c1, c2) is just a shortcut for select().column(c1).column(c2).

        Parameters:
        columns - the columns names that should be selected by the query.
        Returns:
        an in-construction SELECT query (you will need to provide at least a FROM clause to complete the query).
      • select

        public static Select.Selection select()
        Starts building a new SELECT query.
        Returns:
        an in-construction SELECT query (you will need to provide a column selection and at least a FROM clause to complete the query).
      • insertInto

        public static Insert insertInto​(String table)
        Starts building a new INSERT query.
        Parameters:
        table - the name of the table in which to insert.
        Returns:
        an in-construction INSERT query.
      • insertInto

        public static Insert insertInto​(String keyspace,
                                        String table)
        Starts building a new INSERT query.
        Parameters:
        keyspace - the name of the keyspace to use.
        table - the name of the table to insert into.
        Returns:
        an in-construction INSERT query.
      • insertInto

        public static Insert insertInto​(TableMetadata table)
        Starts building a new INSERT query.
        Parameters:
        table - the name of the table to insert into.
        Returns:
        an in-construction INSERT query.
      • update

        public static Update update​(String table)
        Starts building a new UPDATE query.
        Parameters:
        table - the name of the table to update.
        Returns:
        an in-construction UPDATE query (at least a SET and a WHERE clause needs to be provided to complete the query).
      • update

        public static Update update​(String keyspace,
                                    String table)
        Starts building a new UPDATE query.
        Parameters:
        keyspace - the name of the keyspace to use.
        table - the name of the table to update.
        Returns:
        an in-construction UPDATE query (at least a SET and a WHERE clause needs to be provided to complete the query).
      • update

        public static Update update​(TableMetadata table)
        Starts building a new UPDATE query.
        Parameters:
        table - the name of the table to update.
        Returns:
        an in-construction UPDATE query (at least a SET and a WHERE clause needs to be provided to complete the query).
      • delete

        public static Delete.Builder delete​(String... columns)
        Starts building a new DELETE query that deletes the provided names.
        Parameters:
        columns - the columns names that should be deleted by the query.
        Returns:
        an in-construction DELETE query (At least a FROM and a WHERE clause needs to be provided to complete the query).
      • delete

        public static Delete.Selection delete()
        Starts building a new DELETE query.
        Returns:
        an in-construction DELETE query (you will need to provide a column selection and at least a FROM and a WHERE clause to complete the query).
      • unloggedBatch

        public static Batch unloggedBatch​(RegularStatement... statements)
        Builds a new 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.

        Parameters:
        statements - the statements to batch.
        Returns:
        a new RegularStatement that batch statements without using the batch log.
      • truncate

        public static Truncate truncate​(String table)
        Creates a new TRUNCATE query.
        Parameters:
        table - the name of the table to truncate.
        Returns:
        the truncation query.
      • truncate

        public static Truncate truncate​(String keyspace,
                                        String table)
        Creates a new TRUNCATE query.
        Parameters:
        keyspace - the name of the keyspace to use.
        table - the name of the table to truncate.
        Returns:
        the truncation query.
      • truncate

        public static Truncate truncate​(TableMetadata table)
        Creates a new TRUNCATE query.
        Parameters:
        table - the table to truncate.
        Returns:
        the truncation query.
      • quote

        public static String quote​(String columnName)
        Quotes a column name to make it case sensitive.
        Parameters:
        columnName - the column name to quote.
        Returns:
        the quoted column name.
        See Also:
        Metadata.quote(String)
      • token

        public static String token​(String columnName)
        The token of a column name.
        Parameters:
        columnName - the column name to take the token of.
        Returns:
        "token(" + columnName + ")".
      • token

        public static String token​(String... columnNames)
        The token of column names.

        This variant is most useful when the partition key is composite.

        Parameters:
        columnNames - the column names to take the token of.
        Returns:
        a string representing the token of the provided column names.
      • token

        public static Object token​(Object... values)
        Returns a generic token function call.
        Parameters:
        values - the arguments of the token function.
        Returns:
        token function call.
      • eq

        public static Clause eq​(String name,
                                Object value)
        Creates an "equal" WHERE clause stating the provided column must be equal to the provided value.
        Parameters:
        name - the column name
        value - the value
        Returns:
        the corresponding where clause.
      • eq

        public static Clause eq​(Iterable<String> names,
                                Iterable<?> values)
        Creates an "equal" 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.

        Parameters:
        names - the column names
        values - the values
        Returns:
        the corresponding where clause.
        Throws:
        IllegalArgumentException - if names.size() != values.size().
      • ne

        public static Clause ne​(String name,
                                Object value)
        Creates a "not equal" WHERE clause stating the provided column must be different from the provided value.
        Parameters:
        name - the column name
        value - the value
        Returns:
        the corresponding where clause.
      • ne

        public static Clause ne​(Iterable<String> names,
                                Iterable<?> values)
        Creates an "not equal" 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') .

        Parameters:
        names - the column names
        values - the values
        Returns:
        the corresponding where clause.
        Throws:
        IllegalArgumentException - if names.size() != values.size().
      • notNull

        public static Clause notNull​(String name)
        Creates an "IS NOT NULL" WHERE clause for the provided column.
        Parameters:
        name - the column name
        Returns:
        the corresponding where clause.
      • like

        public static Clause like​(String name,
                                  Object value)
        Creates a "like" WHERE clause stating that the provided column must be equal to the provided value.
        Parameters:
        name - the column name.
        value - the value.
        Returns:
        the corresponding where clause.
      • in

        public 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.
        Parameters:
        name - the column name
        values - the values
        Returns:
        the corresponding where clause.
      • in

        public 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.
        Parameters:
        name - the column name
        values - the values
        Returns:
        the corresponding where clause.
      • in

        public static Clause in​(Iterable<String> names,
                                Iterable<?> values)
        Creates an "in" 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.

        Parameters:
        names - the column names
        values - the values
        Returns:
        the corresponding where clause.
        Throws:
        IllegalArgumentException - 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.
      • contains

        public static Clause contains​(String name,
                                      Object value)
        Creates a "contains" WHERE clause stating the provided column must contain the value provided.
        Parameters:
        name - the column name
        value - the value
        Returns:
        the corresponding where clause.
      • containsKey

        public static Clause containsKey​(String name,
                                         Object key)
        Creates a "contains key" WHERE clause stating the provided column must contain the key provided.
        Parameters:
        name - the column name
        key - the key
        Returns:
        the corresponding where clause.
      • lt

        public static Clause lt​(String name,
                                Object value)
        Creates a "lesser than" WHERE clause stating the provided column must be less than the provided value.
        Parameters:
        name - the column name
        value - the value
        Returns:
        the corresponding where clause.
      • lt

        public static Clause lt​(Iterable<String> names,
                                Iterable<?> values)
        Creates a "lesser than" 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) &lt; (2, 'test') .

        Please note that this variant is only supported starting with Cassandra 2.0.6.

        Parameters:
        names - the column names
        values - the values
        Returns:
        the corresponding where clause.
        Throws:
        IllegalArgumentException - if names.size() != values.size().
      • lte

        public 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.
        Parameters:
        name - the column name
        value - the value
        Returns:
        the corresponding where clause.
      • lte

        public static Clause lte​(Iterable<String> names,
                                 Iterable<?> values)
        Creates a "lesser than or equal" 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) &lte; (2, 'test') .

        Please note that this variant is only supported starting with Cassandra 2.0.6.

        Parameters:
        names - the column names
        values - the values
        Returns:
        the corresponding where clause.
        Throws:
        IllegalArgumentException - if names.size() != values.size().
      • gt

        public static Clause gt​(String name,
                                Object value)
        Creates a "greater than" WHERE clause stating the provided column must be greater to the provided value.
        Parameters:
        name - the column name
        value - the value
        Returns:
        the corresponding where clause.
      • gt

        public static Clause gt​(Iterable<String> names,
                                Iterable<?> values)
        Creates a "greater than" 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) &gt; (2, 'test') .

        Please note that this variant is only supported starting with Cassandra 2.0.6.

        Parameters:
        names - the column names
        values - the values
        Returns:
        the corresponding where clause.
        Throws:
        IllegalArgumentException - if names.size() != values.size().
      • gte

        public 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.
        Parameters:
        name - the column name
        value - the value
        Returns:
        the corresponding where clause.
      • gte

        public static Clause gte​(Iterable<String> names,
                                 Iterable<?> values)
        Creates a "greater than or equal" 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) &gte; (2, 'test') .

        Please note that this variant is only supported starting with Cassandra 2.0.6.

        Parameters:
        names - the column names
        values - the values
        Returns:
        the corresponding where clause.
        Throws:
        IllegalArgumentException - if names.size() != values.size().
      • asc

        public static Ordering asc​(String columnName)
        Ascending ordering for the provided column.
        Parameters:
        columnName - the column name
        Returns:
        the corresponding ordering
      • desc

        public static Ordering desc​(String columnName)
        Descending ordering for the provided column.
        Parameters:
        columnName - the column name
        Returns:
        the corresponding ordering
      • timestamp

        public static Using timestamp​(long timestamp)
        Option to set the timestamp for a modification query (insert, update or delete).
        Parameters:
        timestamp - the timestamp (in microseconds) to use.
        Returns:
        the corresponding option
        Throws:
        IllegalArgumentException - if timestamp &lt; 0.
      • timestamp

        public static Using timestamp​(BindMarker marker)
        Option to prepare the timestamp (in microseconds) for a modification query (insert, update or delete).
        Parameters:
        marker - bind marker to use for the timestamp.
        Returns:
        the corresponding option.
      • ttl

        public static Using ttl​(int ttl)
        Option to set the ttl for a modification query (insert, update or delete).
        Parameters:
        ttl - the ttl (in seconds) to use.
        Returns:
        the corresponding option
        Throws:
        IllegalArgumentException - if ttl &lt; 0.
      • ttl

        public static Using ttl​(BindMarker marker)
        Option to prepare the ttl (in seconds) for a modification query (insert, update or delete).
        Parameters:
        marker - bind marker to use for the ttl.
        Returns:
        the corresponding option
      • timeout

        public static Using timeout​(Duration timeout)
        Adds a USING TIMEOUT clause to this statement with a Duration value.

        If this method or timeout(BindMarker) is called multiple times, the value from the last invocation is used.

        Parameters:
        timeout - A timeout value controlling server-side query timeout.
      • timeout

        public static Using timeout​(BindMarker marker)
        Adds a USING TIMEOUT clause to this statement with a bind marker.

        If this method or timeout(Duration) is called multiple times, the value from the last invocation is used.

        Parameters:
        marker - A bind marker understood as Duration controlling server-side query timeout.
      • set

        public static Assignment set​(String name,
                                     Object value)
        Simple "set" assignment of a value to a column.

        This will generate:

         name = value
         
        The column name will only be quoted if it contains special characters, as in:
         "a name that contains spaces" = value
         
        Otherwise, 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)
         
        Parameters:
        name - the column name
        value - the value to assign
        Returns:
        the correspond assignment (to use in an update query)
      • set

        public static Assignment set​(Object name,
                                     Object value)
        Advanced "set" assignment of a value to a column or a UDT field.

        This method is seldom preferable to set(String, Object); it is only useful:

        • when assigning values to individual fields of a UDT (see path(String...)):
           set(path("udt", "field"), value)
           
        • if you wish to pass a "raw" string that will get appended as-is to the query (see 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)
           
        If the runtime type of name is String, this method is equivalent to set(String, Object).
        Parameters:
        name - the column or UDT field name
        value - the value to assign
        Returns:
        the correspond assignment (to use in an update query)
      • incr

        public static Assignment incr​(String name)
        Incrementation of a counter column.

        This will generate: name = name + 1.

        Parameters:
        name - the column name to increment
        Returns:
        the correspond assignment (to use in an update query)
      • incr

        public static Assignment incr​(String name,
                                      long value)
        Incrementation of a counter column by a provided value.

        This will generate: name = name + value.

        Parameters:
        name - the column name to increment
        value - the value by which to increment
        Returns:
        the correspond assignment (to use in an update query)
      • incr

        public static Assignment incr​(String name,
                                      BindMarker value)
        Incrementation of a counter column by a provided value.

        This will generate: name = name + value.

        Parameters:
        name - the column name to increment
        value - a bind marker representing the value by which to increment
        Returns:
        the correspond assignment (to use in an update query)
      • decr

        public static Assignment decr​(String name)
        Decrementation of a counter column.

        This will generate: name = name - 1.

        Parameters:
        name - the column name to decrement
        Returns:
        the correspond assignment (to use in an update query)
      • decr

        public static Assignment decr​(String name,
                                      long value)
        Decrementation of a counter column by a provided value.

        This will generate: name = name - value.

        Parameters:
        name - the column name to decrement
        value - the value by which to decrement
        Returns:
        the correspond assignment (to use in an update query)
      • decr

        public static Assignment decr​(String name,
                                      BindMarker value)
        Decrementation of a counter column by a provided value.

        This will generate: name = name - value.

        Parameters:
        name - the column name to decrement
        value - a bind marker representing the value by which to decrement
        Returns:
        the correspond assignment (to use in an update query)
      • prepend

        public static Assignment prepend​(String name,
                                         Object value)
        Prepend a value to a list column.

        This will generate: name = [ value ] + name.

        Parameters:
        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.
        Returns:
        the correspond assignment (to use in an update query)
      • prependAll

        public static Assignment prependAll​(String name,
                                            List<?> list)
        Prepend a list of values to a list column.

        This will generate: name = list + name.

        Parameters:
        name - the column name (must be of type list).
        list - the list of values to prepend.
        Returns:
        the correspond assignment (to use in an update query)
      • prependAll

        public static Assignment prependAll​(String name,
                                            BindMarker list)
        Prepend a list of values to a list column.

        This will generate: name = list + name.

        Parameters:
        name - the column name (must be of type list).
        list - a bind marker representing the list of values to prepend.
        Returns:
        the correspond assignment (to use in an update query)
      • append

        public static Assignment append​(String name,
                                        Object value)
        Append a value to a list column.

        This will generate: name = name + [value].

        Parameters:
        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.
        Returns:
        the correspond assignment (to use in an update query)
      • appendAll

        public static Assignment appendAll​(String name,
                                           List<?> list)
        Append a list of values to a list column.

        This will generate: name = name + list.

        Parameters:
        name - the column name (must be of type list).
        list - the list of values to append
        Returns:
        the correspond assignment (to use in an update query)
      • appendAll

        public static Assignment appendAll​(String name,
                                           BindMarker list)
        Append a list of values to a list column.

        This will generate: name = name + list.

        Parameters:
        name - the column name (must be of type list).
        list - a bind marker representing the list of values to append
        Returns:
        the correspond assignment (to use in an update query)
      • discard

        public static Assignment discard​(String name,
                                         Object value)
        Discard a value from a list column.

        This will generate: name = name - [value].

        Parameters:
        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.
        Returns:
        the correspond assignment (to use in an update query)
      • discardAll

        public static Assignment discardAll​(String name,
                                            List<?> list)
        Discard a list of values to a list column.

        This will generate: name = name - list.

        Parameters:
        name - the column name (must be of type list).
        list - the list of values to discard
        Returns:
        the correspond assignment (to use in an update query)
      • discardAll

        public static Assignment discardAll​(String name,
                                            BindMarker list)
        Discard a list of values to a list column.

        This will generate: name = name - list.

        Parameters:
        name - the column name (must be of type list).
        list - a bind marker representing the list of values to discard
        Returns:
        the correspond assignment (to use in an update query)
      • setIdx

        public static Assignment setIdx​(String name,
                                        int idx,
                                        Object value)
        Sets a list column value by index.

        This will generate: name[idx] = value.

        Parameters:
        name - the column name (must be of type list).
        idx - the index to set
        value - the value to set
        Returns:
        the correspond assignment (to use in an update query)
      • add

        public static Assignment add​(String name,
                                     Object value)
        Adds a value to a set column.

        This will generate: name = name + {value}.

        Parameters:
        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.
        Returns:
        the correspond assignment (to use in an update query)
      • addAll

        public static Assignment addAll​(String name,
                                        Set<?> set)
        Adds a set of values to a set column.

        This will generate: name = name + set.

        Parameters:
        name - the column name (must be of type set).
        set - the set of values to append
        Returns:
        the correspond assignment (to use in an update query)
      • addAll

        public static Assignment addAll​(String name,
                                        BindMarker set)
        Adds a set of values to a set column.

        This will generate: name = name + set.

        Parameters:
        name - the column name (must be of type set).
        set - a bind marker representing the set of values to append
        Returns:
        the correspond assignment (to use in an update query)
      • remove

        public static Assignment remove​(String name,
                                        Object value)
        Remove a value from a set column.

        This will generate: name = name - {value}.

        Parameters:
        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.
        Returns:
        the correspond assignment (to use in an update query)
      • removeAll

        public static Assignment removeAll​(String name,
                                           Set<?> set)
        Remove a set of values from a set column.

        This will generate: name = name - set.

        Parameters:
        name - the column name (must be of type set).
        set - the set of values to remove
        Returns:
        the correspond assignment (to use in an update query)
      • removeAll

        public static Assignment removeAll​(String name,
                                           BindMarker set)
        Remove a set of values from a set column.

        This will generate: name = name - set.

        Parameters:
        name - the column name (must be of type set).
        set - a bind marker representing the set of values to remove
        Returns:
        the correspond assignment (to use in an update query)
      • put

        public static Assignment put​(String name,
                                     Object key,
                                     Object value)
        Puts a new key/value pair to a map column.

        This will generate: name[key] = value.

        Parameters:
        name - the column name (must be of type map).
        key - the key to put
        value - the value to put
        Returns:
        the correspond assignment (to use in an update query)
      • putAll

        public static Assignment putAll​(String name,
                                        Map<?,​?> map)
        Puts a map of new key/value pairs to a map column.

        This will generate: name = name + map.

        Parameters:
        name - the column name (must be of type map).
        map - the map of key/value pairs to put
        Returns:
        the correspond assignment (to use in an update query)
      • putAll

        public static Assignment putAll​(String name,
                                        BindMarker map)
        Puts a map of new key/value pairs to a map column.

        This will generate: name = name + map.

        Parameters:
        name - the column name (must be of type map).
        map - a bind marker representing the map of key/value pairs to put
        Returns:
        the correspond assignment (to use in an update query)
      • bindMarker

        public static BindMarker bindMarker()
        An object representing an anonymous bind marker (a question mark).

        This can be used wherever a value is expected. For instance, one can do:

        
         Insert i = QueryBuilder.insertInto("test").value("k", 0)
                                                   .value("c", QueryBuilder.bindMarker());
         PreparedStatement p = session.prepare(i.toString());
         
        Returns:
        a new bind marker.
      • bindMarker

        public static BindMarker bindMarker​(String name)
        An object representing a named bind marker.

        This can be used wherever a value is expected. For instance, one can do:

        
         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.

        Parameters:
        name - the name for the bind marker.
        Returns:
        an object representing a bind marker named name.
      • raw

        public static Object raw​(String str)
        Protects a value from any interpretation by the query builder.

        The following table exemplify the behavior of this function:

        Examples of use
        CodeResulting 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();"
        Note: the 2nd and 3rd examples in this table are not a valid CQL3 queries.

        The use of that method is generally discouraged since it lead to security risks. However, if you know what you are doing, it allows to escape the interpretations done by the QueryBuilder.

        Parameters:
        str - the raw value to use as a string
        Returns:
        the value but protected from being interpreted/escaped by the query builder.
      • fcall

        public static Object fcall​(String name,
                                   Object... parameters)
        Creates a function call.
        Parameters:
        name - the name of the function to call.
        parameters - the parameters for the function.
        Returns:
        the function call.
      • cast

        public static Object cast​(Object column,
                                  DataType dataType)
        Creates a Cast of a column using the given dataType.
        Parameters:
        column - the column to cast.
        dataType - the data type to cast to.
        Returns:
        the casted column.
      • now

        public static Object now()
        Creates a now() function call.
        Returns:
        the function call.
      • uuid

        public static Object uuid()
        Creates a uuid() function call.
        Returns:
        the function call.
      • column

        public static Object column​(String name)
        Declares that the name in argument should be treated as a column name.

        This mainly meant for use with Select.Selection.fcall(java.lang.String, java.lang.Object...) when a function should apply to a column name, not a string value.

        Parameters:
        name - the name of the column.
        Returns:
        the name as a column name.
      • path

        public static Object path​(String... segments)
        Creates a path composed of the given path 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.

        Parameters:
        segments - the segments of the path to create.
        Returns:
        the segments concatenated as a single path.
        See Also:
        CASSANDRA-7423
      • fromJson

        public static Object fromJson​(Object json)
        Creates a 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:

        1. A raw string. In this case, it will be appended to the query string as is. It should NOT be surrounded by single quotes. Its format should generally match that returned by a SELECT JSON statement on the same table. Note that it is not possible to insert function calls nor bind markers in a JSON string.
        2. A 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.
        3. Any object that can be serialized to JSON. Such objects can be used provided that a matching 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.

        When passing raw strings to this method, the following rules apply:

        1. String values should be enclosed in double quotes.
        2. Double quotes appearing inside strings should be escaped with a backslash, but single quotes should be escaped in the CQL manner, i.e. by another single quote. For example, the column value foo"'bar should be inserted in the JSON string as "foo\"''bar".
        Parameters:
        json - the JSON string, or a bind marker, or a JSON object handled by a specific codec.
        Returns:
        the function call.
        See Also:
        JSON Support for CQL, JSON Support in Cassandra 2.2
      • toJson

        public static Object toJson​(Object column)
        Creates a 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.

        Parameters:
        column - the column to retrieve JSON from.
        Returns:
        the function call.
        See Also:
        JSON Support for CQL, JSON Support in Cassandra 2.2
      • alias

        public static Object alias​(Object column,
                                   String alias)
        Creates an alias for a given column.

        This is most useful when used with the method select(Object...).

        Parameters:
        column - The column to create an alias for.
        alias - The column alias.
        Returns:
        a column alias.
      • count

        public static Object count​(Object column)
        Creates a count(x) built-in function call.
        Returns:
        the function call.
      • max

        public static Object max​(Object column)
        Creates a max(x) built-in function call.
        Returns:
        the function call.
      • min

        public static Object min​(Object column)
        Creates a min(x) built-in function call.
        Returns:
        the function call.
      • sum

        public static Object sum​(Object column)
        Creates a sum(x) built-in function call.
        Returns:
        the function call.
      • avg

        public static Object avg​(Object column)
        Creates an avg(x) built-in function call.
        Returns:
        the function call.