Search in sources :

Example 26 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class AbstractTestParquetReader method testStructOfPrimitiveAndSingleLevelArray.

@Test
public void testStructOfPrimitiveAndSingleLevelArray() throws Exception {
    Iterable<List<String>> stringArrayField = createNullableTestArrays(transform(intsBetween(0, 31_234), Object::toString));
    Iterable<Integer> intField = limit(cycle(ImmutableList.of(1, 3, 5, 7, 11, 13, 17)), 31_234);
    List<List> values = createTestStructs(intField, stringArrayField);
    List<String> structFieldNames = asList("intField", "stringArrayField");
    Type structType = RowType.from(asList(field("intField", INTEGER), field("stringArrayField", new ArrayType(VARCHAR))));
    tester.testSingleLevelArraySchemaRoundTrip(getStandardStructObjectInspector(structFieldNames, asList(javaIntObjectInspector, getStandardListObjectInspector(javaStringObjectInspector))), values, values, structType);
}
Also used : BigInteger(java.math.BigInteger) ArrayType(com.facebook.presto.common.type.ArrayType) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) StructuralTestUtil.mapType(com.facebook.presto.tests.StructuralTestUtil.mapType) ArrayType(com.facebook.presto.common.type.ArrayType) RowType(com.facebook.presto.common.type.RowType) PrimitiveType(org.apache.parquet.schema.PrimitiveType) MessageType(org.apache.parquet.schema.MessageType) Type(com.facebook.presto.common.type.Type) MessageTypeParser.parseMessageType(org.apache.parquet.schema.MessageTypeParser.parseMessageType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.testng.annotations.Test)

Example 27 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class AbstractTestType method getNonNullValueForType.

/**
 * @return a non-null value, represented in native container type
 */
private static Object getNonNullValueForType(Type type) {
    if (type.getJavaType() == boolean.class) {
        return true;
    }
    if (type.getJavaType() == long.class) {
        return 1L;
    }
    if (type.getJavaType() == double.class) {
        return 1.0;
    }
    if (type.getJavaType() == Slice.class) {
        return Slices.utf8Slice("_");
    }
    if (type instanceof ArrayType) {
        ArrayType arrayType = (ArrayType) type;
        Type elementType = arrayType.getElementType();
        Object elementNonNullValue = getNonNullValueForType(elementType);
        return arrayBlockOf(elementType, elementNonNullValue);
    }
    if (type instanceof MapType) {
        MapType mapType = (MapType) type;
        Type keyType = mapType.getKeyType();
        Type valueType = mapType.getValueType();
        Object keyNonNullValue = getNonNullValueForType(keyType);
        Object valueNonNullValue = getNonNullValueForType(valueType);
        Map map = ImmutableMap.of(keyNonNullValue, valueNonNullValue);
        return mapBlockOf(keyType, valueType, map);
    }
    if (type instanceof RowType) {
        RowType rowType = (RowType) type;
        List<Type> elementTypes = rowType.getTypeParameters();
        Object[] elementNonNullValues = elementTypes.stream().map(AbstractTestType::getNonNullValueForType).toArray(Object[]::new);
        return toRow(elementTypes, elementNonNullValues);
    }
    throw new IllegalStateException("Unsupported Java type " + type.getJavaType() + " (for type " + type + ")");
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) UnknownType(com.facebook.presto.common.type.UnknownType) Type(com.facebook.presto.common.type.Type) RowType(com.facebook.presto.common.type.RowType) RowType(com.facebook.presto.common.type.RowType) Map(java.util.Map) Collections.unmodifiableSortedMap(java.util.Collections.unmodifiableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) MapType(com.facebook.presto.common.type.MapType)

Example 28 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class TestFunctionResolution method testStandardFunctionResolution.

