Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TableInfo and related model classes #423

Merged
merged 10 commits into from
Dec 4, 2015

Conversation

mziccard
Copy link
Contributor

This is a very big PR (but most of it is javadocs and tests) that adds TableInfo model class and all related classes:

  • TableSchema
  • FieldSchema
  • CsvOptions
  • ExternalDataConfiguration
  • UserDefinedFunction

Unit tests are also added.

Remarks
I added the TableSchema class to wrap schema information as it also appears elsewhere (Query results). Schema is just a list of FieldSchema objects so if you prefer we can drop the class and just use List<FieldSchema>. I have no strong preferences.

@mziccard mziccard added the api: bigquery Issues related to the BigQuery API. label Nov 30, 2015
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 30, 2015
}

/**
* Creates an {@code ExternalDataConfiguration} object.

This comment was marked as spam.

- TableSchema renamed to Schema
- FieldSchema renamed to Field
- Add class Type to Field to represent the field's type (and wrap record subfields)
- Add factory method and setter from varargs for Schema
- Better javadoc for CsvOptions and Field
- Update tests according to changes
@mziccard
Copy link
Contributor Author

mziccard commented Dec 1, 2015

Fixed the comments, main changes are:

  • TableSchema renamed to Schema and FieldSchema renamed to Field
  • Changed Type enum to class in Field with factory methods for all types
  • Add setter and builder method that take fields as a vararg for Schema
  • Fixed all javadocs comments and updated tests according to changes

}

/**
* Creates an {@code Field} object.

This comment was marked as spam.

@aozarov
Copy link
Contributor

aozarov commented Dec 2, 2015

Looks good. Few more comments and suggestions.

@aozarov
Copy link
Contributor

aozarov commented Dec 3, 2015

See my comment regarding CsvOptions (I like the change you made and suggested to take it slightly further), the possible bug in TableInfo when nulls are passed in the builder and later retrieved by the built instance and also my suggestion to use inheritance for TableInfo as well (if not inheritence maybe we can consider something similar to what you did with FormatOptions).

Also, I feel like an open comment regarding patch and ExternalDataConfiguration got lost somehow.

@mziccard
Copy link
Contributor Author

mziccard commented Dec 3, 2015

I see where you are going with the hierarchies. The fact is that i really don't like that the user has to cast values to get to real data. It might be me but I really consider casting an unnecessary pain in the neck. The main point is that if we have:

@SuppressWarnings("unchecked")
public <F extends FormatOptions> F formatOptions() {
  return (F) formatOptions;
}

To use this method a user must not only read its javadoc but he needs also to be aware of the FormatOptions hierarchy. If he does't know the expected type, in fact, he has to do type-checking to figure out how to use the return type. Avoiding type-checking and casting is the reason why I provided both format and csvOptions getters.

The same reasoning (even worse maybe) applies to TableInfo type. We might want to have something like:

public abstract class TableType {

  static class Table extends TableType {
    // ...
  }
  static class View {
    // ...
  }
  static class External {
    // ...
  }
  public static Table of(Schema schema);
  public static View of (String query, List<UserDefinedFunction> functions);
  public static External of(ExternalDataConfiguration configuration);
}

public class TableInfo {
  // ...
  public static Builder builder(TableType type);
  public static ViewInfo of(TableType type);
}

This is ok but if you ask me I would not remove all schema(), query(), userDefinedFunctions() and externalConfiguration() getters from TableInfo if favor of public <T extends ViewType>type() for the same reasoning I did above for CsvOptions. Even worse, here the information wrapped in types is not disjoint, the table's schema in fact is returned by the BigQuery service for all 3 types of tables.

To sum things up: I am in favor of using hierarchies to make it easier for the user to build an object right, I am not in favor of having getters that require type-checking. I am open for discussion :)

Also, I feel like an open comment regarding patch and ExternalDataConfiguration got lost somehow.

It got lost in fact, my answer is here.

@aozarov
Copy link
Contributor

aozarov commented Dec 3, 2015

I think javadoc, which shoes class hierarchies, and making the set of format type constants more public (maybe not enum, but there are other ways can do it) could help with knowing which one should be used.

Also, I would expect the user to know it as (similar to the schema) it probably set it.
I only mentioned that method as a "convenient" getter that avoid explicit casting (which
we also do in other places).

Avoiding type-checking and casting is the reason why I provided both format and csvOptions getters.

If someone was calling csvOptions it is because it already knew it was a csvOptions. Yes,
one could call all xxxOptions and check for not null but this does not look better to me than
instanceof.

If we assume that more and more formats are going to be supported (which, I think, is the reason we don't use enum for type), than in that case it would mean adding more and more xxxOptions get methods on ExternalDataConfiguration. Is that desired?

As for TableInfo I think here we should not expect proliferation of types (if any), so
having the, currently 3, specific getters is not a problem (but I don't see that as an improvement) however flattening all options (such as userDefinedFunctions) in TableInfo does not seem
right to me (and force the user to know what belongs to what). In my mind it is prefered to have common stuff in common class and specific stuff in its specific place. BTW, did you consider to make TableInfo abstract and have 3 concrete implementation for it?

- Move schema from TableInfo to TableType
- Add TableType.View class with attributes: view, userDefinedFunctions
- Add TableType.ExternalTable class with attributes: ExternalDataConfiguration
- Fix return null in TableInfo.description/friendlyName/expirationTime
@mziccard
Copy link
Contributor Author

mziccard commented Dec 3, 2015

I obey :) Kidding, I don't completely agree but we could discuss this for days and there's no point in stalling this any longer.
I hope I caught all comments, let me recap:

@aozarov
Copy link
Contributor

aozarov commented Dec 4, 2015

I like this one better! (but still have few suggestions).

Next time when you do not completely agree I suggest you create an issue (marked as question) and we can continue to discuss it there (and solicit more opinions) while keeping the code as is.

@mziccard
Copy link
Contributor Author

mziccard commented Dec 4, 2015

Some more changes:

  • ae2a484: Removes TableType and creates a hierarchy of TableInfo. If you are wondering why BaseTableInfo is not abstract it's because listTables return partial information on tables that does not allow to say whether they are normal tables, views or external tables. So I thought to use BaseTableInfo for them
  • 338ede1: Fixes the mode issue and another minor comment

@aozarov
Copy link
Contributor

aozarov commented Dec 4, 2015

I really like it!! Few nits.

aozarov added a commit that referenced this pull request Dec 4, 2015
Add TableInfo and related model classes
@aozarov aozarov merged commit 12185e8 into googleapis:bigquery Dec 4, 2015
github-actions bot pushed a commit that referenced this pull request Jun 21, 2022
…onfig to v1.5.0 (#423)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-shared-config](https://togithub.com/googleapis/java-shared-config) | `1.4.0` -> `1.5.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-config/1.5.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-config/1.5.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-config/1.5.0/compatibility-slim/1.4.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-shared-config/1.5.0/confidence-slim/1.4.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/java-shared-config</summary>

### [`v1.5.0`](https://togithub.com/googleapis/java-shared-config/blob/HEAD/CHANGELOG.md#&#8203;150-httpsgithubcomgoogleapisjava-shared-configcomparev140v150-2022-06-10)

[Compare Source](https://togithub.com/googleapis/java-shared-config/compare/v1.4.0...v1.5.0)

##### Features

-   add build scripts for native image testing in Java 17 ([#&#8203;1440](https://togithub.com/googleapis/java-shared-config/issues/1440)) ([#&#8203;475](https://togithub.com/googleapis/java-shared-config/issues/475)) ([e4dfc1b](https://togithub.com/googleapis/java-shared-config/commit/e4dfc1ba29295158c78c8fcf94467d2a6a33538a))
-   to produce Java 8 compatible bytecode when using JDK 9+ ([2468276](https://togithub.com/googleapis/java-shared-config/commit/2468276145cdfe1ca911b52f765e026e77661a09))

##### Dependencies

-   update surefire.version to v3.0.0-m7 ([bbfe663](https://togithub.com/googleapis/java-shared-config/commit/bbfe66393af3e49612c9c1e4334ba39c133ea1d0))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-security-private-ca).
github-actions bot pushed a commit to suztomo/google-cloud-java that referenced this pull request Jun 29, 2022
* feat: add v3 client

* 🦉 Updates from OwlBot

* fix declared dependencies

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
github-actions bot pushed a commit to suztomo/google-cloud-java that referenced this pull request Jun 29, 2022
github-actions bot pushed a commit that referenced this pull request Jul 1, 2022
Source-Link: googleapis/synthtool@e122cb0
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:387835a1375a0049ec44e02542c844302854c732d8291bdf8e472c0ff70a8f67
github-actions bot pushed a commit to suztomo/google-cloud-java that referenced this pull request Jul 1, 2022
🤖 I have created a release *beep* *boop*
---


### Updating meta-information for bleeding-edge SNAPSHOT release.

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
github-actions bot pushed a commit to yoshi-code-bot/google-cloud-java that referenced this pull request Nov 8, 2022
…s#1687) (googleapis#423)

* chore(java): add a note in README for migrated split repos

Disable renovate bot and flaky bot for split repositories
that have moved to the Java monorepo.
The Java monorepo will pass the "monorepo=True" parameter
to java.common_templates method in its owlbot.py files so that
the migration note will not appear in the README in the monorepo.

Co-authored-by: Jeff Ching <[email protected]>
Source-Link: https://togithub.com/googleapis/synthtool/commit/d4b291604f148cde065838c498bc8aa79b8dc10e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:edae91ccdd2dded2f572ec341a768ad180305a3e8fbfd93064b28e237d35920a
suztomo pushed a commit that referenced this pull request Feb 1, 2023
The commit are broken down to make it clear which parts are autogenerated and which parts had to be manually edited.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants