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; }
public long getLong() { checkState(!isNull()); checkArgument(type.getJavaType() == long.class, "Type %s cannot be read as long", type); return (Long) value; }
public double getDouble() { checkState(!isNull()); checkArgument(type.getJavaType() == double.class, "Type %s cannot be read as double", type); return (Double) value; }
public Slice getSlice() { checkState(!isNull()); checkArgument(type.getJavaType() == Slice.class, "Type %s cannot be read as Slice", type); return (Slice) value; }
@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; }
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<?> clazz) { checkState(!closed, "cursor is closed"); Type type = getType(field); checkArgument(type.getJavaType() == clazz, "Type %s cannot be read as %s", type, clazz.getSimpleName()); }
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()); }
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 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())); } }
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); }
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, 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, 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); }
@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()); }