zabetak commented on code in PR #4356:
URL: https://github.com/apache/hive/pull/4356#discussion_r1211484999
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/parser/Filter.g:
##########
@@ -549,7 +549,6 @@ DateLiteral
TimestampLiteral
:
KW_TIMESTAMP '\'' TimestampString '\'' { extractTimestamp(getText()) !=
null }?
- | TimestampString { extractTimestamp(getText()) != null }?
Review Comment:
I am wondering if we could retain the support for unquoted literals and at
the same time be backwards compatible by combining the `DateLiteral` and
`TimestampLiteral` together.
```
DateTimeLiteral
:
KW_TIMESTAMP '\'' TimestampString '\'' { extractTimestamp(getText()) !=
null }?
| TimestampString { extractTimestamp(getText()) != null }?
| KW_DATE '\'' DateString '\'' { extractDate(getText()) != null }?
| DateString { extractDate(getText()) != null }?
;
```
This may also allow us to refactor and reduce duplication in other parser
rules inside `Filter.g`.
Is it possible/ Does it make sense?
##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestPartFilterExprUtil.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.hadoop.hive.metastore;
+
+import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.parser.ExpressionTree;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Category(MetastoreUnitTest.class)
+public class TestPartFilterExprUtil {
+
+ @Test
+ public void testMakeExpressionTreeWhenDateLiteralTypeIsNotSpecified() throws
MetaException {
+ ExpressionTree expressionTree = PartFilterExprUtil.makeExpressionTree("(j
= 1990-11-10 or j = 1990-11-11 or j = 1990-11-12)");
+ assertThat(expressionTree.getRoot().toString(),
is("TreeNode{lhs=TreeNode{lhs=LeafNode{keyName='j', operator='=',
value=1990-11-10}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=1990-11-11}}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=1990-11-12}}"));
+ }
+
+ @Test
+ public void testMakeExpressionTreeWhenDateLiteralIsQuoted() throws
MetaException {
+ ExpressionTree expressionTree = PartFilterExprUtil.makeExpressionTree("(j
= '1990-11-10' or j = '1990-11-11' or j = '1990-11-12')");
+ assertThat(expressionTree.getRoot().toString(),
is("TreeNode{lhs=TreeNode{lhs=LeafNode{keyName='j', operator='=',
value=1990-11-10}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=1990-11-11}}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=1990-11-12}}"));
+ }
+
+ @Test
+ public void testMakeExpressionTreeWhenDateLiteralTypeIsSpecified() throws
MetaException {
+ ExpressionTree expressionTree = PartFilterExprUtil.makeExpressionTree("(j)
IN (DATE'1990-11-10', DATE'1990-11-11', DATE'1990-11-12')");
+ assertThat(expressionTree.getRoot().toString(),
is("TreeNode{lhs=TreeNode{lhs=LeafNode{keyName='j', operator='=',
value=1990-11-10}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=1990-11-11}}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=1990-11-12}}"));
+ }
+
+ @Test
+ public void testMakeExpressionTreeWhenTimestampLiteralTypeIsSpecified()
throws MetaException {
+ ExpressionTree expressionTree = PartFilterExprUtil.makeExpressionTree("(j)
IN (TIMESTAMP'2000-01-01 01:00:00', TIMESTAMP'2000-01-01 01:42:00')");
+ assertThat(expressionTree.getRoot().toString(),
is("TreeNode{lhs=LeafNode{keyName='j', operator='=', value=2000-01-01
01:00:00.0}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=2000-01-01 01:42:00.0}}"));
+ }
+
+ @Test
+ public void testMakeExpressionTreeWhenTimestampLiteralIsQuoted() throws
MetaException {
Review Comment:
Even if we decide to drop support for unquoted timestamp literals we may
want to add a test case that asserts that an exception is raised in that case.
##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestPartFilterExprUtil.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.hadoop.hive.metastore;
+
+import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.parser.ExpressionTree;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Category(MetastoreUnitTest.class)
+public class TestPartFilterExprUtil {
+
+ @Test
+ public void testMakeExpressionTreeWhenDateLiteralTypeIsNotSpecified() throws
MetaException {
+ ExpressionTree expressionTree = PartFilterExprUtil.makeExpressionTree("(j
= 1990-11-10 or j = 1990-11-11 or j = 1990-11-12)");
+ assertThat(expressionTree.getRoot().toString(),
is("TreeNode{lhs=TreeNode{lhs=LeafNode{keyName='j', operator='=',
value=1990-11-10}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=1990-11-11}}, andOr='OR', rhs=LeafNode{keyName='j', operator='=',
value=1990-11-12}}"));
+ }
+
+ @Test
+ public void testMakeExpressionTreeWhenDateLiteralIsQuoted() throws
MetaException {
+ ExpressionTree expressionTree = PartFilterExprUtil.makeExpressionTree("(j
= '1990-11-10' or j = '1990-11-11' or j = '1990-11-12')");
Review Comment:
This is parsed as a `StringLiteral` right? Probably we don't care but don't
know if we want to make this visible/assertable (inventing words) in the test.
##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestPartFilterExprUtil.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.hadoop.hive.metastore;
+
+import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.parser.ExpressionTree;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Category(MetastoreUnitTest.class)
+public class TestPartFilterExprUtil {
Review Comment:
In terms of test coverage we may want to add a test for each category of
operator expressions:
```
operatorExpression
:
betweenExpression
|
inExpression
|
multiColInExpression
|
binOpExpression
;
```
So far I see that we have for `inExpression` and `binOpExpression` but not
for the rest.
Basically I would suggest the following matrix:
operator expressions X date variants + operator expressions X timestamp
variants = 4 X 3 + 4 X 3 = 24 tests in total; optionally we can mix in some
AND/ORs if we want.
Making the test parameterized may reduce some boiler plate but not a must do
just a simple suggestion.
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartFilterExprUtil.java:
##########
@@ -101,7 +102,8 @@ public static PartitionExpressionProxy
createExpressionProxy(Configuration conf)
* @param filter Filter.
* @return Expression tree. Null if there was an error.
*/
- private static ExpressionTree makeExpressionTree(String filter) throws
MetaException {
+ @VisibleForTesting
+ static ExpressionTree makeExpressionTree(String filter) throws MetaException
{
Review Comment:
Instead of changing the visibility here maybe we could just use
`FilterParser getFilterParser(String filter)` in the unit test, which is
already public.
##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestPartFilterExprUtil.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.hadoop.hive.metastore;
+
+import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.parser.ExpressionTree;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Category(MetastoreUnitTest.class)
+public class TestPartFilterExprUtil {
Review Comment:
Since we are focusing on dates and timestamps maybe we should rename the
class accordingly; don't feel strongly about it do as you feel.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]