Search in sources :

Example 1 with ConstantBlockValSet

use of com.linkedin.pinot.core.operator.docvalsets.ConstantBlockValSet in project pinot by linkedin.

the class TimeConversionTransformTest method test.

@Test
public void test() {
    long[] input = new long[NUM_ROWS];
    long[] expected = new long[NUM_ROWS];
    long seed = System.currentTimeMillis();
    Random random = new Random(seed);
    for (int i = 0; i < NUM_ROWS; i++) {
        input[i] = random.nextLong() % seed;
        expected[i] = TimeUnit.DAYS.convert(input[i], TimeUnit.MILLISECONDS);
    }
    TransformTestUtils.TestBlockValSet inputTimes = new TransformTestUtils.TestBlockValSet(input, NUM_ROWS);
    ConstantBlockValSet inputTimeUnit = new ConstantBlockValSet("MILLISECONDS", NUM_ROWS);
    ConstantBlockValSet outputTimeUnit = new ConstantBlockValSet("DAYS", NUM_ROWS);
    TimeConversionTransform function = new TimeConversionTransform();
    long[] actual = function.transform(NUM_ROWS, inputTimes, inputTimeUnit, outputTimeUnit);
    for (int i = 0; i < NUM_ROWS; i++) {
        Assert.assertEquals(actual[i], expected[i]);
    }
}
Also used : Random(java.util.Random) TimeConversionTransform(com.linkedin.pinot.core.operator.transform.function.TimeConversionTransform) ConstantBlockValSet(com.linkedin.pinot.core.operator.docvalsets.ConstantBlockValSet) Test(org.testng.annotations.Test)

Example 2 with ConstantBlockValSet

use of com.linkedin.pinot.core.operator.docvalsets.ConstantBlockValSet 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)

Aggregations

ConstantBlockValSet (com.linkedin.pinot.core.operator.docvalsets.ConstantBlockValSet)2 TransformExpressionTree (com.linkedin.pinot.common.request.transform.TransformExpressionTree)1 BlockValSet (com.linkedin.pinot.core.common.BlockValSet)1 TransformBlockValSet (com.linkedin.pinot.core.operator.docvalsets.TransformBlockValSet)1 TimeConversionTransform (com.linkedin.pinot.core.operator.transform.function.TimeConversionTransform)1 TransformFunction (com.linkedin.pinot.core.operator.transform.function.TransformFunction)1 Random (java.util.Random)1 Test (org.testng.annotations.Test)1