By the way, I took an insight into the PlanerImpl.validate():

public SqlNode validate(SqlNode sqlNode) throws ValidationException {
    ensure(State.STATE_3_PARSED);
    this.validator =
        new CalciteSqlValidator(
            operatorTable, createCatalogReader(), typeFactory);
    this.validator.setIdentifierExpansion(true);
    try {
      validatedSqlNode = validator.validate(sqlNode);
    } catch (RuntimeException e) {
      throw new ValidationException(e);
    }
    state = State.STATE_4_VALIDATED;
    return validatedSqlNode;
  }


I noticed the state is often changed in such steps, so, if this cause a 
PlanerImpl instance is always bound to one SqlNode and cannot be reused to 
parse/validate another SqlNodes?
 
———————————————
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








On 9/15/16, 1:07 AM, "[email protected]" 
<[email protected] on behalf of 
[email protected]> wrote:

>You have to run planner.validate after parse, otherwise the state in 
>PlannerImpl will be incorrect. You can also go into the PlannerImpl and steal 
>some code if you need to circumvent those states, but I agree this is probably 
>the easiest way to go about it. The alternative is just creating a parser and 
>SqlToRelConverter to do the parsing and conversion yourself. PlannerImpl takes 
>care of a lot of other things as well like flattening nested types, view 
>expansion, etc IIRC.
>
>> On Sep 14, 2016, at 2:29 AM, bluejoe <[email protected]> wrote:
>> 
>> 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