Search in sources :

Example 1 with DefaultFunctionMetadata

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

the class FunctionParser method parseFunction.

public FunctionMetadata parseFunction(AdminRow row, CqlIdentifier keyspaceId, Map<CqlIdentifier, UserDefinedType> userDefinedTypes) {
    // Cassandra < 3.0:
    // CREATE TABLE system.schema_functions (
    // keyspace_name text,
    // function_name text,
    // signature frozen<list<text>>,
    // argument_names list<text>,
    // argument_types list<text>,
    // body text,
    // called_on_null_input boolean,
    // language text,
    // return_type text,
    // PRIMARY KEY (keyspace_name, function_name, signature)
    // ) WITH CLUSTERING ORDER BY (function_name ASC, signature ASC)
    // 
    // Cassandra >= 3.0:
    // CREATE TABLE system_schema.functions (
    // keyspace_name text,
    // function_name text,
    // argument_names frozen<list<text>>,
    // argument_types frozen<list<text>>,
    // body text,
    // called_on_null_input boolean,
    // language text,
    // return_type text,
    // PRIMARY KEY (keyspace_name, function_name, argument_types)
    // ) WITH CLUSTERING ORDER BY (function_name ASC, argument_types ASC)
    String simpleName = row.getString("function_name");
    List<CqlIdentifier> argumentNames = ImmutableList.copyOf(Lists.transform(row.getListOfString("argument_names"), CqlIdentifier::fromInternal));
    List<String> argumentTypes = row.getListOfString("argument_types");
    if (argumentNames.size() != argumentTypes.size()) {
        LOG.warn("[{}] Error parsing system row for function {}.{}, " + "number of argument names and types don't match (got {} and {}).", logPrefix, keyspaceId.asInternal(), simpleName, argumentNames.size(), argumentTypes.size());
        return null;
    }
    FunctionSignature signature = new FunctionSignature(CqlIdentifier.fromInternal(simpleName), dataTypeParser.parse(keyspaceId, argumentTypes, userDefinedTypes, context));
    String body = row.getString("body");
    Boolean calledOnNullInput = row.getBoolean("called_on_null_input");
    String language = row.getString("language");
    DataType returnType = dataTypeParser.parse(keyspaceId, row.getString("return_type"), userDefinedTypes, context);
    return new DefaultFunctionMetadata(keyspaceId, signature, argumentNames, body, calledOnNullInput, language, returnType);
}
Also used : DefaultFunctionMetadata(com.datastax.oss.driver.internal.core.metadata.schema.DefaultFunctionMetadata) DataType(com.datastax.oss.driver.api.core.type.DataType) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) FunctionSignature(com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature)

Aggregations

CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 FunctionSignature (com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature)1 DataType (com.datastax.oss.driver.api.core.type.DataType)1 DefaultFunctionMetadata (com.datastax.oss.driver.internal.core.metadata.schema.DefaultFunctionMetadata)1