3838import org .apache .wayang .basic .data .Record ;
3939import org .apache .wayang .core .api .Configuration ;
4040import org .apache .wayang .core .plugin .Plugin ;
41+ import org .apache .wayang .api .util .Parameters ;
4142import org .apache .wayang .core .api .WayangContext ;
4243import org .apache .wayang .core .util .ReflectionUtils ;
4344import org .apache .wayang .core .plan .wayangplan .WayangPlan ;
4445import org .apache .wayang .java .Java ;
4546import org .apache .wayang .postgres .Postgres ;
4647import org .apache .wayang .spark .Spark ;
48+ import org .apache .commons .cli .*;
49+
50+
4751
4852import org .json .simple .JSONObject ;
4953import org .json .simple .parser .JSONParser ;
5054
55+ import scala .collection .JavaConversions ;
5156import java .io .BufferedWriter ;
5257import java .io .IOException ;
5358import java .nio .file .Files ;
5459import java .nio .file .Paths ;
5560import java .sql .SQLException ;
5661import java .util .ArrayList ;
62+ import java .util .Arrays ;
5763import java .util .Collection ;
5864import java .util .Properties ;
5965import java .util .concurrent .atomic .AtomicInteger ;
@@ -103,19 +109,40 @@ public static void main(final String[] args) throws Exception {
103109 throw new IllegalArgumentException (
104110 "Usage: ./bin/wayang-submit org.apache.wayang.api.sql.SqlContext <SQL statement path> <JDBC driver> <JDBC URL> <JDBC user> <JDBC password> <Result output path> [platforms...]" );
105111
106- final String queryPath = args [0 ];
107- final String jdbcDriver = args [1 ];
108- final String jdbcUrl = args [2 ];
109- final String jdbcUser = args [3 ];
110- final String jdbcPassword = args [4 ];
111- final String outputPath = args [5 ];
112+ //Specify the named arguments
113+ Options options = new Options ();
114+ options .addOption ("p" , "platforms" , true , "[platforms...]" );
115+ options .addOption ("q" , "query" , true , "SQL statement path" );
116+ options .addOption ("jdbcDriver" , true , "JDBC driver" );
117+ options .addOption ("jdbcUrl" , true , "JDBC URL" );
118+ options .addOption ("jdbcPassword" , true , "JDBC URL" );
119+ options .addOption ("o" , "outputPath" , true , "Output path" );
120+ options .addOption ("d" , "data" , true , "Data path for file-based schema" );
121+ options .addOption ("c" , "config" , true , "File path for config file" );
122+
123+ CommandLineParser parser = new DefaultParser ();
124+ CommandLine cmd = parser .parse (options , args );
125+
126+ final String queryPath = cmd .getOptionValue ("q" );
127+ final String jdbcDriver = cmd .getOptionValue ("jdbcDriver" );
128+ final String jdbcUrl = cmd .getOptionValue ("jdbcUrl" );
129+ final String jdbcUser = cmd .getOptionValue ("jdbcUser" );
130+ final String jdbcPassword = cmd .getOptionValue ("jdbcPassword" );
131+ final String outputPath = cmd .getOptionValue ("o" );
132+ final String dataPath = cmd .getOptionValue ("d" );
112133
113134 final String query = StringUtils .chop (
114135 Files .readString (Paths .get (queryPath ))
115136 .stripTrailing ());
116137
117138 final String driverPlatform = jdbcDriver .split ("\\ ." )[0 ];
118139
140+ final Configuration configuration = new Configuration ();
141+
142+ if (cmd .hasOption ("c" )) {
143+ configuration .load (cmd .getOptionValue ("c" ));
144+ }
145+
119146 final String calciteModel = String .format (
120147 "{\r \n " +
121148 "\" calcite\" : {\r \n " +
@@ -132,15 +159,20 @@ public static void main(final String[] args) throws Exception {
132159 " \" jdbcUser\" : \" %s\" ,\n " +
133160 " \" jdbcPassword\" : \" %s\" \n " +
134161 " }\n " +
162+ " },\n " +
163+ " {\n " +
164+ " \" name\" : \" fs\" ,\n " +
165+ " \" type\" : \" custom\" , \n " +
166+ " \" factory\" : \" org.apache.calcite.adapter.file.FileSchemaFactory\" ,\n " +
167+ " \" operand\" : {\n " +
168+ " \" directory\" : \" " + dataPath + "\" \n " +
169+ " }\n " +
135170 " }\n " +
136171 " ]\n " +
137172 "}\r \n " +
138173 "}" ,
139174 jdbcDriver , jdbcUrl , jdbcUser , jdbcPassword );
140175
141- final Configuration configuration = new Configuration ();
142- configuration .load (ReflectionUtils .loadResource ("wayang-defaults.properties" ));
143-
144176 configuration .setProperty ("wayang.calcite.model" , calciteModel );
145177 configuration .setProperty (String .format ("wayang.%s.jdbc.url" , driverPlatform ), jdbcUrl );
146178 configuration .setProperty (String .format ("wayang.%s.jdbc.user" , driverPlatform ), jdbcUser );
@@ -153,23 +185,9 @@ public static void main(final String[] args) throws Exception {
153185 final SqlContext context = new SqlContext (parseModel ,
154186 List .of (Java .channelConversionPlugin (), Postgres .conversionPlugin ()));
155187
156- for (int i = 6 ; i < args .length ; i ++) {
157- final String platform = args [i ];
158-
159- switch (platform .toLowerCase ()) {
160- case "spark" :
161- context .withPlugin (Spark .basicPlugin ());
162- break ;
163- case "java" :
164- context .withPlugin (Java .basicPlugin ());
165- break ;
166- case "postgres" :
167- context .withPlugin (Postgres .plugin ());
168- break ;
169- default :
170- throw new IllegalArgumentException ("platform not supported " + platform );
171- }
172- }
188+
189+ List <Plugin > plugins = JavaConversions .seqAsJavaList (Parameters .loadPlugins (cmd .getOptionValue ("p" )));
190+ plugins .stream ().forEach (plug -> context .register (plug ));
173191
174192 final Collection <Record > result = context .executeSql (query );
175193
0 commit comments