Skip to content

Commit

Permalink
fix(core): fix join with group by (#446)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuqing Zhu <[email protected]>
  • Loading branch information
jzl18thu and zhuyuqing authored Sep 16, 2024
1 parent 5bf1178 commit 4cbed65
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
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

0 comments on commit 4cbed65

Please sign in to comment.