You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2021/10/06 21:32:23 UTC

[asterixdb] branch master updated: [NO ISSUE][COMP] Add output types to ResultMetadata

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 7147d72  [NO ISSUE][COMP] Add output types to ResultMetadata
7147d72 is described below

commit 7147d725742c5766a16fe9c80cc41c3a489956cc
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Tue Oct 5 12:03:03 2021 -0700

    [NO ISSUE][COMP] Add output types to ResultMetadata
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - Add PopulateResultMetadataRule that saves output types
      in ResultMetadata associated with DistributeResultOperator
    
    Change-Id: I132a61df80021971aa4be63a094795ee7ca789e4
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13545
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 .../asterix/optimizer/base/RuleCollections.java    |  2 +
 .../apache/asterix/api/common/ResultMetadata.java  | 11 ++++
 .../rewriter/rules/PopulateResultMetadataRule.java | 68 ++++++++++++++++++++++
 .../apache/hyracks/api/result/IResultMetadata.java |  5 ++
 4 files changed, 86 insertions(+)

diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
index 4e08d5c..d721c31 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
@@ -121,6 +121,7 @@ import org.apache.hyracks.algebricks.rewriter.rules.IntroJoinInsideSubplanRule;
 import org.apache.hyracks.algebricks.rewriter.rules.IntroduceAggregateCombinerRule;
 import org.apache.hyracks.algebricks.rewriter.rules.IntroduceProjectsRule;
 import org.apache.hyracks.algebricks.rewriter.rules.IsolateHyracksOperatorsRule;
+import org.apache.hyracks.algebricks.rewriter.rules.PopulateResultMetadataRule;
 import org.apache.hyracks.algebricks.rewriter.rules.PullSelectOutOfEqJoin;
 import org.apache.hyracks.algebricks.rewriter.rules.PushGroupByIntoSortRule;
 import org.apache.hyracks.algebricks.rewriter.rules.PushMapOperatorDownThroughProductRule;
@@ -413,6 +414,7 @@ public final class RuleCollections {
         prepareForJobGenRewrites.add(new SetAsterixMemoryRequirementsRule());
         prepareForJobGenRewrites.add(new SweepIllegalNonfunctionalFunctions());
         prepareForJobGenRewrites.add(new FixReplicateOperatorOutputsRule());
+        prepareForJobGenRewrites.add(new PopulateResultMetadataRule());
         return prepareForJobGenRewrites;
     }
 }
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/ResultMetadata.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/ResultMetadata.java
index 35e8daf..94360a1 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/ResultMetadata.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/ResultMetadata.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.api.common;
 
+import java.util.List;
 import java.util.Set;
 
 import org.apache.asterix.translator.SessionConfig;
@@ -36,6 +37,7 @@ public class ResultMetadata implements IResultMetadata {
     private long diskIoCount;
     private Set<Warning> warnings;
     private long totalWarningsCount;
+    private transient List<Object> outputTypes;
 
     public ResultMetadata(SessionConfig.OutputFormat format) {
         this.format = format;
@@ -95,6 +97,15 @@ public class ResultMetadata implements IResultMetadata {
     }
 
     @Override
+    public void setOutputTypes(List<Object> typeList) {
+        this.outputTypes = typeList;
+    }
+
+    public List<Object> getOutputTypes() {
+        return outputTypes;
+    }
+
+    @Override
     public String toString() {
         return "ResultMetadata{" + "format=" + format + ", jobDuration=" + jobDuration + ", processedObjects="
                 + processedObjects + ", diskIoCount=" + diskIoCount + '}';
diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/PopulateResultMetadataRule.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/PopulateResultMetadataRule.java
new file mode 100644
index 0000000..e1b2e5d
--- /dev/null
+++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/PopulateResultMetadataRule.java
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+package org.apache.hyracks.algebricks.rewriter.rules;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
+import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.DistributeResultOperator;
+import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+import org.apache.hyracks.api.result.IResultMetadata;
+
+/**
+ *  Populates {@link DistributeResultOperator}'s {@link IResultMetadata} instance with output type information.
+ */
+public final class PopulateResultMetadataRule implements IAlgebraicRewriteRule {
+
+    @Override
+    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+            throws AlgebricksException {
+        ILogicalOperator op = opRef.getValue();
+        if (op.getOperatorTag() != LogicalOperatorTag.DISTRIBUTE_RESULT) {
+            return false;
+        }
+        DistributeResultOperator dop = (DistributeResultOperator) op;
+        IResultMetadata resultMetadata = dop.getResultMetadata();
+        if (resultMetadata.getOutputTypes() != null) {
+            return false;
+        }
+        List<Mutable<ILogicalExpression>> exprList = dop.getExpressions();
+        List<Object> exprTypeList = new ArrayList<>(exprList.size());
+        IVariableTypeEnvironment typeEnv = context.getOutputTypeEnvironment(dop.getInputs().get(0).getValue());
+        for (Mutable<ILogicalExpression> exprRef : exprList) {
+            exprTypeList.add(typeEnv.getType(exprRef.getValue()));
+        }
+        resultMetadata.setOutputTypes(exprTypeList);
+        return true;
+    }
+
+    @Override
+    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+            throws AlgebricksException {
+        return false;
+    }
+}
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/result/IResultMetadata.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/result/IResultMetadata.java
index 12696af..56dd1a4 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/result/IResultMetadata.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/result/IResultMetadata.java
@@ -19,6 +19,11 @@
 package org.apache.hyracks.api.result;
 
 import java.io.Serializable;
+import java.util.List;
 
 public interface IResultMetadata extends Serializable {
+
+    List<Object> getOutputTypes();
+
+    void setOutputTypes(List<Object> typeInfo);
 }