use of com.facebook.presto.type.ArrayType in project presto by prestodb.
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 = symbolAllocator.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(), symbolAllocator, 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) {
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 com.facebook.presto.type.ArrayType in project presto by prestodb.
the class BlockAssertions method createStringArraysBlock.
public static Block createStringArraysBlock(Iterable<? extends Iterable<String>> values) {
ArrayType arrayType = new ArrayType(VARCHAR);
BlockBuilder builder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 100);
for (Iterable<String> value : values) {
if (value == null) {
builder.appendNull();
} else {
arrayType.writeObject(builder, createStringsBlock(value));
}
}
return builder.build();
}
use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class BlockAssertions method createArrayBigintBlock.
public static Block createArrayBigintBlock(Iterable<? extends Iterable<Long>> values) {
ArrayType arrayType = new ArrayType(BIGINT);
BlockBuilder builder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 100);
for (Iterable<Long> value : values) {
if (value == null) {
builder.appendNull();
} else {
arrayType.writeObject(builder, createLongsBlock(value));
}
}
return builder.build();
}
use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class TestUnnestOperator method testUnnestNonNumericDoubles.
@Test
public void testUnnestNonNumericDoubles() throws Exception {
MetadataManager metadata = createTestMetadataManager();
Type arrayType = metadata.getType(parseTypeSignature("array(double)"));
Type mapType = metadata.getType(parseTypeSignature("map(bigint,double)"));
List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(DOUBLE, NEGATIVE_INFINITY, POSITIVE_INFINITY, NaN), mapBlockOf(BIGINT, DOUBLE, ImmutableMap.of(1, NEGATIVE_INFINITY, 2, POSITIVE_INFINITY, 3, NaN))).build();
OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE, BIGINT, DOUBLE).row(1L, NEGATIVE_INFINITY, 1L, NEGATIVE_INFINITY).row(1L, POSITIVE_INFINITY, 2L, POSITIVE_INFINITY).row(1L, NaN, 3L, NaN).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class TestApproximatePercentileAggregation method createRLEBlock.
private static RunLengthEncodedBlock createRLEBlock(Iterable<Double> percentiles, int positionCount) {
BlockBuilder rleBlockBuilder = new ArrayType(DOUBLE).createBlockBuilder(new BlockBuilderStatus(), 1);
BlockBuilder arrayBlockBuilder = rleBlockBuilder.beginBlockEntry();
for (double percentile : percentiles) {
DOUBLE.writeDouble(arrayBlockBuilder, percentile);
}
rleBlockBuilder.closeEntry();
return new RunLengthEncodedBlock(rleBlockBuilder.build(), positionCount);
}
Aggregations