
com.google.cloud.bigquery.TableId Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gcloud-java-bigquery Show documentation
Show all versions of gcloud-java-bigquery Show documentation
Java idiomatic client for Google Cloud BigQuery.
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigquery;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.api.services.bigquery.model.TableReference;
import com.google.common.base.Function;
import java.io.Serializable;
import java.util.Objects;
/**
* Google BigQuery Table identity.
*/
public final class TableId implements Serializable {
static final Function FROM_PB_FUNCTION =
new Function() {
@Override
public TableId apply(TableReference pb) {
return TableId.fromPb(pb);
}
};
static final Function TO_PB_FUNCTION =
new Function() {
@Override
public TableReference apply(TableId tableId) {
return tableId.toPb();
}
};
private static final long serialVersionUID = -6186254820908152300L;
private final String project;
private final String dataset;
private final String table;
/**
* Returns project's user-defined id.
*/
public String project() {
return project;
}
/**
* Returns dataset's user-defined id.
*/
public String dataset() {
return dataset;
}
/**
* Returns table's user-defined id.
*/
public String table() {
return table;
}
private TableId(String project, String dataset, String table) {
this.project = project;
this.dataset = dataset;
this.table = table;
}
/**
* Creates a table identity given project's, dataset's and table's user-defined ids.
*/
public static TableId of(String project, String dataset, String table) {
return new TableId(checkNotNull(project), checkNotNull(dataset), checkNotNull(table));
}
/**
* Creates a table identity given dataset's and table's user-defined ids.
*/
public static TableId of(String dataset, String table) {
return new TableId(null, checkNotNull(dataset), checkNotNull(table));
}
@Override
public boolean equals(Object obj) {
return obj == this
|| obj instanceof TableId
&& Objects.equals(toPb(), ((TableId) obj).toPb());
}
@Override
public int hashCode() {
return Objects.hash(project, dataset, table);
}
@Override
public String toString() {
return toPb().toString();
}
TableId setProjectId(String projectId) {
return project() != null ? this : TableId.of(projectId, dataset(), table());
}
TableReference toPb() {
return new TableReference().setProjectId(project).setDatasetId(dataset).setTableId(table);
}
static TableId fromPb(TableReference tableRef) {
return new TableId(
tableRef.getProjectId(),
tableRef.getDatasetId(),
tableRef.getTableId());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy