Search in sources :

Example 6 with DoubleType

use of io.prestosql.spi.type.DoubleType in project pulsar by yahoo.

the class PulsarPrimitiveRowDecoder method decodeRow.

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(ByteBuf byteBuf) {
    if (columnHandle == null) {
        return Optional.empty();
    }
    Object value = schema.decode(byteBuf);
    Map<DecoderColumnHandle, FieldValueProvider> primitiveColumn = new HashMap<>();
    if (value == null) {
        primitiveColumn.put(columnHandle, FieldValueProviders.nullValueProvider());
    } else {
        Type type = columnHandle.getType();
        if (type instanceof BooleanType) {
            primitiveColumn.put(columnHandle, booleanValueProvider(Boolean.valueOf((Boolean) value)));
        } else if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType) {
            primitiveColumn.put(columnHandle, longValueProvider(Long.parseLong(value.toString())));
        } else if (type instanceof DoubleType) {
            primitiveColumn.put(columnHandle, doubleValueProvider(Double.parseDouble(value.toString())));
        } else if (type instanceof RealType) {
            primitiveColumn.put(columnHandle, longValueProvider(Float.floatToIntBits((Float.parseFloat(value.toString())))));
        } else if (type instanceof VarbinaryType) {
            primitiveColumn.put(columnHandle, bytesValueProvider((byte[]) value));
        } else if (type instanceof VarcharType) {
            primitiveColumn.put(columnHandle, bytesValueProvider(value.toString().getBytes()));
        } else if (type instanceof DateType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Date) value).getTime()));
        } else if (type instanceof TimeType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Time) value).getTime()));
        } else if (type instanceof TimestampType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Timestamp) value).getTime()));
        } else {
            primitiveColumn.put(columnHandle, bytesValueProvider(value.toString().getBytes()));
        }
    }
    return Optional.of(primitiveColumn);
}
Also used : HashMap(java.util.HashMap) VarcharType(io.prestosql.spi.type.VarcharType) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) TinyintType(io.prestosql.spi.type.TinyintType) BooleanType(io.prestosql.spi.type.BooleanType) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) RealType(io.prestosql.spi.type.RealType) Timestamp(java.sql.Timestamp) BigintType(io.prestosql.spi.type.BigintType) Date(java.util.Date) TimeType(io.prestosql.spi.type.TimeType) IntegerType(io.prestosql.spi.type.IntegerType) BigintType(io.prestosql.spi.type.BigintType) DoubleType(io.prestosql.spi.type.DoubleType) Type(io.prestosql.spi.type.Type) SmallintType(io.prestosql.spi.type.SmallintType) IntegerType(io.prestosql.spi.type.IntegerType) TimeType(io.prestosql.spi.type.TimeType) RealType(io.prestosql.spi.type.RealType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) TinyintType(io.prestosql.spi.type.TinyintType) TimestampType(io.prestosql.spi.type.TimestampType) DateType(io.prestosql.spi.type.DateType) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DoubleType(io.prestosql.spi.type.DoubleType) TimestampType(io.prestosql.spi.type.TimestampType) SmallintType(io.prestosql.spi.type.SmallintType) DateType(io.prestosql.spi.type.DateType)

Example 7 with DoubleType

use of io.prestosql.spi.type.DoubleType in project boostkit-bigdata by kunpengcompute.

the class HivePartitionManager method getFilteredPartitionNames.

private List<String> getFilteredPartitionNames(SemiTransactionalHiveMetastore metastore, HiveIdentity identity, SchemaTableName tableName, List<HiveColumnHandle> partitionKeys, TupleDomain<ColumnHandle> effectivePredicate, Table table) {
    checkArgument(effectivePredicate.getDomains().isPresent());
    List<String> filter = new ArrayList<>();
    for (HiveColumnHandle partitionKey : partitionKeys) {
        Domain domain = effectivePredicate.getDomains().get().get(partitionKey);
        if (domain != null && domain.isNullableSingleValue()) {
            Object value = domain.getNullableSingleValue();
            Type type = domain.getType();
            if (value == null) {
                filter.add(HivePartitionKey.HIVE_DEFAULT_DYNAMIC_PARTITION);
            } else if (type instanceof CharType) {
                Slice slice = (Slice) value;
                filter.add(padSpaces(slice, (CharType) type).toStringUtf8());
            } else if (type instanceof VarcharType) {
                Slice slice = (Slice) value;
                filter.add(slice.toStringUtf8());
            } else // unless we know that all partition values use the canonical Java representation.
            if (!assumeCanonicalPartitionKeys) {
                filter.add(PARTITION_VALUE_WILDCARD);
            } else if (type instanceof DecimalType && !((DecimalType) type).isShort()) {
                Slice slice = (Slice) value;
                filter.add(Decimals.toString(slice, ((DecimalType) type).getScale()));
            } else if (type instanceof DecimalType && ((DecimalType) type).isShort()) {
                filter.add(Decimals.toString((long) value, ((DecimalType) type).getScale()));
            } else if (type instanceof DateType) {
                DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.date().withZoneUTC();
                filter.add(dateTimeFormatter.print(TimeUnit.DAYS.toMillis((long) value)));
            } else if (type instanceof TimestampType) {
                // we don't have time zone info, so just add a wildcard
                filter.add(PARTITION_VALUE_WILDCARD);
            } else if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType || type instanceof DoubleType || type instanceof RealType || type instanceof BooleanType) {
                filter.add(value.toString());
            } else {
                throw new PrestoException(NOT_SUPPORTED, format("Unsupported partition key type: %s", type.getDisplayName()));
            }
        } else {
            filter.add(PARTITION_VALUE_WILDCARD);
        }
    }
    // fetch the partition names
    return metastore.getPartitionNamesByParts(identity, tableName.getSchemaName(), tableName.getTableName(), filter, table).orElseThrow(() -> new TableNotFoundException(tableName));
}
Also used : VarcharType(io.prestosql.spi.type.VarcharType) TinyintType(io.prestosql.spi.type.TinyintType) ArrayList(java.util.ArrayList) BooleanType(io.prestosql.spi.type.BooleanType) PrestoException(io.prestosql.spi.PrestoException) RealType(io.prestosql.spi.type.RealType) BigintType(io.prestosql.spi.type.BigintType) IntegerType(io.prestosql.spi.type.IntegerType) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) DecimalType(io.prestosql.spi.type.DecimalType) Type(io.prestosql.spi.type.Type) RealType(io.prestosql.spi.type.RealType) TimestampType(io.prestosql.spi.type.TimestampType) BigintType(io.prestosql.spi.type.BigintType) CharType(io.prestosql.spi.type.CharType) DoubleType(io.prestosql.spi.type.DoubleType) SmallintType(io.prestosql.spi.type.SmallintType) IntegerType(io.prestosql.spi.type.IntegerType) TinyintType(io.prestosql.spi.type.TinyintType) DateType(io.prestosql.spi.type.DateType) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) Slice(io.airlift.slice.Slice) DoubleType(io.prestosql.spi.type.DoubleType) DecimalType(io.prestosql.spi.type.DecimalType) TimestampType(io.prestosql.spi.type.TimestampType) SmallintType(io.prestosql.spi.type.SmallintType) CharType(io.prestosql.spi.type.CharType) Domain(io.prestosql.spi.predicate.Domain) TupleDomain(io.prestosql.spi.predicate.TupleDomain) DateType(io.prestosql.spi.type.DateType) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 8 with DoubleType

use of io.prestosql.spi.type.DoubleType in project incubator-pulsar by apache.

the class PulsarPrimitiveRowDecoder method decodeRow.

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(ByteBuf byteBuf) {
    if (columnHandle == null) {
        return Optional.empty();
    }
    Object value = schema.decode(byteBuf);
    Map<DecoderColumnHandle, FieldValueProvider> primitiveColumn = new HashMap<>();
    if (value == null) {
        primitiveColumn.put(columnHandle, FieldValueProviders.nullValueProvider());
    } else {
        Type type = columnHandle.getType();
        if (type instanceof BooleanType) {
            primitiveColumn.put(columnHandle, booleanValueProvider(Boolean.valueOf((Boolean) value)));
        } else if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType) {
            primitiveColumn.put(columnHandle, longValueProvider(Long.parseLong(value.toString())));
        } else if (type instanceof DoubleType) {
            primitiveColumn.put(columnHandle, doubleValueProvider(Double.parseDouble(value.toString())));
        } else if (type instanceof RealType) {
            primitiveColumn.put(columnHandle, longValueProvider(Float.floatToIntBits((Float.parseFloat(value.toString())))));
        } else if (type instanceof VarbinaryType) {
            primitiveColumn.put(columnHandle, bytesValueProvider((byte[]) value));
        } else if (type instanceof VarcharType) {
            primitiveColumn.put(columnHandle, bytesValueProvider(value.toString().getBytes()));
        } else if (type instanceof DateType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Date) value).getTime()));
        } else if (type instanceof TimeType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Time) value).getTime()));
        } else if (type instanceof TimestampType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Timestamp) value).getTime()));
        } else {
            primitiveColumn.put(columnHandle, bytesValueProvider(value.toString().getBytes()));
        }
    }
    return Optional.of(primitiveColumn);
}
Also used : HashMap(java.util.HashMap) VarcharType(io.prestosql.spi.type.VarcharType) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) TinyintType(io.prestosql.spi.type.TinyintType) BooleanType(io.prestosql.spi.type.BooleanType) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) RealType(io.prestosql.spi.type.RealType) Timestamp(java.sql.Timestamp) BigintType(io.prestosql.spi.type.BigintType) Date(java.util.Date) TimeType(io.prestosql.spi.type.TimeType) IntegerType(io.prestosql.spi.type.IntegerType) BigintType(io.prestosql.spi.type.BigintType) DoubleType(io.prestosql.spi.type.DoubleType) Type(io.prestosql.spi.type.Type) SmallintType(io.prestosql.spi.type.SmallintType) IntegerType(io.prestosql.spi.type.IntegerType) TimeType(io.prestosql.spi.type.TimeType) RealType(io.prestosql.spi.type.RealType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) TinyintType(io.prestosql.spi.type.TinyintType) TimestampType(io.prestosql.spi.type.TimestampType) DateType(io.prestosql.spi.type.DateType) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DoubleType(io.prestosql.spi.type.DoubleType) TimestampType(io.prestosql.spi.type.TimestampType) SmallintType(io.prestosql.spi.type.SmallintType) DateType(io.prestosql.spi.type.DateType)

Example 9 with DoubleType

use of io.prestosql.spi.type.DoubleType in project pulsar by apache.

