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