Hi, Hyde

I wrote code like this:

FrameworkConfig config = Frameworks.newConfigBuilder().build();
Planner planner = Frameworks.getPlanner(config);
                SqlNode node = planner.parse(sql);
                RelRoot relRoot = planner.rel(node);
                RelNode project = relRoot.project();
                RexNode condition = ((Filter) ((Project) 
project).getInput()).getCondition();


However, an exception was thrown while running 'RelRoot relRoot = 
planner.rel(node);’:

java.lang.IllegalArgumentException: cannot move from STATE_3_PARSED to 
STATE_4_VALIDATED
        at 
org.apache.calcite.prepare.PlannerImpl$State.from(PlannerImpl.java:318)
        at org.apache.calcite.prepare.PlannerImpl.ensure(PlannerImpl.java:108)
        at org.apache.calcite.prepare.PlannerImpl.rel(PlannerImpl.java:200)

How to avoid the error?

thanks~


———————————————
Zhihong SHEN, Ph. D., Senior Engineer
Big Data Application Service Technology Laboratory,
Computer Network Information Center, Chinese Academy of Sciences
office phone:+86-10-58812516
mobile:+86-13671116520








在 16/9/10 上午1:25,“Julian 
Hyde”<[email protected] 代表 [email protected]> 
写入:

>If you can parse & convert to get a RelNode, then the RelNode will probably be 
>a Project with a Filter underneath. So you can write
>
>  RelNode r;
>  RexNode condition = ((Filter) ((Project) r).getInput()).getCondition;
>
>Now, how to parse a SQL statement to a RelNode? I think I’d use
>
>  String sql = …;
>  FrameworkConfig config = ...;
>  Planner planner = Frameworks.getPlanner(config);
>  SqlNode node = planner.parse(sql);
>  RelRoot relRoot = planner.rel(node);
>  RelNode r = relRoot.project();
>
>but I’d like to hear what others consider to be the most painless way to use 
>Calcite’s parser.
>
>Julian
>
>> On Sep 9, 2016, at 2:21 AM, 沈志宏 <[email protected]> wrote:
>> 
>> hi, dear all
>> 
>> is there any tool class to generate RexNodes from a SQL command?
>> for example,
>> 
>> List<RexNode> RexNodeUtils.parse(schema, "select * from persons where name 
>> like 'm%' and age>10")
>> 
>> i am writing a solr adapter and i really really need it to help write java 
>> tests for my query translator.
>> 
>> best regards
>> 
>> 
>> 
>


Reply via email to