Class CqlIdentifier

  • All Implemented Interfaces:
    Serializable

    @Immutable
    public class CqlIdentifier
    extends Object
    implements Serializable
    The identifier of CQL element (keyspace, table, column, etc).

    It has two representations:

    • the "CQL" form, which is how you would type the identifier in a CQL query. It is case-insensitive unless enclosed in double quotation marks; in addition, identifiers that contain special characters (anything other than alphanumeric and underscore), or match CQL keywords, must be double-quoted (with inner double quotes escaped as "").
    • the "internal" form, which is how the name is stored in Cassandra system tables. It is lower-case for case-sensitive identifiers, and in the exact case for case-sensitive identifiers.
    Examples:
    Examples
    Create statementCase-sensitive?CQL idInternal id
    CREATE TABLE t(foo int PRIMARY KEY)Nofoofoo
    CREATE TABLE t(Foo int PRIMARY KEY)Nofoofoo
    CREATE TABLE t("Foo" int PRIMARY KEY)Yes"Foo"Foo
    CREATE TABLE t("foo bar" int PRIMARY KEY)Yes"foo bar"foo bar
    CREATE TABLE t("foo""bar" int PRIMARY KEY)Yes"foo""bar"foo"bar
    CREATE TABLE t("create" int PRIMARY KEY)Yes (reserved keyword)"create"create
    This class provides a common representation and avoids any ambiguity about which form the identifier is in. Driver clients will generally want to create instances from the CQL form with fromCql(String).

    There is no internal caching; if you reuse the same identifiers often, consider caching them in your application.

    See Also:
    Serialized Form
    • Method Detail

      • asInternal

        @NonNull
        public String asInternal()
        Returns the identifier in the "internal" format.
        Returns:
        the identifier in its exact case, unquoted.
      • asCql

        @NonNull
        public String asCql​(boolean pretty)
        Returns the identifier in a format appropriate for concatenation in a CQL query.
        Parameters:
        pretty - if true, use the shortest possible representation: if the identifier is case-insensitive, an unquoted, lower-case string, otherwise the double-quoted form. If false, always use the double-quoted form (this is slightly more efficient since we don't need to inspect the string).
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object