Skip to content

Advanced SQL Analytics Framework#9

Open
everettbu wants to merge 1 commit into
data-analysis-featuresfrom
advanced-sql-analytics
Open

Advanced SQL Analytics Framework#9
everettbu wants to merge 1 commit into
data-analysis-featuresfrom
advanced-sql-analytics

Conversation

@everettbu

@everettbu everettbu commented Jul 26, 2025

Copy link
Copy Markdown

Test 9

Summary by CodeRabbit

  • New Features

    • Introduced a new database abstraction for SQL expressions, with initial methods for listing tables, running commands, and querying data (currently not implemented).
  • Bug Fixes

    • Added a check to prevent the use of SQL expressions when the feature is disabled, providing a clear error message.
  • Chores

    • Removed several unused dependencies to streamline the application.

… vulnerability (#94942)

* disable sql expressions

remove duckdb ref

* Run `make update-workspace`

---------

Co-authored-by: Scott Lepper <scott.lepper@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 26, 2025

Copy link
Copy Markdown

Walkthrough

This change removes several dependencies from the Go module, disables SQL expressions by default via a feature gate, and introduces a new in-memory SQL database abstraction with stub methods. Related code is updated to use the new local database implementation instead of the external go-duck package.

Changes

Cohort / File(s) Change Summary
go.mod Removed multiple dependencies from the require section; no additions or replacements made.
pkg/expr/reader.go Added feature gate check for SQL expressions; SQL queries now return an error if not enabled.
pkg/expr/sql/db.go Introduced new sql package with DB struct and stubbed methods for SQL operations.
pkg/expr/sql/parser.go, pkg/expr/sql_command.go Replaced usage of external go-duck with new local sql package and updated instantiations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExpressionQueryReader
    participant SQLFeatureGate
    participant SQLDB

    User->>ExpressionQueryReader: Submit SQL query
    ExpressionQueryReader->>SQLFeatureGate: Check if SQL expressions enabled
    alt Not enabled
        SQLFeatureGate-->>ExpressionQueryReader: Return false
        ExpressionQueryReader-->>User: Return "sqlExpressions is not implemented" error
    else Enabled
        ExpressionQueryReader->>SQLDB: Execute SQL query
        SQLDB-->>ExpressionQueryReader: Return result/error
        ExpressionQueryReader-->>User: Return result/error
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

A rabbit hopped through fields of code,
Pruning old weeds where dependencies growed.
New SQL seeds, though not yet in bloom,
Await the sun in a feature-gated room.
With stubs in place and errors clear,
The garden’s ready—change is near!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch advanced-sql-analytics

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

@everettbu

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 27, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🔭 Outside diff range comments (1)
pkg/expr/sql/parser.go (1)

22-40: Function will fail due to unimplemented database methods.

The TablesList function relies on RunCommands which currently returns "not implemented" error. This will cause all SQL parsing to fail until the database methods are properly implemented.

Ensure the database implementation is completed before this code path is enabled, or add proper error handling for the transition period.

🧹 Nitpick comments (1)
pkg/expr/sql/parser.go (1)

23-23: Update variable name to reflect the new implementation.

The variable name duckDB is misleading since it no longer uses the DuckDB implementation. Consider renaming for clarity.

-	duckDB := NewInMemoryDB()
+	db := NewInMemoryDB()

And update the subsequent usage:

-	ret, err := duckDB.RunCommands([]string{cmd})
+	ret, err := db.RunCommands([]string{cmd})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbe1e7d and ea71201.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • go.mod (0 hunks)
  • pkg/expr/reader.go (2 hunks)
  • pkg/expr/sql/db.go (1 hunks)
  • pkg/expr/sql/parser.go (1 hunks)
  • pkg/expr/sql_command.go (1 hunks)
💤 Files with no reviewable changes (1)
  • go.mod
🔇 Additional comments (3)
pkg/expr/sql/db.go (1)

20-22: Verify that the QueryFramesInto signature matches the external go-duck interface

Before implementing this stub in pkg/expr/sql/db.go, please confirm that your method signature aligns exactly with the original QueryFramesInto definition in the go-duck package you’re replacing. Any mismatch in parameter order, types (e.g. missing context.Context), or return value will break compatibility.

Checklist for verification:

  • Locate the go-duck package’s QueryFramesInto interface in its source or GoDoc.

  • Compare its full signature (including any context.Context or other additional parameters) against this local stub:

    func (db *DB) QueryFramesInto(
        name string,
        query string,
        frames []*data.Frame,
        f *data.Frame,
    ) error
  • Update the local stub to match exactly (order, types, names) if there are any discrepancies.

pkg/expr/sql_command.go (1)

96-96: Good variable naming improvement.

Renaming from duckDB to db better reflects the abstracted database interface.

pkg/expr/reader.go (1)

129-132: Feature gate protects against unimplemented functionality.

The feature gate check appropriately prevents SQL queries from reaching the unimplemented database methods. However, the gate logic itself is flawed (see comment on enableSqlExpressions function).

Comment thread pkg/expr/reader.go
Comment on lines +194 to +200
func enableSqlExpressions(h *ExpressionQueryReader) bool {
enabled := !h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
if enabled {
return false
}
return false
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical logic error in feature gate implementation.

The enableSqlExpressions function has flawed logic that always returns false, effectively disabling SQL expressions unconditionally:

  1. Line 195 negates the feature flag check
  2. Both conditional branches return false
  3. SQL expressions will never be enabled regardless of the feature flag state

Fix the logic to properly respect the feature flag:

 func enableSqlExpressions(h *ExpressionQueryReader) bool {
-	enabled := !h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
-	if enabled {
-		return false
-	}
-	return false
+	return h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func enableSqlExpressions(h *ExpressionQueryReader) bool {
enabled := !h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
if enabled {
return false
}
return false
}
func enableSqlExpressions(h *ExpressionQueryReader) bool {
return h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
}
🤖 Prompt for AI Agents
In pkg/expr/reader.go around lines 194 to 200, the enableSqlExpressions function
incorrectly negates the feature flag check and returns false in all cases,
causing SQL expressions to always be disabled. Fix this by removing the negation
on the feature flag check and returning true when the feature flag is enabled,
otherwise false, so the function correctly reflects the feature flag state.

Comment thread pkg/expr/sql_command.go
Comment on lines +96 to +100
db := sql.NewInMemoryDB()
var frame = &data.Frame{}

logger.Debug("Executing query", "query", gr.query, "frames", len(allFrames))
err := duckDB.QueryFramesInto(gr.refID, gr.query, allFrames, frame)
err := db.QueryFramesInto(gr.refID, gr.query, allFrames, frame)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

SQL query execution will fail due to unimplemented database methods.

The migration from duck.NewInMemoryDB() to sql.NewInMemoryDB() replaces a working implementation with stub methods. The QueryFramesInto call on line 100 will always return "not implemented" error.

Ensure either:

  1. The database methods are implemented before enabling this code path
  2. The feature gate in reader.go properly blocks SQL queries until implementation is complete
🤖 Prompt for AI Agents
In pkg/expr/sql_command.go around lines 96 to 100, the code uses
sql.NewInMemoryDB() whose methods like QueryFramesInto are not yet implemented,
causing SQL query execution to fail. To fix this, either implement the required
database methods in sql.NewInMemoryDB before enabling this code path, or ensure
that the feature gate in reader.go correctly blocks SQL queries until these
implementations are complete.

Comment thread pkg/expr/sql/db.go
Comment on lines +9 to +26
type DB struct {
}

func (db *DB) TablesList(rawSQL string) ([]string, error) {
return nil, errors.New("not implemented")
}

func (db *DB) RunCommands(commands []string) (string, error) {
return "", errors.New("not implemented")
}

func (db *DB) QueryFramesInto(name string, query string, frames []*data.Frame, f *data.Frame) error {
return errors.New("not implemented")
}

func NewInMemoryDB() *DB {
return &DB{}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: All database methods are unimplemented stubs.

This implementation replaces the external go-duck dependency with stub methods that return "not implemented" errors. This will break existing SQL functionality until proper implementations are provided.

Consider one of the following approaches:

  1. Implement the actual database functionality before merging
  2. Add feature flags to prevent SQL queries from reaching this code
  3. Return more descriptive errors indicating the feature is temporarily disabled
 func (db *DB) TablesList(rawSQL string) ([]string, error) {
-	return nil, errors.New("not implemented")
+	return nil, errors.New("SQL expressions are temporarily disabled - implementation in progress")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type DB struct {
}
func (db *DB) TablesList(rawSQL string) ([]string, error) {
return nil, errors.New("not implemented")
}
func (db *DB) RunCommands(commands []string) (string, error) {
return "", errors.New("not implemented")
}
func (db *DB) QueryFramesInto(name string, query string, frames []*data.Frame, f *data.Frame) error {
return errors.New("not implemented")
}
func NewInMemoryDB() *DB {
return &DB{}
}
func (db *DB) TablesList(rawSQL string) ([]string, error) {
return nil, errors.New("SQL expressions are temporarily disabled - implementation in progress")
}
🤖 Prompt for AI Agents
In pkg/expr/sql/db.go from lines 9 to 26, all database methods are currently
unimplemented stubs returning generic "not implemented" errors, which will break
SQL functionality. To fix this, either implement the actual database logic for
these methods before merging, or add feature flags to disable SQL query
execution through this code path. Alternatively, update the error messages to
clearly indicate that the feature is temporarily disabled to improve clarity for
users.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions!

@github-actions github-actions Bot added the stale label Aug 27, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it has not had any further activity in the last 2 weeks. Thank you for your contributions!

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