1919
2020import org .apache .commons .lang3 .StringUtils ;
2121
22-
2322import org .apache .calcite .jdbc .CalciteSchema ;
2423import org .apache .calcite .jdbc .JavaTypeFactoryImpl ;
2524import org .apache .calcite .rel .RelNode ;
4746import org .apache .wayang .spark .Spark ;
4847import org .apache .commons .cli .*;
4948
50-
49+ import com . google . common . io . Resources ;
5150
5251import org .json .simple .JSONObject ;
5352import org .json .simple .parser .JSONParser ;
5655import java .io .BufferedWriter ;
5756import java .io .IOException ;
5857import java .nio .file .Files ;
58+ import java .nio .charset .Charset ;
5959import java .nio .file .Paths ;
60+ import java .net .URL ;
6061import java .sql .SQLException ;
6162import java .util .ArrayList ;
6263import java .util .Arrays ;
@@ -112,13 +113,14 @@ public static void main(final String[] args) throws Exception {
112113 //Specify the named arguments
113114 Options options = new Options ();
114115 options .addOption ("p" , "platforms" , true , "[platforms...]" );
116+ options .addOption ("s" , "schema" , true , "Schema path" );
115117 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" );
119118 options .addOption ("o" , "outputPath" , true , "Output path" );
120119 options .addOption ("d" , "data" , true , "Data path for file-based schema" );
121120 options .addOption ("c" , "config" , true , "File path for config file" );
121+ options .addOption ("jdbcDriver" , true , "JDBC driver" );
122+ options .addOption ("jdbcUrl" , true , "JDBC URL" );
123+ options .addOption ("jdbcPassword" , true , "JDBC URL" );
122124
123125 CommandLineParser parser = new DefaultParser ();
124126 CommandLine cmd = parser .parse (options , args );
@@ -130,6 +132,7 @@ public static void main(final String[] args) throws Exception {
130132 final String jdbcPassword = cmd .getOptionValue ("jdbcPassword" );
131133 final String outputPath = cmd .getOptionValue ("o" );
132134 final String dataPath = cmd .getOptionValue ("d" );
135+ final String schemaPath = cmd .getOptionValue ("s" );
133136
134137 final String query = StringUtils .chop (
135138 Files .readString (Paths .get (queryPath ))
@@ -143,35 +146,10 @@ public static void main(final String[] args) throws Exception {
143146 configuration .load (cmd .getOptionValue ("c" ));
144147 }
145148
146- final String calciteModel = String .format (
147- "{\r \n " +
148- "\" calcite\" : {\r \n " +
149- " \" version\" : \" 1.0\" ,\n " +
150- " \" defaultSchema\" : \" wayang\" ,\n " +
151- " \" schemas\" : [\n " +
152- " {\n " +
153- " \" name\" : \" postgres\" ,\n " +
154- " \" type\" : \" custom\" ,\n " +
155- " \" factory\" : \" org.apache.wayang.api.sql.calcite.jdbc.JdbcSchema$Factory\" ,\n " +
156- " \" operand\" : {\n " +
157- " \" jdbcDriver\" : \" %s\" ,\n " +
158- " \" jdbcUrl\" : \" %s\" ,\n " +
159- " \" jdbcUser\" : \" %s\" ,\n " +
160- " \" jdbcPassword\" : \" %s\" \n " +
161- " }\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 " +
170- " }\n " +
171- " ]\n " +
172- "}\r \n " +
173- "}" ,
174- jdbcDriver , jdbcUrl , jdbcUser , jdbcPassword );
149+ final String calciteModel = Resources .toString (
150+ new URL (schemaPath ),
151+ Charset .defaultCharset ()
152+ );
175153
176154 configuration .setProperty ("wayang.calcite.model" , calciteModel );
177155 configuration .setProperty (String .format ("wayang.%s.jdbc.url" , driverPlatform ), jdbcUrl );
@@ -185,7 +163,6 @@ public static void main(final String[] args) throws Exception {
185163 final SqlContext context = new SqlContext (parseModel ,
186164 List .of (Java .channelConversionPlugin (), Postgres .conversionPlugin ()));
187165
188-
189166 List <Plugin > plugins = JavaConversions .seqAsJavaList (Parameters .loadPlugins (cmd .getOptionValue ("p" )));
190167 plugins .stream ().forEach (plug -> context .register (plug ));
191168
0 commit comments