improve sql eval

This commit is contained in:
kiki
2013-04-28 17:30:09 +08:00
parent 00e03d8cb2
commit 8a20d359f2
2 changed files with 27 additions and 16 deletions
@@ -931,7 +931,7 @@ public class SQLEvalVisitorUtils {
return ((Number) val).intValue() == 1;
}
throw new IllegalArgumentException();
throw new IllegalArgumentException(val.getClass() + " not supported.");
}
public static String castToString(Object val) {
@@ -1165,7 +1165,7 @@ public class SQLEvalVisitorUtils {
return castToByte(a) + castToByte(b);
}
throw new IllegalArgumentException();
throw new IllegalArgumentException(a.getClass() + " and " + b.getClass() + " not supported.");
}
public static Object div(Object a, Object b) {
@@ -1197,7 +1197,7 @@ public class SQLEvalVisitorUtils {
return castToByte(a) / castToByte(b);
}
throw new IllegalArgumentException();
throw new IllegalArgumentException(a.getClass() + " and " + b.getClass() + " not supported.");
}
public static boolean gt(Object a, Object b) {
@@ -1209,6 +1209,10 @@ public class SQLEvalVisitorUtils {
return true;
}
if (a instanceof String || b instanceof String) {
return ((String) a).compareTo((String) b) > 0;
}
if (a instanceof BigDecimal || b instanceof BigDecimal) {
return castToDecimal(a).compareTo(castToDecimal(b)) > 0;
}
@@ -1252,7 +1256,7 @@ public class SQLEvalVisitorUtils {
return d1.compareTo(d2) > 0;
}
throw new IllegalArgumentException();
throw new IllegalArgumentException(a.getClass() + " and " + b.getClass() + " not supported.");
}
public static boolean gteq(Object a, Object b) {
@@ -1272,6 +1276,10 @@ public class SQLEvalVisitorUtils {
return false;
}
if (a instanceof String || b instanceof String) {
return ((String) a).compareTo((String) b) < 0;
}
if (a instanceof BigDecimal || b instanceof BigDecimal) {
return castToDecimal(a).compareTo(castToDecimal(b)) < 0;
}
@@ -1315,7 +1323,7 @@ public class SQLEvalVisitorUtils {
return d1.compareTo(d2) < 0;
}
throw new IllegalArgumentException();
throw new IllegalArgumentException(a.getClass() + " and " + b.getClass() + " not supported.");
}
public static boolean lteq(Object a, Object b) {
@@ -1339,6 +1347,10 @@ public class SQLEvalVisitorUtils {
return true;
}
if (a instanceof String || b instanceof String) {
return castToString(a).equals(castToString(b));
}
if (a instanceof BigDecimal || b instanceof BigDecimal) {
return castToDecimal(a).compareTo(castToDecimal(b)) == 0;
}
@@ -1378,11 +1390,7 @@ public class SQLEvalVisitorUtils {
return d1.equals(d2);
}
if (a instanceof String || b instanceof String) {
return castToString(a).equals(castToString(b));
}
throw new IllegalArgumentException();
throw new IllegalArgumentException(a.getClass() + " and " + b.getClass() + " not supported.");
}
public static Object add(Object a, Object b) {
@@ -1430,7 +1438,7 @@ public class SQLEvalVisitorUtils {
return castToString(a) + castToString(b);
}
throw new IllegalArgumentException();
throw new IllegalArgumentException(a.getClass() + " and " + b.getClass() + " not supported.");
}
public static Object sub(Object a, Object b) {
@@ -1514,7 +1522,7 @@ public class SQLEvalVisitorUtils {
return castToByte(a) * castToByte(b);
}
throw new IllegalArgumentException();
throw new IllegalArgumentException(a.getClass() + " and " + b.getClass() + " not supported.");
}
public static boolean like(String input, String pattern) {
@@ -51,7 +51,7 @@ public class Substring implements Function {
if (paramSize == 2) {
if (index < 0) {
int lastIndex = str.length() + index ;
int lastIndex = str.length() + index;
return str.substring(lastIndex);
}
@@ -66,15 +66,18 @@ public class Substring implements Function {
}
int len = ((Number) param2Value).intValue();
String result;
if (index < 0) {
int lastIndex = str.length() + index ;
int lastIndex = str.length() + index;
result = str.substring(lastIndex);
} else {
result = str.substring(index - 1);
}
if (len > result.length()) {
return result;
}
return result.substring(0, len);
}
}