3
3
import com .alibaba .druid .sql .ast .SQLExpr ;
4
4
import com .alibaba .druid .sql .ast .expr .SQLBinaryOpExpr ;
5
5
import com .alibaba .druid .sql .ast .expr .SQLMethodInvokeExpr ;
6
+ import org .elasticsearch .script .ScriptService ;
6
7
import org .nlpcn .es4sql .Util ;
7
8
import org .nlpcn .es4sql .domain .Field ;
8
9
import org .nlpcn .es4sql .domain .KVValue ;
19
20
public class ScriptFilter {
20
21
private String script ;
21
22
private Map <String ,Object > args ;
22
-
23
+ private ScriptService . ScriptType scriptType ;
23
24
public ScriptFilter () {
25
+
24
26
args = null ;
27
+ scriptType = ScriptService .ScriptType .INLINE ;
25
28
}
26
29
27
- public ScriptFilter (String script , Map <String , Object > args ) {
30
+ public ScriptFilter (String script , Map <String , Object > args , ScriptService . ScriptType scriptType ) {
28
31
this .script = script ;
29
32
this .args = args ;
33
+ this .scriptType = scriptType ;
30
34
}
31
35
32
36
public boolean tryParseFromMethodExpr (SQLMethodInvokeExpr expr ) throws SqlParseException {
@@ -58,12 +62,32 @@ public boolean tryParseFromMethodExpr(SQLMethodInvokeExpr expr) throws SqlParseE
58
62
SQLExpr right = binaryOpExpr .getRight ();
59
63
Object value = Util .expr2Object (right );
60
64
String key = Util .extendedToString (binaryOpExpr .getLeft ());
61
- args .put (key , value );
65
+ if (key .equals ("script_type" )){
66
+ parseAndUpdateScriptType (value .toString ());
67
+ }
68
+ else {
69
+ args .put (key , value );
70
+ }
62
71
63
72
}
64
73
return true ;
65
74
}
66
75
76
+ private void parseAndUpdateScriptType (String scriptType ) {
77
+ String scriptTypeUpper = scriptType .toUpperCase ();
78
+ switch (scriptTypeUpper ){
79
+ case "INLINE" :
80
+ this .scriptType = ScriptService .ScriptType .INLINE ;
81
+ break ;
82
+ case "INDEXED" :
83
+ this .scriptType = ScriptService .ScriptType .INDEXED ;
84
+ break ;
85
+ case "FILE" :
86
+ this .scriptType = ScriptService .ScriptType .FILE ;
87
+ break ;
88
+ }
89
+ }
90
+
67
91
public boolean containsParameters (){
68
92
return args !=null && args .size () > 0 ;
69
93
}
@@ -72,6 +96,9 @@ public String getScript() {
72
96
return script ;
73
97
}
74
98
99
+ public ScriptService .ScriptType getScriptType () {
100
+ return scriptType ;
101
+ }
75
102
76
103
public Map <String , Object > getArgs () {
77
104
return args ;
0 commit comments