forked from googleapis/google-cloud-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigQueryRpc.java
More file actions
188 lines (152 loc) · 5.71 KB
/
BigQueryRpc.java
File metadata and controls
188 lines (152 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* 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.gcloud.spi;
import com.google.api.services.bigquery.model.Dataset;
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import com.google.api.services.bigquery.model.Job;
import com.google.api.services.bigquery.model.QueryRequest;
import com.google.api.services.bigquery.model.QueryResponse;
import com.google.api.services.bigquery.model.Table;
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
import com.google.api.services.bigquery.model.TableRow;
import com.google.gcloud.bigquery.BigQueryException;
import java.util.Map;
public interface BigQueryRpc {
// These options are part of the Google Cloud BigQuery query parameters
enum Option {
FIELDS("fields"),
DELETE_CONTENTS("deleteContents"),
ALL_DATASETS("all"),
ALL_USERS("allUsers"),
MAX_RESULTS("maxResults"),
PAGE_TOKEN("pageToken"),
START_INDEX("startIndex"),
STATE_FILTER("stateFilter"),
TIMEOUT("timeoutMs");
private final String value;
Option(String value) {
this.value = value;
}
public String value() {
return value;
}
@SuppressWarnings("unchecked")
<T> T get(Map<Option, ?> options) {
return (T) options.get(this);
}
String getString(Map<Option, ?> options) {
return get(options);
}
Long getLong(Map<Option, ?> options) {
return get(options);
}
Boolean getBoolean(Map<Option, ?> options) {
return get(options);
}
}
class Tuple<X, Y> {
private final X x;
private final Y y;
private Tuple(X x, Y y) {
this.x = x;
this.y = y;
}
public static <X, Y> Tuple<X, Y> of(X x, Y y) {
return new Tuple<>(x, y);
}
public X x() {
return x;
}
public Y y() {
return y;
}
}
/**
* Returns the requested dataset or {@code null} if not found.
*
* @throws BigQueryException upon failure
*/
Dataset getDataset(String datasetId, Map<Option, ?> options) throws BigQueryException;
/**
* Lists the project's datasets. Partial information is returned on a dataset (datasetReference,
* friendlyName and id). To get full information use {@link #getDataset(String, Map)}.
*
* @throws BigQueryException upon failure
*/
Tuple<String, Iterable<Dataset>> listDatasets(Map<Option, ?> options) throws BigQueryException;
Dataset create(Dataset dataset, Map<Option, ?> options) throws BigQueryException;
Table create(Table table, Map<Option, ?> options) throws BigQueryException;
Job create(Job job, Map<Option, ?> options) throws BigQueryException;
/**
* Delete the requested dataset.
*
* @return {@code true} if dataset was deleted, {@code false} if it was not found
* @throws BigQueryException upon failure
*/
boolean deleteDataset(String datasetId, Map<Option, ?> options) throws BigQueryException;
Dataset patch(Dataset dataset, Map<Option, ?> options) throws BigQueryException;
Table patch(Table table, Map<Option, ?> options) throws BigQueryException;
/**
* Returns the requested table or {@code null} if not found.
*
* @throws BigQueryException upon failure
*/
Table getTable(String datasetId, String tableId, Map<Option, ?> options) throws BigQueryException;
/**
* Lists the dataset's tables. Partial information is returned on a table (tableReference,
* friendlyName, id and type). To get full information use {@link #getTable(String, String, Map)}.
*
* @throws BigQueryException upon failure
*/
Tuple<String, Iterable<Table>> listTables(String dataset, Map<Option, ?> options)
throws BigQueryException;
/**
* Delete the requested table.
*
* @return {@code true} if table was deleted, {@code false} if it was not found
* @throws BigQueryException upon failure
*/
boolean deleteTable(String datasetId, String tableId) throws BigQueryException;
TableDataInsertAllResponse insertAll(String datasetId, String tableId,
TableDataInsertAllRequest request) throws BigQueryException;
Tuple<String, Iterable<TableRow>> listTableData(String datasetId, String tableId,
Map<Option, ?> options) throws BigQueryException;
/**
* Returns the requested job or {@code null} if not found.
*
* @throws BigQueryException upon failure
*/
Job getJob(String jobId, Map<Option, ?> options) throws BigQueryException;
/**
* Lists the project's jobs.
*
* @throws BigQueryException upon failure
*/
Tuple<String, Iterable<Job>> listJobs(Map<Option, ?> options) throws BigQueryException;
/**
* Sends a job cancel request. This call will return immediately, and the client will need to poll
* for the job status to see if the cancel completed successfully.
*
* @return {@code true} if cancel was requested successfully, {@code false} if the job was not
* found
* @throws BigQueryException upon failure
*/
boolean cancel(String jobId) throws BigQueryException;
GetQueryResultsResponse getQueryResults(String jobId, Map<Option, ?> options)
throws BigQueryException;
QueryResponse query(QueryRequest request) throws BigQueryException;
}