Search in sources :

Example 1 with LiteralExpression

use of org.apache.phoenix.expression.LiteralExpression in project phoenix by apache.

the class ExpressionCompiler method visitLeave.

private Expression visitLeave(ArithmeticParseNode node, List<Expression> children, ArithmeticExpressionBinder binder, ArithmeticExpressionFactory factory) throws SQLException {
    boolean isNull = false;
    for (Expression child : children) {
        boolean isChildLiteral = (child instanceof LiteralExpression);
        isNull |= isChildLiteral && ((LiteralExpression) child).getValue() == null;
    }
    Expression expression = factory.create(node, children);
    for (int i = 0; i < node.getChildren().size(); i++) {
        ParseNode childNode = node.getChildren().get(i);
        if (childNode instanceof BindParseNode) {
            context.getBindManager().addParamMetaData((BindParseNode) childNode, binder == null ? expression : binder.getBindMetaData(i, children, expression));
        }
    }
    ImmutableBytesWritable ptr = context.getTempPtr();
    // If all children are literals, just evaluate now
    if (ExpressionUtil.isConstant(expression)) {
        return ExpressionUtil.getConstantExpression(expression, ptr);
    } else if (isNull) {
        return LiteralExpression.newConstant(null, expression.getDataType(), expression.getDeterminism());
    }
    // Otherwise create and return the expression
    return wrapGroupByExpression(expression);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) DecimalAddExpression(org.apache.phoenix.expression.DecimalAddExpression) TimestampSubtractExpression(org.apache.phoenix.expression.TimestampSubtractExpression) ArrayConstructorExpression(org.apache.phoenix.expression.ArrayConstructorExpression) Expression(org.apache.phoenix.expression.Expression) LikeExpression(org.apache.phoenix.expression.LikeExpression) ByteBasedLikeExpression(org.apache.phoenix.expression.ByteBasedLikeExpression) DoubleSubtractExpression(org.apache.phoenix.expression.DoubleSubtractExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) InListExpression(org.apache.phoenix.expression.InListExpression) DateSubtractExpression(org.apache.phoenix.expression.DateSubtractExpression) ArrayElemRefExpression(org.apache.phoenix.expression.function.ArrayElemRefExpression) CaseExpression(org.apache.phoenix.expression.CaseExpression) DoubleDivideExpression(org.apache.phoenix.expression.DoubleDivideExpression) NotExpression(org.apache.phoenix.expression.NotExpression) DoubleAddExpression(org.apache.phoenix.expression.DoubleAddExpression) DecimalDivideExpression(org.apache.phoenix.expression.DecimalDivideExpression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) RowValueConstructorExpression(org.apache.phoenix.expression.RowValueConstructorExpression) RoundTimestampExpression(org.apache.phoenix.expression.function.RoundTimestampExpression) StringConcatExpression(org.apache.phoenix.expression.StringConcatExpression) ComparisonExpression(org.apache.phoenix.expression.ComparisonExpression) TimestampAddExpression(org.apache.phoenix.expression.TimestampAddExpression) CoerceExpression(org.apache.phoenix.expression.CoerceExpression) StringBasedLikeExpression(org.apache.phoenix.expression.StringBasedLikeExpression) ArrayAnyComparisonExpression(org.apache.phoenix.expression.function.ArrayAnyComparisonExpression) DecimalSubtractExpression(org.apache.phoenix.expression.DecimalSubtractExpression) ModulusExpression(org.apache.phoenix.expression.ModulusExpression) DoubleMultiplyExpression(org.apache.phoenix.expression.DoubleMultiplyExpression) DecimalMultiplyExpression(org.apache.phoenix.expression.DecimalMultiplyExpression) DateAddExpression(org.apache.phoenix.expression.DateAddExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) LongAddExpression(org.apache.phoenix.expression.LongAddExpression) LongSubtractExpression(org.apache.phoenix.expression.LongSubtractExpression) IsNullExpression(org.apache.phoenix.expression.IsNullExpression) AndExpression(org.apache.phoenix.expression.AndExpression) LongMultiplyExpression(org.apache.phoenix.expression.LongMultiplyExpression) ArrayAllComparisonExpression(org.apache.phoenix.expression.function.ArrayAllComparisonExpression) OrExpression(org.apache.phoenix.expression.OrExpression) LongDivideExpression(org.apache.phoenix.expression.LongDivideExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) BindParseNode(org.apache.phoenix.parse.BindParseNode) ModulusParseNode(org.apache.phoenix.parse.ModulusParseNode) LikeParseNode(org.apache.phoenix.parse.LikeParseNode) UDFParseNode(org.apache.phoenix.parse.UDFParseNode) ComparisonParseNode(org.apache.phoenix.parse.ComparisonParseNode) SequenceValueParseNode(org.apache.phoenix.parse.SequenceValueParseNode) InListParseNode(org.apache.phoenix.parse.InListParseNode) AndParseNode(org.apache.phoenix.parse.AndParseNode) ExistsParseNode(org.apache.phoenix.parse.ExistsParseNode) SubtractParseNode(org.apache.phoenix.parse.SubtractParseNode) NotParseNode(org.apache.phoenix.parse.NotParseNode) DivideParseNode(org.apache.phoenix.parse.DivideParseNode) StringConcatParseNode(org.apache.phoenix.parse.StringConcatParseNode) OrParseNode(org.apache.phoenix.parse.OrParseNode) ParseNode(org.apache.phoenix.parse.ParseNode) LiteralParseNode(org.apache.phoenix.parse.LiteralParseNode) FunctionParseNode(org.apache.phoenix.parse.FunctionParseNode) RowValueConstructorParseNode(org.apache.phoenix.parse.RowValueConstructorParseNode) MultiplyParseNode(org.apache.phoenix.parse.MultiplyParseNode) ColumnParseNode(org.apache.phoenix.parse.ColumnParseNode) CaseParseNode(org.apache.phoenix.parse.CaseParseNode) CastParseNode(org.apache.phoenix.parse.CastParseNode) AddParseNode(org.apache.phoenix.parse.AddParseNode) SubqueryParseNode(org.apache.phoenix.parse.SubqueryParseNode) ArithmeticParseNode(org.apache.phoenix.parse.ArithmeticParseNode) IsNullParseNode(org.apache.phoenix.parse.IsNullParseNode) BindParseNode(org.apache.phoenix.parse.BindParseNode)

