Search in sources :

Example 6 with DateType

use of io.prestosql.spi.type.DateType 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)

Example 7 with DateType

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

the class TestTypeUtil method testParseType.

@Test
public void testParseType() {
    Type type = parseType(typeManager, "bigint");
    assertTrue(type instanceof BigintType);
    type = parseType(typeManager, "integer");
    assertTrue(type instanceof IntegerType);
    type = parseType(typeManager, "smallint");
    assertTrue(type instanceof SmallintType);
    type = parseType(typeManager, "boolean");
    assertTrue(type instanceof BooleanType);
    type = parseType(typeManager, "date");
    assertTrue(type instanceof DateType);
    type = parseType(typeManager, "real");
    assertTrue(type instanceof RealType);
    type = parseType(typeManager, "double");
    assertTrue(type instanceof DoubleType);
    type = parseType(typeManager, "HyperLogLog");
    assertTrue(type instanceof HyperLogLogType);
    type = parseType(typeManager, "P4HyperLogLog");
    assertTrue(type instanceof P4HyperLogLogType);
    type = parseType(typeManager, "timestamp");
    assertTrue(type instanceof TimestampType);
    type = parseType(typeManager, "timestamp with time zone");
    assertTrue(type instanceof TimestampWithTimeZoneType);
    type = parseType(typeManager, "time");
    assertTrue(type instanceof TimeType);
    type = parseType(typeManager, "time with time zone");
    assertTrue(type instanceof TimeWithTimeZoneType);
    type = parseType(typeManager, "varbinary");
    assertTrue(type instanceof VarbinaryType);
    type = parseType(typeManager, "unknown");
    assertTrue(type instanceof UnknownType);
}
Also used : BooleanType(io.prestosql.spi.type.BooleanType) P4HyperLogLogType(io.prestosql.spi.type.P4HyperLogLogType) TimeWithTimeZoneType(io.prestosql.spi.type.TimeWithTimeZoneType) RealType(io.prestosql.spi.type.RealType) BigintType(io.prestosql.spi.type.BigintType) TimeType(io.prestosql.spi.type.TimeType) IntegerType(io.prestosql.spi.type.IntegerType) UnknownType(io.prestosql.spi.type.UnknownType) BigintType(io.prestosql.spi.type.BigintType) UnknownType(io.prestosql.spi.type.UnknownType) CharType(io.prestosql.spi.type.CharType) DecimalType(io.prestosql.spi.type.DecimalType) HyperLogLogType(io.prestosql.spi.type.HyperLogLogType) DoubleType(io.prestosql.spi.type.DoubleType) P4HyperLogLogType(io.prestosql.spi.type.P4HyperLogLogType) RowType(io.prestosql.spi.type.RowType) TimestampWithTimeZoneType(io.prestosql.spi.type.TimestampWithTimeZoneType) Type(io.prestosql.spi.type.Type) SmallintType(io.prestosql.spi.type.SmallintType) TimeWithTimeZoneType(io.prestosql.spi.type.TimeWithTimeZoneType) IntegerType(io.prestosql.spi.type.IntegerType) TimeType(io.prestosql.spi.type.TimeType) RealType(io.prestosql.spi.type.RealType) ArrayType(io.prestosql.spi.type.ArrayType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) TimestampType(io.prestosql.spi.type.TimestampType) DateType(io.prestosql.spi.type.DateType) BooleanType(io.prestosql.spi.type.BooleanType) TypeUtil.parseType(io.prestosql.client.util.TypeUtil.parseType) VarcharType(io.prestosql.spi.type.VarcharType) HyperLogLogType(io.prestosql.spi.type.HyperLogLogType) P4HyperLogLogType(io.prestosql.spi.type.P4HyperLogLogType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DoubleType(io.prestosql.spi.type.DoubleType) TimestampWithTimeZoneType(io.prestosql.spi.type.TimestampWithTimeZoneType) TimestampType(io.prestosql.spi.type.TimestampType) SmallintType(io.prestosql.spi.type.SmallintType) DateType(io.prestosql.spi.type.DateType) Test(org.testng.annotations.Test)

Aggregations

DateType (io.prestosql.spi.type.DateType)7 BigintType (io.prestosql.spi.type.BigintType)6 DoubleType (io.prestosql.spi.type.DoubleType)6 IntegerType (io.prestosql.spi.type.IntegerType)6 RealType (io.prestosql.spi.type.RealType)6 VarcharType (io.prestosql.spi.type.VarcharType)6 BooleanType (io.prestosql.spi.type.BooleanType)5 CharType (io.prestosql.spi.type.CharType)5 DecimalType (io.prestosql.spi.type.DecimalType)5 SmallintType (io.prestosql.spi.type.SmallintType)5 TimestampType (io.prestosql.spi.type.TimestampType)5 Type (io.prestosql.spi.type.Type)5 TinyintType (io.prestosql.spi.type.TinyintType)4 VarbinaryType (io.prestosql.spi.type.VarbinaryType)4 Slice (io.airlift.slice.Slice)3 PrestoException (io.prestosql.spi.PrestoException)3 TimeType (io.prestosql.spi.type.TimeType)3 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)2 RowExpression (io.prestosql.spi.relation.RowExpression)2 Timestamp (java.sql.Timestamp)2