@Test
public void testStandardFunctionResolution() {
    StandardFunctionResolution standardFunctionResolution = functionResolution;
    // not
    assertTrue(standardFunctionResolution.isNotFunction(standardFunctionResolution.notFunction()));
    // negate
    assertTrue(standardFunctionResolution.isNegateFunction(standardFunctionResolution.negateFunction(DOUBLE)));
    assertFalse(standardFunctionResolution.isNotFunction(standardFunctionResolution.negateFunction(DOUBLE)));
    // arithmetic
    assertTrue(standardFunctionResolution.isArithmeticFunction(standardFunctionResolution.arithmeticFunction(ADD, DOUBLE, DOUBLE)));
    assertFalse(standardFunctionResolution.isComparisonFunction(standardFunctionResolution.arithmeticFunction(ADD, DOUBLE, DOUBLE)));
    // comparison
    assertTrue(standardFunctionResolution.isComparisonFunction(standardFunctionResolution.comparisonFunction(GREATER_THAN, DOUBLE, DOUBLE)));
    assertFalse(standardFunctionResolution.isArithmeticFunction(standardFunctionResolution.comparisonFunction(GREATER_THAN, DOUBLE, DOUBLE)));
    // between
    assertTrue(standardFunctionResolution.isBetweenFunction(standardFunctionResolution.betweenFunction(DOUBLE, DOUBLE, DOUBLE)));
    assertFalse(standardFunctionResolution.isNotFunction(standardFunctionResolution.betweenFunction(DOUBLE, DOUBLE, DOUBLE)));
    // subscript
    assertTrue(standardFunctionResolution.isSubscriptFunction(standardFunctionResolution.subscriptFunction(new ArrayType(DOUBLE), BIGINT)));
    assertFalse(standardFunctionResolution.isBetweenFunction(standardFunctionResolution.subscriptFunction(new ArrayType(DOUBLE), BIGINT)));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) StandardFunctionResolution(com.facebook.presto.spi.function.StandardFunctionResolution) Test(org.testng.annotations.Test)

Example 29 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class TestPinotColumnMetadata method testParsePinotSchemaToPinotColumns.

