use of io.prestosql.spi.type.RowType in project hetu-core by openlookeng.
the class TypeCoercion method typeCompatibilityForRow.
private TypeCompatibility typeCompatibilityForRow(RowType firstType, RowType secondType) {
List<Field> firstFields = firstType.getFields();
List<Field> secondFields = secondType.getFields();
if (firstFields.size() != secondFields.size()) {
return TypeCompatibility.incompatible();
}
ImmutableList.Builder<Field> fields = ImmutableList.builder();
boolean coercible = true;
for (int i = 0; i < firstFields.size(); i++) {
Type firstFieldType = firstFields.get(i).getType();
Type secondFieldType = secondFields.get(i).getType();
TypeCompatibility typeCompatibility = compatibility(firstFieldType, secondFieldType);
if (!typeCompatibility.isCompatible()) {
return TypeCompatibility.incompatible();
}
Type commonParameterType = typeCompatibility.getCommonSuperType();
Optional<String> firstParameterName = firstFields.get(i).getName();
Optional<String> secondParameterName = secondFields.get(i).getName();
Optional<String> commonName = firstParameterName.equals(secondParameterName) ? firstParameterName : Optional.empty();
// ignore parameter name for coercible
coercible &= typeCompatibility.isCoercible();
fields.add(new Field(commonName, commonParameterType));
}
return TypeCompatibility.compatible(RowType.from(fields.build()), coercible);
}
use of io.prestosql.spi.type.RowType in project hetu-core by openlookeng.
the class OperatorAssertion method toRow.
public static Block toRow(List<Type> parameterTypes, Object... values) {
checkArgument(parameterTypes.size() == values.length, "parameterTypes.size(" + parameterTypes.size() + ") does not equal to values.length(" + values.length + ")");
RowType rowType = RowType.anonymous(parameterTypes);
BlockBuilder blockBuilder = new RowBlockBuilder(parameterTypes, null, 1);
BlockBuilder singleRowBlockWriter = blockBuilder.beginBlockEntry();
for (int i = 0; i < values.length; i++) {
appendToBlockBuilder(parameterTypes.get(i), values[i], singleRowBlockWriter);
}
blockBuilder.closeEntry();
return rowType.getObject(blockBuilder, 0);
}
use of io.prestosql.spi.type.RowType in project hetu-core by openlookeng.
the class TestTypeUtil method testParametricType.
@Test
public void testParametricType() {
Type type = parseType(typeManager, "decimal(10,2)");
assertTrue(type instanceof DecimalType);
type = parseType(typeManager, "char(100)");
assertTrue(type instanceof CharType);
type = parseType(typeManager, "varchar(100)");
assertTrue(type instanceof VarcharType);
type = parseType(typeManager, "array(varchar(10))");
assertTrue(type instanceof ArrayType);
type = parseType(typeManager, "row(street varchar(10))");
assertTrue(type instanceof RowType);
}
use of io.prestosql.spi.type.RowType in project hetu-core by openlookeng.
the class RelationPlanner method planCrossJoinUnnest.
private RelationPlan planCrossJoinUnnest(RelationPlan leftPlan, Join joinNode, Unnest node) {
RelationType unnestOutputDescriptor = analysis.getOutputDescriptor(node);
// Create symbols for the result of unnesting
ImmutableList.Builder<Symbol> unnestedSymbolsBuilder = ImmutableList.builder();
for (Field field : unnestOutputDescriptor.getVisibleFields()) {
Symbol symbol = planSymbolAllocator.newSymbol(field);
unnestedSymbolsBuilder.add(symbol);
}
ImmutableList<Symbol> unnestedSymbols = unnestedSymbolsBuilder.build();
// Add a projection for all the unnest arguments
PlanBuilder planBuilder = initializePlanBuilder(leftPlan);
planBuilder = planBuilder.appendProjections(node.getExpressions(), planSymbolAllocator, idAllocator);
TranslationMap translations = planBuilder.getTranslations();
ProjectNode projectNode = (ProjectNode) planBuilder.getRoot();
ImmutableMap.Builder<Symbol, List<Symbol>> unnestSymbols = ImmutableMap.builder();
UnmodifiableIterator<Symbol> unnestedSymbolsIterator = unnestedSymbols.iterator();
for (Expression expression : node.getExpressions()) {
Type type = analysis.getType(expression);
Symbol inputSymbol = translations.get(expression);
if (type instanceof ArrayType) {
Type elementType = ((ArrayType) type).getElementType();
if (elementType instanceof RowType) {
ImmutableList.Builder<Symbol> unnestSymbolBuilder = ImmutableList.builder();
for (int i = 0; i < ((RowType) elementType).getFields().size(); i++) {
unnestSymbolBuilder.add(unnestedSymbolsIterator.next());
}
unnestSymbols.put(inputSymbol, unnestSymbolBuilder.build());
} else {
unnestSymbols.put(inputSymbol, ImmutableList.of(unnestedSymbolsIterator.next()));
}
} else if (type instanceof MapType) {
unnestSymbols.put(inputSymbol, ImmutableList.of(unnestedSymbolsIterator.next(), unnestedSymbolsIterator.next()));
} else {
throw new IllegalArgumentException("Unsupported type for UNNEST: " + type);
}
}
Optional<Symbol> ordinalitySymbol = node.isWithOrdinality() ? Optional.of(unnestedSymbolsIterator.next()) : Optional.empty();
checkState(!unnestedSymbolsIterator.hasNext(), "Not all output symbols were matched with input symbols");
UnnestNode unnestNode = new UnnestNode(idAllocator.getNextId(), projectNode, leftPlan.getFieldMappings(), unnestSymbols.build(), ordinalitySymbol);
return new RelationPlan(unnestNode, analysis.getScope(joinNode), unnestNode.getOutputSymbols());
}
use of io.prestosql.spi.type.RowType in project hetu-core by openlookeng.
the class TestSerDeUtils method testMapBlock.
@Test
public void testMapBlock() {
MapHolder holder = new MapHolder();
holder.map = new TreeMap<>();
holder.map.put("twelve", new InnerStruct(13, 14L));
holder.map.put("fifteen", new InnerStruct(16, 17L));
RowType rowType = RowType.anonymous(ImmutableList.of(INTEGER, BIGINT));
RowType rowOfMapOfVarcharRowType = RowType.anonymous(ImmutableList.of(HiveTestUtils.mapType(VARCHAR, rowType)));
Block actual = toBinaryBlock(rowOfMapOfVarcharRowType, holder, getInspector(MapHolder.class));
Block mapBlock = mapBlockOf(VARCHAR, rowType, new Object[] { utf8Slice("fifteen"), utf8Slice("twelve") }, new Object[] { rowBlockOf(rowType.getTypeParameters(), 16, 17L), rowBlockOf(rowType.getTypeParameters(), 13, 14L) });
Block expected = StructuralTestUtil.rowBlockOf(ImmutableList.of(HiveTestUtils.mapType(VARCHAR, rowType)), mapBlock);
assertBlockEquals(actual, expected);
}
Aggregations