Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay encoding nested queries #171

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/panoramix/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,19 @@ defmodule Panoramix.Query do

_ ->
# Are we creating a new query from scratch, given some kind of datasource?
%Panoramix.Query{data_source: Panoramix.Query.datasource(source)}
%Panoramix.Query{data_source: source}
end

Map.merge(query, Map.new(query_fields))
end
end

@doc nil
# exported only so that the `from` macro can call it.
def datasource(datasource) when is_binary(datasource) do
defp datasource(datasource) when is_binary(datasource) do
# We're using a named datasource as the source for the query
datasource
end

def datasource(%{type: :query, query: nested_query} = datasource) do
defp datasource(%{type: :query, query: nested_query} = datasource) do
# The datasource is a nested query. Let's convert it to JSON if needed
nested_query_json =
case nested_query do
Expand All @@ -171,7 +169,7 @@ defmodule Panoramix.Query do
%{datasource | query: nested_query_json}
end

def datasource(%{type: :join, left: left, right: right} = datasource) do
defp datasource(%{type: :join, left: left, right: right} = datasource) do
# A join between two datasources.
# A named datasource and a recursive join can only appear on the
# left side, but let's let Druid enforce that.
Expand All @@ -180,7 +178,7 @@ defmodule Panoramix.Query do
%{datasource | left: left_datasource, right: right_datasource}
end

def datasource(%{type: type} = datasource) when is_atom(type) do
defp datasource(%{type: type} = datasource) when is_atom(type) do
# Some other type of datasource. Let's include it literally.
datasource
end
Expand Down Expand Up @@ -852,7 +850,7 @@ defmodule Panoramix.Query do
analysisTypes: query.analysis_types,
bound: query.bound,
context: query.context,
dataSource: query.data_source,
dataSource: datasource(query.data_source),
dimension: query.dimension,
dimensions: query.dimensions,
filter: query.filter,
Expand Down