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

Do not treat interpolated expressions as identifiers #115

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions java/com/metabase/macaw/AstWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ public void visit(OverlapsCondition overlapsCondition) {

@Override
public <S> T visit(Column tableColumn, S context) {
// Ignore nested queries. In the future, we could do a nested part of them and merge the results.
if (tableColumn.getColumnName().startsWith("$$")) {
return null;
}
invokeCallback(COLUMN, tableColumn);

Table table = tableColumn.getTable();
Expand Down
2 changes: 1 addition & 1 deletion java/com/metabase/macaw/BasicTableExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static Set<Table> getTables(PlainSelect select) {
tables.add(table);
} else if (item instanceof TableFunction) {
// Do not allow dynamic tables
throw new AnalysisError(AnalysisErrorType.INVALID_QUERY);
throw new AnalysisError(AnalysisErrorType.UNSUPPORTED_EXPRESSION);
} else {
// Only allow simple table references.
throw new AnalysisError(AnalysisErrorType.UNSUPPORTED_EXPRESSION);
Expand Down
2 changes: 1 addition & 1 deletion java/com/metabase/macaw/CompoundTableExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static void accTables(PlainSelect select, Set<Table> tables, Stack<Set<S
}
} else if (item instanceof TableFunction) {
// Do not allow dynamic tables
throw new AnalysisError(AnalysisErrorType.INVALID_QUERY);
throw new AnalysisError(AnalysisErrorType.UNSUPPORTED_EXPRESSION);
Comment on lines 127 to +128
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Decided to leave this open, there may be a safe subset we choose to support in future.

} else if (item instanceof Select) {
accTables((Select) item, tables, cteAliasScopes);
} else if (item != null) {
Expand Down
1 change: 1 addition & 0 deletions test/macaw/acceptance_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,6 @@
(test-fixture :compound/cte-nonambiguous)
(test-fixture :literal/with-table)
(test-fixture :literal/without-table)
(test-fixture :interpolation/crosstab)

(test-fixture :broken/filter-where))
10 changes: 10 additions & 0 deletions test/resources/acceptance/interpolation__crosstab.analysis.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{:tables [{:table "history"}]
:source-columns [{:table "history" :column "id"}
{:table "history" :column "page"}
{:table "history" :column "h_timestamp"}]
:overrides
{:ast-walker-1
{:tables []
:source-columns []}
Comment on lines +6 to +8
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This walker does its best to return a superset, for better or worse, so it keeps chugging along.

Given the later concerns about false positives, we may want to change this in future.

:basic-select :macaw.error/unsupported-expression
:compound-select :macaw.error/unsupported-expression}}
20 changes: 20 additions & 0 deletions test/resources/acceptance/interpolation__crosstab.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT * FROM crosstab($$

SELECT
history.page,
date_trunc('month', history.h_timestamp)::DATE,
count(history.id) as total
FROM history
WHERE h_timestamp between '2024-01-01' and '2024-12-01'
GROUP BY page, date_trunc('month', history.h_timestamp)
$$,

$$
SELECT
date_trunc('month', generate_series('2024-01-01', '2024-02-01', '1 month'::INTERVAL))::DATE
$$
) AS ct(
page INTEGER,
"Jan" FLOAT,
"Feb" FLOAT
)
Loading