Search in sources :

Example 11 with IntExpression

use of org.apache.drill.common.expression.ValueExpressions.IntExpression in project drill by apache.

the class CompareFunctionsProcessor method visitRowKeyPrefixConvertExpression.

private Boolean visitRowKeyPrefixConvertExpression(ConvertExpression e, int prefixLength, LogicalExpression valueArg) {
    String encodingType = e.getEncodingType();
    rowKeyPrefixStartRow = HConstants.EMPTY_START_ROW;
    rowKeyPrefixStopRow = HConstants.EMPTY_START_ROW;
    rowKeyPrefixFilter = null;
    if ((encodingType.compareTo("UINT4_BE") == 0) || (encodingType.compareTo("UINT_BE") == 0)) {
        if (prefixLength != 4) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        int val;
        if (!(valueArg instanceof IntExpression)) {
            return false;
        }
        val = ((IntExpression) valueArg).getInt();
        // For TIME_EPOCH_BE/BIGINT_BE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case FunctionNames.EQ:
                rowKeyPrefixFilter = new PrefixFilter(ByteBuffer.allocate(4).putInt(val).array());
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val).array();
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case FunctionNames.GE:
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val).array();
                return true;
            case FunctionNames.GT:
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case FunctionNames.LE:
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case FunctionNames.LT:
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val).array();
                return true;
        }
        return false;
    }
    if ((encodingType.compareTo("TIMESTAMP_EPOCH_BE") == 0) || (encodingType.compareTo("TIME_EPOCH_BE") == 0) || (encodingType.compareTo("UINT8_BE") == 0)) {
        if (prefixLength != 8) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        long val;
        if (encodingType.compareTo("TIME_EPOCH_BE") == 0) {
            if (!(valueArg instanceof TimeExpression)) {
                return false;
            }
            val = ((TimeExpression) valueArg).getTime();
        } else if (encodingType.compareTo("UINT8_BE") == 0) {
            if (!(valueArg instanceof LongExpression)) {
                return false;
            }
            val = ((LongExpression) valueArg).getLong();
        } else if (encodingType.compareTo("TIMESTAMP_EPOCH_BE") == 0) {
            if (!(valueArg instanceof TimeStampExpression)) {
                return false;
            }
            val = ((TimeStampExpression) valueArg).getTimeStamp();
        } else {
            // Should not reach here.
            return false;
        }
        // For TIME_EPOCH_BE/BIGINT_BE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case FunctionNames.EQ:
                rowKeyPrefixFilter = new PrefixFilter(ByteBuffer.allocate(8).putLong(val).array());
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val).array();
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case FunctionNames.GE:
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
            case FunctionNames.GT:
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case FunctionNames.LE:
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case FunctionNames.LT:
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
        }
        return false;
    }
    if (encodingType.compareTo("DATE_EPOCH_BE") == 0) {
        if (!(valueArg instanceof DateExpression)) {
            return false;
        }
        if (prefixLength != 8) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        final long MILLISECONDS_IN_A_DAY = 1000 * 60 * 60 * 24;
        long dateToSet;
        // For DATE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case FunctionNames.EQ:
                long startDate = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(startDate).array();
                long stopDate = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(stopDate).array();
                return true;
            case FunctionNames.GE:
                dateToSet = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case FunctionNames.GT:
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case FunctionNames.LE:
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case FunctionNames.LT:
                dateToSet = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
        }
        return false;
    }
    return false;
}
Also used : DateExpression(org.apache.drill.common.expression.ValueExpressions.DateExpression) PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter) IntExpression(org.apache.drill.common.expression.ValueExpressions.IntExpression) TimeExpression(org.apache.drill.common.expression.ValueExpressions.TimeExpression) LongExpression(org.apache.drill.common.expression.ValueExpressions.LongExpression) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString) TimeStampExpression(org.apache.drill.common.expression.ValueExpressions.TimeStampExpression)

Example 12 with IntExpression

use of org.apache.drill.common.expression.ValueExpressions.IntExpression in project drill by apache.

the class FunctionGenerationHelper method getTypeComparisonFunction.

/**
 * Wraps the comparison function in an If-statement which compares the types first, evaluating the comaprison function only
 * if the types are equivialent
 *
 * @param comparisonFunction
 * @param args
 * @return
 */
private static LogicalExpression getTypeComparisonFunction(LogicalExpression comparisonFunction, HoldingContainer... args) {
    List<LogicalExpression> argExpressions = Lists.newArrayList();
    List<MajorType> argTypes = Lists.newArrayList();
    for (HoldingContainer c : args) {
        argTypes.add(c.getMajorType());
        argExpressions.add(new HoldingContainerExpression(c));
    }
    FunctionCall call = new FunctionCall("compareType", argExpressions, ExpressionPosition.UNKNOWN);
    List<LogicalExpression> newArgs = Lists.newArrayList();
    newArgs.add(call);
    newArgs.add(new IntExpression(0, ExpressionPosition.UNKNOWN));
    FunctionCall notEqual = new FunctionCall(FunctionNames.NE, newArgs, ExpressionPosition.UNKNOWN);
    IfExpression.IfCondition ifCondition = new IfCondition(notEqual, call);
    IfExpression ifExpression = IfExpression.newBuilder().setIfCondition(ifCondition).setElse(comparisonFunction).build();
    return ifExpression;
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) IfExpression(org.apache.drill.common.expression.IfExpression) HoldingContainer(org.apache.drill.exec.expr.ClassGenerator.HoldingContainer) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) IntExpression(org.apache.drill.common.expression.ValueExpressions.IntExpression) FunctionCall(org.apache.drill.common.expression.FunctionCall) IfCondition(org.apache.drill.common.expression.IfExpression.IfCondition) HoldingContainerExpression(org.apache.drill.exec.expr.HoldingContainerExpression) IfCondition(org.apache.drill.common.expression.IfExpression.IfCondition)

Aggregations

IntExpression (org.apache.drill.common.expression.ValueExpressions.IntExpression)12 DateExpression (org.apache.drill.common.expression.ValueExpressions.DateExpression)10 LongExpression (org.apache.drill.common.expression.ValueExpressions.LongExpression)10 QuotedString (org.apache.drill.common.expression.ValueExpressions.QuotedString)10 TimeExpression (org.apache.drill.common.expression.ValueExpressions.TimeExpression)10 FunctionCall (org.apache.drill.common.expression.FunctionCall)6 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)6 BooleanExpression (org.apache.drill.common.expression.ValueExpressions.BooleanExpression)6 DoubleExpression (org.apache.drill.common.expression.ValueExpressions.DoubleExpression)6 FloatExpression (org.apache.drill.common.expression.ValueExpressions.FloatExpression)6 TimeStampExpression (org.apache.drill.common.expression.ValueExpressions.TimeStampExpression)6 ByteBuf (io.netty.buffer.ByteBuf)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)4 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)4 PositionedByteRange (org.apache.hadoop.hbase.util.PositionedByteRange)4 SimplePositionedMutableByteRange (org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange)4 IfExpression (org.apache.drill.common.expression.IfExpression)2 IfCondition (org.apache.drill.common.expression.IfExpression.IfCondition)2 Decimal28Expression (org.apache.drill.common.expression.ValueExpressions.Decimal28Expression)2 Decimal38Expression (org.apache.drill.common.expression.ValueExpressions.Decimal38Expression)2