Skip to content

Commit

Permalink
Convert BaseHiveColumnHandle interface into a class
Browse files Browse the repository at this point in the history
  • Loading branch information
imjalpreet authored and yingsu00 committed Jan 18, 2024
1 parent f75610e commit f75f9db
Show file tree
Hide file tree
Showing 51 changed files with 172 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,66 @@
*/
package com.facebook.presto.hive;

import com.facebook.presto.common.Subfield;
import com.facebook.presto.spi.ColumnHandle;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public interface BaseHiveColumnHandle
extends ColumnHandle
import java.util.List;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

public class BaseHiveColumnHandle
implements ColumnHandle
{
String getName();
public enum ColumnType
{
PARTITION_KEY,
REGULAR,
SYNTHESIZED,
AGGREGATED,
}

private final String name;
private final Optional<String> comment;
private final ColumnType columnType;
private final List<Subfield> requiredSubfields;

@JsonCreator
public BaseHiveColumnHandle(
@JsonProperty("name") String name,
@JsonProperty("comment") Optional<String> comment,
@JsonProperty("columnType") ColumnType columnType,
@JsonProperty("requiredSubfields") List<Subfield> requiredSubfields)
{
this.name = requireNonNull(name, "name is null");
this.comment = requireNonNull(comment, "comment is null");
this.columnType = requireNonNull(columnType, "columnType is null");
this.requiredSubfields = requireNonNull(requiredSubfields, "requiredSubfields is null");
}

@JsonProperty
public String getName()
{
return name;
}

@JsonProperty
public Optional<String> getComment()
{
return comment;
}

@JsonProperty
public ColumnType getColumnType()
{
return columnType;
}

@JsonProperty
public List<Subfield> getRequiredSubfields()
{
return requiredSubfields;
}
}
5 changes: 5 additions & 0 deletions presto-hive-hadoop2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<artifactId>presto-hive</artifactId>
</dependency>

<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-hive-common</artifactId>
</dependency>

<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-hive-metastore</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import static com.facebook.airlift.testing.Assertions.assertEqualsIgnoreOrder;
import static com.facebook.presto.common.type.BigintType.BIGINT;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.HiveType.HIVE_LONG;

public class TestHiveFileSystemS3SelectCsvPushdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Optional;

import static com.facebook.airlift.testing.Assertions.assertEqualsIgnoreOrder;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.HiveFileSystemTestUtils.newSession;
import static com.facebook.presto.hive.HiveType.HIVE_LONG;
import static com.facebook.presto.hive.s3select.S3SelectTestHelper.expectedResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import static com.facebook.airlift.testing.Assertions.assertEqualsIgnoreOrder;
import static com.facebook.presto.common.type.BigintType.BIGINT;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.HiveFileSystemTestUtils.filterTable;
import static com.facebook.presto.hive.HiveFileSystemTestUtils.newSession;
import static com.facebook.presto.hive.HiveFileSystemTestUtils.readTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Optional;

import static com.facebook.airlift.testing.Assertions.assertEqualsIgnoreOrder;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.HiveFileSystemTestUtils.newSession;
import static com.facebook.presto.hive.HiveType.HIVE_LONG;
import static com.facebook.presto.hive.s3select.S3SelectTestHelper.expectedResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import static com.facebook.presto.common.type.VarbinaryType.VARBINARY;
import static com.facebook.presto.common.type.Varchars.isVarcharType;
import static com.facebook.presto.common.type.Varchars.truncateToLength;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.HiveErrorCode.HIVE_BAD_DATA;
import static com.facebook.presto.hive.HiveErrorCode.HIVE_CURSOR_ERROR;
import static com.facebook.presto.hive.HiveUtil.closeWithSuppression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import java.util.Optional;

import static com.facebook.presto.common.type.BigintType.BIGINT;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.AGGREGATED;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.PARTITION_KEY;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.SYNTHESIZED;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.AGGREGATED;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.PARTITION_KEY;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.SYNTHESIZED;
import static com.facebook.presto.hive.HiveType.HIVE_INT;
import static com.facebook.presto.hive.HiveType.HIVE_LONG;
import static com.facebook.presto.hive.HiveType.HIVE_STRING;
Expand All @@ -40,7 +40,7 @@
import static java.util.Objects.requireNonNull;

public class HiveColumnHandle
implements BaseHiveColumnHandle
extends BaseHiveColumnHandle
{
public static final int PATH_COLUMN_INDEX = -11;
public static final String PATH_COLUMN_NAME = "$path";
Expand All @@ -67,21 +67,9 @@ public class HiveColumnHandle
// Ids <= this can be used for distinguishing between different prefilled columns.
public static final int MAX_PARTITION_KEY_COLUMN_INDEX = -13;

public enum ColumnType
{
PARTITION_KEY,
REGULAR,
SYNTHESIZED,
AGGREGATED,
}

private final String name;
private final HiveType hiveType;
private final TypeSignature typeName;
private final int hiveColumnIndex;
private final ColumnType columnType;
private final Optional<String> comment;
private final List<Subfield> requiredSubfields;
private final Optional<Aggregation> partialAggregation;

@JsonCreator
Expand All @@ -95,14 +83,12 @@ public HiveColumnHandle(
@JsonProperty("requiredSubfields") List<Subfield> requiredSubfields,
@JsonProperty("partialAggregation") Optional<Aggregation> partialAggregation)
{
this.name = requireNonNull(name, "name is null");
super(name, comment, columnType, requiredSubfields);

checkArgument(hiveColumnIndex >= 0 || columnType == PARTITION_KEY || columnType == SYNTHESIZED || columnType == AGGREGATED, format("hiveColumnIndex:%d is negative, columnType:%s", hiveColumnIndex, columnType.toString()));
this.hiveColumnIndex = hiveColumnIndex;
this.hiveType = requireNonNull(hiveType, "hiveType is null");
this.typeName = requireNonNull(typeSignature, "type is null");
this.columnType = requireNonNull(columnType, "columnType is null");
this.comment = requireNonNull(comment, "comment is null");
this.requiredSubfields = requireNonNull(requiredSubfields, "requiredSubfields is null");
this.partialAggregation = requireNonNull(partialAggregation, "partialAggregation is null");
checkArgument(columnType != AGGREGATED || partialAggregation.isPresent(), "Aggregated column does not have aggregate function");
}
Expand All @@ -119,12 +105,6 @@ public HiveColumnHandle(
this(name, hiveType, typeSignature, hiveColumnIndex, columnType, comment, ImmutableList.of(), partialAggregation);
}

@JsonProperty
public String getName()
{
return name;
}

@JsonProperty
public HiveType getHiveType()
{
Expand All @@ -139,23 +119,17 @@ public int getHiveColumnIndex()

public boolean isPartitionKey()
{
return columnType == PARTITION_KEY;
return getColumnType() == PARTITION_KEY;
}

public boolean isHidden()
{
return columnType == SYNTHESIZED;
return getColumnType() == SYNTHESIZED;
}

public ColumnMetadata getColumnMetadata(TypeManager typeManager)
{
return new ColumnMetadata(name, typeManager.getType(typeName), null, isHidden());
}

@JsonProperty
public Optional<String> getComment()
{
return comment;
return new ColumnMetadata(getName(), typeManager.getType(typeName), null, isHidden());
}

@JsonProperty
Expand All @@ -170,18 +144,6 @@ public TypeSignature getTypeSignature()
return typeName;
}

@JsonProperty
public ColumnType getColumnType()
{
return columnType;
}

@JsonProperty
public List<Subfield> getRequiredSubfields()
{
return requiredSubfields;
}

@Override
public ColumnHandle withRequiredSubfields(List<Subfield> subfields)
{
Expand All @@ -190,13 +152,13 @@ public ColumnHandle withRequiredSubfields(List<Subfield> subfields)
return this;
}

return new HiveColumnHandle(name, hiveType, typeName, hiveColumnIndex, columnType, comment, subfields, partialAggregation);
return new HiveColumnHandle(getName(), hiveType, typeName, hiveColumnIndex, getColumnType(), getComment(), subfields, partialAggregation);
}

@Override
public int hashCode()
{
return Objects.hash(name, hiveColumnIndex, hiveType, columnType, comment);
return Objects.hash(getName(), hiveColumnIndex, hiveType, getColumnType(), getComment());
}

@Override
Expand All @@ -209,22 +171,22 @@ public boolean equals(Object obj)
return false;
}
HiveColumnHandle other = (HiveColumnHandle) obj;
return Objects.equals(this.name, other.name) &&
return Objects.equals(this.getName(), other.getName()) &&
Objects.equals(this.hiveColumnIndex, other.hiveColumnIndex) &&
Objects.equals(this.hiveType, other.hiveType) &&
Objects.equals(this.columnType, other.columnType) &&
Objects.equals(this.comment, other.comment) &&
Objects.equals(this.requiredSubfields, other.requiredSubfields);
Objects.equals(this.getColumnType(), other.getColumnType()) &&
Objects.equals(this.getComment(), other.getComment()) &&
Objects.equals(this.getRequiredSubfields(), other.getRequiredSubfields());
}

@Override
public String toString()
{
if (requiredSubfields.isEmpty()) {
return name + ":" + hiveType + ":" + hiveColumnIndex + ":" + columnType;
if (getRequiredSubfields().isEmpty()) {
return getName() + ":" + hiveType + ":" + hiveColumnIndex + ":" + getColumnType();
}

return name + ":" + hiveType + ":" + hiveColumnIndex + ":" + columnType + ":" + requiredSubfields;
return getName() + ":" + hiveType + ":" + hiveColumnIndex + ":" + getColumnType() + ":" + getRequiredSubfields();
}

public static HiveColumnHandle updateRowIdHandle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
import static com.facebook.presto.common.type.Varchars.isVarcharType;
import static com.facebook.presto.expressions.LogicalRowExpressions.TRUE_CONSTANT;
import static com.facebook.presto.expressions.LogicalRowExpressions.binaryExpression;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.PARTITION_KEY;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.SYNTHESIZED;
import static com.facebook.presto.hive.BucketFunctionType.HIVE_COMPATIBLE;
import static com.facebook.presto.hive.BucketFunctionType.PRESTO_NATIVE;
import static com.facebook.presto.hive.ColumnEncryptionInformation.ColumnWithStructSubfield;
Expand All @@ -173,9 +176,6 @@
import static com.facebook.presto.hive.HiveBucketing.getHiveBucketHandle;
import static com.facebook.presto.hive.HiveClientConfig.InsertExistingPartitionsBehavior;
import static com.facebook.presto.hive.HiveColumnHandle.BUCKET_COLUMN_NAME;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.PARTITION_KEY;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.SYNTHESIZED;
import static com.facebook.presto.hive.HiveColumnHandle.FILE_MODIFIED_TIME_COLUMN_NAME;
import static com.facebook.presto.hive.HiveColumnHandle.FILE_SIZE_COLUMN_NAME;
import static com.facebook.presto.hive.HiveColumnHandle.PATH_COLUMN_NAME;
Expand Down Expand Up @@ -2633,7 +2633,7 @@ public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session
new HiveTableLayoutHandle.Builder()
.setSchemaTableName(handle.getSchemaTableName())
.setTablePath(table.getStorage().getLocation())
.setPartitionColumns(ImmutableList.copyOf(hivePartitionResult.getPartitionColumns()))
.setPartitionColumns(hivePartitionResult.getPartitionColumns())
.setDataColumns(pruneColumnComments(hivePartitionResult.getDataColumns()))
.setTableParameters(hivePartitionResult.getTableParameters())
.setDomainPredicate(domainPredicate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
import java.util.Set;
import java.util.function.Function;

import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.AGGREGATED;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.PARTITION_KEY;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.BaseHiveColumnHandle.ColumnType.SYNTHESIZED;
import static com.facebook.presto.hive.HiveBucketing.getHiveBucketFilter;
import static com.facebook.presto.hive.HiveCoercer.createCoercer;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.AGGREGATED;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.PARTITION_KEY;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR;
import static com.facebook.presto.hive.HiveColumnHandle.ColumnType.SYNTHESIZED;
import static com.facebook.presto.hive.HiveColumnHandle.isPushedDownSubfield;
import static com.facebook.presto.hive.HiveErrorCode.HIVE_UNKNOWN_ERROR;
import static com.facebook.presto.hive.HivePageSourceProvider.ColumnMapping.toColumnHandles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ && queryAccessesTooManyBuckets(hiveBucketHandle.get(), bucketFilter, partitions,

if (effectivePredicate.isNone()) {
return new HivePartitionResult(
partitionColumns,
ImmutableList.copyOf(partitionColumns),
table.getDataColumns(),
table.getParameters(),
partitions,
Expand All @@ -292,7 +292,7 @@ && queryAccessesTooManyBuckets(hiveBucketHandle.get(), bucketFilter, partitions,

if (partitionColumns.isEmpty()) {
return new HivePartitionResult(
partitionColumns,
ImmutableList.copyOf(partitionColumns),
table.getDataColumns(),
table.getParameters(),
partitions,
Expand All @@ -307,7 +307,7 @@ && queryAccessesTooManyBuckets(hiveBucketHandle.get(), bucketFilter, partitions,
TupleDomain<ColumnHandle> remainingTupleDomain = TupleDomain.withColumnDomains(Maps.filterKeys(effectivePredicate.getDomains().get(), not(Predicates.in(partitionColumns))));
TupleDomain<ColumnHandle> enforcedTupleDomain = TupleDomain.withColumnDomains(Maps.filterKeys(effectivePredicate.getDomains().get(), Predicates.in(partitionColumns)));
return new HivePartitionResult(
partitionColumns,
ImmutableList.copyOf(partitionColumns),
table.getDataColumns(),
table.getParameters(),
partitions,
Expand Down Expand Up @@ -398,7 +398,7 @@ public HivePartitionResult getPartitions(SemiTransactionalHiveMetastore metastor

Optional<HiveBucketHandle> bucketHandle = shouldIgnoreTableBucketing(session) ? Optional.empty() : getHiveBucketHandle(table);
return new HivePartitionResult(
partitionColumns,
ImmutableList.copyOf(partitionColumns),
table.getDataColumns(),
table.getParameters(),
partitionList,
Expand Down
Loading

0 comments on commit f75f9db

Please sign in to comment.