use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class TestArrayExceptFunction method testNull.
@Test
public void testNull() throws Exception {
assertFunction("array_except(ARRAY[NULL], NULL)", new ArrayType(UNKNOWN), null);
assertFunction("array_except(NULL, NULL)", new ArrayType(UNKNOWN), null);
assertFunction("array_except(NULL, ARRAY[NULL])", new ArrayType(UNKNOWN), null);
assertFunction("array_except(ARRAY[NULL], ARRAY[NULL])", new ArrayType(UNKNOWN), ImmutableList.of());
assertFunction("array_except(ARRAY[], ARRAY[NULL])", new ArrayType(UNKNOWN), ImmutableList.of());
assertFunction("array_except(ARRAY[NULL], ARRAY[])", new ArrayType(UNKNOWN), singletonList(null));
}
use of com.facebook.presto.type.ArrayType in project presto by prestodb.
the class TestArrayExceptFunction method testEmpty.
@Test
public void testEmpty() throws Exception {
assertFunction("array_except(ARRAY[], ARRAY[])", new ArrayType(UNKNOWN), ImmutableList.of());
assertFunction("array_except(ARRAY[], ARRAY[1, 3])", new ArrayType(INTEGER), ImmutableList.of());
assertFunction("array_except(ARRAY[CAST('abc' as VARCHAR)], ARRAY[])", new ArrayType(VARCHAR), ImmutableList.of("abc"));
}
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();
}
Aggregations