>From Hussain Towaileb <[email protected]>:

Hussain Towaileb has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19004 )


Change subject: [ASTERIXDB-3521][FUN]: Verify datasource function args before 
replicating
......................................................................

[ASTERIXDB-3521][FUN]: Verify datasource function args before replicating

Ext-ref: MB-63994
Change-Id: I56ade50f1efcf0cf46d3883670f31e9a64900a93
---
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexDatasource.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSSingleTableDataGeneratorDatasource.java
M 
hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/IsomorphismOperatorVisitor.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/explain/explain_same_datasource_function_different_arguments/test.020.adm
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/CompletedRequestsDatasource.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/JobSummariesDatasource.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryPartitionDatasource.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.000.ddl.sqlpp
M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
M 
asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/FunctionDataSource.java
M 
hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/metadata/IDataSource.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSAllTablesDataGeneratorDatasource.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.010.update.sqlpp
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/PingDatasource.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsDatasource.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.030.query.sqlpp
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesDatasource.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.020.query.sqlpp
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/ActiveRequestsDatasource.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryIndexDatasource.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/explain/explain_same_datasource_function_different_arguments/test.030.plan
22 files changed, 320 insertions(+), 3 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/04/19004/1

diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/ActiveRequestsDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/ActiveRequestsDatasource.java
index 5239d01..e856c30 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/ActiveRequestsDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/ActiveRequestsDatasource.java
@@ -25,6 +25,7 @@
 import org.apache.asterix.metadata.declared.MetadataProvider;
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;

 public class ActiveRequestsDatasource extends FunctionDataSource {
@@ -48,4 +49,9 @@
     public boolean skipJobCapacityAssignment() {
         return true;
     }
+
+    @Override
+    protected boolean isSameArguments(IDataSource<?> other) {
+        return true;
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/CompletedRequestsDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/CompletedRequestsDatasource.java
index f02af21..b37e020 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/CompletedRequestsDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/CompletedRequestsDatasource.java
@@ -25,6 +25,7 @@
 import org.apache.asterix.metadata.declared.MetadataProvider;
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;

 public class CompletedRequestsDatasource extends FunctionDataSource {
@@ -48,4 +49,9 @@
     public boolean skipJobCapacityAssignment() {
         return true;
     }
+
+    @Override
+    protected boolean isSameArguments(IDataSource<?> other) {
+        return true;
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesDatasource.java
index 3e5033b..79069fb 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesDatasource.java
@@ -18,12 +18,15 @@
  */
 package org.apache.asterix.app.function;

+import java.util.Objects;
+
 import org.apache.asterix.metadata.api.IDatasourceFunction;
 import org.apache.asterix.metadata.declared.DataSourceId;
 import org.apache.asterix.metadata.declared.FunctionDataSource;
 import org.apache.asterix.metadata.declared.MetadataProvider;
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;

 public class DatasetResourcesDatasource extends FunctionDataSource {
@@ -43,4 +46,17 @@
             AlgebricksAbsolutePartitionConstraint locations) {
         return new DatasetResourcesFunction(locations, datasetId);
     }
+
+    public int getDatasetId() {
+        return datasetId;
+    }
+
+    @Override
+    public boolean isSameArguments(IDataSource<?> other) {
+        if (!(other instanceof DatasetResourcesDatasource)) {
+            return false;
+        }
+        DatasetResourcesDatasource that = (DatasetResourcesDatasource) other;
+        return Objects.equals(this.datasetId, that.getDatasetId());
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexDatasource.java
index 1eac011..301c6bd 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexDatasource.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.app.function;

+import java.util.Objects;
+
 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.external.api.IDataParserFactory;
 import org.apache.asterix.external.parser.factory.JSONDataParserFactory;
@@ -25,8 +27,10 @@
 import org.apache.asterix.metadata.declared.DataSourceId;
 import org.apache.asterix.metadata.declared.FunctionDataSource;
 import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.metadata.entities.Index;
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
 import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
@@ -41,16 +45,23 @@
     private final IBinaryComparatorFactory[] comparatorFactories;
     private final AlgebricksAbsolutePartitionConstraint constraint;
     private final int[][] partitionsMap;
+    private final Index index;
 
     public DumpIndexDatasource(INodeDomain domain, IndexDataflowHelperFactory 
indexDataflowHelperFactory,
             RecordDescriptor recDesc, IBinaryComparatorFactory[] 
comparatorFactories,
-            AlgebricksAbsolutePartitionConstraint constraint, int[][] 
partitionsMap) throws AlgebricksException {
+            AlgebricksAbsolutePartitionConstraint constraint, int[][] 
partitionsMap, Index index)
+            throws AlgebricksException {
         super(DUMP_INDEX_DATASOURCE_ID, DumpIndexRewriter.DUMP_INDEX, domain);
         this.indexDataflowHelperFactory = indexDataflowHelperFactory;
         this.recDesc = recDesc;
         this.comparatorFactories = comparatorFactories;
         this.constraint = constraint;
         this.partitionsMap = partitionsMap;
+        this.index = index;
+    }
+
+    public Index getIndex() {
+        return index;
     }

     @Override
@@ -69,4 +80,13 @@
     protected IDataParserFactory createDataParserFactory() {
         return new JSONDataParserFactory();
     }
+
+    @Override
+    public boolean isSameArguments(IDataSource<?> other) {
+        if (!(other instanceof DumpIndexDatasource)) {
+            return false;
+        }
+        DumpIndexDatasource that = (DumpIndexDatasource) other;
+        return Objects.equals(this.index, that.getIndex());
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java
index d50315b..825d571 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java
@@ -89,7 +89,7 @@
                 (AlgebricksAbsolutePartitionConstraint) 
partitioningProperties.getConstraints();
         return new DumpIndexDatasource(context.getComputationNodeDomain(), 
indexDataflowHelperFactory,
                 secondaryIndexHelper.getSecondaryRecDesc(), 
secondaryIndexHelper.getSecondaryComparatorFactories(),
-                secondaryPartitionConstraint, 
partitioningProperties.getComputeStorageMap());
+                secondaryPartitionConstraint, 
partitioningProperties.getComputeStorageMap(), index);
     }

     @Override
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/JobSummariesDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/JobSummariesDatasource.java
index 6bab0cd..2732b82 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/JobSummariesDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/JobSummariesDatasource.java
@@ -24,6 +24,7 @@
 import org.apache.asterix.metadata.declared.MetadataProvider;
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;

 public class JobSummariesDatasource extends FunctionDataSource {
@@ -40,4 +41,9 @@
             AlgebricksAbsolutePartitionConstraint locations) {
         return new 
JobSummariesFunction(AlgebricksAbsolutePartitionConstraint.randomLocation(locations.getLocations()));
     }
+
+    @Override
+    protected boolean isSameArguments(IDataSource<?> other) {
+        return true;
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/PingDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/PingDatasource.java
index 1b6d807..3a3c69f 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/PingDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/PingDatasource.java
@@ -24,6 +24,7 @@
 import org.apache.asterix.metadata.declared.MetadataProvider;
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;

 public class PingDatasource extends FunctionDataSource {
@@ -40,4 +41,8 @@
         return new PingFunction(locations);
     }

+    @Override
+    protected boolean isSameArguments(IDataSource<?> other) {
+        return true;
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryIndexDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryIndexDatasource.java
index 52054d6..aa3923d 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryIndexDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryIndexDatasource.java
@@ -20,6 +20,7 @@

 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;

 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.metadata.api.IDatasourceFunction;
@@ -71,6 +72,14 @@
         this.numSecKeys = numSecKeys;
     }

+    public Dataset getDataset() {
+        return ds;
+    }
+
+    public String getIndexName() {
+        return indexName;
+    }
+
     @Override
     protected void initSchemaType(IAType iType) {
         ARecordType type = (ARecordType) iType;
@@ -138,4 +147,13 @@
         return new DataSourceId(dataset.getDatabaseName(), 
dataset.getDataverseName(), dataset.getDatasetName(),
                 new String[] { indexName, 
QueryIndexRewriter.QUERY_INDEX.getName() });
     }
+
+    @Override
+    public boolean isSameArguments(IDataSource<?> other) {
+        if (!(other instanceof QueryIndexDatasource)) {
+            return false;
+        }
+        QueryIndexDatasource that = (QueryIndexDatasource) other;
+        return Objects.equals(this.ds, that.getDataset()) && 
Objects.equals(this.indexName, that.getIndexName());
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryPartitionDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryPartitionDatasource.java
index 4d40ba6..dc0fc3f 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryPartitionDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/QueryPartitionDatasource.java
@@ -20,6 +20,7 @@

 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;

 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.metadata.api.IDatasourceFunction;
@@ -68,6 +69,10 @@
         this.storageLocations = storageLocations;
     }

+    public Dataset getDataset() {
+        return ds;
+    }
+
     @Override
     protected void initSchemaType(IAType iType) {
         ARecordType type = (ARecordType) iType;
@@ -128,4 +133,13 @@
         return new DataSourceId(dataset.getDatabaseName(), 
dataset.getDataverseName(), dataset.getDatasetName(),
                 new String[] { dataset.getDatasetName(), 
QueryPartitionRewriter.QUERY_PARTITION.getName() });
     }
+
+    @Override
+    public boolean isSameArguments(IDataSource<?> other) {
+        if (!(other instanceof QueryPartitionDatasource)) {
+            return false;
+        }
+        QueryPartitionDatasource that = (QueryPartitionDatasource) other;
+        return Objects.equals(this.ds, that.getDataset());
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsDatasource.java
index 6157412..cefc476 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsDatasource.java
@@ -18,12 +18,15 @@
  */
 package org.apache.asterix.app.function;

+import java.util.Objects;
+
 import org.apache.asterix.metadata.api.IDatasourceFunction;
 import org.apache.asterix.metadata.declared.DataSourceId;
 import org.apache.asterix.metadata.declared.FunctionDataSource;
 import org.apache.asterix.metadata.declared.MetadataProvider;
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;

 public class StorageComponentsDatasource extends FunctionDataSource {
@@ -38,9 +41,22 @@
         this.datasetId = datasetId;
     }

+    public int getDatasetId() {
+        return datasetId;
+    }
+
     @Override
     protected IDatasourceFunction createFunction(MetadataProvider 
metadataProvider,
             AlgebricksAbsolutePartitionConstraint locations) {
         return new StorageComponentsFunction(locations, datasetId);
     }
+
+    @Override
+    public boolean isSameArguments(IDataSource<?> other) {
+        if (!(other instanceof StorageComponentsDatasource)) {
+            return false;
+        }
+        StorageComponentsDatasource that = (StorageComponentsDatasource) other;
+        return Objects.equals(this.datasetId, that.getDatasetId());
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSAllTablesDataGeneratorDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSAllTablesDataGeneratorDatasource.java
index b4d1b03..dd73569 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSAllTablesDataGeneratorDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSAllTablesDataGeneratorDatasource.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.app.function;

+import java.util.Objects;
+
 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.metadata.api.IDatasourceFunction;
 import org.apache.asterix.metadata.declared.DataSourceId;
@@ -26,6 +28,7 @@
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;

 /**
@@ -42,6 +45,10 @@
         this.scalingFactor = scalingFactor;
     }

+    public double getScalingFactor() {
+        return scalingFactor;
+    }
+
     /**
      * This ensures that each function will have a unique DataSourceId by 
passing the table name as part of the
      * DataSourceId. This eliminates the issue of creating a single function 
even though multiple functions calls
@@ -66,4 +73,13 @@
     protected AlgebricksAbsolutePartitionConstraint 
getLocations(IClusterStateManager csm, MetadataProvider md) {
         return md.getDataPartitioningProvider().getClusterLocations();
     }
+
+    @Override
+    public boolean isSameArguments(IDataSource<?> other) {
+        if (!(other instanceof TPCDSAllTablesDataGeneratorDatasource)) {
+            return false;
+        }
+        TPCDSAllTablesDataGeneratorDatasource that = 
(TPCDSAllTablesDataGeneratorDatasource) other;
+        return Objects.equals(this.scalingFactor, that.getScalingFactor());
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSSingleTableDataGeneratorDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSSingleTableDataGeneratorDatasource.java
index 3bbaee2..abf3a3b 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSSingleTableDataGeneratorDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSSingleTableDataGeneratorDatasource.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.app.function;

+import java.util.Objects;
+
 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.metadata.api.IDatasourceFunction;
 import org.apache.asterix.metadata.declared.DataSourceId;
@@ -26,6 +28,7 @@
 import 
org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IDataSource;
 import org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain;

 /**
@@ -44,6 +47,14 @@
         this.scalingFactor = scalingFactor;
     }

+    public String getTableName() {
+        return tableName;
+    }
+
+    public double getScalingFactor() {
+        return scalingFactor;
+    }
+
     /**
      * This ensures that each function will have a unique DataSourceId by 
passing the table name as part of the
      * DataSourceId. This eliminates the issue of creating a single function 
even though multiple functions calls
@@ -70,4 +81,14 @@
     protected AlgebricksAbsolutePartitionConstraint 
getLocations(IClusterStateManager csm, MetadataProvider md) {
         return md.getDataPartitioningProvider().getClusterLocations();
     }
+
+    @Override
+    public boolean isSameArguments(IDataSource<?> other) {
+        if (!(other instanceof TPCDSSingleTableDataGeneratorDatasource)) {
+            return false;
+        }
+        TPCDSSingleTableDataGeneratorDatasource that = 
(TPCDSSingleTableDataGeneratorDatasource) other;
+        return Objects.equals(this.tableName, that.getTableName())
+                && Objects.equals(this.scalingFactor, that.getScalingFactor());
+    }
 }
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.000.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.000.ddl.sqlpp
new file mode 100644
index 0000000..47332b3
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.000.ddl.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+SET `import-private-functions` `true`;
+DROP DATASET test IF EXISTS;
+CREATE DATASET test PRIMARY KEY(id: int);
+
+DROP INDEX test.test_int_idx IF EXISTS;
+CREATE INDEX test_int_idx ON test(intField: int);
+
+DROP INDEX test.test_string_idx IF EXISTS;
+CREATE INDEX test_string_idx ON test(stringField: string);
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.010.update.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.010.update.sqlpp
new file mode 100644
index 0000000..753a384
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.010.update.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+INSERT INTO test({"id": 1, "intField": 15, "stringField": "foo"});
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.020.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.020.query.sqlpp
new file mode 100644
index 0000000..6d5bf8a
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.020.query.sqlpp
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+SET `import-private-functions` `true`;
+
+SELECT dump_index("Default", "test", "test_int_idx") as intIndex
+UNION ALL
+SELECT dump_index("Default", "test", "test_string_idx") as stringIndex;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.030.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.030.query.sqlpp
new file mode 100644
index 0000000..eef8574
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_same_datasource_function_different_arguments/test.030.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+SET `import-private-functions` `true`;
+
+explain
+SELECT dump_index("Default", "test", "test_int_idx") as intIndex
+UNION ALL
+SELECT dump_index("Default", "test", "test_string_idx") as stringIndex;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/explain/explain_same_datasource_function_different_arguments/test.020.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/explain/explain_same_datasource_function_different_arguments/test.020.adm
new file mode 100644
index 0000000..24e0e67
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/explain/explain_same_datasource_function_different_arguments/test.020.adm
@@ -0,0 +1,2 @@
+{ "intIndex": [ { "values": [ 15, 1 ] } ] }
+{ "stringIndex": [ { "values": [ "foo", 1 ] } ] }
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/explain/explain_same_datasource_function_different_arguments/test.030.plan
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/explain/explain_same_datasource_function_different_arguments/test.030.plan
new file mode 100644
index 0000000..825f43a
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/explain/explain_same_datasource_function_different_arguments/test.030.plan
@@ -0,0 +1,38 @@
+distribute result [$$11] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+-- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    union ($$16, $$17, $$11) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+    -- UNION_ALL  |UNPARTITIONED|
+      exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+      -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+        project ([$$16]) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+        -- STREAM_PROJECT  |UNPARTITIONED|
+          assign [$$16] <- [cast({"intIndex": $$13})] [cardinality: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+          -- ASSIGN  |UNPARTITIONED|
+            aggregate [$$13] <- [listify($$12)] [cardinality: 0.0, op-cost: 
0.0, total-cost: 0.0]
+            -- AGGREGATE  |UNPARTITIONED|
+              exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+              -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                data-scan []<-[$$12] <- asterix.dump-index. [cardinality: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source [cardinality: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+      -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+        project ([$$17]) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+        -- STREAM_PROJECT  |UNPARTITIONED|
+          assign [$$17] <- [cast({"stringIndex": $$15})] [cardinality: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+          -- ASSIGN  |UNPARTITIONED|
+            aggregate [$$15] <- [listify($$14)] [cardinality: 0.0, op-cost: 
0.0, total-cost: 0.0]
+            -- AGGREGATE  |UNPARTITIONED|
+              exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+              -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                data-scan []<-[$$14] <- asterix.dump-index. [cardinality: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0]
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source [cardinality: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml 
b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
index c4f73b0..f4e529b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
@@ -342,6 +342,11 @@
         <expected-error>ASX1001: Syntax error: EXPLAIN is not supported for 
this kind of statement</expected-error>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="explain">
+      <compilation-unit 
name="explain_same_datasource_function_different_arguments">
+        <output-dir 
compare="Text">explain_same_datasource_function_different_arguments</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="aggregate">
     <test-case FilePath="aggregate">
diff --git 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/FunctionDataSource.java
 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/FunctionDataSource.java
index 91f7615..0484ae1 100644
--- 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/FunctionDataSource.java
+++ 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/FunctionDataSource.java
@@ -21,6 +21,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;

 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.common.functions.FunctionSignature;
@@ -139,4 +140,19 @@
     protected static DataSourceId createDataSourceId(FunctionIdentifier fid, 
String... parameters) {
         return new DataSourceId(fid.getDatabase(), 
FunctionSignature.getDataverseName(fid), fid.getName(), parameters);
     }
+
+    protected abstract boolean isSameArguments(IDataSource<?> other);
+
+    @Override
+    public boolean equals(IDataSource<?> other) {
+        if (this == other) {
+            return true;
+        }
+        if (!(other instanceof FunctionDataSource)) {
+            return false;
+        }
+        FunctionDataSource that = (FunctionDataSource) other;
+        return Objects.equals(this.id, that.getId()) && 
Objects.equals(this.datasourceType, that.getDatasourceType())
+                && Objects.equals(this.functionId, that.getFunctionId()) && 
isSameArguments(other);
+    }
 }
diff --git 
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/metadata/IDataSource.java
 
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/metadata/IDataSource.java
index 5b75cd9..d078f28 100644
--- 
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/metadata/IDataSource.java
+++ 
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/metadata/IDataSource.java
@@ -51,4 +51,8 @@
     default boolean compareProperties() {
         return false;
     }
+
+    default boolean equals(IDataSource<?> other) {
+        return true;
+    }
 }
diff --git 
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/IsomorphismOperatorVisitor.java
 
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/IsomorphismOperatorVisitor.java
index 05f41a0..2bcb937 100644
--- 
a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/IsomorphismOperatorVisitor.java
+++ 
b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/IsomorphismOperatorVisitor.java
@@ -503,7 +503,10 @@
                 scanOpArg.getSelectCondition() != null ? 
scanOpArg.getSelectCondition().getValue() : null;
         isomorphic = 
VariableUtilities.varListEqualUnordered(op.getVariables(), 
scanOpArg.getVariables())
                 && Objects.equals(opCondition, argCondition);
-        return isomorphic;
+        if (!isomorphic) {
+            return false;
+        }
+        return dataSource.equals(argDataSource);
     }

     @Override

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19004
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I56ade50f1efcf0cf46d3883670f31e9a64900a93
Gerrit-Change-Number: 19004
Gerrit-PatchSet: 1
Gerrit-Owner: Hussain Towaileb <[email protected]>
Gerrit-MessageType: newchange

Reply via email to