NobiGo commented on a change in pull request #2598:
URL: https://github.com/apache/calcite/pull/2598#discussion_r743258201



##########
File path: 
core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
##########
@@ -7202,6 +7218,41 @@ void assertSubFunReturns(boolean binary, String s, int 
start,
         "nvl(CAST(NULL AS VARCHAR(6)), cast(NULL AS VARCHAR(4)))");
   }
 
+
+  private RelNode transformSqlToRel(String sql) throws Exception {
+    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+    final SchemaPlus defSchema = rootSchema.add("hr", new HrClusteredSchema());
+    final FrameworkConfig config = Frameworks.newConfigBuilder()
+        .parserConfig(SqlParser.Config.DEFAULT)
+        .defaultSchema(defSchema)
+        .traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE)
+        .operatorTable(SqlLibraryOperatorTableFactory.INSTANCE
+            .getOperatorTable(SqlLibrary.STANDARD, SqlLibrary.ORACLE))
+        .build();
+    Planner planner = Frameworks.getPlanner(config);
+    SqlNode parse = planner.parse(sql);
+    SqlNode validate = planner.validate(parse);
+    RelRoot planRoot = planner.rel(validate);
+    return planRoot.rel;
+
+  }
+
+  @Test public void testNvlOperands() throws Exception {

Review comment:
       The testNvlFunc has existed in SqlOperatorTest, If it doesn't have 
enough tests for you, please perfect it.
   
   If this can't suit your need. You can add a SQL type test in .iq file.

##########
File path: 
core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
##########
@@ -7202,6 +7218,41 @@ void assertSubFunReturns(boolean binary, String s, int 
start,
         "nvl(CAST(NULL AS VARCHAR(6)), cast(NULL AS VARCHAR(4)))");
   }
 
+
+  private RelNode transformSqlToRel(String sql) throws Exception {
+    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+    final SchemaPlus defSchema = rootSchema.add("hr", new HrClusteredSchema());
+    final FrameworkConfig config = Frameworks.newConfigBuilder()
+        .parserConfig(SqlParser.Config.DEFAULT)
+        .defaultSchema(defSchema)
+        .traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE)
+        .operatorTable(SqlLibraryOperatorTableFactory.INSTANCE
+            .getOperatorTable(SqlLibrary.STANDARD, SqlLibrary.ORACLE))
+        .build();
+    Planner planner = Frameworks.getPlanner(config);
+    SqlNode parse = planner.parse(sql);
+    SqlNode validate = planner.validate(parse);
+    RelRoot planRoot = planner.rel(validate);
+    return planRoot.rel;
+
+  }
+
+  @Test public void testNvlOperands() throws Exception {

Review comment:
       You try to !plan command in .iq file. Same as 
https://github.com/apache/calcite/blob/master/core/src/test/resources/sql/agg.iq#L1707
 .

##########
File path: 
core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
##########
@@ -7202,6 +7218,41 @@ void assertSubFunReturns(boolean binary, String s, int 
start,
         "nvl(CAST(NULL AS VARCHAR(6)), cast(NULL AS VARCHAR(4)))");
   }
 
+
+  private RelNode transformSqlToRel(String sql) throws Exception {
+    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+    final SchemaPlus defSchema = rootSchema.add("hr", new HrClusteredSchema());
+    final FrameworkConfig config = Frameworks.newConfigBuilder()
+        .parserConfig(SqlParser.Config.DEFAULT)
+        .defaultSchema(defSchema)
+        .traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE)
+        .operatorTable(SqlLibraryOperatorTableFactory.INSTANCE
+            .getOperatorTable(SqlLibrary.STANDARD, SqlLibrary.ORACLE))
+        .build();
+    Planner planner = Frameworks.getPlanner(config);
+    SqlNode parse = planner.parse(sql);
+    SqlNode validate = planner.validate(parse);
+    RelRoot planRoot = planner.rel(validate);
+    return planRoot.rel;
+
+  }
+
+  @Test public void testNvlOperands() throws Exception {

Review comment:
       You can try to use !plan command in .iq file. Same as 
https://github.com/apache/calcite/blob/master/core/src/test/resources/sql/agg.iq#L1707
 . This can suit your need?

##########
File path: 
core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
##########
@@ -7202,6 +7218,41 @@ void assertSubFunReturns(boolean binary, String s, int 
start,
         "nvl(CAST(NULL AS VARCHAR(6)), cast(NULL AS VARCHAR(4)))");
   }
 
