Search in sources :

Example 1 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class ParquetTester method assertFileContents.

private static void assertFileContents(JobConf jobConf, TempFile tempFile, Iterable<?> expectedValues, Type type) throws IOException, InterruptedException {
    Path path = new Path(tempFile.getFile().toURI());
    FileSystem fileSystem = path.getFileSystem(jobConf);
    ParquetMetadata parquetMetadata = ParquetMetadataReader.readFooter(fileSystem, path);
    FileMetaData fileMetaData = parquetMetadata.getFileMetaData();
    MessageType fileSchema = fileMetaData.getSchema();
    long size = fileSystem.getFileStatus(path).getLen();
    FSDataInputStream inputStream = fileSystem.open(path);
    ParquetDataSource dataSource = new HdfsParquetDataSource(path, size, inputStream);
    TypeManager typeManager = new TypeRegistry();
    ParquetReader parquetReader = new ParquetReader(fileSchema, fileSchema, parquetMetadata.getBlocks(), dataSource, typeManager, new AggregatedMemoryContext());
    assertEquals(parquetReader.getPosition(), 0);
    int rowsProcessed = 0;
    Iterator<?> iterator = expectedValues.iterator();
    for (int batchSize = parquetReader.nextBatch(); batchSize >= 0; batchSize = parquetReader.nextBatch()) {
        ColumnDescriptor columnDescriptor = fileSchema.getColumns().get(0);
        Block block = parquetReader.readPrimitive(columnDescriptor, type);
        for (int i = 0; i < batchSize; i++) {
            assertTrue(iterator.hasNext());
            Object expected = iterator.next();
            Object actual = decodeObject(type, block, i);
            assertEquals(actual, expected);
        }
        rowsProcessed += batchSize;
        assertEquals(parquetReader.getPosition(), rowsProcessed);
    }
    assertFalse(iterator.hasNext());
    assertEquals(parquetReader.getPosition(), rowsProcessed);
    parquetReader.close();
}
Also used : Path(org.apache.hadoop.fs.Path) ParquetMetadata(parquet.hadoop.metadata.ParquetMetadata) ColumnDescriptor(parquet.column.ColumnDescriptor) ParquetReader(com.facebook.presto.hive.parquet.reader.ParquetReader) TypeRegistry(com.facebook.presto.type.TypeRegistry) AggregatedMemoryContext(com.facebook.presto.hive.parquet.memory.AggregatedMemoryContext) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) TypeManager(com.facebook.presto.spi.type.TypeManager) Block(com.facebook.presto.spi.block.Block) FileMetaData(parquet.hadoop.metadata.FileMetaData) MessageType(parquet.schema.MessageType)

Example 2 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class TestFunctionRegistry method testIdentityCast.

@Test
public void testIdentityCast() {
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    Signature exactOperator = registry.getCoercion(HYPER_LOG_LOG, HYPER_LOG_LOG);
    assertEquals(exactOperator.getName(), mangleOperatorName(OperatorType.CAST.name()));
    assertEquals(transform(exactOperator.getArgumentTypes(), Functions.toStringFunction()), ImmutableList.of(StandardTypes.HYPER_LOG_LOG));
    assertEquals(exactOperator.getReturnType().getBase(), StandardTypes.HYPER_LOG_LOG);
}
Also used : BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeSignature(com.facebook.presto.spi.type.TypeSignature) FunctionRegistry.getMagicLiteralFunctionSignature(com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Example 3 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class TestFunctionRegistry method testConflictingScalarAggregation.

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "'sum' is both an aggregation and a scalar function")
public void testConflictingScalarAggregation() throws Exception {
    List<SqlFunction> functions = new FunctionListBuilder().scalars(ScalarSum.class).getFunctions();
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    registry.addFunctions(functions);
}
Also used : BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Example 4 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class TestFunctionRegistry method testExactMatchBeforeCoercion.

@Test
public void testExactMatchBeforeCoercion() {
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    boolean foundOperator = false;
    for (SqlFunction function : registry.listOperators()) {
        OperatorType operatorType = unmangleOperator(function.getSignature().getName());
        if (operatorType == OperatorType.CAST || operatorType == OperatorType.SATURATED_FLOOR_CAST) {
            continue;
        }
        if (!function.getSignature().getTypeVariableConstraints().isEmpty()) {
            continue;
        }
        if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) {
            continue;
        }
        Signature exactOperator = registry.resolveOperator(operatorType, resolveTypes(function.getSignature().getArgumentTypes(), typeManager));
        assertEquals(exactOperator, function.getSignature());
        foundOperator = true;
    }
    assertTrue(foundOperator);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeSignature(com.facebook.presto.spi.type.TypeSignature) FunctionRegistry.getMagicLiteralFunctionSignature(com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeRegistry(com.facebook.presto.type.TypeRegistry) OperatorType(com.facebook.presto.spi.function.OperatorType) Test(org.testng.annotations.Test)

Example 5 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class MetadataManager method createTestingViewCodec.

private static JsonCodec<ViewDefinition> createTestingViewCodec() {
    ObjectMapperProvider provider = new ObjectMapperProvider();
    provider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(new TypeRegistry())));
    return new JsonCodecFactory(provider).jsonCodec(ViewDefinition.class);
}
Also used : OperatorType(com.facebook.presto.spi.function.OperatorType) Type(com.facebook.presto.spi.type.Type) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) TypeRegistry(com.facebook.presto.type.TypeRegistry) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider)

Aggregations

TypeRegistry (com.facebook.presto.type.TypeRegistry)14 Test (org.testng.annotations.Test)11 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)10 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)9 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)8 FunctionRegistry.getMagicLiteralFunctionSignature (com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature)4 TypeManager (com.facebook.presto.spi.type.TypeManager)4 FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)3 Signature (com.facebook.presto.metadata.Signature)3 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)3 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)3 SchemaTableName (com.facebook.presto.spi.SchemaTableName)3 CallExpression (com.facebook.presto.sql.relational.CallExpression)3 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)3 RowExpression (com.facebook.presto.sql.relational.RowExpression)3 ExpressionOptimizer (com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer)3 ImmutableList (com.google.common.collect.ImmutableList)3 String.format (java.lang.String.format)3 List (java.util.List)3 Assert.assertEquals (org.testng.Assert.assertEquals)3