Search in sources :

Example 31 with PhysicalPlan

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

the class DumpCatTest method testDumpCat.

@Test
public void testDumpCat(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/trace/simple_trace.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()) {
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
    exec.close();
    FragmentHandle handle = context.getHandle();
    /* Form the file name to which the trace output will dump the record batches */
    String qid = QueryIdHelper.getQueryId(handle.getQueryId());
    final int majorFragmentId = handle.getMajorFragmentId();
    final int minorFragmentId = handle.getMinorFragmentId();
    final String logLocation = c.getString(ExecConstants.TRACE_DUMP_DIRECTORY);
    System.out.println("Found log location: " + logLocation);
    final String filename = String.format("%s//%s_%d_%d_mock-scan", logLocation, qid, majorFragmentId, minorFragmentId);
    System.out.println("File Name: " + filename);
    final Configuration conf = new Configuration();
    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, c.getString(ExecConstants.TRACE_DUMP_FILESYSTEM));
    final FileSystem fs = FileSystem.get(conf);
    final Path path = new Path(filename);
    assertTrue("Trace file does not exist", fs.exists(path));
    final DumpCat dumpCat = new DumpCat();
    //Test Query mode
    try (final FileInputStream input = new FileInputStream(filename)) {
        dumpCat.doQuery(input);
    }
    //Test Batch mode
    try (final FileInputStream input = new FileInputStream(filename)) {
        dumpCat.doBatch(input, 0, true);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) Configuration(org.apache.hadoop.conf.Configuration) PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FragmentHandle(org.apache.drill.exec.proto.ExecProtos.FragmentHandle) FileInputStream(java.io.FileInputStream) SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) FileSystem(org.apache.hadoop.fs.FileSystem) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 32 with PhysicalPlan

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

the class TestCastFunctions method testCastVarBinary.

@Test
public //cast to varbinary(length)
void testCastVarBinary(@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/testCastVarBinary.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 VarBinaryVector c0 = exec.getValueVectorById(new SchemaPath("int_lit_cast", ExpressionPosition.UNKNOWN), VarBinaryVector.class);
        final VarBinaryVector.Accessor a0 = c0.getAccessor();
        int count = 0;
        for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
            final VarBinaryHolder holder0 = new VarBinaryHolder();
            a0.get(i, holder0);
            assertEquals("123", StringFunctionHelpers.toStringFromUTF8(holder0.start, holder0.end, holder0.buffer));
            ++count;
        }
        assertEquals(5, count);
    }
    exec.close();
    context.close();
    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) VarBinaryHolder(org.apache.drill.exec.expr.holders.VarBinaryHolder) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) VarBinaryVector(org.apache.drill.exec.vector.VarBinaryVector) Test(org.junit.Test)

Example 33 with PhysicalPlan

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

the class TestAgg method doTest.

private SimpleRootExec doTest(final DrillbitContext bitContext, UserClientConnection connection, String file) throws Exception {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile(file), 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()));
    return exec;
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 34 with PhysicalPlan

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

the class TestParsePhysicalPlan method parseSimplePlan.

@Test
public void parseSimplePlan() throws Exception {
    DrillConfig c = DrillConfig.create();
    ScanResult scanResult = ClassPathScanner.fromPrescan(c);
    LogicalPlanPersistence lpp = new LogicalPlanPersistence(c, scanResult);
    PhysicalPlanReader reader = new PhysicalPlanReader(c, scanResult, lpp, CoordinationProtos.DrillbitEndpoint.getDefaultInstance(), null);
    ObjectReader r = lpp.getMapper().reader(PhysicalPlan.class);
    ObjectWriter writer = lpp.getMapper().writer();
    PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_test1.json"), Charsets.UTF_8));
    String unparse = plan.unparse(writer);
//    System.out.println(unparse);
}
Also used : ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) DrillConfig(org.apache.drill.common.config.DrillConfig) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) LogicalPlanPersistence(org.apache.drill.common.config.LogicalPlanPersistence) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest)

Example 35 with PhysicalPlan

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

the class TestCastFunctions method testCastFloat8.

@Test
public //cast to float8
void testCastFloat8(@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/testCastFloat8.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 Float8Vector c0 = exec.getValueVectorById(new SchemaPath("varchar_cast2", ExpressionPosition.UNKNOWN), Float8Vector.class);
        final Float8Vector.Accessor a0 = c0.getAccessor();
        int count = 0;
        for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
            final Float8Holder holder0 = new Float8Holder();
            a0.get(i, holder0);
            assertEquals(12.56, holder0.value, 0.001);
            ++count;
        }
        assertEquals(5, count);
    }
    exec.close();
    context.close();
    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) Float8Vector(org.apache.drill.exec.vector.Float8Vector) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Float8Holder(org.apache.drill.exec.expr.holders.Float8Holder) 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