This is an automated email from the ASF dual-hosted git repository.
dkuzmenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 2185a2f77e0 HIVE-28343: Iceberg: WHERE clause support in OPTIMIZE
TABLE command (Zoltan Ratkai, reviewed by Attila Turoczy, Dmitriy Fingerman,
Denys Kuzmenko)
2185a2f77e0 is described below
commit 2185a2f77e0555263de667eec480395f526a0609
Author: Zoltan Ratkai <[email protected]>
AuthorDate: Wed Sep 25 16:52:18 2024 +0200
HIVE-28343: Iceberg: WHERE clause support in OPTIMIZE TABLE command (Zoltan
Ratkai, reviewed by Attila Turoczy, Dmitriy Fingerman, Denys Kuzmenko)
Closes #5455
---
.../hadoop/hive/ql/parse/AlterClauseParser.g | 4 +-
.../hive/ql/parse/TestParseOptimizeTable.java | 55 ++++++++++++++++++++++
2 files changed, 57 insertions(+), 2 deletions(-)
diff --git
a/parser/src/java/org/apache/hadoop/hive/ql/parse/AlterClauseParser.g
b/parser/src/java/org/apache/hadoop/hive/ql/parse/AlterClauseParser.g
index 60283282c9b..2c95009529f 100644
--- a/parser/src/java/org/apache/hadoop/hive/ql/parse/AlterClauseParser.g
+++ b/parser/src/java/org/apache/hadoop/hive/ql/parse/AlterClauseParser.g
@@ -114,8 +114,8 @@ optimizeTableStatementSuffix
optimizeTblRewriteDataSuffix
@init { gParent.msgs.push("compaction request"); }
@after { gParent.msgs.pop(); }
- : KW_REWRITE KW_DATA
- -> ^(TOK_ALTERTABLE_COMPACT Identifier["'MAJOR'"] TOK_BLOCKING)
+ : KW_REWRITE KW_DATA whereClause?
+ -> ^(TOK_ALTERTABLE_COMPACT Identifier["'MAJOR'"] TOK_BLOCKING
whereClause?)
;
alterStatementPartitionKeyType
diff --git
a/parser/src/test/org/apache/hadoop/hive/ql/parse/TestParseOptimizeTable.java
b/parser/src/test/org/apache/hadoop/hive/ql/parse/TestParseOptimizeTable.java
new file mode 100644
index 00000000000..1f37f2252f8
--- /dev/null
+++
b/parser/src/test/org/apache/hadoop/hive/ql/parse/TestParseOptimizeTable.java
@@ -0,0 +1,55 @@
+/*
+ * 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.ql.parse;
+
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class TestParseOptimizeTable {
+ ParseDriver parseDriver = new ParseDriver();
+ private static final String EXPECTED_WHERE_FILTER = "\n" +
+ "nil\n" +
+ " TOK_ALTERTABLE\n" +
+ " TOK_TABNAME\n" +
+ " tbl0\n" +
+ " TOK_ALTERTABLE_COMPACT\n" +
+ " 'MAJOR'\n" +
+ " TOK_BLOCKING\n" +
+ " TOK_WHERE\n" +
+ " and\n" +
+ " TOK_FUNCTION\n" +
+ " in\n" +
+ " TOK_TABLE_OR_COL\n" +
+ " col01\n" +
+ " 'A'\n" +
+ " 'B'\n" +
+ " <\n" +
+ " TOK_TABLE_OR_COL\n" +
+ " col02\n" +
+ " '2024-09-17 00:00:00'\n" +
+ " <EOF>\n";
+ @Test
+ public void testOptimizeTableWithWhere() throws Exception {
+
+ ASTNode tree = parseDriver.parse(
+ " optimize table tbl0 rewrite data where (col01 in ('A', 'B') and
col02 < '2024-09-17 00:00:00')", null).getTree();
+ assertThat(tree.dump(), is(EXPECTED_WHERE_FILTER));
+ }
+}