Search in sources :

Example 41 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class DirectPlan method createDirectPlan.

public static <T> PhysicalPlan createDirectPlan(DrillbitEndpoint endpoint, Iterator<T> iterator, Class<T> clazz) {
    PojoRecordReader<T> reader = new PojoRecordReader<T>(clazz, iterator);
    DirectGroupScan scan = new DirectGroupScan(reader);
    Screen screen = new Screen(scan, endpoint);
    PlanPropertiesBuilder propsBuilder = PlanProperties.builder();
    propsBuilder.type(PlanType.APACHE_DRILL_PHYSICAL);
    propsBuilder.version(1);
    propsBuilder.resultMode(ResultMode.EXEC);
    propsBuilder.generator(DirectPlan.class.getSimpleName(), "");
    return new PhysicalPlan(propsBuilder.build(), DefaultSqlHandler.getPops(screen));
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) Screen(org.apache.drill.exec.physical.config.Screen) DirectGroupScan(org.apache.drill.exec.store.direct.DirectGroupScan) PlanPropertiesBuilder(org.apache.drill.common.logical.PlanProperties.PlanPropertiesBuilder) PojoRecordReader(org.apache.drill.exec.store.pojo.PojoRecordReader)

Example 42 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class RunRootExec method main.

public static void main(String[] args) throws Exception {
    String path = args[0];
    int iterations = Integer.parseInt(args[1]);
    Drillbit bit = new Drillbit(c, RemoteServiceSet.getLocalServiceSet(), ClassPathScanner.fromPrescan(c));
    bit.run();
    DrillbitContext bitContext = bit.getContext();
    PhysicalPlanReader reader = bitContext.getPlanReader();
    PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(new File(path), Charsets.UTF_8));
    FunctionImplementationRegistry registry = bitContext.getFunctionImplementationRegistry();
    FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), null, registry);
    SimpleRootExec exec;
    for (int i = 0; i < iterations; i++) {
        Stopwatch w = Stopwatch.createStarted();
        System.out.println("STARTITER:" + i);
        exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
        while (exec.next()) {
            for (ValueVector v : exec) {
                v.clear();
            }
        }
        System.out.println("ENDITER: " + i);
        System.out.println("TIME: " + w.elapsed(TimeUnit.MILLISECONDS) + "ms");
        exec.close();
    }
    context.close();
    bit.close();
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) ValueVector(org.apache.drill.exec.vector.ValueVector) SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) Drillbit(org.apache.drill.exec.server.Drillbit) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) Stopwatch(com.google.common.base.Stopwatch) File(java.io.File) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 43 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class TestOpSerialization method testSerializedDeserialize.

@Test
public void testSerializedDeserialize() throws Throwable {
    DrillConfig c = DrillConfig.create();
    PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    MockSubScanPOP s = new MockSubScanPOP("abc", false, null);
    s.setOperatorId(3);
    Filter f = new Filter(s, new ValueExpressions.BooleanExpression("true", ExpressionPosition.UNKNOWN), 0.1f);
    f.setOperatorId(2);
    UnionExchange e = new UnionExchange(f);
    e.setOperatorId(1);
    Screen screen = new Screen(e, CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
    screen.setOperatorId(0);
    boolean reversed = false;
    while (true) {
        List<PhysicalOperator> pops = Lists.newArrayList();
        pops.add(s);
        pops.add(e);
        pops.add(f);
        pops.add(screen);
        if (reversed) {
            pops = Lists.reverse(pops);
        }
        PhysicalPlan plan1 = new PhysicalPlan(PlanProperties.builder().build(), pops);
        LogicalPlanPersistence logicalPlanPersistence = PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(c);
        String json = plan1.unparse(logicalPlanPersistence.getMapper().writer());
        PhysicalPlan plan2 = reader.readPhysicalPlan(json);
        PhysicalOperator root = plan2.getSortedOperators(false).iterator().next();
        assertEquals(0, root.getOperatorId());
        PhysicalOperator o1 = root.iterator().next();
        assertEquals(1, o1.getOperatorId());
        PhysicalOperator o2 = o1.iterator().next();
        assertEquals(2, o2.getOperatorId());
        if (reversed) {
            break;
        }
        reversed = !reversed;
    }
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) UnionExchange(org.apache.drill.exec.physical.config.UnionExchange) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) Screen(org.apache.drill.exec.physical.config.Screen) ValueExpressions(org.apache.drill.common.expression.ValueExpressions) MockSubScanPOP(org.apache.drill.exec.store.mock.MockSubScanPOP) LogicalPlanPersistence(org.apache.drill.common.config.LogicalPlanPersistence) DrillConfig(org.apache.drill.common.config.DrillConfig) Filter(org.apache.drill.exec.physical.config.Filter) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) Test(org.junit.Test)

Example 44 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class TestSimpleFunctions method testByteSubstring.

@Test
public void testByteSubstring(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/testByteSubstring.json"), 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()));
    while (exec.next()) {
        final NullableVarBinaryVector c1 = exec.getValueVectorById(new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarBinaryVector.class);
        final NullableVarBinaryVector.Accessor a1 = c1.getAccessor();
        int count = 0;
        for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
            if (!a1.isNull(i)) {
                final NullableVarBinaryHolder holder = new NullableVarBinaryHolder();
                a1.get(i, holder);
                assertEquals("aa", StringFunctionHelpers.toStringFromUTF8(holder.start, holder.end, holder.buffer));
                ++count;
            }
        }
        assertEquals(50, count);
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) NullableVarBinaryVector(org.apache.drill.exec.vector.NullableVarBinaryVector) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) NullableVarBinaryHolder(org.apache.drill.exec.expr.holders.NullableVarBinaryHolder) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 45 with PhysicalPlan

use of org.apache.drill.exec.physical.PhysicalPlan in project drill by apache.

the class TestSimpleFunctions method testSubstringNegative.

@Test
public void testSubstringNegative(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/testSubstringNegative.json"), 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()));
    while (exec.next()) {
        final NullableVarCharVector c1 = exec.getValueVectorById(new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarCharVector.class);
        final NullableVarCharVector.Accessor a1 = c1.getAccessor();
        int count = 0;
        for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
            if (!a1.isNull(i)) {
                final NullableVarCharHolder holder = new NullableVarCharHolder();
                a1.get(i, holder);
                //when offset is negative, substring return empty string.
                assertEquals("", StringFunctionHelpers.toStringFromUTF8(holder.start, holder.end, holder.buffer));
                ++count;
            }
        }
        assertEquals(50, count);
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : NullableVarCharHolder(org.apache.drill.exec.expr.holders.NullableVarCharHolder) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) FragmentContext(org.apache.drill.exec.ops.FragmentContext) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)58 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)43 FragmentContext (org.apache.drill.exec.ops.FragmentContext)41 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)41 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)39 Test (org.junit.Test)34 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)24 ExecTest (org.apache.drill.exec.ExecTest)16 SchemaPath (org.apache.drill.common.expression.SchemaPath)15 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)13 ValueVector (org.apache.drill.exec.vector.ValueVector)8 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)6 BigIntVector (org.apache.drill.exec.vector.BigIntVector)6 IntVector (org.apache.drill.exec.vector.IntVector)6 Ignore (org.junit.Ignore)5 DrillConfig (org.apache.drill.common.config.DrillConfig)4 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)4 IOException (java.io.IOException)3 RelNode (org.apache.calcite.rel.RelNode)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3