public static Object getObject(Type type, RowResult row, int field) if (row.isNull(field)) { return null; return row.getString(field); return row.getLong(field) / 1000; return row.getLong(field); return row.getInt(field); return row.getShort(field); return row.getByte(field); return row.getDouble(field); return row.getFloat(field); return row.getBoolean(field); return Slices.wrappedBuffer(row.getBinary(field)); return row.getDecimal(field);
public static long getLong(Type type, RowResult row, int field) return row.getLong(field) / 1000; return row.getLong(field); return row.getInt(field); return row.getShort(field); return row.getByte(field); return floatToRawIntBits(row.getFloat(field)); return row.getDecimal(field).unscaledValue().longValue();
public static Slice getSlice(Type type, RowResult row, int field) { if (type instanceof VarcharType) { return Slices.utf8Slice(row.getString(field)); } else if (type instanceof VarbinaryType) { return Slices.wrappedBuffer(row.getBinary(field)); } else if (type instanceof DecimalType) { BigDecimal dec = row.getDecimal(field); return Decimals.encodeScaledValue(dec); } else { throw new IllegalStateException("getSlice not implemented for " + type); } } }
assertEquals((byte) 1, rr.getByte(0)); assertEquals((byte) 1, rr.getByte(allTypesSchema.getColumnByIndex(0).getName())); assertEquals((short) 2, rr.getShort(1)); assertEquals((short) 2, rr.getShort(allTypesSchema.getColumnByIndex(1).getName())); assertEquals(3, rr.getInt(2)); assertEquals(3, rr.getInt(allTypesSchema.getColumnByIndex(2).getName())); assertEquals(4, rr.getLong(3)); assertEquals(4, rr.getLong(allTypesSchema.getColumnByIndex(3).getName())); assertEquals(true, rr.getBoolean(4)); assertEquals(true, rr.getBoolean(allTypesSchema.getColumnByIndex(4).getName())); assertEquals(5.6f, rr.getFloat(5), .001f); assertEquals(5.6f, rr.getFloat(allTypesSchema.getColumnByIndex(5).getName()), .001f); assertEquals(7.8, rr.getDouble(6), .001); assertEquals(7.8, rr.getDouble(allTypesSchema.getColumnByIndex(6).getName()), .001f); assertEquals("string-value", rr.getString(7)); assertEquals("string-value", rr.getString(allTypesSchema.getColumnByIndex(7).getName())); assertArrayEquals("binary-array".getBytes(UTF_8), rr.getBinaryCopy(8)); assertArrayEquals("binary-array".getBytes(UTF_8), rr.getBinaryCopy(allTypesSchema.getColumnByIndex(8).getName())); ByteBuffer buffer = rr.getBinary(8);
private static CINode getCINode(RowResult result, CINode node) { node.key = getStringFromKeys(result.getLong(0), result.getLong(1)); if (result.isNull(2) || result.isNull(3)) { node.prev = "NO_REFERENCE"; } else { node.prev = getStringFromKeys(result.getLong(2), result.getLong(3)); } node.rowId = result.getInt(4); node.client = result.getString(5); node.updateCount = result.getInt(6); return node; }
assertEquals(magicNumber, rr.getInt(1)); assertEquals(magicNumber, rr.getInt(2)); assertEquals(magicNumber + "", rr.getString(3)); assertEquals(false, rr.getBoolean(4));
@Override protected void map(NullWritable key, RowResult value, Mapper.Context context) throws IOException, InterruptedException { Bytes.setLong(rowKey, value.getLong(0)); Bytes.setLong(rowKey, value.getLong(1), 8); row.set(rowKey, 0, rowKey.length); // Emit that the row is defined context.write(row, DEF); if (value.isNull(2)) { LOG.warn(String.format("Prev is not set for: %s", Bytes.pretty(rowKey))); } else { Bytes.setLong(prev, value.getLong(2)); Bytes.setLong(prev, value.getLong(3), 8); ref.set(prev, 0, prev.length); // Emit which row is referenced by this row. context.write(ref, row); } } }
private void addAllRowsToResult(RowResultIterator it, int recordcount, List<String> querySchema, Vector<HashMap<String, ByteIterator>> result) throws Exception { RowResult row; HashMap<String, ByteIterator> rowResult = new HashMap<>(querySchema.size()); if (it == null) { return; } while (it.hasNext()) { if (result.size() == recordcount) { return; } row = it.next(); int colIdx = 0; for (String col : querySchema) { rowResult.put(col, new StringByteIterator(row.getString(colIdx))); colIdx++; } result.add(rowResult); } }
@Override public boolean isNull(int field) { int mappedField = mapping(field); return mappedField >= 0 && currentRow.isNull(mappedField); }
/** * Get the specified column's integer * @param columnName name of the column to get data for * @return an integer * @throws IllegalArgumentException if the column doesn't exist, is null, * or if the type doesn't match the column's type */ public int getInt(String columnName) { return getInt(this.schema.getColumnIndex(columnName)); }
/** * 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); }
public static double getDouble(Type type, RowResult row, int field) { if (type == DoubleType.DOUBLE) { return row.getDouble(field); } else { throw new IllegalStateException("getDouble not implemented for " + type); } }
public static boolean getBoolean(Type type, RowResult row, int field) { if (type == BooleanType.BOOLEAN) { return row.getBoolean(field); } else { throw new IllegalStateException("getBoolean not implemented for " + type); } }
/** * 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 columnName name of the column to get data for * @return a positive long * @throws IllegalArgumentException if the column doesn't exist or is null */ public long getLong(String columnName) { return getLong(this.schema.getColumnIndex(columnName)); }
/** * Get the specified column's float * @param columnName name of the column to get data for * @return a float * @throws IllegalArgumentException if the column doesn't exist, is null, * or if the type doesn't match the column's type */ public float getFloat(String columnName) { return getFloat(this.schema.getColumnIndex(columnName)); }
/** * Get the specified column's byte * @param columnName name of the column to get data for * @return a byte * @throws IllegalArgumentException if the column doesn't exist, is null, * or if the type doesn't match the column's type */ public byte getByte(String columnName) { return getByte(this.schema.getColumnIndex(columnName)); }
/** * Get the specified column's short * @param columnName name of the column to get data for * @return a short * @throws IllegalArgumentException if the column doesn't exist, is null, * or if the type doesn't match the column's type */ public short getShort(String columnName) { return getShort(this.schema.getColumnIndex(columnName)); }
/** * Get the specified column's binary data. * * This doesn't copy the data and instead returns a ByteBuffer that wraps it. * * @param columnName name of the column to get data for * @return a ByteBuffer with the binary data. * @throws IllegalArgumentException if the column doesn't exist, is null, * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public ByteBuffer getBinary(String columnName) { return getBinary(this.schema.getColumnIndex(columnName)); }
public static long getLong(Type type, RowResult row, int field) { if (type == TimestampType.TIMESTAMP) { return row.getLong(field) / 1000; } else if (type == BigintType.BIGINT) { return row.getLong(field); } else if (type == IntegerType.INTEGER) { return row.getInt(field); } else if (type == SmallintType.SMALLINT) { return row.getShort(field); } else if (type == TinyintType.TINYINT) { return row.getByte(field); } else if (type == RealType.REAL) { return floatToRawIntBits(row.getFloat(field)); } else if (type instanceof DecimalType) { DecimalType dtype = (DecimalType) type; if (dtype.isShort()) { return row.getDecimal(field).unscaledValue().longValue(); } else { throw new IllegalStateException("getLong not supported for long decimal: " + type); } } else { throw new IllegalStateException("getLong not implemented for " + type); } }
if (prev.isNull(0) || prev.isNull(1)) { context.getCounter(Counts.BROKEN_LINKS).increment(1); LOG.warn(getStringFromKeys(prevKeyOne, prevKeyTwo) + " isn't referencing anywhere"); int prevCount = prev.getInt(2); String prevClient = prev.getString(3); if (currentCount == -1) { context.progress(); prevKeyOne = prev.getLong(0); prevKeyTwo = prev.getLong(1); } while (headKeyOne != prevKeyOne && headKeyTwo != prevKeyTwo);