[NO ISSUE][COMP] Ensure Consistent Locations in Splits and Constraints

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- This change ensures that the splits provider and constraints
  have the same order of locations to avoid a possibility where
  splits of a node are assigned to another node.

Change-Id: Id969251eb17bfb5139bc656b1e5025c2742d5318
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2872
Reviewed-by: Michael Blow <mblow@apache.org>
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/StoragePathUtil.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/StoragePathUtil.java
index aa2c7af..63e29ce 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/StoragePathUtil.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/StoragePathUtil.java
@@ -21,6 +21,8 @@
 import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Comparator;
 
 import org.apache.asterix.common.cluster.ClusterPartition;
 import org.apache.asterix.common.storage.ResourceReference;
@@ -39,12 +41,15 @@
 public class StoragePathUtil {
 
     private static final Logger LOGGER = LogManager.getLogger();
+    private static final Comparator<FileSplit> FILE_SPLIT_COMPARATOR =
+            Comparator.comparing(FileSplit::getNodeName).thenComparing(FileSplit::getPath);
 
     private StoragePathUtil() {
     }
 
     public static Pair<IFileSplitProvider, AlgebricksPartitionConstraint> splitProviderAndPartitionConstraints(
             FileSplit[] splits) {
+        Arrays.sort(splits, FILE_SPLIT_COMPARATOR);
         IFileSplitProvider splitProvider = new ConstantFileSplitProvider(splits);
         String[] loc = new String[splits.length];
         for (int p = 0; p < splits.length; p++) {
diff --git a/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/constraints/AlgebricksAbsolutePartitionConstraint.java b/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/constraints/AlgebricksAbsolutePartitionConstraint.java
index 1bb217a..7a1bb28 100644
--- a/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/constraints/AlgebricksAbsolutePartitionConstraint.java
+++ b/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/constraints/AlgebricksAbsolutePartitionConstraint.java
@@ -27,8 +27,7 @@
     private final String[] locations;
 
     public AlgebricksAbsolutePartitionConstraint(String[] locations) {
-        this.locations = locations.clone();
-        Arrays.sort(this.locations);
+        this.locations = locations;
     }
 
     @Override