15 package com.cloudera.impala.analysis;
17 import java.math.BigDecimal;
18 import java.math.BigInteger;
26 import com.cloudera.impala.thrift.TColumnValue;
27 import com.cloudera.impala.thrift.TExprNode;
28 import com.cloudera.impala.thrift.TQueryCtx;
29 import com.google.common.base.Preconditions;
52 Preconditions.checkArgument(type.isValid());
54 switch (type.getPrimitiveType()) {
80 "DATE/DATETIME/TIMESTAMP literals not supported: " + value);
82 Preconditions.checkState(
false,
83 String.format(
"Literals of type '%s' not supported.", type.toSql()));
97 switch (exprNode.node_type) {
99 result = LiteralExpr.create(
100 Double.toString(exprNode.float_literal.value), colType);
102 case DECIMAL_LITERAL:
103 byte[] bytes = exprNode.decimal_literal.getValue();
104 BigDecimal val =
new BigDecimal(
new BigInteger(bytes));
107 val = val.movePointLeft(decimalType.decimalScale());
111 result = LiteralExpr.create(
112 Long.toString(exprNode.int_literal.value), colType);
115 result = LiteralExpr.create(exprNode.string_literal.value, colType);
118 result = LiteralExpr.create(
119 Boolean.toString(exprNode.bool_literal.value), colType);
122 return NullLiteral.create(colType);
124 throw new UnsupportedOperationException(
"Unsupported partition key type: " +
127 Preconditions.checkNotNull(result);
128 result.analyze(null);
130 }
catch (Exception e) {
131 throw new IllegalStateException(
"Error creating LiteralExpr: ", e);
144 throw new NotImplementedException(
"swapSign() only implemented for numeric" +
155 Preconditions.checkState(constExpr.isConstant());
156 Preconditions.checkState(constExpr.getType().isValid());
157 if (constExpr instanceof
LiteralExpr)
return (LiteralExpr) constExpr;
159 TColumnValue val = null;
161 val = FeSupport.EvalConstExpr(constExpr, queryCtx);
164 constExpr.toSql()), e);
167 LiteralExpr result = null;
168 switch (constExpr.getType().getPrimitiveType()) {
173 if (val.isBool_val()) result =
new BoolLiteral(val.bool_val);
176 if (val.isSetByte_val()) {
181 if (val.isSetShort_val()) {
186 if (val.isSetInt_val()) {
191 if (val.isSetLong_val()) {
197 if (val.isSetDouble_val()) {
199 new NumericLiteral(
new BigDecimal(val.double_val), constExpr.getType());
203 if (val.isSetString_val()) {
205 new NumericLiteral(
new BigDecimal(val.string_val), constExpr.getType());
211 if (val.isSetString_val()) result =
new StringLiteral(val.string_val);
217 "DATE/DATETIME/TIMESTAMP literals not supported: " + constExpr.toSql());
219 Preconditions.checkState(
false,
220 String.format(
"Literals of type '%s' not supported.",
221 constExpr.getType().
toSql()));
226 result.analyze(null);
227 return (LiteralExpr)result;
234 if (
this instanceof NullLiteral)
return -1;
235 if (other instanceof NullLiteral)
return 1;
236 if (getClass() != other.getClass())
return -1;
int compareTo(LiteralExpr other)
static LiteralExpr create(String value, Type type)
static LiteralExpr create(Expr constExpr, TQueryCtx queryCtx)
static LiteralExpr fromThrift(TExprNode exprNode, Type colType)
abstract String getStringValue()
LiteralExpr(LiteralExpr other)