Search in sources :

Example 31 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext in project drill by apache.

the class TestCastFunctions method testCastFloat4.

@Test
public //cast to float4
void testCastFloat4(@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/testCastFloat4.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 Float4Vector c0 = exec.getValueVectorById(new SchemaPath("varchar_cast2", ExpressionPosition.UNKNOWN), Float4Vector.class);
        final Float4Vector.Accessor a0 = c0.getAccessor();
        int count = 0;
        for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
            final Float4Holder holder0 = new Float4Holder();
            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) Float4Vector(org.apache.drill.exec.vector.Float4Vector) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) Float4Holder(org.apache.drill.exec.expr.holders.Float4Holder) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Test(org.junit.Test)

Example 32 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext in project drill by apache.

the class TestOptiqPlans method doPhysicalTest.

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

Example 33 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext in project drill by apache.

the class HiveScanBatchCreator method getBatch.

@Override
public ScanBatch getBatch(FragmentContext context, HiveSubScan config, List<RecordBatch> children) throws ExecutionSetupException {
    List<RecordReader> readers = Lists.newArrayList();
    HiveTableWithColumnCache table = config.getTable();
    List<InputSplit> splits = config.getInputSplits();
    List<HivePartition> partitions = config.getPartitions();
    boolean hasPartitions = (partitions != null && partitions.size() > 0);
    int i = 0;
    final UserGroupInformation proxyUgi = ImpersonationUtil.createProxyUgi(config.getUserName(), context.getQueryUserName());
    final HiveConf hiveConf = config.getHiveConf();
    final String formatName = table.getSd().getInputFormat();
    Class<? extends HiveAbstractReader> readerClass = HiveDefaultReader.class;
    if (readerMap.containsKey(formatName)) {
        readerClass = readerMap.get(formatName);
    }
    Constructor<? extends HiveAbstractReader> readerConstructor = null;
    try {
        readerConstructor = readerClass.getConstructor(HiveTableWithColumnCache.class, HivePartition.class, InputSplit.class, List.class, FragmentContext.class, HiveConf.class, UserGroupInformation.class);
        for (InputSplit split : splits) {
            readers.add(readerConstructor.newInstance(table, (hasPartitions ? partitions.get(i++) : null), split, config.getColumns(), context, hiveConf, proxyUgi));
        }
        if (readers.size() == 0) {
            readers.add(readerConstructor.newInstance(table, null, null, config.getColumns(), context, hiveConf, proxyUgi));
        }
    } catch (Exception e) {
        logger.error("No constructor for {}, thrown {}", readerClass.getName(), e);
    }
    return new ScanBatch(config, context, readers.iterator());
}
Also used : FragmentContext(org.apache.drill.exec.ops.FragmentContext) RecordReader(org.apache.drill.exec.store.RecordReader) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) ScanBatch(org.apache.drill.exec.physical.impl.ScanBatch) HiveConf(org.apache.hadoop.hive.conf.HiveConf) List(java.util.List) InputSplit(org.apache.hadoop.mapred.InputSplit) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 34 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext 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 35 with FragmentContext

use of org.apache.drill.exec.ops.FragmentContext 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)

Aggregations

FragmentContext (org.apache.drill.exec.ops.FragmentContext)50 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)42 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)41 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)39 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)37 Test (org.junit.Test)32 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)24 SchemaPath (org.apache.drill.common.expression.SchemaPath)16 ExecTest (org.apache.drill.exec.ExecTest)15 ValueVector (org.apache.drill.exec.vector.ValueVector)8 BigIntVector (org.apache.drill.exec.vector.BigIntVector)6 IntVector (org.apache.drill.exec.vector.IntVector)6 Ignore (org.junit.Ignore)6 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)5 DrillConfig (org.apache.drill.common.config.DrillConfig)3 BigIntHolder (org.apache.drill.exec.expr.holders.BigIntHolder)3 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)3 OpProfileDef (org.apache.drill.exec.ops.OpProfileDef)3 OperatorStats (org.apache.drill.exec.ops.OperatorStats)3 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)3