-
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
BQ Data Transfer: Add quickstart sample #972
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1b89481
BQ Data Transfer: Add quickstart sample
tswast 391db12
Hello 2018. Update license headers for data transfer.
tswast 49d606e
Use Java 8 for data transfer sample.
tswast 3b674c0
Merge branch 'master' into bqdt-quickstart
lesv 879a3fb
Add bigquery data transfer samples to root pom.xml
tswast eac676b
Merge branch 'bqdt-quickstart' of github.com:GoogleCloudPlatform/java…
tswast 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Getting Started with BigQuery Data Transfer API | ||
|
||
[BigQuery Data Transfer Service][BigQuery Data Transfer] features an API that | ||
allows developers to create transfer jobs from data sources to BigQuery. | ||
These sample Java applications demonstrate how to access the BigQuery Data | ||
Transfer API using the [Google Cloud Client Library for | ||
Java][google-cloud-java]. | ||
|
||
[BigQuery Data Transfer]: https://cloud.google.com/bigquery/docs/transfer-service-overview | ||
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java | ||
|
||
## Quickstart | ||
|
||
Install [Maven](http://maven.apache.org/). | ||
|
||
[Authenticate using a service account](https://cloud.google.com/docs/authentication/getting-started). | ||
Create a service account, download a JSON key file, and set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable. | ||
|
||
Build your project with: | ||
|
||
mvn clean package -DskipTests | ||
|
||
You can then run a given `ClassName` via: | ||
|
||
mvn exec:java -Dexec.mainClass=com.example.bigquerydatatransfer.ClassName \ | ||
-DpropertyName=propertyValue \ | ||
-Dexec.args="any arguments to the app" | ||
|
||
### Listing available data sources | ||
|
||
mvn exec:java -Dexec.mainClass=com.example.bigquerydatatransfer.QuickstartSample \ | ||
-Dexec.args='YOUR_PROJECT_ID' |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!-- | ||
Copyright 2018 Google LLC | ||
|
||
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. | ||
--> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.example.bigquerydatatransfer</groupId> | ||
<artifactId>bigquerydatatransfer-google-cloud-samples</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<!-- Parent defines config for testing & linting. --> | ||
<parent> | ||
<artifactId>doc-samples</artifactId> | ||
<groupId>com.google.cloud</groupId> | ||
<version>1.0.0</version> | ||
<relativePath>../../..</relativePath> | ||
</parent> | ||
|
||
<properties> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- [START dependencies] --> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-bigquerydatatransfer</artifactId> | ||
<version>0.32.0-beta</version> | ||
</dependency> | ||
<!-- [END dependencies] --> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.truth</groupId> | ||
<artifactId>truth</artifactId> | ||
<version>0.36</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
58 changes: 58 additions & 0 deletions
58
...ransfer/cloud-client/src/main/java/com/example/bigquerydatatransfer/QuickstartSample.java
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
|
||
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.example.bigquerydatatransfer; | ||
|
||
// [START bigquery_datatransfer_quickstart] | ||
// Imports the Google Cloud client library | ||
import com.google.cloud.bigquery.datatransfer.v1.DataSource; | ||
import com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient; | ||
import com.google.cloud.bigquery.datatransfer.v1.ListDataSourcesRequest; | ||
import com.google.cloud.bigquery.datatransfer.v1.PagedResponseWrappers.ListDataSourcesPagedResponse; | ||
|
||
public class QuickstartSample { | ||
/** | ||
* List available data sources for the BigQuery Data Transfer service. | ||
*/ | ||
public static void main(String... args) throws Exception { | ||
// Sets your Google Cloud Platform project ID. | ||
// String projectId = "YOUR_PROJECT_ID"; | ||
String projectId = args[0]; | ||
|
||
// Instantiate a client. If you don't specify credentials when constructing a client, the | ||
// client library will look for credentials in the environment, such as the | ||
// GOOGLE_APPLICATION_CREDENTIALS environment variable. | ||
try (DataTransferServiceClient client = DataTransferServiceClient.create()) { | ||
// Request the list of available data sources. | ||
String parent = String.format("projects/%s", projectId); | ||
ListDataSourcesRequest request = | ||
ListDataSourcesRequest.newBuilder() | ||
.setParent(parent) | ||
.build(); | ||
ListDataSourcesPagedResponse response = client.listDataSources(request); | ||
|
||
// Print the results. | ||
System.out.println("Supported Data Sources:"); | ||
for (DataSource dataSource : response.iterateAll()) { | ||
System.out.println(dataSource.getDisplayName()); | ||
System.out.printf("\tID: %s%n", dataSource.getDataSourceId()); | ||
System.out.printf("\tFull path: %s%n", dataSource.getName()); | ||
System.out.printf("\tDescription: %s%n", dataSource.getDescription()); | ||
} | ||
} | ||
} | ||
} | ||
// [END bigquery_datatransfer_quickstart] |
56 changes: 56 additions & 0 deletions
56
...nsfer/cloud-client/src/test/java/com/example/bigquerydatatransfer/QuickstartSampleIT.java
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
|
||
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.example.bigquerydatatransfer; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** Tests for quickstart sample. */ | ||
@RunWith(JUnit4.class) | ||
@SuppressWarnings("checkstyle:abbreviationaswordinname") | ||
public class QuickstartSampleIT { | ||
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); | ||
|
||
private ByteArrayOutputStream bout; | ||
private PrintStream out; | ||
|
||
@Before | ||
public void setUp() { | ||
bout = new ByteArrayOutputStream(); | ||
out = new PrintStream(bout); | ||
System.setOut(out); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
System.setOut(null); | ||
} | ||
|
||
@Test | ||
public void testQuickstart() throws Exception { | ||
QuickstartSample.main(PROJECT_ID); | ||
String got = bout.toString(); | ||
assertThat(got).contains("Supported Data Sources:"); | ||
} | ||
} |
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
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.
There should be a link at least to something about Auth?
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.
Done. Added a note about auth to both the sample and this readme (in the Quickstart section).
Since auth is needed across products, I think we should investigate using Jason's README generator. I believe Python, Ruby, and Node.js are all using it already.