@Test
public void testParsePinotSchemaToPinotColumns() {
    PinotConfig pinotConfig = new PinotConfig();
    pinotConfig.setInferDateTypeInSchema(true);
    pinotConfig.setInferTimestampTypeInSchema(true);
    Schema testPinotSchema = new Schema.SchemaBuilder().addSingleValueDimension("singleValueIntDimension", FieldSpec.DataType.INT).addSingleValueDimension("singleValueLongDimension", FieldSpec.DataType.LONG).addSingleValueDimension("singleValueFloatDimension", FieldSpec.DataType.FLOAT).addSingleValueDimension("singleValueDoubleDimension", FieldSpec.DataType.DOUBLE).addSingleValueDimension("singleValueBytesDimension", FieldSpec.DataType.BYTES).addSingleValueDimension("singleValueBooleanDimension", FieldSpec.DataType.BOOLEAN).addSingleValueDimension("singleValueStringDimension", FieldSpec.DataType.STRING).addMultiValueDimension("multiValueIntDimension", FieldSpec.DataType.INT).addMultiValueDimension("multiValueLongDimension", FieldSpec.DataType.LONG).addMultiValueDimension("multiValueFloatDimension", FieldSpec.DataType.FLOAT).addMultiValueDimension("multiValueDoubleDimension", FieldSpec.DataType.DOUBLE).addMultiValueDimension("multiValueBytesDimension", FieldSpec.DataType.BYTES).addMultiValueDimension("multiValueBooleanDimension", FieldSpec.DataType.BOOLEAN).addMultiValueDimension("multiValueStringDimension", FieldSpec.DataType.STRING).addMetric("intMetric", FieldSpec.DataType.INT).addMetric("longMetric", FieldSpec.DataType.LONG).addMetric("floatMetric", FieldSpec.DataType.FLOAT).addMetric("doubleMetric", FieldSpec.DataType.DOUBLE).addMetric("bytesMetric", FieldSpec.DataType.BYTES).addTime(new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch")).addDateTime("epochDayDateTime", FieldSpec.DataType.INT, "1:DAYS:EPOCH", "1:DAYS").addDateTime("epochMillisDateTime", FieldSpec.DataType.LONG, "1:MILLISECONDS:EPOCH", "1:SECONDS").addDateTime("epochTenDayDateTime", FieldSpec.DataType.INT, "10:DAYS:EPOCH", "1:DAYS").addDateTime("epochSecondsDateTime", FieldSpec.DataType.LONG, "1:SECONDS:EPOCH", "1:SECONDS").build();
    Map<String, Type> expectedTypeMap = new ImmutableMap.Builder<String, Type>().put("singleValueIntDimension", INTEGER).put("singleValueLongDimension", BIGINT).put("singleValueFloatDimension", DOUBLE).put("singleValueDoubleDimension", DOUBLE).put("singleValueBytesDimension", VARBINARY).put("singleValueBooleanDimension", BOOLEAN).put("singleValueStringDimension", VARCHAR).put("multiValueIntDimension", new ArrayType(INTEGER)).put("multiValueLongDimension", new ArrayType(BIGINT)).put("multiValueFloatDimension", new ArrayType(DOUBLE)).put("multiValueDoubleDimension", new ArrayType(DOUBLE)).put("multiValueBytesDimension", new ArrayType(VARBINARY)).put("multiValueBooleanDimension", new ArrayType(BOOLEAN)).put("multiValueStringDimension", new ArrayType(VARCHAR)).put("intMetric", INTEGER).put("longMetric", BIGINT).put("floatMetric", DOUBLE).put("doubleMetric", DOUBLE).put("bytesMetric", VARBINARY).put("daysSinceEpoch", DateType.DATE).put("epochDayDateTime", DateType.DATE).put("epochMillisDateTime", TimestampType.TIMESTAMP).put("epochTenDayDateTime", INTEGER).put("epochSecondsDateTime", BIGINT).build();
    Map<String, String> expectedComment = new ImmutableMap.Builder<String, String>().put("sd1", FieldSpec.FieldType.DIMENSION.name()).put("singleValueIntDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueLongDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueFloatDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueDoubleDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueBytesDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueBooleanDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueStringDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueIntDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueLongDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueFloatDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueDoubleDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueBytesDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueBooleanDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueStringDimension", FieldSpec.FieldType.DIMENSION.name()).put("intMetric", FieldSpec.FieldType.METRIC.name()).put("longMetric", FieldSpec.FieldType.METRIC.name()).put("floatMetric", FieldSpec.FieldType.METRIC.name()).put("doubleMetric", FieldSpec.FieldType.METRIC.name()).put("bytesMetric", FieldSpec.FieldType.METRIC.name()).put("daysSinceEpoch", FieldSpec.FieldType.TIME.name()).put("epochDayDateTime", FieldSpec.FieldType.DATE_TIME.name()).put("epochMillisDateTime", FieldSpec.FieldType.DATE_TIME.name()).put("epochTenDayDateTime", FieldSpec.FieldType.DATE_TIME.name()).put("epochSecondsDateTime", FieldSpec.FieldType.DATE_TIME.name()).build();
    List<PinotColumn> pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testPinotSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    for (PinotColumn column : pinotColumns) {
        assertEquals(column.getType(), expectedTypeMap.get(column.getName()), "Failed to compare column type for field - " + column.getName());
        assertEquals(column.getComment(), expectedComment.get(column.getName()), "Failed to compare column comment for field - " + column.getName());
        assertEquals(column.isNullable(), false);
    }
}
Also used : TimeGranularitySpec(org.apache.pinot.spi.data.TimeGranularitySpec) Schema(org.apache.pinot.spi.data.Schema) ImmutableMap(com.google.common.collect.ImmutableMap) ArrayType(com.facebook.presto.common.type.ArrayType) ArrayType(com.facebook.presto.common.type.ArrayType) DateType(com.facebook.presto.common.type.DateType) Type(com.facebook.presto.common.type.Type) TimestampType(com.facebook.presto.common.type.TimestampType) Test(org.testng.annotations.Test)

Example 30 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class TestPinotSegmentPageSource method testMultivaluedType.

@Test
public void testMultivaluedType() throws IOException {
    String[] columnNames = { "col1", "col2" };
    DataSchema.ColumnDataType[] columnDataTypes = { DataSchema.ColumnDataType.INT_ARRAY, DataSchema.ColumnDataType.STRING_ARRAY };
    DataSchema dataSchema = new DataSchema(columnNames, columnDataTypes);
    String[] stringArray = { "stringVal1", "stringVal2" };
    int[] intArray = { 10, 34, 67 };
    DataTableBuilder dataTableBuilder = new DataTableBuilder(dataSchema);
    dataTableBuilder.startRow();
    dataTableBuilder.setColumn(0, intArray);
    dataTableBuilder.setColumn(1, stringArray);
    dataTableBuilder.finishRow();
    DataTable dataTable = dataTableBuilder.build();
    PinotSessionProperties pinotSessionProperties = new PinotSessionProperties(pinotConfig);
    ConnectorSession session = new TestingConnectorSession(pinotSessionProperties.getSessionProperties());
    List<PinotColumnHandle> pinotColumnHandles = ImmutableList.of(new PinotColumnHandle(columnNames[0], PinotColumnUtils.getPrestoTypeFromPinotType(getFieldSpec(columnNames[0], columnDataTypes[0]), false, false), PinotColumnHandle.PinotColumnType.REGULAR), new PinotColumnHandle(columnNames[1], PinotColumnUtils.getPrestoTypeFromPinotType(getFieldSpec(columnNames[1], columnDataTypes[1]), false, false), PinotColumnHandle.PinotColumnType.REGULAR));
    PinotSplit mockPinotSplit = new PinotSplit(pinotConnectorId.toString(), PinotSplit.SplitType.SEGMENT, pinotColumnHandles, Optional.empty(), Optional.of("blah"), ImmutableList.of("seg"), Optional.of("host"), getGrpcPort());
    PinotSegmentPageSource pinotSegmentPageSource = getPinotSegmentPageSource(session, ImmutableList.of(dataTable), mockPinotSplit, pinotColumnHandles);
    Page page = requireNonNull(pinotSegmentPageSource.getNextPage(), "Expected a valid page");
    for (int i = 0; i < columnDataTypes.length; i++) {
        Block block = page.getBlock(i);
        Type type = PinotColumnUtils.getPrestoTypeFromPinotType(getFieldSpec(columnNames[i], columnDataTypes[i]), false, false);
        Assert.assertTrue(type instanceof ArrayType, "presto type should be array");
        if (((ArrayType) type).getElementType() instanceof IntegerType) {
            Assert.assertTrue(block.getBlock(0).getInt(0) == 10, "Array element not matching");
            Assert.assertTrue(block.getBlock(0).getInt(1) == 34, "Array element not matching");
            Assert.assertTrue(block.getBlock(0).getInt(2) == 67, "Array element not matching");
        } else if (((ArrayType) type).getElementType() instanceof VariableWidthType) {
            Type type1 = ((ArrayType) type).getElementType();
            Assert.assertTrue(block.getBlock(0) instanceof VariableWidthBlock);
            VariableWidthBlock variableWidthBlock = (VariableWidthBlock) block.getBlock(0);
            Assert.assertTrue("stringVal1".equals(new String(variableWidthBlock.getSlice(0, 0, variableWidthBlock.getSliceLength(0)).getBytes())), "Array element not matching");
            Assert.assertTrue("stringVal2".equals(new String(variableWidthBlock.getSlice(1, 0, variableWidthBlock.getSliceLength(1)).getBytes())), "Array element not matching");
        }
    }
}
Also used : DataTable(org.apache.pinot.common.utils.DataTable) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) Page(com.facebook.presto.common.Page) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) DataSchema(org.apache.pinot.common.utils.DataSchema) ArrayType(com.facebook.presto.common.type.ArrayType) IntegerType(com.facebook.presto.common.type.IntegerType) VariableWidthType(com.facebook.presto.common.type.VariableWidthType) IntegerType(com.facebook.presto.common.type.IntegerType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) Block(com.facebook.presto.common.block.Block) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) VariableWidthType(com.facebook.presto.common.type.VariableWidthType) DataTableBuilder(org.apache.pinot.core.common.datatable.DataTableBuilder) Test(org.testng.annotations.Test)

Aggregations

ArrayType (com.facebook.presto.common.type.ArrayType)287 Test (org.testng.annotations.Test)219 Type (com.facebook.presto.common.type.Type)99 RowType (com.facebook.presto.common.type.RowType)79 ArrayList (java.util.ArrayList)58 ImmutableList (com.google.common.collect.ImmutableList)54 List (java.util.List)51 MapType (com.facebook.presto.common.type.MapType)39 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)36 Arrays.asList (java.util.Arrays.asList)34 Collections.singletonList (java.util.Collections.singletonList)33 MessageType (org.apache.parquet.schema.MessageType)30 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)28 VarcharType.createUnboundedVarcharType (com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType)27 MessageTypeParser.parseMessageType (org.apache.parquet.schema.MessageTypeParser.parseMessageType)27 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)26 PrimitiveType (org.apache.parquet.schema.PrimitiveType)26 StructuralTestUtil.mapType (com.facebook.presto.tests.StructuralTestUtil.mapType)24 Block (com.facebook.presto.common.block.Block)23 DecimalType (com.facebook.presto.common.type.DecimalType)17