Example 2 with LiteralExpression

use of org.apache.phoenix.expression.LiteralExpression in project phoenix by apache.

the class CeilTimestampExpression method create.

public static Expression create(List<Expression> children) throws SQLException {
    Expression firstChild = children.get(0);
    PDataType firstChildDataType = firstChild.getDataType();
    String timeUnit = (String) ((LiteralExpression) children.get(1)).getValue();
    if (TimeUnit.MILLISECOND.toString().equalsIgnoreCase(timeUnit)) {
        return new CeilTimestampExpression(children);
    }
    // Coerce TIMESTAMP to DATE, as the nanos has no affect
    List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size());
    newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE));
    newChildren.addAll(children.subList(1, children.size()));
    return CeilDateExpression.create(newChildren);
}
Also used : PDataType(org.apache.phoenix.schema.types.PDataType) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) Expression(org.apache.phoenix.expression.Expression) CoerceExpression(org.apache.phoenix.expression.CoerceExpression)

Example 3 with LiteralExpression

use of org.apache.phoenix.expression.LiteralExpression in project phoenix by apache.

the class RoundTimestampExpression method create.

public static Expression create(List<Expression> children) throws SQLException {
    Expression firstChild = children.get(0);
    PDataType firstChildDataType = firstChild.getDataType();
    String timeUnit = (String) ((LiteralExpression) children.get(1)).getValue();
    LiteralExpression multiplierExpr = (LiteralExpression) children.get(2);
    /*
         * When rounding off timestamp to milliseconds, nanos play a part only when the multiplier value
         * is equal to 1. This is because for cases when multiplier value is greater than 1, number of nanos/multiplier
         * will always be less than half the nanos in a millisecond. 
         */
    if ((timeUnit == null || TimeUnit.MILLISECOND.toString().equalsIgnoreCase(timeUnit)) && ((Number) multiplierExpr.getValue()).intValue() == 1) {
        return new RoundTimestampExpression(children);
    }
    // Coerce TIMESTAMP to DATE, as the nanos has no affect
    List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size());
    newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE));
    newChildren.addAll(children.subList(1, children.size()));
    return RoundDateExpression.create(newChildren);
}
Also used : PDataType(org.apache.phoenix.schema.types.PDataType) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) Expression(org.apache.phoenix.expression.Expression) CoerceExpression(org.apache.phoenix.expression.CoerceExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression)

Example 4 with LiteralExpression

use of org.apache.phoenix.expression.LiteralExpression in project phoenix by apache.

the class NthValueFunction method newServerAggregator.

@Override
public Aggregator newServerAggregator(Configuration conf) {
    FirstLastValueServerAggregator aggregator = new FirstLastValueServerAggregator();
    offset = ((Number) ((LiteralExpression) children.get(3)).getValue()).intValue();
    boolean order = (Boolean) ((LiteralExpression) children.get(1)).getValue();
    aggregator.init(children, order, offset);
    return aggregator;
}
Also used : LiteralExpression(org.apache.phoenix.expression.LiteralExpression) FirstLastValueServerAggregator(org.apache.phoenix.expression.aggregator.FirstLastValueServerAggregator) PBoolean(org.apache.phoenix.schema.types.PBoolean)

Example 5 with LiteralExpression

use of org.apache.phoenix.expression.LiteralExpression in project phoenix by apache.

the class SubstrFunction method preservesOrder.

@Override
public OrderPreserving preservesOrder() {
    if (isOffsetConstant) {
        LiteralExpression literal = (LiteralExpression) getOffsetExpression();
        Number offsetNumber = (Number) literal.getValue();
        if (offsetNumber != null) {
            int offset = offsetNumber.intValue();
            if ((offset == 0 || offset == 1) && (!hasLengthExpression || isLengthConstant)) {
                return OrderPreserving.YES_IF_LAST;
            }
        }
    }
    return OrderPreserving.NO;
}
Also used : LiteralExpression(org.apache.phoenix.expression.LiteralExpression)

Aggregations

LiteralExpression (org.apache.phoenix.expression.LiteralExpression)23 Expression (org.apache.phoenix.expression.Expression)11 PDataType (org.apache.phoenix.schema.types.PDataType)9 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)8 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)6 ArrayList (java.util.ArrayList)5 LiteralParseNode (org.apache.phoenix.parse.LiteralParseNode)5 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)4 ParseNode (org.apache.phoenix.parse.ParseNode)4 List (java.util.List)3 Cell (org.apache.hadoop.hbase.Cell)3 Pair (org.apache.hadoop.hbase.util.Pair)3 SQLExceptionInfo (org.apache.phoenix.exception.SQLExceptionInfo)3 ResultIterator (org.apache.phoenix.iterate.ResultIterator)3 SQLException (java.sql.SQLException)2 Scan (org.apache.hadoop.hbase.client.Scan)2 AndExpression (org.apache.phoenix.expression.AndExpression)2 ArrayConstructorExpression (org.apache.phoenix.expression.ArrayConstructorExpression)2 ByteBasedLikeExpression (org.apache.phoenix.expression.ByteBasedLikeExpression)2 CaseExpression (org.apache.phoenix.expression.CaseExpression)2