public static boolean isSupportedLiteralType(Type type) { return SUPPORTED_LITERAL_TYPES.contains(type.getJavaType()); }
private void validateType(int fieldId, Class<?> type) { if (!types[fieldId].getJavaType().equals(type)) { // we don't use Preconditions.checkArgument because it requires boxing fieldId, which affects inner loop performance throw new IllegalArgumentException(String.format("Expected field to be %s, actual %s (field %s)", type, types[fieldId], fieldId)); } }
public NullableValue(Type type, Object value) { requireNonNull(type, "type is null"); if (value != null && !Primitives.wrap(type.getJavaType()).isInstance(value)) { throw new IllegalArgumentException(String.format("Object '%s' does not match type %s", value, type.getJavaType())); } this.type = type; this.value = value; }
private void checkFieldType(int field, Class<?> expected) { Class<?> actual = getType(field).getJavaType(); checkArgument(actual == expected, "Expected field %s to be type %s but is %s", field, expected, actual); }
private void checkFieldType(int field, Class<?> expected) { Class<?> actual = getType(field).getJavaType(); checkArgument(actual == expected, "Expected field %s to be type %s but is %s", field, expected, actual); }
@Override public boolean containsValue(Object value) { if (!Primitives.wrap(type.getJavaType()).isInstance(value)) { throw new IllegalArgumentException(String.format("Value class %s does not match required Type class %s", value.getClass().getName(), Primitives.wrap(type.getJavaType()).getClass().getName())); } return all; }
public AppendingRecordSet(RecordSet delegate, List<Object> appendedValues, List<Type> appendedTypes) { this.delegate = requireNonNull(delegate, "delegate is null"); this.appendedValues = new ArrayList<>(requireNonNull(appendedValues, "appendedValues is null")); // May contain null elements this.appendedTypes = ImmutableList.copyOf(requireNonNull(appendedTypes, "appendedTypes is null")); checkArgument(appendedValues.size() == appendedTypes.size(), "appendedValues must have the same size as appendedTypes"); for (int i = 0; i < appendedValues.size(); i++) { Object value = appendedValues.get(i); if (value != null) { checkArgument(Primitives.wrap(appendedTypes.get(i).getJavaType()).isInstance(value), "Object value does not match declared type"); } } }
private ReadMapping(Type type, ReadFunction readFunction) { this.type = requireNonNull(type, "type is null"); this.readFunction = requireNonNull(readFunction, "readFunction is null"); checkArgument( type.getJavaType() == readFunction.getJavaType(), "Presto type %s is not compatible with read function %s returning %s", type, readFunction, readFunction.getJavaType()); }
public static Block nativeValueToBlock(Type type, Object object) { if (object != null && !Primitives.wrap(type.getJavaType()).isInstance(object)) { throw new IllegalArgumentException(String.format("Object '%s' does not match type %s", object, type.getJavaType())); } BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); writeNativeValue(type, blockBuilder, object); return blockBuilder.build(); }
@Override public Block toBlock(Type desiredType) { checkArgument(desiredType.getJavaType() == Slice.class, "type doesn't match: %s", desiredType); Slice values = bytes == null ? Slices.EMPTY_SLICE : Slices.wrappedBuffer(bytes); int numberOfRecords = numberOfRecords(); return new VariableWidthBlock( numberOfRecords, values, calculateOffsets(sizes, nulls, numberOfRecords), Optional.ofNullable(nulls)); }
private static List<ParameterMetadata> createParameterMetadata(Type type) { if (type.getJavaType().isPrimitive()) { return ImmutableList.of( new ParameterMetadata(STATE), new ParameterMetadata(INPUT_CHANNEL, type)); } else { return ImmutableList.of( new ParameterMetadata(STATE), new ParameterMetadata(BLOCK_INPUT_CHANNEL, type), new ParameterMetadata(BLOCK_INDEX)); } }
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { checkArgument(boundVariables.getTypeVariables().size() == 1, "Expected only one type"); Type type = boundVariables.getTypeVariable("T"); MethodHandle identity = MethodHandles.identity(type.getJavaType()); return new ScalarFunctionImplementation( false, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), identity, isDeterministic()); } }
private RedisFieldDecoder<String> chooseFieldDecoder(DecoderColumnHandle column) { checkArgument(!column.isInternal(), "unexpected internal column '%s'", column.getName()); if (column.getDataFormat() == null) { return new HashRedisFieldDecoder(); } if (column.getType().getJavaType() == long.class && "iso8601".equals(column.getDataFormat())) { return new ISO8601HashRedisFieldDecoder(); } throw new IllegalArgumentException(format("unknown data format '%s' for column '%s'", column.getDataFormat(), column.getName())); } }
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { checkArgument(arity == 1, "Expected arity to be 1"); Type type = boundVariables.getTypeVariable("T"); Class<?> indeterminateOperatorClass = generateIndeterminate(type, functionRegistry); MethodHandle indeterminateMethod = methodHandle(indeterminateOperatorClass, "indeterminate", type.getJavaType(), boolean.class); return new ScalarFunctionImplementation( false, ImmutableList.of(valueTypeArgumentProperty(USE_NULL_FLAG)), indeterminateMethod, isDeterministic()); }
public void assertDecodedAs(String jsonValue, Type type, boolean expectedValue) { checkArgument(type.getJavaType() == boolean.class, "Wrong (not boolean based) presto type '%s'", type); FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type); assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type)); assertEquals(decodedValue.getBoolean(), expectedValue); }
public void assertDecodedAs(String jsonValue, Type type, Slice expectedValue) { checkArgument(type.getJavaType() == Slice.class, "Wrong (not Slice based) presto type '%s'", type); FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type); assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type)); assertEquals(decodedValue.getSlice(), expectedValue); }
public void assertDecodedAs(String jsonValue, Type type, long expectedValue) { checkArgument(type.getJavaType() == long.class, "Wrong (not long based) presto type '%s'", type); FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type); assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type)); assertEquals(decodedValue.getLong(), expectedValue); }
public void assertDecodedAs(String jsonValue, Type type, double expectedValue) { checkArgument(type.getJavaType() == double.class, "Wrong (not double based) presto type '%s'", type); FieldValueProvider decodedValue = decode(Optional.of(jsonValue), type); assertFalse(decodedValue.isNull(), format("expected non null when decoding %s as %s", jsonValue, type)); assertEquals(decodedValue.getDouble(), expectedValue); }
@Override public ScalarFunctionImplementation specialize( BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type toType = boundVariables.getTypeVariable("E"); MethodHandle methodHandle = METHOD_HANDLE_NON_NULL.asType(METHOD_HANDLE_NON_NULL.type().changeReturnType(toType.getJavaType())); return new ScalarFunctionImplementation( false, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle, isDeterministic()); }
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type returnType = boundVariables.getTypeVariable("T"); return new ScalarFunctionImplementation( true, ImmutableList.of(functionTypeArgumentProperty(InvokeLambda.class)), METHOD_HANDLE.asType( METHOD_HANDLE.type() .changeReturnType(wrap(returnType.getJavaType()))), isDeterministic()); }