@Override public void encodeValueInto(Block block, int position, SliceOutput output) { output.writeLong(Long.reverseBytes(Double.doubleToLongBits(type.getDouble(block, position)))); }
@Override void readFirstField(Block block, int position, DoubleAndBlockPositionValueState state) { state.setFirst(firstType.getDouble(block, position)); }
private void encodeValue(Block block, int position, SliceOutput output) { double value = type.getDouble(block, position); buffer.setLength(0); buffer.append(value); for (int index = 0; index < buffer.length(); index++) { output.writeByte(buffer.charAt(index)); } }
@Override public double getDouble(int field) { return types.get(field).getDouble(page.getBlock(field), position); }
@Override public double getDouble(int field) { checkState(position >= 0, "Not yet advanced"); checkState(position < page.getPositionCount(), "Already finished"); Type type = types.get(field); return type.getDouble(page.getBlock(field), position); }
@UsedByGeneratedCode public static Double doubleSubscript(Type elementType, Block array, long index) { checkIndex(array, index); int position = toIntExact(index - 1); if (array.isNull(position)) { return null; } return elementType.getDouble(array, position); }
public static void input(Type type, NullableDoubleState state, Block block, int position) { if (!state.isNull()) { return; } state.setNull(false); state.setDouble(type.getDouble(block, position)); }
public double getDouble(int channel, int position) { long pageAddress = valueAddresses.getLong(position); Block block = channels[channel].get(decodeSliceIndex(pageAddress)); int blockPosition = decodePosition(pageAddress); return types.get(channel).getDouble(block, blockPosition); }
@Override public void addBlock(Type type, Block block) { for (int position = 0; position < block.getPositionCount(); position++) { if (!block.isNull(position)) { double value; if (type == RealType.REAL) { value = Float.intBitsToFloat((int) type.getLong(block, position)); } else { value = type.getDouble(block, position); } addValue(value); } } }
@UsedByGeneratedCode public static Double doubleArrayMinMax(MethodHandle compareMethodHandle, Type elementType, Block block) { try { if (block.getPositionCount() == 0) { return null; } boolean containNull = false; double selectedValue = elementType.getDouble(block, 0); for (int i = 0; i < block.getPositionCount(); i++) { if (block.isNull(i)) { containNull = true; } double value = elementType.getDouble(block, i); if ((boolean) compareMethodHandle.invokeExact(value, selectedValue)) { selectedValue = value; } else if (isNaN(value)) { return NaN; } } return containNull ? null : 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)) { double value = type.getDouble(block, position); statisticsBuilder.addValue(value); dataStream.writeDouble(value); } } }
/** * 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("T") @TypeParameterSpecialization(name = "T", nativeContainerType = double.class) @SqlType("array(T)") public Block sortDouble( @TypeParameter("T") Type type, @SqlType("array(T)") Block block, @SqlType("function(T, T, int)") ComparatorDoubleLambda function) { int arrayLength = block.getPositionCount(); initPositionsList(arrayLength); Comparator<Integer> comparator = (x, y) -> comparatorResult(function.apply( block.isNull(x) ? null : type.getDouble(block, x), block.isNull(y) ? null : type.getDouble(block, y))); sortPositions(arrayLength, comparator); return computeResultBlock(type, block, arrayLength); }
@TypeParameter("E") @SqlNullable @SqlType("E") public static Double doubleElementAt(@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.getDouble(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("T") @TypeParameterSpecialization(name = "T", nativeContainerType = double.class) @SqlType("array(T)") public static Block filterDouble( @TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") FilterDoubleLambda function) { int positionCount = arrayBlock.getPositionCount(); BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { Double input = null; if (!arrayBlock.isNull(position)) { input = elementType.getDouble(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 = double.class) @SqlType(StandardTypes.BIGINT) public static long hashDouble( @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.getDouble(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") double element) { int size = array.getPositionCount(); for (int i = 0; i < size; i++) { if (!array.isNull(i)) { double arrayValue = type.getDouble(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; }
Boolean result = (Boolean) equals.invokeExact(elementType.getDouble(arrayBlock, i), value); checkNotIndeterminate(result); if (result) {
private Block createAlternatingNullsBlock(Block testBlock) { BlockBuilder nullsBlockBuilder = type.createBlockBuilder(null, testBlock.getPositionCount()); for (int position = 0; position < testBlock.getPositionCount(); position++) { if (testBlock.isNull(position)) { checkState(type instanceof UnknownType); nullsBlockBuilder.appendNull(); } else if (type.getJavaType() == boolean.class) { type.writeBoolean(nullsBlockBuilder, type.getBoolean(testBlock, position)); } else if (type.getJavaType() == long.class) { type.writeLong(nullsBlockBuilder, type.getLong(testBlock, position)); } else if (type.getJavaType() == double.class) { type.writeDouble(nullsBlockBuilder, type.getDouble(testBlock, position)); } else if (type.getJavaType() == Slice.class) { Slice slice = type.getSlice(testBlock, position); type.writeSlice(nullsBlockBuilder, slice, 0, slice.length()); } else { type.writeObject(nullsBlockBuilder, type.getObject(testBlock, position)); } nullsBlockBuilder.appendNull(); } return nullsBlockBuilder.build(); }