Search in sources :

Example 1 with TransformFunction

use of com.linkedin.pinot.core.operator.transform.function.TransformFunction in project pinot by linkedin.

the class TransformExpressionTreeTest method test.

/**
   * This test validates an expression tree built by {@link TransformExpressionTree#buildTree(AstNode)}
   */
@Test
public void test() {
    TransformFunctionFactory.init(new String[] { TransformFunctionFactoryTest.foo.class.getName(), TransformFunctionFactoryTest.bar.class.getName() });
    Pql2Compiler compiler = new Pql2Compiler();
    String expression = "foo(bar('a', foo(b, 'c', d)), e)";
    TransformExpressionTree expressionTree = compiler.compileToExpressionTree(expression);
    TransformFunction rootTransform = TransformFunctionFactory.get(expressionTree.getTransformName());
    Assert.assertEquals(rootTransform.getName(), "foo");
    List<TransformExpressionTree> firstChildren = expressionTree.getChildren();
    Assert.assertEquals(firstChildren.size(), 2);
    TransformExpressionTree firstChild = firstChildren.get(0);
    Assert.assertEquals(firstChild.getTransformName(), "bar");
    Assert.assertEquals(firstChildren.get(1).toString(), "e");
    List<TransformExpressionTree> secondChildren = firstChild.getChildren();
    Assert.assertEquals(secondChildren.size(), 2);
    Assert.assertEquals(secondChildren.get(0).toString(), "a");
    Assert.assertEquals(secondChildren.get(1).getTransformName(), "foo");
    List<TransformExpressionTree> thirdChildren = secondChildren.get(1).getChildren();
    Assert.assertEquals(thirdChildren.get(0).toString(), "b");
    Assert.assertEquals(thirdChildren.get(1).toString(), "c");
    Assert.assertEquals(thirdChildren.get(2).toString(), "d");
}
Also used : TransformFunction(com.linkedin.pinot.core.operator.transform.function.TransformFunction) TransformExpressionTree(com.linkedin.pinot.common.request.transform.TransformExpressionTree) Pql2Compiler(com.linkedin.pinot.pql.parsers.Pql2Compiler) Test(org.testng.annotations.Test)

Example 2 with TransformFunction

use of com.linkedin.pinot.core.operator.transform.function.TransformFunction in project pinot by linkedin.

the class DivisionTransformTest method test.

/**
   * Tests that division of two columns as returned by the {@link DivisionTransform}
   * is as expected.
   */
@Test
public void test() {
    long seed = System.nanoTime();
    Random random = new Random(seed);
    double[] input1 = new double[NUM_ROWS];
    double[] input2 = new double[NUM_ROWS];
    double[] expected = new double[NUM_ROWS];
    for (int i = 0; i < NUM_ROWS; i++) {
        input1[i] = random.nextDouble();
        input2[i] = random.nextDouble();
        expected[i] = input1[i] / input2[i];
    }
    TransformFunction function = new DivisionTransform();
    double[] actual = function.transform(NUM_ROWS, new TransformTestUtils.TestBlockValSet(input1, NUM_ROWS), new TransformTestUtils.TestBlockValSet(input2, NUM_ROWS));
    for (int i = 0; i < NUM_ROWS; i++) {
        Assert.assertEquals(actual[i], expected[i], EPSILON, ("Random seed: " + seed));
    }
}
Also used : DivisionTransform(com.linkedin.pinot.core.operator.transform.function.DivisionTransform) Random(java.util.Random) TransformFunction(com.linkedin.pinot.core.operator.transform.function.TransformFunction) Test(org.testng.annotations.Test)

Example 3 with TransformFunction

use of com.linkedin.pinot.core.operator.transform.function.TransformFunction in project pinot by linkedin.

the class AdditionTransformTest method test.

/**
   * Tests that addition for three columns (one int, one float and one double)
   * are as expected.
   */
@Test
public void test() {
    long seed = System.nanoTime();
    Random random = new Random(seed);
    double[] input1 = new double[NUM_ROWS];
    double[] input2 = new double[NUM_ROWS];
    double[] input3 = new double[NUM_ROWS];
    double[] expected = new double[NUM_ROWS];
    for (int i = 0; i < NUM_ROWS; i++) {
        input1[i] = random.nextInt();
        input2[i] = random.nextFloat();
        input3[i] = random.nextDouble();
        expected[i] = input1[i] + input2[i] + input3[i];
    }
    TransformFunction function = new AdditionTransform();
    double[] actual = function.transform(NUM_ROWS, new TransformTestUtils.TestBlockValSet(input1, NUM_ROWS), new TransformTestUtils.TestBlockValSet(input2, NUM_ROWS), new TransformTestUtils.TestBlockValSet(input3, NUM_ROWS));
    for (int i = 0; i < NUM_ROWS; i++) {
        Assert.assertEquals(actual[i], expected[i], EPSILON, ("Random seed: " + seed));
    }
}
Also used : Random(java.util.Random) TransformFunction(com.linkedin.pinot.core.operator.transform.function.TransformFunction) AdditionTransform(com.linkedin.pinot.core.operator.transform.function.AdditionTransform) Test(org.testng.annotations.Test)

