Skip to content

Convert all BigQuery deserialized enum types to StringEnumValue#2128

Merged
tcoffee-google merged 4 commits intogoogleapis:masterfrom
tcoffee-google:string_enum_bigquery
Jun 9, 2017
Merged

Convert all BigQuery deserialized enum types to StringEnumValue#2128
tcoffee-google merged 4 commits intogoogleapis:masterfrom
tcoffee-google:string_enum_bigquery

Conversation

@tcoffee-google
Copy link
Copy Markdown
Contributor

Introduces generalization of pattern for Storage/Datastore/Logging to simulate enum types with
single data members. This appears to cover all cases in remaining Cloud APIs.

Introduces generalization of pattern for Storage/Datastore/Logging to simulate enum types with
single data members. This appears to cover all cases in remaining Cloud APIs.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 8, 2017
@tcoffee-google
Copy link
Copy Markdown
Contributor Author

Posting BigQuery for design review before converting remaining APIs.

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 7aeab93 on tcoffee-google:string_enum_bigquery into ** on GoogleCloudPlatform:master**.

private StandardSQLTypeName equivalent;

LegacySQLTypeName(StandardSQLTypeName equivalent) {
LegacySQLTypeName setStandardType(StandardSQLTypeName equivalent) {

This comment was marked as spam.

This comment was marked as spam.

@tcoffee-google
Copy link
Copy Markdown
Contributor Author

@garrettjonesgoogle would you agree with the codacy-bot recommendation here? If so, I can retroactively change the previously published StringEnumValue subclasses as well.

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 389bbdd on tcoffee-google:string_enum_bigquery into ** on GoogleCloudPlatform:master**.

@shinfan
Copy link
Copy Markdown
Contributor

shinfan commented Jun 9, 2017

It would be nice to fix the codacy-bot suggestions... Those posts make the page very long and hard to scroll...

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor

@tcoffee-google sure, let's take care of the codacy recommendations.

@tcoffee-google
Copy link
Copy Markdown
Contributor Author

Fixed for BigQuery --- I'll change this others once this one is approved.

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor

LGTM

@tcoffee-google
Copy link
Copy Markdown
Contributor Author

tcoffee-google commented Jun 9, 2017

For reference in case of future maintenance, the enums to be converted were found from instances of the (Emacs-style) regexp

\( *\)\(\w+ \)*fromPb(.*) {
\(\1  .*
\)*?\1  .*?valueOf.*
\(\1  .*
\)*?\1}

and conversions were done by fixed-point application of the following regexp replacements (the first two are sufficient for cases without subfields):

  1. convert enum to class
\( *\)\(\(\w+ \)*\)?enum \(\w+\) {
\(\(\(\1  .*\)?
\)*\)\1}

=>

\1\2static final class \4 extends StringEnumValue {
\1  private static final long serialVersionUID = \,(random)L;

\1  private static final ApiFunction<String, \4> CONSTRUCTOR =
\1      new ApiFunction<String, \4>() {
\1        @Override
\1        public \4 apply(String constant) {
\1          return new \4(constant);
\1        }
\1      };

\1  private static final StringEnumType<\4> type = new StringEnumType(
\1      \4.class,
\1      CONSTRUCTOR);

\5
\1  private \4(String constant) {
\1    super(constant);
\1  }

\1  /**
\1   * Get the \4 for the given String constant, and throw an exception if the constant is
\1   * not recognized.
\1   */
\1  \2static \4 valueOfStrict(String constant) {
\1    return type.valueOfStrict(constant);
\1  }

\1  /**
\1   * Get the \4 for the given String constant, and allow unrecognized values.
\1   */
\1  \2static \4 valueOf(String constant) {
\1    return type.valueOf(constant);
\1  }

\1  /**
\1   * Return the known values for \4.
\1   */
\1  \2static \4[] values() {
\1    return type.values();
\1  }
\1}

(removing the initial "static" for top-level enums)

  1. convert values to fields
\( *\)\(\(\w+ \)*\)class \(\w+\)\( extends StringEnumValue {
\(\(\1  .*\)?
\)*?\)\1  \([A-Z0-9_]+\)\(?:[,;]?\)\(
\(\(\1  .*\)?
\)*\1}\)

=>

\1\2class \4\5\1  \2\4 \8 = type.createAndRegister("\8");\9
  1. convert subfielded values to fields
\( *\)\(\(?:\w+ \)*\)class \(\w+\)\( extends StringEnumValue {
\(?:\(?:\1  .*\)?
\)*?\)\1  \([A-Z0-9_]+\)(\(.+\))\(?:[,;]?\)\(
\(?:\(?:\1  .*\)?
\)*\)\1  \3\((\(\w+\) \w+) {
\(?:\(?:\1  .*\)?
\)*\1  .+ \9 get\(\w+\)() {
\(?:\(?:\1  .*\)?
\)*\1}\)

=>

\1\2class \3\4\1  \2\3 \5 = type.createAndRegister("\5").set\,(match-string 10)(\6);\7\1  \3\8
  1. convert subfield constructor to setter
\( *\)\(\(?:\w+ \)*\)class \(\w+\)\( extends StringEnumValue {
\(?:\(?:\1  .*\)?
\)*?\)\1  \3\((\(\w+\) \w+) {
\(?:\(?:\1  .*\)?
\)*?\)\(\1  }
\(?:\(?:\1  .*\)?
\)*\1  .+ \6 get\(\w+\)() {
\(?:\(?:\1  .*\)?
\)*\1}\)

=>

\1\2class \3\4\1  private \3 set\8\5\1    return this;
\7

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling f45aebd on tcoffee-google:string_enum_bigquery into ** on GoogleCloudPlatform:master**.

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling f45aebd on tcoffee-google:string_enum_bigquery into ** on GoogleCloudPlatform:master**.

@tcoffee-google tcoffee-google merged commit ae640b7 into googleapis:master Jun 9, 2017
@tcoffee-google tcoffee-google deleted the string_enum_bigquery branch June 9, 2017 22:12
@tcoffee-google
Copy link
Copy Markdown
Contributor Author

Addresses #1944.

chingor13 pushed a commit that referenced this pull request Feb 20, 2026
🤖 I have created a release *beep* *boop*
---


## [2.37.2](https://togithub.com/googleapis/java-bigquerystorage/compare/v2.37.1...v2.37.2) (2023-05-30)


### Bug Fixes

* Pass the parameter value of enableConnectionPool instead of true always ([#2096](https://togithub.com/googleapis/java-bigquerystorage/issues/2096)) ([253678d](https://togithub.com/googleapis/java-bigquerystorage/commit/253678df630c717fbcf7018b3245aa56b5f22660))


### Dependencies

* Update dependency com.google.cloud:google-cloud-bigquery to v2.26.0 ([#2114](https://togithub.com/googleapis/java-bigquerystorage/issues/2114)) ([8b44534](https://togithub.com/googleapis/java-bigquerystorage/commit/8b4453476b17dcbb10faaa52c6a2b06506d89d62))
* Update dependency com.google.cloud:google-cloud-bigquery to v2.26.1 ([#2128](https://togithub.com/googleapis/java-bigquerystorage/issues/2128)) ([62afd46](https://togithub.com/googleapis/java-bigquerystorage/commit/62afd46bb4cad09886c49bac88a2052c8754f8fe))
* Update dependency com.google.cloud:google-cloud-shared-dependencies to v3.10.1 ([#2121](https://togithub.com/googleapis/java-bigquerystorage/issues/2121)) ([3fabc5d](https://togithub.com/googleapis/java-bigquerystorage/commit/3fabc5d467becd3d9b816f9545e8a1e6dd09f682))
* Update dependency com.google.http-client:google-http-client to v1.43.2 ([#2109](https://togithub.com/googleapis/java-bigquerystorage/issues/2109)) ([0d57daf](https://togithub.com/googleapis/java-bigquerystorage/commit/0d57daff0d113089ba1957753febeed92024e4c2))
* Update dependency com.google.truth:truth to v1.1.4 ([#2126](https://togithub.com/googleapis/java-bigquerystorage/issues/2126)) ([a0be7ad](https://togithub.com/googleapis/java-bigquerystorage/commit/a0be7ad59b1604972b190befe2e4befd2e2c6431))

---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 23, 2026
Add an explicit check to the test whether there are credentials available.
meltsufin pushed a commit that referenced this pull request Apr 29, 2026
meltsufin pushed a commit that referenced this pull request May 1, 2026
meltsufin pushed a commit that referenced this pull request May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants