abhishekagarwal87 commented on a change in pull request #10350:
URL: https://github.com/apache/druid/pull/10350#discussion_r487129886
##########
File path:
sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java
##########
@@ -1072,6 +1075,221 @@ public void testPad()
);
}
+ @Test
+ public void testContains()
+ {
+ testHelper.testExpression(
+ ContainsOperatorConversion.caseSensitive().calciteOperator(),
+ ImmutableList.of(
+ testHelper.makeInputRef("spacey"),
+ testHelper.makeLiteral("there")
+ ),
+ DruidExpression.fromExpression("contains_string(\"spacey\",'there')"),
+ 1L
+ );
+
+ testHelper.testExpression(
+ ContainsOperatorConversion.caseSensitive().calciteOperator(),
+ ImmutableList.of(
+ testHelper.makeInputRef("spacey"),
+ testHelper.makeLiteral("There")
+ ),
+ DruidExpression.fromExpression("contains_string(\"spacey\",'There')"),
+ 0L
+ );
+
+ testHelper.testExpression(
+ ContainsOperatorConversion.caseInsensitive().calciteOperator(),
+ ImmutableList.of(
+ testHelper.makeInputRef("spacey"),
+ testHelper.makeLiteral("There")
+ ),
+ DruidExpression.fromExpression("icontains_string(\"spacey\",'There')"),
+ 1L
+ );
+
+ testHelper.testExpression(
+ ContainsOperatorConversion.caseSensitive().calciteOperator(),
+ ImmutableList.of(
+ testHelper.makeCall(
+ SqlStdOperatorTable.CONCAT,
+ testHelper.makeLiteral("what is"),
+ testHelper.makeInputRef("spacey")
+ ),
+ testHelper.makeLiteral("what")
+ ),
+ DruidExpression.fromExpression("contains_string(concat('what
is',\"spacey\"),'what')"),
+ 1L
+ );
+
+ testHelper.testExpression(
+ ContainsOperatorConversion.caseSensitive().calciteOperator(),
+ ImmutableList.of(
+ testHelper.makeCall(
+ SqlStdOperatorTable.CONCAT,
+ testHelper.makeLiteral("what is"),
+ testHelper.makeInputRef("spacey")
+ ),
+ testHelper.makeLiteral("there")
+ ),
+ DruidExpression.fromExpression("contains_string(concat('what
is',\"spacey\"),'there')"),
+ 1L
+ );
+
+ testHelper.testExpression(
+ ContainsOperatorConversion.caseInsensitive().calciteOperator(),
+ ImmutableList.of(
+ testHelper.makeCall(
+ SqlStdOperatorTable.CONCAT,
+ testHelper.makeLiteral("what is"),
+ testHelper.makeInputRef("spacey")
+ ),
+ testHelper.makeLiteral("There")
+ ),
+ DruidExpression.fromExpression("icontains_string(concat('what
is',\"spacey\"),'There')"),
+ 1L
+ );
+
+ testHelper.testExpression(
+ SqlStdOperatorTable.AND,
+ ImmutableList.of(
+ testHelper.makeCall(
+ ContainsOperatorConversion.caseSensitive().calciteOperator(),
+ testHelper.makeInputRef("spacey"),
+ testHelper.makeLiteral("there")
+ ),
+ testHelper.makeCall(
+ SqlStdOperatorTable.EQUALS,
+ testHelper.makeLiteral("yes"),
+ testHelper.makeLiteral("yes")
+ )
+ ),
+ DruidExpression.fromExpression("(contains_string(\"spacey\",'there')
&& ('yes' == 'yes'))"),
+ 1L
+ );
+
+ testHelper.testExpression(
+ SqlStdOperatorTable.AND,
+ ImmutableList.of(
+ testHelper.makeCall(
+ ContainsOperatorConversion.caseInsensitive().calciteOperator(),
+ testHelper.makeInputRef("spacey"),
+ testHelper.makeLiteral("There")
+ ),
+ testHelper.makeCall(
+ SqlStdOperatorTable.EQUALS,
+ testHelper.makeLiteral("yes"),
+ testHelper.makeLiteral("yes")
+ )
+ ),
+ DruidExpression.fromExpression("(icontains_string(\"spacey\",'There')
&& ('yes' == 'yes'))"),
Review comment:
I was not handling the null values similar to other expressions. It
should work now. code coverage bot was complaining as tests were added in `sql`
module and these `Expr*` classes are in the `processing` module. After I added
the tests in the processing module, I realized what the problem was. When an
empty string is passed, the functions get a null value that they again convert
to an empty value.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]