You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2022/12/02 22:14:59 UTC

Change in asterixdb[master]: [DO NOT MERGE] Flip joins for printted plans

From Wail Alkowaileet <wa...@gmail.com>:

Wail Alkowaileet has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17297 )


Change subject: [DO NOT MERGE] Flip joins for printted plans
......................................................................

[DO NOT MERGE] Flip joins for printted plans

Change-Id: Ib96f6a1b205372f248b4d7ecb84d4169485d3ff3
---
M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/OptimizationConfUtil.java
M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/SqlppCompilationProvider.java
M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java
M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java
M asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
7 files changed, 174 insertions(+), 149 deletions(-)



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

diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/SqlppCompilationProvider.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/SqlppCompilationProvider.java
index 4ad888c..2b4cd63 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/SqlppCompilationProvider.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/SqlppCompilationProvider.java
@@ -75,23 +75,26 @@
 
     @Override
     public Set<String> getCompilerOptions() {
-        return new HashSet<>(Set.of(CompilerProperties.COMPILER_JOINMEMORY_KEY,
-                CompilerProperties.COMPILER_GROUPMEMORY_KEY, CompilerProperties.COMPILER_SORTMEMORY_KEY,
-                CompilerProperties.COMPILER_WINDOWMEMORY_KEY, CompilerProperties.COMPILER_TEXTSEARCHMEMORY_KEY,
-                CompilerProperties.COMPILER_PARALLELISM_KEY, CompilerProperties.COMPILER_SORT_PARALLEL_KEY,
-                CompilerProperties.COMPILER_SORT_SAMPLES_KEY, CompilerProperties.COMPILER_EXTERNALSCANMEMORY_KEY,
-                CompilerProperties.COMPILER_INDEXONLY_KEY, CompilerProperties.COMPILER_INTERNAL_SANITYCHECK_KEY,
-                CompilerProperties.COMPILER_EXTERNAL_FIELD_PUSHDOWN_KEY, CompilerProperties.COMPILER_SUBPLAN_MERGE_KEY,
-                CompilerProperties.COMPILER_SUBPLAN_NESTEDPUSHDOWN_KEY, CompilerProperties.COMPILER_ARRAYINDEX_KEY,
-                CompilerProperties.COMPILER_CBO_KEY, CompilerProperties.COMPILER_CBO_TEST_KEY,
-                CompilerProperties.COMPILER_FORCE_JOIN_ORDER_KEY, CompilerProperties.COMPILER_QUERY_PLAN_SHAPE_KEY,
-                CompilerProperties.COMPILER_MIN_MEMORY_ALLOCATION_KEY, FunctionUtil.IMPORT_PRIVATE_FUNCTIONS,
-                FuzzyUtils.SIM_FUNCTION_PROP_NAME, FuzzyUtils.SIM_THRESHOLD_PROP_NAME,
-                StartFeedStatement.WAIT_FOR_COMPLETION, FeedActivityDetails.FEED_POLICY_NAME,
-                FeedActivityDetails.COLLECT_LOCATIONS, SqlppQueryRewriter.INLINE_WITH_OPTION,
-                SqlppExpressionToPlanTranslator.REWRITE_IN_AS_OR_OPTION, "hash_merge", "output-record-type",
-                DisjunctivePredicateToJoinRule.REWRITE_OR_AS_JOIN_OPTION,
-                SetAsterixPhysicalOperatorsRule.REWRITE_ATTEMPT_BATCH_ASSIGN,
-                EquivalenceClassUtils.REWRITE_INTERNAL_QUERYUID_PK, SqlppQueryRewriter.SQL_COMPAT_OPTION));
+        return new HashSet<>(
+                Set.of(CompilerProperties.COMPILER_JOINMEMORY_KEY, CompilerProperties.COMPILER_GROUPMEMORY_KEY,
+                        CompilerProperties.COMPILER_SORTMEMORY_KEY, CompilerProperties.COMPILER_WINDOWMEMORY_KEY,
+                        CompilerProperties.COMPILER_TEXTSEARCHMEMORY_KEY, CompilerProperties.COMPILER_PARALLELISM_KEY,
+                        CompilerProperties.COMPILER_SORT_PARALLEL_KEY, CompilerProperties.COMPILER_SORT_SAMPLES_KEY,
+                        CompilerProperties.COMPILER_EXTERNALSCANMEMORY_KEY, CompilerProperties.COMPILER_INDEXONLY_KEY,
+                        CompilerProperties.COMPILER_INTERNAL_SANITYCHECK_KEY,
+                        CompilerProperties.COMPILER_EXTERNAL_FIELD_PUSHDOWN_KEY,
+                        CompilerProperties.COMPILER_SUBPLAN_MERGE_KEY,
+                        CompilerProperties.COMPILER_SUBPLAN_NESTEDPUSHDOWN_KEY,
+                        CompilerProperties.COMPILER_ARRAYINDEX_KEY, CompilerProperties.COMPILER_CBO_KEY,
+                        CompilerProperties.COMPILER_CBO_TEST_KEY, CompilerProperties.COMPILER_FORCE_JOIN_ORDER_KEY,
+                        CompilerProperties.COMPILER_QUERY_PLAN_SHAPE_KEY,
+                        CompilerProperties.COMPILER_MIN_MEMORY_ALLOCATION_KEY, CompilerProperties.COMPILER_RIGHTTOLEFT,
+                        FunctionUtil.IMPORT_PRIVATE_FUNCTIONS, FuzzyUtils.SIM_FUNCTION_PROP_NAME,
+                        FuzzyUtils.SIM_THRESHOLD_PROP_NAME, StartFeedStatement.WAIT_FOR_COMPLETION,
+                        FeedActivityDetails.FEED_POLICY_NAME, FeedActivityDetails.COLLECT_LOCATIONS,
+                        SqlppQueryRewriter.INLINE_WITH_OPTION, SqlppExpressionToPlanTranslator.REWRITE_IN_AS_OR_OPTION,
+                        "hash_merge", "output-record-type", DisjunctivePredicateToJoinRule.REWRITE_OR_AS_JOIN_OPTION,
+                        SetAsterixPhysicalOperatorsRule.REWRITE_ATTEMPT_BATCH_ASSIGN,
+                        EquivalenceClassUtils.REWRITE_INTERNAL_QUERYUID_PK, SqlppQueryRewriter.SQL_COMPAT_OPTION));
     }
 }
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
index adcdcb2..2d002a9 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
@@ -18,6 +18,9 @@
  */
 package org.apache.asterix.api.common;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -112,9 +115,6 @@
 import org.apache.hyracks.api.job.resource.IClusterCapacity;
 import org.apache.hyracks.control.common.config.OptionTypes;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectWriter;
