Skip to content

Commit

Permalink
Enable optic consumer to utilize different lexing settings in Framewo…
Browse files Browse the repository at this point in the history
…rks/Planner
  • Loading branch information
jacques-n authored and julianhyde committed Jan 29, 2014
1 parent 3b76846 commit 6d1c6ef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Expand Up @@ -18,11 +18,11 @@
package net.hydromatic.optiq.prepare;

import net.hydromatic.linq4j.function.Function1;

import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
import net.hydromatic.optiq.Schemas;
import net.hydromatic.optiq.impl.java.JavaTypeFactory;
import net.hydromatic.optiq.jdbc.ConnectionConfig;
import net.hydromatic.optiq.jdbc.OptiqSchema;
import net.hydromatic.optiq.tools.*;

Expand All @@ -42,6 +42,7 @@ public class PlannerImpl implements Planner {
private final Function1<SchemaPlus, Schema> schemaFactory;
private final SqlOperatorTable operatorTable;
private final ImmutableList<RuleSet> ruleSets;
private final ConnectionConfig.Lex lex;

// Options. TODO: allow client to set these. Maybe use a ConnectionConfig.
private boolean caseSensitive = true;
Expand All @@ -65,11 +66,12 @@ public class PlannerImpl implements Planner {
private SqlToRelConverter sqlToRelConverter;
private RelNode rel;

public PlannerImpl(Function1<SchemaPlus, Schema> schemaFactory,
public PlannerImpl(ConnectionConfig.Lex lex, Function1<SchemaPlus, Schema> schemaFactory,
SqlOperatorTable operatorTable, ImmutableList<RuleSet> ruleSets) {
this.schemaFactory = schemaFactory;
this.operatorTable = operatorTable;
this.ruleSets = ruleSets;
this.lex = lex;
this.state = State.STATE_0_CLOSED;
reset();
}
Expand Down Expand Up @@ -133,7 +135,7 @@ public SqlNode parse(final String sql) throws SqlParseException {
ready();
}
ensure(State.STATE_2_READY);
SqlParser parser = new SqlParser(sql);
SqlParser parser = new SqlParser(sql, lex.quoting, lex.unquotedCasing, lex.quotedCasing);
SqlNode sqlNode = parser.parseStmt();
state = State.STATE_3_PARSED;
return sqlNode;
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/net/hydromatic/optiq/tools/Frameworks.java
Expand Up @@ -18,9 +18,9 @@
package net.hydromatic.optiq.tools;

import net.hydromatic.linq4j.function.Function1;

import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
import net.hydromatic.optiq.jdbc.ConnectionConfig;
import net.hydromatic.optiq.jdbc.OptiqConnection;
import net.hydromatic.optiq.prepare.OptiqPrepareImpl;
import net.hydromatic.optiq.prepare.PlannerImpl;
Expand All @@ -46,6 +46,8 @@ private Frameworks() {
/**
* Creates an instance of {@code Planner}.
*
* @param lex The type of lexing the SqlParser should do. Controls case rules
* and quoted identifier syntax.
* @param schemaFactory Schema factory. Given a root schema, it creates and
* returns the schema that should be used to execute
* queries.
Expand All @@ -62,9 +64,10 @@ private Frameworks() {
* @return The Planner object.
*/
public static Planner getPlanner(
ConnectionConfig.Lex lex,
Function1<SchemaPlus, Schema> schemaFactory,
SqlStdOperatorTable operatorTable, RuleSet... ruleSets) {
return new PlannerImpl(schemaFactory, operatorTable,
return new PlannerImpl(lex, schemaFactory, operatorTable,
ImmutableList.copyOf(ruleSets));
}

Expand Down
Expand Up @@ -18,10 +18,10 @@
package net.hydromatic.optiq.tools;

import net.hydromatic.linq4j.function.Function1;

import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
import net.hydromatic.optiq.impl.java.ReflectiveSchema;
import net.hydromatic.optiq.jdbc.ConnectionConfig;
import net.hydromatic.optiq.rules.java.EnumerableConvention;
import net.hydromatic.optiq.rules.java.JavaRules;
import net.hydromatic.optiq.test.JdbcTest;
Expand All @@ -34,9 +34,7 @@
import org.eigenbase.sql.SqlNode;
import org.eigenbase.sql.fun.SqlStdOperatorTable;
import org.eigenbase.sql.parser.SqlParseException;

import org.eigenbase.util.Util;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.*;
Expand Down Expand Up @@ -102,6 +100,7 @@ private String toString(RelNode rel) {

private Planner getPlanner(RuleSet... ruleSets) {
return Frameworks.getPlanner(
ConnectionConfig.Lex.ORACLE,
new Function1<SchemaPlus, Schema>() {
public Schema apply(SchemaPlus parentSchema) {
return new ReflectiveSchema(parentSchema, "hr",
Expand Down

0 comments on commit 6d1c6ef

Please sign in to comment.