-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
add parsing for AT TIME ZONE #9477
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.sql.parsers.parser; | ||
|
||
import java.util.Arrays; | ||
import org.apache.calcite.sql.SqlKind; | ||
import org.apache.calcite.sql.SqlNode; | ||
import org.apache.calcite.sql.SqlSpecialOperator; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
import org.apache.calcite.sql.type.OperandTypes; | ||
import org.apache.calcite.sql.type.SqlTypeFamily; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
|
||
public class SqlAtTimeZone extends SqlSpecialOperator { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets model it similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has special syntax (it's not the usual |
||
|
||
public static final SqlAtTimeZone INSTANCE = new SqlAtTimeZone(); | ||
|
||
private SqlAtTimeZone() { | ||
super( | ||
"AT_TIME_ZONE", | ||
SqlKind.OTHER_FUNCTION, | ||
32, // put this at the same precedence as LIKE (see SqlLikeOperator) | ||
false, | ||
opBinding -> opBinding.getTypeFactory().createSqlType(SqlTypeName.TIMESTAMP), | ||
null, | ||
OperandTypes.family(SqlTypeFamily.TIME) | ||
); | ||
} | ||
|
||
@Override | ||
public ReduceResult reduceExpr(int ordinal, TokenSequence list) { | ||
SqlNode left = list.node(ordinal - 1); | ||
SqlNode right = list.node(ordinal + 1); | ||
return new ReduceResult(ordinal - 1, | ||
ordinal + 2, | ||
createCall( | ||
SqlParserPos.sum( | ||
Arrays.asList(requireNonNull(left, "left").getParserPosition(), | ||
requireNonNull(right, "right").getParserPosition(), | ||
list.pos(ordinal))), | ||
left, | ||
right)); | ||
} | ||
} |
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 we need to check this. can't it be something like
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 modeled this after the LIKE syntax which has that check - I'm not 100% sure why they added that restriction, because I checked Postgres and
SELECT (SELECT str FROM foo) LIKE 'foo' FROM foo;
works and so does nestedAT TIME ZONE
like your example query.I tried these in Pinot, though, and it looks like there are other limitations that prevent us from doing that...
SELECT (SELECT str FROM foo) LIKE 'foo' FROM foo;
returns the following exception in Pinot:If you feel strongly, I can remove the check, but it won't work either way without additional work (which I think we can address in a follow-up if desired)
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.
for now it should be fine. since this should probably go back to calcite we can adjust later