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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations