Search in sources :

Example 6 with Float8Vector

use of org.apache.drill.exec.vector.Float8Vector in project drill by apache.

the class TestMathFunctions method testBasicMathFunctions.

@Test
public void testBasicMathFunctions() throws Throwable {
    final DrillbitContext bitContext = mockDrillbitContext();
    final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.asCharSource(DrillFileUtils.getResourceAsFile("/functions/simple_math_functions.json"), Charsets.UTF_8).read());
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContextImpl context = new FragmentContextImpl(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    while (exec.next()) {
        final IntVector intMulVector = exec.getValueVectorById(new SchemaPath("INTMUL", ExpressionPosition.UNKNOWN), IntVector.class);
        final Float8Vector floatMulVector = exec.getValueVectorById(new SchemaPath("FLOATMUL", ExpressionPosition.UNKNOWN), Float8Vector.class);
        final IntVector intAddVector = exec.getValueVectorById(new SchemaPath("INTADD", ExpressionPosition.UNKNOWN), IntVector.class);
        final Float8Vector floatAddVector = exec.getValueVectorById(new SchemaPath("FLOATADD", ExpressionPosition.UNKNOWN), Float8Vector.class);
        assertEquals(exec.getRecordCount(), 1);
        assertEquals(intMulVector.getAccessor().get(0), 2);
        assertEquals(floatMulVector.getAccessor().get(0), (1.1 * 2.2), 0);
        assertEquals(intAddVector.getAccessor().get(0), 3);
        assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0);
    }
    if (context.getExecutorState().getFailureCause() != null) {
        throw context.getExecutorState().getFailureCause();
    }
    assertTrue(!context.getExecutorState().isFailed());
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) IntVector(org.apache.drill.exec.vector.IntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) Float8Vector(org.apache.drill.exec.vector.Float8Vector) UserClientConnection(org.apache.drill.exec.rpc.UserClientConnection) FragmentContextImpl(org.apache.drill.exec.ops.FragmentContextImpl) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 7 with Float8Vector

use of org.apache.drill.exec.vector.Float8Vector in project drill by apache.

the class DoubleGen method setValue.

@Override
public void setValue(ValueVector v, int index) {
    Float8Vector vector = (Float8Vector) v;
    vector.getMutator().set(index, value());
}
Also used : Float8Vector(org.apache.drill.exec.vector.Float8Vector)

Example 8 with Float8Vector

use of org.apache.drill.exec.vector.Float8Vector in project drill by apache.

the class TestMathFunctions method testBasicMathFunctions.

@Test
public void testBasicMathFunctions(@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/simple_math_functions.json"), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    while (exec.next()) {
        final IntVector intMulVector = exec.getValueVectorById(new SchemaPath("INTMUL", ExpressionPosition.UNKNOWN), IntVector.class);
        final Float8Vector floatMulVector = exec.getValueVectorById(new SchemaPath("FLOATMUL", ExpressionPosition.UNKNOWN), Float8Vector.class);
        final IntVector intAddVector = exec.getValueVectorById(new SchemaPath("INTADD", ExpressionPosition.UNKNOWN), IntVector.class);
        final Float8Vector floatAddVector = exec.getValueVectorById(new SchemaPath("FLOATADD", ExpressionPosition.UNKNOWN), Float8Vector.class);
        assertEquals(exec.getRecordCount(), 1);
        assertEquals(intMulVector.getAccessor().get(0), 2);
        assertEquals(floatMulVector.getAccessor().get(0), (1.1 * 2.2), 0);
        assertEquals(intAddVector.getAccessor().get(0), 3);
        assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0);
    }
    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) IntVector(org.apache.drill.exec.vector.IntVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) Float8Vector(org.apache.drill.exec.vector.Float8Vector) 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 9 with Float8Vector

use of org.apache.drill.exec.vector.Float8Vector in project drill by apache.

the class TestCastFunctions method testCastFloat8.

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

Example 10 with Float8Vector

use of org.apache.drill.exec.vector.Float8Vector in project drill by axbaretto.

the class TestOrderedPartitionExchange method twoBitTwoExchangeRun.

/**
 * Starts two drillbits and runs a physical plan with a Mock scan, project, OrderedParititionExchange, Union Exchange,
 * and sort. The final sort is done first on the partition column, and verifies that the partitions are correct, in that
 * all rows in partition 0 should come in the sort order before any row in partition 1, etc. Also verifies that the standard
 * deviation of the size of the partitions is less than one tenth the mean size of the partitions, because we expect all
 * the partitions to be roughly equal in size.
 * @throws Exception
 */
