You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "zstan (via GitHub)" <gi...@apache.org> on 2025/06/09 09:18:52 UTC
[PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
zstan opened a new pull request, #6005:
URL: https://github.com/apache/ignite-3/pull/6005
Thank you for submitting the pull request.
To streamline the review process of the patch and ensure better code quality
we ask both an author and a reviewer to verify the following:
### The Review Checklist
- [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:
\- There is a single JIRA ticket related to the pull request.
\- The web-link to the pull request is attached to the JIRA ticket.
\- The JIRA ticket has the Patch Available state.
\- The description of the JIRA ticket explains WHAT was made, WHY and HOW.
\- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
- [ ] **Design:** new code conforms with the design principles of the components it is added to.
- [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
- [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
- [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
### Notes
- [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137451260
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/mapping/FragmentPrinter.java:
##########
@@ -291,6 +333,41 @@ public IgniteRel visit(IgniteIndexScan rel) {
return super.visit(rel);
}
+ @Override
+ public IgniteRel visit(IgniteKeyValueGet rel) {
+ printExecutableNode(rel);
+ return super.visit(rel);
+ }
+
+ @Override
+ public IgniteRel visit(IgniteSelectCount rel) {
+ printExecutableNode(rel);
+ return super.visit(rel);
+ }
+
+ @Override
+ public IgniteRel visit(IgniteKeyValueModify rel) {
+ printExecutableNode(rel);
+ return super.visit(rel);
+ }
+
+ @Override
+ public IgniteRel visit(IgniteSystemViewScan rel) {
+ RelOptTable source = rel.getTable();
+ assert source != null;
+
+ IgniteSystemViewImpl sysView = source.unwrap(IgniteSystemViewImpl.class);
+ assert sysView != null;
+
+ String viewName = String.join(".", rel.getTable().getQualifiedName());
+
+ output.writeFormattedString("(name={}, distribution={})",
+ viewName, sysView.distribution()
+ );
Review Comment:
Let's move this to a separate method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2138422399
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -522,13 +524,56 @@ private AsyncDataCursor<InternalSqlRow> executeKill(
return new IteratorToDataCursorAdapter<>(ret, Runnable::run);
}
- @SuppressWarnings("MethodMayBeStatic")
- private AsyncDataCursor<InternalSqlRow> executeExplain(ExplainPlan plan) {
- String planString = plan.plan().explain();
+ private AsyncDataCursor<InternalSqlRow> executeExplain(
+ SqlOperationContext operationContext,
+ ExplainPlan plan
+ ) {
+ switch (plan.mode()) {
+ case PLAN: {
+ String planString = plan.plan().explain();
+
+ InternalSqlRow res = new InternalSqlRowSingleString(planString);
+
+ return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ }
+ case MAPPING:
+ if (plan.plan() instanceof MultiStepPlan) {
+ QueryTransactionContext txContext = operationContext.txContext();
+
+ assert txContext != null;
+
+ boolean readOnly = plan.type().implicitTransactionReadOnlyMode();
+ QueryTransactionWrapper txWrapper = txContext.explicitTx();
+ if (txWrapper != null) {
+ InternalTransaction tx = txWrapper.unwrap();
+ readOnly = tx.isReadOnly();
+ }
+
+ Predicate<String> nodeExclusionFilter = operationContext.nodeExclusionFilter();
- InternalSqlRow res = new InternalSqlRowSingleString(planString);
+ MappingParameters mappingParameters =
+ MappingParameters.create(operationContext.parameters(), readOnly, nodeExclusionFilter);
- return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ CompletableFuture<List<MappedFragment>> mapping = mappingService.map((MultiStepPlan) plan.plan(), mappingParameters);
+
+ CompletableFuture<InternalSqlRow> fragments = FragmentPrinter.fragmentsToString(mapping);
+
+ CompletableFuture<Iterator<InternalSqlRow>> fragments0 = fragments.thenApply(List::of)
+ .thenApply(List::iterator);
Review Comment:
ok, done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137961820
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -522,13 +524,56 @@ private AsyncDataCursor<InternalSqlRow> executeKill(
return new IteratorToDataCursorAdapter<>(ret, Runnable::run);
}
- @SuppressWarnings("MethodMayBeStatic")
- private AsyncDataCursor<InternalSqlRow> executeExplain(ExplainPlan plan) {
- String planString = plan.plan().explain();
+ private AsyncDataCursor<InternalSqlRow> executeExplain(
+ SqlOperationContext operationContext,
+ ExplainPlan plan
+ ) {
+ switch (plan.mode()) {
+ case PLAN: {
+ String planString = plan.plan().explain();
+
+ InternalSqlRow res = new InternalSqlRowSingleString(planString);
+
+ return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ }
+ case MAPPING:
+ if (plan.plan() instanceof MultiStepPlan) {
+ QueryTransactionContext txContext = operationContext.txContext();
+
+ assert txContext != null;
+
+ boolean readOnly = plan.type().implicitTransactionReadOnlyMode();
+ QueryTransactionWrapper txWrapper = txContext.explicitTx();
+ if (txWrapper != null) {
+ InternalTransaction tx = txWrapper.unwrap();
+ readOnly = tx.isReadOnly();
+ }
+
+ Predicate<String> nodeExclusionFilter = operationContext.nodeExclusionFilter();
- InternalSqlRow res = new InternalSqlRowSingleString(planString);
+ MappingParameters mappingParameters =
+ MappingParameters.create(operationContext.parameters(), readOnly, nodeExclusionFilter);
- return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ CompletableFuture<List<MappedFragment>> mapping = mappingService.map((MultiStepPlan) plan.plan(), mappingParameters);
+
+ CompletableFuture<InternalSqlRow> fragments = FragmentPrinter.fragmentsToString(mapping);
+
+ CompletableFuture<Iterator<InternalSqlRow>> fragments0 = fragments.thenApply(List::of)
+ .thenApply(List::iterator);
Review Comment:
I prefer to make `String fragmentsToString()` public and remove `CompletableFuture<InternalSqlRow> fragmentsToString(CompletableFuture<List<MappedFragment>> fragments)`
```suggestion
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(FragmentPrinter::fragmentsToString)
.thenApply(InternalSqlRowSingleString::new)
.thenApply(InternalSqlRow.class::cast)
.thenApply(List::of)
.thenApply(List::iterator);
```
or simple
```
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(
fragments -> {
String fragmentsString = FragmentPrinter.fragmentsToString(fragments);
return List.of((InternalSqlRow) new InternalSqlRowSingleString(fragmentsString)).iterator();
}
);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137445626
##########
modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/QueryCheckerImpl.java:
##########
@@ -320,6 +321,7 @@ public void check() {
.defaultSchema(defaultSchema);
String qry = queryTemplate.createQuery();
+ boolean containExplain = qry.toUpperCase(Locale.ROOT).startsWith("EXPLAIN ");
Review Comment:
```suggestion
boolean containExplain = qry.substring(0, 8).equalsIgnoreCase("EXPLAIN ");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2138072535
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/RelAwarePlan.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.exec;
+
+import org.apache.ignite.internal.sql.engine.rel.IgniteRel;
+
+/**
+ * Plan that relies on {@link IgniteRel} in execution implementation.
+ */
+@FunctionalInterface
+public interface RelAwarePlan {
+ /** Returns rel representation. */
+ IgniteRel getRel();
Review Comment:
At this point all plans but KillPlan have a RelNode. So is this
```
if (plan instanceOf RelAwarePlan) {
var p = (RelAwarePlan) plan;
// do something with RelNode
}
```
Any better than a null check?
```
var node = plan.node();
if (node != null) {
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan merged PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2139212119
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/mapping/FragmentPrinter.java:
##########
@@ -60,6 +70,38 @@ private FragmentPrinter(Output output) {
this.output = output;
}
+ /** Print optimized plan in common fragment printer format. */
+ public static String relAwareToString(RelAwarePlan plan, String localNode) {
+ Output output = new Output(String::valueOf);
+
+ FragmentPrinter printer = new FragmentPrinter(output);
+
+ output.setNewLinePadding(0);
+ output.writeFormattedString(FRAGMENT_PREFIX + "{} root", 0);
+
+ output.setNewLinePadding(2);
+ output.writeNewline();
+
+ output.appendPadding();
+ output.writeKeyValue("executionNodes", List.of(localNode).toString());
+ output.writeNewline();
+
+ output.appendPadding();
+ output.writeString("tree:");
+ output.writeNewline();
+
+ printer.printRel(plan.getRel());
+
+ return output.builder.toString();
+ }
+
+ /** Wrapper. */
+ public static CompletableFuture<InternalSqlRow> fragmentsToString(CompletableFuture<List<MappedFragment>> fragments) {
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137698264
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/sqllogic/Plan.java:
##########
@@ -31,11 +31,26 @@ final class Plan extends Command {
private final String expectedPlan;
+ private final boolean mapping;
+
Plan(Script script, ScriptContext ctx, String[] cmd) throws IOException {
super(script.scriptPosition());
var sqlString = new IgniteStringBuilder();
+ if (cmd.length == 2) {
+ String explainType = cmd[1];
+ switch (explainType) {
+ case "mapping":
+ mapping = true;
+ break;
+ default:
+ throw script.reportInvalidCommand("Unsupported explain type", cmd);
+ }
+ } else {
+ mapping = false;
+ }
Review Comment:
second aporoach - done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137437492
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/SelectCountPlan.java:
##########
@@ -137,6 +134,11 @@ public ResultSetMetadata metadata() {
return metadata;
}
+ @Override
+ public IgniteRel getRel() {
Review Comment:
```suggestion
public IgniteSelectCount getRel() {
```
You can narrow return type to avoid explicit casts in few places.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137961820
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -522,13 +524,56 @@ private AsyncDataCursor<InternalSqlRow> executeKill(
return new IteratorToDataCursorAdapter<>(ret, Runnable::run);
}
- @SuppressWarnings("MethodMayBeStatic")
- private AsyncDataCursor<InternalSqlRow> executeExplain(ExplainPlan plan) {
- String planString = plan.plan().explain();
+ private AsyncDataCursor<InternalSqlRow> executeExplain(
+ SqlOperationContext operationContext,
+ ExplainPlan plan
+ ) {
+ switch (plan.mode()) {
+ case PLAN: {
+ String planString = plan.plan().explain();
+
+ InternalSqlRow res = new InternalSqlRowSingleString(planString);
+
+ return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ }
+ case MAPPING:
+ if (plan.plan() instanceof MultiStepPlan) {
+ QueryTransactionContext txContext = operationContext.txContext();
+
+ assert txContext != null;
+
+ boolean readOnly = plan.type().implicitTransactionReadOnlyMode();
+ QueryTransactionWrapper txWrapper = txContext.explicitTx();
+ if (txWrapper != null) {
+ InternalTransaction tx = txWrapper.unwrap();
+ readOnly = tx.isReadOnly();
+ }
+
+ Predicate<String> nodeExclusionFilter = operationContext.nodeExclusionFilter();
- InternalSqlRow res = new InternalSqlRowSingleString(planString);
+ MappingParameters mappingParameters =
+ MappingParameters.create(operationContext.parameters(), readOnly, nodeExclusionFilter);
- return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ CompletableFuture<List<MappedFragment>> mapping = mappingService.map((MultiStepPlan) plan.plan(), mappingParameters);
+
+ CompletableFuture<InternalSqlRow> fragments = FragmentPrinter.fragmentsToString(mapping);
+
+ CompletableFuture<Iterator<InternalSqlRow>> fragments0 = fragments.thenApply(List::of)
+ .thenApply(List::iterator);
Review Comment:
I prefer to make `String fragmentsToString()` public and remove `CompletableFuture<InternalSqlRow> fragmentsToString(CompletableFuture<List<MappedFragment>> fragments)`
```suggestion
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(FragmentPrinter::fragmentsToString)
.thenApply(InternalSqlRowSingleString::new)
.thenApply(InternalSqlRow.class::cast)
.thenApply(List::of)
.thenApply(List::iterator);
```
or simple
```
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(
fragments -> {
String fragmentsString = FragmentPrinter.fragmentsToString(fragments);
InternalSqlRow row = new InternalSqlRowSingleString(fragmentsString);
return List.of(row).iterator();
}
);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137961820
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -522,13 +524,56 @@ private AsyncDataCursor<InternalSqlRow> executeKill(
return new IteratorToDataCursorAdapter<>(ret, Runnable::run);
}
- @SuppressWarnings("MethodMayBeStatic")
- private AsyncDataCursor<InternalSqlRow> executeExplain(ExplainPlan plan) {
- String planString = plan.plan().explain();
+ private AsyncDataCursor<InternalSqlRow> executeExplain(
+ SqlOperationContext operationContext,
+ ExplainPlan plan
+ ) {
+ switch (plan.mode()) {
+ case PLAN: {
+ String planString = plan.plan().explain();
+
+ InternalSqlRow res = new InternalSqlRowSingleString(planString);
+
+ return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ }
+ case MAPPING:
+ if (plan.plan() instanceof MultiStepPlan) {
+ QueryTransactionContext txContext = operationContext.txContext();
+
+ assert txContext != null;
+
+ boolean readOnly = plan.type().implicitTransactionReadOnlyMode();
+ QueryTransactionWrapper txWrapper = txContext.explicitTx();
+ if (txWrapper != null) {
+ InternalTransaction tx = txWrapper.unwrap();
+ readOnly = tx.isReadOnly();
+ }
+
+ Predicate<String> nodeExclusionFilter = operationContext.nodeExclusionFilter();
- InternalSqlRow res = new InternalSqlRowSingleString(planString);
+ MappingParameters mappingParameters =
+ MappingParameters.create(operationContext.parameters(), readOnly, nodeExclusionFilter);
- return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ CompletableFuture<List<MappedFragment>> mapping = mappingService.map((MultiStepPlan) plan.plan(), mappingParameters);
+
+ CompletableFuture<InternalSqlRow> fragments = FragmentPrinter.fragmentsToString(mapping);
+
+ CompletableFuture<Iterator<InternalSqlRow>> fragments0 = fragments.thenApply(List::of)
+ .thenApply(List::iterator);
Review Comment:
I prefer to make `String fragmentsToString()` public and remove `CompletableFuture<InternalSqlRow> fragmentsToString(CompletableFuture<List<MappedFragment>> fragments)`
```suggestion
CompletableFuture<Iterator<InternalSqlRow>> fragments =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(FragmentPrinter::fragmentsToString)
.thenApply(InternalSqlRowSingleString::new)
.thenApply(InternalSqlRow.class::cast)
.thenApply(List::of)
.thenApply(List::iterator);
```
or simple
```
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(fragments -> {
String fragmentsString = FragmentPrinter.fragmentsToString(fragments);
InternalSqlRow row = new InternalSqlRowSingleString(fragmentsString);
return List.of(row).iterator();
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2138072535
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/RelAwarePlan.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.exec;
+
+import org.apache.ignite.internal.sql.engine.rel.IgniteRel;
+
+/**
+ * Plan that relies on {@link IgniteRel} in execution implementation.
+ */
+@FunctionalInterface
+public interface RelAwarePlan {
+ /** Returns rel representation. */
+ IgniteRel getRel();
Review Comment:
At this point, all plans, except for `KillPlan`, have RelNodes. So is this
```
if (plan instanceOf RelAwarePlan) {
var p = (RelAwarePlan) plan;
// do something with RelNode
}
```
Any better than a null check?
```
var node = plan.node();
if (node != null) {
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137479543
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/sqllogic/Plan.java:
##########
@@ -31,11 +31,26 @@ final class Plan extends Command {
private final String expectedPlan;
+ private final boolean mapping;
+
Plan(Script script, ScriptContext ctx, String[] cmd) throws IOException {
super(script.scriptPosition());
var sqlString = new IgniteStringBuilder();
+ if (cmd.length == 2) {
+ String explainType = cmd[1];
+ switch (explainType) {
+ case "mapping":
+ mapping = true;
+ break;
+ default:
+ throw script.reportInvalidCommand("Unsupported explain type", cmd);
+ }
+ } else {
+ mapping = false;
+ }
Review Comment:
Both of these approaches will lead to elimination of recently added `if-else` blocks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2138072535
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/RelAwarePlan.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.exec;
+
+import org.apache.ignite.internal.sql.engine.rel.IgniteRel;
+
+/**
+ * Plan that relies on {@link IgniteRel} in execution implementation.
+ */
+@FunctionalInterface
+public interface RelAwarePlan {
+ /** Returns rel representation. */
+ IgniteRel getRel();
Review Comment:
At this point all plans but KillPlan have a RelNode. So is this
```
if (plan instanceOf RelAwarePlan) {
var p = (RelAwarePlan) plan;
// do something with RelNode
}
```
Any better than?
```
var node = plan.node();
if (node != null) {
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137451260
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/mapping/FragmentPrinter.java:
##########
@@ -291,6 +333,41 @@ public IgniteRel visit(IgniteIndexScan rel) {
return super.visit(rel);
}
+ @Override
+ public IgniteRel visit(IgniteKeyValueGet rel) {
+ printExecutableNode(rel);
+ return super.visit(rel);
+ }
+
+ @Override
+ public IgniteRel visit(IgniteSelectCount rel) {
+ printExecutableNode(rel);
+ return super.visit(rel);
+ }
+
+ @Override
+ public IgniteRel visit(IgniteKeyValueModify rel) {
+ printExecutableNode(rel);
+ return super.visit(rel);
+ }
+
+ @Override
+ public IgniteRel visit(IgniteSystemViewScan rel) {
+ RelOptTable source = rel.getTable();
+ assert source != null;
+
+ IgniteSystemViewImpl sysView = source.unwrap(IgniteSystemViewImpl.class);
+ assert sysView != null;
+
+ String viewName = String.join(".", rel.getTable().getQualifiedName());
+
+ output.writeFormattedString("(name={}, distribution={})",
+ viewName, sysView.distribution()
+ );
Review Comment:
Let's move this to a separate method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137961820
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -522,13 +524,56 @@ private AsyncDataCursor<InternalSqlRow> executeKill(
return new IteratorToDataCursorAdapter<>(ret, Runnable::run);
}
- @SuppressWarnings("MethodMayBeStatic")
- private AsyncDataCursor<InternalSqlRow> executeExplain(ExplainPlan plan) {
- String planString = plan.plan().explain();
+ private AsyncDataCursor<InternalSqlRow> executeExplain(
+ SqlOperationContext operationContext,
+ ExplainPlan plan
+ ) {
+ switch (plan.mode()) {
+ case PLAN: {
+ String planString = plan.plan().explain();
+
+ InternalSqlRow res = new InternalSqlRowSingleString(planString);
+
+ return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ }
+ case MAPPING:
+ if (plan.plan() instanceof MultiStepPlan) {
+ QueryTransactionContext txContext = operationContext.txContext();
+
+ assert txContext != null;
+
+ boolean readOnly = plan.type().implicitTransactionReadOnlyMode();
+ QueryTransactionWrapper txWrapper = txContext.explicitTx();
+ if (txWrapper != null) {
+ InternalTransaction tx = txWrapper.unwrap();
+ readOnly = tx.isReadOnly();
+ }
+
+ Predicate<String> nodeExclusionFilter = operationContext.nodeExclusionFilter();
- InternalSqlRow res = new InternalSqlRowSingleString(planString);
+ MappingParameters mappingParameters =
+ MappingParameters.create(operationContext.parameters(), readOnly, nodeExclusionFilter);
- return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ CompletableFuture<List<MappedFragment>> mapping = mappingService.map((MultiStepPlan) plan.plan(), mappingParameters);
+
+ CompletableFuture<InternalSqlRow> fragments = FragmentPrinter.fragmentsToString(mapping);
+
+ CompletableFuture<Iterator<InternalSqlRow>> fragments0 = fragments.thenApply(List::of)
+ .thenApply(List::iterator);
Review Comment:
I prefer to make `String fragmentsToString()` public and remove `CompletableFuture<InternalSqlRow> fragmentsToString(CompletableFuture<List<MappedFragment>> fragments)`
```suggestion
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(FragmentPrinter::fragmentsToString)
.thenApply(InternalSqlRowSingleString::new)
.thenApply(InternalSqlRow.class::cast)
.thenApply(List::of)
.thenApply(List::iterator);
```
or simple
```
CompletableFuture<Iterator<InternalSqlRow>> fragments =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(fragments -> {
String fragmentsString = FragmentPrinter.fragmentsToString(fragments);
InternalSqlRow row = new InternalSqlRowSingleString(fragmentsString);
return List.of(row).iterator();
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2139211719
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItSqlMultiStatementTest.java:
##########
@@ -85,6 +88,35 @@ void basicMultiStatementQuery() {
.check();
}
+ // TODO: https://issues.apache.org/jira/browse/IGNITE-25600 move into FragmentMappingTest
+ @Test
+ void testExplainMappingWithDifferentTx() {
+ assertTrue(initialNodes() > 1);
+
+ sql("CREATE ZONE Z1 (partitions 10, replicas " + initialNodes() + ") storage profiles ['default']");
+ sql("CREATE TABLE t(id INT PRIMARY KEY, col1 INT) ZONE Z1");
Review Comment:
yes, i plan to remove it there
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2138072535
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/RelAwarePlan.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.exec;
+
+import org.apache.ignite.internal.sql.engine.rel.IgniteRel;
+
+/**
+ * Plan that relies on {@link IgniteRel} in execution implementation.
+ */
+@FunctionalInterface
+public interface RelAwarePlan {
+ /** Returns rel representation. */
+ IgniteRel getRel();
Review Comment:
At this point, all plans but KillPlan have RelNodes. So is this
```
if (plan instanceOf RelAwarePlan) {
var p = (RelAwarePlan) plan;
// do something with RelNode
}
```
Any better than a null check?
```
var node = plan.node();
if (node != null) {
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137697620
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/SelectCountPlan.java:
##########
@@ -137,6 +134,11 @@ public ResultSetMetadata metadata() {
return metadata;
}
+ @Override
+ public IgniteRel getRel() {
Review Comment:
done
##########
modules/sql-engine/src/testFixtures/java/org/apache/ignite/internal/sql/engine/util/QueryCheckerImpl.java:
##########
@@ -320,6 +321,7 @@ public void check() {
.defaultSchema(defaultSchema);
String qry = queryTemplate.createQuery();
+ boolean containExplain = qry.toUpperCase(Locale.ROOT).startsWith("EXPLAIN ");
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137961820
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -522,13 +524,56 @@ private AsyncDataCursor<InternalSqlRow> executeKill(
return new IteratorToDataCursorAdapter<>(ret, Runnable::run);
}
- @SuppressWarnings("MethodMayBeStatic")
- private AsyncDataCursor<InternalSqlRow> executeExplain(ExplainPlan plan) {
- String planString = plan.plan().explain();
+ private AsyncDataCursor<InternalSqlRow> executeExplain(
+ SqlOperationContext operationContext,
+ ExplainPlan plan
+ ) {
+ switch (plan.mode()) {
+ case PLAN: {
+ String planString = plan.plan().explain();
+
+ InternalSqlRow res = new InternalSqlRowSingleString(planString);
+
+ return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ }
+ case MAPPING:
+ if (plan.plan() instanceof MultiStepPlan) {
+ QueryTransactionContext txContext = operationContext.txContext();
+
+ assert txContext != null;
+
+ boolean readOnly = plan.type().implicitTransactionReadOnlyMode();
+ QueryTransactionWrapper txWrapper = txContext.explicitTx();
+ if (txWrapper != null) {
+ InternalTransaction tx = txWrapper.unwrap();
+ readOnly = tx.isReadOnly();
+ }
+
+ Predicate<String> nodeExclusionFilter = operationContext.nodeExclusionFilter();
- InternalSqlRow res = new InternalSqlRowSingleString(planString);
+ MappingParameters mappingParameters =
+ MappingParameters.create(operationContext.parameters(), readOnly, nodeExclusionFilter);
- return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ CompletableFuture<List<MappedFragment>> mapping = mappingService.map((MultiStepPlan) plan.plan(), mappingParameters);
+
+ CompletableFuture<InternalSqlRow> fragments = FragmentPrinter.fragmentsToString(mapping);
+
+ CompletableFuture<Iterator<InternalSqlRow>> fragments0 = fragments.thenApply(List::of)
+ .thenApply(List::iterator);
Review Comment:
I prefer to make `String fragmentsToString()` public and remove `CompletableFuture<InternalSqlRow> fragmentsToString(CompletableFuture<List<MappedFragment>> fragments)`
```suggestion
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(FragmentPrinter::fragmentsToString)
.thenApply(InternalSqlRowSingleString::new)
.thenApply(InternalSqlRow.class::cast)
.thenApply(List::of)
.thenApply(List::iterator);
```
or simple
```
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(fragments -> {
String fragmentsString = FragmentPrinter.fragmentsToString(fragments);
InternalSqlRow row = new InternalSqlRowSingleString(fragmentsString);
return List.of(row).iterator();
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137475229
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/sqllogic/Plan.java:
##########
@@ -31,11 +31,26 @@ final class Plan extends Command {
private final String expectedPlan;
+ private final boolean mapping;
+
Plan(Script script, ScriptContext ctx, String[] cmd) throws IOException {
super(script.scriptPosition());
var sqlString = new IgniteStringBuilder();
+ if (cmd.length == 2) {
+ String explainType = cmd[1];
+ switch (explainType) {
+ case "mapping":
+ mapping = true;
+ break;
+ default:
+ throw script.reportInvalidCommand("Unsupported explain type", cmd);
+ }
+ } else {
+ mapping = false;
+ }
Review Comment:
Maybe we can simplify this via one of the way:
* use separate classes and one-word commands for "explain plan" and "explain mapping"
In logic test they will be looks like
```
plan
SELECT ....
----
```
```
mapping
SELECT ...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137477786
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/sqllogic/Plan.java:
##########
@@ -31,11 +31,26 @@ final class Plan extends Command {
private final String expectedPlan;
+ private final boolean mapping;
+
Plan(Script script, ScriptContext ctx, String[] cmd) throws IOException {
super(script.scriptPosition());
var sqlString = new IgniteStringBuilder();
+ if (cmd.length == 2) {
+ String explainType = cmd[1];
+ switch (explainType) {
+ case "mapping":
+ mapping = true;
+ break;
+ default:
+ throw script.reportInvalidCommand("Unsupported explain type", cmd);
+ }
+ } else {
+ mapping = false;
+ }
Review Comment:
Or better, use multi-word command
```
explain plan
SELECT ....
----
```
```
explain mapping
plan
SELECT ....
----
````
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2138072535
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/RelAwarePlan.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.engine.exec;
+
+import org.apache.ignite.internal.sql.engine.rel.IgniteRel;
+
+/**
+ * Plan that relies on {@link IgniteRel} in execution implementation.
+ */
+@FunctionalInterface
+public interface RelAwarePlan {
+ /** Returns rel representation. */
+ IgniteRel getRel();
Review Comment:
At this point, all plans, except for `KillPlan`, have RelNodes. So is this
```
if (plan instanceOf RelAwarePlan) {
var p = (RelAwarePlan) plan;
// do something with RelNode
}
```
Any better than a null check?
```
var node = plan.node(); // QueryPlan node()
if (node != null) {
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-25369 Sql. Introduce EXPLAIN MAPPING FOR command [ignite-3]
Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #6005:
URL: https://github.com/apache/ignite-3/pull/6005#discussion_r2137832348
##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItSqlMultiStatementTest.java:
##########
@@ -85,6 +88,35 @@ void basicMultiStatementQuery() {
.check();
}
+ // TODO: https://issues.apache.org/jira/browse/IGNITE-25600 move into FragmentMappingTest
+ @Test
+ void testExplainMappingWithDifferentTx() {
+ assertTrue(initialNodes() > 1);
+
+ sql("CREATE ZONE Z1 (partitions 10, replicas " + initialNodes() + ") storage profiles ['default']");
+ sql("CREATE TABLE t(id INT PRIMARY KEY, col1 INT) ZONE Z1");
Review Comment:
```suggestion
runScript("CREATE ZONE Z1 (partitions 10, replicas " + initialNodes() + ") storage profiles ['default'];"
+ "CREATE TABLE t(id INT PRIMARY KEY, col1 INT) ZONE Z1");
```
please ignore this, it you will remove this test in `IGNITE-25600`
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/mapping/FragmentPrinter.java:
##########
@@ -60,6 +70,38 @@ private FragmentPrinter(Output output) {
this.output = output;
}
+ /** Print optimized plan in common fragment printer format. */
+ public static String relAwareToString(RelAwarePlan plan, String localNode) {
+ Output output = new Output(String::valueOf);
+
+ FragmentPrinter printer = new FragmentPrinter(output);
+
+ output.setNewLinePadding(0);
+ output.writeFormattedString(FRAGMENT_PREFIX + "{} root", 0);
+
+ output.setNewLinePadding(2);
+ output.writeNewline();
+
+ output.appendPadding();
+ output.writeKeyValue("executionNodes", List.of(localNode).toString());
+ output.writeNewline();
+
+ output.appendPadding();
+ output.writeString("tree:");
+ output.writeNewline();
+
+ printer.printRel(plan.getRel());
+
+ return output.builder.toString();
+ }
+
+ /** Wrapper. */
+ public static CompletableFuture<InternalSqlRow> fragmentsToString(CompletableFuture<List<MappedFragment>> fragments) {
Review Comment:
I don't understand the purpose of this method.
Why we can't just make public `String fragmentsToString(List..)`?
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -522,13 +524,56 @@ private AsyncDataCursor<InternalSqlRow> executeKill(
return new IteratorToDataCursorAdapter<>(ret, Runnable::run);
}
- @SuppressWarnings("MethodMayBeStatic")
- private AsyncDataCursor<InternalSqlRow> executeExplain(ExplainPlan plan) {
- String planString = plan.plan().explain();
+ private AsyncDataCursor<InternalSqlRow> executeExplain(
+ SqlOperationContext operationContext,
+ ExplainPlan plan
+ ) {
+ switch (plan.mode()) {
+ case PLAN: {
+ String planString = plan.plan().explain();
+
+ InternalSqlRow res = new InternalSqlRowSingleString(planString);
+
+ return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ }
+ case MAPPING:
+ if (plan.plan() instanceof MultiStepPlan) {
+ QueryTransactionContext txContext = operationContext.txContext();
+
+ assert txContext != null;
+
+ boolean readOnly = plan.type().implicitTransactionReadOnlyMode();
+ QueryTransactionWrapper txWrapper = txContext.explicitTx();
+ if (txWrapper != null) {
+ InternalTransaction tx = txWrapper.unwrap();
+ readOnly = tx.isReadOnly();
+ }
+
+ Predicate<String> nodeExclusionFilter = operationContext.nodeExclusionFilter();
- InternalSqlRow res = new InternalSqlRowSingleString(planString);
+ MappingParameters mappingParameters =
+ MappingParameters.create(operationContext.parameters(), readOnly, nodeExclusionFilter);
- return new IteratorToDataCursorAdapter<>(List.of(res).iterator());
+ CompletableFuture<List<MappedFragment>> mapping = mappingService.map((MultiStepPlan) plan.plan(), mappingParameters);
+
+ CompletableFuture<InternalSqlRow> fragments = FragmentPrinter.fragmentsToString(mapping);
+
+ CompletableFuture<Iterator<InternalSqlRow>> fragments0 = fragments.thenApply(List::of)
+ .thenApply(List::iterator);
Review Comment:
I prefer to make `String fragmentsToString()` public and remove `fragmentsToString(CompletableFuture<List<MappedFragment>> fragments)`
```suggestion
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(FragmentPrinter::fragmentsToString)
.thenApply(InternalSqlRowSingleString::new)
.thenApply(InternalSqlRow.class::cast)
.thenApply(List::of)
.thenApply(List::iterator);
```
or simple
```
CompletableFuture<Iterator<InternalSqlRow>> fragments0 =
mappingService.map((MultiStepPlan) plan.plan(), mappingParameters)
.thenApply(
fragments -> {
String fragmentsString = FragmentPrinter.fragmentsToString(fragments);
return List.of((InternalSqlRow) new InternalSqlRowSingleString(fragmentsString)).iterator();
}
);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org