the class PulsarPrimitiveRowDecoder method decodeRow.

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(ByteBuf byteBuf) {
    if (columnHandle == null) {
        return Optional.empty();
    }
    Object value = schema.decode(byteBuf);
    Map<DecoderColumnHandle, FieldValueProvider> primitiveColumn = new HashMap<>();
    if (value == null) {
        primitiveColumn.put(columnHandle, FieldValueProviders.nullValueProvider());
    } else {
        Type type = columnHandle.getType();
        if (type instanceof BooleanType) {
            primitiveColumn.put(columnHandle, booleanValueProvider(Boolean.valueOf((Boolean) value)));
        } else if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType) {
            primitiveColumn.put(columnHandle, longValueProvider(Long.parseLong(value.toString())));
        } else if (type instanceof DoubleType) {
            primitiveColumn.put(columnHandle, doubleValueProvider(Double.parseDouble(value.toString())));
        } else if (type instanceof RealType) {
            primitiveColumn.put(columnHandle, longValueProvider(Float.floatToIntBits((Float.parseFloat(value.toString())))));
        } else if (type instanceof VarbinaryType) {
            primitiveColumn.put(columnHandle, bytesValueProvider((byte[]) value));
        } else if (type instanceof VarcharType) {
            primitiveColumn.put(columnHandle, bytesValueProvider(value.toString().getBytes()));
        } else if (type instanceof DateType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Date) value).getTime()));
        } else if (type instanceof TimeType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Time) value).getTime()));
        } else if (type instanceof TimestampType) {
            primitiveColumn.put(columnHandle, longValueProvider(((Timestamp) value).getTime()));
        } else {
            primitiveColumn.put(columnHandle, bytesValueProvider(value.toString().getBytes()));
        }
    }
    return Optional.of(primitiveColumn);
}
Also used : HashMap(java.util.HashMap) VarcharType(io.prestosql.spi.type.VarcharType) FieldValueProvider(io.prestosql.decoder.FieldValueProvider) TinyintType(io.prestosql.spi.type.TinyintType) BooleanType(io.prestosql.spi.type.BooleanType) DecoderColumnHandle(io.prestosql.decoder.DecoderColumnHandle) RealType(io.prestosql.spi.type.RealType) Timestamp(java.sql.Timestamp) BigintType(io.prestosql.spi.type.BigintType) Date(java.util.Date) TimeType(io.prestosql.spi.type.TimeType) IntegerType(io.prestosql.spi.type.IntegerType) BigintType(io.prestosql.spi.type.BigintType) DoubleType(io.prestosql.spi.type.DoubleType) Type(io.prestosql.spi.type.Type) SmallintType(io.prestosql.spi.type.SmallintType) IntegerType(io.prestosql.spi.type.IntegerType) TimeType(io.prestosql.spi.type.TimeType) RealType(io.prestosql.spi.type.RealType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) TinyintType(io.prestosql.spi.type.TinyintType) TimestampType(io.prestosql.spi.type.TimestampType) DateType(io.prestosql.spi.type.DateType) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DoubleType(io.prestosql.spi.type.DoubleType) TimestampType(io.prestosql.spi.type.TimestampType) SmallintType(io.prestosql.spi.type.SmallintType) DateType(io.prestosql.spi.type.DateType)

Example 10 with DoubleType

use of io.prestosql.spi.type.DoubleType in project hetu-core by openlookeng.

the class HivePartitionManager method getFilteredPartitionNames.

private List<String> getFilteredPartitionNames(SemiTransactionalHiveMetastore metastore, HiveIdentity identity, SchemaTableName tableName, List<HiveColumnHandle> partitionKeys, TupleDomain<ColumnHandle> effectivePredicate, Table table) {
    checkArgument(effectivePredicate.getDomains().isPresent());
    List<String> filter = new ArrayList<>();
    for (HiveColumnHandle partitionKey : partitionKeys) {
        Domain domain = effectivePredicate.getDomains().get().get(partitionKey);
        if (domain != null && domain.isNullableSingleValue()) {
            Object value = domain.getNullableSingleValue();
            Type type = domain.getType();
            if (value == null) {
                filter.add(HivePartitionKey.HIVE_DEFAULT_DYNAMIC_PARTITION);
            } else if (type instanceof CharType) {
                Slice slice = (Slice) value;
                filter.add(padSpaces(slice, (CharType) type).toStringUtf8());
            } else if (type instanceof VarcharType) {
                Slice slice = (Slice) value;
                filter.add(slice.toStringUtf8());
            } else // unless we know that all partition values use the canonical Java representation.
            if (!assumeCanonicalPartitionKeys) {
                filter.add(PARTITION_VALUE_WILDCARD);
            } else if (type instanceof DecimalType && !((DecimalType) type).isShort()) {
                Slice slice = (Slice) value;
                filter.add(Decimals.toString(slice, ((DecimalType) type).getScale()));
            } else if (type instanceof DecimalType && ((DecimalType) type).isShort()) {
                filter.add(Decimals.toString((long) value, ((DecimalType) type).getScale()));
            } else if (type instanceof DateType) {
                DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.date().withZoneUTC();
                filter.add(dateTimeFormatter.print(TimeUnit.DAYS.toMillis((long) value)));
            } else if (type instanceof TimestampType) {
                // we don't have time zone info, so just add a wildcard
                filter.add(PARTITION_VALUE_WILDCARD);
            } else if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType || type instanceof DoubleType || type instanceof RealType || type instanceof BooleanType) {
                filter.add(value.toString());
            } else {
                throw new PrestoException(NOT_SUPPORTED, format("Unsupported partition key type: %s", type.getDisplayName()));
            }
        } else {
            filter.add(PARTITION_VALUE_WILDCARD);
        }
    }
    // fetch the partition names
    return metastore.getPartitionNamesByParts(identity, tableName.getSchemaName(), tableName.getTableName(), filter, table).orElseThrow(() -> new TableNotFoundException(tableName));
}
Also used : VarcharType(io.prestosql.spi.type.VarcharType) TinyintType(io.prestosql.spi.type.TinyintType) ArrayList(java.util.ArrayList) BooleanType(io.prestosql.spi.type.BooleanType) PrestoException(io.prestosql.spi.PrestoException) RealType(io.prestosql.spi.type.RealType) BigintType(io.prestosql.spi.type.BigintType) IntegerType(io.prestosql.spi.type.IntegerType) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) DecimalType(io.prestosql.spi.type.DecimalType) Type(io.prestosql.spi.type.Type) RealType(io.prestosql.spi.type.RealType) TimestampType(io.prestosql.spi.type.TimestampType) BigintType(io.prestosql.spi.type.BigintType) CharType(io.prestosql.spi.type.CharType) DoubleType(io.prestosql.spi.type.DoubleType) SmallintType(io.prestosql.spi.type.SmallintType) IntegerType(io.prestosql.spi.type.IntegerType) TinyintType(io.prestosql.spi.type.TinyintType) DateType(io.prestosql.spi.type.DateType) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) Slice(io.airlift.slice.Slice) DoubleType(io.prestosql.spi.type.DoubleType) DecimalType(io.prestosql.spi.type.DecimalType) TimestampType(io.prestosql.spi.type.TimestampType) SmallintType(io.prestosql.spi.type.SmallintType) CharType(io.prestosql.spi.type.CharType) Domain(io.prestosql.spi.predicate.Domain) TupleDomain(io.prestosql.spi.predicate.TupleDomain) DateType(io.prestosql.spi.type.DateType) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Aggregations

DoubleType (io.prestosql.spi.type.DoubleType)12 VarcharType (io.prestosql.spi.type.VarcharType)12 RealType (io.prestosql.spi.type.RealType)11 Type (io.prestosql.spi.type.Type)11 BigintType (io.prestosql.spi.type.BigintType)10 IntegerType (io.prestosql.spi.type.IntegerType)10 BooleanType (io.prestosql.spi.type.BooleanType)9 DateType (io.prestosql.spi.type.DateType)9 SmallintType (io.prestosql.spi.type.SmallintType)9 TimestampType (io.prestosql.spi.type.TimestampType)9 CharType (io.prestosql.spi.type.CharType)8 DecimalType (io.prestosql.spi.type.DecimalType)8 TinyintType (io.prestosql.spi.type.TinyintType)8 PrestoException (io.prestosql.spi.PrestoException)7 VarbinaryType (io.prestosql.spi.type.VarbinaryType)7 Slice (io.airlift.slice.Slice)5 TimeType (io.prestosql.spi.type.TimeType)5 Timestamp (java.sql.Timestamp)4 DecoderColumnHandle (io.prestosql.decoder.DecoderColumnHandle)3 FieldValueProvider (io.prestosql.decoder.FieldValueProvider)3