Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the explain (TYPE IO) Exception when table is hive partition tabl… #12349

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import java.util.Set;

import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static io.airlift.json.JsonCodec.jsonCodec;
import static java.lang.String.format;
Expand Down Expand Up @@ -205,17 +204,17 @@ private EstimatedStatsAndCost getEstimatedStatsAndCost()
public static class TableColumnInfo
{
private final CatalogSchemaTableName table;
private final Set<ColumnConstraint> columnConstraints;
private final Constraint constraint;
private final EstimatedStatsAndCost estimate;

@JsonCreator
public TableColumnInfo(
@JsonProperty("table") CatalogSchemaTableName table,
@JsonProperty("columnConstraints") Set<ColumnConstraint> columnConstraints,
@JsonProperty("constraint") Constraint constraint,
@JsonProperty("estimate") EstimatedStatsAndCost estimate)
{
this.table = requireNonNull(table, "table is null");
this.columnConstraints = requireNonNull(columnConstraints, "columnConstraints is null");
this.constraint = requireNonNull(constraint, "constraint is null");
this.estimate = requireNonNull(estimate, "estimate is null");
}

Expand All @@ -226,9 +225,9 @@ public CatalogSchemaTableName getTable()
}

@JsonProperty
public Set<ColumnConstraint> getColumnConstraints()
public Constraint getConstraint()
{
return columnConstraints;
return constraint;
}

@JsonProperty
Expand All @@ -248,28 +247,84 @@ public boolean equals(Object obj)
}
TableColumnInfo o = (TableColumnInfo) obj;
return Objects.equals(table, o.table) &&
Objects.equals(columnConstraints, o.columnConstraints) &&
Objects.equals(constraint, o.constraint) &&
Objects.equals(estimate, o.estimate);
}

@Override
public int hashCode()
{
return Objects.hash(table, columnConstraints, estimate);
return Objects.hash(table, constraint, estimate);
}

@Override
public String toString()
{
return toStringHelper(this)
.add("table", table)
.add("columnConstraints", columnConstraints)
.add("constraint", constraint)
.add("estimate", estimate)
.toString();
}
}
}

public static class Constraint
{
private final boolean isNone;
private final Set<ColumnConstraint> columnConstraints;

@JsonCreator
public Constraint(
@JsonProperty("none") boolean isNone,
@JsonProperty("columnConstraints") Set<ColumnConstraint> columnConstraints)
{
this.isNone = isNone;
this.columnConstraints = ImmutableSet.copyOf(requireNonNull(columnConstraints, "columnConstraints is null"));
}

@JsonProperty
public boolean isNone()
{
return isNone;
}

@JsonProperty
public Set<ColumnConstraint> getColumnConstraints()
{
return columnConstraints;
}

@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Constraint o = (Constraint) obj;
return Objects.equals(isNone, o.isNone) &&
Objects.equals(columnConstraints, o.columnConstraints);
}

@Override
public int hashCode()
{
return Objects.hash(isNone, columnConstraints);
}

@Override
public String toString()
{
return toStringHelper(this)
.add("none", isNone)
.add("columnConstraints", columnConstraints)
.toString();
}
}

public static class ColumnConstraint
{
private final String columnName;
Expand Down Expand Up @@ -703,7 +758,7 @@ private void addInputTableConstraints(TupleDomain<ColumnHandle> filterDomain, Ta
tableMetadata.getCatalogName(),
tableMetadata.getTable().getSchemaName(),
tableMetadata.getTable().getTableName()),
parseConstraints(table, predicateDomain.intersect(filterDomain)),
parseConstraint(table, predicateDomain.intersect(filterDomain)),
estimatedStatsAndCost));
}

Expand All @@ -722,18 +777,20 @@ private EstimatedStatsAndCost getEstimatedStatsAndCost(TableScanNode node)
return estimatedStatsAndCost;
}

private Set<ColumnConstraint> parseConstraints(TableHandle tableHandle, TupleDomain<ColumnHandle> constraint)
private Constraint parseConstraint(TableHandle tableHandle, TupleDomain<ColumnHandle> constraint)
{
checkArgument(!constraint.isNone());
if (constraint.isNone()) {
return new Constraint(true, ImmutableSet.of());
}
ImmutableSet.Builder<ColumnConstraint> columnConstraints = ImmutableSet.builder();
for (Map.Entry<ColumnHandle, Domain> entry : constraint.getDomains().get().entrySet()) {
for (Map.Entry<ColumnHandle, Domain> entry : constraint.getDomains().orElseThrow().entrySet()) {
ColumnMetadata columnMetadata = plannerContext.getMetadata().getColumnMetadata(session, tableHandle, entry.getKey());
columnConstraints.add(new ColumnConstraint(
columnMetadata.getName(),
columnMetadata.getType(),
parseDomain(entry.getValue().simplify())));
}
return columnConstraints.build();
return new Constraint(false, columnConstraints.build());
}

private FormattedDomain parseDomain(Domain domain)
Expand Down
Loading