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());
}
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;
}
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());
}
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();
}
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());
}
Aggregations