Search in sources :

Example 1 with FuncHolder

use of org.apache.drill.common.expression.fn.FuncHolder 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 FuncHolder

use of org.apache.drill.common.expression.fn.FuncHolder in project drill by axbaretto.

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) BooleanStatistics(org.apache.parquet.column.statistics.BooleanStatistics) 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)

Example 3 with FuncHolder

use of org.apache.drill.common.expression.fn.FuncHolder in project drill by axbaretto.

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 (isIsFunction(funcName)) {
        return handleIsFunction(funcHolderExpr, value);
    }
    if (CastFunctions.isCastFunction(funcName)) {
        List<LogicalExpression> newArgs = generateNewExpressions(funcHolderExpr.args, value);
        if (newArgs == null) {
            return null;
        }
        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) ValueHolder(org.apache.drill.exec.expr.holders.ValueHolder) DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder)

Example 4 with FuncHolder

use of org.apache.drill.common.expression.fn.FuncHolder in project drill by apache.

the class StatisticsProvider method visitFunctionHolderExpression.

@Override
@SuppressWarnings("unchecked")
public ColumnStatistics<?> visitFunctionHolderExpression(FunctionHolderExpression holderExpr, Void value) {
    FuncHolder funcHolder = holderExpr.getHolder();
    if (!(funcHolder instanceof DrillSimpleFuncHolder)) {
        // Only Drill function is allowed.
        return null;
    }
    String funcName = ((DrillSimpleFuncHolder) funcHolder).getRegisteredNames()[0];
    if (FunctionReplacementUtils.isCastFunction(funcName)) {
        ColumnStatistics<T> stat = (ColumnStatistics<T>) holderExpr.args.get(0).accept(this, null);
        if (!IsPredicate.isNullOrEmpty(stat)) {
            return evalCastFunc(holderExpr, stat);
        }
    }
    return null;
}
Also used : ColumnStatistics(org.apache.drill.metastore.statistics.ColumnStatistics) DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder) FuncHolder(org.apache.drill.common.expression.fn.FuncHolder) DrillSimpleFuncHolder(org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder)

Example 5 with FuncHolder

use of org.apache.drill.common.expression.fn.FuncHolder 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

FuncHolder (org.apache.drill.common.expression.fn.FuncHolder)6 DrillSimpleFuncHolder (org.apache.drill.exec.expr.fn.DrillSimpleFuncHolder)6 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)3 ValueHolder (org.apache.drill.exec.expr.holders.ValueHolder)3 ColumnStatistics (org.apache.drill.exec.store.parquet.stat.ColumnStatistics)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 Statistics (org.apache.parquet.column.statistics.Statistics)2 ArrayList (java.util.ArrayList)1 ColumnStatistics (org.apache.drill.metastore.statistics.ColumnStatistics)1 BooleanStatistics (org.apache.parquet.column.statistics.BooleanStatistics)1