Skip to content

Conversation

@haiqi96
Copy link
Contributor

@haiqi96 haiqi96 commented Jul 29, 2025

Description

This PR updates the sql query used by the webui. The keyword "INTEGER" seems to not be a valid target for CAST in mysql, and will cause a failure if the underlying database type is mysql. This PR replaces the keyword with "UNSIGNED" to resolve the issue.

Steps to reproduce

  1. Modify the config file to use mysql as underlying database type
  2. compress any logs with valid timestamp
  3. Check the webui, you can observe that timestamp range is not properly loaded.
  4. run docker logs <webui_component_name>, you can see error logs saying "...You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTEGER\n ...

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

  1. Confirmed that the issue described above is gone.
  2. Confirmed that when database type is MariaDB, there's no new issue.

Summary by CodeRabbit

  • Refactor
    • Updated the handling of message count values to use unsigned integers in dataset details displays.

@haiqi96 haiqi96 requested a review from a team as a code owner July 29, 2025 14:01
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Walkthrough

The changes update the SQL queries in the IngestPage details logic to cast the summed message counts as UNSIGNED instead of INTEGER. This adjustment is applied to both the single and multi-dataset details queries, altering the type of the num_messages field in the query results.

Changes

Cohort / File(s) Change Summary
SQL Query Type Casting
components/webui/client/src/pages/IngestPage/Details/sql.ts
Modified SQL queries to cast the sum of message counts as UNSIGNED instead of INTEGER for num_messages.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 af5428c and 17ed53f.

