Skip to content

Commit 5621146

Browse files
---
yaml --- r: 8119 b: refs/heads/tswast-patch-1 c: ae640b7 h: refs/heads/master i: 8117: d6ec147 8115: eaea350 8111: 286211c
1 parent 9c8ead3 commit 5621146

5 files changed

Lines changed: 203 additions & 29 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: a909f376c76f26ddbab863531e14aecbae71a211
60+
refs/heads/tswast-patch-1: ae640b7a928e235e0ba87e1a0df00ca0f495a982
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Acl.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

21+
import com.google.api.core.ApiFunction;
2122
import com.google.api.services.bigquery.model.Dataset.Access;
23+
import com.google.cloud.StringEnumType;
24+
import com.google.cloud.StringEnumValue;
2225

2326
import java.io.Serializable;
2427
import java.util.Objects;
@@ -43,21 +46,61 @@ public final class Acl implements Serializable {
4346
*
4447
* @see <a href="https://cloud.google.com/bigquery/access-control#datasetroles">Dataset Roles</a>
4548
*/
46-
public enum Role {
49+
public static final class Role extends StringEnumValue {
50+
private static final long serialVersionUID = -1992679397135956912L;
51+
52+
private static final ApiFunction<String, Role> CONSTRUCTOR =
53+
new ApiFunction<String, Role>() {
54+
@Override
55+
public Role apply(String constant) {
56+
return new Role(constant);
57+
}
58+
};
59+
60+
private static final StringEnumType<Role> type = new StringEnumType(
61+
Role.class,
62+
CONSTRUCTOR);
63+
4764
/**
4865
* Can read, query, copy or export tables in the dataset.
4966
*/
50-
READER,
67+
public static final Role READER = type.createAndRegister("READER");
5168

5269
/**
5370
* Same as {@link #READER} plus can edit or append data in the dataset.
5471
*/
55-
WRITER,
72+
public static final Role WRITER = type.createAndRegister("WRITER");
5673

5774
/**
5875
* Same as {@link #WRITER} plus can update and delete the dataset.
5976
*/
60-
OWNER
77+
public static final Role OWNER = type.createAndRegister("OWNER");
78+
79+
private Role(String constant) {
80+
super(constant);
81+
}
82+
83+
/**
84+
* Get the Role for the given String constant, and throw an exception if the constant is
85+
* not recognized.
86+
*/
87+
public static Role valueOfStrict(String constant) {
88+
return type.valueOfStrict(constant);
89+
}
90+
91+
/**
92+
* Get the Role for the given String constant, and allow unrecognized values.
93+
*/
94+
public static Role valueOf(String constant) {
95+
return type.valueOf(constant);
96+
}
97+
98+
/**
99+
* Return the known values for Role.
100+
*/
101+
public static Role[] values() {
102+
return type.values();
103+
}
61104
}
62105

63106
/**

branches/tswast-patch-1/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.google.cloud.bigquery;
1818

19+
import com.google.api.core.ApiFunction;
20+
import com.google.cloud.StringEnumType;
21+
import com.google.cloud.StringEnumValue;
1922
import com.google.common.base.MoreObjects;
2023
import com.google.common.collect.ImmutableList;
2124
import com.google.common.collect.Lists;
@@ -35,22 +38,62 @@ public class JobStatus implements Serializable {
3538
/**
3639
* Possible states that a BigQuery Job can assume.
3740
*/
38-
public enum State {
41+
public static final class State extends StringEnumValue {
42+
private static final long serialVersionUID = 818920627219751204L;
43+
44+
private static final ApiFunction<String, State> CONSTRUCTOR =
45+
new ApiFunction<String, State>() {
46+
@Override
47+
public State apply(String constant) {
48+
return new State(constant);
49+
}
50+
};
51+
52+
private static final StringEnumType<State> type = new StringEnumType(
53+
State.class,
54+
CONSTRUCTOR);
55+
3956
/**
4057
* The BigQuery Job is waiting to be executed.
4158
*/
42-
PENDING,
59+
public static final State PENDING = type.createAndRegister("PENDING");
4360

4461
/**
4562
* The BigQuery Job is being executed.
4663
*/
47-
RUNNING,
64+
public static final State RUNNING = type.createAndRegister("RUNNING");
4865

4966
/**
5067
* The BigQuery Job has completed either succeeding or failing. If failed {@link #getError()}
5168
* will be non-null.
5269
*/
53-
DONE
70+
public static final State DONE = type.createAndRegister("DONE");
71+
72+
private State(String constant) {
73+
super(constant);
74+
}
75+
76+
/**
77+
* Get the State for the given String constant, and throw an exception if the constant is
78+
* not recognized.
79+
*/
80+
public static State valueOfStrict(String constant) {
81+
return type.valueOfStrict(constant);
82+
}
83+
84+
/**
85+
* Get the State for the given String constant, and allow unrecognized values.
86+
*/
87+
public static State valueOf(String constant) {
88+
return type.valueOf(constant);
89+
}
90+
91+
/**
92+
* Return the known values for State.
93+
*/
94+
public static State[] values() {
95+
return type.values();
96+
}
5497
}
5598

5699
private final State state;

branches/tswast-patch-1/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/LegacySQLTypeName.java

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,63 @@
1616

1717
package com.google.cloud.bigquery;
1818

19+
import com.google.api.core.ApiFunction;
20+
import com.google.cloud.StringEnumType;
21+
import com.google.cloud.StringEnumValue;
22+
1923
/**
2024
* A type used in legacy SQL contexts. NOTE: some contexts use a mix of types; for example,
2125
* for queries that use standard SQL, the return types are the legacy SQL types.
2226
*
2327
* @see <a href="https://cloud.google.com/bigquery/data-types">https://cloud.google.com/bigquery/data-types</a>
2428
*/
25-
public enum LegacySQLTypeName {
29+
public final class LegacySQLTypeName extends StringEnumValue {
30+
private static final long serialVersionUID = 1421040468991161123L;
31+
32+
private static final ApiFunction<String, LegacySQLTypeName> CONSTRUCTOR =
33+
new ApiFunction<String, LegacySQLTypeName>() {
34+
@Override
35+
public LegacySQLTypeName apply(String constant) {
36+
return new LegacySQLTypeName(constant);
37+
}
38+
};
39+
40+
private static final StringEnumType<LegacySQLTypeName> type = new StringEnumType(
41+
LegacySQLTypeName.class,
42+
CONSTRUCTOR);
43+
2644
/** Variable-length binary data. */
27-
BYTES(StandardSQLTypeName.BYTES),
45+
public static final LegacySQLTypeName BYTES = type.createAndRegister("BYTES").setStandardType(StandardSQLTypeName.BYTES);
2846
/** Variable-length character (Unicode) data. */
29-
STRING(StandardSQLTypeName.STRING),
47+
public static final LegacySQLTypeName STRING = type.createAndRegister("STRING").setStandardType(StandardSQLTypeName.STRING);
3048
/** A 64-bit signed integer value. */
31-
INTEGER(StandardSQLTypeName.INT64),
49+
public static final LegacySQLTypeName INTEGER = type.createAndRegister("INTEGER").setStandardType(StandardSQLTypeName.INT64);
3250
/** A 64-bit IEEE binary floating-point value. */
33-
FLOAT(StandardSQLTypeName.FLOAT64),
51+
public static final LegacySQLTypeName FLOAT = type.createAndRegister("FLOAT").setStandardType(StandardSQLTypeName.FLOAT64);
3452
/** A Boolean value (true or false). */
35-
BOOLEAN(StandardSQLTypeName.BOOL),
53+
public static final LegacySQLTypeName BOOLEAN = type.createAndRegister("BOOLEAN").setStandardType(StandardSQLTypeName.BOOL);
3654
/** Represents an absolute point in time, with microsecond precision. */
37-
TIMESTAMP(StandardSQLTypeName.TIMESTAMP),
55+
public static final LegacySQLTypeName TIMESTAMP = type.createAndRegister("TIMESTAMP").setStandardType(StandardSQLTypeName.TIMESTAMP);
3856
/** Represents a logical calendar date. Note, support for this type is limited in legacy SQL. */
39-
DATE(StandardSQLTypeName.DATE),
57+
public static final LegacySQLTypeName DATE = type.createAndRegister("DATE").setStandardType(StandardSQLTypeName.DATE);
4058
/**
4159
* Represents a time, independent of a specific date, to microsecond precision. Note, support for
4260
* this type is limited in legacy SQL.
4361
*/
44-
TIME(StandardSQLTypeName.TIME),
62+
public static final LegacySQLTypeName TIME = type.createAndRegister("TIME").setStandardType(StandardSQLTypeName.TIME);
4563
/**
4664
* Represents a year, month, day, hour, minute, second, and subsecond (microsecond precision).
4765
* Note, support for this type is limited in legacy SQL.
4866
*/
49-
DATETIME(StandardSQLTypeName.DATETIME),
67+
public static final LegacySQLTypeName DATETIME = type.createAndRegister("DATETIME").setStandardType(StandardSQLTypeName.DATETIME);
5068
/** A record type with a nested schema. */
51-
RECORD(StandardSQLTypeName.STRUCT);
69+
public static final LegacySQLTypeName RECORD = type.createAndRegister("RECORD").setStandardType(StandardSQLTypeName.STRUCT);
5270

5371
private StandardSQLTypeName equivalent;
5472

55-
LegacySQLTypeName(StandardSQLTypeName equivalent) {
73+
private LegacySQLTypeName setStandardType(StandardSQLTypeName equivalent) {
5674
this.equivalent = equivalent;
75+
return this;
5776
}
5877

5978
/**
@@ -62,4 +81,30 @@ public enum LegacySQLTypeName {
6281
public StandardSQLTypeName getStandardType() {
6382
return equivalent;
6483
}
84+
85+
private LegacySQLTypeName(String constant) {
86+
super(constant);
87+
}
88+
89+
/**
90+
* Get the LegacySQLTypeName for the given String constant, and throw an exception if the constant is
91+
* not recognized.
92+
*/
93+
public static LegacySQLTypeName valueOfStrict(String constant) {
94+
return type.valueOfStrict(constant);
95+
}
96+
97+
/**
98+
* Get the LegacySQLTypeName for the given String constant, and allow unrecognized values.
99+
*/
100+
public static LegacySQLTypeName valueOf(String constant) {
101+
return type.valueOf(constant);
102+
}
103+
104+
/**
105+
* Return the known values for LegacySQLTypeName.
106+
*/
107+
public static LegacySQLTypeName[] values() {
108+
return type.values();
109+
}
65110
}

branches/tswast-patch-1/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDefinition.java

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

21+
import com.google.api.core.ApiFunction;
2122
import com.google.api.services.bigquery.model.Table;
23+
import com.google.cloud.StringEnumType;
24+
import com.google.cloud.StringEnumValue;
2225
import com.google.common.base.MoreObjects;
2326

2427
import java.io.Serializable;
@@ -37,20 +40,34 @@ public abstract class TableDefinition implements Serializable {
3740
/**
3841
* The table type.
3942
*/
40-
public enum Type {
43+
public static final class Type extends StringEnumValue {
44+
private static final long serialVersionUID = -551560816480511474L;
45+
46+
private static final ApiFunction<String, Type> CONSTRUCTOR =
47+
new ApiFunction<String, Type>() {
48+
@Override
49+
public Type apply(String constant) {
50+
return new Type(constant);
51+
}
52+
};
53+
54+
private static final StringEnumType<Type> type = new StringEnumType(
55+
Type.class,
56+
CONSTRUCTOR);
57+
4158
/**
4259
* A normal BigQuery table. Instances of {@code TableDefinition} for this type are implemented
4360
* by {@link StandardTableDefinition}.
4461
*/
45-
TABLE,
62+
public static final Type TABLE = type.createAndRegister("TABLE");
4663

4764
/**
4865
* A virtual table defined by a SQL query. Instances of {@code TableDefinition} for this type
4966
* are implemented by {@link ViewDefinition}.
5067
*
5168
* @see <a href="https://cloud.google.com/bigquery/querying-data#views">Views</a>
5269
*/
53-
VIEW,
70+
public static final Type VIEW = type.createAndRegister("VIEW");
5471

5572
/**
5673
* A BigQuery table backed by external data. Instances of {@code TableDefinition} for this type
@@ -59,7 +76,33 @@ public enum Type {
5976
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
6077
* Sources</a>
6178
*/
62-
EXTERNAL
79+
public static final Type EXTERNAL = type.createAndRegister("EXTERNAL");
80+
81+
private Type(String constant) {
82+
super(constant);
83+
}
84+
85+
/**
86+
* Get the Type for the given String constant, and throw an exception if the constant is
87+
* not recognized.
88+
*/
89+
public static Type valueOfStrict(String constant) {
90+
return type.valueOfStrict(constant);
91+
}
92+
93+
/**
94+
* Get the Type for the given String constant, and allow unrecognized values.
95+
*/
96+
public static Type valueOf(String constant) {
97+
return type.valueOf(constant);
98+
}
99+
100+
/**
101+
* Return the known values for Type.
102+
*/
103+
public static Type[] values() {
104+
return type.values();
105+
}
63106
}
64107

65108
/**
@@ -170,12 +213,12 @@ Table toPb() {
170213

171214
@SuppressWarnings("unchecked")
172215
static <T extends TableDefinition> T fromPb(Table tablePb) {
173-
switch (Type.valueOf(tablePb.getType())) {
174-
case TABLE:
216+
switch (Type.valueOf(tablePb.getType()).toString()) {
217+
case "TABLE":
175218
return (T) StandardTableDefinition.fromPb(tablePb);
176-
case VIEW:
219+
case "VIEW":
177220
return (T) ViewDefinition.fromPb(tablePb);
178-
case EXTERNAL:
221+
case "EXTERNAL":
179222
return (T) ExternalTableDefinition.fromPb(tablePb);
180223
default:
181224
// never reached

0 commit comments

Comments
 (0)