Skip to content

Support for the SHOW TRANSACTION statement and the L2_DISTANCE function#37429

Closed
ccxxxyy wants to merge 6 commits into
apache:masterfrom
ccxxxyy:issueNo
Closed

Support for the SHOW TRANSACTION statement and the L2_DISTANCE function#37429
ccxxxyy wants to merge 6 commits into
apache:masterfrom
ccxxxyy:issueNo

Conversation

@ccxxxyy
Copy link
Copy Markdown
Contributor

@ccxxxyy ccxxxyy commented Dec 18, 2025

for #31505

Changes proposed in this pull request:


Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.
  • I have updated the Release Notes of the current development version. For more details, see Update Release Note

Copy link
Copy Markdown
Member

@terrymanu terrymanu left a comment

Choose a reason for hiding this comment

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

Here’s a gentle change request with details—thanks for the effort so far, and please keep going:

  • parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDALStatementVisitor.java: In visitShowTransaction, add result.addParameterMarkers(getParameterMarkerSegments()) (like other SHOW visitors) so SHOW TRANSACTION ... WHERE label=? keeps parameter metadata.
  • parser/sql/statement/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/statement/mysql/dal/show/MySQLShowTransactionStatement.java: Prefer storing FromDatabaseSegment (consistent with other SHOW statements) and override getAttributes() to set FromDatabaseSQLStatementAttribute / AllowNotUseDatabaseSQLStatementAttribute etc., so the FROM clause position and routing/database requirements are honored rather than being ignored or defaulted.
  • test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/mysql/MySQLDALStatementAssert.java: Add an assertion branch for MySQLShowTransactionStatement to verify fromDatabase and where, ensuring the new XML cases actually validate the parsed output.

These tweaks will align the new syntax with existing behavior and prevent loss of placeholder/routing info.

@ccxxxyy ccxxxyy requested a review from terrymanu December 19, 2025 08:42
@ccxxxyy
Copy link
Copy Markdown
Contributor Author

ccxxxyy commented Dec 19, 2025

@terrymanu Hi, I have made the revisions as required. Hope you can review them when you have time.

Copy link
Copy Markdown
Member

@terrymanu terrymanu left a comment

Choose a reason for hiding this comment

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

Here are a few friendly change-request suggestions to get this over the line:

  • Please wire SHOW TRANSACTION into backend execution: add a matching admin executor (and factory wiring, similar to MySQLShowTablesExecutor) so the parsed statement can actually run in proxy/JDBC; consider adding an e2e/admin test to prove the result shape.
  • Revisit the grammar constraint: the current rule requires WHERE. If Doris allows SHOW TRANSACTION [FROM db] without WHERE, expand the rule and add a parser case to cover it.
  • Verify downstream handling of the new array literal → ListExpression: add a small parser-to-binder/route regression test (e.g., encrypt/shadow rewrite path) to ensure bracketed arrays aren’t misinterpreted as IN lists or otherwise altered.
  • Add a dedicated assertion/test for MySQLShowTransactionStatement covering both FROM db and WHERE variants, and include parameter-marker scenarios if supported.

Thanks for the solid parser work—once these pieces are in, this feature should be ready.

@ccxxxyy
Copy link
Copy Markdown
Contributor Author

ccxxxyy commented Dec 20, 2025

@terrymanu Hi, I have made the modifications as required. Hope you can review them when you have a moment.
Regarding the third point of the modification suggestion, I hope you can take a look at my thoughts: Based on the official Doris documentation , the concern about "array literal → ListExpression" is mainly theoretical. The WHERE clause of SHOW TRANSACTION only supports simple equality comparisons, and the right side of the WHERE clause is just a simple literal (LiteralExpressionSegment). According to the Doris official documentation and our implementation: The WHERE clause must use the form of id = or label = ; it does not support complex expressions such as IN, ANY, or array literals; the parser correctly parses the WHERE clause as a simple binary comparison. Existing tests have fully verified the behavior of SHOW TRANSACTION:
-- ✅ Supported syntax (binary equality comparison)
SHOW TRANSACTION WHERE id = 4005
SHOW TRANSACTION WHERE label = 'test_label'
SHOW TRANSACTION FROM db WHERE id = 4005
-- ❌ Unsupported syntax
SHOW TRANSACTION WHERE id IN (4005, 4006, 4007) -- IN clause not supported
SHOW TRANSACTION WHERE id = ANY [4005, 4006] -- Arrays not supported
SHOW TRANSACTION WHERE (id, label) = (4005, 'x') -- Tuple comparison not supported