-
 /**
  * Provides helper methods for compilation of a query into a JobSpec and submission
  * to Hyracks through the Hyracks client interface.
@@ -197,8 +197,8 @@
         final boolean isExplainOnly = isQuery && query.isExplain();
 
         SessionConfig conf = output.config();
-        if (isQuery && !conf.is(SessionConfig.FORMAT_ONLY_PHYSICAL_OPS)
-                && conf.is(SessionConfig.OOB_REWRITTEN_EXPR_TREE)) {
+        if (isQuery && !conf.is(SessionConfig.FORMAT_ONLY_PHYSICAL_OPS) && conf.is(
+                SessionConfig.OOB_REWRITTEN_EXPR_TREE)) {
             generateRewrittenExpressionTree(query);
         }
 
@@ -210,8 +210,8 @@
         ILogicalPlan plan =
                 isLoad ? t.translateLoad(statement) : t.translate(query, outputDatasetName, statement, resultMetadata);
 
-        if ((isQuery || isLoad) && !conf.is(SessionConfig.FORMAT_ONLY_PHYSICAL_OPS)
-                && conf.is(SessionConfig.OOB_LOGICAL_PLAN)) {
+        if ((isQuery || isLoad) && !conf.is(SessionConfig.FORMAT_ONLY_PHYSICAL_OPS) && conf.is(
+                SessionConfig.OOB_LOGICAL_PLAN)) {
             generateLogicalPlan(plan, output.config().getPlanFormat());
         }
         ICcApplicationContext ccAppContext = metadataProvider.getApplicationContext();
@@ -295,7 +295,7 @@
 
         if (!conf.isGenerateJobSpec()) {
             if (isQuery || isLoad) {
-                generateOptimizedLogicalPlan(plan, output.config().getPlanFormat());
+                generateOptimizedLogicalPlan(plan, physOptConf, output.config().getPlanFormat());
             }
             return null;
         }
@@ -370,14 +370,17 @@
         }
     }
 
-    private IPlanPrettyPrinter getPrettyPrintVisitor(SessionConfig.PlanFormat planFormat) {
-        return planFormat.equals(SessionConfig.PlanFormat.JSON) ? PlanPrettyPrinter.createJsonPlanPrettyPrinter()
-                : PlanPrettyPrinter.createStringPlanPrettyPrinter();
+    private IPlanPrettyPrinter getPrettyPrintVisitor(SessionConfig.PlanFormat planFormat,
+            PhysicalOptimizationConfig config) {
+        return planFormat.equals(SessionConfig.PlanFormat.JSON) ?
+                PlanPrettyPrinter.createJsonPlanPrettyPrinter() :
+                PlanPrettyPrinter.createConfigurable(config);
     }
 
     private byte getStatementCategory(Query query, ICompiledDmlStatement statement) {
-        return statement != null ? statement.getCategory()
-                : query != null ? Statement.Category.QUERY : Statement.Category.DDL;
+        return statement != null ?
+                statement.getCategory() :
+                query != null ? Statement.Category.QUERY : Statement.Category.DDL;
     }
 
     public void executeJobArray(IHyracksClientConnection hcc, JobSpecification[] specs, PrintWriter out)
@@ -492,8 +495,8 @@
     private Map<String, Object> validateConfig(Map<String, Object> config, SourceLocation sourceLoc)
             throws AlgebricksException {
         for (String parameterName : config.keySet()) {
-            if (!configurableParameterNames.contains(parameterName)
-                    && !parameterName.startsWith(PREFIX_INTERNAL_PARAMETERS)) {
+            if (!configurableParameterNames.contains(parameterName) && !parameterName.startsWith(
+                    PREFIX_INTERNAL_PARAMETERS)) {
                 throw AsterixException.create(ErrorCode.COMPILATION_UNSUPPORTED_QUERY_PARAMETER, sourceLoc,
                         parameterName);
             }
@@ -526,9 +529,9 @@
         executionPlans.setOptimizedLogicalPlan(getPrettyPrintVisitor(format).printPlan(plan, log2phys).toString());
     }
 
-    private void generateOptimizedLogicalPlan(ILogicalPlan plan, SessionConfig.PlanFormat format)
-            throws AlgebricksException {
-        executionPlans.setOptimizedLogicalPlan(getPrettyPrintVisitor(format).printPlan(plan).toString());
+    private void generateOptimizedLogicalPlan(ILogicalPlan plan, PhysicalOptimizationConfig config,
+            SessionConfig.PlanFormat format) throws AlgebricksException {
+        executionPlans.setOptimizedLogicalPlan(getPrettyPrintVisitor(format, config).printPlan(plan).toString());
     }
 
     private void generateJob(JobSpecification spec) {
@@ -544,7 +547,8 @@
     public static AlgebricksAbsolutePartitionConstraint getJobLocations(JobSpecification spec,
             INodeJobTracker jobTracker, AlgebricksAbsolutePartitionConstraint clusterLocations) {
         final Set<String> jobParticipatingNodes = jobTracker.getJobParticipatingNodes(spec);
-        return new AlgebricksAbsolutePartitionConstraint(Arrays.stream(clusterLocations.getLocations())
-                .filter(jobParticipatingNodes::contains).toArray(String[]::new));
+        return new AlgebricksAbsolutePartitionConstraint(
+                Arrays.stream(clusterLocations.getLocations()).filter(jobParticipatingNodes::contains)
+                        .toArray(String[]::new));
     }
 }
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java
index 62691a0..23d2b60 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java
@@ -18,6 +18,12 @@
  */
 package org.apache.asterix.common.config;
 
+import org.apache.hyracks.algebricks.core.config.AlgebricksConfig;
+import org.apache.hyracks.api.config.IOption;
+import org.apache.hyracks.api.config.IOptionType;
+import org.apache.hyracks.api.config.Section;
+import org.apache.hyracks.util.StorageUtil;
+
 import static org.apache.hyracks.control.common.config.OptionTypes.BOOLEAN;
 import static org.apache.hyracks.control.common.config.OptionTypes.INTEGER;
 import static org.apache.hyracks.control.common.config.OptionTypes.INTEGER_BYTE_UNIT;
@@ -27,98 +33,54 @@
 import static org.apache.hyracks.util.StorageUtil.StorageUnit.KILOBYTE;
 import static org.apache.hyracks.util.StorageUtil.StorageUnit.MEGABYTE;
 
-import org.apache.hyracks.algebricks.core.config.AlgebricksConfig;
-import org.apache.hyracks.api.config.IOption;
-import org.apache.hyracks.api.config.IOptionType;
-import org.apache.hyracks.api.config.Section;
-import org.apache.hyracks.util.StorageUtil;
-
 public class CompilerProperties extends AbstractProperties {
 
     public enum Option implements IOption {
-        COMPILER_SORTMEMORY(
-                LONG_BYTE_UNIT,
-                StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
-                "The memory budget (in bytes) for a sort operator instance in a partition"),
-        COMPILER_JOINMEMORY(
-                LONG_BYTE_UNIT,
-                StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
-                "The memory budget (in bytes) for a join operator instance in a partition"),
-        COMPILER_GROUPMEMORY(
-                LONG_BYTE_UNIT,
-                StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
-                "The memory budget (in bytes) for a group by operator instance in a partition"),
-        COMPILER_WINDOWMEMORY(
-                LONG_BYTE_UNIT,
-                StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
-                "The memory budget (in bytes) for a window operator instance in a partition"),
-        COMPILER_TEXTSEARCHMEMORY(
-                LONG_BYTE_UNIT,
-                StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
-                "The memory budget (in bytes) for an inverted-index-search operator instance in a partition"),
-        COMPILER_EXTERNALSCANMEMORY(
-                INTEGER_BYTE_UNIT,
-                StorageUtil.getIntSizeInBytes(8, KILOBYTE),
-                "The memory budget (in bytes) for an external scan operator instance in a partition"),
-        COMPILER_FRAMESIZE(
-                INTEGER_BYTE_UNIT,
-                StorageUtil.getIntSizeInBytes(32, KILOBYTE),
-                "The page size (in bytes) for computation"),
-        COMPILER_PARALLELISM(
-                INTEGER,
-                COMPILER_PARALLELISM_AS_STORAGE,
-                "The degree of parallelism for query "
-                        + "execution. Zero means to use the storage parallelism as the query execution parallelism, while "
-                        + "other integer values dictate the number of query execution parallel partitions. The system will "
-                        + "fall back to use the number of all available CPU cores in the cluster as the degree of parallelism "
-                        + "if the number set by a user is too large or too small"),
-        COMPILER_SORT_PARALLEL(
-                BOOLEAN,
-                AlgebricksConfig.SORT_PARALLEL_DEFAULT,
-                "Enabling/Disabling full parallel sort"),
-        COMPILER_SORT_SAMPLES(
-                POSITIVE_INTEGER,
-                AlgebricksConfig.SORT_SAMPLES_DEFAULT,
-                "The number of samples which parallel sorting should take from each partition"),
-        COMPILER_INDEXONLY(BOOLEAN, AlgebricksConfig.INDEX_ONLY_DEFAULT, "Enabling/disabling index-only plans"),
-        COMPILER_INTERNAL_SANITYCHECK(
-                BOOLEAN,
+        COMPILER_SORTMEMORY(LONG_BYTE_UNIT, StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
+                "The memory budget (in bytes) for a sort operator instance in a partition"), COMPILER_JOINMEMORY(
+                LONG_BYTE_UNIT, StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
+                "The memory budget (in bytes) for a join operator instance in a partition"), COMPILER_GROUPMEMORY(
+                LONG_BYTE_UNIT, StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
+                "The memory budget (in bytes) for a group by operator instance in a partition"), COMPILER_WINDOWMEMORY(
+                LONG_BYTE_UNIT, StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
+                "The memory budget (in bytes) for a window operator instance in a partition"), COMPILER_TEXTSEARCHMEMORY(
+                LONG_BYTE_UNIT, StorageUtil.getLongSizeInBytes(32L, MEGABYTE),
+                "The memory budget (in bytes) for an inverted-index-search operator instance in a partition"), COMPILER_EXTERNALSCANMEMORY(
+                INTEGER_BYTE_UNIT, StorageUtil.getIntSizeInBytes(8, KILOBYTE),
+                "The memory budget (in bytes) for an external scan operator instance in a partition"), COMPILER_FRAMESIZE(
+                INTEGER_BYTE_UNIT, StorageUtil.getIntSizeInBytes(32, KILOBYTE),
+                "The page size (in bytes) for computation"), COMPILER_PARALLELISM(INTEGER,
+                COMPILER_PARALLELISM_AS_STORAGE, "The degree of parallelism for query "
+                + "execution. Zero means to use the storage parallelism as the query execution parallelism, while "
+                + "other integer values dictate the number of query execution parallel partitions. The system will "
+                + "fall back to use the number of all available CPU cores in the cluster as the degree of parallelism "
+                + "if the number set by a user is too large or too small"), COMPILER_SORT_PARALLEL(BOOLEAN,
+                AlgebricksConfig.SORT_PARALLEL_DEFAULT, "Enabling/Disabling full parallel sort"), COMPILER_SORT_SAMPLES(
+                POSITIVE_INTEGER, AlgebricksConfig.SORT_SAMPLES_DEFAULT,
+                "The number of samples which parallel sorting should take from each partition"), COMPILER_INDEXONLY(
+                BOOLEAN, AlgebricksConfig.INDEX_ONLY_DEFAULT,
+                "Enabling/disabling index-only plans"), COMPILER_INTERNAL_SANITYCHECK(BOOLEAN,
                 AlgebricksConfig.SANITYCHECK_DEFAULT,
-                "Enable/disable compiler sanity check"),
-        COMPILER_EXTERNAL_FIELD_PUSHDOWN(
-                BOOLEAN,
+                "Enable/disable compiler sanity check"), COMPILER_EXTERNAL_FIELD_PUSHDOWN(BOOLEAN,
                 AlgebricksConfig.EXTERNAL_FIELD_PUSHDOWN_DEFAULT,
-                "Enable pushdown of field accesses to the external data-scan operator"),
-        COMPILER_SUBPLAN_MERGE(
-                BOOLEAN,
+                "Enable pushdown of field accesses to the external data-scan operator"), COMPILER_SUBPLAN_MERGE(BOOLEAN,
                 AlgebricksConfig.SUBPLAN_MERGE_DEFAULT,
-                "Enable merging subplans with other subplans"),
-        COMPILER_SUBPLAN_NESTEDPUSHDOWN(
-                BOOLEAN,
+                "Enable merging subplans with other subplans"), COMPILER_SUBPLAN_NESTEDPUSHDOWN(BOOLEAN,
                 AlgebricksConfig.SUBPLAN_NESTEDPUSHDOWN_DEFAULT,
-                "When merging subplans into groupby/suplan allow nesting of subplans"),
-        COMPILER_MIN_MEMORY_ALLOCATION(
-                BOOLEAN,
-                AlgebricksConfig.MIN_MEMORY_ALLOCATION_DEFAULT,
-                "Enable/disable allocating minimum budget for certain queries"),
-        COMPILER_ARRAYINDEX(
-                BOOLEAN,
+                "When merging subplans into groupby/suplan allow nesting of subplans"), COMPILER_MIN_MEMORY_ALLOCATION(
+                BOOLEAN, AlgebricksConfig.MIN_MEMORY_ALLOCATION_DEFAULT,
+                "Enable/disable allocating minimum budget for certain queries"), COMPILER_ARRAYINDEX(BOOLEAN,
                 AlgebricksConfig.ARRAY_INDEX_DEFAULT,
-                "Enable/disable using array-indexes in queries"),
-        COMPILER_BATCH_LOOKUP(
-                BOOLEAN,
+                "Enable/disable using array-indexes in queries"), COMPILER_BATCH_LOOKUP(BOOLEAN,
                 AlgebricksConfig.BATCH_LOOKUP_DEFAULT,
-                "Enable/disable batch point-lookups when running queries with secondary indexes"),
-        COMPILER_CBO(BOOLEAN, AlgebricksConfig.CBO_DEFAULT, "Set the mode for cost based optimization"),
-        COMPILER_CBOTEST(BOOLEAN, AlgebricksConfig.CBO_TEST_DEFAULT, "Set the mode for cost based optimization"),
-        COMPILER_FORCEJOINORDER(
-                BOOLEAN,
-                AlgebricksConfig.FORCE_JOIN_ORDER_DEFAULT,
-                "Set the mode for forcing the join order in a query plan"),
-        COMPILER_QUERYPLANSHAPE(
-                STRING,
+                "Enable/disable batch point-lookups when running queries with secondary indexes"), COMPILER_CBO(BOOLEAN,
+                AlgebricksConfig.CBO_DEFAULT, "Set the mode for cost based optimization"), COMPILER_CBOTEST(BOOLEAN,
+                AlgebricksConfig.CBO_TEST_DEFAULT, "Set the mode for cost based optimization"), COMPILER_FORCEJOINORDER(
+                BOOLEAN, AlgebricksConfig.FORCE_JOIN_ORDER_DEFAULT,
+                "Set the mode for forcing the join order in a query plan"), COMPILER_QUERYPLANSHAPE(STRING,
                 AlgebricksConfig.QUERY_PLAN_SHAPE_DEFAULT,
-                "Set the mode for forcing the shape of the query plan");
+                "Set the mode for forcing the shape of the query plan"), COMPILER_RIGHTTOLEFT(BOOLEAN, false,
+                "Rerender join rightToLeft");
 
         private final IOptionType type;
         private final Object defaultValue;
@@ -198,6 +160,8 @@
 
     public static final String COMPILER_QUERY_PLAN_SHAPE_KEY = Option.COMPILER_QUERYPLANSHAPE.ini();
 
+    public static final String COMPILER_RIGHTTOLEFT = Option.COMPILER_RIGHTTOLEFT.ini();
+
     public static final int COMPILER_PARALLELISM_AS_STORAGE = 0;
 
     public CompilerProperties(PropertiesAccessor accessor) {
@@ -288,11 +252,15 @@
         return accessor.getBoolean(Option.COMPILER_FORCEJOINORDER);
     }
 
+    public boolean isRightToLeft() {
+        return accessor.getBoolean(Option.COMPILER_RIGHTTOLEFT);
+    }
+
     public String getQueryPlanShapeMode() {
         String queryPlanShapeMode = accessor.getString(Option.COMPILER_QUERYPLANSHAPE);
-        if (!(queryPlanShapeMode.equals(AlgebricksConfig.QUERY_PLAN_SHAPE_ZIGZAG)
-                || queryPlanShapeMode.equals(AlgebricksConfig.QUERY_PLAN_SHAPE_LEFTDEEP)
-                || queryPlanShapeMode.equals(AlgebricksConfig.QUERY_PLAN_SHAPE_RIGHTDEEP)))
+        if (!(queryPlanShapeMode.equals(AlgebricksConfig.QUERY_PLAN_SHAPE_ZIGZAG) || queryPlanShapeMode.equals(
+                AlgebricksConfig.QUERY_PLAN_SHAPE_LEFTDEEP) || queryPlanShapeMode.equals(
+                AlgebricksConfig.QUERY_PLAN_SHAPE_RIGHTDEEP)))
             return AlgebricksConfig.QUERY_PLAN_SHAPE_DEFAULT;
         return queryPlanShapeMode;
     }
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/OptimizationConfUtil.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/OptimizationConfUtil.java
index e1edc1c..dd6c6b6 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/OptimizationConfUtil.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/OptimizationConfUtil.java
@@ -64,14 +64,17 @@
                 compilerProperties.isIndexOnly());
         boolean sanityCheck = getBoolean(querySpecificConfig, CompilerProperties.COMPILER_INTERNAL_SANITYCHECK_KEY,
                 compilerProperties.isSanityCheck());
-        boolean externalFieldPushdown = getBoolean(querySpecificConfig,
-                CompilerProperties.COMPILER_EXTERNAL_FIELD_PUSHDOWN_KEY, compilerProperties.isFieldAccessPushdown());
+        boolean externalFieldPushdown =
+                getBoolean(querySpecificConfig, CompilerProperties.COMPILER_EXTERNAL_FIELD_PUSHDOWN_KEY,
+                        compilerProperties.isFieldAccessPushdown());
         boolean subplanMerge = getBoolean(querySpecificConfig, CompilerProperties.COMPILER_SUBPLAN_MERGE_KEY,
                 compilerProperties.getSubplanMerge());
-        boolean subplanNestedPushdown = getBoolean(querySpecificConfig,
-                CompilerProperties.COMPILER_SUBPLAN_NESTEDPUSHDOWN_KEY, compilerProperties.getSubplanNestedPushdown());
-        boolean minMemoryAllocation = getBoolean(querySpecificConfig,
-                CompilerProperties.COMPILER_MIN_MEMORY_ALLOCATION_KEY, compilerProperties.getMinMemoryAllocation());
+        boolean subplanNestedPushdown =
+                getBoolean(querySpecificConfig, CompilerProperties.COMPILER_SUBPLAN_NESTEDPUSHDOWN_KEY,
+                        compilerProperties.getSubplanNestedPushdown());
+        boolean minMemoryAllocation =
+                getBoolean(querySpecificConfig, CompilerProperties.COMPILER_MIN_MEMORY_ALLOCATION_KEY,
+                        compilerProperties.getMinMemoryAllocation());
         boolean arrayIndex = getBoolean(querySpecificConfig, CompilerProperties.COMPILER_ARRAYINDEX_KEY,
                 compilerProperties.isArrayIndex());
         int externalScanBufferSize = getExternalScanBufferSize(
@@ -87,6 +90,8 @@
                 compilerProperties.getForceJoinOrderMode());
         String queryPlanShape = getString(querySpecificConfig, CompilerProperties.COMPILER_QUERY_PLAN_SHAPE_KEY,
                 compilerProperties.getQueryPlanShapeMode());
+        boolean rightToLeft = getBoolean(querySpecificConfig, CompilerProperties.COMPILER_RIGHTTOLEFT,
+                compilerProperties.isRightToLeft());
 
         PhysicalOptimizationConfig physOptConf = new PhysicalOptimizationConfig();
         physOptConf.setFrameSize(frameSize);
@@ -110,6 +115,7 @@
         physOptConf.setCBOTestMode(cboTest);
         physOptConf.setForceJoinOrderMode(forceJoinOrder);
         physOptConf.setQueryPlanShapeMode(queryPlanShape);
+        physOptConf.setRightToLeft(rightToLeft);
         return physOptConf;
     }
 