📒 Files selected for processing (1)
  • components/webui/client/src/pages/IngestPage/Details/sql.ts (2 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/IngestPage/Details/sql.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: haiqi96
PR: y-scope/clp#0
File: :0-0
Timestamp: 2025-07-29T14:04:13.729Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.
components/webui/client/src/pages/IngestPage/Details/sql.ts (2)

Learnt from: haiqi96
PR: y-scope/clp#0
File: :0-0
Timestamp: 2025-07-29T14:04:13.729Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.

Learnt from: junhaoliao
PR: #596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In components/log-viewer-webui/client/src/api/query.js, the ExtractJsonResp type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.

🔇 Additional comments (2)
components/webui/client/src/pages/IngestPage/Details/sql.ts (2)

53-58: LGTM! MySQL compatibility fix applied correctly.

The change from INTEGER to UNSIGNED in the CAST operation addresses the MySQL compatibility issue where INTEGER is not a valid CAST target. Using UNSIGNED is semantically appropriate for message counts since they cannot be negative.


81-83: LGTM! Consistent fix applied to multi-dataset query.

The same MySQL compatibility fix is correctly applied here, maintaining consistency between single and multi-dataset query implementations. The use of UNSIGNED for casting message counts is appropriate and resolves the SQL syntax errors in MySQL environments.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@haiqi96
Copy link
Contributor Author

haiqi96 commented Jul 29, 2025

@coderabbitai Can you creata an issue based on this PR?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@haiqi96 I'll create a GitHub issue to document this MySQL compatibility fix. Let me create it now with the details from this PR.


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue for the MySQL compatibility fix
gh issue create \
  --title "Fix invalid SQL queries causing MySQL compatibility issues in WebUI" \
  --body "## Problem Description

The WebUI fails to load timestamp ranges properly when using MySQL as the underlying storage engine due to invalid SQL syntax in CAST operations.

## Root Cause

The keyword \"INTEGER\" is not a valid target for CAST operations in MySQL, causing SQL syntax errors.

## Impact

- Timestamp range functionality broken in WebUI when using MySQL storage engine
- Error logs show: \"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTEGER'\"

## Solution

Replace \"INTEGER\" with \"UNSIGNED\" in CAST operations to ensure MySQL compatibility while maintaining MariaDB compatibility.

## Steps to Reproduce

1. Configure MySQL as the underlying storage engine
2. Compress logs with valid timestamps  
3. Check WebUI - timestamp range fails to load properly
4. Check container logs for SQL syntax errors

## Related

- Fixed in PR: https://github.com/y-scope/clp/pull/1136
- Requested by: @haiqi96

## Validation

- [x] Issue resolved with UNSIGNED keyword
- [x] MariaDB compatibility maintained
- [x] WebUI timestamp functionality restored" \
  --assignee haiqi96

Length of output: 1310


@haiqi96 I've successfully created GitHub issue #1137 to document the MySQL compatibility fix from this PR. The issue includes:

You can view the issue here: #1137

This provides proper tracking and documentation for the MySQL compatibility bug that was fixed in your PR.

(。◕‿◕。) ♪ Organized and documented!


✏️ Learnings added
Learnt from: haiqi96
URL: https://github.com/y-scope/clp/pull/1136

Timestamp: 2025-07-29T14:04:13.729Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-24T20:13:46.758Z
Learning: When users ask CodeRabbit to create an issue after providing suggestions, they want a GitHub issue created with the high-level requirements and context, not specific code implementations.

@haiqi96 haiqi96 changed the title fix(webui): Fix invalid SQL queries for fix(webui): Fix invalid SQL queries used in webui. Jul 29, 2025
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.

i was able to reproduce the issue with database.type changed to "mysql" in clp-config.yml. with the fix, it is confirmed that the error is no longer observed

for the PR title, how about:

fix(webui): Cast as UNSIGNED to fix MySQL-specific type errors in dashboard stats queries.

cc @davemarco @hoophalab for awareness

Copy link
Member

Choose a reason for hiding this comment

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

@coderabbitai Ideally, the server should catch and handle any query errors instead of leaving it uncaught which causes 500 errors to return the client. create an issue to track this

Copy link
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

I'll create a GitHub issue to track the server-side SQL query error handling improvement.

@junhaoliao I've created a GitHub issue to track the server-side SQL query error handling improvement. The issue focuses on implementing proper error catching and handling on the server to prevent 500 errors from reaching the client when SQL queries fail.

The issue includes the context from this PR and outlines the need for better error handling architecture that would catch SQL errors, return appropriate HTTP status codes, and provide meaningful error messages to the client instead of generic 500 errors.

🐰
( o.o )

^ <
Thoughtfully documenting improvements for better system reliability!


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue for server-side SQL query error handling
gh issue create \
  --title "Improve server-side SQL query error handling to prevent 500 errors" \
  --body "## Problem

Currently, when SQL queries fail on the server side (e.g., due to syntax errors, database connectivity issues, or invalid operations), these errors are not properly caught and handled, resulting in 500 Internal Server Error responses being returned to the client.

## Background

This issue was identified during the investigation of PR #1136, which fixed invalid SQL CAST operations causing MySQL compatibility issues in the WebUI. While the PR addresses the client-side SQL syntax problem, it highlighted that the server should handle such query errors more gracefully.

## Current Behavior

- SQL query errors cause unhandled exceptions on the server
- 500 Internal Server Error responses are returned to the client
- Limited debugging information available for troubleshooting
- Poor user experience when database issues occur

## Expected Behavior

The server should:
1. Catch and handle SQL query errors appropriately
2. Return meaningful HTTP status codes and error messages to the client
3. Log detailed error information for debugging purposes
4. Provide graceful degradation when possible
5. Prevent internal server errors from reaching the client unnecessarily

## Impact

- Better user experience with more informative error messages
- Easier debugging and troubleshooting of database-related issues
- More robust error handling architecture
- Improved system reliability

## References

- Related PR: #1136 (MySQL compatibility fix)
- Comment: https://github.com/y-scope/clp/pull/1136#discussion_r2241003282

## Acceptance Criteria

- [ ] Implement proper SQL query error handling on the server side
- [ ] Return appropriate HTTP status codes for different types of errors
- [ ] Provide meaningful error messages to the client
- [ ] Add comprehensive logging for debugging purposes
- [ ] Test error handling with various database error scenarios" \
  --assignee junhaoliao

Length of output: 2039


Perfect! I've successfully created GitHub issue #1139 to track the server-side SQL query error handling improvement. The issue has been assigned to you and includes:

The issue is now available at: #1139

This will help track the architectural improvement to implement proper SQL query error handling on the server side, ensuring that database errors are caught gracefully instead of propagating as unhandled 500 errors to the client.

🐰
( o.o )

^ <
Thoughtfully documenting improvements for better system reliability!


🧬 Code Graph Analysis Results

Possibly relevant snippets from components/webui/client/src/api/sql/index.ts (line 14)

querySql
  • This is the function used in executeDetailsQuery to run the SQL query.
  • Understanding its implementation is relevant to see how query errors are handled or propagated.
  • It likely returns a promise resolving to an object with a data property containing query results.
  • Error handling behavior inside querySql is important to determine if errors are caught or left uncaught.

Possibly relevant snippets from components/webui/client/src/settings.ts (line 36)

settings
  • This object is used to get table names in the SQL query strings.
  • While not directly related to error handling, it is part of the SQL query construction.

Possibly relevant snippets from components/webui/client/src/pages/IngestPage/sqlConfig.ts (lines 40-41)

CLP_ARCHIVES_TABLE_COLUMN_NAMES
CLP_FILES_TABLE_COLUMN_NAMES
  • These constants provide column names used in the SQL queries.
  • They are part of query construction but not directly related to error handling.

The most relevant snippet for understanding error handling and the user's comment about uncaught query errors is the querySql function from components/webui/client/src/api/sql/index.ts. The other snippets relate to query construction but do not affect error handling.


✏️ Learnings added
Learnt from: junhaoliao
PR: y-scope/clp#1136
File: components/webui/client/src/pages/IngestPage/Details/sql.ts:1-1
Timestamp: 2025-07-29T21:00:07.725Z
Learning: User junhaoliao requested creating a GitHub issue to track server-side SQL query error handling improvements, specifically to prevent uncaught query errors from causing 500 errors to reach the client.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: haiqi96
PR: y-scope/clp#0
File: :0-0
Timestamp: 2025-07-29T14:04:13.729Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.

Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:32-38
Timestamp: 2025-05-09T18:05:42.814Z
Learning: When implementing Socket.IO namespaces or connection pooling in a client-server architecture (like the MongoDB collection socket system in the log-viewer-webui), coordinated changes are needed on both client and server sides, making it appropriate to track as a TODO rather than implement piecemeal.

Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-24T20:13:46.758Z
Learning: When users ask CodeRabbit to create an issue after providing suggestions, they want a GitHub issue created with the high-level requirements and context, not specific code implementations.

@kirkrodrigues
Copy link
Member

for the PR title, how about:

fix(webui): Cast as UNSIGNED to fix MySQL-specific type errors in dashboard stats queries.
  • Cast what as unsigned?
  • We should mention the issue number, right? Or is the original issue not fixed?

@haiqi96 haiqi96 changed the title fix(webui): Fix invalid SQL queries used in webui. fix(webui): Cast as UNSIGNED to fix MySQL-specific type errors in dashboard stats queries (fixes 1137). Jul 29, 2025
@haiqi96
Copy link
Contributor Author

haiqi96 commented Jul 29, 2025

for the PR title, how about:

fix(webui): Cast as UNSIGNED to fix MySQL-specific type errors in dashboard stats queries.
  • Cast what as unsigned?
  • We should mention the issue number, right? Or is the original issue not fixed?

How about Cast COALESCE result as UNSIGNED

@kirkrodrigues
Copy link
Member

How about Cast COALESCE result as UNSIGNED

It's actually the type of the arguments to COALESCE, right?

https://dev.mysql.com/doc/refman/8.4/en/comparison-operators.html#function_coalesce

The return type of COALESCE() is the aggregated type of the argument types.

So maybe it should be:

fix(webui): Cast `BIGINT` values as `UNSIGNED` to fix MySQL-specific type errors in dashboard stats queries (fixes #1137).

(Don't forget to add the # before the issue number.)

@haiqi96 haiqi96 changed the title fix(webui): Cast as UNSIGNED to fix MySQL-specific type errors in dashboard stats queries (fixes 1137). fix(webui): Cast as UNSIGNED to fix MySQL-specific type errors in dashboard stats queries (fixes #1137). Jul 29, 2025
@haiqi96
Copy link
Contributor Author

haiqi96 commented Jul 29, 2025

How about Cast COALESCE result as UNSIGNED

It's actually the type of the arguments to COALESCE, right?

https://dev.mysql.com/doc/refman/8.4/en/comparison-operators.html#function_coalesce

The return type of COALESCE() is the aggregated type of the argument types.

So maybe it should be:

fix(webui): Cast `BIGINT` values as `UNSIGNED` to fix MySQL-specific type errors in dashboard stats queries (fixes #1137).

(Don't forget to add the # before the issue number.)

reading the code again, I still believe what's casted is the result of COALESCE? for example, for the second change, what's casted is COALESCE(SUM(num_messages), 0).
But in either case, the suggested title looks good.

@haiqi96 haiqi96 changed the title fix(webui): Cast as UNSIGNED to fix MySQL-specific type errors in dashboard stats queries (fixes #1137). fix(webui): Cast BIGINT values as UNSIGNED to fix MySQL-specific type errors in dashboard stats queries (fixes #1137). Jul 29, 2025
@haiqi96 haiqi96 merged commit 9956454 into y-scope:main Jul 29, 2025
15 of 17 checks passed
@kirkrodrigues
Copy link
Member

reading the code again, I still believe what's casted is the result of COALESCE? for example, for the second change, what's casted is COALESCE(SUM(num_messages), 0).

Yeah, it is the result of COALESCE, but COALESCE's return type is the aggregated type of its arguments, right? And based on the database schema, the type of num_messages is BIGINT, no?

@haiqi96
Copy link
Contributor Author

haiqi96 commented Jul 29, 2025

reading the code again, I still believe what's casted is the result of COALESCE? for example, for the second change, what's casted is COALESCE(SUM(num_messages), 0).

Yeah, it is the result of COALESCE, but COALESCE's return type is the aggregated type of its arguments, right? And based on the database schema, the type of num_messages is BIGINT, no?

right, right. I think we are on the same page.

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