Search in sources :

Example 6 with RecordBatch

use of org.apache.drill.exec.record.RecordBatch in project drill by apache.

the class TestMiniPlan method testUnionFilter.

@Test
public void testUnionFilter() throws Exception {
    List<String> leftJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 1 }]", "[{\"a\": 5, \"b\" : 5},{\"a\": 3, \"b\" : 8}]", "[{\"a\": 40, \"b\" : 3},{\"a\": 13, \"b\" : 100}]");
    List<String> rightJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 10 }]", "[{\"a\": 50, \"b\" : 100}]");
    RecordBatch batch = new PopBuilder().physicalOperator(// Children list is provided through RecordBatch
    new UnionAll(Collections.EMPTY_LIST)).addInputAsChild().physicalOperator(new Filter(null, parseExpr("a=5"), 1.0f)).addJsonScanAsChild().jsonBatches(leftJsonBatches).columnsToRead("a", "b").buildAddAsInput().buildAddAsInput().addInputAsChild().physicalOperator(new Filter(null, parseExpr("a=50"), 1.0f)).addJsonScanAsChild().jsonBatches(rightJsonBatches).columnsToRead("a", "b").buildAddAsInput().buildAddAsInput().build();
    BatchSchema expectedSchema = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).addNullable("b", TypeProtos.MinorType.BIGINT).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
    new MiniPlanTestBuilder().root(batch).expectedSchema(expectedSchema).baselineValues(5l, 1l).baselineValues(5l, 5l).baselineValues(50l, 100l).go();
}
Also used : Filter(org.apache.drill.exec.physical.config.Filter) BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) UnionAll(org.apache.drill.exec.physical.config.UnionAll) Test(org.junit.Test)

Example 7 with RecordBatch

use of org.apache.drill.exec.record.RecordBatch in project drill by apache.

the class TestMiniPlan method testSimpleParquetScan.

@Test
public void testSimpleParquetScan() throws Exception {
    String file = FileUtils.getResourceAsFile("/tpchmulti/region/01.parquet").toURI().toString();
    RecordBatch scanBatch = new ParquetScanBuilder().fileSystem(fs).columnsToRead("R_REGIONKEY").inputPaths(Lists.newArrayList(file)).build();
    BatchSchema expectedSchema = new SchemaBuilder().add("R_REGIONKEY", TypeProtos.MinorType.BIGINT).build();
    new MiniPlanTestBuilder().root(scanBatch).expectedSchema(expectedSchema).baselineValues(0L).baselineValues(1L).go();
}
Also used : BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) Test(org.junit.Test)

Example 8 with RecordBatch

use of org.apache.drill.exec.record.RecordBatch in project drill by apache.

the class ExpressionInterpreterTest method createMockScanBatch.

@SuppressWarnings("resource")
private ScanBatch createMockScanBatch(Drillbit bit, MockSubScanPOP scanPOP, BitControl.PlanFragment planFragment) {
    final List<RecordBatch> children = Lists.newArrayList();
    final MockScanBatchCreator creator = new MockScanBatchCreator();
    try {
        final FragmentContext context = new FragmentContext(bit.getContext(), planFragment, null, bit.getContext().getFunctionImplementationRegistry());
        return creator.getBatch(context, scanPOP, children);
    } catch (Exception ex) {
        throw new DrillRuntimeException("Error when setup fragment context" + ex);
    }
}
Also used : FragmentContext(org.apache.drill.exec.ops.FragmentContext) RecordBatch(org.apache.drill.exec.record.RecordBatch) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) MockScanBatchCreator(org.apache.drill.exec.store.mock.MockScanBatchCreator) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 9 with RecordBatch

use of org.apache.drill.exec.record.RecordBatch in project drill by apache.

the class ImplCreator method getRecordBatch.

/** Create a RecordBatch and its children for given PhysicalOperator */
@VisibleForTesting
public RecordBatch getRecordBatch(final PhysicalOperator op, final FragmentContext context) throws ExecutionSetupException {
    Preconditions.checkNotNull(op);
    final List<RecordBatch> childRecordBatches = getChildren(op, context);
    if (context.isImpersonationEnabled()) {
        final UserGroupInformation proxyUgi = ImpersonationUtil.createProxyUgi(op.getUserName(), context.getQueryUserName());
        try {
            return proxyUgi.doAs(new PrivilegedExceptionAction<RecordBatch>() {

                @Override
                public RecordBatch run() throws Exception {
                    final CloseableRecordBatch batch = ((BatchCreator<PhysicalOperator>) getOpCreator(op, context)).getBatch(context, op, childRecordBatches);
                    operators.addFirst(batch);
                    return batch;
                }
            });
        } catch (InterruptedException | IOException e) {
            final String errMsg = String.format("Failed to create RecordBatch for operator with id '%d'", op.getOperatorId());
            logger.error(errMsg, e);
            throw new ExecutionSetupException(errMsg, e);
        }
    } else {
        final CloseableRecordBatch batch = ((BatchCreator<PhysicalOperator>) getOpCreator(op, context)).getBatch(context, op, childRecordBatches);
        operators.addFirst(batch);
        return batch;
    }
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) RecordBatch(org.apache.drill.exec.record.RecordBatch) CloseableRecordBatch(org.apache.drill.exec.record.CloseableRecordBatch) IOException(java.io.IOException) IOException(java.io.IOException) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) CloseableRecordBatch(org.apache.drill.exec.record.CloseableRecordBatch) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

RecordBatch (org.apache.drill.exec.record.RecordBatch)9 Test (org.junit.Test)5 BatchSchema (org.apache.drill.exec.record.BatchSchema)4 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)4 Filter (org.apache.drill.exec.physical.config.Filter)2 UnionAll (org.apache.drill.exec.physical.config.UnionAll)2 Ignore (org.junit.Ignore)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)1 FragmentContext (org.apache.drill.exec.ops.FragmentContext)1 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)1 HashPartitionSender (org.apache.drill.exec.physical.config.HashPartitionSender)1 PartitionSenderRootExec (org.apache.drill.exec.physical.impl.partitionsender.PartitionSenderRootExec)1 CloseableRecordBatch (org.apache.drill.exec.record.CloseableRecordBatch)1 MockScanBatchCreator (org.apache.drill.exec.store.mock.MockScanBatchCreator)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1