io.trino.plugin.hive.metastore.HivePartitionName 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.JsonProperty;
import com.google.common.collect.ImmutableList;
import javax.annotation.concurrent.Immutable;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static io.trino.plugin.hive.util.HiveUtil.toPartitionValues;
import static java.util.Objects.requireNonNull;
@Immutable
public class HivePartitionName
{
private final HiveTableName hiveTableName;
private final List partitionValues;
private final Optional partitionName; // does not participate in hashCode/equals
@JsonCreator
public HivePartitionName(
@JsonProperty("hiveTableName") HiveTableName hiveTableName,
@JsonProperty("partitionValues") List partitionValues,
@JsonProperty("partitionName") Optional partitionName)
{
this.hiveTableName = requireNonNull(hiveTableName, "hiveTableName is null");
this.partitionValues = ImmutableList.copyOf(requireNonNull(partitionValues, "partitionValues is null"));
this.partitionName = requireNonNull(partitionName, "partitionName is null");
}
public static HivePartitionName hivePartitionName(HiveTableName hiveTableName, String partitionName)
{
return new HivePartitionName(hiveTableName, toPartitionValues(partitionName), Optional.of(partitionName));
}
public static HivePartitionName hivePartitionName(HiveTableName hiveTableName, List partitionValues)
{
return new HivePartitionName(hiveTableName, partitionValues, Optional.empty());
}
@JsonProperty
public HiveTableName getHiveTableName()
{
return hiveTableName;
}
@JsonProperty
public List getPartitionValues()
{
return partitionValues;
}
@JsonProperty
public Optional getPartitionName()
{
return partitionName;
}
@Override
public String toString()
{
return toStringHelper(this)
.add("hiveTableName", hiveTableName)
.add("partitionValues", partitionValues)
.add("partitionName", partitionName)
.toString();
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
HivePartitionName other = (HivePartitionName) o;
return Objects.equals(hiveTableName, other.hiveTableName) &&
Objects.equals(partitionValues, other.partitionValues);
}
@Override
public int hashCode()
{
return Objects.hash(hiveTableName, partitionValues);
}
}