Search in sources :

Example 1 with CqlBuilder

use of org.apache.cassandra.cql3.CqlBuilder in project cassandra by apache.

the class UDFunction method toCqlString.

@Override
public String toCqlString(boolean withInternals, boolean ifNotExists) {
    CqlBuilder builder = new CqlBuilder();
    builder.append("CREATE FUNCTION ");
    if (ifNotExists) {
        builder.append("IF NOT EXISTS ");
    }
    builder.append(name()).append("(");
    for (int i = 0, m = argNames().size(); i < m; i++) {
        if (i > 0)
            builder.append(", ");
        builder.append(argNames().get(i)).append(' ').append(toCqlString(argTypes().get(i)));
    }
    builder.append(')').newLine().increaseIndent().append(isCalledOnNullInput() ? "CALLED" : "RETURNS NULL").append(" ON NULL INPUT").newLine().append("RETURNS ").append(toCqlString(returnType())).newLine().append("LANGUAGE ").append(language()).newLine().append("AS $$").append(body()).append("$$;");
    return builder.toString();
}
Also used : CqlBuilder(org.apache.cassandra.cql3.CqlBuilder)

Example 2 with CqlBuilder

use of org.apache.cassandra.cql3.CqlBuilder in project cassandra by apache.

the class TableMetadata method toCqlString.

@Override
public String toCqlString(boolean withInternals, boolean ifNotExists) {
    CqlBuilder builder = new CqlBuilder(2048);
    appendCqlTo(builder, withInternals, withInternals, ifNotExists);
    return builder.toString();
}
Also used : CqlBuilder(org.apache.cassandra.cql3.CqlBuilder)

Example 3 with CqlBuilder

use of org.apache.cassandra.cql3.CqlBuilder in project cassandra by apache.

the class UDAggregate method toCqlString.

@Override
public String toCqlString(boolean withInternals, boolean ifNotExists) {
    CqlBuilder builder = new CqlBuilder();
    builder.append("CREATE AGGREGATE ");
    if (ifNotExists) {
        builder.append("IF NOT EXISTS ");
    }
    builder.append(name()).append('(').appendWithSeparators(argTypes, (b, t) -> b.append(toCqlString(t)), ", ").append(')').newLine().increaseIndent().append("SFUNC ").append(stateFunction().name().name).newLine().append("STYPE ").append(toCqlString(stateType()));
    if (finalFunction() != null)
        builder.newLine().append("FINALFUNC ").append(finalFunction().name().name);
    if (initialCondition() != null)
        builder.newLine().append("INITCOND ").append(stateType().asCQL3Type().toCQLLiteral(initialCondition(), ProtocolVersion.CURRENT));
    return builder.append(";").toString();
}
Also used : CqlBuilder(org.apache.cassandra.cql3.CqlBuilder)

Example 4 with CqlBuilder

use of org.apache.cassandra.cql3.CqlBuilder in project cassandra by apache.

the class IndexMetadata method toCqlString.

public String toCqlString(TableMetadata table, boolean ifNotExists) {
    CqlBuilder builder = new CqlBuilder();
    appendCqlTo(builder, table, ifNotExists);
    return builder.toString();
}
Also used : CqlBuilder(org.apache.cassandra.cql3.CqlBuilder)

Example 5 with CqlBuilder

use of org.apache.cassandra.cql3.CqlBuilder in project cassandra by apache.

the class KeyspaceMetadata method toCqlString.

@Override
public String toCqlString(boolean withInternals, boolean ifNotExists) {
    CqlBuilder builder = new CqlBuilder();
    if (isVirtual()) {
        builder.append("/*").newLine().append("Warning: Keyspace ").appendQuotingIfNeeded(name).append(" is a virtual keyspace and cannot be recreated with CQL.").newLine().append("Structure, for reference:").newLine().append("VIRTUAL KEYSPACE ").appendQuotingIfNeeded(name).append(';').newLine().append("*/").toString();
    } else {
        builder.append("CREATE KEYSPACE ");
        if (ifNotExists) {
            builder.append("IF NOT EXISTS ");
        }
        builder.appendQuotingIfNeeded(name).append(" WITH replication = ");
        params.replication.appendCqlTo(builder);
        builder.append("  AND durable_writes = ").append(params.durableWrites).append(';').toString();
    }
    return builder.toString();
}
Also used : CqlBuilder(org.apache.cassandra.cql3.CqlBuilder)

Aggregations

CqlBuilder (org.apache.cassandra.cql3.CqlBuilder)5