12
12
See the License for the specific language governing permissions and
13
13
limitations under the License.
14
14
*/
15
+
15
16
package com .google .cloud .bigquery .samples ;
16
17
17
18
import com .google .api .services .bigquery .Bigquery ;
31
32
/**
32
33
* Cli tool to load data from a CSV into Bigquery.
33
34
*/
34
- public class LoadDataCSVSample {
35
-
36
- /**
37
- * Protected constructor since this is a collection of static methods.
38
- */
39
- protected LoadDataCSVSample () {
35
+ public class LoadDataCsvSample {
40
36
41
- }
37
+ /**
38
+ * Protected constructor since this is a collection of static methods.
39
+ */
40
+ protected LoadDataCsvSample () {
41
+ }
42
42
43
- /**
44
- * Cli tool to load data from a CSV into Bigquery.
45
- * @param args Command line args, should be empty
46
- * @throws IOException IOException
47
- * @throws InterruptedException InterruptedException
48
- */
43
+ /**
44
+ * Cli tool to load data from a CSV into Bigquery.
45
+ * @param args Command line args, should be empty
46
+ * @throws IOException IOException
47
+ * @throws InterruptedException InterruptedException
48
+ */
49
49
// [START main]
50
- public static void main (final String [] args ) throws IOException ,
51
- InterruptedException {
50
+ public static void main (final String [] args )
51
+ throws IOException , InterruptedException {
52
52
Scanner scanner = new Scanner (System .in );
53
53
System .out .println ("Enter your project id: " );
54
54
String projectId = scanner .nextLine ();
@@ -57,14 +57,14 @@ public static void main(final String[] args) throws IOException,
57
57
System .out .println ("Enter your table id: " );
58
58
String tableId = scanner .nextLine ();
59
59
System .out .println ("Enter the Google Cloud Storage Path to the data "
60
- + "you'd like to load: " );
60
+ + "you'd like to load: " );
61
61
String cloudStoragePath = scanner .nextLine ();
62
62
System .out .println ("Enter the filepath to your schema: " );
63
63
String sourceSchemaPath = scanner .nextLine ();
64
64
65
65
66
66
System .out .println ("Enter how often to check if your job is complete "
67
- + "(milliseconds): " );
67
+ + "(milliseconds): " );
68
68
long interval = scanner .nextLong ();
69
69
scanner .close ();
70
70
@@ -74,21 +74,20 @@ public static void main(final String[] args) throws IOException,
74
74
tableId ,
75
75
new FileReader (new File (sourceSchemaPath )),
76
76
interval );
77
-
78
77
}
79
78
// [END main]
80
79
81
- /**
82
- * Run the bigquery ClI.
83
- * @param cloudStoragePath The bucket we are using
84
- * @param projectId Project id
85
- * @param datasetId datasetid
86
- * @param tableId tableid
87
- * @param schemaSource Source of the schema
88
- * @param interval interval to wait between polling in milliseconds
89
- * @throws IOException Thrown if there is an error connecting to Bigquery.
90
- * @throws InterruptedException Should never be thrown
91
- */
80
+ /**
81
+ * Run the bigquery ClI.
82
+ * @param cloudStoragePath The bucket we are using
83
+ * @param projectId Project id
84
+ * @param datasetId datasetid
85
+ * @param tableId tableid
86
+ * @param schemaSource Source of the schema
87
+ * @param interval interval to wait between polling in milliseconds
88
+ * @throws IOException Thrown if there is an error connecting to Bigquery.
89
+ * @throws InterruptedException Should never be thrown
90
+ */
92
91
// [START run]
93
92
public static void run (
94
93
final String cloudStoragePath ,
@@ -121,15 +120,15 @@ public static void run(
121
120
}
122
121
// [END run]
123
122
124
- /**
125
- * A job that extracts data from a table.
126
- * @param bigquery Bigquery service to use
127
- * @param cloudStoragePath Cloud storage bucket we are inserting into
128
- * @param table Table to extract from
129
- * @param schema The schema of the table we are loading into
130
- * @return The job to extract data from the table
131
- * @throws IOException Thrown if error connceting to Bigtable
132
- */
123
+ /**
124
+ * A job that extracts data from a table.
125
+ * @param bigquery Bigquery service to use
126
+ * @param cloudStoragePath Cloud storage bucket we are inserting into
127
+ * @param table Table to extract from
128
+ * @param schema The schema of the table we are loading into
129
+ * @return The job to extract data from the table
130
+ * @throws IOException Thrown if error connceting to Bigtable
131
+ */
133
132
// [START load_job]
134
133
public static Job loadJob (
135
134
final Bigquery bigquery ,
@@ -138,15 +137,13 @@ public static Job loadJob(
138
137
final TableSchema schema ) throws IOException {
139
138
140
139
JobConfigurationLoad load = new JobConfigurationLoad ()
141
- .setDestinationTable (table )
142
- .setSchema (schema )
143
- .setSourceUris (Collections .singletonList (cloudStoragePath ));
140
+ .setDestinationTable (table )
141
+ .setSchema (schema )
142
+ .setSourceUris (Collections .singletonList (cloudStoragePath ));
144
143
145
144
return bigquery .jobs ().insert (table .getProjectId (),
146
145
new Job ().setConfiguration (new JobConfiguration ().setLoad (load )))
147
146
.execute ();
148
147
}
149
148
// [END load_job]
150
-
151
-
152
149
}
0 commit comments