com.facebook.presto.hive.metastore.file.PartitionMetadata Maven / Gradle / Ivy
/*
* 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.facebook.presto.hive.metastore.file;
import com.facebook.presto.hive.HiveBucketProperty;
import com.facebook.presto.hive.HiveStorageFormat;
import com.facebook.presto.hive.metastore.Column;
import com.facebook.presto.hive.metastore.HiveColumnStatistics;
import com.facebook.presto.hive.metastore.Partition;
import com.facebook.presto.hive.metastore.PartitionStatistics;
import com.facebook.presto.hive.metastore.PartitionWithStatistics;
import com.facebook.presto.hive.metastore.Storage;
import com.facebook.presto.hive.metastore.StorageFormat;
import com.facebook.presto.hive.metastore.Table;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static com.facebook.presto.hive.HiveStorageFormat.getHiveStorageFormat;
import static com.facebook.presto.hive.metastore.MetastoreUtil.updateStatisticsParameters;
import static com.facebook.presto.hive.metastore.PrestoTableType.EXTERNAL_TABLE;
import static com.facebook.presto.hive.metastore.StorageFormat.VIEW_STORAGE_FORMAT;
import static com.google.common.base.MoreObjects.firstNonNull;
import static java.util.Objects.requireNonNull;
public class PartitionMetadata
{
private final List columns;
private final Map parameters;
private final StorageFormat storageFormat;
private final Optional bucketProperty;
private final Map storageParameters;
private final Map serdeParameters;
private final Optional externalLocation;
private final Map columnStatistics;
private final boolean eligibleToIgnore;
private final boolean sealedPartition;
private final Optional rowIdPartitionComponent;
@JsonCreator
public PartitionMetadata(
@JsonProperty("columns") List columns,
@JsonProperty("parameters") Map parameters,
@JsonDeserialize(using = StorageFormatCompatDeserializer.class)
@JsonProperty("storageFormat") StorageFormat storageFormat,
@JsonProperty("bucketProperty") Optional bucketProperty,
@JsonProperty("storageParameters") Map storageParameters,
@JsonProperty("serdeParameters") Map serdeParameters,
@JsonProperty("externalLocation") Optional externalLocation,
@JsonProperty("columnStatistics") Map columnStatistics,
@JsonProperty("eligibleToIgnore") boolean eligibleToIgnore,
@JsonProperty("sealedPartition") boolean sealedPartition,
@JsonProperty("rowIdPartitionComponent") Optional rowIdPartitionComponent)
{
this.columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null"));
this.parameters = ImmutableMap.copyOf(requireNonNull(parameters, "parameters is null"));
this.storageFormat = storageFormat == null ? VIEW_STORAGE_FORMAT : storageFormat;
this.bucketProperty = requireNonNull(bucketProperty, "bucketProperty is null");
this.storageParameters = ImmutableMap.copyOf(firstNonNull(storageParameters, ImmutableMap.of()));
this.serdeParameters = requireNonNull(serdeParameters, "serdeParameters is null");
this.externalLocation = requireNonNull(externalLocation, "externalLocation is null");
this.columnStatistics = ImmutableMap.copyOf(requireNonNull(columnStatistics, "columnStatistics is null"));
this.eligibleToIgnore = eligibleToIgnore;
this.sealedPartition = sealedPartition;
this.rowIdPartitionComponent = requireNonNull(rowIdPartitionComponent);
}
@Deprecated
public PartitionMetadata(
List columns,
Map parameters,
Optional storageFormat,
Optional bucketProperty,
Map storageParameters,
Map serdeParameters,
Optional externalLocation,
Map columnStatistics,
boolean eligibleToIgnore,
boolean sealedPartition,
Optional rowIdPartitionComponent)
{
this(
columns,
parameters,
storageFormat.map(StorageFormat::fromHiveStorageFormat).orElse(VIEW_STORAGE_FORMAT),
bucketProperty,
storageParameters,
serdeParameters,
externalLocation,
columnStatistics,
eligibleToIgnore,
sealedPartition,
rowIdPartitionComponent);
}
public PartitionMetadata(Table table, PartitionWithStatistics partitionWithStatistics)
{
Partition partition = partitionWithStatistics.getPartition();
PartitionStatistics statistics = partitionWithStatistics.getStatistics();
this.columns = partition.getColumns();
this.parameters = updateStatisticsParameters(partition.getParameters(), statistics.getBasicStatistics());
storageFormat = partition.getStorage().getStorageFormat();
if (table.getTableType().equals(EXTERNAL_TABLE)) {
externalLocation = Optional.of(partition.getStorage().getLocation());
}
else {
externalLocation = Optional.empty();
}
bucketProperty = partition.getStorage().getBucketProperty();
storageParameters = partition.getStorage().getParameters();
serdeParameters = partition.getStorage().getSerdeParameters();
columnStatistics = ImmutableMap.copyOf(statistics.getColumnStatistics());
eligibleToIgnore = partition.isEligibleToIgnore();
sealedPartition = partition.isSealedPartition();
this.rowIdPartitionComponent = partition.getRowIdPartitionComponent();
}
@JsonProperty
public List getColumns()
{
return columns;
}
@JsonProperty
public Map getParameters()
{
return parameters;
}
@Deprecated
@JsonIgnore
public Optional getStorageFormat()
{
return getHiveStorageFormat(storageFormat);
}
@JsonProperty("storageFormat")
public StorageFormat getPartitionStorageFormat()
{
return storageFormat;
}
@JsonProperty
public Optional getBucketProperty()
{
return bucketProperty;
}
@JsonProperty
public Map getStorageParameters()
{
return storageParameters;
}
@JsonProperty
public Map getSerdeParameters()
{
return serdeParameters;
}
@JsonProperty
public Optional getExternalLocation()
{
return externalLocation;
}
@JsonProperty
public Map getColumnStatistics()
{
return columnStatistics;
}
@JsonProperty
public boolean isEligibleToIgnore()
{
return eligibleToIgnore;
}
@JsonProperty
public boolean isSealedPartition()
{
return sealedPartition;
}
public PartitionMetadata withParameters(Map parameters)
{
return new PartitionMetadata(columns, parameters, storageFormat, bucketProperty, storageParameters, serdeParameters, externalLocation, columnStatistics, eligibleToIgnore, sealedPartition, rowIdPartitionComponent);
}
public PartitionMetadata withColumnStatistics(Map columnStatistics)
{
return new PartitionMetadata(columns, parameters, storageFormat, bucketProperty, storageParameters, serdeParameters, externalLocation, columnStatistics, eligibleToIgnore, sealedPartition, rowIdPartitionComponent);
}
public Partition toPartition(String databaseName, String tableName, List values, String location)
{
return new Partition(
databaseName,
tableName,
values,
Storage.builder()
.setLocation(externalLocation.orElse(location))
.setStorageFormat(storageFormat)
.setBucketProperty(bucketProperty)
.setSerdeParameters(serdeParameters)
.setParameters(parameters)
.build(),
columns,
parameters,
Optional.empty(),
eligibleToIgnore,
sealedPartition,
0,
0,
rowIdPartitionComponent);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy