public static Function makeToBlobFunction(AbstractType<?> fromType) { String name = fromType.asCQL3Type() + "asblob"; return new NativeScalarFunction(name, BytesType.instance, fromType) { public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer> parameters) { return parameters.get(0); } }; }
public static int typeHashCode(AbstractType<?> t) { return t.asCQL3Type().toString().hashCode(); }
public static List<String> asCQLTypeStringList(List<AbstractType<?>> abstractTypes) { List<String> r = new ArrayList<>(abstractTypes.size()); for (AbstractType<?> abstractType : abstractTypes) r.add(abstractType.asCQL3Type().toString()); return r; }
public static List<String> asCQLTypeStringList(List<AbstractType<?>> abstractTypes) { List<String> r = new ArrayList<>(abstractTypes.size()); for (AbstractType<?> abstractType : abstractTypes) r.add(abstractType.asCQL3Type().toString()); return r; }
public static List<String> asCQLTypeStringList(List<AbstractType<?>> abstractTypes) { List<String> r = new ArrayList<>(abstractTypes.size()); for (AbstractType<?> abstractType : abstractTypes) r.add(abstractType.asCQL3Type().toString()); return r; }
/** * Creates the name of the cast function use to cast to the specified type. * * @param outputType the output type * @return the name of the cast function use to cast to the specified type */ public static String getFunctionName(AbstractType<?> outputType) { return getFunctionName(outputType.asCQL3Type()); }
/** * Creates the name of the cast function use to cast to the specified type. * * @param outputType the output type * @return the name of the cast function use to cast to the specified type */ public static String getFunctionName(AbstractType<?> outputType) { return getFunctionName(outputType.asCQL3Type()); }
@Override public String columnName(List<String> columnNames) { return String.format("cast(%s as %s)", columnNames.get(0), toLowerCaseString(outputType().asCQL3Type())); }
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!(receiver.type instanceof ListType)) throw new InvalidRequestException(String.format("Invalid list literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); ColumnSpecification valueSpec = Lists.valueSpecOf(receiver); for (Term.Raw rt : elements) { if (!rt.testAssignment(keyspace, valueSpec).isAssignable()) throw new InvalidRequestException(String.format("Invalid list literal for %s: value %s is not of type %s", receiver.name, rt, valueSpec.type.asCQL3Type())); } }
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!(receiver.type instanceof ListType)) throw new InvalidRequestException(String.format("Invalid list literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); ColumnSpecification valueSpec = Lists.valueSpecOf(receiver); for (Term.Raw rt : elements) { if (!rt.testAssignment(keyspace, valueSpec).isAssignable()) throw new InvalidRequestException(String.format("Invalid list literal for %s: value %s is not of type %s", receiver.name, rt, valueSpec.type.asCQL3Type())); } }
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!(receiver.type instanceof ListType)) throw new InvalidRequestException(String.format("Invalid list literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); ColumnSpecification valueSpec = Lists.valueSpecOf(receiver); for (Term.Raw rt : elements) { if (!rt.testAssignment(keyspace, valueSpec).isAssignable()) throw new InvalidRequestException(String.format("Invalid list literal for %s: value %s is not of type %s", receiver.name, rt, valueSpec.type.asCQL3Type())); } }
private static void addDroppedColumnToSchemaMutation(CFMetaData table, CFMetaData.DroppedColumn column, Mutation.SimpleBuilder builder) { builder.update(DroppedColumns) .row(table.cfName, column.name) .add("dropped_time", new Date(TimeUnit.MICROSECONDS.toMillis(column.droppedTime))) .add("type", expandUserTypes(column.type).asCQL3Type().toString()); }
private static void addDroppedColumnToSchemaMutation(CFMetaData table, CFMetaData.DroppedColumn column, Mutation.SimpleBuilder builder) { builder.update(DroppedColumns) .row(table.cfName, column.name) .add("dropped_time", new Date(TimeUnit.MICROSECONDS.toMillis(column.droppedTime))) .add("type", expandUserTypes(column.type).asCQL3Type().toString()); }
/** * Returns the Java Driver {@link com.datastax.driver.core.DataType} for the C* internal type. */ public static DataType driverType(AbstractType abstractType) { CQL3Type cqlType = abstractType.asCQL3Type(); String abstractTypeDef = cqlType.getType().toString(); return driverTypeFromAbstractType(abstractTypeDef); }
private static String toCQLAdd(String keyspace, String cf, ColumnDefinition cd) { return String.format("ALTER TABLE %s.%s ADD %s %s%s;", quoteIdentifier(keyspace), quoteIdentifier(cf), quoteIdentifier(cd.name.toString()), cd.type.asCQL3Type().toString(), cd.isStatic() ? " static" : ""); }
public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!term.testAssignment(keyspace, castedSpecOf(keyspace, receiver)).isAssignable()) throw new InvalidRequestException(String.format("Cannot cast value %s to type %s", term, type)); if (!testAssignment(keyspace, receiver).isAssignable()) throw new InvalidRequestException(String.format("Cannot assign value %s to %s of type %s", this, receiver.name, receiver.type.asCQL3Type())); return term.prepare(keyspace, receiver); }
static void addFunctionToSchemaMutation(UDFunction function, Mutation.SimpleBuilder builder) { builder.update(Functions) .row(function.name().name, functionArgumentsList(function)) .add("body", function.body()) .add("language", function.language()) .add("return_type", function.returnType().asCQL3Type().toString()) .add("called_on_null_input", function.isCalledOnNullInput()) .add("argument_names", function.argNames().stream().map((c) -> bbToString(c.bytes)).collect(toList())); }
static void addFunctionToSchemaMutation(UDFunction function, Mutation.SimpleBuilder builder) { builder.update(Functions) .row(function.name().name, functionArgumentsList(function)) .add("body", function.body()) .add("language", function.language()) .add("return_type", function.returnType().asCQL3Type().toString()) .add("called_on_null_input", function.isCalledOnNullInput()) .add("argument_names", function.argNames().stream().map((c) -> bbToString(c.bytes)).collect(toList())); }
static void addFunctionToSchemaMutation(UDFunction function, Mutation.SimpleBuilder builder) { builder.update(Functions) .row(function.name().name, functionArgumentsList(function)) .add("body", function.body()) .add("language", function.language()) .add("return_type", function.returnType().asCQL3Type().toString()) .add("called_on_null_input", function.isCalledOnNullInput()) .add("argument_names", function.argNames().stream().map((c) -> bbToString(c.bytes)).collect(toList())); }
private static void addColumnToSchemaMutation(CFMetaData table, ColumnDefinition column, Mutation.SimpleBuilder builder) { AbstractType<?> type = column.type; if (type instanceof ReversedType) type = ((ReversedType) type).baseType; builder.update(Columns) .row(table.cfName, column.name.toString()) .add("column_name_bytes", column.name.bytes) .add("kind", column.kind.toString().toLowerCase()) .add("position", column.position()) .add("clustering_order", column.clusteringOrder().toString().toLowerCase()) .add("type", type.asCQL3Type().toString()); }