use of org.apache.drill.exec.vector.VarCharVector in project drill by apache.
the class BatchValidator method validateNullableVector.
private void validateNullableVector(String name, NullableVector vector) {
if (vector instanceof NullableVarCharVector) {
@SuppressWarnings("resource") VarCharVector values = ((NullableVarCharVector) vector).getValuesVector();
validateVarCharVector(name + "-values", values, rowCount);
}
}
use of org.apache.drill.exec.vector.VarCharVector in project drill by apache.
the class TestHiveUDFs method testUDF.
@Test
public void testUDF() throws Throwable {
int numRecords = 0;
String planString = Resources.toString(Resources.getResource("functions/hive/UDF.json"), Charsets.UTF_8);
List<QueryDataBatch> results = testPhysicalWithResults(planString);
RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
for (QueryDataBatch result : results) {
batchLoader.load(result.getHeader().getDef(), result.getData());
if (batchLoader.getRecordCount() <= 0) {
result.release();
batchLoader.clear();
continue;
}
// Output columns and types
// 1. str1 : VarChar
// 2. str1Length : Int
// 3. str1Ascii : Int
// 4. flt1 : Float4
// 5. pow : Float8
VarCharVector str1V = (VarCharVector) batchLoader.getValueAccessorById(VarCharVector.class, 0).getValueVector();
BigIntVector str1LengthV = (BigIntVector) batchLoader.getValueAccessorById(BigIntVector.class, 1).getValueVector();
IntVector str1AsciiV = (IntVector) batchLoader.getValueAccessorById(IntVector.class, 2).getValueVector();
Float4Vector flt1V = (Float4Vector) batchLoader.getValueAccessorById(Float4Vector.class, 3).getValueVector();
NullableFloat8Vector powV = (NullableFloat8Vector) batchLoader.getValueAccessorById(NullableFloat8Vector.class, 4).getValueVector();
for (int i = 0; i < batchLoader.getRecordCount(); i++) {
String str1 = new String(str1V.getAccessor().get(i), Charsets.UTF_8);
long str1Length = str1LengthV.getAccessor().get(i);
assertTrue(str1.length() == str1Length);
int str1Ascii = str1AsciiV.getAccessor().get(i);
float flt1 = flt1V.getAccessor().get(i);
double pow = 0;
if (!powV.getAccessor().isNull(i)) {
pow = powV.getAccessor().get(i);
assertTrue(Math.pow(flt1, 2.0) == pow);
}
System.out.println(str1 + ", " + str1Length + ", " + str1Ascii + ", " + flt1 + ", " + pow);
numRecords++;
}
result.release();
batchLoader.clear();
}
System.out.println("Processed " + numRecords + " records");
}
use of org.apache.drill.exec.vector.VarCharVector in project drill by apache.
the class StringGen method setValue.
@Override
public void setValue(ValueVector v, int index) {
VarCharVector vector = (VarCharVector) v;
vector.getMutator().setSafe(index, value().getBytes());
}
use of org.apache.drill.exec.vector.VarCharVector in project drill by apache.
the class DateGen method setValue.
@Override
public void setValue(ValueVector v, int index) {
VarCharVector vector = (VarCharVector) v;
long randTime = baseTime + value();
String str = fmt.format(new Date(randTime));
vector.getMutator().setSafe(index, str.getBytes());
}
use of org.apache.drill.exec.vector.VarCharVector in project drill by apache.
the class TestBatchValidator method testRepeatedBadValueOffset.
@Test
public void testRepeatedBadValueOffset() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR, DataMode.REPEATED).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).add((Object) new String[] {}).add((Object) new String[] { "fred", "barney", "wilma" }).add((Object) new String[] { "dino" }).build();
VectorAccessible va = batch.vectorAccessible();
@SuppressWarnings("resource") ValueVector v = va.iterator().next().getValueVector();
RepeatedVarCharVector rvc = (RepeatedVarCharVector) v;
@SuppressWarnings("resource") VarCharVector vc = rvc.getDataVector();
@SuppressWarnings("resource") UInt4Vector ov = vc.getOffsetVector();
ov.getMutator().set(4, 100_000);
BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
validator.validate();
List<String> errors = validator.errors();
assertEquals(1, errors.size());
assertTrue(errors.get(0).contains("Invalid offset"));
batch.clear();
}
Aggregations