Skip to content

[CALCITE-5416] RelToSql converter generates invalid code when merging…#2997

Closed
JiajunBernoulli wants to merge 4 commits intoapache:mainfrom
JiajunBernoulli:CALCITE-5416
Closed

[CALCITE-5416] RelToSql converter generates invalid code when merging…#2997
JiajunBernoulli wants to merge 4 commits intoapache:mainfrom
JiajunBernoulli:CALCITE-5416

Conversation

@JiajunBernoulli
Copy link
Contributor

… rollup and sort clauses

+ "GROUP BY ROLLUP(\"product_class_id\", \"brand_name\")\n"
+ "ORDER BY \"product_class_id\", \"brand_name\"";
final String expectedMysql = "SELECT `product_class_id`, `brand_name`\n"
final String expectedMysql = "SELECT *\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

That is probably excessive - if order of grouping fields matches the order of sort fields, we can omit ORDER BY clause (as it was done in the old solution).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I restored to old solution. Thanks for your review.

Copy link
Contributor

@julianhyde julianhyde left a comment

Choose a reason for hiding this comment

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

LGTM, with the suggestions I made.

Also, improve the commit message and bug summary. Mention MySQL, JDBC adapter, GROUP BY WITH ROLLUP, ORDER BY.

SqlSelect sqlSelect = result.subSelect();
SqlNodeList sortExps = exprList(builder.context, e.getSortExps());
sqlSelect.setOrderBy(sortExps);
SqlNode offset = e.offset == null ? null : builder.context.toSql(null, e.offset);
Copy link
Contributor

Choose a reason for hiding this comment

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

for offset and fetch I think if would be clearer than ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, if is clearer.

final Builder builder =
visitAggregate(aggregate, ImmutableList.copyOf(groupList),
visitAggregate(aggregate,
rollupList,
Copy link
Contributor

Choose a reason for hiding this comment

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

put rollupList on previous line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

groupList.add(aggregate.getGroupSet().nth(fc.getFieldIndex()));
}
groupList.addAll(Aggregate.Group.getRollup(aggregate.getGroupSets()));
boolean isImplicitlySort = rollupList.subList(0, sortList.size()).equals(sortList);
Copy link
Contributor

Choose a reason for hiding this comment

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

should be final

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't have this consciousness before, thank you for letting me learn.

return result;
}
// It does not allow "WITH ROLLUP" in combination with "ORDER BY",
// so generate the grouped result apply ORDER BY to it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change "It" to "MySQL"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

…"(GROUP BY x, y WITH ROLLUP) ORDER BY y, x" for MySQL 5
@JiajunBernoulli
Copy link
Contributor Author

JiajunBernoulli commented Dec 19, 2022

LGTM, with the suggestions I made.

Also, improve the commit message and bug summary. Mention MySQL, JDBC adapter, GROUP BY WITH ROLLUP, ORDER BY.

Thanks for your review.

julianhyde pushed a commit to julianhyde/calcite that referenced this pull request Feb 10, 2023
… ROLLUP and ORDER BY clauses

JDBC adapter should convert

  SELECT ...
  GROUP BY ROLLUP(x, y)
  ORDER BY y, x

to

  SELECT ...
  FROM (SELECT ...
    GROUP BY x, y WITH ROLLUP)
  ORDER BY y, x

because MySQL 5 does not allow GROUP BY WITH ROLLUP and
ORDER BY in the same query.

Close apache#2997
@asfgit asfgit closed this in 9f91d61 Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants