You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2021/08/30 08:57:34 UTC

[impala] 03/03: IMPALA-10888: sort partitions by name before comparing in test

This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit beb8019f5300bb163424e7fdfec50b8e4b796e26
Author: Vihang Karajgaonkar <vi...@apache.org>
AuthorDate: Thu Aug 26 15:55:26 2021 -0700

    IMPALA-10888: sort partitions by name before comparing in test
    
    CatalogHmsFileMetadataTest and EnableCatalogdHmsCacheFlagTest
    compare the partition filemetada which is returned over by
    get_partitions_by_names HMS API. However, the catalogd's
    implementation of API does not return the partitions in a
    deterministic order. Hence the tests can fail intermittently.
    
    The patch sorts the returned partitions by names before
    making any comparisons to avoid the flakiness of the test.
    
    Testing:
    1. Modified existing test to do the sorting before
    asserting the filemetadata comparison.
    
    Change-Id: I75aa9d714e888ec7f7efd62e475ba1d3a3342256
    Reviewed-on: http://gerrit.cloudera.org:8080/17812
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 .../apache/impala/catalog/CatalogHmsAPIHelper.java |  7 +++++++
 .../metastore/AbstractCatalogMetastoreTest.java    | 23 ++++++++++++++++++++++
 .../metastore/CatalogHmsFileMetadataTest.java      |  9 +++++++++
 .../metastore/EnableCatalogdHmsCacheFlagTest.java  |  3 +++
 4 files changed, 42 insertions(+)

diff --git a/fe/src/main/java/org/apache/impala/catalog/CatalogHmsAPIHelper.java b/fe/src/main/java/org/apache/impala/catalog/CatalogHmsAPIHelper.java
index dd7937d..0121cfd 100644
--- a/fe/src/main/java/org/apache/impala/catalog/CatalogHmsAPIHelper.java
+++ b/fe/src/main/java/org/apache/impala/catalog/CatalogHmsAPIHelper.java
@@ -17,6 +17,7 @@
 
 package org.apache.impala.catalog;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Stopwatch;
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
@@ -27,6 +28,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -48,6 +50,7 @@ import org.apache.hadoop.hive.metastore.PartitionExpressionProxy;
 import org.apache.hadoop.hive.metastore.api.ColumnStatistics;
 import org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc;
 import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
 import org.apache.hadoop.hive.metastore.api.FileMetadata;
 import org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesRequest;
 import org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesResult;
@@ -438,6 +441,10 @@ public class CatalogHmsAPIHelper {
         retPartitions.add(part);
       }
     }
