-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-7310] Support the syntax SELECT * EXCLUDE(columns) #4662
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
Conversation
mihaibudiu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was fast!
|
Let's see if there are any other comments. |
|
Actually, the documentation needs to be updated: reference.md |
|
One more thing: can you add some tests with the syntax |
This case is not supported yet. I will look into how we can add support for it. |
|
I think supporting T.* EXCLUDE(...) will require some additional work. We should probably remove the LGTM label for now, as I may need to do some refactoring. |
mihaibudiu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if this can include the T.* syntax as well.
Maybe yes, I will check it. |
63ea502 to
155496e
Compare
mihaibudiu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the changes in a separate commit would have made this a bit easier to review
site/_docs/reference.md
Outdated
| * A scalar value has length 1; | ||
| * The length of array or object is the number of elements is contains. | ||
|
|
||
| ### Babel parser extensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you instead add the new rule to the grammar and make this a note after the grammar rule is described?
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| /** | ||
| * Represents {@code SELECT * EXCLUDE(...)} when parsed by the Babel parser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that the Babel parser (only) uses this class should probably not be part of the Javadoc of this class.
| } | ||
|
|
||
| @Override public void validate(SqlValidator validator, SqlValidatorScope scope) { | ||
| // Babel already validates the exclude list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems odd, what if someone wants to use this outside of Babel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted this empty override of the validate method.
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
Show resolved
Hide resolved
|
|
||
| private static boolean matchesExcludeNames(List<String> columnNames, | ||
| List<String> excludeNames, SqlNameMatcher nameMatcher) { | ||
| if (excludeNames.size() > columnNames.size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this right even if there are duplicates?
or have duplicates been checked elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EXCLUDE list is compared item by item, and duplicates are also included. Additionally, there is a Boolean type for identification, so no extra consideration for duplicates is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you are returning after comparing only lengths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this should be a comparison between column names and fully qualified names. For example, [deptno] (in excludeNames) and [emp.deptno] (in columnNames).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So each list is a qualified identifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, excludeNamescan be either [deptno] or [emp, deptno], while columnNameswould be [emp, deptno] or [emp, empno].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make this clearer in the name of the arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in cb1be43
| return false; | ||
| } | ||
| for (SqlNode node : excludeList) { | ||
| if (!(node instanceof SqlIdentifier)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this can never happen, so this can perhaps be an assertion?
Yes, because it was basically a major refactoring, I force-pushed it. Then do you think it's better to let the default parser have this capability without distinguishing Babel separately? |
|
No, I think it's fine to have it in Babel, but in general I don't think a class should list in JavaDoc the places where it's used unless the class is private. After all, you don't know what other code people will write in the future using this class. |
|
Some other comments have been addressed. If I missed anything, please let me know. |
| * Represents {@code SELECT * EXCLUDE(...)}. | ||
| */ | ||
| public class SqlStarExclude extends SqlCall { | ||
| public static final SqlSpecialOperator OPERATOR = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change
public static final SqlSpecialOperator OPERATOR
to
public static final SqlOperator OPERATOR.
Also, implement the createCall method for the operator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review, I have addressed this in 6f38e07
| return ImmutableNullableList.of(starIdentifier, excludeList); | ||
| } | ||
|
|
||
| @Override public SqlNode clone(SqlParserPos pos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to override clone if operator createCall is implemented correctly
dssysolyatin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I added a few minor comments
| } | ||
|
|
||
| @Override public List<SqlNode> getOperandList() { | ||
| return ImmutableNullableList.of(starIdentifier, excludeList); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it is ImmutableNullableList and not just ImmutableList ? If I understand correctly both starIdentifier and excludeList are not nullable.
| starIdentifier.unparse(writer, leftPrec, rightPrec); | ||
| writer.sep("EXCLUDE"); | ||
| writer.print("("); | ||
| for (int i = 0; i < excludeList.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need your own unparse logic for SqlNodeList instead of using excludeList.unparse
final SqlWriter.Frame frame = writer.startList("(", ")");
excludeList.unparse(...)
writer.endList(frame)
bceaf40 to
0b84851
Compare
|
I've made some adjustments to |
|
mihaibudiu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great from my pov, if @dssysolyatin likes it we can merge it after squashing.
dssysolyatin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Feel free to merge
|
@xiedeyantu please squash the commits; feel free to merge if you want, otherwise I will do it |
0b84851 to
7783877
Compare
|
Jenkins might have some issues. Should we wait for it? |
|
Nah, jenkins can run later too |



See CALCITE-7310