Skip to content

Conversation

@davemarco
Copy link
Contributor

@davemarco davemarco commented Oct 31, 2025

Description

Adds monaco markers to single line editor. Markers are generated using ANTLR grammar. Errors show up as red underline for the user. Grammar is different for each SQL field

Screenshot 2025-11-04 at 1 19 41 PM

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Red lines show up under parsing error

Summary by CodeRabbit

  • New Features
    • Real-time SQL validation added to SELECT, WHERE and ORDER BY inputs — highlights syntax and semantic issues as you type with precise location markers.
    • Validation now shows improved, more accurate column-range highlighting for reported errors and updates as input changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2025

Walkthrough

Adds client-side SQL validation: SqlInput gains a validateFn prop and editor ref to apply Monaco markers; sql-parser now exposes three validators returning ValidationError[] (select, boolean, sort); Select, Where, and OrderBy components pass the appropriate validators into SqlInput.

Changes

Cohort / File(s) Summary
SqlInput component
components/webui/client/src/components/SqlInput/index.tsx
Replaced props with new SqlInputProps that include optional validateFn. Added editorRef, set editor instance on ready, and a useEffect to run validateFn on editorProps.value changes, converting returned ValidationError[] to Monaco markers (or clearing markers). Spread remaining editorProps into SqlEditor. Exported SqlInputProps.
SQL parser validators & types
components/webui/client/src/sql-parser/index.ts
Added ValidationError type and internal setupParser. Replaced previous single validate flow with three public validators: validateSelectItemList, validateBooleanExpression, validateSortItemList. Introduced SyntaxErrorListener that accumulates ValidationError objects using token-based start/end column logic. Removed in-builder validation from buildSearchQuery/buildTimelineQuery and updated exports to include the new validators and ValidationError.
GuidedControls integrations
components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/Select.tsx, components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/Where.tsx, components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/OrderBy.tsx
Each component imports its corresponding validator from sql-parser and passes it as validateFn to SqlInput to enable inline validation for SELECT, WHERE, and ORDER BY inputs respectively.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant SqlInput as SqlInput (wrapper)
    participant Editor as Monaco Editor (model)
    participant Validator as Validator Function

    User->>SqlInput: Type or update SQL text
    SqlInput->>SqlInput: useEffect detects value change
    SqlInput->>Editor: Get model & current text
    alt validateFn present and text non-empty
        SqlInput->>Validator: validateFn(sqlString)
        Validator-->>SqlInput: ValidationError[]
        SqlInput->>Editor: Map errors to Monaco markers and setModelMarkers
    else no validateFn or empty text
        SqlInput->>Editor: Clear Monaco markers
    end
    Editor-->>User: Render diagnostics/markers
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • Inspect components/webui/client/src/sql-parser/index.ts for correct error collection, token start/end column calculations, and exported validator signatures.
  • Verify components/webui/client/src/components/SqlInput/index.tsx for editor ref lifecycle, useEffect dependencies, safe model access, and proper marker mapping/cleanup.
  • Confirm Select.tsx, Where.tsx, and OrderBy.tsx correctly import and pass validators and that ValidationError aligns with Monaco marker fields.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding SQL syntax error highlighting to guided UI inputs using ANTLR parsing in the Presto SQL components.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8799f54 and ec83aef.

📒 Files selected for processing (1)
  • components/webui/client/src/components/SqlInput/index.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit configuration file

  • Prefer false == <expression> rather than !<expression>.

Files:

  • components/webui/client/src/components/SqlInput/index.tsx
🧠 Learnings (1)
📚 Learning: 2025-06-09T17:48:56.024Z
Learnt from: junhaoliao
Repo: y-scope/clp PR: 988
File: components/log-viewer-webui/client/src/components/QueryBox/InputWithCaseSensitive/CaseSenstiveToggle.tsx:34-37
Timestamp: 2025-06-09T17:48:56.024Z
Learning: In the y-scope/clp project, prefer `false == <expression>` rather than `!<expression>` for boolean expressions in TypeScript/JavaScript files, as specified in the coding guidelines.

Applied to files:

  • components/webui/client/src/components/SqlInput/index.tsx
🧬 Code graph analysis (1)
components/webui/client/src/components/SqlInput/index.tsx (3)
components/webui/client/src/components/SqlEditor/index.tsx (2)
  • SqlEditorProps (144-144)
  • SqlEditorType (145-145)
components/webui/client/src/sql-parser/index.ts (1)
  • ValidationError (254-254)
components/webui/common/src/utility-types.ts (1)
  • Nullable (3-3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: package-image
  • GitHub Check: lint-check (ubuntu-24.04)
  • GitHub Check: lint-check (macos-15)
🔇 Additional comments (5)
components/webui/client/src/components/SqlInput/index.tsx (5)

18-23: LGTM! Type definition is clear and well-structured.

The SqlInputProps type correctly extends SqlEditorProps and adds the optional validation function with appropriate typing.


31-37: LGTM! Props handling and ref management are correctly implemented.

The component signature, prop destructuring, and editor ref initialization follow React best practices. Storing the editor instance enables the validation effect to access the Monaco API.


63-96: LGTM! Validation logic is correct and follows coding guidelines.

The validation effect correctly:

  • Uses explicit null checks per coding guidelines (lines 66, 71, 78)
  • Clears markers for empty or unvalidated input
  • Maps ValidationError fields to Monaco IMarkerData accurately
  • Depends on the correct values (editorProps.value and validateFn)

The implementation properly integrates SQL validation with Monaco editor markers.


132-132: LGTM! Props forwarding is correctly implemented.

Spreading editorProps instead of the original props correctly excludes validateFn from being passed down to SqlEditor, which doesn't recognize that prop.


137-137: LGTM! Type export enables proper typing in consuming components.

Exporting SqlInputProps allows parent components (Select, Where, OrderBy) to correctly type their props when passing validators.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@davemarco davemarco requested a review from hoophalab November 4, 2025 18:16
@davemarco davemarco marked this pull request as ready for review November 4, 2025 18:16
@davemarco davemarco requested a review from a team as a code owner November 4, 2025 18:16
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f24600 and 57edfd4.

⛔ Files ignored due to path filters (2)
  • components/webui/client/src/sql-parser/generated/SqlLexer.ts is excluded by !**/generated/**
  • components/webui/client/src/sql-parser/generated/SqlParser.ts is excluded by !**/generated/**
📒 Files selected for processing (6)
  • components/webui/client/src/components/SqlInput/index.tsx (3 hunks)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/OrderBy.tsx (2 hunks)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/Select.tsx (2 hunks)
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/Where.tsx (2 hunks)
  • components/webui/client/src/sql-parser/Sql.g4 (1 hunks)
  • components/webui/client/src/sql-parser/index.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit configuration file

  • Prefer false == <expression> rather than !<expression>.

Files:

  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/Where.tsx
  • components/webui/client/src/components/SqlInput/index.tsx
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/OrderBy.tsx
  • components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/Select.tsx
  • components/webui/client/src/sql-parser/index.ts
🧬 Code graph analysis (3)
components/webui/client/src/components/SqlInput/index.tsx (2)
components/webui/client/src/components/SqlEditor/index.tsx (2)
  • SqlEditorProps (144-144)
  • SqlEditorType (145-145)
components/webui/client/src/sql-parser/index.ts (1)
  • ValidationError (249-249)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/OrderBy.tsx (1)
components/webui/client/src/sql-parser/index.ts (1)
  • validateSortItemList (243-243)
components/webui/client/src/sql-parser/index.ts (1)
components/webui/client/src/sql-parser/generated/SqlParser.ts (1)
  • SqlParser (19-11121)
🪛 GitHub Actions: clp-lint
components/webui/client/src/sql-parser/index.ts

[error] 8-8: ESLint: 'Token' is defined but never used. (no-unused-vars)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: package-image
🔇 Additional comments (13)
components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/OrderBy.tsx (2)

3-3: LGTM!

The import is correctly sourced and aligns with the new validation architecture.


28-28: LGTM!

The validator is correctly wired into SqlInput, enabling client-side validation for ORDER BY expressions.

components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/Where.tsx (2)

3-3: LGTM!

The import is correctly sourced from the sql-parser module.


28-28: LGTM!

The validator integration enables real-time syntax validation for WHERE clause expressions.

components/webui/client/src/pages/SearchPage/SearchControls/Presto/GuidedControls/Select.tsx (2)

3-3: LGTM!

The import is correctly sourced and follows the established pattern.


28-28: LGTM!

The validator correctly enables syntax validation for SELECT item lists.

components/webui/client/src/sql-parser/Sql.g4 (1)

5-23: LGTM!

The grammar rules correctly define standalone parsing contexts for SELECT items, boolean expressions, and sort items. The EOF markers ensure complete input validation, which is essential for guided UI controls.

components/webui/client/src/components/SqlInput/index.tsx (3)

2-10: LGTM!

The additional imports support the validation feature correctly.


17-22: LGTM!

The type definition is well-structured and properly documented.


30-60: LGTM!

The editor reference management is correctly implemented for validation purposes.

components/webui/client/src/sql-parser/index.ts (3)

22-28: LGTM!

The ValidationError interface is well-structured and provides all necessary fields for editor markers.


42-48: Verify column calculations for Monaco compatibility.

The column calculation logic uses 1-based indexing, which is correct for Monaco editor. However, ensure that e.offendingToken.start and e.offendingToken.stop represent character positions (not token indices) and that the +1 and +2 adjustments produce the expected highlighting ranges in the editor.


87-136: LGTM!

The setupParser helper and three validator functions are well-structured and follow a consistent pattern. The validators correctly invoke the corresponding ANTLR grammar rules for standalone expression validation.

@davemarco
Copy link
Contributor Author

still dependent on previous PR being merged after release, but I think @hoophalab u can start looking at

hoophalab
hoophalab previously approved these changes Nov 5, 2025
Copy link
Contributor

@hoophalab hoophalab left a comment

Choose a reason for hiding this comment

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

lgtm. some cosmetic comments.

Validation: If a syntax error is detectable by the grammar checker, a red marker will appear in the SQL input field.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb77dad and 8799f54.

📒 Files selected for processing (1)
  • components/webui/client/src/components/SqlInput/index.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit configuration file

  • Prefer false == <expression> rather than !<expression>.

Files:

  • components/webui/client/src/components/SqlInput/index.tsx
🧠 Learnings (1)
📚 Learning: 2025-06-09T17:48:56.024Z
Learnt from: junhaoliao
Repo: y-scope/clp PR: 988
File: components/log-viewer-webui/client/src/components/QueryBox/InputWithCaseSensitive/CaseSenstiveToggle.tsx:34-37
Timestamp: 2025-06-09T17:48:56.024Z
Learning: In the y-scope/clp project, prefer `false == <expression>` rather than `!<expression>` for boolean expressions in TypeScript/JavaScript files, as specified in the coding guidelines.

Applied to files:

  • components/webui/client/src/components/SqlInput/index.tsx
🧬 Code graph analysis (1)
components/webui/client/src/components/SqlInput/index.tsx (3)
components/webui/client/src/components/SqlEditor/index.tsx (2)
  • SqlEditorProps (144-144)
  • SqlEditorType (145-145)
components/webui/client/src/sql-parser/index.ts (1)
  • ValidationError (254-254)
components/webui/common/src/utility-types.ts (1)
  • Nullable (3-3)
🪛 GitHub Actions: clp-lint
components/webui/client/src/components/SqlInput/index.tsx

[warning] 2-2: Run autofix to sort these imports! simple-import-sort/imports


[error] 8-8: There should be no space after '{' @stylistic/object-curly-spacing


[error] 8-8: There should be no space before '}' @stylistic/object-curly-spacing

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: package-image
🔇 Additional comments (3)
components/webui/client/src/components/SqlInput/index.tsx (3)

19-24: LGTM!

The type definition is well-structured with clear documentation. The optional validateFn prop maintains backward compatibility while enabling the new validation feature.


32-34: LGTM!

The props destructuring cleanly separates the validation function from editor props, and the ref is properly typed with Nullable<SqlEditorType>.


138-138: LGTM!

Exporting SqlInputProps allows consumers to properly type their components when using the validateFn prop.

Comment on lines +2 to +6
import {
useCallback,
useEffect,
useRef,
} from "react";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix import sorting to resolve pipeline failure.

The pipeline reports an import sorting violation that must be resolved before merge.

Run the autofix command to sort the imports:

npm run lint:fix

Or manually reorder if needed.

🧰 Tools
🪛 GitHub Actions: clp-lint

[warning] 2-2: Run autofix to sort these imports! simple-import-sort/imports

🤖 Prompt for AI Agents
In components/webui/client/src/components/SqlInput/index.tsx around lines 2 to
6, import statements are not sorted which triggers the lint pipeline; run the
autofix to reorder imports (npm run lint:fix) or manually reorder the imports to
match the project's ESLint/organize-imports rules (group external packages, then
local imports, alphabetize within groups), save the file, and commit the change
to clear the import-sorting violation.

Comment on lines +64 to +97
// Validate SQL and update markers whenever value changes
useEffect(() => {
const editor = editorRef.current;
if (null === editor) {
return;
}

const model = editor.getModel();
if (null === model) {
return;
}

const value = editorProps.value ?? "";

// Clear markers if no validation function or empty/whitespace-only input
if ("undefined" === typeof validateFn || "" === value.trim()) {
monaco.editor.setModelMarkers(model, "sql-parser", []);

return;
}

const errors = validateFn(value);
const markers: monaco.editor.IMarkerData[] = errors.map((error) => ({
endColumn: error.endColumn,
endLineNumber: error.line,
message: error.message,
severity: monaco.MarkerSeverity.Error,
startColumn: error.startColumn,
startLineNumber: error.line,
}));

monaco.editor.setModelMarkers(model, "sql-parser", markers);
}, [editorProps.value,
validateFn]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

LGTM with optional error-handling suggestion.

The validation logic correctly applies Monaco markers and follows the coding guidelines with explicit comparisons. The useEffect dependencies are accurate.

Optionally, consider wrapping the validator call in a try-catch to handle unexpected parse errors gracefully:

     const errors = validateFn(value);
+    try {
+        errors = validateFn(value);
+    } catch (e) {
+        console.error("Validation failed:", e);
+        return;
+    }
     const markers: monaco.editor.IMarkerData[] = errors.map((error) => ({

This would prevent the component from crashing if the validator throws an unexpected error.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In components/webui/client/src/components/SqlInput/index.tsx around lines 64 to
97, the call to validateFn(value) is not guarded against runtime exceptions
which could crash the component; wrap the validator invocation in a try-catch,
on error log or report the exception (e.g., console.error or a telemetry call),
clear any existing markers via monaco.editor.setModelMarkers(model,
"sql-parser", []) and return so the component remains stable, and keep the
existing marker-setting logic in the try block for successful validations.

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

deferring to @hoophalab 's review

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.

3 participants