Example 4 with TransformFunction

use of com.linkedin.pinot.core.operator.transform.function.TransformFunction in project pinot by linkedin.

the class MultiplicationTransformTest method test.

/**
   * Tests that multiplication for three columns (one int, one float and one double)
   * are as expected.
   */
@Test
public void test() {
    long seed = System.nanoTime();
    Random random = new Random(seed);
    double[] input1 = new double[NUM_ROWS];
    double[] input2 = new double[NUM_ROWS];
    double[] input3 = new double[NUM_ROWS];
    double[] expected = new double[NUM_ROWS];
    for (int i = 0; i < NUM_ROWS; i++) {
        input1[i] = random.nextInt(1000);
        input2[i] = random.nextFloat();
        input3[i] = random.nextDouble();
        expected[i] = input1[i] * input2[i] * input3[i];
    }
    TransformFunction function = new MultiplicationTransform();
    double[] actual = function.transform(NUM_ROWS, new TransformTestUtils.TestBlockValSet(input1, NUM_ROWS), new TransformTestUtils.TestBlockValSet(input2, NUM_ROWS), new TransformTestUtils.TestBlockValSet(input3, NUM_ROWS));
    for (int i = 0; i < NUM_ROWS; i++) {
        Assert.assertEquals(actual[i], expected[i], EPSILON, ("Random seed: " + seed));
    }
}
Also used : Random(java.util.Random) TransformFunction(com.linkedin.pinot.core.operator.transform.function.TransformFunction) MultiplicationTransform(com.linkedin.pinot.core.operator.transform.function.MultiplicationTransform) Test(org.testng.annotations.Test)

Example 5 with TransformFunction

use of com.linkedin.pinot.core.operator.transform.function.TransformFunction in project pinot by linkedin.

the class SubtractionTransformTest method test.

/**
   * Tests that the subtraction of two columns as returned by {@link SubtractionTransform
   * is as expected.
   */
@Test
public void test() {
    long seed = System.nanoTime();
    Random random = new Random(seed);
    double[] input1 = new double[NUM_ROWS];
    double[] input2 = new double[NUM_ROWS];
    double[] expected = new double[NUM_ROWS];
    for (int i = 0; i < NUM_ROWS; i++) {
        input1[i] = random.nextDouble();
        input2[i] = random.nextDouble();
        expected[i] = input1[i] - input2[i];
    }
    TransformFunction function = new SubtractionTransform();
    double[] actual = function.transform(NUM_ROWS, new TransformTestUtils.TestBlockValSet(input1, NUM_ROWS), new TransformTestUtils.TestBlockValSet(input2, NUM_ROWS));
    for (int i = 0; i < NUM_ROWS; i++) {
        Assert.assertEquals(actual[i], expected[i], EPSILON, ("Random seed: " + seed));
    }
}
Also used : SubtractionTransform(com.linkedin.pinot.core.operator.transform.function.SubtractionTransform) Random(java.util.Random) TransformFunction(com.linkedin.pinot.core.operator.transform.function.TransformFunction) Test(org.testng.annotations.Test)

Aggregations

TransformFunction (com.linkedin.pinot.core.operator.transform.function.TransformFunction)7 Test (org.testng.annotations.Test)6 Random (java.util.Random)4 TransformExpressionTree (com.linkedin.pinot.common.request.transform.TransformExpressionTree)2 BlockValSet (com.linkedin.pinot.core.common.BlockValSet)1 ConstantBlockValSet (com.linkedin.pinot.core.operator.docvalsets.ConstantBlockValSet)1 TransformBlockValSet (com.linkedin.pinot.core.operator.docvalsets.TransformBlockValSet)1 AdditionTransform (com.linkedin.pinot.core.operator.transform.function.AdditionTransform)1 DivisionTransform (com.linkedin.pinot.core.operator.transform.function.DivisionTransform)1 MultiplicationTransform (com.linkedin.pinot.core.operator.transform.function.MultiplicationTransform)1 SubtractionTransform (com.linkedin.pinot.core.operator.transform.function.SubtractionTransform)1 Pql2Compiler (com.linkedin.pinot.pql.parsers.Pql2Compiler)1