Skip to content

Commit 8fc1c6d

Browse files
author
Bill Prin
committed
Fix style on ExportDataCloudStorageSample
1 parent 3f58947 commit 8fc1c6d

File tree

2 files changed

+77
-44
lines changed

2 files changed

+77
-44
lines changed

bigquery/src/main/java/com/google/cloud/bigquery/samples/BigqueryUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class BigqueryUtils {
4343
* Private contructor to prevent creation of this class, which is just all
4444
* static helper methods.
4545
*/
46-
private BigqueryUtils() {
46+
protected BigqueryUtils() {
4747

4848
}
4949

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/*
2-
Copyright 2015, Google, Inc.
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
6-
7-
http://www.apache.org/licenses/LICENSE-2.0
8-
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
2+
Copyright 2015, Google, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515
package com.google.cloud.bigquery.samples;
@@ -24,79 +24,112 @@
2424
import java.util.Scanner;
2525

2626
/**
27-
* TODO: Insert description here. (generated by elibixby)
27+
* Sample of how to Export Cloud Data.
2828
*/
29-
public class ExportDataCloudStorageSample extends BigqueryUtils {
29+
public class ExportDataCloudStorageSample {
3030

31+
/**
32+
* Protected constructor since this is a collection of static functions.
33+
*/
34+
protected ExportDataCloudStorageSample() {
35+
super();
36+
}
3137

32-
38+
/**
39+
* This program can be run to demonstrate running a Bigquery query from the
40+
* CLI.
41+
* @param args Command line args
42+
* @throws IOException If there is an error connceting to bigquery
43+
* @throws InterruptedException Should never be thrown.
44+
*/
3345
// [START main]
34-
public static void main(String[] args) throws IOException, InterruptedException{
46+
public static void main(final String[] args) throws IOException,
47+
InterruptedException {
3548
Scanner scanner = new Scanner(System.in);
3649
System.out.println("Enter your project id: ");
3750
String projectId = scanner.nextLine();
3851
System.out.println("Enter your dataset id: ");
3952
String datasetId = scanner.nextLine();
4053
System.out.println("Enter your table id: ");
4154
String tableId = scanner.nextLine();
42-
System.out.println("Enter the Google Cloud Storage Path to which you'd like to export: ");
55+
System.out.println("Enter the Google Cloud Storage Path to which you'd "
56+
+ "like to export: ");
4357
String cloudStoragePath = scanner.nextLine();
44-
System.out.println("Enter how often to check if your job is complete (milliseconds): ");
58+
System.out.println("Enter how often to check if your job is complete "
59+
+ "(milliseconds): ");
4560
long interval = scanner.nextLong();
4661
scanner.close();
47-
62+
4863
run(cloudStoragePath, projectId, datasetId, tableId, interval);
49-
64+
5065
}
5166
// [END main]
52-
67+
68+
/**
69+
* Run the bigquery ClI.
70+
* @param cloudStoragePath The bucket we are using
71+
* @param projectId Project id
72+
* @param datasetId datasetid
73+
* @param tableId tableid
74+
* @param interval interval to wait between polling in milliseconds
75+
* @throws IOException Thrown if there is an error connecting to Bigquery.
76+
* @throws InterruptedException Should never be thrown
77+
*/
5378
// [START run]
54-
public static void run(
55-
String cloudStoragePath,
56-
String projectId,
57-
String datasetId,
58-
String tableId,
59-
long interval) throws IOException, InterruptedException{
79+
public static void run(
80+
final String cloudStoragePath,
81+
final String projectId,
82+
final String datasetId,
83+
final String tableId,
84+
final long interval) throws IOException, InterruptedException {
6085

6186
Bigquery bigquery = BigqueryServiceFactory.getService();
62-
87+
6388
Job extractJob = extractJob(
6489
bigquery,
6590
cloudStoragePath,
6691
new TableReference()
6792
.setProjectId(projectId)
6893
.setDatasetId(datasetId)
6994
.setTableId(tableId));
70-
71-
Bigquery.Jobs.Get get_job = bigquery.jobs().get(
72-
extractJob.getJobReference().getProjectId(),
95+
96+
Bigquery.Jobs.Get getJob = bigquery.jobs().get(
97+
extractJob.getJobReference().getProjectId(),
7398
extractJob.getJobReference().getJobId());
74-
75-
pollJob(get_job, interval);
76-
99+
100+
BigqueryUtils.pollJob(getJob, interval);
101+
77102
System.out.println("Export is Done!");
78-
103+
79104
}
80105
// [END run]
81-
82-
106+
107+
108+
/**
109+
* A job that extracts data from a table.
110+
* @param bigquery Bigquery service to use
111+
* @param cloudStoragePath Cloud storage bucket we are inserting into
112+
* @param table Table to extract from
113+
* @return The job to extract data from the table
114+
* @throws IOException Thrown if error connceting to Bigtable
115+
*/
83116
// [START extract_job]
84117
public static Job extractJob(
85-
Bigquery bigquery,
86-
String cloudStoragePath,
87-
TableReference table) throws IOException{
88-
118+
final Bigquery bigquery,
119+
final String cloudStoragePath,
120+
final TableReference table) throws IOException {
121+
89122
JobConfigurationExtract extract = new JobConfigurationExtract()
90123
.setSourceTable(table)
91124
.setDestinationUri(cloudStoragePath);
92125

93-
return bigquery.jobs().insert(table.getProjectId(),
126+
return bigquery.jobs().insert(table.getProjectId(),
94127
new Job().setConfiguration(new JobConfiguration().setExtract(extract)))
95128
.execute();
96129
}
97130
// [END extract_job]
98131

99-
100-
132+
133+
101134

102135
}

0 commit comments

Comments
 (0)