Skip to content

[SPARK] Preserve multi-line statement format in Spark engine UI - #7878

Closed
cxzl25 wants to merge 2 commits into
apache:masterfrom
cxzl25:spark-ui-statement-preserve-format
Closed

cxzl25 wants to merge 2 commits into
apache:masterfrom
cxzl25:spark-ui-statement-preserve-format

Conversation

@cxzl25

@cxzl25 cxzl25 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Why are the changes needed?

The Statement column in the Kyuubi tab of the Spark UI uses Spark's description-input CSS class. Its white-space is nowrap when collapsed and normal when expanded, so line breaks and indentation are lost in both states and long multi-line SQL is hard to read.

This PR follows the description cell of Spark's SQL tab: the cell still holds the full statement truncated to one line, and multi-line statements get a +details toggle that shows the statement in its original format inside a <pre> block. It reuses Spark's UIUtils.detailsUINode, which also renders the failure reason details, so no new CSS or JS is needed. The statement table is shared by the engine page and the session page, so both are covered.

How was this patch tested?

Add UT
local test

Master

master

PR

PR

Was this patch assisted by generative AI tooling?

Assisted-by: Claude:claude-opus-5-5

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change preserving multi-line SQL formatting in the Kyuubi UI.

No open issues 🎉

What changed in this PR

Preserves multi-line SQL formatting in the Spark UI’s Kyuubi tab, covering both engine and session statement tables.

Changes:

  • Keeps the collapsed statement preview and adds expandable, preformatted details using Spark’s existing detailsUINode helper.
  • Adds a test that checks the statement appears in both the preview and a formatting-preserving <pre> block.
File Description
externals/​kyuubi-spark-sql-engine/​src/​test/​scala/​org/​apache/​spark/​ui/​EngineTabSuite.scala Adds coverage for multi-line statement rendering.
externals/​kyuubi-spark-sql-engine/​src/​main/​scala/​org/​apache/​spark/​ui/​EnginePage.scala Adds collapsible, preformatted statement details to the shared table.

Review effort: Balanced

@pan3793

pan3793 commented Nov 25, 2026

Copy link
Copy Markdown
Member

but leading spaces are still lost?

@cxzl25

cxzl25 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

but leading spaces are still lost?

Spark SQL Tab

image

Kyuubi Tab

image

@pan3793 pan3793 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for confirming! The missing indentation in the first screenshot was probably from Beeline, since KyuubiCommands.handleMultiLineCmd calls HiveStringUtils.removeComments on each line, which ends with .trim().

The change looks good overall, just two minor suggestions below.

* similar to the description cell of Spark's SQL tab.
*/
private def statementCell(statement: String): Seq[Node] = {
val isMultiline = statement.trim.indexOf('\n') >= 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Guard against null here (e.g., val stmt = Option(statement).getOrElse("")) to avoid an NPE on deserialized events in KyuubiHistoryServerPlugin; previously {event.statement} rendered null as empty text.

assert(resp.contains("Completed Statement Statistics"))
}

test("multi-line statement keeps original format in engine tab") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider also executing a single-line statement (e.g., "\nSELECT 1\n") in the same test case and asserting it does not render <pre>, so both branches of isMultiline (including .trim) are covered without an extra engine restart.

@pan3793 pan3793 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@pan3793 pan3793 closed this in dfd0f7a Nov 26, 2026
pan3793 pushed a commit that referenced this pull request Nov 26, 2026
…engine UI

### Why are the changes needed?
The Statement column in the Kyuubi tab of the Spark UI uses Spark's `description-input` CSS class. Its `white-space` is `nowrap` when collapsed and `normal` when expanded, so line breaks and indentation are lost in both states and long multi-line SQL is hard to read.

This PR follows the description cell of Spark's SQL tab: the cell still holds the full statement truncated to one line, and multi-line statements get a  `+details` toggle that shows the statement in its original format inside a `<pre>` block. It reuses Spark's `UIUtils.detailsUINode`, which also renders the failure reason details, so no new CSS or JS is needed. The statement table is shared by the engine page and the session page, so both are covered.

### How was this patch tested?
Add UT
local test

Master

<img width="4496" height="2094" alt="master" src="https://github.com/user-attachments/assets/d2ee5c5c-7189-4038-a4fb-3194c709ea07" />

PR

<img width="4496" height="2524" alt="PR" src="https://github.com/user-attachments/assets/56edecd1-b606-424e-bc4c-ab4a5678a09a" />

### Was this patch assisted by generative AI tooling?
Assisted-by: Claude:claude-opus-5-5

Closes #7878 from cxzl25/spark-ui-statement-preserve-format.

Closes #7878

149deba [sychen] address
721f4c1 [sychen] ui

Authored-by: cxzl25 <sychen@ctrip.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
(cherry picked from commit dfd0f7a)
Signed-off-by: Cheng Pan <chengpan@apache.org>
@pan3793

pan3793 commented Nov 26, 2026

Copy link
Copy Markdown
Member

Merge Summary:

Posted by merge_kyuubi_pr.py

@pan3793 pan3793 added this to the v1.12.1 milestone Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants