2222import com .google .common .base .Preconditions ;
2323import com .google .common .collect .Lists ;
2424import java .io .File ;
25+ import java .io .IOException ;
2526import java .net .URL ;
2627import java .util .ArrayList ;
2728import java .util .Arrays ;
@@ -39,6 +40,7 @@ public List<String> types() {
3940
4041 private static final String TAB = "\t \t " ;
4142 private static final String NEW_LINE = "\n " ;
43+ private static final String DEFAULT_BOOTSTRAP_DIRECTORY = "examples/batch/baseballStats" ;
4244
4345 public enum Color {
4446 RESET ("\u001B [0m" ), GREEN ("\u001B [32m" ), YELLOW ("\u001B [33m" ), CYAN ("\u001B [36m" );
@@ -54,10 +56,6 @@ public String getCode() {
5456 }
5557 }
5658
57- public String getBootstrapDataDir () {
58- return "examples/batch/baseballStats" ;
59- }
60-
6159 public int getNumMinions () {
6260 return 0 ;
6361 }
@@ -91,30 +89,17 @@ public static String prettyPrintResponse(JsonNode response) {
9189
9290 public void execute ()
9391 throws Exception {
92+ String tableName = getTableName (DEFAULT_BOOTSTRAP_DIRECTORY );
9493 File quickstartTmpDir = new File (_dataDir , String .valueOf (System .currentTimeMillis ()));
95- File baseDir = new File (quickstartTmpDir , "baseballStats" );
94+ File baseDir = new File (quickstartTmpDir , tableName );
9695 File dataDir = new File (baseDir , "rawdata" );
9796 Preconditions .checkState (dataDir .mkdirs ());
9897
99- File schemaFile = new File (baseDir , "baseballStats_schema.json" );
100- File tableConfigFile = new File (baseDir , "baseballStats_offline_table_config.json" );
101- File ingestionJobSpecFile = new File (baseDir , "ingestionJobSpec.yaml" );
102- File dataFile = new File (dataDir , "baseballStats_data.csv" );
103-
104- ClassLoader classLoader = Quickstart .class .getClassLoader ();
105- URL resource = classLoader .getResource (getBootstrapDataDir () + "/baseballStats_schema.json" );
106- com .google .common .base .Preconditions .checkNotNull (resource );
107- FileUtils .copyURLToFile (resource , schemaFile );
108- resource = classLoader .getResource (getBootstrapDataDir () + "/rawdata/baseballStats_data.csv" );
109- com .google .common .base .Preconditions .checkNotNull (resource );
110- FileUtils .copyURLToFile (resource , dataFile );
111- resource = classLoader .getResource (getBootstrapDataDir () + "/ingestionJobSpec.yaml" );
112- if (resource != null ) {
113- FileUtils .copyURLToFile (resource , ingestionJobSpecFile );
98+ if (useDefaultBootstrapTableDir ()) {
99+ copyResourceTableToTmpDirectory (getBootstrapDataDir (DEFAULT_BOOTSTRAP_DIRECTORY ), tableName , baseDir , dataDir );
100+ } else {
101+ copyFilesystemTableToTmpDirectory (getBootstrapDataDir (DEFAULT_BOOTSTRAP_DIRECTORY ), tableName , baseDir );
114102 }
115- resource = classLoader .getResource (getBootstrapDataDir () + "/baseballStats_offline_table_config.json" );
116- com .google .common .base .Preconditions .checkNotNull (resource );
117- FileUtils .copyURLToFile (resource , tableConfigFile );
118103
119104 QuickstartTableRequest request = new QuickstartTableRequest (baseDir .getAbsolutePath ());
120105 QuickstartRunner runner =
@@ -133,13 +118,74 @@ public void execute()
133118 e .printStackTrace ();
134119 }
135120 }));
136- printStatus (Color .CYAN , "***** Bootstrap baseballStats table *****" );
121+ printStatus (Color .CYAN , "***** Bootstrap " + tableName + " table *****" );
137122 runner .bootstrapTable ();
138123
139124 waitForBootstrapToComplete (runner );
140125
141126 printStatus (Color .YELLOW , "***** Offline quickstart setup complete *****" );
142127
128+ if (useDefaultBootstrapTableDir ()) {
129+ // Quickstart is using the default baseballStats sample table, so run sample queries.
130+ runSampleQueries (runner );
131+ }
132+
133+ printStatus (Color .GREEN , "You can always go to http://localhost:9000 to play around in the query console" );
134+ }
135+
136+ private static void copyResourceTableToTmpDirectory (String sourcePath , String tableName , File baseDir , File dataDir )
137+ throws IOException {
138+
139+ File schemaFile = new File (baseDir , tableName + "_schema.json" );
140+ File tableConfigFile = new File (baseDir , tableName + "_offline_table_config.json" );
141+ File ingestionJobSpecFile = new File (baseDir , "ingestionJobSpec.yaml" );
142+ File dataFile = new File (dataDir , tableName + "_data.csv" );
143+
144+ ClassLoader classLoader = Quickstart .class .getClassLoader ();
145+ URL resource = classLoader .getResource (sourcePath + File .separator + tableName + "_schema.json" );
146+ com .google .common .base .Preconditions .checkNotNull (resource );
147+ FileUtils .copyURLToFile (resource , schemaFile );
148+ resource =
149+ classLoader .getResource (sourcePath + File .separator + "rawdata" + File .separator + tableName + "_data.csv" );
150+ com .google .common .base .Preconditions .checkNotNull (resource );
151+ FileUtils .copyURLToFile (resource , dataFile );
152+ resource = classLoader .getResource (sourcePath + File .separator + "ingestionJobSpec.yaml" );
153+ if (resource != null ) {
154+ FileUtils .copyURLToFile (resource , ingestionJobSpecFile );
155+ }
156+ resource = classLoader .getResource (sourcePath + File .separator + tableName + "_offline_table_config.json" );
157+ com .google .common .base .Preconditions .checkNotNull (resource );
158+ FileUtils .copyURLToFile (resource , tableConfigFile );
159+ }
160+
161+ private static void copyFilesystemTableToTmpDirectory (String sourcePath , String tableName , File baseDir )
162+ throws IOException {
163+ File fileDb = new File (sourcePath );
164+
165+ if (!fileDb .exists () || !fileDb .isDirectory ()) {
166+ throw new RuntimeException ("Directory " + fileDb .getAbsolutePath () + " not found." );
167+ }
168+
169+ File schemaFile = new File (fileDb , tableName + "_schema.json" );
170+ if (!schemaFile .exists ()) {
171+ throw new RuntimeException ("Schema file " + schemaFile .getAbsolutePath () + " not found." );
172+ }
173+
174+ File tableFile = new File (fileDb , tableName + "_offline_table_config.json" );
175+ if (!tableFile .exists ()) {
176+ throw new RuntimeException ("Table table " + tableFile .getAbsolutePath () + " not found." );
177+ }
178+
179+ File data = new File (fileDb , "rawdata" + File .separator + tableName + "_data.csv" );
180+ if (!data .exists ()) {
181+ throw new RuntimeException (("Data file " + data .getAbsolutePath () + " not found. " ));
182+ }
183+
184+ FileUtils .copyDirectory (fileDb , baseDir );
185+ }
186+
187+ private static void runSampleQueries (QuickstartRunner runner )
188+ throws Exception {
143189 String q1 = "select count(*) from baseballStats limit 1" ;
144190 printStatus (Color .YELLOW , "Total number of documents in the table" );
145191 printStatus (Color .CYAN , "Query : " + q1 );
@@ -173,8 +219,6 @@ public void execute()
173219 printStatus (Color .CYAN , "Query : " + q5 );
174220 printStatus (Color .YELLOW , prettyPrintResponse (runner .runQuery (q5 )));
175221 printStatus (Color .GREEN , "***************************************************" );
176-
177- printStatus (Color .GREEN , "You can always go to http://localhost:9000 to play around in the query console" );
178222 }
179223
180224 public static void main (String [] args )
0 commit comments