@@ -117,8 +123,9 @@
             int compilerExternalScanMemorySize, SourceLocation sourceLoc) throws AsterixException {
         IOptionType<Integer> intByteParser = OptionTypes.INTEGER_BYTE_UNIT;
         try {
-            return externalScanMemorySizeParameter != null ? intByteParser.parse(externalScanMemorySizeParameter)
-                    : compilerExternalScanMemorySize;
+            return externalScanMemorySizeParameter != null ?
+                    intByteParser.parse(externalScanMemorySizeParameter) :
+                    compilerExternalScanMemorySize;
         } catch (IllegalArgumentException e) {
             throw AsterixException.create(ErrorCode.COMPILATION_ERROR, sourceLoc, e.getMessage());
         }
@@ -172,8 +179,9 @@
             SourceLocation sourceLoc) throws AsterixException {
         String valueInQuery = (String) querySpecificConfig.get(CompilerProperties.COMPILER_SORT_SAMPLES_KEY);
         try {
-            return valueInQuery == null ? compilerProperties.getSortSamples()
-                    : OptionTypes.POSITIVE_INTEGER.parse(valueInQuery);
+            return valueInQuery == null ?
+                    compilerProperties.getSortSamples() :
+                    OptionTypes.POSITIVE_INTEGER.parse(valueInQuery);
         } catch (IllegalArgumentException e) {
             throw AsterixException.create(ErrorCode.COMPILATION_BAD_QUERY_PARAMETER_VALUE, sourceLoc,
                     CompilerProperties.COMPILER_SORT_SAMPLES_KEY, 1, "samples");
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
index 430ca1c..c3c7b76 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/LogicalOperatorPrettyPrintVisitor.java
@@ -18,11 +18,12 @@
  */
 package org.apache.hyracks.algebricks.core.algebra.prettyprint;
 
+import org.apache.commons.lang3.mutable.Mutable;
+
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.common.utils.Triple;
@@ -30,7 +31,9 @@
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
 import org.apache.hyracks.algebricks.core.algebra.base.IPhysicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
 import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
+import org.apache.hyracks.algebricks.core.algebra.base.PhysicalOperatorTag;
 import org.apache.hyracks.algebricks.core.algebra.expressions.IAlgebricksConstantValue;
 import org.apache.hyracks.algebricks.core.algebra.metadata.IProjectionInfo;
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
@@ -79,9 +82,15 @@
 
     private static final int INIT_INDENT = 2;
     private static final int SUBPLAN_INDENT = INIT_INDENT * 5;
+    private final boolean rightToLeft;
 
     LogicalOperatorPrettyPrintVisitor() {
+        this(false);
+    }
+
+    LogicalOperatorPrettyPrintVisitor(boolean rightToLeft) {
         super(new LogicalExpressionPrettyPrintVisitor<>());
+        this.rightToLeft = rightToLeft;
     }
 
     @Override
@@ -131,8 +140,17 @@
         }
 
         if (printInputs) {
-            for (Mutable<ILogicalOperator> i : op.getInputs()) {
-                printOperatorImpl((AbstractLogicalOperator) i.getValue(), indent + INIT_INDENT, printInputs);
+            if (rightToLeft && op.getOperatorTag() == LogicalOperatorTag.INNERJOIN
+                    && pOp.getOperatorTag() == PhysicalOperatorTag.HYBRID_HASH_JOIN) {
+                AbstractLogicalOperator left = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
+                AbstractLogicalOperator right = (AbstractLogicalOperator) op.getInputs().get(1).getValue();
+
+                printOperatorImpl(right, indent + INIT_INDENT, printInputs);
+                printOperatorImpl(left, indent + INIT_INDENT, printInputs);
+            } else {
+                for (Mutable<ILogicalOperator> i : op.getInputs()) {
+                    printOperatorImpl((AbstractLogicalOperator) i.getValue(), indent + INIT_INDENT, printInputs);
+                }
             }
         }
     }
@@ -255,9 +273,9 @@
 
     @Override
     public Void visitSelectOperator(SelectOperator op, Integer indent) throws AlgebricksException {
-        String retainMissing = op.getMissingPlaceholderVariable() != null
-                ? " retain-untrue (" + op.getMissingPlaceholderVariable() + " <- " + op.getRetainMissingAsValue() + ")"
-                : "";
+        String retainMissing = op.getMissingPlaceholderVariable() != null ?
+                " retain-untrue (" + op.getMissingPlaceholderVariable() + " <- " + op.getRetainMissingAsValue() + ")" :
+                "";
         addIndent(indent).append("select (").append(op.getCondition().getValue().accept(exprVisitor, indent))
                 .append(")").append(retainMissing);
         return null;
@@ -348,8 +366,8 @@
             String opSignature, IAlgebricksConstantValue leftOuterMissingValue) throws AlgebricksException {
         AlgebricksStringBuilderWriter plan =
                 addIndent(indent).append(opSignature).append(' ').append(String.valueOf(op.getVariables()))
-                        .append(" <- ").append(op.getExpressionRef().getValue().accept(exprVisitor, indent)).append(
-                                leftOuterMissingValue != null ? printLeftOuterMissingValue(leftOuterMissingValue) : "");
+                        .append(" <- ").append(op.getExpressionRef().getValue().accept(exprVisitor, indent))
+                        .append(leftOuterMissingValue != null ? printLeftOuterMissingValue(leftOuterMissingValue) : "");
         appendFilterInformation(plan, op.getMinFilterVars(), op.getMaxFilterVars());
         return plan;
     }
@@ -457,10 +475,10 @@
         buffer.append(" partitioned by ");
         pprintExprList(op.getPrimaryKeyExpressions(), indent);
         if (op.getOperation() == Kind.UPSERT) {
-            buffer.append(" out: ([record-before-upsert:" + op.getBeforeOpRecordVar()
-                    + ((op.getBeforeOpAdditionalNonFilteringVars() != null)
-                            ? (", additional-before-upsert: " + op.getBeforeOpAdditionalNonFilteringVars()) : "")
-                    + "]) ");
+            buffer.append(" out: ([record-before-upsert:" + op.getBeforeOpRecordVar() + ((
+                    op.getBeforeOpAdditionalNonFilteringVars() != null) ?
+                    (", additional-before-upsert: " + op.getBeforeOpAdditionalNonFilteringVars()) :
+                    "") + "]) ");
         }
         if (op.isBulkload()) {
             buffer.append(" [bulkload]");
@@ -673,7 +691,8 @@
 
     private void pprintOrderList(List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> orderList,
             Integer indent) throws AlgebricksException {
-        for (Iterator<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> i = orderList.iterator(); i.hasNext();) {
+        for (Iterator<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> i =
+             orderList.iterator(); i.hasNext(); ) {
             Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p = i.next();
             String fst = getOrderString(p.first);
             buffer.append("(" + fst + ", " + p.second.getValue().accept(exprVisitor, indent) + ")");
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
index 5874c4c..1415e56 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/prettyprint/PlanPrettyPrinter.java
@@ -20,6 +20,7 @@
 
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
+import org.apache.hyracks.algebricks.core.rewriter.base.PhysicalOptimizationConfig;
 
 public class PlanPrettyPrinter {
 
@@ -33,6 +34,10 @@
         return new LogicalOperatorPrettyPrintVisitor();
     }
 
+    public static IPlanPrettyPrinter createConfigurable(PhysicalOptimizationConfig config) {
+        return new LogicalOperatorPrettyPrintVisitor(config.getRightToLeft());
+    }
+
     public static void printPhysicalOps(ILogicalPlan plan, AlgebricksStringBuilderWriter out, int indent,
             boolean verbose) throws AlgebricksException {
         AbstractLogicalOperatorPrettyPrintVisitor.printPhysicalOps(plan, out, indent, verbose);
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java
index 86be6d0..7bebc6b 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java
@@ -52,6 +52,7 @@
     private static final String CBO_TEST = "CBO_TEST";
     private static final String FORCE_JOIN_ORDER = "FORCE_JOIN_ORDER";
     private static final String QUERY_PLAN_SHAPE = "QUERY_PLAN_SHAPE";
+    private static final String RIGHT_TO_LEFT = "RIGHT_TO_LEFT";
 
     private final Properties properties = new Properties();
 
@@ -258,9 +259,9 @@
 
     public String getQueryPlanShapeMode() {
         String queryPlanShapeMode = getString(QUERY_PLAN_SHAPE, AlgebricksConfig.QUERY_PLAN_SHAPE_DEFAULT);
-        if (!(queryPlanShapeMode.equals(AlgebricksConfig.QUERY_PLAN_SHAPE_ZIGZAG)
-                || queryPlanShapeMode.equals(AlgebricksConfig.QUERY_PLAN_SHAPE_LEFTDEEP)
-                || queryPlanShapeMode.equals(AlgebricksConfig.QUERY_PLAN_SHAPE_RIGHTDEEP))) {
+        if (!(queryPlanShapeMode.equals(AlgebricksConfig.QUERY_PLAN_SHAPE_ZIGZAG) || queryPlanShapeMode.equals(
+                AlgebricksConfig.QUERY_PLAN_SHAPE_LEFTDEEP) || queryPlanShapeMode.equals(
+                AlgebricksConfig.QUERY_PLAN_SHAPE_RIGHTDEEP))) {
             return AlgebricksConfig.QUERY_PLAN_SHAPE_DEFAULT;
         }
         return queryPlanShapeMode;
@@ -294,6 +295,14 @@
         setInt(EXTERNAL_SCAN_BUFFER_SIZE, bufferSize);
     }
 
+    public void setRightToLeft(boolean rightToLeft) {
+        setBoolean(RIGHT_TO_LEFT, rightToLeft);
+    }
+
+    public boolean getRightToLeft() {
+        return getBoolean(RIGHT_TO_LEFT, false);
+    }
+
     private void setInt(String property, int value) {
         properties.setProperty(property, Integer.toString(value));
     }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17297
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: Ib96f6a1b205372f248b4d7ecb84d4169485d3ff3
Gerrit-Change-Number: 17297
Gerrit-PatchSet: 1
Gerrit-Owner: Wail Alkowaileet <wa...@gmail.com>
Gerrit-MessageType: newchange