Skip to content

Commit 048a665

Browse files
committed
Create packages for bigquery and outline spi layer
1 parent fac7687 commit 048a665

File tree

9 files changed

+567
-0
lines changed

9 files changed

+567
-0
lines changed

gcloud-java-bigquery/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
Google Cloud Java Client for BigQuery
2+
====================================
3+
4+
Java idiomatic client for [Google Cloud BigQuery] (https://cloud.google.com/bigquery).
5+
6+
[![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java)
7+
[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master)
8+
<!-- TODO(mziccard): add in the maven shield once the artifact is pushed to maven -->
9+
10+
- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
11+
+<!-- TODO(mziccard): add link to API documentatin -->
12+
13+
> Note: This client is a work-in-progress, and may occasionally
14+
> make backwards-incompatible changes.
15+
16+
Quickstart
17+
----------
18+
Add this to your pom.xml file
19+
<!-- TODO(mziccard): add dependency code -->
20+
21+
22+
Example Application
23+
-------------------
24+
25+
<!-- TODO(mziccard): add example application -->
26+
27+
Authentication
28+
--------------
29+
30+
See the [Authentication](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) section in the base directory's README.
31+
32+
About Google Cloud BigQuery
33+
--------------------------
34+
35+
[Google Cloud BigQuery][cloud-bigquery] is a fully managed, NoOps, low cost data analytics service.
36+
Data can be streamed into BigQuery at millions of rows per second to enable real-time analysis.
37+
With BigQuery you can easily deploy Petabyte-scale Databases.
38+
39+
Be sure to activate the Google Cloud Resource Manager API on the Developer's Console to use Resource Manager from your project.
40+
41+
See the ``gcloud-java`` API [bigquery documentation][bigquery-api] to learn how to interact
42+
with Google Cloud BigQuery using this Client Library.
43+
44+
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) and a project ID if running this snippet elsewhere.
45+
46+
<!-- TODO(mziccard): add code snippet -->
47+
48+
Java Versions
49+
-------------
50+
51+
Java 7 or above is required for using this client.
52+
53+
Testing
54+
-------
55+
56+
<!-- TODO(mziccard): add this in once the RemoteGCBQMHelper class is functional -->
57+
58+
Versioning
59+
----------
60+
61+
This library follows [Semantic Versioning] (http://semver.org/).
62+
63+
It is currently in major version zero (``0.y.z``), which means that anything
64+
may change at any time and the public API should not be considered
65+
stable.
66+
67+
Contributing
68+
------------
69+
70+
Contributions to this library are always welcome and highly encouraged.
71+
72+
See [CONTRIBUTING] for more information on how to get started.
73+
74+
License
75+
-------
76+
77+
Apache 2.0 - See [LICENSE] for more information.
78+
79+
80+
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
81+
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
82+
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-bigquery
83+
[cloud-platform]: https://cloud.google.com/
84+
85+
[cloud-bigquery]: https://cloud.google.com/bigquery/
86+
[bigquery-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/bigquery/package-summary.html

gcloud-java-bigquery/pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.google.gcloud</groupId>
5+
<artifactId>gcloud-java-bigquery</artifactId>
6+
<packaging>jar</packaging>
7+
<name>GCloud Java bigquery</name>
8+
<description>
9+
Java idiomatic client for Google Cloud BigQuery.
10+
</description>
11+
<parent>
12+
<groupId>com.google.gcloud</groupId>
13+
<artifactId>gcloud-java-pom</artifactId>
14+
<version>0.0.11-SNAPSHOT</version>
15+
</parent>
16+
<properties>
17+
<site.installationModule>gcloud-java-bigquery</site.installationModule>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>${project.groupId}</groupId>
22+
<artifactId>gcloud-java-core</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.google.apis</groupId>
27+
<artifactId>google-api-services-bigquery</artifactId>
28+
<version>v2-rev239-1.20.0</version>
29+
<scope>compile</scope>
30+
<exclusions>
31+
<exclusion>
32+
<groupId>com.google.guava</groupId>
33+
<artifactId>guava-jdk5</artifactId>
34+
</exclusion>
35+
</exclusions>
36+
</dependency>
37+
<dependency>
38+
<groupId>junit</groupId>
39+
<artifactId>junit</artifactId>
40+
<version>4.12</version>
41+
<scope>test</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.easymock</groupId>
45+
<artifactId>easymock</artifactId>
46+
<version>3.3</version>
47+
<scope>test</scope>
48+
</dependency>
49+
</dependencies>
50+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.bigquery;
18+
19+
import com.google.gcloud.Service;
20+
21+
/**
22+
* An interface for Google Cloud BigQuery.
23+
*
24+
* @see <a href="https://cloud.google.com/bigquery/what-is-bigquery">Google Cloud BigQuery</a>
25+
*/
26+
public interface Bigquery extends Service<BigqueryOptions> {
27+
28+
// TODO(mziccard) add missing methods
29+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.bigquery;
18+
19+
import com.google.gcloud.RetryHelper;
20+
import com.google.gcloud.RetryHelper.RetryHelperException;
21+
22+
/**
23+
* BigQuery service exception.
24+
*
25+
* @see <a href="https://cloud.google.com/bigquery/troubleshooting-errors">Google Cloud
26+
* BigQuery error codes</a>
27+
*/
28+
public class BigqueryException extends RuntimeException {
29+
30+
private static final long serialVersionUID = -1914262521588059797L;
31+
public static final int UNKNOWN_CODE = -1;
32+
33+
private final int code;
34+
private final boolean retryable;
35+
36+
public BigqueryException(int code, String message, boolean retryable) {
37+
super(message);
38+
this.code = code;
39+
this.retryable = retryable;
40+
}
41+
42+
/**
43+
* Returns the code associated with this exception.
44+
*/
45+
public int code() {
46+
return code;
47+
}
48+
49+
public boolean retryable() {
50+
return retryable;
51+
}
52+
53+
/**
54+
* Translate RetryHelperException to the BigqueryException that caused the error. This method will
55+
* always throw an exception.
56+
*
57+
* @throws BigqueryException when {@code ex} was caused by a {@code BigqueryException}
58+
* @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException}
59+
*/
60+
static BigqueryException translateAndThrow(RetryHelperException ex) {
61+
if (ex.getCause() instanceof BigqueryException) {
62+
throw (BigqueryException) ex.getCause();
63+
}
64+
if (ex instanceof RetryHelper.RetryInterruptedException) {
65+
RetryHelper.RetryInterruptedException.propagate();
66+
}
67+
throw new BigqueryException(UNKNOWN_CODE, ex.getMessage(), false);
68+
}
69+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.bigquery;
18+
19+
20+
import com.google.gcloud.ServiceFactory;
21+
22+
/**
23+
* An interface for BigQuery factories.
24+
*/
25+
public interface BigqueryFactory extends ServiceFactory<Bigquery, BigqueryOptions> {
26+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.bigquery;
18+
19+
import com.google.common.collect.ImmutableSet;
20+
import com.google.gcloud.ServiceOptions;
21+
import com.google.gcloud.spi.DefaultBigqueryRpc;
22+
import com.google.gcloud.spi.BigqueryRpc;
23+
import com.google.gcloud.spi.BigqueryRpcFactory;
24+
25+
import java.util.Set;
26+
27+
public class BigqueryOptions extends ServiceOptions<Bigquery, BigqueryRpc, BigqueryOptions> {
28+
29+
private static final String BIGQUERY_SCOPE = "https://www.googleapis.com/auth/bigquery";
30+
private static final Set<String> SCOPES = ImmutableSet.of(BIGQUERY_SCOPE);
31+
private static final long serialVersionUID = -215981591481708043L;
32+
33+
public static class DefaultBigqueryFactory implements BigqueryFactory {
34+
35+
private static final BigqueryFactory INSTANCE = new DefaultBigqueryFactory();
36+
37+
@Override
38+
public Bigquery create(BigqueryOptions options) {
39+
// TODO(mziccard) return new BigqueryImpl(options);
40+
return null;
41+
}
42+
}
43+
44+
public static class DefaultBigqueryRpcFactory implements BigqueryRpcFactory {
45+
46+
private static final BigqueryRpcFactory INSTANCE = new DefaultBigqueryRpcFactory();
47+
48+
@Override
49+
public BigqueryRpc create(BigqueryOptions options) {
50+
// TODO(mziccard) return new DefaultBigqueryRpc(options);
51+
return null;
52+
}
53+
}
54+
55+
public static class Builder extends
56+
ServiceOptions.Builder<Bigquery, BigqueryRpc, BigqueryOptions, Builder> {
57+
58+
private Builder() {
59+
}
60+
61+
private Builder(BigqueryOptions options) {
62+
super(options);
63+
}
64+
65+
@Override
66+
public BigqueryOptions build() {
67+
return new BigqueryOptions(this);
68+
}
69+
}
70+
71+
private BigqueryOptions(Builder builder) {
72+
super(BigqueryFactory.class, BigqueryRpcFactory.class, builder);
73+
}
74+
75+
@Override
76+
protected BigqueryFactory defaultServiceFactory() {
77+
return DefaultBigqueryFactory.INSTANCE;
78+
}
79+
80+
@Override
81+
protected BigqueryRpcFactory defaultRpcFactory() {
82+
return DefaultBigqueryRpcFactory.INSTANCE;
83+
}
84+
85+
@Override
86+
protected Set<String> scopes() {
87+
return SCOPES;
88+
}
89+
90+
@Override
91+
public Builder toBuilder() {
92+
return new Builder(this);
93+
}
94+
95+
@Override
96+
public int hashCode() {
97+
return baseHashCode();
98+
}
99+
100+
@Override
101+
public boolean equals(Object obj) {
102+
if (!(obj instanceof BigqueryOptions)) {
103+
return false;
104+
}
105+
BigqueryOptions other = (BigqueryOptions) obj;
106+
return baseEquals(other);
107+
}
108+
109+
public static Builder builder() {
110+
return new Builder();
111+
}
112+
}

0 commit comments

Comments
 (0)