int numRecords = 0;
String planString = Resources.toString(Resources.getResource("functions/hive/GenericUDF.json"), Charsets.UTF_8);
List<QueryResultBatch> results = testPhysicalWithResults(planString);
RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
for (QueryResultBatch result : results) {
batchLoader.load(result.getHeader().getDef(), result.getData());
if (batchLoader.getRecordCount() <= 0) {
result.release();
batchLoader.clear();
continue;
}
// Output columns and types
// 1. str1 : Var16Char
// 2. upperStr1 : NullableVar16Char
// 3. unix_timestamp : NullableBigInt
// 4. concat : NullableVarChar
// 5. flt1 : Float4
// 6. format_number : NullableFloat8
// 7. nullableStr1 : NullableVar16Char
// 8. upperNullableStr1 : NullableVar16Char
Var16CharVector str1V = (Var16CharVector) batchLoader.getValueAccessorById(Var16CharVector.class, 0).getValueVector();
NullableVar16CharVector upperStr1V = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 1).getValueVector();
NullableBigIntVector unix_timestampV = (NullableBigIntVector) batchLoader.getValueAccessorById(NullableBigIntVector.class, 2).getValueVector();
NullableVar16CharVector concatV = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 3).getValueVector();
Float4Vector flt1V = (Float4Vector) batchLoader.getValueAccessorById(Float4Vector.class, 4).getValueVector();
NullableVar16CharVector format_numberV = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 5).getValueVector();
NullableVar16CharVector nullableStr1V = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 6).getValueVector();
NullableVar16CharVector upperNullableStr1V = (NullableVar16CharVector) batchLoader.getValueAccessorById(NullableVar16CharVector.class, 7).getValueVector();
for (int i=0; i<batchLoader.getRecordCount(); i++) {
String in = new String(str1V.getAccessor().get(i), Charsets.UTF_16);
String upper = new String(upperStr1V.getAccessor().get(i), Charsets.UTF_16);
assertTrue(in.toUpperCase().equals(upper));
long unix_timestamp = unix_timestampV.getAccessor().get(i);
String concat = new String(concatV.getAccessor().get(i), Charsets.UTF_16);
assertTrue(concat.equals(in+"-"+in));
float flt1 = flt1V.getAccessor().get(i);
String format_number = new String(format_numberV.getAccessor().get(i), Charsets.UTF_16);
String nullableStr1 = null;
if (!nullableStr1V.getAccessor().isNull(i)) {
nullableStr1 = new String(nullableStr1V.getAccessor().get(i), Charsets.UTF_16);
}
String upperNullableStr1 = null;
if (!upperNullableStr1V.getAccessor().isNull(i)) {
upperNullableStr1 = new String(upperNullableStr1V.getAccessor().get(i), Charsets.UTF_16);
}
assertEquals(nullableStr1 != null, upperNullableStr1 != null);
if (nullableStr1 != null) {
assertEquals(nullableStr1.toUpperCase(), upperNullableStr1);
}
System.out.println(in + ", " + upper + ", " + unix_timestamp + ", " + concat + ", " +
flt1 + ", " + format_number + ", " + nullableStr1 + ", " + upperNullableStr1);
numRecords++;
}
result.release();
batchLoader.clear();
}
System.out.println("Processed " + numRecords + " records");
}