@Description("compute CRC-32") @ScalarFunction @SqlType(StandardTypes.BIGINT) public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice) { CRC32 crc32 = new CRC32(); crc32.update(slice.toByteBuffer()); return crc32.getValue(); }
private static OGCGeometry geomFromBinary(Slice input) { requireNonNull(input, "input is null"); OGCGeometry geometry; try { geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice()); } catch (IllegalArgumentException | IndexOutOfBoundsException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e); } geometry.setSpatialReference(null); return geometry; }
return ((Slice) nativeValue).toByteBuffer();
private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length) { int currentPosition = toIntExact(input.position()); ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice(); input.setPosition(currentPosition + length); Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer); return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype()); }
values.add(type.getSlice(block, position).toByteBuffer());
row.addBinary(destChannel, type.getSlice(block, position).toByteBuffer());
public ByteBuffer toByteBuffer() { return toByteBuffer(0, size); }
public ByteBuffer toByteBuffer() { return toByteBuffer(0, size); }
/** * Decodes the a portion of this slice into a string with the specified * character set name. */ public String toString(int index, int length, Charset charset) { if (length == 0) { return ""; } if (base instanceof byte[]) { return new String((byte[]) base, (int) ((address - ARRAY_BYTE_BASE_OFFSET) + index), length, charset); } // direct memory can only be converted to a string using a ByteBuffer return decodeString(toByteBuffer(index, length), charset); }
private static OGCGeometry geomFromBinary(Slice input) { requireNonNull(input, "input is null"); OGCGeometry geometry; try { geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice()); } catch (IllegalArgumentException | IndexOutOfBoundsException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e); } geometry.setSpatialReference(null); return geometry; }
@Description("compute CRC-32") @ScalarFunction @SqlType(StandardTypes.BIGINT) public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice) { CRC32 crc32 = new CRC32(); crc32.update(slice.toByteBuffer()); return crc32.getValue(); }
private static OGCGeometry geomFromBinary(Slice input) { requireNonNull(input, "input is null"); OGCGeometry geometry; try { geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice()); } catch (IllegalArgumentException | IndexOutOfBoundsException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e); } geometry.setSpatialReference(null); return geometry; }
@Description("compute CRC-32") @ScalarFunction @SqlType(StandardTypes.BIGINT) public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice) { CRC32 crc32 = new CRC32(); crc32.update(slice.toByteBuffer()); return crc32.getValue(); }
private static void assertToByteBuffer(Slice slice, byte[] original) { for (int index = 0; index < original.length; index++) { for (int length = 0; length < (original.length - index); length++) { byte[] actual = getBytes(slice.toByteBuffer(index, length)); byte[] expected = Arrays.copyOfRange(original, index, index + length); assertEquals(actual, expected); } } }
public static Object getJavaValue(Type type, Object nativeValue) { if (type instanceof VarcharType) { return ((Slice) nativeValue).toStringUtf8(); } else if (type == TimestampType.TIMESTAMP) { return ((Long) nativeValue) * 1000; } else if (type == BigintType.BIGINT) { return nativeValue; } else if (type == IntegerType.INTEGER) { return ((Long) nativeValue).intValue(); } else if (type == SmallintType.SMALLINT) { return ((Long) nativeValue).shortValue(); } else if (type == TinyintType.TINYINT) { return ((Long) nativeValue).byteValue(); } else if (type == DoubleType.DOUBLE) { return nativeValue; } else if (type == RealType.REAL) { // conversion can result in precision lost return intBitsToFloat(((Long) nativeValue).intValue()); } else if (type == BooleanType.BOOLEAN) { return nativeValue; } else if (type instanceof VarbinaryType) { return ((Slice) nativeValue).toByteBuffer(); } else if (type instanceof DecimalType) { return nativeValue; } else { throw new IllegalStateException("Back conversion not implemented for " + type); } }
private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length) { int currentPosition = toIntExact(input.position()); ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice(); input.setPosition(currentPosition + length); Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer); return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype()); }
private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length) { int currentPosition = toIntExact(input.position()); ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice(); input.setPosition(currentPosition + length); Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer); return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype()); }
private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length) { int currentPosition = toIntExact(input.position()); ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice(); input.setPosition(currentPosition + length); Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer); return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype()); }
@Test public void testToByteBuffer() { byte[] original = "hello world".getBytes(UTF_8); Slice slice = allocate(original.length); slice.setBytes(0, original); assertEquals(slice.getBytes(), original); assertEquals(getBytes(slice.toByteBuffer()), original); assertToByteBuffer(slice, original); }
values.add(type.getSlice(block, position).toByteBuffer());