use of org.apache.drill.exec.ops.FragmentContextImpl in project drill by axbaretto.
the class DumpCatTest method testDumpCat.
@Test
public void testDumpCat() throws Throwable {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final PhysicalPlanReader reader = defaultPhysicalPlanReader(c);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/trace/simple_trace.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
}
if (context.getExecutorState().getFailureCause() != null) {
throw context.getExecutorState().getFailureCause();
}
assertTrue(!context.getExecutorState().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);
}
}
use of org.apache.drill.exec.ops.FragmentContextImpl in project drill by axbaretto.
the class TestStringFunctions method runTest.
public void runTest(Object[] expectedResults, String planPath) throws Throwable {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8);
if (reader == null) {
reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
}
if (registry == null) {
registry = new FunctionImplementationRegistry(c);
}
if (context == null) {
context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
}
final PhysicalPlan plan = reader.readPhysicalPlan(planString);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
// skip schema batch
exec.next();
while (exec.next()) {
final Object[] res = getRunResult(exec);
assertEquals("return count does not match", expectedResults.length, res.length);
for (int i = 0; i < res.length; i++) {
assertEquals(String.format("column %s does not match", i), expectedResults[i], res[i]);
}
}
if (context.getExecutorState().getFailureCause() != null) {
throw context.getExecutorState().getFailureCause();
}
assertTrue(!context.getExecutorState().isFailed());
}
use of org.apache.drill.exec.ops.FragmentContextImpl in project drill by axbaretto.
the class TestAgg method doTest.
private SimpleRootExec doTest(String file) throws Exception {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile(file), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContextImpl context = new FragmentContextImpl(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.FragmentContextImpl in project drill by axbaretto.
the class TestCastFunctions method testCastInt.
@Test
public // cast to int
void testCastInt() throws Throwable {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastInt.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG);
final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
final IntVector c0 = exec.getValueVectorById(new SchemaPath("varchar_cast", ExpressionPosition.UNKNOWN), IntVector.class);
final IntVector.Accessor a0 = c0.getAccessor();
int count = 0;
for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
final IntHolder holder0 = new IntHolder();
a0.get(i, holder0);
assertEquals(1256, holder0.value);
++count;
}
assertEquals(5, count);
}
exec.close();
context.close();
if (context.getExecutorState().getFailureCause() != null) {
throw context.getExecutorState().getFailureCause();
}
assertTrue(!context.getExecutorState().isFailed());
}
use of org.apache.drill.exec.ops.FragmentContextImpl in project drill by axbaretto.
the class TestCastFunctions method testCastNumException.
@Test(expected = NumberFormatException.class)
public void testCastNumException() throws Throwable {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastNumException.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG);
final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
}
exec.close();
context.close();
assertTrue(context.getExecutorState().isFailed());
if (context.getExecutorState().getFailureCause() != null) {
throw context.getExecutorState().getFailureCause();
}
}
Aggregations