use of org.apache.drill.exec.vector.BigIntVector in project drill by apache.
the class TestCastFunctions method testCastBigInt.
//private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleFunctions.class);
@Test
public // cast to bigint.
void testCastBigInt(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
mockDrillbitContext(bitContext);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/cast/testCastBigInt.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG);
final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
final BigIntVector c0 = exec.getValueVectorById(new SchemaPath("varchar_cast", ExpressionPosition.UNKNOWN), BigIntVector.class);
final BigIntVector.Accessor a0 = c0.getAccessor();
int count = 0;
for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
BigIntHolder holder0 = new BigIntHolder();
a0.get(i, holder0);
assertEquals(1256, holder0.value);
++count;
}
assertEquals(5, count);
}
exec.close();
context.close();
if (context.getFailureCause() != null) {
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
}
use of org.apache.drill.exec.vector.BigIntVector in project drill by apache.
the class WriterRecordBatch method addOutputContainerData.
private void addOutputContainerData() {
final VarCharVector fragmentIdVector = (VarCharVector) container.getValueAccessorById(VarCharVector.class, container.getValueVectorId(SchemaPath.getSimplePath("Fragment")).getFieldIds()).getValueVector();
AllocationHelper.allocate(fragmentIdVector, 1, 50);
final BigIntVector summaryVector = (BigIntVector) container.getValueAccessorById(BigIntVector.class, container.getValueVectorId(SchemaPath.getSimplePath("Number of records written")).getFieldIds()).getValueVector();
AllocationHelper.allocate(summaryVector, 1, 8);
fragmentIdVector.getMutator().setSafe(0, fragmentUniqueId.getBytes());
fragmentIdVector.getMutator().setValueCount(1);
summaryVector.getMutator().setSafe(0, counter);
summaryVector.getMutator().setValueCount(1);
container.setRecordCount(1);
}
use of org.apache.drill.exec.vector.BigIntVector in project drill by apache.
the class TestQueriesOnLargeFile method testRead.
@Test
public void testRead() throws Exception {
List<QueryDataBatch> results = testSqlWithResults(String.format("SELECT count(*) FROM dfs_test.`default`.`%s`", dataFile.getPath()));
RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
for (QueryDataBatch batch : results) {
batchLoader.load(batch.getHeader().getDef(), batch.getData());
if (batchLoader.getRecordCount() <= 0) {
continue;
}
BigIntVector countV = (BigIntVector) batchLoader.getValueAccessorById(BigIntVector.class, 0).getValueVector();
assertTrue("Total of " + NUM_RECORDS + " records expected in count", countV.getAccessor().get(0) == NUM_RECORDS);
batchLoader.clear();
batch.release();
}
}
use of org.apache.drill.exec.vector.BigIntVector in project drill by apache.
the class TestSimpleLimit method verifySum.
private void verifySum(DrillbitContext bitContext, UserClientConnection connection, String testPlan, int expectedCount, long expectedSum) throws Throwable {
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/limit/" + testPlan), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
int recordCount = 0;
long sum = 0;
while (exec.next()) {
recordCount += exec.getRecordCount();
final BigIntVector v = (BigIntVector) exec.iterator().next();
for (int i = 0; i < v.getAccessor().getValueCount(); i++) {
sum += v.getAccessor().get(i);
}
}
assertEquals(expectedCount, recordCount);
assertEquals(expectedSum, sum);
if (context.getFailureCause() != null) {
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
}
use of org.apache.drill.exec.vector.BigIntVector in project drill by apache.
the class TestAgg method twoKeyAgg.
@Test
public void twoKeyAgg(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
SimpleRootExec exec = doTest(bitContext, connection, "/agg/twokey.json");
while (exec.next()) {
final IntVector key1 = exec.getValueVectorById(SchemaPath.getSimplePath("key1"), IntVector.class);
final BigIntVector key2 = exec.getValueVectorById(SchemaPath.getSimplePath("key2"), BigIntVector.class);
final BigIntVector cnt = exec.getValueVectorById(SchemaPath.getSimplePath("cnt"), BigIntVector.class);
final NullableBigIntVector total = exec.getValueVectorById(SchemaPath.getSimplePath("total"), NullableBigIntVector.class);
final Integer[] keyArr1 = { Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE };
final long[] keyArr2 = { 0, 1, 2, 0, 1, 2 };
final long[] cntArr = { 34, 34, 34, 34, 34, 34 };
final long[] totalArr = { 0, 34, 68, 0, 34, 68 };
for (int i = 0; i < exec.getRecordCount(); i++) {
// System.out.print(key1.getAccessor().getObject(i));
// System.out.print("\t");
// System.out.print(key2.getAccessor().getObject(i));
// System.out.print("\t");
// System.out.print(cnt.getAccessor().getObject(i));
// System.out.print("\t");
// System.out.print(total.getAccessor().getObject(i));
// System.out.println();
assertEquals((Long) cntArr[i], cnt.getAccessor().getObject(i));
assertEquals(keyArr1[i], key1.getAccessor().getObject(i));
assertEquals((Long) keyArr2[i], key2.getAccessor().getObject(i));
assertEquals((Long) totalArr[i], total.getAccessor().getObject(i));
}
}
if (exec.getContext().getFailureCause() != null) {
throw exec.getContext().getFailureCause();
}
assertTrue(!exec.getContext().isFailed());
}
Aggregations