Skip to content

Commit 0f6a47e

Browse files
Adding QueryParameter support in BigQuery (#1451)
Also: * Adding DATE/TIME/DATETIME to LegacySQLTypeName
1 parent 84480fb commit 0f6a47e

File tree

9 files changed

+1318
-103
lines changed

9 files changed

+1318
-103
lines changed

google-cloud-bigquery/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>com.google.apis</groupId>
3333
<artifactId>google-api-services-bigquery</artifactId>
34-
<version>v2-rev303-1.22.0</version>
34+
<version>v2-rev330-1.22.0</version>
3535
<scope>compile</scope>
3636
<exclusions>
3737
<exclusion>

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Field.java

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,15 @@ public static class Type implements Serializable {
7272

7373
private static final long serialVersionUID = 2841484762609576959L;
7474

75-
public enum Value {
76-
BYTES, STRING, INTEGER, FLOAT, BOOLEAN, TIMESTAMP, RECORD
77-
}
78-
79-
private final Value value;
75+
private final LegacySQLTypeName value;
8076
private final List<Field> fields;
8177

82-
private Type(Value value) {
78+
private Type(LegacySQLTypeName value) {
8379
this.value = checkNotNull(value);
8480
this.fields = null;
8581
}
8682

87-
private Type(Value value, List<Field> fields) {
83+
private Type(LegacySQLTypeName value, List<Field> fields) {
8884
checkArgument(fields.size() > 0, "Record must have at least one field");
8985
this.value = value;
9086
this.fields = fields;
@@ -97,7 +93,7 @@ private Type(Value value, List<Field> fields) {
9793
* Data Types</a>
9894
*/
9995
@Deprecated
100-
public Value value() {
96+
public LegacySQLTypeName value() {
10197
return getValue();
10298
}
10399

@@ -107,81 +103,81 @@ public Value value() {
107103
* @see <a href="https://cloud.google.com/bigquery/preparing-data-for-bigquery#datatypes">
108104
* Data Types</a>
109105
*/
110-
public Value getValue() {
106+
public LegacySQLTypeName getValue() {
111107
return value;
112108
}
113109

114110
/**
115-
* Returns the list of sub-fields if {@link #value()} is set to {@link Value#RECORD}. Returns
116-
* {@code null} otherwise.
111+
* Returns the list of sub-fields if {@link #value()} is set to {@link
112+
* LegacySQLTypeName#RECORD}. Returns {@code null} otherwise.
117113
*/
118114
@Deprecated
119115
public List<Field> fields() {
120116
return getFields();
121117
}
122118

123119
/**
124-
* Returns the list of sub-fields if {@link #value()} is set to {@link Value#RECORD}. Returns
125-
* {@code null} otherwise.
120+
* Returns the list of sub-fields if {@link #value()} is set to {@link
121+
* LegacySQLTypeName#RECORD}. Returns {@code null} otherwise.
126122
*/
127123
public List<Field> getFields() {
128124
return fields;
129125
}
130126

131127
/**
132-
* Returns a {@link Value#BYTES} field value.
128+
* Returns a {@link LegacySQLTypeName#BYTES} field value.
133129
*/
134130
public static Type bytes() {
135-
return new Type(Value.BYTES);
131+
return new Type(LegacySQLTypeName.BYTES);
136132
}
137133

138134
/**
139-
* Returns a {@link Value#STRING} field value.
135+
* Returns a {@link LegacySQLTypeName#STRING} field value.
140136
*/
141137
public static Type string() {
142-
return new Type(Value.STRING);
138+
return new Type(LegacySQLTypeName.STRING);
143139
}
144140

145141
/**
146-
* Returns an {@link Value#INTEGER} field value.
142+
* Returns an {@link LegacySQLTypeName#INTEGER} field value.
147143
*/
148144
public static Type integer() {
149-
return new Type(Value.INTEGER);
145+
return new Type(LegacySQLTypeName.INTEGER);
150146
}
151147

152148
/**
153-
* Returns a {@link Value#FLOAT} field value.
149+
* Returns a {@link LegacySQLTypeName#FLOAT} field value.
154150
*/
155151
public static Type floatingPoint() {
156-
return new Type(Value.FLOAT);
152+
return new Type(LegacySQLTypeName.FLOAT);
157153
}
158154

159155
/**
160-
* Returns a {@link Value#BOOLEAN} field value.
156+
* Returns a {@link LegacySQLTypeName#BOOLEAN} field value.
161157
*/
162158
public static Type bool() {
163-
return new Type(Value.BOOLEAN);
159+
return new Type(LegacySQLTypeName.BOOLEAN);
164160
}
165161

166162
/**
167-
* Returns a {@link Value#TIMESTAMP} field value.
163+
* Returns a {@link LegacySQLTypeName#TIMESTAMP} field value.
168164
*/
169165
public static Type timestamp() {
170-
return new Type(Value.TIMESTAMP);
166+
return new Type(LegacySQLTypeName.TIMESTAMP);
171167
}
172168

173169
/**
174-
* Returns a {@link Value#RECORD} field value with associated list of sub-fields.
170+
* Returns a {@link LegacySQLTypeName#RECORD} field value with associated list of sub-fields.
175171
*/
176172
public static Type record(Field... fields) {
177-
return new Type(Value.RECORD, ImmutableList.copyOf(fields));
173+
return new Type(LegacySQLTypeName.RECORD, ImmutableList.copyOf(fields));
178174
}
179175

180176
/**
181-
* Returns a {@link Value#RECORD} field value with associated list of sub-fields.
177+
* Returns a {@link LegacySQLTypeName#RECORD} field value with associated list of sub-fields.
182178
*/
183179
public static Type record(List<Field> fields) {
184-
return new Type(Value.RECORD, ImmutableList.copyOf(checkNotNull(fields)));
180+
return new Type(LegacySQLTypeName.RECORD, ImmutableList.copyOf(checkNotNull(fields)));
185181
}
186182

187183
@Override
@@ -389,17 +385,17 @@ public String getDescription() {
389385
}
390386

391387
/**
392-
* Returns the list of sub-fields if {@link #type()} is a {@link Type.Value#RECORD}. Returns
393-
* {@code null} otherwise.
388+
* Returns the list of sub-fields if {@link #type()} is a {@link LegacySQLTypeName#RECORD}.
389+
* Returns {@code null} otherwise.
394390
*/
395391
@Deprecated
396392
public List<Field> fields() {
397393
return getFields();
398394
}
399395

400396
/**
401-
* Returns the list of sub-fields if {@link #type()} is a {@link Type.Value#RECORD}. Returns
402-
* {@code null} otherwise.
397+
* Returns the list of sub-fields if {@link #type()} is a {@link LegacySQLTypeName#RECORD}.
398+
* Returns {@code null} otherwise.
403399
*/
404400
public List<Field> getFields() {
405401
return type.getFields();
@@ -474,7 +470,7 @@ public static Builder newBuilder(String name, Type type) {
474470
static Field fromPb(TableFieldSchema fieldSchemaPb) {
475471
Builder fieldBuilder = new Builder();
476472
fieldBuilder.setName(fieldSchemaPb.getName());
477-
Type.Value enumValue = Type.Value.valueOf(fieldSchemaPb.getType());
473+
LegacySQLTypeName enumValue = LegacySQLTypeName.valueOf(fieldSchemaPb.getType());
478474
if (fieldSchemaPb.getMode() != null) {
479475
fieldBuilder.setMode(Mode.valueOf(fieldSchemaPb.getMode()));
480476
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2016 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.cloud.bigquery;
18+
19+
/**
20+
* A type used in legacy SQL contexts. NOTE: some contexts use a mix of types; for example,
21+
* for queries that use standard SQL, the return types are the legacy SQL types.
22+
*
23+
* @see <a href="https://cloud.google.com/bigquery/data-types">https://cloud.google.com/bigquery/data-types</a>
24+
*/
25+
public enum LegacySQLTypeName {
26+
/** Variable-length binary data. */
27+
BYTES(StandardSQLTypeName.BYTES),
28+
/** Variable-length character (Unicode) data. */
29+
STRING(StandardSQLTypeName.STRING),
30+
/** A 64-bit signed integer value. */
31+
INTEGER(StandardSQLTypeName.INT64),
32+
/** A 64-bit IEEE binary floating-point value. */
33+
FLOAT(StandardSQLTypeName.FLOAT64),
34+
/** A Boolean value (true or false). */
35+
BOOLEAN(StandardSQLTypeName.BOOL),
36+
/** Represents an absolute point in time, with microsecond precision. */
37+
TIMESTAMP(StandardSQLTypeName.TIMESTAMP),
38+
/** Represents a logical calendar date. Note, support for this type is limited in legacy SQL. */
39+
DATE(StandardSQLTypeName.DATE),
40+
/**
41+
* Represents a time, independent of a specific date, to microsecond precision. Note, support for
42+
* this type is limited in legacy SQL.
43+
*/
44+
TIME(StandardSQLTypeName.TIME),
45+
/**
46+
* Represents a year, month, day, hour, minute, second, and subsecond (microsecond precision).
47+
* Note, support for this type is limited in legacy SQL.
48+
*/
49+
DATETIME(StandardSQLTypeName.DATETIME),
50+
/** A record type with a nested schema. */
51+
RECORD(StandardSQLTypeName.STRUCT);
52+
53+
private StandardSQLTypeName equivalent;
54+
55+
LegacySQLTypeName(StandardSQLTypeName equivalent) {
56+
this.equivalent = equivalent;
57+
}
58+
59+
/**
60+
* Provides the standard SQL type name equivalent to this type name.
61+
*/
62+
public StandardSQLTypeName getStandardType() {
63+
return equivalent;
64+
}
65+
}

0 commit comments

Comments
 (0)