Skip to content

Conversation

@qianheng-aws
Copy link
Collaborator

@qianheng-aws qianheng-aws commented Jan 21, 2025

Description

Before this PR, PPL plan will fail executing on calcite engine and fallback to the original v2 engine. This PR aims to make the plan execute successfully on calcite engine.

The changes includes:

  • Replace RelRunners with CalciteConnection to do execution
  • Add OpenSearchSchema to the rootSchema of above connection
  • Change ExprValue to Object in OpenSearchTable

Related Issues

Resolves #3307

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Collaborator

@noCharger noCharger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qianheng-aws is this PR plan for review?

Signed-off-by: Heng Qian <qianheng@amazon.com>
@qianheng-aws qianheng-aws force-pushed the feature/calcite-engine branch from 148b79c to cf34fab Compare January 24, 2025 08:13
@qianheng-aws
Copy link
Collaborator Author

@qianheng-aws is this PR plan for review?

Yeah, but it should only be merged to the feature branch calcite-engine. It requires the review from @LantaoJin as he initiated that feature branch.

@penghuo penghuo added the calcite calcite migration releated label Jan 28, 2025
Copy link
Collaborator

@penghuo penghuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR ensure CalciteStandaloneIT passes?

  1. Could u refine the PR description? Make Calcite execute is generic.
  2. Could u enable CalciteStandaloneIT, and disable other PPL ITs. we expected IT should passed.

RelNode rel, CalcitePlanContext context, ResponseListener<QueryResponse> listener) {
try (PreparedStatement statement = RelRunners.run(rel)) {
Connection connection = context.connection;
final RelShuttle shuttle = new RelHomogeneousShuttle();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it required?

@Override
public Table get(Object key) {
if (!super.containsKey(key)) {
registerTable((String) key);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we do registerTable(new QualifiedName((String)key)) instead?

Comment on lines 46 to 54
try {
this.statement = connection.createStatement().unwrap(CalciteServerStatement.class);
} catch (Exception e) {
throw new RuntimeException("create statement failed", e);
}
this.prepare = new CalcitePrepareImpl();
this.relBuilder = prepare.perform(statement, config,
(cluster, relOptSchema, rootSchema, statement) -> new OSRelBuilder(config.getContext(),
cluster, relOptSchema));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could u help explain the purpose this statement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It aims to construct a relBuilder with the same logic as RelBuilder.create(config) while reusing the same statement created by connection.

I've removed this change because I realized that I just need to reuse the schema of connection and I've set that schema into the config by my second commit.

@qianheng-aws qianheng-aws changed the title [POC] Make Calcite execute successfully [POC] Make PPL execute successfully on Calcite engine Feb 5, 2025
…ble when visitRelation.

Signed-off-by: Heng Qian <qianheng@amazon.com>
Signed-off-by: Heng Qian <qianheng@amazon.com>
@qianheng-aws qianheng-aws force-pushed the feature/calcite-engine branch from cf34fab to 8ad5251 Compare February 5, 2025 08:25
Copy link
Member

@LantaoJin LantaoJin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except a less comments

this.connection = connection;
try {
this.statement = connection.createStatement().unwrap(CalciteServerStatement.class);
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: this try-catch is for unwrap or createStatement failure, better to separate the NPE out, or else mass of UT will go through via NPE here.

if (connection != null) {
  // try-catch block
}

}

public abstract Enumerable<ExprValue> search();
public abstract Enumerable<Object> search();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's reason to replace ExprValue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw exception and says that ExprValue is loaded in app classloader while Object is loaded in bootstrap classloader.

Signed-off-by: Heng Qian <qianheng@amazon.com>
@LantaoJin LantaoJin merged commit 1314a31 into opensearch-project:feature/calcite-engine Feb 7, 2025
5 of 13 checks passed
penghuo pushed a commit to penghuo/os-sql that referenced this pull request Mar 12, 2025
…ject#3258)

* [POC] Make Calcite execute successfully

Signed-off-by: Heng Qian <qianheng@amazon.com>

* [POC] Change caching schema to simple schema and avoid registering table when visitRelation.

Signed-off-by: Heng Qian <qianheng@amazon.com>

* spotlessApply

Signed-off-by: Heng Qian <qianheng@amazon.com>

* address comments

Signed-off-by: Heng Qian <qianheng@amazon.com>

---------

Signed-off-by: Heng Qian <qianheng@amazon.com>
penghuo pushed a commit that referenced this pull request Jun 16, 2025
* [POC] Make Calcite execute successfully

Signed-off-by: Heng Qian <qianheng@amazon.com>

* [POC] Change caching schema to simple schema and avoid registering table when visitRelation.

Signed-off-by: Heng Qian <qianheng@amazon.com>

* spotlessApply

Signed-off-by: Heng Qian <qianheng@amazon.com>

* address comments

Signed-off-by: Heng Qian <qianheng@amazon.com>

---------

Signed-off-by: Heng Qian <qianheng@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

calcite calcite migration releated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants