Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Fix execution of queries over analyst tables. #4494

Merged
merged 4 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.1.3
20.1.4
4 changes: 2 additions & 2 deletions air/docs/book.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"author": "Aircloak GmbH",
"description": "This copy of the Aircloak user guide describes the features of, and how to configure and work with Aircloak Insights version 20.1.3.",
"description": "This copy of the Aircloak user guide describes the features of, and how to configure and work with Aircloak Insights version 20.1.4.",
"gitbook": "3.2.2",
"language": "en",
"plugins": [
Expand All @@ -13,5 +13,5 @@
"styles": {
"website": "styles/website.css"
},
"title": "Aircloak User Guide – version 20.1.3"
"title": "Aircloak User Guide – version 20.1.4"
}
2 changes: 1 addition & 1 deletion air/docs/content/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---- This way the mix task compiling the docs will be able to insert the current
---- version number when it changes.
---- Please check the automatically adjusted header into version control.
## Aircloak Insights - version 20.1.3
## Aircloak Insights - version 20.1.4
---- Please only cautiously edit the line above.

- [Introduction](README.md)
Expand Down
6 changes: 6 additions & 0 deletions air/lib/air_web/templates/changelog/changelog.html.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 20.1.4

### Bugfixes

- Fixed invalid optimization when executing queries over analyst tables.

## Version 20.1.3

### Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion cloak/lib/cloak/sql/compiler/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ defmodule Cloak.Sql.Compiler.Helpers do
|> function.()
|> update_in(
[Query.Lenses.direct_subqueries(opts) |> Lens.key(:ast)],
&apply_top_down(&1, function)
&apply_top_down(&1, function, opts)
)

@doc "Runs the given function for its side-effects on the given query and all of its subqueries."
Expand Down
2 changes: 1 addition & 1 deletion cloak/lib/cloak/sql/compiler/noise_layers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ defmodule Cloak.Sql.Compiler.NoiseLayers do
{_, nil} ->
index = Enum.find_index(all_expressions, expression_matcher)
true = index != nil
%Expression{expression | alias: "#{prefix()}#{index}"}
%Expression{expression | alias: "#{prefix()}#{index}", synthetic?: true}

{_, _} ->
existing_expression
Expand Down
32 changes: 32 additions & 0 deletions cloak/test/cloak/query/noise_layer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,38 @@ defmodule Cloak.Query.NoiseLayerTest do
assert_analyst_table_consistent(query, subquery)
end

test "[Issue #4492] analyst table with multiple select *" do
:ok = insert_rows(_user_ids = 1..10, "noise_layers", ["number", "other"], [10, 10])

query = "SELECT count(*) FROM (SELECT * FROM $subquery) t"

subquery = """
SELECT * FROM (
SELECT user_id, number
FROM noise_layers
GROUP BY 1, 2
) t
"""

assert_analyst_table_consistent(query, subquery)
end

test "[Issue #4490] analyst table with select * and unselected grouping" do
:ok = insert_rows(_user_ids = 1..10, "noise_layers", ["number"], [10])

query = "SELECT count(*) FROM $subquery"

subquery = """
SELECT * FROM (
SELECT user_id
FROM noise_layers
GROUP BY user_id, number
) t
"""

assert_analyst_table_consistent(query, subquery)
end

def assert_analyst_table_consistent(query, subquery) do
regular_query = query |> String.replace("$subquery", "(#{subquery}) AS foo")
analyst_query = query |> String.replace("$subquery", "foo")
Expand Down