Refine search
@Override public int compare(byte[] left, byte[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = SignedBytes.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@UsedByGeneratedCode public static long shortDecimalToTinyint(long decimal, long precision, long scale, long tenToScale) { // this rounds the decimal value to the nearest integral value long longResult = (decimal + tenToScale / 2) / tenToScale; if (decimal < 0) { longResult = -((-decimal + tenToScale / 2) / tenToScale); } try { return SignedBytes.checkedCast(longResult); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to TINYINT", longResult)); } }
/** * Sorts the elements of {@code array} in descending order. * * @since 23.1 */ public static void sortDescending(byte[] array) { checkNotNull(array); sortDescending(array, 0, array.length); }
/** * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java * serialization). This has been measured to save at least 400 bytes compared to regular * serialization. * * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter. */ public void writeTo(OutputStream out) throws IOException { // Serial form: // 1 signed byte for the strategy // 1 unsigned byte for the number of hash functions // 1 big endian int, the number of longs in our bitset // N big endian longs of our bitset DataOutputStream dout = new DataOutputStream(out); dout.writeByte(SignedBytes.checkedCast(strategy.ordinal())); dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor dout.writeInt(bits.data.length()); for (int i = 0; i < bits.data.length(); i++) { dout.writeLong(bits.data.get(i)); } }
private static long normalizeIntegerValue(Type type, long value) { if (type.equals(BIGINT)) { return value; } if (type.equals(INTEGER)) { return Ints.saturatedCast(value); } if (type.equals(SMALLINT)) { return Shorts.saturatedCast(value); } if (type.equals(TINYINT)) { return SignedBytes.saturatedCast(value); } throw new IllegalArgumentException("Unexpected type: " + type); }
public void testLexicographicalComparator() { List<byte[]> ordered = Arrays.asList( new byte[] {}, new byte[] {LEAST}, new byte[] {LEAST, LEAST}, new byte[] {LEAST, (byte) 1}, new byte[] {(byte) 1}, new byte[] {(byte) 1, LEAST}, new byte[] {GREATEST, GREATEST - (byte) 1}, new byte[] {GREATEST, GREATEST}, new byte[] {GREATEST, GREATEST, GREATEST}); Comparator<byte[]> comparator = SignedBytes.lexicographicalComparator(); Helpers.testComparator(comparator, ordered); }
private static void assertCastFails(long value) { try { SignedBytes.checkedCast(value); fail("Cast to byte should have failed: " + value); } catch (IllegalArgumentException ex) { assertTrue( value + " not found in exception text: " + ex.getMessage(), ex.getMessage().contains(String.valueOf(value))); } }
public void testSaturatedCast() { for (byte value : VALUES) { assertEquals(value, SignedBytes.saturatedCast((long) value)); } assertEquals(GREATEST, SignedBytes.saturatedCast(GREATEST + 1L)); assertEquals(LEAST, SignedBytes.saturatedCast(LEAST - 1L)); assertEquals(GREATEST, SignedBytes.saturatedCast(Long.MAX_VALUE)); assertEquals(LEAST, SignedBytes.saturatedCast(Long.MIN_VALUE)); }
@GwtIncompatible // SerializableTester public void testLexicographicalComparatorSerializable() { Comparator<byte[]> comparator = SignedBytes.lexicographicalComparator(); assertSame(comparator, SerializableTester.reserialize(comparator)); }
@ScalarOperator(CAST) @SqlType(StandardTypes.TINYINT) public static long castToTinyint(@SqlType(StandardTypes.BIGINT) long value) { try { return SignedBytes.checkedCast(value); } catch (IllegalArgumentException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "Out of range for tinyint: " + value, e); } }
@Override public void setField(Block block, int position) { value.set(SignedBytes.checkedCast(TinyintType.TINYINT.getLong(block, position))); rowInspector.setStructFieldData(row, field, value); } }
@Override public int compare(byte[] left, byte[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = SignedBytes.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@ScalarOperator(SATURATED_FLOOR_CAST) @SqlType(StandardTypes.TINYINT) public static long saturatedFloorCastToTinyint(@SqlType(StandardTypes.SMALLINT) long value) { return SignedBytes.saturatedCast(value); }
/** * Sorts the elements of {@code array} in descending order. * * @since 23.1 */ public static void sortDescending(byte[] array) { checkNotNull(array); sortDescending(array, 0, array.length); }
@Override public int compare(INode left, INode right) { if (left == null) { return right == null ? 0 : -1; } else { if (right == null) { return 1; } else { int cmp = compare(left.getParent(), right.getParent()); return cmp == 0 ? SignedBytes.lexicographicalComparator().compare( left.getLocalNameBytes(), right.getLocalNameBytes()) : cmp; } } } };
@ScalarOperator(NEGATION) @SqlType(StandardTypes.TINYINT) public static long negate(@SqlType(StandardTypes.TINYINT) long value) { try { return SignedBytes.checkedCast(-value); } catch (IllegalArgumentException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "tinyint negation overflow: " + value, e); } }
/** * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java * serialization). This has been measured to save at least 400 bytes compared to regular * serialization. * * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter. */ public void writeTo(OutputStream out) throws IOException { // Serial form: // 1 signed byte for the strategy // 1 unsigned byte for the number of hash functions // 1 big endian int, the number of longs in our bitset // N big endian longs of our bitset DataOutputStream dout = new DataOutputStream(out); dout.writeByte(SignedBytes.checkedCast(strategy.ordinal())); dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor dout.writeInt(bits.data.length()); for (int i = 0; i < bits.data.length(); i++) { dout.writeLong(bits.data.get(i)); } }
@Override public int compare(byte[] left, byte[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = SignedBytes.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@ScalarOperator(SATURATED_FLOOR_CAST) @SqlType(StandardTypes.TINYINT) public static long saturatedFloorCastToTinyint(@SqlType(StandardTypes.BIGINT) long value) { return SignedBytes.saturatedCast(value); }
/** * Sorts the elements of {@code array} in descending order. * * @since 23.1 */ public static void sortDescending(byte[] array) { checkNotNull(array); sortDescending(array, 0, array.length); }