!1026 Fix rename of bucketing column

Merge pull request !1026 from NeerajUnnikrishnan/rename_bkt_col
This commit is contained in:
i-robot 2021-08-17 04:56:20 +00:00 committed by Gitee
commit ac24b321a5
3 changed files with 24 additions and 6 deletions

View File

@ -49,7 +49,6 @@ import java.util.stream.Collectors;
import static io.prestosql.plugin.hive.HiveBucketing.BucketingVersion.BUCKETING_V1;
import static io.prestosql.plugin.hive.HiveBucketing.BucketingVersion.BUCKETING_V2;
import static io.prestosql.plugin.hive.HiveColumnHandle.BUCKET_COLUMN_NAME;
import static io.prestosql.plugin.hive.HiveErrorCode.HIVE_INVALID_METADATA;
import static io.prestosql.plugin.hive.HiveUtil.getRegularColumnHandles;
import static java.lang.String.format;
import static java.util.Map.Entry;
@ -152,9 +151,7 @@ public final class HiveBucketing
for (String bucketColumnName : hiveBucketProperty.get().getBucketedBy()) {
HiveColumnHandle bucketColumnHandle = map.get(bucketColumnName);
if (bucketColumnHandle == null) {
throw new PrestoException(
HIVE_INVALID_METADATA,
format("Table '%s.%s' is bucketed on non-existent column '%s'", table.getDatabaseName(), table.getTableName(), bucketColumnName));
return Optional.empty();
}
bucketColumns.add(bucketColumnHandle);
}
@ -166,7 +163,7 @@ public final class HiveBucketing
public static Optional<HiveBucketFilter> getHiveBucketFilter(Table table, TupleDomain<ColumnHandle> effectivePredicate)
{
if (!table.getStorage().getBucketProperty().isPresent()) {
if (!getHiveBucketHandle(table).isPresent()) {
return Optional.empty();
}

View File

@ -123,6 +123,7 @@ import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static io.prestosql.plugin.hive.HiveBucketing.bucketedOnTimestamp;
import static io.prestosql.plugin.hive.HiveBucketing.getHiveBucketHandle;
import static io.prestosql.plugin.hive.HiveColumnHandle.bucketColumnHandle;
import static io.prestosql.plugin.hive.util.CustomSplitConversionUtils.recreateSplitWithCustomInfo;
import static io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
@ -878,7 +879,7 @@ public final class HiveUtil
// add hidden columns
columns.add(HiveColumnHandle.pathColumnHandle());
if (table.getStorage().getBucketProperty().isPresent()) {
if (getHiveBucketHandle(table).isPresent()) {
if (!bucketedOnTimestamp(table.getStorage().getBucketProperty().get(), table)) {
columns.add(bucketColumnHandle());
}

View File

@ -3200,6 +3200,26 @@ public class TestHiveIntegrationSmokeTest
assertUpdate("DROP TABLE test_drop_bucketing_column");
}
@Test
private void testRenameBucketingColumn()
{
@Language("SQL") String createTable = "" +
"CREATE TABLE test_rename_bucketing_column\n" +
"WITH (\n" +
" bucket_count = 5, bucketed_by = ARRAY ['orderstatus']\n" +
")\n" +
"AS\n" +
"SELECT custkey, orderkey, orderstatus FROM orders";
assertUpdate(createTable, "SELECT count(*) FROM orders");
assertQuery("SELECT orderkey, orderstatus FROM test_rename_bucketing_column", "SELECT orderkey, orderstatus FROM orders");
assertUpdate("ALTER TABLE test_rename_bucketing_column RENAME COLUMN orderstatus TO orderstatus1");
assertQuery("SELECT orderkey, orderstatus1 FROM test_rename_bucketing_column", "SELECT orderkey, orderstatus FROM orders");
assertUpdate("DROP TABLE test_rename_bucketing_column");
}
@Test
public void testAvroTypeValidation()
{