@Override public boolean getBoolean(int field) { return types.get(field).getBoolean(page.getBlock(field), position); }
@Override void readFirstField(Block block, int position, BooleanAndBlockPositionValueState state) { state.setFirst(firstType.getBoolean(block, position)); }
@Override public void encodeValueInto(Block block, int position, SliceOutput output) { output.writeBoolean(type.getBoolean(block, position)); }
@Override public boolean getBoolean(int field) { checkState(position >= 0, "Not yet advanced"); checkState(position < page.getPositionCount(), "Already finished"); Type type = types.get(field); return type.getBoolean(page.getBlock(field), position); }
private void encodeValue(Block block, int position, SliceOutput output) { if (type.getBoolean(block, position)) { output.writeBytes(TRUE); } else { output.writeBytes(FALSE); } }
@UsedByGeneratedCode public static Boolean booleanSubscript(Type elementType, Block array, long index) { checkIndex(array, index); int position = toIntExact(index - 1); if (array.isNull(position)) { return null; } return elementType.getBoolean(array, position); }
@Override public void addBlock(Type type, Block block) { for (int position = 0; position < block.getPositionCount(); position++) { if (!block.isNull(position)) { addValue(type.getBoolean(block, position)); } } }
public boolean getBoolean(int channel, int position) { long pageAddress = valueAddresses.getLong(position); Block block = channels[channel].get(decodeSliceIndex(pageAddress)); int blockPosition = decodePosition(pageAddress); return types.get(channel).getBoolean(block, blockPosition); }
public static void input(Type type, NullableBooleanState state, Block block, int position) { if (!state.isNull()) { return; } state.setNull(false); state.setBoolean(type.getBoolean(block, position)); }
@Override public void encodeColumn(Block block, SliceOutput output, EncodeOutput encodeOutput) { for (int position = 0; position < block.getPositionCount(); position++) { if (!block.isNull(position)) { output.writeBoolean(type.getBoolean(block, position)); } encodeOutput.closeEntry(); } }
@UsedByGeneratedCode public static Boolean booleanArrayMinMax(MethodHandle compareMethodHandle, Type elementType, Block block) { try { if (block.getPositionCount() == 0) { return null; } boolean selectedValue = elementType.getBoolean(block, 0); for (int i = 0; i < block.getPositionCount(); i++) { if (block.isNull(i)) { return null; } boolean value = elementType.getBoolean(block, i); if ((boolean) compareMethodHandle.invokeExact(value, selectedValue)) { selectedValue = value; } } return selectedValue; } catch (Throwable t) { throw internalError(t); } }
@Override public void writeBlock(Block block) { checkState(!closed); checkArgument(block.getPositionCount() > 0, "Block is empty"); // record nulls for (int position = 0; position < block.getPositionCount(); position++) { presentStream.writeBoolean(!block.isNull(position)); } // record values for (int position = 0; position < block.getPositionCount(); position++) { if (!block.isNull(position)) { boolean value = type.getBoolean(block, position); dataStream.writeBoolean(value); statisticsBuilder.addValue(value); } } }
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = boolean.class) @SqlType("array(T)") public Block sortBoolean( @TypeParameter("T") Type type, @SqlType("array(T)") Block block, @SqlType("function(T, T, int)") ComparatorBooleanLambda function) { int arrayLength = block.getPositionCount(); initPositionsList(arrayLength); Comparator<Integer> comparator = (x, y) -> comparatorResult(function.apply( block.isNull(x) ? null : type.getBoolean(block, x), block.isNull(y) ? null : type.getBoolean(block, y))); sortPositions(arrayLength, comparator); return computeResultBlock(type, block, arrayLength); }
/** * Get the native value as an object in the value at {@code position} of {@code block}. */ public static Object readNativeValue(Type type, Block block, int position) { Class<?> javaType = type.getJavaType(); if (block.isNull(position)) { return null; } if (javaType == long.class) { return type.getLong(block, position); } if (javaType == double.class) { return type.getDouble(block, position); } if (javaType == boolean.class) { return type.getBoolean(block, position); } if (javaType == Slice.class) { return type.getSlice(block, position); } return type.getObject(block, position); }
@TypeParameter("E") @SqlNullable @SqlType("E") public static Boolean booleanElementAt(@TypeParameter("E") Type elementType, @SqlType("array(E)") Block array, @SqlType("bigint") long index) { int position = checkedIndexToBlockPosition(array, index); if (position == -1) { return null; } if (array.isNull(position)) { return null; } return elementType.getBoolean(array, position); }
private static SortedMap<Integer, Object> indexStackValues(Type type, Block block) { SortedMap<Integer, Object> values = new TreeMap<>(); for (int position = 0; position < block.getPositionCount(); position++) { if (block.isNull(position)) { values.put(position, null); } else if (type.getJavaType() == boolean.class) { values.put(position, type.getBoolean(block, position)); } else if (type.getJavaType() == long.class) { values.put(position, type.getLong(block, position)); } else if (type.getJavaType() == double.class) { values.put(position, type.getDouble(block, position)); } else if (type.getJavaType() == Slice.class) { values.put(position, type.getSlice(block, position)); } else { values.put(position, type.getObject(block, position)); } } return unmodifiableSortedMap(values); }
@TypeParameter("E") @SqlNullable @SqlType("E") public static Boolean speciailizedBoolean(@TypeParameter("E") Type type, @BlockPosition @SqlType(value = "E", nativeContainerType = boolean.class) Block block, @BlockIndex int position) { hitBlockPositionBoolean.set(true); return type.getBoolean(block, position); }
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = boolean.class) @SqlType("array(T)") public static Block filterBoolean( @TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") FilterBooleanLambda function) { int positionCount = arrayBlock.getPositionCount(); BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { Boolean input = null; if (!arrayBlock.isNull(position)) { input = elementType.getBoolean(arrayBlock, position); } Boolean keep = function.apply(input); if (TRUE.equals(keep)) { elementType.appendTo(arrayBlock, position, resultBuilder); } } return resultBuilder.build(); }
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = boolean.class) @SqlType(StandardTypes.BIGINT) public static long hashBoolean( @OperatorDependency(operator = HASH_CODE, returnType = StandardTypes.BIGINT, argumentTypes = {"T"}) MethodHandle hashFunction, @TypeParameter("T") Type type, @SqlType("array(T)") Block block) { try { long hash = 0; for (int i = 0; i < block.getPositionCount(); i++) { hash = CombineHashFunction.getHash(hash, block.isNull(i) ? NULL_HASH_CODE : (long) hashFunction.invokeExact(type.getBoolean(block, i))); } return hash; } catch (Throwable t) { throw internalError(t); } }
@TypeParameter("T") @SqlType(StandardTypes.BIGINT) public static long arrayPosition( @TypeParameter("T") Type type, @OperatorDependency(operator = EQUAL, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle equalMethodHandle, @SqlType("array(T)") Block array, @SqlType("T") boolean element) { int size = array.getPositionCount(); for (int i = 0; i < size; i++) { if (!array.isNull(i)) { boolean arrayValue = type.getBoolean(array, i); try { Boolean result = (Boolean) equalMethodHandle.invokeExact(arrayValue, element); checkNotIndeterminate(result); if (result) { return i + 1; // result is 1-based (instead of 0) } } catch (Throwable t) { throw internalError(t); } } } return 0; }