io.prestosql.spi.type.DoubleType Java Examples
The following examples show how to use
io.prestosql.spi.type.DoubleType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAnnotationEngineForAggregates.java From presto with Apache License 2.0 | 6 votes |
@Test public void testFixedTypeParameterInjectionAggregateFunctionParse() { Signature expectedSignature = new Signature( "fixed_type_parameter_injection", ImmutableList.of(), ImmutableList.of(), DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()), false); ParametricAggregation aggregation = parseFunctionDefinition(FixedTypeParameterInjectionAggregateFunction.class); assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with fixed parameter type injected"); assertTrue(aggregation.getFunctionMetadata().isDeterministic()); assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature); ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations(); assertImplementationCount(implementations, 1, 0, 0); AggregationImplementation implementationDouble = implementations.getExactImplementations().get(expectedSignature); assertFalse(implementationDouble.getStateSerializerFactory().isPresent()); assertEquals(implementationDouble.getDefinitionClass(), FixedTypeParameterInjectionAggregateFunction.class); assertDependencyCount(implementationDouble, 1, 1, 1); assertFalse(implementationDouble.hasSpecializedTypeParameters()); List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL); assertTrue(implementationDouble.getInputParameterMetadataTypes().equals(expectedMetadataTypes)); assertEquals(implementationDouble.getStateClass(), NullableDoubleState.class); }
Example #2
Source File: DoubleHistogramAggregation.java From presto with Apache License 2.0 | 6 votes |
@OutputFunction("map(double,double)") public static void output(@AggregationState State state, BlockBuilder out) { if (state.get() == null) { out.appendNull(); } else { Map<Double, Double> value = state.get().getBuckets(); BlockBuilder entryBuilder = out.beginBlockEntry(); for (Map.Entry<Double, Double> entry : value.entrySet()) { DoubleType.DOUBLE.writeDouble(entryBuilder, entry.getKey()); DoubleType.DOUBLE.writeDouble(entryBuilder, entry.getValue()); } out.closeEntry(); } }
Example #3
Source File: TestPrometheusIntegrationTests1.java From presto with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "testRetrieveUpValue") public void testGetColumnTypes() throws Exception { URI dataUri = new URI("http://" + server.getAddress().getHost() + ":" + server.getAddress().getPort() + "/"); RecordSet recordSet = new PrometheusRecordSet(new PrometheusSplit(dataUri), ImmutableList.of( new PrometheusColumnHandle("labels", createUnboundedVarcharType(), 0), new PrometheusColumnHandle("value", DoubleType.DOUBLE, 1), new PrometheusColumnHandle("timestamp", TimestampType.TIMESTAMP, 2))); assertEquals(recordSet.getColumnTypes(), ImmutableList.of(createUnboundedVarcharType(), DoubleType.DOUBLE, TimestampType.TIMESTAMP)); recordSet = new PrometheusRecordSet(new PrometheusSplit(dataUri), ImmutableList.of( new PrometheusColumnHandle("value", BIGINT, 1), new PrometheusColumnHandle("text", createUnboundedVarcharType(), 0))); assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, createUnboundedVarcharType())); recordSet = new PrometheusRecordSet(new PrometheusSplit(dataUri), ImmutableList.of( new PrometheusColumnHandle("value", BIGINT, 1), new PrometheusColumnHandle("value", BIGINT, 1), new PrometheusColumnHandle("text", createUnboundedVarcharType(), 0))); assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, BIGINT, createUnboundedVarcharType())); recordSet = new PrometheusRecordSet(new PrometheusSplit(dataUri), ImmutableList.of()); assertEquals(recordSet.getColumnTypes(), ImmutableList.of()); }
Example #4
Source File: TestCsvDecoder.java From presto with Apache License 2.0 | 6 votes |
@Test public void testNulls() { String csv = ",,,"; DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", createVarcharType(10), "0", null, null, false, false, false); DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", BigintType.BIGINT, "1", null, null, false, false, false); DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", DoubleType.DOUBLE, "2", null, null, false, false, false); DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", BooleanType.BOOLEAN, "3", null, null, false, false, false); Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4); RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns); Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null) .orElseThrow(AssertionError::new); assertEquals(decodedRow.size(), columns.size()); checkIsNull(decodedRow, row1); checkIsNull(decodedRow, row2); checkIsNull(decodedRow, row3); checkIsNull(decodedRow, row4); }
Example #5
Source File: TestCsvDecoder.java From presto with Apache License 2.0 | 6 votes |
@Test public void testSupportedDataTypeValidation() { // supported types singleColumnDecoder(BigintType.BIGINT); singleColumnDecoder(IntegerType.INTEGER); singleColumnDecoder(SmallintType.SMALLINT); singleColumnDecoder(TinyintType.TINYINT); singleColumnDecoder(BooleanType.BOOLEAN); singleColumnDecoder(DoubleType.DOUBLE); singleColumnDecoder(createUnboundedVarcharType()); singleColumnDecoder(createVarcharType(100)); // some unsupported types assertUnsupportedColumnTypeException(() -> singleColumnDecoder(RealType.REAL)); assertUnsupportedColumnTypeException(() -> singleColumnDecoder(DecimalType.createDecimalType(10, 4))); assertUnsupportedColumnTypeException(() -> singleColumnDecoder(VarbinaryType.VARBINARY)); }
Example #6
Source File: TestRawDecoder.java From presto with Apache License 2.0 | 6 votes |
private void checkTwice(Map<DecoderColumnHandle, FieldValueProvider> decodedRow, DecoderColumnHandle handle) { FieldValueProvider provider = decodedRow.get(handle); assertNotNull(provider); Type type = handle.getType(); if (type == BigintType.BIGINT) { assertEquals(provider.getLong(), provider.getLong()); } else if (type == BooleanType.BOOLEAN) { assertEquals(provider.getBoolean(), provider.getBoolean()); } else if (type == DoubleType.DOUBLE) { assertEquals(provider.getDouble(), provider.getDouble()); } else if (type == VarcharType.VARCHAR) { assertEquals(provider.getSlice(), provider.getSlice()); } }
Example #7
Source File: TestRawDecoder.java From presto with Apache License 2.0 | 6 votes |
@Test public void testSupportedDataTypeValidation() { // supported types singleColumnDecoder(BigintType.BIGINT, "0", "LONG"); singleColumnDecoder(IntegerType.INTEGER, "0", "INT"); singleColumnDecoder(SmallintType.SMALLINT, "0", "SHORT"); singleColumnDecoder(TinyintType.TINYINT, "0", "BYTE"); singleColumnDecoder(BooleanType.BOOLEAN, "0", "LONG"); singleColumnDecoder(DoubleType.DOUBLE, "0", "DOUBLE"); singleColumnDecoder(createUnboundedVarcharType(), "0", "BYTE"); singleColumnDecoder(createVarcharType(100), "0", "BYTE"); // some unsupported types assertUnsupportedColumnTypeException(() -> singleColumnDecoder(RealType.REAL, "0", "BYTE")); assertUnsupportedColumnTypeException(() -> singleColumnDecoder(DecimalType.createDecimalType(10, 4), "0", "BYTE")); assertUnsupportedColumnTypeException(() -> singleColumnDecoder(VarbinaryType.VARBINARY, "0", "BYTE")); }
Example #8
Source File: TestAvroDecoder.java From presto with Apache License 2.0 | 6 votes |
@Test public void testSupportedDataTypeValidation() { // supported types singleColumnDecoder(BigintType.BIGINT); singleColumnDecoder(VarbinaryType.VARBINARY); singleColumnDecoder(BooleanType.BOOLEAN); singleColumnDecoder(DoubleType.DOUBLE); singleColumnDecoder(createUnboundedVarcharType()); singleColumnDecoder(createVarcharType(100)); singleColumnDecoder(new ArrayType(BigintType.BIGINT)); singleColumnDecoder(VARCHAR_MAP_TYPE); singleColumnDecoder(DOUBLE_MAP_TYPE); // some unsupported types assertUnsupportedColumnTypeException(() -> singleColumnDecoder(DecimalType.createDecimalType(10, 4))); }
Example #9
Source File: SessionPropertyManager.java From presto with Apache License 2.0 | 6 votes |
public static String serializeSessionProperty(Type type, Object value) { if (value == null) { throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property cannot be null"); } if (BooleanType.BOOLEAN.equals(type)) { return value.toString(); } if (BigintType.BIGINT.equals(type)) { return value.toString(); } if (IntegerType.INTEGER.equals(type)) { return value.toString(); } if (DoubleType.DOUBLE.equals(type)) { return value.toString(); } if (VarcharType.VARCHAR.equals(type)) { return value.toString(); } if (type instanceof ArrayType || type instanceof MapType) { return getJsonCodecForType(type).toJson(value); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
Example #10
Source File: SessionPropertyManager.java From presto with Apache License 2.0 | 6 votes |
private static Class<?> getMapKeyType(Type type) { if (VarcharType.VARCHAR.equals(type)) { return String.class; } if (BooleanType.BOOLEAN.equals(type)) { return Boolean.class; } if (BigintType.BIGINT.equals(type)) { return Long.class; } if (IntegerType.INTEGER.equals(type)) { return Integer.class; } if (DoubleType.DOUBLE.equals(type)) { return Double.class; } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property map key type %s is not supported", type)); }
Example #11
Source File: PrometheusClient.java From presto with Apache License 2.0 | 6 votes |
public PrometheusTable getTable(String schema, String tableName) { requireNonNull(schema, "schema is null"); requireNonNull(tableName, "tableName is null"); if (schema.equals("default")) { List<String> tableNames = (List<String>) tableSupplier.get().get("data"); if (tableNames == null) { return null; } if (!tableNames.contains(tableName)) { return null; } MapType varcharMapType = (MapType) typeManager.getType(mapType(VARCHAR.getTypeSignature(), VARCHAR.getTypeSignature())); PrometheusTable table = new PrometheusTable( tableName, ImmutableList.of( new PrometheusColumn("labels", varcharMapType), new PrometheusColumn("timestamp", TimestampType.TIMESTAMP), new PrometheusColumn("value", DoubleType.DOUBLE))); PrometheusTableHandle tableHandle = new PrometheusTableHandle(schema, tableName); return table; } return null; }
Example #12
Source File: TestAnnotationEngineForAggregates.java From presto with Apache License 2.0 | 6 votes |
@Test public void testNotDecomposableAggregationParse() { Signature expectedSignature = new Signature( "custom_decomposable_aggregate", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature())); ParametricAggregation aggregation = parseFunctionDefinition(NotDecomposableAggregationFunction.class); assertEquals(aggregation.getFunctionMetadata().getDescription(), "Aggregate with Decomposable=false"); assertTrue(aggregation.getFunctionMetadata().isDeterministic()); assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature); assertFalse(aggregation.isDecomposable()); InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().build(), 1, METADATA); assertEquals(specialized.getFinalType(), DoubleType.DOUBLE); assertEquals(specialized.name(), "custom_decomposable_aggregate"); }
Example #13
Source File: MLFeaturesFunctions.java From presto with Apache License 2.0 | 6 votes |
private static Block featuresHelper(PageBuilder pageBuilder, double... features) { if (pageBuilder.isFull()) { pageBuilder.reset(); } BlockBuilder mapBlockBuilder = pageBuilder.getBlockBuilder(0); BlockBuilder blockBuilder = mapBlockBuilder.beginBlockEntry(); for (int i = 0; i < features.length; i++) { BigintType.BIGINT.writeLong(blockBuilder, i); DoubleType.DOUBLE.writeDouble(blockBuilder, features[i]); } mapBlockBuilder.closeEntry(); pageBuilder.declarePosition(); return mapBlockBuilder.getObject(mapBlockBuilder.getPositionCount() - 1, Block.class); }
Example #14
Source File: TestAnnotationEngineForAggregates.java From presto with Apache License 2.0 | 6 votes |
@Test public void testStateOnDifferentThanFirstPositionAggregationParse() { Signature expectedSignature = new Signature( "simple_exact_aggregate_aggregation_state_moved", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature())); ParametricAggregation aggregation = parseFunctionDefinition(StateOnDifferentThanFirstPositionAggregationFunction.class); assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature); AggregationImplementation implementation = getOnlyElement(aggregation.getImplementations().getExactImplementations().values()); assertEquals(implementation.getDefinitionClass(), StateOnDifferentThanFirstPositionAggregationFunction.class); List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL, AggregationMetadata.ParameterMetadata.ParameterType.STATE); assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes)); }
Example #15
Source File: JsonUtil.java From presto with Apache License 2.0 | 6 votes |
public static boolean canCastFromJson(Type type) { if (type instanceof BooleanType || type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType || type instanceof RealType || type instanceof DoubleType || type instanceof DecimalType || type instanceof VarcharType || type instanceof JsonType) { return true; } if (type instanceof ArrayType) { return canCastFromJson(((ArrayType) type).getElementType()); } if (type instanceof MapType) { return isValidJsonObjectKeyType(((MapType) type).getKeyType()) && canCastFromJson(((MapType) type).getValueType()); } if (type instanceof RowType) { return type.getTypeParameters().stream().allMatch(JsonUtil::canCastFromJson); } return false; }
Example #16
Source File: PinotColumn.java From presto with Apache License 2.0 | 6 votes |
public static Type getPrestoTypeFromPinotType(DataType dataType) { switch (dataType) { case BOOLEAN: return BooleanType.BOOLEAN; case FLOAT: case DOUBLE: return DoubleType.DOUBLE; case INT: return IntegerType.INTEGER; case LONG: return BigintType.BIGINT; case STRING: return VarcharType.VARCHAR; case BYTES: return VarbinaryType.VARBINARY; default: break; } throw new PinotException(PINOT_UNSUPPORTED_COLUMN_TYPE, Optional.empty(), "Not support type conversion for pinot data type: " + dataType); }
Example #17
Source File: SessionPropertyManager.java From presto with Apache License 2.0 | 6 votes |
private static Object deserializeSessionProperty(Type type, String value) { if (value == null) { throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property cannot be null"); } if (VarcharType.VARCHAR.equals(type)) { return value; } if (BooleanType.BOOLEAN.equals(type)) { return Boolean.valueOf(value); } if (BigintType.BIGINT.equals(type)) { return Long.valueOf(value); } if (IntegerType.INTEGER.equals(type)) { return Integer.valueOf(value); } if (DoubleType.DOUBLE.equals(type)) { return Double.valueOf(value); } if (type instanceof ArrayType || type instanceof MapType) { return getJsonCodecForType(type).fromJson(value); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
Example #18
Source File: BenchmarkDecimalOperators.java From presto with Apache License 2.0 | 5 votes |
private Object generateRandomValue(Type type) { if (type instanceof DoubleType) { return random.nextDouble() * (2L * doubleMaxValue) - doubleMaxValue; } if (type instanceof DecimalType) { return randomDecimal((DecimalType) type); } if (type instanceof BigintType) { int randomInt = random.nextInt(); return randomInt == 0 ? 1 : randomInt; } throw new UnsupportedOperationException(type.toString()); }
Example #19
Source File: TestAnnotationEngineForAggregates.java From presto with Apache License 2.0 | 5 votes |
@Test public void testPartiallyFixedTypeParameterInjectionAggregateFunctionParse() { Signature expectedSignature = new Signature( "partially_fixed_type_parameter_injection", ImmutableList.of(typeVariable("T1"), typeVariable("T2")), ImmutableList.of(), DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()), false); ParametricAggregation aggregation = parseFunctionDefinition(PartiallyFixedTypeParameterInjectionAggregateFunction.class); assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with fixed parameter type injected"); assertTrue(aggregation.getFunctionMetadata().isDeterministic()); assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature); assertTrue(aggregation.isDecomposable()); ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations(); assertImplementationCount(implementations, 0, 0, 1); AggregationImplementation implementationDouble = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableDoubleState.class).collect(toImmutableList()).get(0); assertFalse(implementationDouble.getStateSerializerFactory().isPresent()); assertEquals(implementationDouble.getDefinitionClass(), PartiallyFixedTypeParameterInjectionAggregateFunction.class); assertDependencyCount(implementationDouble, 1, 1, 1); assertFalse(implementationDouble.hasSpecializedTypeParameters()); List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL); assertTrue(implementationDouble.getInputParameterMetadataTypes().equals(expectedMetadataTypes)); assertEquals(implementationDouble.getStateClass(), NullableDoubleState.class); InternalAggregationFunction specialized = aggregation.specialize( BoundVariables.builder().setTypeVariable("T1", DoubleType.DOUBLE).setTypeVariable("T2", DoubleType.DOUBLE).build(), 1, METADATA); assertEquals(specialized.getFinalType(), DoubleType.DOUBLE); assertTrue(specialized.getParameterTypes().equals(ImmutableList.of(DoubleType.DOUBLE))); assertEquals(specialized.name(), "partially_fixed_type_parameter_injection"); }
Example #20
Source File: ShardStats.java From presto with Apache License 2.0 | 5 votes |
private static ColumnStats doComputeColumnStats(OrcReader orcReader, long columnId, Type type, TypeManager typeManager) throws IOException { OrcColumn column = getColumn(orcReader.getRootColumn().getNestedColumns(), columnId); Type columnType = toOrcFileType(type, typeManager); OrcRecordReader reader = orcReader.createRecordReader( ImmutableList.of(column), ImmutableList.of(columnType), OrcPredicate.TRUE, UTC, newSimpleAggregatedMemoryContext(), INITIAL_BATCH_SIZE, exception -> new PrestoException(RAPTOR_ERROR, "Error reading column: " + columnId, exception)); if (type.equals(BooleanType.BOOLEAN)) { return indexBoolean(reader, columnId); } if (type.equals(BigintType.BIGINT) || type.equals(DateType.DATE) || type.equals(TimestampType.TIMESTAMP)) { return indexLong(type, reader, columnId); } if (type.equals(DoubleType.DOUBLE)) { return indexDouble(reader, columnId); } if (type instanceof VarcharType) { return indexString(type, reader, columnId); } return null; }
Example #21
Source File: TestPrometheusTable.java From presto with Apache License 2.0 | 5 votes |
@Test public void testColumnMetadata() { assertEquals(prometheusTable.getColumnsMetadata(), ImmutableList.of( new ColumnMetadata("labels", varcharMapType), new ColumnMetadata("timestamp", TimestampType.TIMESTAMP), new ColumnMetadata("value", DoubleType.DOUBLE))); }
Example #22
Source File: TestCsvDecoder.java From presto with Apache License 2.0 | 5 votes |
@Test public void testLessTokensThanColumns() { String csv = "ala,10"; DecoderTestColumnHandle column1 = new DecoderTestColumnHandle(0, "column1", createVarcharType(10), "0", null, null, false, false, false); DecoderTestColumnHandle column2 = new DecoderTestColumnHandle(1, "column2", BigintType.BIGINT, "1", null, null, false, false, false); DecoderTestColumnHandle column3 = new DecoderTestColumnHandle(2, "column3", createVarcharType(10), "2", null, null, false, false, false); DecoderTestColumnHandle column4 = new DecoderTestColumnHandle(0, "column4", BigintType.BIGINT, "3", null, null, false, false, false); DecoderTestColumnHandle column5 = new DecoderTestColumnHandle(0, "column5", DoubleType.DOUBLE, "4", null, null, false, false, false); DecoderTestColumnHandle column6 = new DecoderTestColumnHandle(0, "column6", BooleanType.BOOLEAN, "5", null, null, false, false, false); Set<DecoderColumnHandle> columns = ImmutableSet.of(column1, column2, column3, column4, column5, column6); RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns); Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null) .orElseThrow(AssertionError::new); assertEquals(decodedRow.size(), columns.size()); checkValue(decodedRow, column1, "ala"); checkValue(decodedRow, column2, 10); checkIsNull(decodedRow, column3); checkIsNull(decodedRow, column4); checkIsNull(decodedRow, column5); checkIsNull(decodedRow, column6); }
Example #23
Source File: TestAnnotationEngineForAggregates.java From presto with Apache License 2.0 | 5 votes |
@Test public void testInjectTypeAggregateParse() { Signature expectedSignature = new Signature( "inject_type_aggregate", ImmutableList.of(typeVariable("T")), ImmutableList.of(), new TypeSignature("T"), ImmutableList.of(new TypeSignature("T")), false); ParametricAggregation aggregation = parseFunctionDefinition(InjectTypeAggregateFunction.class); assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with type injected"); assertTrue(aggregation.getFunctionMetadata().isDeterministic()); assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature); assertTrue(aggregation.isDecomposable()); ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations(); assertEquals(implementations.getGenericImplementations().size(), 1); AggregationImplementation implementation = implementations.getGenericImplementations().get(0); assertTrue(implementation.getStateSerializerFactory().isPresent()); assertEquals(implementation.getDefinitionClass(), InjectTypeAggregateFunction.class); assertDependencyCount(implementation, 1, 1, 1); assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1); assertTrue(implementation.getInputDependencies().get(0) instanceof TypeImplementationDependency); assertTrue(implementation.getCombineDependencies().get(0) instanceof TypeImplementationDependency); assertTrue(implementation.getOutputDependencies().get(0) instanceof TypeImplementationDependency); assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof TypeImplementationDependency); assertFalse(implementation.hasSpecializedTypeParameters()); List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL); assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes)); InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, METADATA); assertEquals(specialized.getFinalType(), DoubleType.DOUBLE); assertEquals(specialized.name(), "inject_type_aggregate"); }
Example #24
Source File: TypeHelper.java From presto with Apache License 2.0 | 5 votes |
public static Object getObject(Type type, RowResult row, int field) { if (row.isNull(field)) { return null; } if (type instanceof VarcharType) { return row.getString(field); } if (type.equals(TimestampType.TIMESTAMP)) { return row.getLong(field) / 1000; } if (type == BigintType.BIGINT) { return row.getLong(field); } if (type == IntegerType.INTEGER) { return row.getInt(field); } if (type == SmallintType.SMALLINT) { return row.getShort(field); } if (type == TinyintType.TINYINT) { return row.getByte(field); } if (type == DoubleType.DOUBLE) { return row.getDouble(field); } if (type == RealType.REAL) { return row.getFloat(field); } if (type == BooleanType.BOOLEAN) { return row.getBoolean(field); } if (type instanceof VarbinaryType) { return Slices.wrappedBuffer(row.getBinary(field)); } if (type instanceof DecimalType) { return row.getDecimal(field); } throw new IllegalStateException("getObject not implemented for " + type); }
Example #25
Source File: Marker.java From presto with Apache License 2.0 | 5 votes |
/** * LOWER UNBOUNDED is specified with an empty value and a ABOVE bound * UPPER UNBOUNDED is specified with an empty value and a BELOW bound */ @JsonCreator public Marker( @JsonProperty("type") Type type, @JsonProperty("valueBlock") Optional<Block> valueBlock, @JsonProperty("bound") Bound bound) { requireNonNull(type, "type is null"); requireNonNull(valueBlock, "valueBlock is null"); requireNonNull(bound, "bound is null"); if (!type.isOrderable()) { throw new IllegalArgumentException("type must be orderable"); } if (valueBlock.isEmpty() && bound == Bound.EXACTLY) { throw new IllegalArgumentException("Cannot be equal to unbounded"); } if (valueBlock.isPresent() && valueBlock.get().getPositionCount() != 1) { throw new IllegalArgumentException("value block should only have one position"); } if (type instanceof RealType && valueBlock.isPresent() && Float.isNaN(intBitsToFloat(toIntExact((long) blockToNativeValue(type, valueBlock.get()))))) { throw new IllegalArgumentException("cannot use Real NaN as range bound"); } if (type instanceof DoubleType && valueBlock.isPresent() && Double.isNaN((double) blockToNativeValue(type, valueBlock.get()))) { throw new IllegalArgumentException("cannot use Double NaN as range bound"); } this.type = type; this.valueBlock = valueBlock; this.bound = bound; }
Example #26
Source File: IcebergPageSink.java From presto with Apache License 2.0 | 5 votes |
public static Object getIcebergValue(Block block, int position, Type type) { if (block.isNull(position)) { return null; } if (type instanceof BigintType) { return type.getLong(block, position); } if (type instanceof IntegerType || type instanceof SmallintType || type instanceof TinyintType || type instanceof DateType) { return toIntExact(type.getLong(block, position)); } if (type instanceof BooleanType) { return type.getBoolean(block, position); } if (type instanceof DecimalType) { return readBigDecimal((DecimalType) type, block, position); } if (type instanceof RealType) { return intBitsToFloat(toIntExact(type.getLong(block, position))); } if (type instanceof DoubleType) { return type.getDouble(block, position); } if (type instanceof TimestampType) { return MILLISECONDS.toMicros(type.getLong(block, position)); } if (type instanceof TimestampWithTimeZoneType) { return MILLISECONDS.toMicros(unpackMillisUtc(type.getLong(block, position))); } if (type instanceof VarbinaryType) { return type.getSlice(block, position).getBytes(); } if (type instanceof VarcharType) { return type.getSlice(block, position).toStringUtf8(); } throw new UnsupportedOperationException("Type not supported as partition column: " + type.getDisplayName()); }
Example #27
Source File: AvroColumnDecoder.java From presto with Apache License 2.0 | 5 votes |
private static void serializePrimitive(BlockBuilder blockBuilder, Object value, Type type, String columnName) { requireNonNull(blockBuilder, "parent blockBuilder is null"); if (value == null) { blockBuilder.appendNull(); return; } if (type instanceof BooleanType) { type.writeBoolean(blockBuilder, (Boolean) value); return; } if ((value instanceof Integer || value instanceof Long) && (type instanceof BigintType || type instanceof IntegerType || type instanceof SmallintType || type instanceof TinyintType)) { type.writeLong(blockBuilder, ((Number) value).longValue()); return; } if (type instanceof DoubleType) { type.writeDouble(blockBuilder, (Double) value); return; } if (type instanceof RealType) { type.writeLong(blockBuilder, floatToIntBits((Float) value)); return; } if (type instanceof VarcharType || type instanceof VarbinaryType) { type.writeSlice(blockBuilder, getSlice(value, type, columnName)); return; } throw new PrestoException(DECODER_CONVERSION_NOT_SUPPORTED, format("cannot decode object of '%s' as '%s' for column '%s'", value.getClass(), type, columnName)); }
Example #28
Source File: DecoderFactory.java From presto with Apache License 2.0 | 5 votes |
public static Decoder createDecoder(Type type) { requireNonNull(type, "type is null"); if (type instanceof FixedWidthType) { if (type instanceof DoubleType) { return new DoubleDecoder(); } else if (type instanceof BigintType) { return new BigintDecoder(); } else if (type instanceof IntegerType) { return new IntegerDecoder(); } else if (type instanceof BooleanType) { return new BooleanDecoder(); } else { throw new PinotException(PINOT_UNSUPPORTED_COLUMN_TYPE, Optional.empty(), "type '" + type + "' not supported"); } } else if (type instanceof ArrayType) { return new ArrayDecoder(type); } else { return new VarcharDecoder(); } }
Example #29
Source File: TestRawDecoder.java From presto with Apache License 2.0 | 5 votes |
@Test public void testInvalidMapping() { assertThatThrownBy(() -> singleColumnDecoder(DoubleType.DOUBLE, "x", "DOUBLE")) .isInstanceOf(PrestoException.class) .hasMessageContaining("invalid mapping format 'x' for column 'some_column'"); }
Example #30
Source File: TestCsvDecoder.java From presto with Apache License 2.0 | 5 votes |
@Test public void testSimple() { String csv = "\"row 1\",row2,\"row3\",100,\"200\",300,4.5"; DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", createVarcharType(2), "0", null, null, false, false, false); DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", createVarcharType(10), "1", null, null, false, false, false); DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", createVarcharType(10), "2", null, null, false, false, false); DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", BigintType.BIGINT, "3", null, null, false, false, false); DecoderTestColumnHandle row5 = new DecoderTestColumnHandle(4, "row5", BigintType.BIGINT, "4", null, null, false, false, false); DecoderTestColumnHandle row6 = new DecoderTestColumnHandle(5, "row6", BigintType.BIGINT, "5", null, null, false, false, false); DecoderTestColumnHandle row7 = new DecoderTestColumnHandle(6, "row7", DoubleType.DOUBLE, "6", null, null, false, false, false); Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4, row5, row6, row7); RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns); Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null) .orElseThrow(AssertionError::new); assertEquals(decodedRow.size(), columns.size()); checkValue(decodedRow, row1, "ro"); checkValue(decodedRow, row2, "row2"); checkValue(decodedRow, row3, "row3"); checkValue(decodedRow, row4, 100); checkValue(decodedRow, row5, 200); checkValue(decodedRow, row6, 300); checkValue(decodedRow, row7, 4.5d); }