|
7 | 7 | import com.google.common.collect.Lists;
|
8 | 8 | import com.google.common.collect.Sets;
|
9 | 9 | import org.elasticsearch.common.collect.Tuple;
|
| 10 | +import org.elasticsearch.plugin.nlpcn.executors.CSVResult; |
10 | 11 | import org.nlpcn.es4sql.domain.KVValue;
|
11 | 12 |
|
12 | 13 | import java.util.List;
|
@@ -62,17 +63,20 @@ public static Tuple<String, String> function(String methodName, List<KVValue> pa
|
62 | 63 | name);
|
63 | 64 | break;
|
64 | 65 |
|
65 |
| - case "floor": |
| 66 | + case "abs": |
66 | 67 | case "round":
|
| 68 | + case "floor": |
67 | 69 | case "ceil":
|
68 | 70 | case "cbrt":
|
69 | 71 | case "rint":
|
70 |
| - case "pow": |
71 | 72 | case "exp":
|
72 | 73 | case "sqrt":
|
73 | 74 | functionStr = mathSingleValueTemplate("Math."+methodName,methodName,Util.expr2Object((SQLExpr) paramers.get(0).value).toString(), name);
|
74 | 75 | break;
|
75 | 76 |
|
| 77 | + case "pow": |
| 78 | + functionStr = mathDoubleValueTemplate("Math."+methodName, methodName, Util.expr2Object((SQLExpr) paramers.get(0).value).toString(), Util.expr2Object((SQLExpr) paramers.get(1).value).toString(), name); |
| 79 | + break; |
76 | 80 |
|
77 | 81 | case "substring":
|
78 | 82 | functionStr = substring(Util.expr2Object((SQLExpr) paramers.get(0).value).toString(),
|
@@ -302,6 +306,15 @@ public static Tuple<String, String> trim(String strColumn, String valueName) {
|
302 | 306 |
|
303 | 307 | }
|
304 | 308 |
|
| 309 | + private static Tuple<String, String> mathDoubleValueTemplate(String methodName, String fieldName, String val1, String val2, String valueName) { |
| 310 | + String name = fieldName + "_" + random(); |
| 311 | + if (valueName == null) { |
| 312 | + return new Tuple(name, "def "+name+" = "+methodName+"(doc['"+val1+"'].value, "+val2+")"); |
| 313 | + } else { |
| 314 | + return new Tuple(name, val1 + ";def "+name+" = "+methodName+"("+valueName+", "+val2+")"); |
| 315 | + } |
| 316 | + } |
| 317 | + |
305 | 318 | private static Tuple<String, String> mathSingleValueTemplate(String methodName, String strColumn, String valueName) {
|
306 | 319 | return mathSingleValueTemplate(methodName,methodName, strColumn,valueName);
|
307 | 320 | }
|
|
0 commit comments