Search in sources :

Example 1 with RowType

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);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Path(org.apache.hadoop.fs.Path) ParquetRecordCursorProvider(com.facebook.presto.hive.parquet.ParquetRecordCursorProvider) RowType(com.facebook.presto.type.RowType) FileSplit(org.apache.hadoop.mapred.FileSplit) File(java.io.File) Test(org.testng.annotations.Test)

Example 2 with RowType

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"));
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) RowType(com.facebook.presto.type.RowType) MapType(com.facebook.presto.type.MapType) Test(org.testng.annotations.Test)

Example 3 with RowType

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();
}
Also used : RowType(com.facebook.presto.type.RowType) OperatorType(com.facebook.presto.spi.function.OperatorType) Type(com.facebook.presto.spi.type.Type) ImmutableList(com.google.common.collect.ImmutableList) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) MethodHandle(java.lang.invoke.MethodHandle)

Example 4 with RowType

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);
    }
}
Also used : RCFileInputFormat(org.apache.hadoop.hive.ql.io.RCFileInputFormat) InputFormat(org.apache.hadoop.mapred.InputFormat) RCFileOutputFormat(org.apache.hadoop.hive.ql.io.RCFileOutputFormat) RowType(com.facebook.presto.type.RowType) StructObject(org.apache.hadoop.hive.serde2.StructObject)

Aggregations

RowType (com.facebook.presto.type.RowType)4 ArrayType (com.facebook.presto.type.ArrayType)2 Test (org.testng.annotations.Test)2 ParquetRecordCursorProvider (com.facebook.presto.hive.parquet.ParquetRecordCursorProvider)1 Signature (com.facebook.presto.metadata.Signature)1 OperatorType (com.facebook.presto.spi.function.OperatorType)1 Type (com.facebook.presto.spi.type.Type)1 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)1 MapType (com.facebook.presto.type.MapType)1 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 MethodHandle (java.lang.invoke.MethodHandle)1 Path (org.apache.hadoop.fs.Path)1 RCFileInputFormat (org.apache.hadoop.hive.ql.io.RCFileInputFormat)1 RCFileOutputFormat (org.apache.hadoop.hive.ql.io.RCFileOutputFormat)1 StructObject (org.apache.hadoop.hive.serde2.StructObject)1 FileSplit (org.apache.hadoop.mapred.FileSplit)1 InputFormat (org.apache.hadoop.mapred.InputFormat)1