This is an automated email from the ASF dual-hosted git repository.
zabetak 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 964d706d9fe HIVE-29765: HiveBetween#unparse ignores negated flag
(#6637)
964d706d9fe is described below
commit 964d706d9fe45c69ec7018d8c015c57a30d3231f
Author: Ruben Quesada Lopez <[email protected]>
AuthorDate: Thu Aug 6 14:34:15 2026 +0100
HIVE-29765: HiveBetween#unparse ignores negated flag (#6637)
---
.../calcite/reloperators/HiveBetween.java | 9 ++++
.../calcite/reloperators/TestHiveBetween.java | 61 ++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveBetween.java
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveBetween.java
index 03ab2fcad3b..92d6ad3780d 100644
---
a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveBetween.java
+++
b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveBetween.java
@@ -40,6 +40,11 @@ public class HiveBetween extends SqlSpecialOperator {
public static final SqlSpecialOperator INSTANCE =
new HiveBetween();
+ /**
+ * Ordinal of the 'negated flag' operand (if enabled, the BETWEEN is
inverted: NOT BETWEEN).
+ */
+ public static final int NEGATED_FLAG_OPERAND = 0;
+
/**
* Ordinal of the 'value' operand.
*/
@@ -104,6 +109,10 @@ public void unparse(
final SqlWriter.Frame frame =
writer.startList(SqlWriter.FrameTypeEnum.create("BETWEEN"), "", "");
call.operand(VALUE_OPERAND).unparse(writer, getLeftPrec(), 0);
+ final SqlLiteral negatedFlag = call.operand(NEGATED_FLAG_OPERAND);
+ if (negatedFlag.booleanValue()) {
+ writer.sep("NOT");
+ }
writer.sep(super.getName());
// If the expression for the lower bound contains a call to an AND
diff --git
a/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/TestHiveBetween.java
b/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/TestHiveBetween.java
new file mode 100644
index 00000000000..b570efb885f
--- /dev/null
+++
b/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/TestHiveBetween.java
@@ -0,0 +1,61 @@
+/*
+ * 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.optimizer.calcite.reloperators;
+
+import org.apache.calcite.sql.SqlBasicCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNumericLiteral;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.pretty.SqlPrettyWriter;
+
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestHiveBetween {
+
+ private static final SqlParserPos POS = SqlParserPos.ZERO;
+
+ @Test
+ public void testUnparseBetween() {
+ assertEquals("col BETWEEN 10 AND 20", unparse(false, "col", 10L, 20L));
+ }
+
+ @Test
+ public void testUnparseNotBetween() {
+ assertEquals("field NOT BETWEEN 30 AND 40", unparse(true, "field", 30L,
40L));
+ }
+
+ private static String unparse(boolean negated, String name, long lower, long
upper) {
+ List<SqlNode> operands = List.of(
+ SqlLiteral.createBoolean(negated, POS), // operand 0: negated flag
+ new SqlIdentifier(name, POS), // operand 1: value
+
SqlNumericLiteral.createExactNumeric(BigDecimal.valueOf(lower).toString(),
POS), // operand 2: lower
+
SqlNumericLiteral.createExactNumeric(BigDecimal.valueOf(upper).toString(), POS)
// operand 3: upper
+ );
+ SqlBasicCall call = new SqlBasicCall(HiveBetween.INSTANCE, operands, POS);
+ SqlPrettyWriter writer = new
SqlPrettyWriter(SqlPrettyWriter.config().withQuoteAllIdentifiers(false));
+ HiveBetween.INSTANCE.unparse(writer, call, 0, 0);
+ return writer.toString();
+ }
+}