Visitar URL original
Change in TableId behaviour for non default BigQueryClient project 1.44 -> 1.45 · Issue #3808 · googleapis/google-cloud-java · GitHub
Skip to content

Change in TableId behaviour for non default BigQueryClient project 1.44 -> 1.45 #3808

Closed

Description

When using the getTable method of the BigQuery client the project of the TableId is overwritten. TableId would previously ignore this if a project had been set. Table Id has been changed such that the project is always overwritten. There is now no way to get a table for a project other than the one the client was created for.

TableId tableId = TableId.of(project, schema, tableName);
Table table = client.getTable(tableId);
// table returns null if project != client.getOptions().getProjectId()

this is due to the change in TableId

In BigQueryImpl:

public Table getTable(TableId tableId, TableOption... options) {
    final TableId completeTableId = tableId.setProjectId(getOptions().getProjectId());
    ...

TableId old code:

TableId setProjectId(String projectId) {
  return getProject() != null ? this : TableId.of(projectId, getDataset(), getTable());
}

TableId new code:

TableId setProjectId(String projectId) {
  Preconditions
    .checkArgument(!Strings.isNullOrEmpty(projectId), "Provided projectId is null or empty");
  return TableId.of(projectId, getDataset(), getTable());
}

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: bigqueryIssues related to the BigQuery API.
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on Oct 14, 2018
  2. MMMarcy commented on Oct 17, 2018

    @MMMarcy

    @NickApostolidesMatillion I'm the author of that change. It was due to #3283 and this behavior is definitely unintended. However, reverting the change will re-open the mentioned issue.

    Perhaps something like:

    public Table getTable(TableId tableId, TableOption... options) {
    
        final TableId completeTableId = tableId.setProjectId(
            tableId.getProjectId() == null
            ? getOptions().getProjectId()
            : tableId.getProjectId()
        );
    ...
    }

    Would solve your issue and still keep the fix for #3283 (granted that now you supply a TableId with the desired projectId already set).

  3. NickApostolidesMatillion commented on Oct 17, 2018

    @NickApostolidesMatillion
    Author

    @MMMarcy that would work for us. It is more suitable to have this logic in BigQueryImpl.

    Thanks

  4. MMMarcy commented on Oct 17, 2018

    @MMMarcy

    Perfect. Waiting for the owners thoughts now. If positive, I can open a PR

  5. MMMarcy commented on Oct 17, 2018

    @MMMarcy

    Actually, thinking more about this using the proposed solution I mentioned hides too much of the behavior to the caller. Maybe overloading the getTable method with

    public Table getTable(TableId tableId, ProjectId projectId, TableOption... options) {
    ...
    }

    seems a better alternative.

  6. NickApostolidesMatillion commented on Oct 17, 2018

    @NickApostolidesMatillion
    Author

    TableId already has a factory method including the project:

    public static TableId of(String project, String dataset, String table)

    I would suggest that if the project is set in TableId, the developer knows the project he/she wants.

  7. added
    🚨 criticalP0 critical issue. Requires immediate fix
    and removed
    🚨 criticalP0 critical issue. Requires immediate fix
    triage meI really want to be triaged.
    on Oct 17, 2018
  8. 12 remaining items

  9. polleyg commented on Nov 22, 2018

    @polleyg

    Hey Folks - any chance of getting someone to look at this? It's becoming a bit of a problem now. Maybe reverting the original change should be considered.

  10. mikekap commented on Dec 3, 2018

    @mikekap

    I think there's way more callsites of setProjectId that aren't fixed - including insertAll that are still broken. IntelliJ shows 15 usages of which 3 are fixed now.

  11. mikekap commented on Dec 6, 2018

    @mikekap

    @MMMarcy given the extent of the breakage - what was the motivation behind the original change? The setProjectId method is package-private so it shouldn't have been called externally.

  12. reopened this on Dec 6, 2018
  13. sduskis commented on Dec 6, 2018

    @sduskis
    Contributor

    @pmakani, it looks like there are more places that need to change.

  14. chingor13 commented on Dec 12, 2018

    @chingor13
    Contributor

    @pmakani Did #4196 actually fix all the cases?

  15. polleyg commented on Dec 13, 2018

    @polleyg

    @chingor13 I was about to ask the same. He's all the references I see to setProject() in my IDEA..
    screen shot 2018-12-13 at 11 00 13 am

  16. lepistone commented on Mar 21, 2019

    @lepistone

    Hi, we believe this is still broken as of today (1.65.0). As in the description of this ticket, still There is now no way to get a table for a project other than the one the client was created for.

    Specifically, in https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java#L635-L639 , the project in my tableId will always be overridden with the project of the service, if the service has a project.

    Maybe the intention of that code was to override the project only if it is not set in tableId? Then the code would look like

              tableId.setProjectId(
                  Strings.isNullOrEmpty(tableId.getProjectId())
                      ? serviceOptions.getProjectId());
                      : tableId.getProject()

    Or maybe, the confusion arose between TableId and TableInfo. The code above calls TableId::setProject, which will always perform the change. See: https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableId.java#L100

    Thanks!

  17. added a commit that references this issue on Dec 6, 2019
    97a3e14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨 criticalP0 critical issue. Requires immediate fixapi: bigqueryIssues related to the BigQuery API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions