for (int i = 0; i < rsIndexToRecordIndex.length; ++i) { int rsIndex = rsIndexToRecordIndex[i]; if (rsIndex == -1 || rsRecord.isNull(rsIndex)) { record.put(i, rsRecord.nextBoolean(rsIndex)); break; case TINYINT: record.put(i, (int) rsRecord.nextByte(rsIndex)); break; case SMALLINT: record.put(i, (int) rsRecord.nextShort(rsIndex)); break; case INT: record.put(i, rsRecord.nextInt(rsIndex)); break; case BIGINT: record.put(i, rsRecord.nextLong(rsIndex)); break; case FLOAT: record.put(i, rsRecord.nextFloat(rsIndex)); break; case DOUBLE: record.put(i, rsRecord.nextDouble(rsIndex)); break; case VARCHAR: case CHAR: record.put(i, rsRecord.nextByteArray(rsIndex).toString()); break;
if (record.getSchema().cols.size() != schema_.getNumColumns()) { throw new IllegalArgumentException(String.format("Schema for new record does " + "not match existing schema: %d (new) != %d (existing)", record.getSchema().cols.size(), schema_.getNumColumns())); if (record.isNull(i)) { columnVals_[i] = null; continue; switch (cInfo.type.typeId) { case BOOLEAN: ((BooleanWritable) columnValObjects_[i]).set(record.nextBoolean(i)); break; case TINYINT: ((ByteWritable) columnValObjects_[i]).set(record.nextByte(i)); break; case SMALLINT: ((ShortWritable) columnValObjects_[i]).set(record.nextShort(i)); break; case INT: ((IntWritable) columnValObjects_[i]).set(record.nextInt(i)); break; case BIGINT: ((LongWritable) columnValObjects_[i]).set(record.nextLong(i)); break; case FLOAT: ((FloatWritable) columnValObjects_[i]).set(record.nextFloat(i)); break; case DOUBLE:
Record record = new Record(avroSchema_); for (int i = 0; i < schema_.cols.size(); ++i) { if (rsRecord.isNull(i)) { record.put(i, null); continue; case BOOLEAN: record.put(i, rsRecord.nextBoolean(i)); break; case TINYINT: record.put(i, (int)rsRecord.nextByte(i)); break; case SMALLINT: record.put(i, (int)rsRecord.nextShort(i)); break; case INT: record.put(i, rsRecord.nextInt(i)); break; case BIGINT: record.put(i, rsRecord.nextLong(i)); break; case FLOAT: record.put(i, rsRecord.nextFloat(i)); break; case DOUBLE: record.put(i, rsRecord.nextDouble(i)); break; case STRING: case VARCHAR: case CHAR: record.put(i, rsRecord.nextByteArray(i).toString()); break; default: throw new RuntimeException(
/** * Advances to the next record. * Returns true if there are more values to retrieve, false otherwise. */ @Override public boolean nextKeyValue() throws IOException, InterruptedException { try { if (!reader_.records().hasNext()) return false; } catch (RecordServiceException e) { // TODO: is this the most proper way to deal with this in MR? throw new IOException("Could not fetch record.", e); } Records.Record record = reader_.records().next(); if (record.isNull(0)) { record_.set(EMPTY); } else { ByteArray data = record.nextByteArray(0); record_.set(data.byteBuffer().array(), data.offset(), data.len()); } currentKey_.set(recordNum_++); return true; }
protected Records(RecordServiceWorkerClient worker, RecordServiceWorkerClient.TaskState handle) throws IOException, RecordServiceException { worker_ = worker; handle_ = handle; closeWorker_ = false; record_ = new Record(handle.getSchema()); nextBatch(); if (record_.schema_.isCountStar) { // This is a count(*). We will read the one and only value that is the number of // records. The iterator interface will return count(*) number of NULLs. Preconditions.checkState(record_.schema_.cols.size() == 1); Preconditions.checkState(record_.schema_.cols.get(0).type.typeId == Type.BIGINT); Preconditions.checkState(record_.numRecords_ == 1); record_.numRecords_ = record_.nextLong(0); } hasNext_ = hasNext(); }
@Override public boolean next(LongWritable key, Text value) throws IOException { try { if (!reader_.records().hasNext()) return false; Records.Record record = reader_.records().next(); if (record.isNull(0)) { value.set(EMPTY); } else { ByteArray data = record.nextByteArray(0); value.set(data.byteBuffer().array(), data.offset(), data.len()); } key.set(recordNum_++); return true; } catch (RecordServiceException e) { throw new IOException("Could not get next record.", e); } }
/** * Returns the schema for the returned records. */ public Schema getSchema() { return record_.getSchema(); }