Github user maryannxue commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/212#discussion_r81202889
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java ---
    @@ -1036,4 +1048,40 @@ public Void visitCall(RexCall call) {
                 return null;
             }
         }
    +
    +    public static Object convertLiteral(SqlLiteral literal, 
PhoenixRelImplementor implementor) {
    +        try {
    +            final SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);
    +            final FrameworkConfig config = Frameworks.newConfigBuilder()
    +                    .parserConfig(SqlParser.Config.DEFAULT)
    +                    .defaultSchema(rootSchema).build();
    +            Planner planner = Frameworks.getPlanner(config);
    +
    +            SqlParserPos POS = SqlParserPos.ZERO;
    +            final SqlNodeList selectList =
    +                    new SqlNodeList(
    +                            Collections.singletonList(literal),
    +                            SqlParserPos.ZERO);
    +
    +
    +            String sql = new SqlSelect(POS, SqlNodeList.EMPTY, selectList, 
null, null, null, null,
    +                    SqlNodeList.EMPTY, null, null, null).toString();
    +            SqlNode sqlNode = planner.parse(sql);
    +            sqlNode = planner.validate(sqlNode);
    +            Project proj = (Project) (planner.rel(sqlNode).rel);
    +            RexNode rex = proj.getChildExps().get(0);
    +
    +            Expression e = CalciteUtils.toExpression(rex, implementor);
    +            ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    +            e = ExpressionUtil.getConstantExpression(e, ptr);
    +            Object ret = e.getDataType().toObject(ptr);
    +            if(ret instanceof NlsString){
    +                ret = ((NlsString) ret).toString();
    +            }
    +            return ret;
    +        }
    +        catch (Exception e){
    +            throw new RuntimeException("Could not convert literal to its 
object type: " + e);
    --- End diff --
    
    Normally you don't append the Exception itself to the end of the error 
message. You message should include the exact SqlLiteral it failed to convert 
and add the original Exception as inner exception.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to