Skip to content

Conversation

@everettbu
Copy link

Test 9

… vulnerability (#94942)

* disable sql expressions

remove duckdb ref

* Run `make update-workspace`

---------

Co-authored-by: Scott Lepper <[email protected]>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR implements an "Advanced SQL Analytics Framework" for Grafana's expression system by replacing an external DuckDB dependency with an internal SQL implementation. The changes remove the github.com/scottlepp/go-duck dependency and several related packages, introducing a new internal SQL engine structure.

The core changes include:

  • New SQL DB Interface: Added pkg/expr/sql/db.go with a DB struct that defines methods for SQL operations (TablesList, RunCommands, QueryFramesInto)
  • SQL Command Integration: Modified pkg/expr/sql_command.go to use the new internal sql.NewInMemoryDB() instead of the external DuckDB implementation
  • SQL Parser Updates: Updated pkg/expr/sql/parser.go to use the new internal DB for SQL analysis
  • Feature Flag Protection: Added feature flag checking in pkg/expr/reader.go with enableSqlExpressions() function
  • Dependency Cleanup: Removed DuckDB-related dependencies from go.mod and updated workspace dependencies in go.work.sum

This change represents a strategic shift from relying on external SQL engines to building custom SQL analytics capabilities within Grafana's expression system. The framework is designed to work with Grafana's existing data frame processing pipeline and supports SQL queries over time series data.

Confidence score: 0/5

  • This PR will cause immediate runtime failures and completely break SQL expression functionality
  • All SQL operations now return "not implemented" errors, making the feature non-functional despite maintaining the API surface
  • Critical logic bugs in feature flag implementation and missing return statements will cause additional failures
  • Files need immediate attention: pkg/expr/sql/db.go, pkg/expr/sql_command.go, pkg/expr/reader.go, pkg/expr/sql/parser.go

6 files reviewed, 5 comments

Edit Code Review Bot Settings | Greptile

// TablesList returns a list of tables for the sql statement
func TablesList(rawSQL string) ([]string, error) {
duckDB := duck.NewInMemoryDB()
duckDB := NewInMemoryDB()
Copy link

Choose a reason for hiding this comment

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

logic: This now calls a stub implementation that always returns 'not implemented' error, breaking SQL parsing functionality

// TablesList returns a list of tables for the sql statement
func TablesList(rawSQL string) ([]string, error) {
duckDB := duck.NewInMemoryDB()
duckDB := NewInMemoryDB()
Copy link

Choose a reason for hiding this comment

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

logic: This now calls a stub implementation that always returns 'not implemented' error, breaking SQL parsing functionality

Comment on lines +20 to +22
func (db *DB) QueryFramesInto(name string, query string, frames []*data.Frame, f *data.Frame) error {
return errors.New("not implemented")
}
Copy link

Choose a reason for hiding this comment

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

logic: This method is called directly by SQLCommand.Execute() but always fails, breaking SQL expressions when enabled

}

func enableSqlExpressions(h *ExpressionQueryReader) bool {
enabled := !h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
Copy link

Choose a reason for hiding this comment

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

logic: Logic error: The double negation here means enabled will be true when the feature flag is OFF, which is counterintuitive

Suggested change
enabled := !h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)
enabled := h.features.IsEnabledGlobally(featuremgmt.FlagSqlExpressions)

// TablesList returns a list of tables for the sql statement
func TablesList(rawSQL string) ([]string, error) {
duckDB := duck.NewInMemoryDB()
duckDB := NewInMemoryDB()
Copy link

Choose a reason for hiding this comment

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

logic: This now calls a stub implementation that always returns 'not implemented' error, breaking SQL parsing functionality

Comment on lines +196 to +199
if enabled {
return false
}
return false
Copy link

Choose a reason for hiding this comment

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

logic: This function always returns false regardless of feature flag state. If this is intentional to disable the feature, add a comment explaining why

Suggested change
if enabled {
return false
}
return false
if enabled {
return true
}
return false

Comment on lines 25 to 26
cmd := fmt.Sprintf("SELECT json_serialize_sql('%s')", rawSQL)
ret, err := duckDB.RunCommands([]string{cmd})
Copy link

Choose a reason for hiding this comment

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

logic: The json_serialize_sql function is specific to DuckDB and won't work with the stub implementation

Comment on lines +12 to +14
func (db *DB) TablesList(rawSQL string) ([]string, error) {
return nil, errors.New("not implemented")
}
Copy link

Choose a reason for hiding this comment

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

logic: This method is called by sql.TablesList() in parser.go but always fails, preventing SQL query validation

@github-actions
Copy link
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
Copy link
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!

@github-actions github-actions bot closed this Sep 12, 2025
@everettbu everettbu reopened this Sep 12, 2025
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

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