use of com.facebook.presto.type.RowType in project presto by prestodb.
the class TestHiveFileFormats method testParquetThrift.
@Test(dataProvider = "rowCount")
public void testParquetThrift(int rowCount) throws Exception {
RowType nameType = new RowType(ImmutableList.of(createUnboundedVarcharType(), createUnboundedVarcharType()), Optional.empty());
RowType phoneType = new RowType(ImmutableList.of(createUnboundedVarcharType(), createUnboundedVarcharType()), Optional.empty());
RowType personType = new RowType(ImmutableList.of(nameType, INTEGER, createUnboundedVarcharType(), new ArrayType(phoneType)), Optional.empty());
List<TestColumn> testColumns = ImmutableList.of(new TestColumn("persons", getStandardListObjectInspector(getStandardStructObjectInspector(ImmutableList.of("name", "id", "email", "phones"), ImmutableList.of(getStandardStructObjectInspector(ImmutableList.of("first_name", "last_name"), ImmutableList.of(javaStringObjectInspector, javaStringObjectInspector)), javaIntObjectInspector, javaStringObjectInspector, getStandardListObjectInspector(getStandardStructObjectInspector(ImmutableList.of("number", "type"), ImmutableList.of(javaStringObjectInspector, javaStringObjectInspector)))))), null, arrayBlockOf(personType, rowBlockOf(ImmutableList.of(nameType, INTEGER, createUnboundedVarcharType(), new ArrayType(phoneType)), rowBlockOf(ImmutableList.of(createUnboundedVarcharType(), createUnboundedVarcharType()), "Bob", "Roberts"), 0, "bob.roberts@example.com", arrayBlockOf(phoneType, rowBlockOf(ImmutableList.of(createUnboundedVarcharType(), createUnboundedVarcharType()), "1234567890", null))))));
File file = new File(this.getClass().getClassLoader().getResource("addressbook.parquet").getPath());
FileSplit split = new FileSplit(new Path(file.getAbsolutePath()), 0, file.length(), new String[0]);
HiveRecordCursorProvider cursorProvider = new ParquetRecordCursorProvider(false, HDFS_ENVIRONMENT);
testCursorProvider(cursorProvider, split, PARQUET, testColumns, 1);
}
use of com.facebook.presto.type.RowType in project presto by prestodb.
the class TestApplyFunction method testTypeCombinations.
@Test
public void testTypeCombinations() throws Exception {
assertFunction("apply(25, x -> x + 1)", INTEGER, 26);
assertFunction("apply(25, x -> x + 1.0)", DOUBLE, 26.0);
assertFunction("apply(25, x -> x = 25)", BOOLEAN, true);
assertFunction("apply(25, x -> to_base(x, 16))", createVarcharType(64), "19");
assertFunction("apply(25, x -> ARRAY[x + 1])", new ArrayType(INTEGER), ImmutableList.of(26));
assertFunction("apply(25.6, x -> CAST(x AS BIGINT))", BIGINT, 26L);
assertFunction("apply(25.6, x -> x + 1.0)", DOUBLE, 26.6);
assertFunction("apply(25.6, x -> x = 25.6)", BOOLEAN, true);
assertFunction("apply(25.6, x -> CAST(x AS VARCHAR))", createUnboundedVarcharType(), "25.6");
assertFunction("apply(25.6, x -> MAP(ARRAY[x + 1], ARRAY[true]))", new MapType(DOUBLE, BOOLEAN), ImmutableMap.of(26.6, true));
assertFunction("apply(true, x -> if(x, 25, 26))", INTEGER, 25);
assertFunction("apply(false, x -> if(x, 25.6, 28.9))", DOUBLE, 28.9);
assertFunction("apply(true, x -> not x)", BOOLEAN, false);
assertFunction("apply(false, x -> CAST(x AS VARCHAR))", createUnboundedVarcharType(), "false");
assertFunction("apply(true, x -> ARRAY[x])", new ArrayType(BOOLEAN), ImmutableList.of(true));
assertFunction("apply('41', x -> from_base(x, 16))", BIGINT, 65L);
assertFunction("apply('25.6', x -> CAST(x AS DOUBLE))", DOUBLE, 25.6);
assertFunction("apply('abc', x -> 'abc' = x)", BOOLEAN, true);
assertFunction("apply('abc', x -> x || x)", createUnboundedVarcharType(), "abcabc");
assertFunction("apply('123', x -> ROW(x, CAST(x AS INTEGER), x > '0'))", new RowType(ImmutableList.of(createVarcharType(3), INTEGER, BOOLEAN), Optional.empty()), ImmutableList.of("123", 123, true));
assertFunction("apply(ARRAY['abc', NULL, '123'], x -> from_base(x[3], 10))", BIGINT, 123L);
assertFunction("apply(ARRAY['abc', NULL, '123'], x -> CAST(x[3] AS DOUBLE))", DOUBLE, 123.0);
assertFunction("apply(ARRAY['abc', NULL, '123'], x -> x[2] IS NULL)", BOOLEAN, true);
assertFunction("apply(ARRAY['abc', NULL, '123'], x -> x[2])", createVarcharType(3), null);
assertFunction("apply(MAP(ARRAY['abc', 'def'], ARRAY[123, 456]), x -> map_keys(x))", new ArrayType(createVarcharType(3)), ImmutableList.of("abc", "def"));
}
use of com.facebook.presto.type.RowType in project presto by prestodb.
the class RowComparisonOperator method getMethodHandles.
protected List<MethodHandle> getMethodHandles(RowType type, FunctionRegistry functionRegistry, OperatorType operatorType) {
ImmutableList.Builder<MethodHandle> argumentMethods = ImmutableList.builder();
for (Type parameterType : type.getTypeParameters()) {
Signature signature = functionRegistry.resolveOperator(operatorType, ImmutableList.of(parameterType, parameterType));
argumentMethods.add(functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle());
}
return argumentMethods.build();
}
use of com.facebook.presto.type.RowType in project presto by prestodb.
the class RcFileTester method testRoundTrip.
public void testRoundTrip(Type type, Iterable<?> writeValues, Format... skipFormats) throws Exception {
ImmutableSet<Format> skipFormatsSet = ImmutableSet.copyOf(skipFormats);
// just the values
testRoundTripType(type, writeValues, skipFormatsSet);
// all nulls
assertRoundTrip(type, transform(writeValues, constant(null)), skipFormatsSet);
// values wrapped in struct
if (structTestsEnabled) {
testStructRoundTrip(type, writeValues, skipFormatsSet);
}
// values wrapped in a struct wrapped in a struct
if (complexStructuralTestsEnabled) {
Iterable<Object> simpleStructs = transform(insertNullEvery(5, writeValues), RcFileTester::toHiveStruct);
testRoundTripType(new RowType(ImmutableList.of(createRowType(type)), Optional.of(ImmutableList.of("field"))), transform(simpleStructs, Collections::singletonList), skipFormatsSet);
}
// values wrapped in map
if (mapTestsEnabled) {
testMapRoundTrip(type, writeValues, skipFormatsSet);
}
// values wrapped in list
if (listTestsEnabled) {
testListRoundTrip(type, writeValues, skipFormatsSet);
}
// values wrapped in a list wrapped in a list
if (complexStructuralTestsEnabled) {
testListRoundTrip(createListType(type), transform(writeValues, RcFileTester::toHiveList), skipFormatsSet);
}
}
Aggregations