public AbstractType<?> getExactTypeIfKnown(String keyspace) { return function.returnType(); }
protected AbstractType<?> getReturnType() { return fun.returnType(); }
public AbstractType<?> getType() { return fun.returnType(); }
protected AbstractType<?> getReturnType() { return fun.returnType(); }
public AbstractType<?> getType() { return fun.returnType(); }
public AbstractType<?> getType() { return fun.returnType(); }
public AbstractType<?> getExactTypeIfKnown(String keyspace) { return function.returnType(); }
public AbstractType<?> getType() { return fun.returnType(); }
protected AbstractType<?> getReturnType() { return fun.returnType(); }
public AbstractType<?> getExactTypeIfKnown(String keyspace) { return function.returnType(); }
private static Term.Terminal makeTerminal(Function fun, ByteBuffer result, int version) throws InvalidRequestException { if (!(fun.returnType() instanceof CollectionType)) return new Constants.Value(result); switch (((CollectionType)fun.returnType()).kind) { case LIST: return Lists.Value.fromSerialized(result, (ListType)fun.returnType(), version); case SET: return Sets.Value.fromSerialized(result, (SetType)fun.returnType(), version); case MAP: return Maps.Value.fromSerialized(result, (MapType)fun.returnType(), version); } throw new AssertionError(); }
private static Term.Terminal makeTerminal(Function fun, ByteBuffer result, ProtocolVersion version) throws InvalidRequestException { if (result == null) return null; if (fun.returnType().isCollection()) { switch (((CollectionType) fun.returnType()).kind) { case LIST: return Lists.Value.fromSerialized(result, (ListType) fun.returnType(), version); case SET: return Sets.Value.fromSerialized(result, (SetType) fun.returnType(), version); case MAP: return Maps.Value.fromSerialized(result, (MapType) fun.returnType(), version); } } else if (fun.returnType().isUDT()) { return UserTypes.Value.fromSerialized(result, (UserType) fun.returnType()); } return new Constants.Value(result); }
private static Term.Terminal makeTerminal(Function fun, ByteBuffer result, ProtocolVersion version) throws InvalidRequestException { if (fun.returnType().isCollection()) { switch (((CollectionType) fun.returnType()).kind) { case LIST: return Lists.Value.fromSerialized(result, (ListType) fun.returnType(), version); case SET: return Sets.Value.fromSerialized(result, (SetType) fun.returnType(), version); case MAP: return Maps.Value.fromSerialized(result, (MapType) fun.returnType(), version); } } else if (fun.returnType().isUDT()) { return UserTypes.Value.fromSerialized(result, (UserType) fun.returnType()); } return new Constants.Value(result); }
public static AbstractType<?> getReturnType(String functionName, String ksName, String cfName) { List<Function.Factory> factories = declared.get(functionName.toLowerCase()); return factories.isEmpty() ? null // That's ok, we'll complain later : factories.get(0).create(ksName, cfName).returnType(); }
private static String signature(Function fun) { List<AbstractType<?>> args = fun.argsType(); StringBuilder sb = new StringBuilder(); sb.append("("); for (int i = 0; i < args.size(); i++) { if (i > 0) sb.append(", "); sb.append(args.get(i).asCQL3Type()); } sb.append(") -> "); sb.append(fun.returnType().asCQL3Type()); return sb.toString(); }
private static Term.Terminal makeTerminal(Function fun, ByteBuffer result, ProtocolVersion version) throws InvalidRequestException { if (result == null) return null; if (fun.returnType().isCollection()) { switch (((CollectionType) fun.returnType()).kind) { case LIST: return Lists.Value.fromSerialized(result, (ListType) fun.returnType(), version); case SET: return Sets.Value.fromSerialized(result, (SetType) fun.returnType(), version); case MAP: return Maps.Value.fromSerialized(result, (MapType) fun.returnType(), version); } } else if (fun.returnType().isUDT()) { return UserTypes.Value.fromSerialized(result, (UserType) fun.returnType()); } return new Constants.Value(result); }
private static ByteBuffer executeInternal(Function fun, List<ByteBuffer> params) throws InvalidRequestException { ByteBuffer result = fun.execute(params); try { // Check the method didn't lied on it's declared return type if (result != null) fun.returnType().validate(result); return result; } catch (MarshalException e) { throw new RuntimeException(String.format("Return of function %s (%s) is not a valid value for its declared return type %s", fun, ByteBufferUtil.bytesToHex(result), fun.returnType().asCQL3Type())); } }
private static boolean isValidType(String keyspace, Function fun, List<? extends AssignementTestable> providedArgs, ColumnSpecification receiver) throws InvalidRequestException { if (!receiver.type.isValueCompatibleWith(fun.returnType())) return false; if (providedArgs.size() != fun.argsType().size()) return false; for (int i = 0; i < providedArgs.size(); i++) { AssignementTestable provided = providedArgs.get(i); // If the concrete argument is a bind variables, it can have any type. // We'll validate the actually provided value at execution time. if (provided == null) continue; ColumnSpecification expected = makeArgSpec(receiver, fun, i); if (!provided.isAssignableTo(keyspace, expected)) return false; } return true; }
private static void validateTypes(String keyspace, Function fun, List<? extends AssignementTestable> providedArgs, ColumnSpecification receiver) throws InvalidRequestException { if (!receiver.type.isValueCompatibleWith(fun.returnType())) throw new InvalidRequestException(String.format("Type error: cannot assign result of function %s (type %s) to %s (type %s)", fun.name(), fun.returnType().asCQL3Type(), receiver, receiver.type.asCQL3Type())); if (providedArgs.size() != fun.argsType().size()) throw new InvalidRequestException(String.format("Invalid number of arguments in call to function %s: %d required but %d provided", fun.name(), fun.argsType().size(), providedArgs.size())); for (int i = 0; i < providedArgs.size(); i++) { AssignementTestable provided = providedArgs.get(i); // If the concrete argument is a bind variables, it can have any type. // We'll validate the actually provided value at execution time. if (provided == null) continue; ColumnSpecification expected = makeArgSpec(receiver, fun, i); if (!provided.isAssignableTo(keyspace, expected)) throw new InvalidRequestException(String.format("Type error: %s cannot be passed as argument %d of function %s of type %s", provided, i, fun.name(), expected.type.asCQL3Type())); } }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { SelectorFactories factories = SelectorFactories.createFactoriesAndCollectColumnDefinitions(args, function.argTypes(), cfm, defs, boundNames); //lookup first for generic function taking arbitrary types Function fun = GenericFunctionRegistry.getInstance(function.name(), factories.getReturnTypes()); if (fun == null) fun = FunctionResolver.get(cfm.ksName, function.name(), args, cfm.ksName, cfm.cfName, null); if (fun == null) throw new InvalidRequestException(String.format("Unknown function '%s'", function.name())); if (fun.returnType() == null) throw new InvalidRequestException(String.format("Unknown function %s called in selection clause", function.name())); return AbstractFunctionSelector.newFactory(function, factories); }