15 package com.cloudera.impala.analysis;
17 import java.io.IOException;
18 import java.io.StringReader;
19 import java.math.BigDecimal;
21 import java_cup.runtime.Symbol;
23 import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
28 import com.cloudera.impala.thrift.TExprNode;
29 import com.cloudera.impala.thrift.TExprNodeType;
30 import com.cloudera.impala.thrift.TStringLiteral;
31 import com.google.common.base.Objects;
32 import com.google.common.base.Preconditions;
57 if (!super.equals(obj))
return false;
68 msg.node_type = TExprNodeType.STRING_LITERAL;
77 return BaseSemanticAnalyzer.unescapeSQLString(
"'" +
value_ +
"'");
87 return Objects.toStringHelper(
this)
94 Preconditions.checkState(targetType.isNumericType() || targetType.isDateType()
95 || targetType.equals(this.type_) || targetType.isStringType());
96 if (targetType.equals(
this.type_)) {
98 }
else if (targetType.isStringType()) {
100 }
else if (targetType.isNumericType()) {
102 }
else if (targetType.isDateType()) {
104 return new CastExpr(targetType,
this);
120 StringReader reader =
new StringReader(
value_);
121 SqlScanner scanner =
new SqlScanner(reader);
123 boolean negative =
false;
130 sym = scanner.next_token();
131 while (sym.sym == SqlParserSymbols.SUBTRACT) {
132 negative = !negative;
133 sym = scanner.next_token();
135 }
catch (IOException e) {
136 throw new AnalysisException(
"Failed to convert string literal to number.", e);
138 if (sym.sym == SqlParserSymbols.NUMERIC_OVERFLOW) {
139 throw new AnalysisException(
"Number too large: " +
value_);
141 if (sym.sym == SqlParserSymbols.INTEGER_LITERAL) {
142 BigDecimal val = (BigDecimal) sym.value;
143 if (negative) val = val.negate();
146 if (sym.sym == SqlParserSymbols.DECIMAL_LITERAL) {
147 BigDecimal val = (BigDecimal) sym.value;
148 if (negative) val = val.negate();
152 throw new AnalysisException(
153 "Failed to convert string literal '" +
value_ +
"' to number.");
158 int ret = super.compareTo(o);
159 if (ret != 0)
return ret;
161 return value_.compareTo(other.getStringValue());
boolean equals(Object obj)
StringLiteral(String value, Type type)
static final ScalarType STRING
void toThrift(TExprNode msg)
String getUnescapedValue()
StringLiteral(String value)
int compareTo(LiteralExpr o)
StringLiteral(StringLiteral other)
LiteralExpr convertToNumber()
Expr uncheckedCastTo(Type targetType)