Search in sources :

Example 81 with PhysicalPlan

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

the class TestSimpleFunctions method testSubstringNegative.

@Test
public void testSubstringNegative(@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/testSubstringNegative.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 NullableVarCharVector c1 = exec.getValueVectorById(new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarCharVector.class);
        final NullableVarCharVector.Accessor a1 = c1.getAccessor();
        int count = 0;
        for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
            if (!a1.isNull(i)) {
                final NullableVarCharHolder holder = new NullableVarCharHolder();
                a1.get(i, holder);
                //when offset is negative, substring return empty string.
                assertEquals("", StringFunctionHelpers.toStringFromUTF8(holder.start, holder.end, holder.buffer));
                ++count;
            }
        }
        assertEquals(50, count);
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : NullableVarCharHolder(org.apache.drill.exec.expr.holders.NullableVarCharHolder) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) FragmentContext(org.apache.drill.exec.ops.FragmentContext) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 82 with PhysicalPlan

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

the class TestSimpleFunctions method testSubstring.

@Test
public void testSubstring(@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/testSubstring.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 NullableVarCharVector c1 = exec.getValueVectorById(new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarCharVector.class);
        final NullableVarCharVector.Accessor a1 = c1.getAccessor();
        int count = 0;
        for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
            if (!a1.isNull(i)) {
                final NullableVarCharHolder holder = new NullableVarCharHolder();
                a1.get(i, holder);
                assertEquals("aaaa", StringFunctionHelpers.toStringFromUTF8(holder.start, holder.end, holder.buffer));
                ++count;
            }
        }
        assertEquals(50, count);
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : NullableVarCharHolder(org.apache.drill.exec.expr.holders.NullableVarCharHolder) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) FragmentContext(org.apache.drill.exec.ops.FragmentContext) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 83 with PhysicalPlan

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

the class TestStringFunctions method runTest.

public void runTest(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable {
    mockDrillbitContext(bitContext);
    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) {
        //new FragmentContext(bitContext, ExecProtos.FragmentHandle.getInstance(), connection, registry);
        context = new FragmentContext(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.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 84 with PhysicalPlan

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

the class TestSimpleProjection method project.

@Test
public void project(@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("/project/test1.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()) {
        VectorUtil.showVectorAccessibleContent(exec.getIncoming(), "\t");
        final NullableBigIntVector c1 = exec.getValueVectorById(new SchemaPath("col1", ExpressionPosition.UNKNOWN), NullableBigIntVector.class);
        final NullableBigIntVector c2 = exec.getValueVectorById(new SchemaPath("col2", ExpressionPosition.UNKNOWN), NullableBigIntVector.class);
        int x = 0;
        final NullableBigIntVector.Accessor a1 = c1.getAccessor();
        final NullableBigIntVector.Accessor a2 = c2.getAccessor();
        for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
            if (!a1.isNull(i)) {
                assertEquals(a1.get(i) + 1, a2.get(i));
            }
            x += a1.isNull(i) ? 0 : a1.get(i);
        }
    }
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest)

Example 85 with PhysicalPlan

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

the class TestSimpleSort method sortOneKeyAscending.

@Test
public void sortOneKeyAscending(@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("/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());
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) BigIntVector(org.apache.drill.exec.vector.BigIntVector) IntVector(org.apache.drill.exec.vector.IntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)155 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)121 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)113 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)111 Test (org.junit.Test)97 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)80 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)78 UserClientConnection (org.apache.drill.exec.rpc.UserClientConnection)70 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)69 SchemaPath (org.apache.drill.common.expression.SchemaPath)46 ExecTest (org.apache.drill.exec.ExecTest)46 FragmentContext (org.apache.drill.exec.ops.FragmentContext)39 OperatorTest (org.apache.drill.categories.OperatorTest)32 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)30 ValueVector (org.apache.drill.exec.vector.ValueVector)23 IntVector (org.apache.drill.exec.vector.IntVector)18 BigIntVector (org.apache.drill.exec.vector.BigIntVector)17 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)15 Ignore (org.junit.Ignore)15 SlowTest (org.apache.drill.categories.SlowTest)10