Search in sources :

Example 46 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class TestAbstractDwrfEncryptionInformationSource method testGetReadEncryptionInformationForUnPartitionedTableWithColumnLevelEncryption.

@Test
public void testGetReadEncryptionInformationForUnPartitionedTableWithColumnLevelEncryption() {
    Table table = createTable(DWRF, Optional.of(forPerColumn(fromHiveProperty("key1:col_string,col_struct.b.b2;key2:col_bigint,col_struct.a"), "algo", "provider")), false);
    Optional<EncryptionInformation> encryptionInformation = encryptionInformationSource.getReadEncryptionInformation(SESSION, table, Optional.of(ImmutableSet.of(// hiveColumnIndex value does not matter in this test
    new HiveColumnHandle("col_bigint", HIVE_LONG, HIVE_LONG.getTypeSignature(), 0, REGULAR, Optional.empty(), Optional.empty()), new HiveColumnHandle("col_map", HIVE_LONG, HIVE_LONG.getTypeSignature(), 0, REGULAR, Optional.empty(), Optional.empty()), new HiveColumnHandle("col_struct", STRUCT_TYPE, STRUCT_TYPE.getTypeSignature(), 0, REGULAR, Optional.empty(), ImmutableList.of(new Subfield("col_struct.a"), new Subfield("col_struct.b.b2")), Optional.empty()))));
    Map<String, byte[]> expectedFieldToKeyData = ImmutableMap.of("col_bigint", "key2".getBytes(), "col_struct.a", "key2".getBytes(), "col_struct.b.b2", "key1".getBytes());
    assertTrue(encryptionInformation.isPresent());
    assertEquals(encryptionInformation.get(), EncryptionInformation.fromEncryptionMetadata(DwrfEncryptionMetadata.forPerField(expectedFieldToKeyData, ImmutableMap.of(TEST_EXTRA_METADATA, table.getTableName()), "algo", "provider")));
}
Also used : Table(com.facebook.presto.hive.metastore.Table) DwrfTableEncryptionProperties.forTable(com.facebook.presto.hive.DwrfTableEncryptionProperties.forTable) Subfield(com.facebook.presto.common.Subfield) Test(org.testng.annotations.Test)

Example 47 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class TestCoercingFilters method testIntegerToVarchar.

@Test
public void testIntegerToVarchar() {
    TupleDomainFilter filter = BytesRange.of("10".getBytes(), false, "10".getBytes(), false, false);
    HiveCoercer coercer = new IntegerNumberToVarcharCoercer(INTEGER, VARCHAR);
    TupleDomainFilter coercingFilter = coercer.toCoercingFilter(filter, new Subfield("c"));
    assertTrue(coercingFilter.testLong(10));
    assertFalse(coercingFilter.testLong(25));
    assertFalse(coercingFilter.testNull());
}
Also used : IntegerNumberToVarcharCoercer(com.facebook.presto.hive.HiveCoercer.IntegerNumberToVarcharCoercer) Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) Test(org.testng.annotations.Test)

Example 48 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class TestCoercingFilters method testVarcharToInteger.

@Test
public void testVarcharToInteger() {
    TupleDomainFilter filter = BigintRange.of(100, Integer.MAX_VALUE, false);
    HiveCoercer coercer = new VarcharToIntegerNumberCoercer(VARCHAR, INTEGER);
    TupleDomainFilter coercingFilter = coercer.toCoercingFilter(filter, new Subfield("c"));
    assertTrue(coercingFilter.testLength(1));
    assertTrue(coercingFilter.testLength(2));
    assertTrue(coercingFilter.testLength(3));
    assertTrue(coercingFilter.testBytes("100".getBytes(), 0, 3));
    assertTrue(coercingFilter.testBytes("145".getBytes(), 0, 3));
    assertTrue(coercingFilter.testBytes("2147483647".getBytes(), 0, 10));
    assertFalse(coercingFilter.testBytes("50".getBytes(), 0, 2));
    assertFalse(coercingFilter.testBytes("-50".getBytes(), 0, 3));
    // parsing error
    assertFalse(coercingFilter.testBytes("abc".getBytes(), 0, 3));
    // out of range
    assertFalse(coercingFilter.testBytes("2147483648".getBytes(), 0, 10));
    assertFalse(coercingFilter.testNull());
}
Also used : VarcharToIntegerNumberCoercer(com.facebook.presto.hive.HiveCoercer.VarcharToIntegerNumberCoercer) Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) Test(org.testng.annotations.Test)

Example 49 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class SelectiveStreamReaders method createStreamReader.

public static SelectiveStreamReader createStreamReader(StreamDescriptor streamDescriptor, Map<Subfield, TupleDomainFilter> filters, Optional<Type> outputType, List<Subfield> requiredSubfields, DateTimeZone hiveStorageTimeZone, OrcRecordReaderOptions options, boolean legacyMapSubscript, OrcAggregatedMemoryContext systemMemoryContext) {
    OrcTypeKind type = streamDescriptor.getOrcTypeKind();
    switch(type) {
        case BOOLEAN:
            {
                checkArgument(requiredSubfields.isEmpty(), "Boolean stream reader doesn't support subfields");
                verifyStreamType(streamDescriptor, outputType, BooleanType.class::isInstance);
                return new BooleanSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
            }
        case BYTE:
            {
                checkArgument(requiredSubfields.isEmpty(), "Byte stream reader doesn't support subfields");
                verifyStreamType(streamDescriptor, outputType, TinyintType.class::isInstance);
                return new ByteSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
            }
        case SHORT:
        case INT:
        case LONG:
        case DATE:
            {
                checkArgument(requiredSubfields.isEmpty(), "Primitive type stream reader doesn't support subfields");
                verifyStreamType(streamDescriptor, outputType, t -> t instanceof BigintType || t instanceof IntegerType || t instanceof SmallintType || t instanceof DateType);
                return new LongSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext);
            }
        case FLOAT:
            {
                checkArgument(requiredSubfields.isEmpty(), "Float type stream reader doesn't support subfields");
                verifyStreamType(streamDescriptor, outputType, RealType.class::isInstance);
                return new FloatSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
            }
        case DOUBLE:
            checkArgument(requiredSubfields.isEmpty(), "Double stream reader doesn't support subfields");
            verifyStreamType(streamDescriptor, outputType, DoubleType.class::isInstance);
            return new DoubleSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
        case BINARY:
        case STRING:
        case VARCHAR:
        case CHAR:
            checkArgument(requiredSubfields.isEmpty(), "Primitive stream reader doesn't support subfields");
            verifyStreamType(streamDescriptor, outputType, t -> t instanceof VarcharType || t instanceof CharType || t instanceof VarbinaryType);
            return new SliceSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext);
        case TIMESTAMP:
            {
                checkArgument(requiredSubfields.isEmpty(), "Timestamp stream reader doesn't support subfields");
                verifyStreamType(streamDescriptor, outputType, TimestampType.class::isInstance);
                return new TimestampSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), hiveStorageTimeZone, outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()), options);
            }
        case LIST:
            verifyStreamType(streamDescriptor, outputType, ArrayType.class::isInstance);
            return new ListSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, null, 0, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
        case STRUCT:
            verifyStreamType(streamDescriptor, outputType, RowType.class::isInstance);
            return new StructSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
        case MAP:
            verifyStreamType(streamDescriptor, outputType, MapType.class::isInstance);
            return new MapSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
        case DECIMAL:
            {
                verifyStreamType(streamDescriptor, outputType, DecimalType.class::isInstance);
                if (streamDescriptor.getOrcType().getPrecision().get() <= MAX_SHORT_PRECISION) {
                    return new ShortDecimalSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
                } else {
                    return new LongDecimalSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
                }
            }
        case UNION:
        default:
            throw new IllegalArgumentException("Unsupported type: " + type);
    }
}
Also used : StreamDescriptor(com.facebook.presto.orc.StreamDescriptor) Iterables(com.google.common.collect.Iterables) DateTimeZone(org.joda.time.DateTimeZone) MapType(com.facebook.presto.common.type.MapType) DecimalType(com.facebook.presto.common.type.DecimalType) BooleanType(com.facebook.presto.common.type.BooleanType) OrcTypeKind(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind) MAX_SHORT_PRECISION(com.facebook.presto.common.type.Decimals.MAX_SHORT_PRECISION) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) IntegerType(com.facebook.presto.common.type.IntegerType) Subfield(com.facebook.presto.common.Subfield) Map(java.util.Map) ArrayType(com.facebook.presto.common.type.ArrayType) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) TinyintType(com.facebook.presto.common.type.TinyintType) OrcAggregatedMemoryContext(com.facebook.presto.orc.OrcAggregatedMemoryContext) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) BigintType(com.facebook.presto.common.type.BigintType) OrcRecordReaderOptions(com.facebook.presto.orc.OrcRecordReaderOptions) VarcharType(com.facebook.presto.common.type.VarcharType) RealType(com.facebook.presto.common.type.RealType) String.format(java.lang.String.format) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) SmallintType(com.facebook.presto.common.type.SmallintType) List(java.util.List) VarbinaryType(com.facebook.presto.common.type.VarbinaryType) Optional(java.util.Optional) Arrays.ensureCapacity(com.facebook.presto.common.array.Arrays.ensureCapacity) DateType(com.facebook.presto.common.type.DateType) DoubleType(com.facebook.presto.common.type.DoubleType) RowType(com.facebook.presto.common.type.RowType) TimestampType(com.facebook.presto.common.type.TimestampType) VarcharType(com.facebook.presto.common.type.VarcharType) RowType(com.facebook.presto.common.type.RowType) OrcTypeKind(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) VarbinaryType(com.facebook.presto.common.type.VarbinaryType) SmallintType(com.facebook.presto.common.type.SmallintType) DateType(com.facebook.presto.common.type.DateType) BigintType(com.facebook.presto.common.type.BigintType) IntegerType(com.facebook.presto.common.type.IntegerType) DoubleType(com.facebook.presto.common.type.DoubleType) CharType(com.facebook.presto.common.type.CharType)

