Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ SqlCreate SqlCreateDatabase(Span s, boolean replace) :
}

/**
* USE DATABASE ( catalog_name '.' )? database_name
* USE [ DATABASE ] ( catalog_name '.' )? database_name
*/
SqlCall SqlUseDatabase(Span s, String scope) :
{
Expand All @@ -391,7 +391,7 @@ SqlCall SqlUseDatabase(Span s, String scope) :
<USE> {
s.add(this);
}
<DATABASE>
[ <DATABASE> ]
databaseName = CompoundIdentifier()
{
return new SqlUseDatabase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class BeamCalciteTable extends AbstractQueryableTable
private final Map<String, String> pipelineOptionsMap;
private @Nullable PipelineOptions pipelineOptions;

BeamCalciteTable(
public BeamCalciteTable(
BeamSqlTable beamTable,
Map<String, String> pipelineOptionsMap,
@Nullable PipelineOptions pipelineOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,23 @@
import org.apache.beam.sdk.transforms.SerializableFunction;
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.jdbc.CalcitePrepare;
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.plan.RelOptUtil;
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode;
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.schema.Function;
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlKind;
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.tools.RelBuilder;
import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.tools.RuleSet;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Contains the metadata of tables/UDF functions, and exposes APIs to
* query/validate/optimize/translate SQL statements.
*/
@Internal
public class BeamSqlEnv {
private static final Logger LOG = LoggerFactory.getLogger(BeamSqlEnv.class);

JdbcConnection connection;
QueryPlanner planner;

Expand Down Expand Up @@ -116,6 +122,31 @@ public BeamRelNode parseQuery(String query, QueryParameters queryParameters)
return planner.convertToBeamRel(query, queryParameters);
}

public QueryPlanner getPlanner() {
return planner;
}

public RelBuilder getRelBuilder() {
return planner.getRelBuilder();
}

public BeamRelNode convertToBeamRel(RelNode relNode) {
return planner.convertToBeamRel(relNode, QueryParameters.ofNone());
}

public RelNode parseLogicalPlan(String query) throws ParseException {
return planner.parseToRel(query, QueryParameters.ofNone());
}

public void registerSchemaFunction(String name, Function function) {
connection.getCurrentSchemaPlus().add(name, function);
}

public org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlOperatorTable
getOperatorTable() {
return planner.getOperatorTable();
}

public boolean isDdl(String sqlStatement) throws ParseException {
return planner.parse(sqlStatement).getKind().belongsTo(SqlKind.DDL);
}
Expand Down Expand Up @@ -196,6 +227,7 @@ public BeamSqlEnvBuilder setCurrentSchema(String name) {

/** Set the ruleSet used for query optimizer. */
public BeamSqlEnvBuilder setRuleSets(Collection<RuleSet> ruleSets) {
LOG.info("Setting BeamSqlEnv rulesets to: {}", ruleSets);
this.ruleSets = ruleSets;
return this;
}
Expand Down Expand Up @@ -262,6 +294,7 @@ public BeamSqlEnv build() {

configureSchemas(jdbcConnection);

LOG.info("Instantiating planner with ruleSets: {}", ruleSets);
QueryPlanner planner = instantiatePlanner(jdbcConnection, ruleSets);

// The planner may choose to add its own builtin functions to the schema, so load user-defined
Expand Down
Loading
Loading