@@ -83,29 +83,17 @@ class LeaderBoardRunner {
8383 " timing:STRING"
8484 ]. join(" ," )
8585
86- // Remove existing tables if they exist
8786 String tables = t. run(" bq query --use_legacy_sql=false 'SELECT table_name FROM ${ dataset} .INFORMATION_SCHEMA.TABLES'" )
8887
89- if (tables. contains(userTable)) {
90- t. run(" bq rm -f -t ${ dataset} .${ userTable} " )
88+ if (! tables. contains(userTable)) {
89+ t. intent(" Creating table: ${ userTable} " )
90+ t. run(" bq mk --table ${ dataset} .${ userTable} ${ userSchema} " )
9191 }
92- if (tables. contains(teamTable)) {
93- t. run(" bq rm -f -t ${ dataset} .${ teamTable} " )
92+ if (! tables. contains(teamTable)) {
93+ t. intent(" Creating table: ${ teamTable} " )
94+ t. run(" bq mk --table ${ dataset} .${ teamTable} ${ teamSchema} " )
9495 }
9596
96- // It will take couple seconds to clean up tables.
97- // This loop makes sure tables are completely deleted before running the pipeline
98- tables = t. run(" bq query --use_legacy_sql=false 'SELECT table_name FROM ${ dataset} .INFORMATION_SCHEMA.TABLES'" )
99- while (tables. contains(userTable) || tables. contains(teamTable)) {
100- sleep(3000 )
101- tables = t. run(" bq query --use_legacy_sql=false 'SELECT table_name FROM ${ dataset} .INFORMATION_SCHEMA.TABLES'" )
102- }
103-
104- t. intent(" Creating table: ${ userTable} " )
105- t. run(" bq mk --table ${ dataset} .${ userTable} ${ userSchema} " )
106- t. intent(" Creating table: ${ teamTable} " )
107- t. run(" bq mk --table ${ dataset} .${ teamTable} ${ teamSchema} " )
108-
10997 // Verify that the tables have been created successfully
11098 tables = t. run(" bq query --use_legacy_sql=false 'SELECT table_name FROM ${ dataset} .INFORMATION_SCHEMA.TABLES'" )
11199 while (! tables. contains(userTable) || ! tables. contains(teamTable)) {
167155 (useStreamingEngine ? " with Streaming Engine" : " " ))
168156 }
169157 t. success(" LeaderBoard successfully run on DataflowRunner." + (useStreamingEngine ? " with Streaming Engine" : " " ))
158+
159+ tables = t. run(" bq query --use_legacy_sql=false 'SELECT table_name FROM ${ dataset} .INFORMATION_SCHEMA.TABLES'" )
160+ if (tables. contains(userTable)) {
161+ t. run(" bq rm -f -t ${ dataset} .${ userTable} " )
162+ }
163+ if (tables. contains(teamTable)) {
164+ t. run(" bq rm -f -t ${ dataset} .${ teamTable} " )
165+ }
166+
167+ // It will take couple seconds to clean up tables.
168+ // This loop makes sure tables are completely deleted before running the pipeline
169+ tables = t. run(" bq query --use_legacy_sql=false 'SELECT table_name FROM ${ dataset} .INFORMATION_SCHEMA.TABLES'" )
170+ while (tables. contains(userTable) || tables. contains(teamTable)) {
171+ sleep(3000 )
172+ tables = t. run(" bq query --use_legacy_sql=false 'SELECT table_name FROM ${ dataset} .INFORMATION_SCHEMA.TABLES'" )
173+ }
170174 }
171175}
172176
0 commit comments