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

fix(core): fix join with group by #446

Merged
merged 2 commits into from
Sep 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public boolean hasAlias() {

@Override
public boolean hasSinglePrefix() {
if (!subQuery.isSimpleQuery()) {
return false;
}

if (hasAlias()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public void initFreeVariables() {
public List<Pair<String, String>> getSubQueryAliasList(String alias) {
return leftQuery.getSubQueryAliasList(alias);
}

@Override
public boolean isSimpleQuery() {
return leftQuery.isSimpleQuery() && rightQuery.isSimpleQuery();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public void addFreeVariable(String freeVariable) {

public abstract List<Pair<String, String>> getSubQueryAliasList(String alias);

public abstract boolean isSimpleQuery();

public enum SelectStatementType {
UNARY,
BINARY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ public void setSlideDistance(long slideDistance) {
this.groupByClause.setSlideDistance(slideDistance);
}

@Override
public boolean isSimpleQuery() {
return groupByClause.getQueryType() == QueryType.SimpleQuery;
}

public QueryType getQueryType() {
return groupByClause.getQueryType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,21 @@ public void testJoinWithGroupBy() {
+ "+-----+----+\n"
+ "Total line number = 1\n";
executor.executeAndCompare(query, expected);

query =
"select test1.d, sum(avg_a) from test1 join (select d, avg(a) as avg_a from test2 group by d) on test1.d = test2.d group by test1.d;";
expected =
"ResultSets:\n"
+ "+-------+----------+\n"
+ "|test1.d|sum(avg_a)|\n"
+ "+-------+----------+\n"
+ "| val5| 2.0|\n"
+ "| val3| 2.0|\n"
+ "| val2| 4.0|\n"
+ "| val1| 4.0|\n"
+ "+-------+----------+\n"
+ "Total line number = 4\n";
executor.executeAndCompare(query, expected);
}

@Test
Expand Down
Loading