Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce style. #35

Merged
merged 2 commits into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions bigquery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@
<artifactId>google-oauth-client-jetty</artifactId>
<version>${project.oauth.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-matchers</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@
* Example of authorizing with BigQuery and reading from a public dataset.
*/
public class AsyncQuerySample extends BigqueryUtils {


// [START main]
/**
* Prompts for all the parameters required to make a query.
*
* @param args Command line args
* @throws IOException IOException
* @throws InterruptedException InterruptedException
*/
public static void main(final String[] args)
throws IOException, InterruptedException {

Scanner scanner = new Scanner(System.in);
System.out.println("Enter your project id: ");
String projectId = scanner.nextLine();
Expand All @@ -52,20 +51,20 @@ public static void main(final String[] args)
System.out.println("Run query in batch mode? [true|false] ");
boolean batch = Boolean.valueOf(scanner.nextLine());
System.out.println("Enter how often to check if your job is complete "
+ "(milliseconds): ");
+ "(milliseconds): ");
long waitTime = scanner.nextLong();
scanner.close();
Iterator<GetQueryResultsResponse> pages = run(projectId, queryString,
batch, waitTime);
batch, waitTime);
while (pages.hasNext()) {
printRows(pages.next().getRows(), System.out);
}

}
// [END main]
// [START run]

