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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations