public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!term.isAssignableTo(keyspace, castedSpecOf(keyspace, receiver))) throw new InvalidRequestException(String.format("Cannot cast value %s to type %s", term, type)); if (!isAssignableTo(keyspace, receiver)) throw new InvalidRequestException(String.format("Cannot assign value %s to %s of type %s", this, receiver, receiver.type.asCQL3Type())); return term.prepare(keyspace, receiver); }
@Override public AbstractType<?> getExactTypeIfKnown(String keyspace) { List<AbstractType<?>> types = new ArrayList<>(elements.size()); for (Term.Raw term : elements) { AbstractType<?> type = term.getExactTypeIfKnown(keyspace); if (type == null) return null; types.add(type); } return new TupleType(types); }
sb.append(rel.getValue().getText());
initcond = Terms.asBytes(functionName.keyspace, ival.toString(), stateType);
initcond = Terms.asBytes(functionName.keyspace, ival.toString(), stateType);
initcond = Terms.asBytes(functionName.keyspace, ival.toString(), stateType);
sb.append(rel.getValue().getText());
sb.append(rel.getValue().getText());
public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver) { if (!(receiver.type instanceof MapType)) return AssignmentTestable.TestResult.NOT_ASSIGNABLE; // If there is no elements, we can't say it's an exact match (an empty map if fundamentally polymorphic). if (entries.isEmpty()) return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE; ColumnSpecification keySpec = Maps.keySpecOf(receiver); ColumnSpecification valueSpec = Maps.valueSpecOf(receiver); // It's an exact match if all are exact match, but is not assignable as soon as any is non assignable. AssignmentTestable.TestResult res = AssignmentTestable.TestResult.EXACT_MATCH; for (Pair<Term.Raw, Term.Raw> entry : entries) { AssignmentTestable.TestResult t1 = entry.left.testAssignment(keyspace, keySpec); AssignmentTestable.TestResult t2 = entry.right.testAssignment(keyspace, valueSpec); if (t1 == AssignmentTestable.TestResult.NOT_ASSIGNABLE || t2 == AssignmentTestable.TestResult.NOT_ASSIGNABLE) return AssignmentTestable.TestResult.NOT_ASSIGNABLE; if (t1 != AssignmentTestable.TestResult.EXACT_MATCH || t2 != AssignmentTestable.TestResult.EXACT_MATCH) res = AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE; } return res; }
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!receiver.type.isUDT()) throw new InvalidRequestException(String.format("Invalid user type literal for %s of type %s", receiver, receiver.type.asCQL3Type())); UserType ut = (UserType)receiver.type; for (int i = 0; i < ut.size(); i++) { FieldIdentifier field = ut.fieldName(i); Term.Raw value = entries.get(field); if (value == null) continue; ColumnSpecification fieldSpec = fieldSpecOf(receiver, i); if (!value.testAssignment(keyspace, fieldSpec).isAssignable()) { throw new InvalidRequestException(String.format("Invalid user type literal for %s: field %s is not of type %s", receiver, field, fieldSpec.type.asCQL3Type())); } } }
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!receiver.type.isUDT()) throw new InvalidRequestException(String.format("Invalid user type literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); UserType ut = (UserType)receiver.type; for (int i = 0; i < ut.size(); i++) { FieldIdentifier field = ut.fieldName(i); Term.Raw value = entries.get(field); if (value == null) continue; ColumnSpecification fieldSpec = fieldSpecOf(receiver, i); if (!value.testAssignment(keyspace, fieldSpec).isAssignable()) { throw new InvalidRequestException(String.format("Invalid user type literal for %s: field %s is not of type %s", receiver.name, field, fieldSpec.type.asCQL3Type())); } } }
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!receiver.type.isUDT()) throw new InvalidRequestException(String.format("Invalid user type literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); UserType ut = (UserType)receiver.type; for (int i = 0; i < ut.size(); i++) { FieldIdentifier field = ut.fieldName(i); Term.Raw value = entries.get(field); if (value == null) continue; ColumnSpecification fieldSpec = fieldSpecOf(receiver, i); if (!value.testAssignment(keyspace, fieldSpec).isAssignable()) { throw new InvalidRequestException(String.format("Invalid user type literal for %s: field %s is not of type %s", receiver.name, field, fieldSpec.type.asCQL3Type())); } } }
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!(receiver.type instanceof SetType)) { // We've parsed empty maps as a set literal to break the ambiguity so // handle that case now if ((receiver.type instanceof MapType) && elements.isEmpty()) return; throw new InvalidRequestException(String.format("Invalid set literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); } ColumnSpecification valueSpec = Sets.valueSpecOf(receiver); for (Term.Raw rt : elements) { if (!rt.testAssignment(keyspace, valueSpec).isAssignable()) throw new InvalidRequestException(String.format("Invalid set 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 SetType)) { // We've parsed empty maps as a set literal to break the ambiguity so // handle that case now if ((receiver.type instanceof MapType) && elements.isEmpty()) return; throw new InvalidRequestException(String.format("Invalid set literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); } ColumnSpecification valueSpec = Sets.valueSpecOf(receiver); for (Term.Raw rt : elements) { if (!rt.testAssignment(keyspace, valueSpec).isAssignable()) throw new InvalidRequestException(String.format("Invalid set 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 SetType)) { // We've parsed empty maps as a set literal to break the ambiguity so // handle that case now if ((receiver.type instanceof MapType) && elements.isEmpty()) return; throw new InvalidRequestException(String.format("Invalid set literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); } ColumnSpecification valueSpec = Sets.valueSpecOf(receiver); for (Term.Raw rt : elements) { if (!rt.isAssignableTo(keyspace, valueSpec)) throw new InvalidRequestException(String.format("Invalid set 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.isUDT()) throw new InvalidRequestException(String.format("Invalid user type literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); UserType ut = (UserType)receiver.type; for (int i = 0; i < ut.size(); i++) { FieldIdentifier field = ut.fieldName(i); Term.Raw value = entries.get(field); if (value == null) continue; ColumnSpecification fieldSpec = fieldSpecOf(receiver, i); if (!value.testAssignment(keyspace, fieldSpec).isAssignable()) { throw new InvalidRequestException(String.format("Invalid user type literal for %s: field %s is not of type %s", receiver.name, field, fieldSpec.type.asCQL3Type())); } } }
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { if (!checkIfTupleType(receiver.type)) throw new InvalidRequestException(String.format("Invalid tuple type literal for %s of type %s", receiver.name, receiver.type.asCQL3Type())); TupleType tt = getTupleType(receiver.type); for (int i = 0; i < elements.size(); i++) { if (i >= tt.size()) { throw new InvalidRequestException(String.format("Invalid tuple literal for %s: too many elements. Type %s expects %d but got %d", receiver.name, tt.asCQL3Type(), tt.size(), elements.size())); } Term.Raw value = elements.get(i); ColumnSpecification spec = componentSpecOf(receiver, i); if (!value.testAssignment(keyspace, spec).isAssignable()) throw new InvalidRequestException(String.format("Invalid tuple literal for %s: component %d is not of type %s", receiver.name, i, spec.type.asCQL3Type())); } }