// [START run]
/**
* Run the query.
*
* @param projectId Get this from Google Developers console
* @param queryString Query we want to run against BigQuery
Expand All @@ -75,7 +74,7 @@ public static void main(final String[] args)
* @throws IOException Thrown if there's an IOException
* @throws InterruptedException Thrown if there's an Interrupted Exception
*/
public static Iterator<GetQueryResultsResponse> run(final String projectId,
public static Iterator<GetQueryResultsResponse> run(final String projectId,
final String queryString,
final boolean batch,
final long waitTime)
Expand All @@ -94,7 +93,7 @@ public static Iterator<GetQueryResultsResponse> run(final String projectId,
GetQueryResults resultsRequest = bigquery.jobs().getQueryResults(
projectId, query.getJobReference().getJobId());

return getPages(resultsRequest);
return getPages(resultsRequest);
}
// [END run]

Expand All @@ -115,7 +114,7 @@ public static Job asyncQuery(final Bigquery bigquery,
final boolean batch) throws IOException {

JobConfigurationQuery queryConfig = new JobConfigurationQuery()
.setQuery(querySql);
.setQuery(querySql);

if (batch) {
queryConfig.setPriority("BATCH");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.google.cloud.bigquery.samples;

import com.google.api.client.json.GenericJson;
Expand Down Expand Up @@ -44,7 +45,6 @@ public class BigqueryUtils {
* static helper methods.
*/
protected BigqueryUtils() {

}

/**
Expand All @@ -53,12 +53,11 @@ protected BigqueryUtils() {
* @param out Output stream we want to print to
*/
// [START print_rows]
public static void printRows(final List<TableRow> rows, final PrintStream
out) {
public static void printRows(final List<TableRow> rows, final PrintStream out) {
for (TableRow row : rows) {
for (TableCell field : row.getF()) {
out.printf("%-50s", field.getV());
}
}
out.println();
}
}
Expand All @@ -73,14 +72,13 @@ public static void printRows(final List<TableRow> rows, final PrintStream
* @throws InterruptedException InterruptedException
*/
// [START poll_job]
public static Job pollJob(final Bigquery.Jobs.Get request, final long
interval)
public static Job pollJob(final Bigquery.Jobs.Get request, final long interval)
throws IOException, InterruptedException {
Job job = request.execute();
while (!job.getStatus().getState().equals("DONE")) {
System.out.println("Job is "
+ job.getStatus().getState()
+ " waiting " + interval + " milliseconds...");
+ job.getStatus().getState()
+ " waiting " + interval + " milliseconds...");
Thread.sleep(interval);
job = request.execute();
}
Expand All @@ -97,7 +95,7 @@ public static Job pollJob(final Bigquery.Jobs.Get request, final long
*/
// [START paging]
public static <T extends GenericJson> Iterator<T> getPages(
final BigqueryRequest<T> requestTemplate) {
final BigqueryRequest<T> requestTemplate) {

/**
* An iterator class that pages through a Bigquery request.
Expand Down Expand Up @@ -168,8 +166,8 @@ public static TableSchema loadSchema(final Reader schemaSource) {
TableSchema sourceSchema = new TableSchema();

List<TableFieldSchema> fields = (new Gson())
.<List<TableFieldSchema>>fromJson(schemaSource,
(new ArrayList<TableFieldSchema>()).getClass());
.<List<TableFieldSchema>>fromJson(schemaSource,
(new ArrayList<TableFieldSchema>()).getClass());

sourceSchema.setFields(fields);

Expand All @@ -186,8 +184,7 @@ public static TableSchema loadSchema(final Reader schemaSource) {
* @throws IOException Thrown if there is a network error connecting to
* Bigquery.
*/
public static void listDatasets(final Bigquery bigquery, final String
projectId)
public static void listDatasets(final Bigquery bigquery, final String projectId)
throws IOException {
Datasets.List datasetRequest = bigquery.datasets().list(projectId);
DatasetList datasetList = datasetRequest.execute();
Expand All @@ -201,5 +198,4 @@ public static void listDatasets(final Bigquery bigquery, final String
}
}
// [END list_datasets]

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@
* Sample of how to Export Cloud Data.
*/
public class ExportDataCloudStorageSample {

/**
* Protected constructor since this is a collection of static functions.
*/
protected ExportDataCloudStorageSample() {
super();
}
/**
* Protected constructor since this is a collection of static functions.
*/
protected ExportDataCloudStorageSample() {
super();
}

/**
* This program can be run to demonstrate running a Bigquery query from the
Expand All @@ -43,8 +42,8 @@ protected ExportDataCloudStorageSample() {
* @throws InterruptedException Should never be thrown.
*/
// [START main]
public static void main(final String[] args) throws IOException,
InterruptedException {
public static void main(final String[] args)
throws IOException, InterruptedException {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your project id: ");
String projectId = scanner.nextLine();
Expand All @@ -53,15 +52,14 @@ public static void main(final String[] args) throws IOException,
System.out.println("Enter your table id: ");
String tableId = scanner.nextLine();
System.out.println("Enter the Google Cloud Storage Path to which you'd "
+ "like to export: ");
+ "like to export: ");
String cloudStoragePath = scanner.nextLine();
System.out.println("Enter how often to check if your job is complete "
+ "(milliseconds): ");
+ "(milliseconds): ");
long interval = scanner.nextLong();
scanner.close();

run(cloudStoragePath, projectId, datasetId, tableId, interval);

}
// [END main]

Expand Down Expand Up @@ -120,16 +118,12 @@ public static Job extractJob(
final TableReference table) throws IOException {

JobConfigurationExtract extract = new JobConfigurationExtract()
.setSourceTable(table)
.setDestinationUri(cloudStoragePath);
.setSourceTable(table)
.setDestinationUri(cloudStoragePath);

return bigquery.jobs().insert(table.getProjectId(),
new Job().setConfiguration(new JobConfiguration().setExtract(extract)))
.execute();
}
// [END extract_job]




}
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,24 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
// [START all]
package com.google.cloud.bigquery.samples;


package com.google.cloud.bigquery.samples;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
// [START all]
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.store.DataStoreFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.bigquery.Bigquery.Datasets;
import com.google.api.services.bigquery.Bigquery.Jobs.Insert;
import com.google.api.services.bigquery.Bigquery;
import com.google.api.services.bigquery.BigqueryScopes;
import com.google.api.services.bigquery.model.DatasetList;
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import com.google.api.services.bigquery.model.Job;
import com.google.api.services.bigquery.model.JobConfiguration;
import com.google.api.services.bigquery.model.JobConfigurationQuery;
import com.google.api.services.bigquery.model.JobReference;
import com.google.api.services.bigquery.model.QueryRequest;
import com.google.api.services.bigquery.model.QueryResponse;
import com.google.api.services.bigquery.model.TableCell;
import com.google.api.services.bigquery.model.TableRow;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

Expand Down Expand Up @@ -144,7 +121,7 @@ private static void printResults(List<TableRow> rows) {
*/
public static void main(String[] args) throws IOException {
Scanner sc;
if(args.length == 0) {
if (args.length == 0) {
// Prompt the user to enter the id of the project to run the queries under
System.out.print("Enter the project ID: ");
sc = new Scanner(System.in);
Expand Down
Loading