io.trino.plugin.hive.metastore.Partition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trino-hive Show documentation
Show all versions of trino-hive Show documentation
This is a Databricks build of Trino's Hive plugin which includes support for HTTP based transport
for it's Hive metastore thrift interface.
The newest version!
/*
* 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 io.trino.plugin.hive.metastore;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.spi.connector.SchemaTableName;
import javax.annotation.concurrent.Immutable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import static com.google.common.base.MoreObjects.toStringHelper;
import static io.trino.plugin.hive.metastore.MetastoreUtil.adjustRowCount;
import static java.util.Objects.requireNonNull;
@Immutable
public class Partition
{
private final String databaseName;
private final String tableName;
private final List values;
private final Storage storage;
private final List columns;
private final Map parameters;
@JsonCreator
public Partition(
@JsonProperty("databaseName") String databaseName,
@JsonProperty("tableName") String tableName,
@JsonProperty("values") List values,
@JsonProperty("storage") Storage storage,
@JsonProperty("columns") List columns,
@JsonProperty("parameters") Map parameters)
{
this.databaseName = requireNonNull(databaseName, "databaseName is null");
this.tableName = requireNonNull(tableName, "tableName is null");
this.values = ImmutableList.copyOf(requireNonNull(values, "values is null"));
this.storage = requireNonNull(storage, "storage is null");
this.columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null"));
this.parameters = ImmutableMap.copyOf(requireNonNull(parameters, "parameters is null"));
}
@JsonIgnore
public Partition withAdjustedRowCount(String partitionName, long rowCountDelta)
{
return new Partition(databaseName, tableName, values, storage, columns, adjustRowCount(parameters, partitionName, rowCountDelta));
}
@JsonProperty
public String getDatabaseName()
{
return databaseName;
}
@JsonProperty
public String getTableName()
{
return tableName;
}
@JsonIgnore
public SchemaTableName getSchemaTableName()
{
return new SchemaTableName(databaseName, tableName);
}
@JsonProperty
public List getValues()
{
return values;
}
@JsonProperty
public Storage getStorage()
{
return storage;
}
@JsonProperty
public List getColumns()
{
return columns;
}
@JsonProperty
public Map getParameters()
{
return parameters;
}
@Override
public String toString()
{
return toStringHelper(this)
.add("databaseName", databaseName)
.add("tableName", tableName)
.add("values", values)
.toString();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Partition partition = (Partition) o;
return Objects.equals(databaseName, partition.databaseName) &&
Objects.equals(tableName, partition.tableName) &&
Objects.equals(values, partition.values) &&
Objects.equals(storage, partition.storage) &&
Objects.equals(columns, partition.columns) &&
Objects.equals(parameters, partition.parameters);
}
@Override
public int hashCode()
{
return Objects.hash(databaseName, tableName, values, storage, columns, parameters);
}
public static Builder builder()
{
return new Builder();
}
public static Builder builder(Partition partition)
{
return new Builder(partition);
}
public static class Builder
{
private final Storage.Builder storageBuilder;
private String databaseName;
private String tableName;
private List values;
private List columns;
private Map parameters = ImmutableMap.of();
private Builder()
{
this.storageBuilder = Storage.builder();
}
private Builder(Partition partition)
{
this.storageBuilder = Storage.builder(partition.getStorage());
this.databaseName = partition.getDatabaseName();
this.tableName = partition.getTableName();
this.values = partition.getValues();
this.columns = partition.getColumns();
this.parameters = partition.getParameters();
}
public Builder setDatabaseName(String databaseName)
{
this.databaseName = databaseName;
return this;
}
public Builder setTableName(String tableName)
{
this.tableName = tableName;
return this;
}
public Builder setValues(List values)
{
this.values = values;
return this;
}
public Storage.Builder getStorageBuilder()
{
return storageBuilder;
}
public Builder withStorage(Consumer consumer)
{
consumer.accept(storageBuilder);
return this;
}
public Builder setColumns(List columns)
{
this.columns = columns;
return this;
}
public Builder setParameters(Map parameters)
{
this.parameters = parameters;
return this;
}
public Partition build()
{
return new Partition(databaseName, tableName, values, storageBuilder.build(), columns, parameters);
}
}
}