@ccxxxyy ccxxxyy requested a review from terrymanu December 20, 2025 03:51
Copy link
Copy Markdown
Member

@terrymanu terrymanu left a comment

Choose a reason for hiding this comment

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

Here are the suggestions (hope they help—once refined it should be close to merge-ready):

  • proxy/backend/dialect/mysql/handler/admin/executor/show/MySQLShowTransactionExecutor.java currently always returns an empty result and ignores both WHERE and FROM database filtering, so it swallows the request and doesn’t solve the root need (returning transaction
    status). Please wire it to real transaction/load job data (or at least throw a clear “not supported” error instead of an empty set), and apply FROM/WHERE filtering. Add tests covering data present/absent and filter-miss cases.
  • The same executor only returns 6 columns (TransactionId, Label, Database, TransactionStatus, LoadStartTime, LoadFinishTime), which doesn’t match the Doris SHOW TRANSACTION reference (missing columns like Coordinator, LoadJobSourceType, PrepareTime, CommitTime, Reason,
    ErrorReplicasCount, ListenerId, TimeoutMs, etc.). Please align the column set and types with the Doris protocol, and assert column names/types in tests to avoid client compatibility issues.
  • MySQLShowTransactionExecutorTest only checks “empty data, metadata shape” and misses key behaviors: WHERE filtering, actual data row(s), and full column set. After wiring the logic, please add tests for ID/label filter hit/miss, with/without FROM behavior, and
    asserting a real transaction row.
  • Optional: if you can’t hook to real data yet, prefer an explicit error (e.g., UnsupportedOperationException or a user-facing message) instead of an empty result, to avoid misleading users into thinking there are no transactions.

Thanks for pushing Doris grammar and cases in the right direction—keep it up!

@terrymanu
Copy link
Copy Markdown
Member

Here’s a consolidated note to help land the next revision:

  • The implementation still stops at “parse succeeds / returns empty set”; it doesn’t address the core need of returning real SHOW TRANSACTION data—executor ignores FROM/WHERE and isn’t wired to any transaction/load-job source.
  • The returned columns don’t match the Doris protocol (missing Coordinator, LoadJobSourceType, PrepareTime/CommitTime, etc.), so clients may break.
  • Tests only cover empty data and metadata shape; they don’t cover real data, filter hit/miss, or column name/type assertions—so the bugs stay hidden.

Next steps:

  1. Wire to real data (or explicitly raise “not supported” instead of a silent empty set) and honor FROM/WHERE filters.
  2. Align column definitions (order and types) with Doris SHOW TRANSACTION.
  3. Add tests for a data row, ID/label filter hit/miss, and column name/type assertions.

@ccxxxyy
Copy link
Copy Markdown
Contributor Author

ccxxxyy commented Dec 21, 2025

@terrymanu Hi, I hope my revision can meet the requirements. Hope you can review them when you have time.

@ccxxxyy ccxxxyy requested a review from terrymanu December 21, 2025 04:19
Copy link
Copy Markdown
Member

@terrymanu terrymanu left a comment

Choose a reason for hiding this comment

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

Core reason: each revision tweaked grammar, columns, and empty-result tests but never fixed the root issue—returning real SHOW TRANSACTION data. The executor still returns an empty set, filtering is minimal (Column=Literal only) and can throw type exceptions, and tests only cover empty results/metadata, so the core functionality is missing and defects stay hidden.

