-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Refactor BigQuery samples. #297
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
/** | ||
* Sample of how to Export Cloud Data. | ||
*/ | ||
public class ExportDataCloudStorageSample { | ||
public class ExportDataCloudStorageSample { | ||
/** | ||
* Protected constructor since this is a collection of static functions. | ||
*/ | ||
|
@@ -42,20 +42,17 @@ 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sure there is a good reason why we don't use command line args, w/ reasonable defaults. |
||
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(); | ||
|
||
|
@@ -79,30 +76,33 @@ public static void run( | |
final String projectId, | ||
final String datasetId, | ||
final String tableId, | ||
final long interval) throws IOException, InterruptedException { | ||
final long interval) | ||
throws IOException, InterruptedException { | ||
|
||
Bigquery bigquery = BigqueryServiceFactory.getService(); | ||
Bigquery bigquery = BigQueryServiceFactory.getService(); | ||
|
||
Job extractJob = extractJob( | ||
bigquery, | ||
cloudStoragePath, | ||
new TableReference() | ||
.setProjectId(projectId) | ||
.setDatasetId(datasetId) | ||
.setTableId(tableId)); | ||
Job extractJob = | ||
extractJob( | ||
bigquery, | ||
cloudStoragePath, | ||
new TableReference() | ||
.setProjectId(projectId) | ||
.setDatasetId(datasetId) | ||
.setTableId(tableId)); | ||
|
||
Bigquery.Jobs.Get getJob = bigquery.jobs().get( | ||
extractJob.getJobReference().getProjectId(), | ||
extractJob.getJobReference().getJobId()); | ||
Bigquery.Jobs.Get getJob = | ||
bigquery | ||
.jobs() | ||
.get( | ||
extractJob.getJobReference().getProjectId(), | ||
extractJob.getJobReference().getJobId()); | ||
|
||
BigqueryUtils.pollJob(getJob, 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 | ||
|
@@ -113,16 +113,17 @@ public static void run( | |
*/ | ||
// [START extract_job] | ||
public static Job extractJob( | ||
final Bigquery bigquery, | ||
final String cloudStoragePath, | ||
final TableReference table) throws IOException { | ||
final Bigquery bigquery, final String cloudStoragePath, final TableReference table) | ||
throws IOException { | ||
|
||
JobConfigurationExtract extract = new JobConfigurationExtract() | ||
.setSourceTable(table) | ||
.setDestinationUri(cloudStoragePath); | ||
JobConfigurationExtract extract = | ||
new JobConfigurationExtract().setSourceTable(table).setDestinationUri(cloudStoragePath); | ||
|
||
return bigquery.jobs().insert(table.getProjectId(), | ||
new Job().setConfiguration(new JobConfiguration().setExtract(extract))) | ||
return bigquery | ||
.jobs() | ||
.insert( | ||
table.getProjectId(), | ||
new Job().setConfiguration(new JobConfiguration().setExtract(extract))) | ||
.execute(); | ||
} | ||
// [END extract_job] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some reason these aren't command line args, with defaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the way it was in the existing sample, and it didn't bother me as much as some of the other things I fixed. I can look at changing this, too.