private static int preceding(int rowPosition, long value) { if (value > rowPosition) { return 0; } return toIntExact(rowPosition - value); }
@Override public int size() { return toIntExact(bufferOffset + bufferPosition); }
@Override public int getValueLength(Slice slice, int offset) { return toIntExact(readVInt(slice, offset)); }
public int getFullGcCount() { long startFullGcCount = this.startFullGcCount.get(); if (startFullGcCount < 0) { return 0; } long endFullGcCount = this.endFullGcCount.get(); if (endFullGcCount <= 0) { endFullGcCount = gcMonitor.getMajorGcCount(); } return toIntExact(max(0, endFullGcCount - startFullGcCount)); }
@Override public void setPosition(long position) { if (delegate == null) { if (position < 0 || position > globalLength) { throw new IndexOutOfBoundsException("Invalid position " + position + " for slice with length " + globalLength); } initialPosition = toIntExact(position); return; } delegate.setPosition(position); }
@Override public void writeLong(BlockBuilder blockBuilder, long value) { try { toIntExact(value); } catch (ArithmeticException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Value (%sb) is not a valid single-precision float", Long.toBinaryString(value).replace(' ', '0'))); } blockBuilder.writeInt((int) value).closeEntry(); }
@Override public int hashCode(Object value) { try { return toIntExact(Long.hashCode((long) hashCodeHandle.invokeExact(value))); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
public long getCheckpoint() { // if the decompressed buffer is empty, return a checkpoint starting at the next block if (current == null || (current.position() == 0 && current.remaining() == 0)) { return createInputStreamCheckpoint(toIntExact(compressedSliceInput.position()), 0); } // otherwise return a checkpoint at the last compressed block read and the current position in the buffer return createInputStreamCheckpoint(currentCompressedBlockOffset, toIntExact(current.position())); }
@Override public SqlIntervalYearMonth getExpectedValue(int start, int length) { if (length == 0) { return null; } double sum = 0; for (int i = start; i < start + length; i++) { sum += i; } return new SqlIntervalYearMonth(toIntExact(round(sum / length))); }
@Description("Creates a Bing tile from XY coordinates and zoom level") @ScalarFunction("bing_tile") @SqlType(BingTileType.NAME) public static long toBingTile(@SqlType(StandardTypes.INTEGER) long tileX, @SqlType(StandardTypes.INTEGER) long tileY, @SqlType(StandardTypes.INTEGER) long zoomLevel) { checkZoomLevel(zoomLevel); checkCoordinate(tileX, zoomLevel); checkCoordinate(tileY, zoomLevel); return BingTile.fromCoordinates(toIntExact(tileX), toIntExact(tileY), toIntExact(zoomLevel)).encode(); }
@UsedByGeneratedCode public static Object objectSubscript(Type elementType, Block array, long index) { checkIndex(array, index); int position = toIntExact(index - 1); if (array.isNull(position)) { return null; } return elementType.getObject(array, position); }
@Override public long getNextJoinPosition(long currentJoinPosition, int probePosition, Page allProbeChannelsPage) { int partition = decodePartition(currentJoinPosition); long joinPosition = decodeJoinPosition(currentJoinPosition); LookupSource lookupSource = lookupSources[partition]; long nextJoinPosition = lookupSource.getNextJoinPosition(joinPosition, probePosition, allProbeChannelsPage); if (nextJoinPosition < 0) { return nextJoinPosition; } return encodePartitionedJoinPosition(partition, toIntExact(nextJoinPosition)); }
@Override public StreamDataOutput getStreamDataOutput(int column) { return new StreamDataOutput(buffer::writeDataTo, new Stream(column, streamKind, toIntExact(buffer.getOutputDataSize()), true)); }
@Override public StreamDataOutput getStreamDataOutput(int column) { return new StreamDataOutput(buffer::writeDataTo, new Stream(column, DATA, toIntExact(buffer.getOutputDataSize()), false)); }
private static Block fixedWidthSequence(long start, long stop, long step, FixedWidthType type) { checkValidStep(start, stop, step); int length = toIntExact((stop - start) / step + 1L); checkMaxEntry(length); BlockBuilder blockBuilder = type.createBlockBuilder(null, length); for (long i = 0, value = start; i < length; ++i, value += step) { type.writeLong(blockBuilder, value); } return blockBuilder.build(); }
private Slice getSliceOutput() { buffer.close(); DynamicSliceOutput output = new DynamicSliceOutput(toIntExact(buffer.getOutputDataSize())); buffer.writeDataTo(output); Slice slice = output.slice(); buffer.reset(); return slice; } }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType("varchar(x)") public static Slice castToSlice(@SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long value) { return utf8Slice(IntervalYearMonth.formatMonths(toIntExact(value))); }
private static SerializedPage readSerializedPage(SliceInput sliceInput) { int positionCount = sliceInput.readInt(); byte codecMarker = sliceInput.readByte(); int uncompressedSizeInBytes = sliceInput.readInt(); int sizeInBytes = sliceInput.readInt(); Slice slice = sliceInput.readSlice(toIntExact((sizeInBytes))); return new SerializedPage(slice, lookupCodecFromMarker(codecMarker), positionCount, uncompressedSizeInBytes); }
@Description("add the specified amount of time to the given time") @LiteralParameters("x") @ScalarFunction("date_add") @SqlType(StandardTypes.TIME) public static long addFieldValueTime(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIME) long time) { if (session.isLegacyTimestamp()) { ISOChronology chronology = getChronology(session.getTimeZoneKey()); return modulo24Hour(chronology, getTimeField(chronology, unit).add(time, toIntExact(value))); } return modulo24Hour(getTimeField(UTC_CHRONOLOGY, unit).add(time, toIntExact(value))); }
@Description("add the specified amount of time to the given timestamp") @LiteralParameters("x") @ScalarFunction("date_add") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long addFieldValueTimestampWithTimeZone( @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) { long millis = getTimestampField(unpackChronology(timestampWithTimeZone), unit).add(unpackMillisUtc(timestampWithTimeZone), toIntExact(value)); return updateMillisUtc(millis, timestampWithTimeZone); }