Example 50 with Subfield

use of com.facebook.presto.common.Subfield in project presto by prestodb.

the class StructSelectiveStreamReader method getRequiredFields.

private static Optional<Map<String, List<Subfield>>> getRequiredFields(List<Subfield> requiredSubfields) {
    if (requiredSubfields.isEmpty()) {
        return Optional.empty();
    }
    Map<String, List<Subfield>> fields = new HashMap<>();
    for (Subfield subfield : requiredSubfields) {
        List<Subfield.PathElement> path = subfield.getPath();
        String name = ((Subfield.NestedField) path.get(0)).getName().toLowerCase(Locale.ENGLISH);
        fields.computeIfAbsent(name, k -> new ArrayList<>());
        if (path.size() > 1) {
            fields.get(name).add(new Subfield("c", path.subList(1, path.size())));
        }
    }
    return Optional.of(ImmutableMap.copyOf(fields));
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Subfield(com.facebook.presto.common.Subfield)

Aggregations

Subfield (com.facebook.presto.common.Subfield)54 ImmutableMap (com.google.common.collect.ImmutableMap)27 Map (java.util.Map)27 ImmutableList (com.google.common.collect.ImmutableList)25 List (java.util.List)24 TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)22 Type (com.facebook.presto.common.type.Type)21 ArrayList (java.util.ArrayList)21 Optional (java.util.Optional)20 Test (org.testng.annotations.Test)19 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)18 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)18 Collectors.toList (java.util.stream.Collectors.toList)12 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)11 ColumnHandle (com.facebook.presto.spi.ColumnHandle)11 String.format (java.lang.String.format)11 Set (java.util.Set)11 Domain (com.facebook.presto.common.predicate.Domain)10 CharType (com.facebook.presto.common.type.CharType)10 DecimalType (com.facebook.presto.common.type.DecimalType)10