Search in sources :

Example 6 with TransformFunction

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

the class DefaultExpressionEvaluator method evaluateExpression.

/**
   * Helper (recursive) method that walks the expression tree bottom up evaluating
   * transforms at each level.
   *
   * @param projectionBlock Projection block for which to evaluate the expression for
   * @param expressionTree Expression tree to evaluate
   * @return Result of the expression transform
   */
private BlockValSet evaluateExpression(ProjectionBlock projectionBlock, TransformExpressionTree expressionTree) {
    TransformFunction function = getTransformFunction(expressionTree.getTransformName());
    int numDocs = projectionBlock.getNumDocs();
    String expressionString = expressionTree.toString();
    TransformExpressionTree.ExpressionType expressionType = expressionTree.getExpressionType();
    switch(expressionType) {
        case FUNCTION:
            List<TransformExpressionTree> children = expressionTree.getChildren();
            int numChildren = children.size();
            BlockValSet[] transformArgs = new BlockValSet[numChildren];
            for (int i = 0; i < numChildren; i++) {
                transformArgs[i] = evaluateExpression(projectionBlock, children.get(i));
            }
            return new TransformBlockValSet(function, numDocs, transformArgs);
        case IDENTIFIER:
            return projectionBlock.getBlockValueSet(expressionString);
        case LITERAL:
            return new ConstantBlockValSet(expressionString, numDocs);
        default:
            throw new IllegalArgumentException("Illegal expression type in expression evaluator: " + expressionType);
    }
}
Also used : TransformFunction(com.linkedin.pinot.core.operator.transform.function.TransformFunction) TransformExpressionTree(com.linkedin.pinot.common.request.transform.TransformExpressionTree) BlockValSet(com.linkedin.pinot.core.common.BlockValSet) ConstantBlockValSet(com.linkedin.pinot.core.operator.docvalsets.ConstantBlockValSet) TransformBlockValSet(com.linkedin.pinot.core.operator.docvalsets.TransformBlockValSet) TransformBlockValSet(com.linkedin.pinot.core.operator.docvalsets.TransformBlockValSet) ConstantBlockValSet(com.linkedin.pinot.core.operator.docvalsets.ConstantBlockValSet)

Example 7 with TransformFunction

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

the class TransformFunctionFactoryTest method testTransformLoading.

/**
   * This test ensure that any transform class can be loaded as long as it is
   * in the class path.
   */
@Test
public void testTransformLoading() {
    TransformFunction[] transforms = new TransformFunction[] { new foo(), new bar(), new foo() };
    String[] classNames = new String[transforms.length];
    for (int i = 0; i < transforms.length; i++) {
        classNames[i] = transforms[i].getClass().getName();
    }
    TransformFunctionFactory.init(classNames);
    // Assert that the transform factory can provide instances for the transforms.
    for (TransformFunction transform : transforms) {
        Assert.assertNotNull(TransformFunctionFactory.get(transform.getName()));
    }
}
Also used : 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