@Test
public void twoBitTwoExchangeRun() throws Exception {
    RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
    try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
        Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        bit1.run();
        bit2.run();
        client.connect();
        List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(DrillFileUtils.getResourceAsFile("/sender/ordered_exchange.json"), Charsets.UTF_8));
        int count = 0;
        List<Integer> partitionRecordCounts = Lists.newArrayList();
        for (QueryDataBatch b : results) {
            if (b.getData() != null) {
                int rows = b.getHeader().getRowCount();
                count += rows;
                DrillConfig config = DrillConfig.create();
                RecordBatchLoader loader = new RecordBatchLoader(new BootStrapContext(config, SystemOptionManager.createDefaultOptionDefinitions(), ClassPathScanner.fromPrescan(config)).getAllocator());
                loader.load(b.getHeader().getDef(), b.getData());
                BigIntVector vv1 = (BigIntVector) loader.getValueAccessorById(BigIntVector.class, loader.getValueVectorId(new SchemaPath("col1", ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
                Float8Vector vv2 = (Float8Vector) loader.getValueAccessorById(Float8Vector.class, loader.getValueVectorId(new SchemaPath("col2", ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
                IntVector pVector = (IntVector) loader.getValueAccessorById(IntVector.class, loader.getValueVectorId(new SchemaPath("partition", ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
                long previous1 = Long.MIN_VALUE;
                double previous2 = Double.MIN_VALUE;
                int partPrevious = -1;
                long current1 = Long.MIN_VALUE;
                double current2 = Double.MIN_VALUE;
                int partCurrent = -1;
                int partitionRecordCount = 0;
                for (int i = 0; i < rows; i++) {
                    previous1 = current1;
                    previous2 = current2;
                    partPrevious = partCurrent;
                    current1 = vv1.getAccessor().get(i);
                    current2 = vv2.getAccessor().get(i);
                    partCurrent = pVector.getAccessor().get(i);
                    Assert.assertTrue(current1 >= previous1);
                    if (current1 == previous1) {
                        Assert.assertTrue(current2 <= previous2);
                    }
                    if (partCurrent == partPrevious || partPrevious == -1) {
                        partitionRecordCount++;
                    } else {
                        partitionRecordCounts.add(partitionRecordCount);
                        partitionRecordCount = 0;
                    }
                }
                partitionRecordCounts.add(partitionRecordCount);
                loader.clear();
            }
            b.release();
        }
        double[] values = new double[partitionRecordCounts.size()];
        int i = 0;
        for (Integer rc : partitionRecordCounts) {
            values[i++] = rc.doubleValue();
        }
        StandardDeviation stdDev = new StandardDeviation();
        Mean mean = new Mean();
        double std = stdDev.evaluate(values);
        double m = mean.evaluate(values);
        System.out.println("mean: " + m + " std dev: " + std);
        // Assert.assertTrue(std < 0.1 * m);
        assertEquals(31000, count);
    }
}
Also used : Mean(org.apache.commons.math.stat.descriptive.moment.Mean) BigIntVector(org.apache.drill.exec.vector.BigIntVector) IntVector(org.apache.drill.exec.vector.IntVector) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) Float8Vector(org.apache.drill.exec.vector.Float8Vector) BigIntVector(org.apache.drill.exec.vector.BigIntVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) DrillConfig(org.apache.drill.common.config.DrillConfig) Drillbit(org.apache.drill.exec.server.Drillbit) SchemaPath(org.apache.drill.common.expression.SchemaPath) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) BootStrapContext(org.apache.drill.exec.server.BootStrapContext) StandardDeviation(org.apache.commons.math.stat.descriptive.moment.StandardDeviation) DrillClient(org.apache.drill.exec.client.DrillClient) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

Float8Vector (org.apache.drill.exec.vector.Float8Vector)17 SchemaPath (org.apache.drill.common.expression.SchemaPath)8 Test (org.junit.Test)8 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)6 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)6 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)6 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)6 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)5 IntVector (org.apache.drill.exec.vector.IntVector)5 ValueVector (org.apache.drill.exec.vector.ValueVector)5 OperatorTest (org.apache.drill.categories.OperatorTest)4 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)4 UserClientConnection (org.apache.drill.exec.rpc.UserClientConnection)4 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)4 ExecTest (org.apache.drill.exec.ExecTest)3 Float8Holder (org.apache.drill.exec.expr.holders.Float8Holder)3 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)3 Mean (org.apache.commons.math.stat.descriptive.moment.Mean)2 StandardDeviation (org.apache.commons.math.stat.descriptive.moment.StandardDeviation)2 DrillConfig (org.apache.drill.common.config.DrillConfig)2