mirror of
https://github.com/apache/druid.git
synced 2025-02-28 06:19:13 +00:00
fix regexp_like, contains_string, icontains_string to return null instead of false for null inputs in sql compatible mode (#15963)
This commit is contained in:
parent
2b23d0b5b5
commit
48b8d42698
@ -71,7 +71,7 @@ class ContainsExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
|
||||
|
||||
if (s == null) {
|
||||
// same behavior as regexp_like.
|
||||
return ExprEval.ofLongBoolean(false);
|
||||
return ExprEval.ofLong(null);
|
||||
} else {
|
||||
final boolean doesContain = searchFunction.apply(s);
|
||||
return ExprEval.ofLongBoolean(doesContain);
|
||||
|
@ -74,7 +74,7 @@ public class RegexpLikeExprMacro implements ExprMacroTable.ExprMacro
|
||||
|
||||
if (s == null) {
|
||||
// True nulls do not match anything. Note: this branch only executes in SQL-compatible null handling mode.
|
||||
return ExprEval.ofLongBoolean(false);
|
||||
return ExprEval.ofLong(null);
|
||||
} else {
|
||||
final Matcher matcher = pattern.matcher(s);
|
||||
return ExprEval.ofLongBoolean(matcher.find());
|
||||
|
@ -166,11 +166,11 @@ public class CaseInsensitiveExprMacroTest extends MacroTestBase
|
||||
@Test
|
||||
public void testEmptyStringSearchOnNull()
|
||||
{
|
||||
final ExprEval<?> result = eval("icontains_string(a, '')", InputBindings.nilBindings());
|
||||
Assert.assertEquals(
|
||||
ExprEval.ofLongBoolean(!NullHandling.sqlCompatible()).value(),
|
||||
result.value()
|
||||
);
|
||||
ExprEval<?> result = eval("icontains_string(a, '')", InputBindings.nilBindings());
|
||||
if (NullHandling.sqlCompatible()) {
|
||||
Assert.assertNull(result.value());
|
||||
} else {
|
||||
Assert.assertEquals(ExprEval.ofLongBoolean(true).value(), result.value());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -151,9 +151,10 @@ public class ContainsExprMacroTest extends MacroTestBase
|
||||
public void testEmptyStringSearchOnNull()
|
||||
{
|
||||
final ExprEval<?> result = eval("contains_string(a, '')", InputBindings.nilBindings());
|
||||
Assert.assertEquals(
|
||||
ExprEval.ofLongBoolean(!NullHandling.sqlCompatible()).value(),
|
||||
result.value()
|
||||
);
|
||||
if (NullHandling.sqlCompatible()) {
|
||||
Assert.assertNull(result.value());
|
||||
} else {
|
||||
Assert.assertEquals(ExprEval.ofLongBoolean(true).value(), result.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,9 +151,10 @@ public class RegexpLikeExprMacroTest extends MacroTestBase
|
||||
public void testEmptyStringPatternOnNull()
|
||||
{
|
||||
final ExprEval<?> result = eval("regexp_like(a, '')", InputBindings.nilBindings());
|
||||
Assert.assertEquals(
|
||||
ExprEval.ofLongBoolean(NullHandling.replaceWithDefault()).value(),
|
||||
result.value()
|
||||
);
|
||||
if (NullHandling.sqlCompatible()) {
|
||||
Assert.assertNull(result.value());
|
||||
} else {
|
||||
Assert.assertEquals(ExprEval.ofLongBoolean(true).value(), result.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -581,7 +581,7 @@ public class ExpressionsTest extends CalciteTestBase
|
||||
testHelper.makeLiteral("(.)")
|
||||
),
|
||||
makeExpression("regexp_like(null,'(.)')"),
|
||||
0L
|
||||
NullHandling.sqlCompatible() ? null : 0L
|
||||
);
|
||||
|
||||
testHelper.testExpressionString(
|
||||
@ -593,7 +593,7 @@ public class ExpressionsTest extends CalciteTestBase
|
||||
makeExpression("regexp_like(null,'')"),
|
||||
|
||||
// In SQL-compatible mode, nulls don't match anything. Otherwise, they match like empty strings.
|
||||
NullHandling.sqlCompatible() ? 0L : 1L
|
||||
NullHandling.sqlCompatible() ? null : 1L
|
||||
);
|
||||
|
||||
testHelper.testExpressionString(
|
||||
@ -603,7 +603,7 @@ public class ExpressionsTest extends CalciteTestBase
|
||||
testHelper.makeLiteral("null")
|
||||
),
|
||||
makeExpression("regexp_like(null,'null')"),
|
||||
0L
|
||||
NullHandling.sqlCompatible() ? null : 0L
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user