private static Slice subslice(Slice parent, int offset, int length) { return new Slice(parent.getRawArray(), parent.getRawOffset() + offset, length); }
static void readProtobuf(final Slice slice, final Builder builder) { final int length = slice.length(); final byte[] payload = slice.getRawArray(); final int offset = slice.getRawOffset(); try { builder.mergeFrom(payload, offset, length); if (!builder.isInitialized()) { throw new RuntimeException("Could not deserialize the response," + " incompatible RPC? Error is: " + builder.getInitializationErrorString()); } } catch (InvalidProtocolBufferException e) { throw new RuntimeException("Invalid RPC response: length=" + length, e); } }
/** * Get the specified column's short * @param columnIndex Column index in the schema * @return a short * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public short getShort(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.INT16); return Bytes.getShort(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex)); }
/** * Get a copy of the specified column's binary data. * @param columnIndex Column index in the schema * @return a byte[] with the binary data. * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public byte[] getBinaryCopy(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); // C++ puts a Slice in rowData which is 16 bytes long for simplicity, // but we only support ints. long offset = getLong(columnIndex); long length = rowData.getLong(getCurrentRowDataOffsetForColumn(columnIndex) + 8); assert offset < Integer.MAX_VALUE; assert length < Integer.MAX_VALUE; byte[] ret = new byte[(int)length]; System.arraycopy(indirectData.getRawArray(), indirectData.getRawOffset() + (int) offset, ret, 0, (int) length); return ret; }
void advancePointerTo(int rowIndex) { this.index = rowIndex; this.offset = this.rowSize * this.index; if (schema.hasNullableColumns() && this.index != INDEX_RESET_LOCATION) { this.nullsBitSet = Bytes.toBitSet( this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(schema.getColumnCount()), schema.getColumnCount()); } }
/** * Get the specified column's float * @param columnIndex Column index in the schema * @return a float * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public float getFloat(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.FLOAT); return Bytes.getFloat(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex)); }
/** * Get the specified column's long * * If this is a UNIXTIME_MICROS column, the long value corresponds to a number of microseconds * since midnight, January 1, 1970 UTC. * * @param columnIndex Column index in the schema * @return a positive long * @throws IllegalArgumentException if the column is null * @throws IndexOutOfBoundsException if the column doesn't exist */ public long getLong(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); // Can't check type because this could be a long, string, or Timestamp. return Bytes.getLong(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex)); }
/** * Get the specified column's boolean * @param columnIndex Column index in the schema * @return a boolean * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public boolean getBoolean(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.BOOL); byte b = Bytes.getByte(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex)); return b == 1; }
/** * Get the specified column's integer * @param columnIndex Column index in the schema * @return an integer * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public int getInt(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.INT32); return Bytes.getInt(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex)); }
/** * Get the specified column's byte * @param columnIndex Column index in the schema * @return a byte * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public byte getByte(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.INT8); return Bytes.getByte(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex)); }
/** * Get the specified column's double * @param columnIndex Column index in the schema * @return a double * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public double getDouble(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.DOUBLE); return Bytes.getDouble(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex)); }
/** * Get the specified column's binary data. * * This doesn't copy the data and instead returns a ByteBuffer that wraps it. * * @param columnIndex Column index in the schema * @return a ByteBuffer with the binary data. * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public ByteBuffer getBinary(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.BINARY); // C++ puts a Slice in rowData which is 16 bytes long for simplicity, // but we only support ints. long offset = getLong(columnIndex); long length = rowData.getLong(getCurrentRowDataOffsetForColumn(columnIndex) + 8); assert offset < Integer.MAX_VALUE; assert length < Integer.MAX_VALUE; return ByteBuffer.wrap(indirectData.getRawArray(), indirectData.getRawOffset() + (int) offset, (int) length); }
/** * Get the specified column's Timestamp. * * @param columnIndex Column index in the schema * @return a Timestamp * @throws IllegalArgumentException if the column is null, is unset, * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public Timestamp getTimestamp(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.UNIXTIME_MICROS); ColumnSchema column = schema.getColumnByIndex(columnIndex); long micros = Bytes.getLong(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex)); return TimestampUtil.microsToTimestamp(micros); }
/** * Get the specified column's string. * @param columnIndex Column index in the schema * @return a string * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public String getString(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.STRING); // C++ puts a Slice in rowData which is 16 bytes long for simplity, but we only support ints. long offset = getLong(columnIndex); long length = rowData.getLong(getCurrentRowDataOffsetForColumn(columnIndex) + 8); assert offset < Integer.MAX_VALUE; assert length < Integer.MAX_VALUE; return Bytes.getString(indirectData.getRawArray(), indirectData.getRawOffset() + (int)offset, (int)length); }
/** * Get the specified column's Decimal. * * @param columnIndex Column index in the schema * @return a BigDecimal. * @throws IllegalArgumentException if the column is null * @throws IndexOutOfBoundsException if the column doesn't exist */ public BigDecimal getDecimal(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.DECIMAL); ColumnSchema column = schema.getColumnByIndex(columnIndex); ColumnTypeAttributes typeAttributes = column.getTypeAttributes(); return Bytes.getDecimal(this.rowData.getRawArray(), this.rowData.getRawOffset() + getCurrentRowDataOffsetForColumn(columnIndex), typeAttributes.getPrecision(), typeAttributes.getScale()); }