Search in sources :

Example 1 with IntExpression

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

the class CompareFunctionsProcessor method visitConvertExpression.

@Override
public Boolean visitConvertExpression(ConvertExpression e, LogicalExpression valueArg) throws RuntimeException {
    if (e.getConvertFunction() == ConvertExpression.CONVERT_FROM) {
        String encodingType = e.getEncodingType();
        int prefixLength = 0;
        // CONVERT_FROM(BYTE_SUBSTR(row_key, 1, 8), 'DATE_EPOCH_BE') < DATE '2015-06-17'
        if (e.getInput() instanceof FunctionCall) {
            // We can prune scan range only for big-endian encoded data
            if (encodingType.endsWith("_BE") == false) {
                return false;
            }
            FunctionCall call = (FunctionCall) e.getInput();
            String functionName = call.getName();
            if (!functionName.equalsIgnoreCase("byte_substr")) {
                return false;
            }
            LogicalExpression nameArg = call.args.get(0);
            LogicalExpression valueArg1 = call.args.size() >= 2 ? call.args.get(1) : null;
            LogicalExpression valueArg2 = call.args.size() >= 3 ? call.args.get(2) : null;
            if (((nameArg instanceof SchemaPath) == false) || (valueArg1 == null) || ((valueArg1 instanceof IntExpression) == false) || (valueArg2 == null) || ((valueArg2 instanceof IntExpression) == false)) {
                return false;
            }
            boolean isRowKey = ((SchemaPath) nameArg).getAsUnescapedPath().equals(DrillHBaseConstants.ROW_KEY);
            int offset = ((IntExpression) valueArg1).getInt();
            if (!isRowKey || (offset != 1)) {
                return false;
            }
            this.path = (SchemaPath) nameArg;
            prefixLength = ((IntExpression) valueArg2).getInt();
            this.isRowKeyPrefixComparison = true;
            return visitRowKeyPrefixConvertExpression(e, prefixLength, valueArg);
        }
        if (e.getInput() instanceof SchemaPath) {
            ByteBuf bb = null;
            switch(encodingType) {
                case "INT_BE":
                case "INT":
                case "UINT_BE":
                case "UINT":
                case "UINT4_BE":
                case "UINT4":
                    if (valueArg instanceof IntExpression && (isEqualityFn || encodingType.startsWith("U"))) {
                        bb = newByteBuf(4, encodingType.endsWith("_BE"));
                        bb.writeInt(((IntExpression) valueArg).getInt());
                    }
                    break;
                case "BIGINT_BE":
                case "BIGINT":
                case "UINT8_BE":
                case "UINT8":
                    if (valueArg instanceof LongExpression && (isEqualityFn || encodingType.startsWith("U"))) {
                        bb = newByteBuf(8, encodingType.endsWith("_BE"));
                        bb.writeLong(((LongExpression) valueArg).getLong());
                    }
                    break;
                case "FLOAT":
                    if (valueArg instanceof FloatExpression && isEqualityFn) {
                        bb = newByteBuf(4, true);
                        bb.writeFloat(((FloatExpression) valueArg).getFloat());
                    }
                    break;
                case "DOUBLE":
                    if (valueArg instanceof DoubleExpression && isEqualityFn) {
                        bb = newByteBuf(8, true);
                        bb.writeDouble(((DoubleExpression) valueArg).getDouble());
                    }
                    break;
                case "TIME_EPOCH":
                case "TIME_EPOCH_BE":
                    if (valueArg instanceof TimeExpression) {
                        bb = newByteBuf(8, encodingType.endsWith("_BE"));
                        bb.writeLong(((TimeExpression) valueArg).getTime());
                    }
                    break;
                case "DATE_EPOCH":
                case "DATE_EPOCH_BE":
                    if (valueArg instanceof DateExpression) {
                        bb = newByteBuf(8, encodingType.endsWith("_BE"));
                        bb.writeLong(((DateExpression) valueArg).getDate());
                    }
                    break;
                case "BOOLEAN_BYTE":
                    if (valueArg instanceof BooleanExpression) {
                        bb = newByteBuf(1, false);
                        bb.writeByte(((BooleanExpression) valueArg).getBoolean() ? 1 : 0);
                    }
                    break;
                case "DOUBLE_OB":
                case "DOUBLE_OBD":
                    if (valueArg instanceof DoubleExpression) {
                        bb = newByteBuf(9, true);
                        PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 9);
                        if (encodingType.endsWith("_OBD")) {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat64(br, ((DoubleExpression) valueArg).getDouble(), Order.DESCENDING);
                            this.sortOrderAscending = false;
                        } else {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat64(br, ((DoubleExpression) valueArg).getDouble(), Order.ASCENDING);
                        }
                    }
                    break;
                case "FLOAT_OB":
                case "FLOAT_OBD":
                    if (valueArg instanceof FloatExpression) {
                        bb = newByteBuf(5, true);
                        PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 5);
                        if (encodingType.endsWith("_OBD")) {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat32(br, ((FloatExpression) valueArg).getFloat(), Order.DESCENDING);
                            this.sortOrderAscending = false;
                        } else {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat32(br, ((FloatExpression) valueArg).getFloat(), Order.ASCENDING);
                        }
                    }
                    break;
                case "BIGINT_OB":
                case "BIGINT_OBD":
                    if (valueArg instanceof LongExpression) {
                        bb = newByteBuf(9, true);
                        PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 9);
                        if (encodingType.endsWith("_OBD")) {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeInt64(br, ((LongExpression) valueArg).getLong(), Order.DESCENDING);
                            this.sortOrderAscending = false;
                        } else {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeInt64(br, ((LongExpression) valueArg).getLong(), Order.ASCENDING);
                        }
                    }
                    break;
                case "INT_OB":
                case "INT_OBD":
                    if (valueArg instanceof IntExpression) {
                        bb = newByteBuf(5, true);
                        PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 5);
                        if (encodingType.endsWith("_OBD")) {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeInt32(br, ((IntExpression) valueArg).getInt(), Order.DESCENDING);
                            this.sortOrderAscending = false;
                        } else {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeInt32(br, ((IntExpression) valueArg).getInt(), Order.ASCENDING);
                        }
                    }
                    break;
                case "UTF8_OB":
                case "UTF8_OBD":
                    if (valueArg instanceof QuotedString) {
                        int stringLen = ((QuotedString) valueArg).value.getBytes(Charsets.UTF_8).length;
                        bb = newByteBuf(stringLen + 2, true);
                        PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, stringLen + 2);
                        if (encodingType.endsWith("_OBD")) {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeString(br, ((QuotedString) valueArg).value, Order.DESCENDING);
                            this.sortOrderAscending = false;
                        } else {
                            org.apache.hadoop.hbase.util.OrderedBytes.encodeString(br, ((QuotedString) valueArg).value, Order.ASCENDING);
                        }
                    }
                    break;
                case "UTF8":
                    // let visitSchemaPath() handle this.
                    return e.getInput().accept(this, valueArg);
            }
            if (bb != null) {
                this.value = bb.array();
                this.path = (SchemaPath) e.getInput();
                return true;
            }
        }
    }
    return false;
}
Also used : IntExpression(org.apache.drill.common.expression.ValueExpressions.IntExpression) DoubleExpression(org.apache.drill.common.expression.ValueExpressions.DoubleExpression) FloatExpression(org.apache.drill.common.expression.ValueExpressions.FloatExpression) TimeExpression(org.apache.drill.common.expression.ValueExpressions.TimeExpression) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange) ByteBuf(io.netty.buffer.ByteBuf) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) BooleanExpression(org.apache.drill.common.expression.ValueExpressions.BooleanExpression) DateExpression(org.apache.drill.common.expression.ValueExpressions.DateExpression) SchemaPath(org.apache.drill.common.expression.SchemaPath) SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) LongExpression(org.apache.drill.common.expression.ValueExpressions.LongExpression) FunctionCall(org.apache.drill.common.expression.FunctionCall)

