jiangxt2 commented on code in PR #58117:
URL: https://github.com/apache/spark/pull/58117#discussion_r4002363233


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/bitmapExpressions.scala:
##########
@@ -375,6 +383,83 @@ case class BitmapXor(left: Expression, right: Expression) 
extends BitmapBinaryEx
     copy(left = newLeft, right = newRight)
 }
 
+@ExpressionDescription(
+  usage = """
+    _FUNC_(bitmap, bit_position) - Returns true if the bit at the given 
bucket-local position is
+    set in the bitmap, false otherwise.
+  """,
+  arguments = """
+    Arguments:
+      * bitmap - The bitmap to test.
+        An expression that evaluates to a binary. A NULL bitmap produces a 
NULL result.
+      * bit_position - The bucket-local bit position to test.
+        An expression that evaluates to a numeric value and is cast to a long. 
A NULL position
+        produces a NULL result. A negative position, a position at or above 
32768, or a position
+        beyond the actual bitmap length returns false. To query an original 
value, use
+        bitmap_bit_position(value) and match bitmap_bucket_number(value) to 
the bitmap bucket.
+  """,
+  examples = """
+    Examples:
+      > SELECT _FUNC_(X '01', 0L);
+       true
+      > SELECT _FUNC_(X '01', 1L);
+       false
+      > SELECT _FUNC_(X '10', 4L);
+       true
+  """,
+  since = "4.4.0",
+  group = "misc_funcs")
+case class BitmapContains(left: Expression, right: Expression)
+  extends BinaryExpression with RuntimeReplaceable {
+
+  override def checkInputDataTypes(): TypeCheckResult = {
+    if (left.dataType != BinaryType && left.dataType != NullType) {
+      DataTypeMismatch(
+        errorSubClass = "UNEXPECTED_INPUT_TYPE",
+        messageParameters = Map(
+          "paramIndex" -> ordinalNumber(0),
+          "requiredType" -> toSQLType(BinaryType),
+          "inputSql" -> toSQLExpr(left),
+          "inputType" -> toSQLType(left.dataType)
+        )
+      )
+    } else if (!right.dataType.isInstanceOf[NumericType] && right.dataType != 
NullType) {
+      DataTypeMismatch(
+        errorSubClass = "UNEXPECTED_INPUT_TYPE",
+        messageParameters = Map(
+          "paramIndex" -> ordinalNumber(1),
+          "requiredType" -> toSQLType(LongType),
+          "inputSql" -> toSQLExpr(right),
+          "inputType" -> toSQLType(right.dataType)
+        )
+      )
+    } else {
+      TypeCheckSuccess
+    }
+  }
+
+  override def dataType: DataType = BooleanType
+
+  override def prettyName: String = "bitmap_contains"
+
+  override lazy val replacement: Expression = {
+    // StaticInvoke needs an exact BinaryType child, including for a bare NULL 
literal.
+    val bitmap = if (left.dataType == NullType) Cast(left, BinaryType) else 
left
+    StaticInvoke(
+      classOf[BitmapExpressionUtils],
+      BooleanType,
+      "bitmapContains",
+      Seq(bitmap, Cast(right, LongType)),

Review Comment:
   Thanks @cloud-fan. Addressed in commit `d8406f3835f`.
   
   - Aligned interpreted `InvokeLike` and `NewInstance` argument evaluation 
with `prepareArguments`, so later arguments are skipped after a 
result-determining NULL while preserving existing behavior on normal and 
`propagateNull = false` paths.
   - Added `StaticInvoke` and `NewInstance` regression coverage, and updated 
the bitmap test to force both `CODEGEN_ONLY` and `NO_CODEGEN` for a NULL bitmap 
paired with an ANSI-mode cast overflow.
   - Updated the PR description to remove the stale head/CI statement and 
document the new parity coverage.
   
   Validation passed: Catalyst suites (318 tests total), 
`BitmapExpressionsQuerySuite` (29 tests), `DatasetSuite` (222 tests), and 
Catalyst/SQL Scalastyle checks.
   
   Please take another look when convenient.



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

Reply via email to