use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class TestOrcFile method testZeroCopySeek.
@Test
public void testZeroCopySeek() throws Exception {
ObjectInspector inspector;
synchronized (TestOrcFile.class) {
inspector = ObjectInspectorFactory.getReflectionObjectInspector(BigRow.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA);
}
Writer writer = OrcFile.createWriter(testFilePath, OrcFile.writerOptions(conf).inspector(inspector).stripeSize(200000).bufferSize(65536).rowIndexStride(1000));
Random rand = new Random(42);
final int COUNT = 32768;
long[] intValues = new long[COUNT];
double[] doubleValues = new double[COUNT];
String[] stringValues = new String[COUNT];
BytesWritable[] byteValues = new BytesWritable[COUNT];
String[] words = new String[128];
for (int i = 0; i < words.length; ++i) {
words[i] = Integer.toHexString(rand.nextInt());
}
for (int i = 0; i < COUNT / 2; ++i) {
intValues[2 * i] = rand.nextLong();
intValues[2 * i + 1] = intValues[2 * i];
stringValues[2 * i] = words[rand.nextInt(words.length)];
stringValues[2 * i + 1] = stringValues[2 * i];
}
for (int i = 0; i < COUNT; ++i) {
doubleValues[i] = rand.nextDouble();
byte[] buf = new byte[20];
rand.nextBytes(buf);
byteValues[i] = new BytesWritable(buf);
}
for (int i = 0; i < COUNT; ++i) {
writer.addRow(createRandomRow(intValues, doubleValues, stringValues, byteValues, words, i));
}
writer.close();
writer = null;
Reader reader = OrcFile.createReader(testFilePath, OrcFile.readerOptions(conf).filesystem(fs));
assertEquals(COUNT, reader.getNumberOfRows());
/* enable zero copy record reader */
Configuration conf = new Configuration();
conf.setBoolean(OrcConf.USE_ZEROCOPY.getHiveConfName(), true);
RecordReader rows = reader.rows();
/* all tests are identical to the other seek() tests */
OrcStruct row = null;
for (int i = COUNT - 1; i >= 0; --i) {
// we load the previous buffer of rows
if (i % COUNT == COUNT - 1) {
rows.seekToRow(i - (COUNT - 1));
}
rows.seekToRow(i);
row = (OrcStruct) rows.next(row);
BigRow expected = createRandomRow(intValues, doubleValues, stringValues, byteValues, words, i);
assertEquals(expected.boolean1.booleanValue(), ((BooleanWritable) row.getFieldValue(0)).get());
assertEquals(expected.byte1.byteValue(), ((ByteWritable) row.getFieldValue(1)).get());
assertEquals(expected.short1.shortValue(), ((ShortWritable) row.getFieldValue(2)).get());
assertEquals(expected.int1.intValue(), ((IntWritable) row.getFieldValue(3)).get());
assertEquals(expected.long1.longValue(), ((LongWritable) row.getFieldValue(4)).get());
assertEquals(expected.float1.floatValue(), ((FloatWritable) row.getFieldValue(5)).get(), 0.0001);
assertEquals(expected.double1.doubleValue(), ((DoubleWritable) row.getFieldValue(6)).get(), 0.0001);
assertEquals(expected.bytes1, row.getFieldValue(7));
assertEquals(expected.string1, row.getFieldValue(8));
List<InnerStruct> expectedList = expected.middle.list;
List<OrcStruct> actualList = (List) ((OrcStruct) row.getFieldValue(9)).getFieldValue(0);
compareList(expectedList, actualList);
compareList(expected.list, (List) row.getFieldValue(10));
}
rows.close();
Iterator<StripeInformation> stripeIterator = reader.getStripes().iterator();
long offsetOfStripe2 = 0;
long offsetOfStripe4 = 0;
long lastRowOfStripe2 = 0;
for (int i = 0; i < 5; ++i) {
StripeInformation stripe = stripeIterator.next();
if (i < 2) {
lastRowOfStripe2 += stripe.getNumberOfRows();
} else if (i == 2) {
offsetOfStripe2 = stripe.getOffset();
lastRowOfStripe2 += stripe.getNumberOfRows() - 1;
} else if (i == 4) {
offsetOfStripe4 = stripe.getOffset();
}
}
boolean[] columns = new boolean[reader.getStatistics().length];
// long colulmn
columns[5] = true;
// text column
columns[9] = true;
/* use zero copy record reader */
rows = reader.rowsOptions(new Reader.Options().range(offsetOfStripe2, offsetOfStripe4 - offsetOfStripe2).include(columns));
rows.seekToRow(lastRowOfStripe2);
for (int i = 0; i < 2; ++i) {
row = (OrcStruct) rows.next(row);
BigRow expected = createRandomRow(intValues, doubleValues, stringValues, byteValues, words, (int) (lastRowOfStripe2 + i));
assertEquals(expected.long1.longValue(), ((LongWritable) row.getFieldValue(4)).get());
assertEquals(expected.string1, row.getFieldValue(8));
}
rows.close();
}
use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class PerformTestRCFileAndSeqFile method writeSeqenceFileTest.
private void writeSeqenceFileTest(FileSystem fs, int rowCount, Path file, int columnNum, CompressionCodec codec) throws IOException {
byte[][] columnRandom;
resetRandomGenerators();
BytesRefArrayWritable bytes = new BytesRefArrayWritable(columnNum);
columnRandom = new byte[columnNum][];
for (int i = 0; i < columnNum; i++) {
BytesRefWritable cu = new BytesRefWritable();
bytes.set(i, cu);
}
// zero length key is not allowed by block compress writer, so we use a byte
// writable
ByteWritable key = new ByteWritable();
SequenceFile.Writer seqWriter = SequenceFile.createWriter(fs, conf, file, ByteWritable.class, BytesRefArrayWritable.class, CompressionType.BLOCK, codec);
for (int i = 0; i < rowCount; i++) {
nextRandomRow(columnRandom, bytes);
seqWriter.append(key, bytes);
}
seqWriter.close();
}
use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class PerformTestRCFileAndSeqFile method performSequenceFileRead.
public void performSequenceFileRead(FileSystem fs, int count, Path file) throws IOException {
SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf);
ByteWritable key = new ByteWritable();
BytesRefArrayWritable val = new BytesRefArrayWritable();
for (int i = 0; i < count; i++) {
reader.next(key, val);
}
}
use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class TestGenericUDFOPMinus method testByteMinusShort.
@Test
public void testByteMinusShort() throws HiveException {
GenericUDFOPMinus udf = new GenericUDFOPMinus();
ByteWritable left = new ByteWritable((byte) 4);
ShortWritable right = new ShortWritable((short) 6);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.shortTypeInfo);
ShortWritable res = (ShortWritable) udf.evaluate(args);
Assert.assertEquals(-2, res.get());
}
use of org.apache.hadoop.hive.serde2.io.ByteWritable in project hive by apache.
the class TestGenericUDFPower method testBytePowerShort.
@Test
public void testBytePowerShort() throws HiveException {
GenericUDFPower udf = new GenericUDFPower();
ByteWritable left = new ByteWritable((byte) 2);
ShortWritable right = new ShortWritable((short) 4);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo());
DoubleWritable res = (DoubleWritable) udf.evaluate(args);
Assert.assertEquals(new Double(16), new Double(res.get()));
}
Aggregations