Search in sources :

Example 1 with DefaultAggregateMetadata

use of com.datastax.oss.driver.internal.core.metadata.schema.DefaultAggregateMetadata in project java-driver by datastax.

the class AggregateParser method parseAggregate.

public AggregateMetadata parseAggregate(AdminRow row, CqlIdentifier keyspaceId, Map<CqlIdentifier, UserDefinedType> userDefinedTypes) {
    // Cassandra < 3.0:
    // CREATE TABLE system.schema_aggregates (
    // keyspace_name text,
    // aggregate_name text,
    // signature frozen<list<text>>,
    // argument_types list<text>,
    // final_func text,
    // initcond blob,
    // return_type text,
    // state_func text,
    // state_type text,
    // PRIMARY KEY (keyspace_name, aggregate_name, signature)
    // ) WITH CLUSTERING ORDER BY (aggregate_name ASC, signature ASC)
    // 
    // Cassandra >= 3.0:
    // CREATE TABLE system.schema_aggregates (
    // keyspace_name text,
    // aggregate_name text,
    // argument_types frozen<list<text>>,
    // final_func text,
    // initcond text,
    // return_type text,
    // state_func text,
    // state_type text,
    // PRIMARY KEY (keyspace_name, aggregate_name, argument_types)
    // ) WITH CLUSTERING ORDER BY (aggregate_name ASC, argument_types ASC)
    String simpleName = row.getString("aggregate_name");
    List<String> argumentTypes = row.getListOfString("argument_types");
    FunctionSignature signature = new FunctionSignature(CqlIdentifier.fromInternal(simpleName), dataTypeParser.parse(keyspaceId, argumentTypes, userDefinedTypes, context));
    DataType stateType = dataTypeParser.parse(keyspaceId, row.getString("state_type"), userDefinedTypes, context);
    TypeCodec<Object> stateTypeCodec = context.getCodecRegistry().codecFor(stateType);
    String stateFuncSimpleName = row.getString("state_func");
    FunctionSignature stateFuncSignature = new FunctionSignature(CqlIdentifier.fromInternal(stateFuncSimpleName), ImmutableList.<DataType>builder().add(stateType).addAll(signature.getParameterTypes()).build());
    String finalFuncSimpleName = row.getString("final_func");
    FunctionSignature finalFuncSignature = (finalFuncSimpleName == null) ? null : new FunctionSignature(CqlIdentifier.fromInternal(finalFuncSimpleName), stateType);
    DataType returnType = dataTypeParser.parse(keyspaceId, row.getString("return_type"), userDefinedTypes, context);
    Object initCond;
    if (row.isString("initcond")) {
        // Cassandra 3
        String initCondString = row.getString("initcond");
        initCond = (initCondString == null) ? null : stateTypeCodec.parse(initCondString);
    } else {
        // Cassandra 2.2
        ByteBuffer initCondBlob = row.getByteBuffer("initcond");
        initCond = (initCondBlob == null) ? null : stateTypeCodec.decode(initCondBlob, context.getProtocolVersion());
    }
    return new DefaultAggregateMetadata(keyspaceId, signature, finalFuncSignature, initCond, returnType, stateFuncSignature, stateType, stateTypeCodec);
}
Also used : DefaultAggregateMetadata(com.datastax.oss.driver.internal.core.metadata.schema.DefaultAggregateMetadata) DataType(com.datastax.oss.driver.api.core.type.DataType) FunctionSignature(com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature) ByteBuffer(java.nio.ByteBuffer)

Aggregations

FunctionSignature (com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature)1 DataType (com.datastax.oss.driver.api.core.type.DataType)1 DefaultAggregateMetadata (com.datastax.oss.driver.internal.core.metadata.schema.DefaultAggregateMetadata)1 ByteBuffer (java.nio.ByteBuffer)1