@Test public void testSubstringNegative( @Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection connection) throws Throwable { new NonStrictExpectations() { { bitContext.getMetrics(); result = new MetricRegistry(); bitContext.getAllocator(); result = new TopLevelAllocator(); bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); bitContext.getConfig(); result = c; } }; PhysicalPlanReader reader = new PhysicalPlanReader( c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); PhysicalPlan plan = reader.readPhysicalPlan( Files.toString( FileUtils.getResourceAsFile("/functions/testSubstringNegative.json"), Charsets.UTF_8)); FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); SimpleRootExec exec = new SimpleRootExec( ImplCreator.getExec( context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while (exec.next()) { NullableVarCharVector c1 = exec.getValueVectorById( new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarCharVector.class); NullableVarCharVector.Accessor a1; a1 = c1.getAccessor(); int count = 0; for (int i = 0; i < c1.getAccessor().getValueCount(); i++) { if (!a1.isNull(i)) { NullableVarCharHolder holder = new NullableVarCharHolder(); a1.get(i, holder); // when offset is negative, substring return empty string. assertEquals("", holder.toString()); ++count; } } assertEquals(50, count); } if (context.getFailureCause() != null) { throw context.getFailureCause(); } assertTrue(!context.isFailed()); }
@Test public void sortOneKeyAscending( @Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { new NonStrictExpectations() { { bitContext.getMetrics(); result = new MetricRegistry(); bitContext.getAllocator(); result = new TopLevelAllocator(); bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); bitContext.getConfig(); result = c; bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c); } }; final PhysicalPlanReader reader = new PhysicalPlanReader( c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); final PhysicalPlan plan = reader.readPhysicalPlan( Files.toString(FileUtils.getResourceAsFile("/sort/one_key_sort.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())); int previousInt = Integer.MIN_VALUE; int recordCount = 0; int batchCount = 0; while (exec.next()) { batchCount++; final IntVector c1 = exec.getValueVectorById( new SchemaPath("blue", ExpressionPosition.UNKNOWN), IntVector.class); final IntVector c2 = exec.getValueVectorById( new SchemaPath("green", ExpressionPosition.UNKNOWN), IntVector.class); final IntVector.Accessor a1 = c1.getAccessor(); final IntVector.Accessor a2 = c2.getAccessor(); for (int i = 0; i < c1.getAccessor().getValueCount(); i++) { recordCount++; assertTrue(previousInt <= a1.get(i)); previousInt = a1.get(i); assertEquals(previousInt, a2.get(i)); } } System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount)); if (context.getFailureCause() != null) { throw context.getFailureCause(); } assertTrue(!context.isFailed()); }