@Override protected boolean isEntryNull(int position) { return valueIsNull != null && valueIsNull.getByte(position) != 0; }
@ScalarOperator(CAST) @SqlType(StandardTypes.HYPER_LOG_LOG) public static Slice castToHyperLogLog(@SqlType(SetDigestType.NAME) Slice slice) { checkArgument(slice.getByte(0) == 1, "Legacy version of SetDigest cannot cast to HyperLogLog"); int hllLength = slice.getInt(SIZE_OF_BYTE); return Slices.wrappedBuffer(slice.getBytes(SIZE_OF_BYTE + SIZE_OF_INT, hllLength)); } }
public static long readVInt(Slice slice, int start, int length) { if (length == 1) { return slice.getByte(start); } return readVIntInternal(slice, start, length); }
@SuppressWarnings("PointlessArithmeticExpression") private static boolean isFalse(Slice slice, int start, int length) { return (length == 5) && (toUpperCase(slice.getByte(start + 0)) == 'F') && (toUpperCase(slice.getByte(start + 1)) == 'A') && (toUpperCase(slice.getByte(start + 2)) == 'L') && (toUpperCase(slice.getByte(start + 3)) == 'S') && (toUpperCase(slice.getByte(start + 4)) == 'E'); }
@Override protected boolean isEntryNull(int position) { return valueIsNull.getUnderlyingSlice().getByte(position) != 0; }
@Override public void decodeValueInto(BlockBuilder builder, Slice slice, int offset, int length) { type.writeLong(builder, slice.getByte(offset)); } }
@SuppressWarnings("PointlessArithmeticExpression") private static boolean isTrue(Slice slice, int start, int length) { return (length == 4) && (toUpperCase(slice.getByte(start + 0)) == 'T') && (toUpperCase(slice.getByte(start + 1)) == 'R') && (toUpperCase(slice.getByte(start + 2)) == 'U') && (toUpperCase(slice.getByte(start + 3)) == 'E'); }
private static int hashBytes(int initialValue, Slice bytes) { int result = initialValue; for (int i = 0; i < bytes.length(); i++) { result = result * 31 + bytes.getByte(i); } return result; }
@Override public void decodeValueInto(BlockBuilder builder, Slice slice, int offset, int length) { type.writeBoolean(builder, slice.getByte(offset) != 0); } }
public static boolean isNegativeVInt(Slice slice, int offset) { return isNegativeVInt(slice.getByte(offset)); }
public static int decodeVIntSize(Slice slice, int offset) { return decodeVIntSize(slice.getByte(offset)); }
private BigDecimal parseBigDecimal(Slice slice, int offset, int length) { checkArgument(length < buffer.length); for (int i = 0; i < length; i++) { buffer[i] = (char) slice.getByte(offset + i); } BigDecimal decimal = new BigDecimal(buffer, 0, length); checkState(decimal.scale() <= type.getScale(), "Read decimal value scale larger than column scale"); decimal = decimal.setScale(type.getScale(), HALF_UP); checkState(decimal.precision() <= type.getPrecision(), "Read decimal precision larger than column precision"); return decimal; } }
@Override public void writeSlice(BlockBuilder blockBuilder, Slice value, int offset, int length) { if (length > 0 && value.getByte(offset + length - 1) == ' ') { throw new IllegalArgumentException("Slice representing Char should not have trailing spaces"); } blockBuilder.writeBytes(value, offset, length).closeEntry(); }
private static int compareCharsShorterToLonger(Slice shorter, Slice longer) { for (int i = 0; i < shorter.length(); ++i) { int result = compareUnsignedBytes(shorter.getByte(i), longer.getByte(i)); if (result != 0) { return result; } } for (int i = shorter.length(); i < longer.length(); ++i) { int result = compareUnsignedBytes((byte) ' ', longer.getByte(i)); if (result != 0) { return result; } } return 0; }
public static long readVInt(Slice slice, int start) { byte firstByte = slice.getByte(start); int length = decodeVIntSize(firstByte); if (length == 1) { return firstByte; } return readVIntInternal(slice, start, length); }
@Override public byte getByte(int position, int offset) { checkReadablePosition(position); return getRawSlice().getByte(valueOffset(position) + offset); }
@Override public byte getByte(int position, int offset) { checkReadablePosition(position); return getRawSlice(position).getByte(getPositionOffset(position) + offset); }
@Override public int getValueLength(Slice slice, int offset) { int length = 4; if (hasNanosVInt(slice.getByte(offset))) { int nanosVintLength = decodeVIntSize(slice, offset + 4); length += nanosVintLength; // is there extra data for "seconds" if (isNegativeVInt(slice, offset + 4)) { length += decodeVIntSize(slice, offset + 4 + nanosVintLength); } } return length; }
private static void writeValues(Slice[] expectedValues, BlockBuilder blockBuilder) { for (Slice expectedValue : expectedValues) { if (expectedValue == null) { blockBuilder.appendNull(); } else { blockBuilder.writeByte(expectedValue.getByte(0)).closeEntry(); } } }