Skip to content

Conversation

@msmithstubbs
Copy link
Contributor

@msmithstubbs msmithstubbs commented Jan 15, 2026

Allows users to select which backend to run a query again.

  • Adds a backends dropdown to the /query view
  • Warns user when the query uses a source with out a configured backend
  • Support in /api/query
  • Requests to /api/query accept an optional backend_id.
  • When backend_id and sql params are used the sql dialect will be inferred from the selected backend.
    • If no backend is specified the default is BigQuery with BigQuery SQL dialect.
    • If the request includes ach_sql, pg_sql, or bq_sql param this determines the sql dialect used.
CleanShot 2026-01-15 at 16 40 42@2x

Error messages

An backend error from running a query is rendered in the UI under the form. Format is slightly different depending on how the backend returns errors:

CleanShot 2026-01-28 at 11 49 09@2x

@msmithstubbs msmithstubbs force-pushed the feat/query-clickhouse-backend branch 2 times, most recently from 4ab1b8c to ab3be59 Compare January 20, 2026 02:43
@msmithstubbs msmithstubbs changed the title wip: backend dropdown for /query view feat: backend dropdown for /query view Jan 20, 2026
@msmithstubbs msmithstubbs marked this pull request as ready for review January 20, 2026 04:34
Comment on lines 171 to 175
expect(ClickHouseAdaptor, :execute_query, fn _backend, query, _opts ->
assert {~S|SELECT now() AS "my_time"|, _, _, %{language: :ch_sql}} = query

{:ok, [%{"my_time" => "123"}]}
end)
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't stub if can, ideally we run it against the test CH backend with test setup for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done,

test "?sql= with backend_id uses backend's language", %{conn: conn, user: user} do
backend = insert(:backend, user: user, type: :clickhouse)

expect(ClickHouseAdaptor, :execute_query, fn _backend, query, _opts ->
Copy link
Contributor

Choose a reason for hiding this comment

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

as below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and done.

@spec validate_backend_sources(Query.t(), Backend.t(), String.t()) :: :ok | {:error, String.t()}
defp validate_backend_sources(%Query{backend_id: nil}, _backend, _query_string), do: :ok

defp validate_backend_sources(
Copy link
Contributor

Choose a reason for hiding this comment

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

i think instead of validating, since this can become quite complex, we just let the error propagate to the user as an error message, either as a flash or an alert (which might be more readable).
if a table doesn't exist then it should be quite self-explanatory that something is not configured right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, and query run error is now rendered under the form.

Copy link
Contributor

@Ziinc Ziinc left a comment

Choose a reason for hiding this comment

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

overall changes look good, just hesitant on the validation logic, looks very heavy for what we need.

@msmithstubbs msmithstubbs marked this pull request as draft January 28, 2026 01:50
@msmithstubbs msmithstubbs force-pushed the feat/query-clickhouse-backend branch from d7ef484 to 1220945 Compare January 28, 2026 01:52
@msmithstubbs msmithstubbs force-pushed the feat/query-clickhouse-backend branch from 1220945 to ed361c0 Compare January 28, 2026 04:58
{"lib/logflare_web/controllers/stripe_controller.ex", :pattern_match_cov},
{"lib/logflare_web/live/billingaccount_live/payment_method_component.ex", :call},
{"lib/logflare_web/live/monaco_editor_component.ex", :pattern_match},
{"lib/logflare_web/live/endpoints/endpoints_live.ex", :unused_fun},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to get test typings to pass.

@msmithstubbs msmithstubbs marked this pull request as ready for review January 28, 2026 05:13
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