Source:
public static Block bigintDistinct(@SqlType("array(bigint)") Block array) { final int arrayLength = array.getPositionCount(); if (arrayLength < 2) { return array; } BlockBuilder distinctElementBlockBuilder; LongSet set = new LongOpenHashSet(arrayLength); if (array.mayHaveNull()) { int position = 0; boolean notSeenNull = true; while (position < arrayLength) { if (array.isNull(position)) { if (notSeenNull) { notSeenNull = false; } else { break; } } else if (!set.add(BIGINT.getLong(array, position))) { break; } position++; } if (position == arrayLength) { return array; } distinctElementBlockBuilder = BIGINT.createBlockBuilder(null, arrayLength); for (int i = 0; i < position; i++) { BIGINT.appendTo(array, i, distinctElementBlockBuilder); } for (position++; position < arrayLength; position++) { if (array.isNull(position)) { if (notSeenNull) { notSeenNull = false; } } else if (set.add(BIGINT.getLong(array, position))) { BIGINT.appendTo(array, position, distinctElementBlockBuilder); } } if (!notSeenNull) { distinctElementBlockBuilder.appendNull(); } } else { int position = 0; while (position < arrayLength && set.add(BIGINT.getLong(array, position))) { position++; } if (position == arrayLength) { return array; } distinctElementBlockBuilder = BIGINT.createBlockBuilder(null, arrayLength); for (int i = 0; i < position; i++) { BIGINT.appendTo(array, i, distinctElementBlockBuilder); } for (position++; position < arrayLength; position++) { if (set.add(BIGINT.getLong(array, position))) { BIGINT.appendTo(array, position, distinctElementBlockBuilder); } } } return distinctElementBlockBuilder.build(); }

Target:
public static Block bigintDistinct(@SqlType("array(bigint)") Block array) { final int arrayLength = array.getPositionCount(); if (arrayLength < 2) { return array; } BlockBuilder distinctElementBlockBuilder; LongSet set = new LongOpenHashSet(arrayLength); if (array.mayHaveNull()) { int position = 0; boolean containsNull = false; while (position < arrayLength) { if (array.isNull(position)) { if (!containsNull) { containsNull = true; } else { break; } } else if (!set.add(BIGINT.getLong(array, position))) { break; } position++; } if (position == arrayLength) { return array; } distinctElementBlockBuilder = BIGINT.createBlockBuilder(null, arrayLength); for (int i = 0; i < position; i++) { BIGINT.appendTo(array, i, distinctElementBlockBuilder); } for (position++; position < arrayLength; position++) { if (array.isNull(position)) { if (!containsNull) { BIGINT.appendTo(array, position, distinctElementBlockBuilder); } } else if (set.add(BIGINT.getLong(array, position))) { BIGINT.appendTo(array, position, distinctElementBlockBuilder); } } } else { int position = 0; while (position < arrayLength && set.add(BIGINT.getLong(array, position))) { position++; } if (position == arrayLength) { return array; } distinctElementBlockBuilder = BIGINT.createBlockBuilder(null, arrayLength); for (int i = 0; i < position; i++) { BIGINT.appendTo(array, i, distinctElementBlockBuilder); } for (position++; position < arrayLength; position++) { if (set.add(BIGINT.getLong(array, position))) { BIGINT.appendTo(array, position, distinctElementBlockBuilder); } } } return distinctElementBlockBuilder.build(); }