Recommendation: pause coding and analyze first, instead of piling more changes:

  • Clarify requirements: where to fetch SHOW TRANSACTION data (Doris transaction/load-job source), and ensure column fields/order/types exactly match the Doris protocol.
  • Design the data path: how to obtain the transaction list from metadata/engine, how FROM/WHERE (ID/label) should affect results; if unsupported, return an explicit “not supported” error instead of an empty set.
  • Fix filtering and type handling: handle case-insensitive names, stringified numbers, non-equality cases, and avoid ClassCastException.
  • Define a test checklist: data rows, filter hit/miss, column name/type assertions, and error/unsupported paths.

Get this analysis and design straight before further coding; otherwise the PR will keep being unmergeable.

@ccxxxyy
Copy link
Copy Markdown
Contributor Author

ccxxxyy commented Dec 21, 2025

@terrymanu Hi, Thank you very much for your patient guidance. Upon thorough analysis and deliberation, I have implemented further revisions with the aim of providing a correct solution. I sincerely appreciate your comments and corrections and have made every effort to ensure the modifications comply with the requirements. Should any issues persist, I kindly request your understanding and further instructions. I would like to express my gratitude once again for your feedback and support.
Regarding the specification of "Column=Literal only," I consider this to be a potentially reasonable design. The syntax structure provided in the official documentation is: WHERE [id = <transaction_id> | label = <label_name>];

@ccxxxyy ccxxxyy requested a review from terrymanu December 21, 2025 09:51
@terrymanu
Copy link
Copy Markdown
Member

Documentation does require Column=Literal (id/label), which is reasonable, but the implementation still lacks data retrieval and strict semantic validation, so that alone doesn’t complete the fix.

@ccxxxyy
Copy link
Copy Markdown
Contributor Author

ccxxxyy commented Dec 22, 2025

@terrymanu Hi! I hope my revisions can meet the requirements. Thank you for your patient guidance. Hope you could take a look when you have a moment

@ccxxxyy
Copy link
Copy Markdown
Contributor Author

ccxxxyy commented Dec 23, 2025

@terrymanu Hi! Hope you can take a look at my latest commit when you have time. Thank you for your time. I hope the latest revision meets the requirements.

Copy link
Copy Markdown
Member

@terrymanu terrymanu left a comment

Choose a reason for hiding this comment

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

Here’s feedback for the PR author:

Key issues

  • MySQLShowTransactionExecutor#loadTransactions() just throws UnsupportedOperationException, so SHOW TRANSACTION will always fail at runtime; the root goal (supporting the statement) isn’t achieved.
  • Syntax mismatch: Doris docs specify SHOW TRANSACTION [FROM ] WHERE id=<...> | label=<...>; and require WHERE. The executor enforces WHERE (correct), but the added supported SQL includes a no-WHERE case, which will now throw IllegalArgumentException, conflicting
    with Doris syntax and your executor behavior.
  • Runtime regression: Moving from “parse unsupported” to “parse ok but always fails” is a worse user experience.

Suggestions

  1. Align syntax and cases: Drop/adjust the no-WHERE Doris SQL case; keep only forms with WHERE id=... or WHERE label=... as per docs.
  2. Implement loadTransactions(): Fetch transaction info from Doris FE (or an existing API) and populate the 12 columns; if you can’t support it yet, don’t register the executor in the factory (or return an empty result with a clear “not supported” message) to avoid
    throwing UnsupportedOperationException.
  3. Compatibility behavior: For missing/incomplete databases, return an empty result (unless syntax is invalid), matching SHOW conventions.
  4. Tests: Adjust/add cases to cover id/label filters hit/miss, remove the no-WHERE case, and validate the final behavior.
  5. If execution can’t be supported now, consider keeping only the parser-level additions (grammar/AST/assert) and explicitly not enabling the executor path to avoid confusing users.

@ccxxxyy
Copy link
Copy Markdown
Contributor Author

ccxxxyy commented Dec 24, 2025

Your guidance is very meaningful. I think I need some time at present to carefully consider the design of the solution for this part instead of starting to code immediately. When I'm confident, I'll raise a pull request again. Thank you once more for your reply.

@ccxxxyy ccxxxyy closed this Dec 24, 2025
@ccxxxyy ccxxxyy deleted the issueNo branch December 24, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants