bhat-vinay commented on code in PR #10947:
URL: https://github.com/apache/hudi/pull/10947#discussion_r1552838587


##########
hudi-spark-datasource/hudi-spark-common/src/test/scala/org/apache/hudi/TestRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.hudi
+
+import org.apache.hudi.common.model.HoodieRecord.HoodieMetadataField
+import org.apache.spark.sql.catalyst.expressions.{AttributeReference, EqualTo, 
Expression, FromUnixTime, In, Literal}
+import org.apache.spark.sql.types.StringType
+import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
+import org.junit.jupiter.api.Test
+
+import java.util.TimeZone
+
+class TestRecordLevelIndexSupport {
+  @Test
+  def testFilterQueryWithRecordKey(): Unit = {
+    // Case 1: EqualTo filters not on simple AttributeReference and 
non-Literal should return empty result
+    val fmt = "yyyy-MM-dd HH:mm:ss"
+    val fromUnixTime = FromUnixTime(Literal(0L), Literal(fmt), 
Some(TimeZone.getDefault.getID))
+    var testFilter: Expression = EqualTo(fromUnixTime, Literal("2020-01-01 
00:10:20"))
+    var result = RecordLevelIndexSupport.filterQueryWithRecordKey(testFilter, 
Option.empty)
+    assertTrue(result.isEmpty)
+
+    // Case 2: EqualTo filters not on Literal and not on simple 
AttributeReference should return empty result
+    testFilter = EqualTo(Literal("2020-01-01 00:10:20"), fromUnixTime)
+    result = RecordLevelIndexSupport.filterQueryWithRecordKey(testFilter, 
Option.empty)
+    assertTrue(result.isEmpty)
+
+    // Case 3: EqualTo filters on simple AttributeReference and non-Literal 
should return empty result
+    testFilter = EqualTo(AttributeReference("_row_key", StringType, nullable = 
true)(), fromUnixTime)
+    result = RecordLevelIndexSupport.filterQueryWithRecordKey(testFilter, 
Option.empty)
+    assertTrue(result.isEmpty)
+
+    // Case 4: EqualTo filters on simple AttributeReference and Literal which 
should return non-empty result
+    testFilter = EqualTo(AttributeReference("_row_key", StringType, nullable = 
true)(), Literal("row1"))
+    result = RecordLevelIndexSupport.filterQueryWithRecordKey(testFilter, 
Option.apply(HoodieMetadataField.RECORD_KEY_METADATA_FIELD.getFieldName))
+    assertTrue(result.isDefined)
+    assertEquals(result, Option.apply(testFilter, List.apply("row1")))
+
+    // case 5: EqualTo on fields other than record key should return empty 
result
+    result = RecordLevelIndexSupport.filterQueryWithRecordKey(testFilter, 
Option.apply("blah"))
+    assertTrue(result.isEmpty)
+
+    // Case 6: In filter on fields other than record key should return empty 
result
+    testFilter = In(AttributeReference("_row_key", StringType, nullable = 
true)(), List.apply(Literal("xyz"), Literal("abc")))
+    result = RecordLevelIndexSupport.filterQueryWithRecordKey(testFilter, 
Option.apply("blah"))
+    assertTrue(result.isEmpty)
+
+    // Case 7: In filter on record key should return non-empty result

Review Comment:
   `NOT IN` is not really supported by RLI based file pruning today. Hence it 
should all return empty result. Added a few negative tests



-- 
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]

Reply via email to