Skip to content

Move examples from the cloud-storage-docs-xml-api-examples repo, and update them to use Application Default Credentials. #14

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

Merged
merged 27 commits into from
May 29, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bafd8c3
Move from cloud-storagedocs-xml-api-examples
May 22, 2015
fed4ae8
Update READMEs for new dir structure
May 22, 2015
9ebe7fa
Rename directories to be less redundant.
May 22, 2015
dcf91cc
Update to use App Default Creds.
May 22, 2015
ccf5fc8
Remove package, so eclipse isn't confused.
May 22, 2015
dd10b2c
Add Application Default Credentials quirks.
May 22, 2015
309d399
Update: no longer using service accounts.
May 26, 2015
f606873
Merge remote-tracking branch 'origin/master' into jerjou/xml-api
May 28, 2015
014079d
Add checkstyle plugin
May 28, 2015
c2b6935
More check style configuration
May 28, 2015
1b9f309
Fix style on DeferSampleServlet
May 28, 2015
45920e1
More check style changes
May 28, 2015
0e4514f
Finish fixing Async Query and Defer Sample
May 28, 2015
99a7533
Fix style in BigqueryServiceFactory
May 28, 2015
3f58947
Fix style errors on BigqueryUtils
May 28, 2015
8fc1c6d
Fix style on ExportDataCloudStorageSample
May 28, 2015
e514139
Fix style on LoadDataCsvSample
May 28, 2015
d989529
Remove vestigial key.json. README points to doc
May 28, 2015
78daa80
Fix StreamingSample checkstyle
May 28, 2015
005689f
Fix SyncQuerySample
May 28, 2015
69e24dc
Fail on bad style
May 28, 2015
b34b01c
Fix java style violations.
May 28, 2015
5019fb6
Merge branch 'jerjou/xml-api' of github.com:GoogleCloudPlatform/java-…
May 28, 2015
957da6b
Fix java style violations.
May 28, 2015
a0d74ee
Remove unused 'all' tag.
May 28, 2015
3f26d5b
Style: prettier line break.
May 29, 2015
a33bbb0
AsyncQuerySample extends BigqueryUtils, so can't be final
May 29, 2015
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
Prev Previous commit
Next Next commit
Fix style on ExportDataCloudStorageSample
  • Loading branch information
Bill Prin committed May 28, 2015
commit 8fc1c6ddd4659394a8ce97e2db9c08b42e2ad718
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final class BigqueryUtils {
* Private contructor to prevent creation of this class, which is just all
* static helper methods.
*/
private BigqueryUtils() {
protected BigqueryUtils() {

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
Copyright 2015, Google, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
Copyright 2015, Google, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.google.cloud.bigquery.samples;
Expand All @@ -24,79 +24,112 @@
import java.util.Scanner;

/**
* TODO: Insert description here. (generated by elibixby)
* Sample of how to Export Cloud Data.
*/
public class ExportDataCloudStorageSample extends BigqueryUtils {
public class ExportDataCloudStorageSample {

/**
* 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
* CLI.
* @param args Command line args
* @throws IOException If there is an error connceting to bigquery
* @throws InterruptedException Should never be thrown.
*/
// [START main]
public static void main(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();
System.out.println("Enter your dataset id: ");
String datasetId = scanner.nextLine();
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: ");
System.out.println("Enter the Google Cloud Storage Path to which you'd "
+ "like to export: ");
String cloudStoragePath = scanner.nextLine();
System.out.println("Enter how often to check if your job is complete (milliseconds): ");
System.out.println("Enter how often to check if your job is complete "
+ "(milliseconds): ");
long interval = scanner.nextLong();
scanner.close();

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

}
// [END main]


/**
* Run the bigquery ClI.
* @param cloudStoragePath The bucket we are using
* @param projectId Project id
* @param datasetId datasetid
* @param tableId tableid
* @param interval interval to wait between polling in milliseconds
* @throws IOException Thrown if there is an error connecting to Bigquery.
* @throws InterruptedException Should never be thrown
*/
// [START run]
public static void run(
String cloudStoragePath,
String projectId,
String datasetId,
String tableId,
long interval) throws IOException, InterruptedException{
public static void run(
final String cloudStoragePath,
final String projectId,
final String datasetId,
final String tableId,
final long interval) throws IOException, InterruptedException {

Bigquery bigquery = BigqueryServiceFactory.getService();

Job extractJob = extractJob(
bigquery,
cloudStoragePath,
new TableReference()
.setProjectId(projectId)
.setDatasetId(datasetId)
.setTableId(tableId));
Bigquery.Jobs.Get get_job = bigquery.jobs().get(
extractJob.getJobReference().getProjectId(),

Bigquery.Jobs.Get getJob = bigquery.jobs().get(
extractJob.getJobReference().getProjectId(),
extractJob.getJobReference().getJobId());
pollJob(get_job, interval);

BigqueryUtils.pollJob(getJob, interval);

System.out.println("Export is Done!");

}
// [END run]




/**
* A job that extracts data from a table.
* @param bigquery Bigquery service to use
* @param cloudStoragePath Cloud storage bucket we are inserting into
* @param table Table to extract from
* @return The job to extract data from the table
* @throws IOException Thrown if error connceting to Bigtable
*/
// [START extract_job]
public static Job extractJob(
Bigquery bigquery,
String cloudStoragePath,
TableReference table) throws IOException{
final Bigquery bigquery,
final String cloudStoragePath,
final TableReference table) throws IOException {

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

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




}