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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0119a19  [GRIFFIN-294] bugfix for completness enumeration wrong sql
0119a19 is described below

commit 0119a19c93d0607ecfda2c5e029169e689c2bfd0
Author: Zhao Li <[email protected]>
AuthorDate: Fri Nov 1 21:36:02 2019 +0800

    [GRIFFIN-294] bugfix for completness enumeration wrong sql
    
    if there is only 'hive_none' in enumeration values list, it will generate 
wrong sql. Update code to fix this bug
    
    Author: Zhao Li <[email protected]>
    Author: Zhao <[email protected]>
    
    Closes #545 from LittleZhao/griffin-294.
---
 .../dsl/transform/CompletenessExpr2DQSteps.scala   | 24 ++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git 
a/measure/src/main/scala/org/apache/griffin/measure/step/builder/dsl/transform/CompletenessExpr2DQSteps.scala
 
b/measure/src/main/scala/org/apache/griffin/measure/step/builder/dsl/transform/CompletenessExpr2DQSteps.scala
index 4d3344e..46def8f 100644
--- 
a/measure/src/main/scala/org/apache/griffin/measure/step/builder/dsl/transform/CompletenessExpr2DQSteps.scala
+++ 
b/measure/src/main/scala/org/apache/griffin/measure/step/builder/dsl/transform/CompletenessExpr2DQSteps.scala
@@ -18,6 +18,8 @@ under the License.
 */
 package org.apache.griffin.measure.step.builder.dsl.transform
 
+import org.apache.commons.lang.StringUtils
+
 import 
org.apache.griffin.measure.configuration.dqdefinition.{RuleErrorConfParam, 
RuleParam}
 import org.apache.griffin.measure.configuration.enums._
 import org.apache.griffin.measure.context.DQContext
@@ -200,19 +202,29 @@ case class CompletenessExpr2DQSteps(context: DQContext,
       return result
     } else if ("enumeration".equalsIgnoreCase(errorType.get)) {
       val values: Seq[String] = errorConf.getValues
-      // hive_none means None
-      var hasNone: Boolean = false
+      var inResult = ""
+      var nullResult = ""
       if (values.contains("hive_none")) {
-        hasNone = true
+        // hive_none means NULL
+        nullResult = s"(`${columnName}` IS NULL)"
       }
 
       val valueWithQuote: String = values.filter(value => 
!"hive_none".equals(value))
         .map(value => s"'${value}'").mkString(", ")
 
-      var result = s"(`${columnName}` IN (${valueWithQuote}))"
-      if (hasNone) {
-        result = s"((${result}) OR (`${columnName}` IS NULL))"
+      if (!StringUtils.isEmpty(valueWithQuote)) {
+        inResult = s"(`${columnName}` IN (${valueWithQuote}))"
       }
+
+      var result = ""
+      if (!StringUtils.isEmpty(inResult) && !StringUtils.isEmpty(nullResult)) {
+        result = s"(${inResult} OR ${nullResult})"
+      } else if (!StringUtils.isEmpty(inResult)) {
+        result = inResult
+      } else {
+        result = nullResult
+      }
+
       return result
     }
     throw new IllegalArgumentException("type in error.confs only supports 
regex and enumeration way")

Reply via email to