Example 2 with IntExpression

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

the class CompareFunctionsProcessor method visitSchemaPath.

@Override
public Boolean visitSchemaPath(SchemaPath path, LogicalExpression valueArg) throws RuntimeException {
    // If valueArg is null, this might be a IS NULL/IS NOT NULL type of query
    if (valueArg == null) {
        this.path = path;
        return true;
    }
    if (valueArg instanceof QuotedString) {
        this.value = KeyValueBuilder.initFrom(((QuotedString) valueArg).value);
        this.path = path;
        return true;
    }
    if (valueArg instanceof IntExpression) {
        this.value = KeyValueBuilder.initFrom(((IntExpression) valueArg).getInt());
        this.path = path;
        return true;
    }
    if (valueArg instanceof FloatExpression) {
        this.value = KeyValueBuilder.initFrom(((FloatExpression) valueArg).getFloat());
        this.path = path;
        return true;
    }
    if (valueArg instanceof BooleanExpression) {
        this.value = KeyValueBuilder.initFrom(((BooleanExpression) valueArg).getBoolean());
        this.path = path;
        return true;
    }
    if (valueArg instanceof Decimal28Expression) {
        this.value = KeyValueBuilder.initFrom(((Decimal28Expression) valueArg).getBigDecimal());
        this.path = path;
        return true;
    }
    if (valueArg instanceof Decimal38Expression) {
        this.value = KeyValueBuilder.initFrom(((Decimal38Expression) valueArg).getBigDecimal());
        this.path = path;
        return true;
    }
    if (valueArg instanceof DoubleExpression) {
        this.value = KeyValueBuilder.initFrom(((DoubleExpression) valueArg).getDouble());
        this.path = path;
        return true;
    }
    if (valueArg instanceof LongExpression) {
        this.value = KeyValueBuilder.initFrom(((LongExpression) valueArg).getLong());
        this.path = path;
        return true;
    }
    if (valueArg instanceof DateExpression) {
        long d = ((DateExpression) valueArg).getDate();
        final long MILLISECONDS_IN_A_DAY = (long) 1000 * 60 * 60 * 24;
        int daysSinceEpoch = (int) (d / MILLISECONDS_IN_A_DAY);
        this.value = KeyValueBuilder.initFrom(ODate.fromDaysSinceEpoch(daysSinceEpoch));
        this.path = path;
        return true;
    }
    if (valueArg instanceof TimeExpression) {
        int t = ((TimeExpression) valueArg).getTime();
        LocalTime lT = LocalTime.fromMillisOfDay(t);
        this.value = KeyValueBuilder.initFrom(new OTime(lT.getHourOfDay(), lT.getMinuteOfHour(), lT.getSecondOfMinute(), lT.getMillisOfSecond()));
        this.path = path;
        return true;
    }
    if (valueArg instanceof TimeStampExpression) {
    // disable pushdown of TimeStampExpression type until bug 22824 is fixed.
    // 
    // this.value = KeyValueBuilder.initFrom(new OTimestamp(((TimeStampExpression)valueArg).getTimeStamp()));
    // this.path = path;
    // return true;
    }
    return false;
}
Also used : LocalTime(org.joda.time.LocalTime) IntExpression(org.apache.drill.common.expression.ValueExpressions.IntExpression) Decimal38Expression(org.apache.drill.common.expression.ValueExpressions.Decimal38Expression) DoubleExpression(org.apache.drill.common.expression.ValueExpressions.DoubleExpression) FloatExpression(org.apache.drill.common.expression.ValueExpressions.FloatExpression) TimeExpression(org.apache.drill.common.expression.ValueExpressions.TimeExpression) TimeStampExpression(org.apache.drill.common.expression.ValueExpressions.TimeStampExpression) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString) BooleanExpression(org.apache.drill.common.expression.ValueExpressions.BooleanExpression) DateExpression(org.apache.drill.common.expression.ValueExpressions.DateExpression) Decimal28Expression(org.apache.drill.common.expression.ValueExpressions.Decimal28Expression) LongExpression(org.apache.drill.common.expression.ValueExpressions.LongExpression) OTime(org.ojai.types.OTime)

Example 3 with IntExpression

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

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 "equal":
                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 "greater_than_or_equal_to":
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val).array();
                return true;
            case "greater_than":
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "less_than_or_equal_to":
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "less_than":
                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 "equal":
                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 "greater_than_or_equal_to":
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
            case "greater_than":
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "less_than_or_equal_to":
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "less_than":
                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 "equal":
                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 "greater_than_or_equal_to":
                dateToSet = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "greater_than":
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "less_than_or_equal_to":
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "less_than":
                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 4 with IntExpression

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

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("not_equal", 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)

Example 5 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) == false) {
            return false;
        }
        val = ((IntExpression) valueArg).getInt();
        // For TIME_EPOCH_BE/BIGINT_BE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case "equal":
                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 "greater_than_or_equal_to":
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val).array();
                return true;
            case "greater_than":
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "less_than_or_equal_to":
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "less_than":
                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) == false) {
                return false;
            }
            val = ((TimeExpression) valueArg).getTime();
        } else if (encodingType.compareTo("UINT8_BE") == 0) {
            if ((valueArg instanceof LongExpression) == false) {
                return false;
            }
            val = ((LongExpression) valueArg).getLong();
        } else if (encodingType.compareTo("TIMESTAMP_EPOCH_BE") == 0) {
            if ((valueArg instanceof TimeStampExpression) == false) {
                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 "equal":
                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 "greater_than_or_equal_to":
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
            case "greater_than":
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "less_than_or_equal_to":
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "less_than":
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
        }
        return false;
    }
    if (encodingType.compareTo("DATE_EPOCH_BE") == 0) {
        if ((valueArg instanceof DateExpression) == false) {
            return false;
        }
        if (prefixLength != 8) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        final long MILLISECONDS_IN_A_DAY = (long) 1000 * 60 * 60 * 24;
        long dateToSet;
        // For DATE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case "equal":
                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 "greater_than_or_equal_to":
                dateToSet = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "greater_than":
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "less_than_or_equal_to":
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "less_than":
                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)

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