Search in sources :

Example 1 with DrillSimpleFuncHolder

use of org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder in project drill by apache.

the class ParquetFilterBuilder method visitFunctionHolderExpression.

@Override
public LogicalExpression visitFunctionHolderExpression(FunctionHolderExpression funcHolderExpr, Set<LogicalExpression> value) throws RuntimeException {
    FuncHolder holder = funcHolderExpr.getHolder();
    if (!(holder instanceof DrillSimpleFuncHolder)) {
        return null;
    }
    if (value.contains(funcHolderExpr)) {
        ValueHolder result;
        try {
            result = InterpreterEvaluator.evaluateConstantExpr(udfUtilities, funcHolderExpr);
        } catch (Exception e) {
            logger.warn("Error in evaluating function of {}", funcHolderExpr.getName());
            return null;
        }
        logger.debug("Reduce a constant function expression into a value expression");
        return getValueExpressionFromConst(result, funcHolderExpr.getMajorType().getMinorType());
    }
    final String funcName = ((DrillSimpleFuncHolder) holder).getRegisteredNames()[0];
    if (isCompareFunction(funcName)) {
        return handleCompareFunction(funcHolderExpr, value);
    }
    if (CastFunctions.isCastFunction(funcName)) {
        List<LogicalExpression> newArgs = new ArrayList();
        for (LogicalExpression arg : funcHolderExpr.args) {
            final LogicalExpression newArg = arg.accept(this, value);
            if (newArg == null) {
                return null;
            }
            newArgs.add(newArg);
        }
        return funcHolderExpr.copy(newArgs);
    } else {
        return null;
    }
}
Also used : DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder) FuncHolder(org.apache.drill.common.expression.fn.FuncHolder) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ArrayList(java.util.ArrayList) ValueHolder(org.apache.drill.exec.expr.holders.ValueHolder) DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder)

Example 2 with DrillSimpleFuncHolder

use of org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder in project drill by apache.

the class RangeExprEvaluator method evalCastFunc.

private Statistics evalCastFunc(FunctionHolderExpression holderExpr, Statistics input) {
    try {
        DrillSimpleFuncHolder funcHolder = (DrillSimpleFuncHolder) holderExpr.getHolder();
        DrillSimpleFunc interpreter = funcHolder.createInterpreter();
        final ValueHolder minHolder, maxHolder;
        TypeProtos.MinorType srcType = holderExpr.args.get(0).getMajorType().getMinorType();
        TypeProtos.MinorType destType = holderExpr.getMajorType().getMinorType();
        if (srcType.equals(destType)) {
            // same type cast ==> NoOp.
            return input;
        } else if (!CAST_FUNC.containsKey(srcType) || !CAST_FUNC.get(srcType).contains(destType)) {
            // cast func between srcType and destType is NOT allowed.
            return null;
        }
        switch(srcType) {
            case INT:
                minHolder = ValueHolderHelper.getIntHolder(((IntStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getIntHolder(((IntStatistics) input).getMax());
                break;
            case BIGINT:
                minHolder = ValueHolderHelper.getBigIntHolder(((LongStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getBigIntHolder(((LongStatistics) input).getMax());
                break;
            case FLOAT4:
                minHolder = ValueHolderHelper.getFloat4Holder(((FloatStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getFloat4Holder(((FloatStatistics) input).getMax());
                break;
            case FLOAT8:
                minHolder = ValueHolderHelper.getFloat8Holder(((DoubleStatistics) input).getMin());
                maxHolder = ValueHolderHelper.getFloat8Holder(((DoubleStatistics) input).getMax());
                break;
            default:
                return null;
        }
        final ValueHolder[] args1 = { minHolder };
        final ValueHolder[] args2 = { maxHolder };
        final ValueHolder minFuncHolder = InterpreterEvaluator.evaluateFunction(interpreter, args1, holderExpr.getName());
        final ValueHolder maxFuncHolder = InterpreterEvaluator.evaluateFunction(interpreter, args2, holderExpr.getName());
        switch(destType) {
            //TODO : need handle # of nulls.
            case INT:
                return getStatistics(((IntHolder) minFuncHolder).value, ((IntHolder) maxFuncHolder).value);
            case BIGINT:
                return getStatistics(((BigIntHolder) minFuncHolder).value, ((BigIntHolder) maxFuncHolder).value);
            case FLOAT4:
                return getStatistics(((Float4Holder) minFuncHolder).value, ((Float4Holder) maxFuncHolder).value);
            case FLOAT8:
                return getStatistics(((Float8Holder) minFuncHolder).value, ((Float8Holder) maxFuncHolder).value);
            default:
                return null;
        }
    } catch (Exception e) {
        throw new DrillRuntimeException("Error in evaluating function of " + holderExpr.getName());
    }
}
Also used : LongStatistics(org.apache.parquet.column.statistics.LongStatistics) FloatStatistics(org.apache.parquet.column.statistics.FloatStatistics) IntStatistics(org.apache.parquet.column.statistics.IntStatistics) DoubleStatistics(org.apache.parquet.column.statistics.DoubleStatistics) ValueHolder(org.apache.drill.exec.expr.holders.ValueHolder) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) TypeProtos(org.apache.drill.common.types.TypeProtos) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder) DrillSimpleFunc(org.apache.drill.exec.expr.DrillSimpleFunc)

Example 3 with DrillSimpleFuncHolder

use of org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder in project drill by apache.

the class RangeExprEvaluator method visitFunctionHolderExpression.

@Override
public Statistics visitFunctionHolderExpression(FunctionHolderExpression holderExpr, Void value) throws RuntimeException {
    FuncHolder funcHolder = holderExpr.getHolder();
    if (!(funcHolder instanceof DrillSimpleFuncHolder)) {
        // Only Drill function is allowed.
        return null;
    }
    final String funcName = ((DrillSimpleFuncHolder) funcHolder).getRegisteredNames()[0];
    if (CastFunctions.isCastFunction(funcName)) {
        Statistics stat = holderExpr.args.get(0).accept(this, null);
        if (stat != null && !stat.isEmpty()) {
            return evalCastFunc(holderExpr, stat);
        }
    }
    return null;
}
Also used : DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder) FuncHolder(org.apache.drill.common.expression.fn.FuncHolder) IntStatistics(org.apache.parquet.column.statistics.IntStatistics) ColumnStatistics(org.apache.drill.exec.store.parquet.stat.ColumnStatistics) FloatStatistics(org.apache.parquet.column.statistics.FloatStatistics) Statistics(org.apache.parquet.column.statistics.Statistics) DoubleStatistics(org.apache.parquet.column.statistics.DoubleStatistics) LongStatistics(org.apache.parquet.column.statistics.LongStatistics) DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder)

Aggregations

DrillSimpleFuncHolder (org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder)3 FuncHolder (org.apache.drill.common.expression.fn.FuncHolder)2 ValueHolder (org.apache.drill.exec.expr.holders.ValueHolder)2 DoubleStatistics (org.apache.parquet.column.statistics.DoubleStatistics)2 FloatStatistics (org.apache.parquet.column.statistics.FloatStatistics)2 IntStatistics (org.apache.parquet.column.statistics.IntStatistics)2 LongStatistics (org.apache.parquet.column.statistics.LongStatistics)2 ArrayList (java.util.ArrayList)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)1 TypeProtos (org.apache.drill.common.types.TypeProtos)1 DrillSimpleFunc (org.apache.drill.exec.expr.DrillSimpleFunc)1 ColumnStatistics (org.apache.drill.exec.store.parquet.stat.ColumnStatistics)1 Statistics (org.apache.parquet.column.statistics.Statistics)1