fe/src/main/java/com/cloudera/impala/analysis/LiteralExpr.java
/**
   * Evaluates the given constant expr and returns its result as a LiteralExpr.
   * Assumes expr has been analyzed. Returns constExpr if is it already a LiteralExpr.
   */
Evaluates the given constant expr and returns its result as a LiteralExpr.
Assumes expr has been analyzed. Returns constExpr if is it already a LiteralExpr.
Evaluates the given constant expr and returns its result as a LiteralExpr . Assumes expr has been analyzed . Returns constExpr if is it already a LiteralExpr .
public static LiteralExpr create(Expr constExpr, TQueryContext queryCtxt)
      throws AnalysisException {
    Preconditions.checkState(constExpr.isConstant());
    Preconditions.checkState(constExpr.getType().isValid());
    if (constExpr instanceof LiteralExpr) return (LiteralExpr) constExpr;
    TColumnValue val = null;
    try {
      val = FeSupport.EvalConstExpr(constExpr, queryCtxt);
    } catch (InternalException e) {
      throw new AnalysisException(String.format("Failed to evaluate expr '%s'",
          constExpr.toSql()), e);
    }
    LiteralExpr result = null;
    switch (constExpr.getType().getPrimitiveType()) {
      case NULL_TYPE:
        result = new NullLiteral();
        break;
      case BOOLEAN:
        if (val.isBool_val()) result = new BoolLiteral(val.bool_val);
        break;
      case TINYINT:
        if (val.isSetByte_val()) {
          result = new IntLiteral(BigInteger.valueOf(val.byte_val));
        }
        break;
      case SMALLINT:
        if (val.isSetShort_val()) {
          result = new IntLiteral(BigInteger.valueOf(val.short_val));
        }
        break;
      case INT:
        if (val.isSetInt_val()) result = new IntLiteral(BigInteger.valueOf(val.int_val));
        break;
      case BIGINT:
        if (val.isSetLong_val()) {
          result = new IntLiteral(BigInteger.valueOf(val.long_val));
        }
        break;
      case FLOAT:
      case DOUBLE:
        if (val.isSetDouble_val()) result = new FloatLiteral(val.double_val);
        break;
      case STRING:
        if (val.isSetString_val()) result = new StringLiteral(val.string_val);
        break;
      case DATE:
      case DATETIME:
      case TIMESTAMP:
        throw new AnalysisException(
            "DATE/DATETIME/TIMESTAMP literals not supported: " + constExpr.toSql());
    }
    if (result == null) result = new NullLiteral();
    return result;
  }
public static LiteralExpr create ( Expr constExpr , TQueryContext queryCtxt ) throws AnalysisException { Preconditions . checkState ( constExpr . isConstant ( ) ) ; Preconditions . checkState ( constExpr . getType ( ) . isValid ( ) ) ; if ( constExpr instanceof LiteralExpr ) return ( LiteralExpr ) constExpr ; TColumnValue val = null ; try { val = FeSupport . EvalConstExpr ( constExpr , queryCtxt ) ; } catch ( InternalException e ) { throw new AnalysisException ( String . format ( "Failed to evaluate expr '%s'" , constExpr . toSql ( ) ) , e ) ; } LiteralExpr result = null ; switch ( constExpr . getType ( ) . getPrimitiveType ( ) ) { case NULL_TYPE : result = new NullLiteral ( ) ; break ; case BOOLEAN : if ( val . isBool_val ( ) ) result = new BoolLiteral ( val . bool_val ) ; break ; case TINYINT : if ( val . isSetByte_val ( ) ) { result = new IntLiteral ( BigInteger . valueOf ( val . byte_val ) ) ; } break ; case SMALLINT : if ( val . isSetShort_val ( ) ) { result = new IntLiteral ( BigInteger . valueOf ( val . short_val ) ) ; } break ; case INT : if ( val . isSetInt_val ( ) ) result = new IntLiteral ( BigInteger . valueOf ( val . int_val ) ) ; break ; case BIGINT : if ( val . isSetLong_val ( ) ) { result = new IntLiteral ( BigInteger . valueOf ( val . long_val ) ) ; } break ; case FLOAT : case DOUBLE : if ( val . isSetDouble_val ( ) ) result = new FloatLiteral ( val . double_val ) ; break ; case STRING : if ( val . isSetString_val ( ) ) result = new StringLiteral ( val . string_val ) ; break ; case DATE : case DATETIME : case TIMESTAMP : throw new AnalysisException ( "DATE/DATETIME/TIMESTAMP literals not supported: " + constExpr . toSql ( ) ) ; } if ( result == null ) result = new NullLiteral ( ) ; return result ; }
Evaluates the given constant expr and returns its result as a LiteralExpr.
Evaluates the given constant expr and returns its result as a LiteralExpr .
// None of the fields in the thrift struct were set indicating a NULL.