+    // HMS API returns partitions sorted by partition name, however this is just a
+    // semantic behavior. We don't have any evidence of clients relying on the sortedness
+    // of returned partitions. Hence, we optimistically return the partitions without
+    // sorting by names here.
     GetPartitionsByNamesResult result = new GetPartitionsByNamesResult(retPartitions);
     if (request.isGetFileMetadata()) {
       result.setDictionary(getSerializedNetworkAddress(
diff --git a/fe/src/test/java/org/apache/impala/catalog/metastore/AbstractCatalogMetastoreTest.java b/fe/src/test/java/org/apache/impala/catalog/metastore/AbstractCatalogMetastoreTest.java
index 04e3959..5ac0199 100644
--- a/fe/src/test/java/org/apache/impala/catalog/metastore/AbstractCatalogMetastoreTest.java
+++ b/fe/src/test/java/org/apache/impala/catalog/metastore/AbstractCatalogMetastoreTest.java
@@ -17,13 +17,21 @@
 
 package org.apache.impala.catalog.metastore;
 
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Partition;
 import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
 import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
 import org.apache.impala.authorization.NoopAuthorizationFactory;
 import org.apache.impala.authorization.NoopAuthorizationFactory.NoopAuthorizationManager;
 import org.apache.impala.catalog.CatalogServiceCatalog;
+import org.apache.impala.compat.MetastoreShim;
 import org.apache.impala.service.CatalogOpExecutor;
 import org.apache.impala.testutil.CatalogServiceTestCatalog;
 import org.apache.impala.testutil.CatalogTestMetastoreServer;
@@ -61,6 +69,21 @@ public abstract class AbstractCatalogMetastoreTest {
     catalogHmsClient_ = new HiveMetaStoreClient(CONF);
   }
 
+  /**
+   * Sort the given partitions by names.
+   */
+  protected static void sortPartitionsByNames(List<FieldSchema> partitionKeys,
+      List<Partition> retPartitions) {
+    assertTrue(retPartitions.isEmpty() || partitionKeys.size() == retPartitions.get(0)
+        .getValuesSize());
+    List<String> partitionColNames = new ArrayList<>();
+    for (FieldSchema partSchema : partitionKeys) {
+      partitionColNames.add(partSchema.getName());
+    }
+    retPartitions.sort(Comparator.comparing(
+        (part) -> MetastoreShim.makePartName(partitionColNames, part.getValues())));
+  }
+
   @AfterClass
   public static void cleanUp() throws Exception {
     catalogMetastoreServer_.stop();
diff --git a/fe/src/test/java/org/apache/impala/catalog/metastore/CatalogHmsFileMetadataTest.java b/fe/src/test/java/org/apache/impala/catalog/metastore/CatalogHmsFileMetadataTest.java
index b56afb1..ff67596 100644
--- a/fe/src/test/java/org/apache/impala/catalog/metastore/CatalogHmsFileMetadataTest.java
+++ b/fe/src/test/java/org/apache/impala/catalog/metastore/CatalogHmsFileMetadataTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
@@ -34,6 +35,7 @@ import org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesResult;
 import org.apache.hadoop.hive.metastore.api.Partition;
 import org.apache.hadoop.hive.metastore.api.Table;
 import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
+import org.apache.impala.catalog.CatalogHmsAPIHelper;
 import org.apache.impala.catalog.HdfsPartition;
 import org.apache.impala.catalog.HdfsPartition.FileBlock;
 import org.apache.impala.catalog.HdfsPartition.FileDescriptor;
@@ -44,6 +46,7 @@ import org.apache.thrift.TException;
 import org.junit.Test;
 
 public class CatalogHmsFileMetadataTest extends AbstractCatalogMetastoreTest {
+
   /**
    * The test fetches partitions of a table over HMS API and then compares if the
    * deserialized filemetadata from the response matches with what we have in catalogd.
@@ -80,6 +83,9 @@ public class CatalogHmsFileMetadataTest extends AbstractCatalogMetastoreTest {
     request.setNames(Arrays.asList("year=2009/month=1", "year=2009/month=2"));
     request.setGetFileMetadata(true);
     result = catalogHmsClient_.getPartitionsByNames(request);
+    // make sure that the partitions are in sorted order
+    sortPartitionsByNames(tbl.getMetaStoreTable().getPartitionKeys(),
+        result.getPartitions());
     for (Partition part : result.getPartitions()) {
       assertNotNull(part.getFileMetadata());
     }
@@ -124,6 +130,9 @@ public class CatalogHmsFileMetadataTest extends AbstractCatalogMetastoreTest {
     request.setGetFileMetadata(true);
     request.setValidWriteIdList(tbl.getValidWriteIds().toString());
     GetPartitionsByNamesResult result = catalogHmsClient_.getPartitionsByNames(request);
+    // sort partitions by names to avoid flakiness
+    sortPartitionsByNames(tbl.getMetaStoreTable().getPartitionKeys(),
+        result.getPartitions());
     for (Partition part : result.getPartitions()) {
       assertNotNull(part.getFileMetadata());
     }
diff --git a/fe/src/test/java/org/apache/impala/catalog/metastore/EnableCatalogdHmsCacheFlagTest.java b/fe/src/test/java/org/apache/impala/catalog/metastore/EnableCatalogdHmsCacheFlagTest.java
index 008ec3a..a9e9530 100644
--- a/fe/src/test/java/org/apache/impala/catalog/metastore/EnableCatalogdHmsCacheFlagTest.java
+++ b/fe/src/test/java/org/apache/impala/catalog/metastore/EnableCatalogdHmsCacheFlagTest.java
@@ -79,6 +79,9 @@ public class EnableCatalogdHmsCacheFlagTest extends AbstractCatalogMetastoreTest
     request.setNames(Arrays.asList("year=2009/month=1", "year=2009/month=2"));
     request.setGetFileMetadata(true);
     result = catalogHmsClient_.getPartitionsByNames(request);
+    // sort partitions by names to avoid flakiness
+    sortPartitionsByNames(tbl.getMetaStoreTable().getPartitionKeys(),
+        result.getPartitions());
     for (Partition part : result.getPartitions()) {
       assertNotNull(part.getFileMetadata());
     }