use of io.prestosql.operator.aggregation.TypedSet in project hetu-core by openlookeng.
the class ArrayExceptFunction method except.
@TypeParameter("E")
@SqlType("array(E)")
public static Block except(@TypeParameter("E") Type type, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) {
int leftPositionCount = leftArray.getPositionCount();
int rightPositionCount = rightArray.getPositionCount();
if (leftPositionCount == 0) {
return leftArray;
}
TypedSet typedSet = new TypedSet(type, leftPositionCount + rightPositionCount, "array_except");
BlockBuilder distinctElementBlockBuilder = type.createBlockBuilder(null, leftPositionCount);
for (int i = 0; i < rightPositionCount; i++) {
typedSet.add(rightArray, i);
}
for (int i = 0; i < leftPositionCount; i++) {
if (!typedSet.contains(leftArray, i)) {
typedSet.add(leftArray, i);
type.appendTo(leftArray, i, distinctElementBlockBuilder);
}
}
return distinctElementBlockBuilder.build();
}
Aggregations