This is an automated email from the ASF dual-hosted git repository.

gortiz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 87ea7c8d66 Fix default value handling in REGEXP_EXTRACT transform 
function (#14489)
87ea7c8d66 is described below

commit 87ea7c8d66b2f488a57ec3039b0835c91d2516cf
Author: Yash Mayya <yash.ma...@gmail.com>
AuthorDate: Thu Nov 21 17:27:54 2024 +0700

    Fix default value handling in REGEXP_EXTRACT transform function (#14489)
---
 .../function/RegexpExtractTransformFunction.java         |  6 +++---
 .../transform/function/RegexpTransformFunctionTest.java  | 16 ++++++++++++++--
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/RegexpExtractTransformFunction.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/RegexpExtractTransformFunction.java
index ba0d7042a5..732a9c93b1 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/RegexpExtractTransformFunction.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/RegexpExtractTransformFunction.java
@@ -81,10 +81,10 @@ public class RegexpExtractTransformFunction extends 
BaseTransformFunction {
     }
 
     if (arguments.size() == 4) {
-      TransformFunction positionFunction = arguments.get(3);
-      Preconditions.checkState(positionFunction instanceof 
LiteralTransformFunction,
+      TransformFunction defaultValueTransformFunction = arguments.get(3);
+      Preconditions.checkState(defaultValueTransformFunction instanceof 
LiteralTransformFunction,
           "`default_value` must be a literal expression.");
-      _defaultValue = ((LiteralTransformFunction) 
regexpFunction).getStringLiteral();
+      _defaultValue = ((LiteralTransformFunction) 
defaultValueTransformFunction).getStringLiteral();
     } else {
       _defaultValue = "";
     }
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/RegexpTransformFunctionTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/RegexpTransformFunctionTest.java
index cded64d11a..370d6c93f5 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/RegexpTransformFunctionTest.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/RegexpTransformFunctionTest.java
@@ -41,8 +41,20 @@ public class RegexpTransformFunctionTest extends 
BaseTransformFunctionTest {
     for (int i = 0; i < NUM_ROWS; i++) {
       Matcher matcher = PATTERN.matcher(_stringSVValues[i]);
       Assert.assertEquals(
-          matcher.find() && matcher.groupCount() >= group ? 
matcher.group(group) : defaultValue,
-          actualValues[i]);
+          actualValues[i],
+          matcher.find() && matcher.groupCount() >= group ? 
matcher.group(group) : defaultValue
+      );
+    }
+  }
+
+  @Test
+  public void testDefaultValue() {
+    String expressionStr = String.format("REGEXP_EXTRACT(%s, '%s', 1, 
'null')", STRING_SV_COLUMN, "nonMatchingRegex");
+    ExpressionContext expression = 
RequestContextUtils.getExpression(expressionStr);
+    TransformFunction transformFunction = 
TransformFunctionFactory.get(expression, _dataSourceMap);
+    String[] actualValues = 
transformFunction.transformToStringValuesSV(_projectionBlock);
+    for (int i = 0; i < NUM_ROWS; i++) {
+      Assert.assertEquals(actualValues[i], "null");
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to