[ 
https://issues.apache.org/jira/browse/PHOENIX-3264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15533744#comment-15533744
 ] 

ASF GitHub Bot commented on PHOENIX-3264:
-----------------------------------------

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

    https://github.com/apache/phoenix/pull/212#discussion_r81212299
  
    --- 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 --
    
    Will amend this, thanks!


> Allow TRUE and FALSE to be used as literal constants
> ----------------------------------------------------
>
>                 Key: PHOENIX-3264
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3264
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: James Taylor
>            Assignee: Eric Lomore
>         Attachments: Sql2RelImplementation.png, SqlLiteral.png, 
> SqlNodeToRexConverterImpl.png, SqlOptionNode.png, objectdependencies.png, 
> objectdependencies2.png, stacktrace.png
>
>
> Phoenix supports TRUE and FALSE as boolean literals, but perhaps Calcite 
> doesn't? Looks like this is leading to a fair number of failures.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to