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

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


The following commit(s) were added to refs/heads/master by this push:
     new 086e848  [NO ISSUE][RT][COMP] Use more components to identify a 
datasource
086e848 is described below

commit 086e8485f6c3587a7b7dd857481a14a115321889
Author: Till Westmann <[email protected]>
AuthorDate: Thu Jun 6 19:26:56 2019 -0700

    [NO ISSUE][RT][COMP] Use more components to identify a datasource
    
    - user model changes: no
    - storage format changes: no
    - interface changes: additional constructor for DataSourceId
    
    Change-Id: If371a6c7f8302ee7a83ddba0f1c6aeecdea4d5ef
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3426
    Contrib: Jenkins <[email protected]>
    Sonar-Qube: Jenkins <[email protected]>
    Tested-by: Jenkins <[email protected]>
    Integration-Tests: Jenkins <[email protected]>
    Reviewed-by: Hussain Towaileb <[email protected]>
---
 .../app/function/TPCDSDataGeneratorDatasource.java | 12 +++---
 .../asterix/metadata/declared/DataSourceId.java    | 46 ++++++++++++++++------
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSDataGeneratorDatasource.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSDataGeneratorDatasource.java
index d0ff67e..cb7e357 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSDataGeneratorDatasource.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/TPCDSDataGeneratorDatasource.java
@@ -36,7 +36,7 @@ public class TPCDSDataGeneratorDatasource extends 
FunctionDataSource {
 
     public TPCDSDataGeneratorDatasource(INodeDomain domain, String tableName, 
double scalingFactor)
             throws AlgebricksException {
-        super(createDataSourceId(tableName), domain);
+        super(createDataSourceId(tableName, scalingFactor), domain);
         this.tableName = tableName;
         this.scalingFactor = scalingFactor;
     }
@@ -46,13 +46,15 @@ public class TPCDSDataGeneratorDatasource extends 
FunctionDataSource {
      * DataSourceId. This eliminates the issue of creating a single function 
even though multiple functions calls
      * are happening with different parameters and the optimizer understands 
them as a single function.
      *
-     * @param tableName table name to be added as part of the DataSourceId
-     *
+     * @param tableName
+     *            table name to be added as part of the DataSourceId
+     * @param scalingFactor
+     *            scaling factor to be added as part of the DataSourceId
      * @return A DataSourceId that's based on the function details and its 
parameters
      */
-    private static DataSourceId createDataSourceId(String tableName) {
+    private static DataSourceId createDataSourceId(String tableName, double 
scalingFactor) {
         return new 
DataSourceId(TPCDSDataGeneratorRewriter.TPCDS_DATA_GENERATOR.getNamespace(),
-                TPCDSDataGeneratorRewriter.TPCDS_DATA_GENERATOR.getName() + 
"." + tableName);
+                TPCDSDataGeneratorRewriter.TPCDS_DATA_GENERATOR.getName(), 
tableName, Double.toString(scalingFactor));
     }
 
     @Override
diff --git 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/DataSourceId.java
 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/DataSourceId.java
index c96fcd1..d61ae15 100644
--- 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/DataSourceId.java
+++ 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/DataSourceId.java
@@ -19,43 +19,63 @@
 
 package org.apache.asterix.metadata.declared;
 
-import java.util.Objects;
+import java.util.Arrays;
 
 public final class DataSourceId {
 
-    private String dataverseName;
-    private String datasourceName;
+    private String[] components;
 
+    /**
+     * The original constructor taking
+     *
+     * @param dataverseName
+     *            the dataverse (namespace) for this datasource
+     * @param datasourceName
+     *            the name for this datasource
+     */
     public DataSourceId(String dataverseName, String datasourceName) {
-        this.dataverseName = dataverseName;
-        this.datasourceName = datasourceName;
+        this(new String[] { dataverseName, datasourceName });
+    }
+
+    /**
+     * An extended constructor taking an arbitrary number of name components.
+     * This constructor allows the definition of datasources that have the 
same dataverse name and datasource name but
+     * that would expose different behavior. It enables the definition of 
(compile-time) parameterized datasources.
+     * Please note that the first 2 parameters still need to be 1) a dataverse 
name and 2) a datasource name.
+     *
+     * @param components
+     *            name components used to construct the datasource identifier.
+     */
+    public DataSourceId(String... components) {
+        this.components = components;
     }
 
     @Override
     public String toString() {
-        return dataverseName + "." + datasourceName;
+        return String.join(".", components);
     }
 
     public String getDataverseName() {
-        return dataverseName;
+        return components[0];
     }
 
     public String getDatasourceName() {
-        return datasourceName;
+        return components[1];
     }
 
     @Override
     public boolean equals(Object o) {
-        if (this == o)
+        if (this == o) {
             return true;
-        if (o == null || getClass() != o.getClass())
+        }
+        if (o == null || getClass() != o.getClass()) {
             return false;
-        DataSourceId that = (DataSourceId) o;
-        return Objects.equals(dataverseName, that.dataverseName) && 
Objects.equals(datasourceName, that.datasourceName);
+        }
+        return Arrays.equals(components, ((DataSourceId) o).components);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(dataverseName, datasourceName);
+        return Arrays.hashCode(components);
     }
 }

Reply via email to