[ https://issues.apache.org/jira/browse/BEAM-5106?focusedWorklogId=133205&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-133205 ]
ASF GitHub Bot logged work on BEAM-5106: ---------------------------------------- Author: ASF GitHub Bot Created on: 09/Aug/18 19:54 Start Date: 09/Aug/18 19:54 Worklog Time Spent: 10m Work Description: amaliujia commented on a change in pull request #6174: [BEAM-5106][SQL]test conditional operators and functions at DSL level URL: https://github.com/apache/beam/pull/6174#discussion_r209058332 ########## File path: sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlDslSqlStdOperatorsTest.java ########## @@ -1170,4 +1171,32 @@ public void testTimestampMinusInterval() throws Exception { parseDate("1983-01-19 01:01:58")); checker.buildRunAndCheck(); } + + @Test + @SqlOperatorTest(name = "CASE", kind = "CASE") + @SqlOperatorTest(name = "NULLIF", kind = "NULLIF") + @SqlOperatorTest(name = "COALESCE", kind = "COALESCE") + public void testConditionalOperatorsAndFunctions() { + ExpressionChecker checker = + new ExpressionChecker() + .addExpr("CASE 1 WHEN 1 THEN 'hello' ELSE 'world' END", "hello") + .addExpr( + "CASE 2 " + "WHEN 1 THEN 'hello' " + "WHEN 3 THEN 'bond' " + "ELSE 'world' END", + "world") + .addExpr( + "CASE 3 " + "WHEN 1 THEN 'hello' " + "WHEN 3 THEN 'bond' " + "ELSE 'world' END", + "bond") + .addExpr("CASE " + "WHEN 1 = 1 THEN 'hello' " + "ELSE 'world' END", "hello") + .addExpr("CASE " + "WHEN 1 > 1 THEN 'hello' " + "ELSE 'world' END", "world") + .addExpr("NULLIF(5, 4) ", 5) + .addExpr("NULLIF(4, 5) ", 4) + .addExpr("NULLIF(5, 5)", null, FieldType.INT32) Review comment: The AutoValue tool we are using will generate code like this without `@Nullable`: ``` if (expectedResult == null) { throw new NullPointerException("Null expectedResult"); } ``` So any conversion won't pass this null check. Also, if without ``` if (expectedValue == null) { schema = Schema.builder().addNullableField(expression, testCase.resultFieldType()).build(); } else { schema = Schema.builder().addField(expression, testCase.resultFieldType()).build(); } ```, `Row` will also fail this code, see https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/values/Row.java#L402 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 133205) Time Spent: 2h (was: 1h 50m) > Test conditional functions at DSL level > --------------------------------------- > > Key: BEAM-5106 > URL: https://issues.apache.org/jira/browse/BEAM-5106 > Project: Beam > Issue Type: Sub-task > Components: dsl-sql > Reporter: Rui Wang > Assignee: Rui Wang > Priority: Major > Time Spent: 2h > Remaining Estimate: 0h > -- This message was sent by Atlassian JIRA (v7.6.3#76005)