+
+  private RelNode transformSqlToRel(String sql) throws Exception {
+    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+    final SchemaPlus defSchema = rootSchema.add("hr", new HrClusteredSchema());
+    final FrameworkConfig config = Frameworks.newConfigBuilder()
+        .parserConfig(SqlParser.Config.DEFAULT)
+        .defaultSchema(defSchema)
+        .traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE)
+        .operatorTable(SqlLibraryOperatorTableFactory.INSTANCE
+            .getOperatorTable(SqlLibrary.STANDARD, SqlLibrary.ORACLE))
+        .build();
+    Planner planner = Frameworks.getPlanner(config);
+    SqlNode parse = planner.parse(sql);
+    SqlNode validate = planner.validate(parse);
+    RelRoot planRoot = planner.rel(validate);
+    return planRoot.rel;
+
+  }
+
+  @Test public void testNvlOperands() throws Exception {

Review comment:
       Maybe in SqlToRelConverterTest. I think this test case in here is not 
standard.

##########
File path: 
core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
##########
@@ -7202,6 +7218,41 @@ void assertSubFunReturns(boolean binary, String s, int 
start,
         "nvl(CAST(NULL AS VARCHAR(6)), cast(NULL AS VARCHAR(4)))");
   }
 
+
+  private RelNode transformSqlToRel(String sql) throws Exception {
+    final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+    final SchemaPlus defSchema = rootSchema.add("hr", new HrClusteredSchema());
+    final FrameworkConfig config = Frameworks.newConfigBuilder()
+        .parserConfig(SqlParser.Config.DEFAULT)
+        .defaultSchema(defSchema)
+        .traitDefs(ConventionTraitDef.INSTANCE, RelCollationTraitDef.INSTANCE)
+        .operatorTable(SqlLibraryOperatorTableFactory.INSTANCE
+            .getOperatorTable(SqlLibrary.STANDARD, SqlLibrary.ORACLE))
+        .build();
+    Planner planner = Frameworks.getPlanner(config);
+    SqlNode parse = planner.parse(sql);
+    SqlNode validate = planner.validate(parse);
+    RelRoot planRoot = planner.rel(validate);
+    return planRoot.rel;
+
+  }
+
+  @Test public void testNvlOperands() throws Exception {

Review comment:
       I noticed the changes in SQL to RelNode So maybe 
SqlToRelConverterTest(The test result in SqlToRelConverterTest.xml) is more 
appropriate. Of course, If you think .iq is enough for this, You can try` !use 
oraclefunc ` expamle as 
https://github.com/apache/calcite/blob/master/core/src/test/resources/sql/functions.iq#L83
 .  

##########
File path: core/src/test/resources/sql/functions.iq
##########
@@ -179,5 +179,15 @@ SELECT EXISTSNODE(
 
 !ok
 
+# [CALCITE-4875] Preserve Operand Nullability in NVL rewrite
+# Asserting that NVL does not change a Nullable operand to NOT Nullable
+
+!use oraclefunc
+select nvl("name", 'undefined') FROM "hr"."emps";
+
+EnumerableCalc(expr#0..4=[{inputs}], expr#5=[IS NOT NULL($t2)], 
expr#6=[CAST($t2):VARCHAR], expr#7=['undefined':VARCHAR], expr#8=[CASE($t5, 
$t6, $t7)], EXPR$0=[$t8])
+  EnumerableTableScan(table=[[hr, emps]])
+!plan

Review comment:
       Can you add extra ` !ok` command to test the output?  Others is good for 
me.




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


Reply via email to