Browse Source

公式允许判断空

menglu 3 years ago
parent
commit
9d6b7a89e2

+ 6 - 11
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/QueryUtil.java

@@ -142,21 +142,20 @@ public class QueryUtil {
 			SceneDataPrimitive SceneValuePrimitive = new SceneDataPrimitive();
 			result = SceneValuePrimitive;
 			CriteriaDefault CriteriaDefault = (CriteriaDefault) criteria;
-			boolean exist_null = false;
 			for (String var : scanner.varDict.keySet()) {
 				Match_e me = (Match_e) CriteriaDefault.column2MatchList.get(var).get(0);
 				if (me.change()) {
 					SceneValuePrimitive.change = true;
 				}
 				if (me.value == null) {
-					exist_null = true;
+					walker.put_null(var);
 				} else {
 					if (me.value instanceof Integer) {
-						walker.put(var, (int) me.value);
+						walker.put(var, (long) ((int) me.value));
 					} else if (me.value instanceof Long) {
 						walker.put(var, (long) me.value);
 					} else if (me.value instanceof Float) {
-						walker.put(var, (float) me.value);
+						walker.put(var, (double) ((float) me.value));
 					} else if (me.value instanceof Double) {
 						walker.put(var, (double) me.value);
 					} else {
@@ -170,7 +169,7 @@ public class QueryUtil {
 					SceneValuePrimitive.change = true;
 				}
 				if (me.value == null) {
-					exist_null = true;
+					walker.putString(var, null);
 				} else {
 					if (me.value instanceof String) {
 						walker.putString(var, (String) me.value);
@@ -179,12 +178,8 @@ public class QueryUtil {
 					}
 				}
 			}
-			if (exist_null) {
-				SceneValuePrimitive.value = null;
-			} else {
-				ValueObject prog_result = walker.prog();
-				SceneValuePrimitive.value = prog_result.value();
-			}
+			ValueObject prog_result = walker.prog();
+			SceneValuePrimitive.value = prog_result.value();
 		} else if (QueryType.equals("quote")) {
 			CriteriaDefault CriteriaDefault = (CriteriaDefault) criteria;
 			MatchBase MatchBase = CriteriaDefault.column2MatchList.get("quote").get(0);

File diff suppressed because it is too large
+ 504 - 467
ibms-data-sdk/src/main/java/com/sagacloud/advanced/expression/AdvancedExpressionLexer.java


File diff suppressed because it is too large
+ 1107 - 842
ibms-data-sdk/src/main/java/com/sagacloud/advanced/expression/AdvancedExpressionParser.java


File diff suppressed because it is too large
+ 541 - 395
ibms-data-sdk/src/main/java/com/sagacloud/advanced/expression/AdvancedExpressionScanner.java


File diff suppressed because it is too large
+ 572 - 420
ibms-data-sdk/src/main/java/com/sagacloud/advanced/expression/AdvancedExpressionWalker.java


+ 8 - 0
ibms-data-sdk/src/main/java/com/sagacloud/util/math/FunctionUtil.java

@@ -29,6 +29,10 @@ public class FunctionUtil {
 	}
 
 	public static ValueObject compute(String function, ValueObject a) {
+		if (a.is_null()) {
+			return new ValueObject(null);
+		}
+
 		ValueObject result = new ValueObject();
 		result.type = 1;
 		double valuea;
@@ -48,6 +52,10 @@ public class FunctionUtil {
 	}
 
 	public static ValueObject compute(String function, ValueObject a, ValueObject b) {
+		if (a.is_null() || b.is_null()) {
+			return new ValueObject(null);
+		}
+
 		ValueObject result = new ValueObject();
 		result.type = 1;
 		double valuea;

+ 15 - 6
ibms-data-sdk/src/main/java/com/sagacloud/util/math/ValueObject.java

@@ -5,18 +5,19 @@ public class ValueObject {
 
 	}
 
-	public ValueObject(long value) {
+	public ValueObject(int type, Long value) {
+		this.type = type;
 		this.intValue = value;
 	}
 
-	public ValueObject(double value) {
+	public ValueObject(int type, Double value) {
+		this.type = type;
 		this.doubleValue = value;
-		this.type = 1;
 	}
 
 	public ValueObject(String value) {
-		this.stringValue = value;
 		this.type = 2;
+		this.stringValue = value;
 	}
 
 	// public ValueObject(String text) {
@@ -29,8 +30,8 @@ public class ValueObject {
 	// }
 
 	public int type;// 0:int;1:double;2:string
-	public long intValue;
-	public double doubleValue;
+	public Long intValue;
+	public Double doubleValue;
 	public String stringValue;
 
 	public Object value() {
@@ -44,4 +45,12 @@ public class ValueObject {
 		}
 		return result;
 	}
+
+	public boolean is_null() {
+		if (this.type == 2 && this.stringValue == null) {
+			return true;
+		} else {
+			return false;
+		}
+	}
 }

+ 63 - 0
ibms-data-sdk/src/main/java/com/sagacloud/util/math/ValueObjectUtil.java

@@ -1,7 +1,12 @@
 package com.sagacloud.util.math;
 
 public class ValueObjectUtil {
+
 	public static ValueObject compute(String operator, ValueObject a, ValueObject b) {
+		if (a.is_null() || b.is_null()) {
+			return new ValueObject(null);
+		}
+
 		ValueObject result = new ValueObject();
 		if (a.type == 0 && b.type == 0) {
 			if (operator.equals("+")) {
@@ -44,7 +49,36 @@ public class ValueObjectUtil {
 		return result;
 	}
 
+	public static boolean stringcompare(String operator, ValueObject b) {
+		if (operator.equals("==")) {
+			return b.stringValue == null;
+		} else if (operator.equals("!=")) {
+			return b.stringValue != null;
+		}
+		return true;
+	}
+
 	public static boolean stringcompare(String operator, ValueObject a, ValueObject b) {
+		if (a.is_null() && b.is_null()) {
+			if (operator.equals("==")) {
+				return true;
+			} else {
+				return false;
+			}
+		} else if (a.is_null()) {
+			if (operator.equals("<") || operator.equals("<=") || operator.equals("!=")) {
+				return true;
+			} else {
+				return false;
+			}
+		} else if (b.is_null()) {
+			if (operator.equals(">") || operator.equals(">=") || operator.equals("!=")) {
+				return true;
+			} else {
+				return false;
+			}
+		}
+
 		int cmp = a.stringValue.compareTo(b.stringValue);
 		if (operator.equals("<")) {
 			return cmp < 0;
@@ -62,7 +96,36 @@ public class ValueObjectUtil {
 		return true;
 	}
 
+	public static boolean compare(String operator, ValueObject b) {
+		if (operator.equals("==")) {
+			return b.stringValue == null;
+		} else if (operator.equals("!=")) {
+			return b.stringValue != null;
+		}
+		return true;
+	}
+
 	public static boolean compare(String operator, ValueObject a, ValueObject b) {
+		if (a.is_null() && b.is_null()) {
+			if (operator.equals("==")) {
+				return true;
+			} else {
+				return false;
+			}
+		} else if (a.is_null()) {
+			if (operator.equals("<") || operator.equals("<=") || operator.equals("!=")) {
+				return true;
+			} else {
+				return false;
+			}
+		} else if (b.is_null()) {
+			if (operator.equals(">") || operator.equals(">=") || operator.equals("!=")) {
+				return true;
+			} else {
+				return false;
+			}
+		}
+
 		if (a.type == 0 && b.type == 0) {
 			if (operator.equals("<")) {
 				return a.intValue < b.intValue;