Search in sources :

Example 26 with IAlgebraicRewriteRule

use of org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule in project asterixdb by apache.

the class RuleCollections method buildNormalizationRuleCollection.

public static final List<IAlgebraicRewriteRule> buildNormalizationRuleCollection(ICcApplicationContext appCtx) {
    List<IAlgebraicRewriteRule> normalization = new LinkedList<>();
    normalization.add(new ResolveVariableRule());
    normalization.add(new CheckInsertUpsertReturningRule());
    normalization.add(new IntroduceUnnestForCollectionToSequenceRule());
    normalization.add(new EliminateSubplanRule());
    normalization.add(new EnforceOrderByAfterSubplan());
    normalization.add(new BreakSelectIntoConjunctsRule());
    normalization.add(new ExtractGbyExpressionsRule());
    normalization.add(new ExtractDistinctByExpressionsRule());
    normalization.add(new ExtractOrderExpressionsRule());
    // IntroduceStaticTypeCastRule should go before
    // IntroduceDynamicTypeCastRule to
    // avoid unnecessary dynamic casting
    normalization.add(new IntroduceStaticTypeCastForInsertRule());
    normalization.add(new IntroduceDynamicTypeCastRule());
    normalization.add(new IntroduceDynamicTypeCastForExternalFunctionRule());
    normalization.add(new IntroduceEnforcedListTypeRule());
    normalization.add(new ExtractCommonExpressionsRule());
    // Let PushAggFuncIntoStandaloneAggregateRule run after ExtractCommonExpressionsRule
    // so that PushAggFunc can happen in fewer places.
    normalization.add(new PushAggFuncIntoStandaloneAggregateRule());
    normalization.add(new ListifyUnnestingFunctionRule());
    normalization.add(new ConstantFoldingRule(appCtx));
    normalization.add(new RemoveRedundantSelectRule());
    normalization.add(new UnnestToDataScanRule());
    normalization.add(new MetaFunctionToMetaVariableRule());
    normalization.add(new FuzzyEqRule());
    normalization.add(new SimilarityCheckRule());
    return normalization;
}
Also used : IntroduceDynamicTypeCastRule(org.apache.asterix.optimizer.rules.IntroduceDynamicTypeCastRule) EnforceOrderByAfterSubplan(org.apache.hyracks.algebricks.rewriter.rules.EnforceOrderByAfterSubplan) IntroduceEnforcedListTypeRule(org.apache.asterix.optimizer.rules.IntroduceEnforcedListTypeRule) ExtractGbyExpressionsRule(org.apache.hyracks.algebricks.rewriter.rules.ExtractGbyExpressionsRule) ExtractOrderExpressionsRule(org.apache.asterix.optimizer.rules.ExtractOrderExpressionsRule) IntroduceDynamicTypeCastForExternalFunctionRule(org.apache.asterix.optimizer.rules.IntroduceDynamicTypeCastForExternalFunctionRule) IntroduceUnnestForCollectionToSequenceRule(org.apache.asterix.optimizer.rules.IntroduceUnnestForCollectionToSequenceRule) ExtractDistinctByExpressionsRule(org.apache.asterix.optimizer.rules.ExtractDistinctByExpressionsRule) IAlgebraicRewriteRule(org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule) IntroduceStaticTypeCastForInsertRule(org.apache.asterix.optimizer.rules.IntroduceStaticTypeCastForInsertRule) ListifyUnnestingFunctionRule(org.apache.asterix.optimizer.rules.ListifyUnnestingFunctionRule) FuzzyEqRule(org.apache.asterix.optimizer.rules.FuzzyEqRule) ExtractCommonExpressionsRule(org.apache.hyracks.algebricks.rewriter.rules.ExtractCommonExpressionsRule) LinkedList(java.util.LinkedList) UnnestToDataScanRule(org.apache.asterix.optimizer.rules.UnnestToDataScanRule) EliminateSubplanRule(org.apache.hyracks.algebricks.rewriter.rules.subplan.EliminateSubplanRule) ConstantFoldingRule(org.apache.asterix.optimizer.rules.ConstantFoldingRule) SimilarityCheckRule(org.apache.asterix.optimizer.rules.SimilarityCheckRule) BreakSelectIntoConjunctsRule(org.apache.hyracks.algebricks.rewriter.rules.BreakSelectIntoConjunctsRule) RemoveRedundantSelectRule(org.apache.asterix.optimizer.rules.RemoveRedundantSelectRule) MetaFunctionToMetaVariableRule(org.apache.asterix.optimizer.rules.MetaFunctionToMetaVariableRule) ResolveVariableRule(org.apache.asterix.optimizer.rules.ResolveVariableRule) PushAggFuncIntoStandaloneAggregateRule(org.apache.asterix.optimizer.rules.PushAggFuncIntoStandaloneAggregateRule) CheckInsertUpsertReturningRule(org.apache.asterix.optimizer.rules.CheckInsertUpsertReturningRule)

Example 27 with IAlgebraicRewriteRule

use of org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule in project asterixdb by apache.

the class RuleCollections method buildFuzzyJoinRuleCollection.

public static final List<IAlgebraicRewriteRule> buildFuzzyJoinRuleCollection() {
    List<IAlgebraicRewriteRule> fuzzy = new LinkedList<>();
    // fuzzy.add(new FuzzyJoinRule()); -- The non-indexed fuzzy join will be temporarily disabled. It should be enabled some time in the near future.
    fuzzy.add(new InferTypesRule());
    return fuzzy;
}
Also used : InferTypesRule(org.apache.hyracks.algebricks.rewriter.rules.InferTypesRule) IAlgebraicRewriteRule(org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule) LinkedList(java.util.LinkedList)

Example 28 with IAlgebraicRewriteRule

use of org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule in project asterixdb by apache.

the class RuleCollections method buildLoadFieldsRuleCollection.

public static final List<IAlgebraicRewriteRule> buildLoadFieldsRuleCollection(ICcApplicationContext appCtx) {
    List<IAlgebraicRewriteRule> fieldLoads = new LinkedList<>();
    fieldLoads.add(new LoadRecordFieldsRule());
    fieldLoads.add(new PushFieldAccessRule());
    // fieldLoads.add(new ByNameToByHandleFieldAccessRule()); -- disabled
    fieldLoads.add(new ByNameToByIndexFieldAccessRule());
    fieldLoads.add(new RemoveRedundantVariablesRule());
    fieldLoads.add(new AsterixInlineVariablesRule());
    fieldLoads.add(new RemoveUnusedAssignAndAggregateRule());
    fieldLoads.add(new ConstantFoldingRule(appCtx));
    fieldLoads.add(new RemoveRedundantSelectRule());
    fieldLoads.add(new FeedScanCollectionToUnnest());
    fieldLoads.add(new NestedSubplanToJoinRule());
    fieldLoads.add(new InlineSubplanInputForNestedTupleSourceRule());
    fieldLoads.add(new RemoveLeftOuterUnnestForLeftOuterJoinRule());
    return fieldLoads;
}
Also used : ByNameToByIndexFieldAccessRule(org.apache.asterix.optimizer.rules.ByNameToByIndexFieldAccessRule) NestedSubplanToJoinRule(org.apache.hyracks.algebricks.rewriter.rules.subplan.NestedSubplanToJoinRule) AsterixInlineVariablesRule(org.apache.asterix.optimizer.rules.AsterixInlineVariablesRule) PushFieldAccessRule(org.apache.asterix.optimizer.rules.PushFieldAccessRule) FeedScanCollectionToUnnest(org.apache.asterix.optimizer.rules.FeedScanCollectionToUnnest) LinkedList(java.util.LinkedList) LoadRecordFieldsRule(org.apache.asterix.optimizer.rules.LoadRecordFieldsRule) ConstantFoldingRule(org.apache.asterix.optimizer.rules.ConstantFoldingRule) InlineSubplanInputForNestedTupleSourceRule(org.apache.asterix.optimizer.rules.subplan.InlineSubplanInputForNestedTupleSourceRule) IAlgebraicRewriteRule(org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule) RemoveRedundantSelectRule(org.apache.asterix.optimizer.rules.RemoveRedundantSelectRule) RemoveLeftOuterUnnestForLeftOuterJoinRule(org.apache.asterix.optimizer.rules.RemoveLeftOuterUnnestForLeftOuterJoinRule) RemoveRedundantVariablesRule(org.apache.hyracks.algebricks.rewriter.rules.RemoveRedundantVariablesRule) RemoveUnusedAssignAndAggregateRule(org.apache.hyracks.algebricks.rewriter.rules.RemoveUnusedAssignAndAggregateRule)

Example 29 with IAlgebraicRewriteRule

use of org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule in project asterixdb by apache.

the class RuleCollections method buildPhysicalRewritesTopLevelRuleCollection.

public static final List<IAlgebraicRewriteRule> buildPhysicalRewritesTopLevelRuleCollection(ICcApplicationContext appCtx) {
    List<IAlgebraicRewriteRule> physicalRewritesTopLevel = new LinkedList<>();
    physicalRewritesTopLevel.add(new PushNestedOrderByUnderPreSortedGroupByRule());
    physicalRewritesTopLevel.add(new CopyLimitDownRule());
    // CopyLimitDownRule may generates non-topmost limits with numeric_adds functions.
    // We are going to apply a constant folding rule again for this case.
    physicalRewritesTopLevel.add(new ConstantFoldingRule(appCtx));
    physicalRewritesTopLevel.add(new PushLimitIntoOrderByRule());
    physicalRewritesTopLevel.add(new IntroduceProjectsRule());
    physicalRewritesTopLevel.add(new SetAlgebricksPhysicalOperatorsRule());
    physicalRewritesTopLevel.add(new IntroduceRapidFrameFlushProjectAssignRule());
    physicalRewritesTopLevel.add(new SetExecutionModeRule());
    physicalRewritesTopLevel.add(new IntroduceRandomPartitioningFeedComputationRule());
    return physicalRewritesTopLevel;
}
Also used : PushNestedOrderByUnderPreSortedGroupByRule(org.apache.hyracks.algebricks.rewriter.rules.PushNestedOrderByUnderPreSortedGroupByRule) ConstantFoldingRule(org.apache.asterix.optimizer.rules.ConstantFoldingRule) CopyLimitDownRule(org.apache.hyracks.algebricks.rewriter.rules.CopyLimitDownRule) PushLimitIntoOrderByRule(org.apache.asterix.optimizer.rules.PushLimitIntoOrderByRule) IntroduceRandomPartitioningFeedComputationRule(org.apache.asterix.optimizer.rules.IntroduceRandomPartitioningFeedComputationRule) SetExecutionModeRule(org.apache.hyracks.algebricks.rewriter.rules.SetExecutionModeRule) IAlgebraicRewriteRule(org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule) IntroduceProjectsRule(org.apache.hyracks.algebricks.rewriter.rules.IntroduceProjectsRule) LinkedList(java.util.LinkedList) SetAlgebricksPhysicalOperatorsRule(org.apache.hyracks.algebricks.rewriter.rules.SetAlgebricksPhysicalOperatorsRule) IntroduceRapidFrameFlushProjectAssignRule(org.apache.asterix.optimizer.rules.IntroduceRapidFrameFlushProjectAssignRule)

Example 30 with IAlgebraicRewriteRule

use of org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule in project asterixdb by apache.

the class SequentialFirstRuleCheckFixpointRuleControllerTest method testRewriteWithRuleCollection.

@Test
public void testRewriteWithRuleCollection() throws Exception {
    SequentialFirstRuleCheckFixpointRuleController ruleController = new SequentialFirstRuleCheckFixpointRuleController(true);
    // Specifies three rules - R1, R2, and R3.
    IAlgebraicRewriteRule firstRule = mock(IAlgebraicRewriteRule.class);
    IAlgebraicRewriteRule secondRule = mock(IAlgebraicRewriteRule.class);
    IAlgebraicRewriteRule thirdRule = mock(IAlgebraicRewriteRule.class);
    List<IAlgebraicRewriteRule> ruleList = new LinkedList<>();
    ruleList.add(firstRule);
    ruleList.add(secondRule);
    ruleList.add(thirdRule);
    @SuppressWarnings("unchecked") Mutable<ILogicalOperator> root = PowerMockito.mock(Mutable.class);
    AbstractLogicalOperator rootOp = PowerMockito.mock(AbstractLogicalOperator.class);
    List<Mutable<ILogicalOperator>> emptyList = new ArrayList<>();
    PowerMockito.when(root.getValue()).thenReturn(rootOp);
    PowerMockito.when(rootOp.getInputs()).thenReturn(emptyList);
    // Case 1: the first rule returns true in the first iteration.
    //  Iteration1: R1 true, R2 false, R3 false
    //  Iteration2: R1 false, R2 false, R3 false
    PowerMockito.when(firstRule.rewritePre(any(), any())).thenReturn(true).thenReturn(false);
    PowerMockito.when(secondRule.rewritePre(any(), any())).thenReturn(false);
    PowerMockito.when(thirdRule.rewritePre(any(), any())).thenReturn(false);
    ruleController.rewriteWithRuleCollection(root, ruleList);
    // The count should be two for all rules.
    verify(firstRule, times(2)).rewritePre(any(), any());
    verify(secondRule, times(2)).rewritePre(any(), any());
    verify(thirdRule, times(2)).rewritePre(any(), any());
    // Case 2: the first rule returns false in the first iteration.
    //  Iteration1: R1 false (R2 and R3 should not be invoked.)
    reset(firstRule);
    reset(secondRule);
    reset(thirdRule);
    PowerMockito.when(firstRule.rewritePre(any(), any())).thenReturn(false);
    PowerMockito.when(secondRule.rewritePre(any(), any())).thenReturn(true);
    PowerMockito.when(thirdRule.rewritePre(any(), any())).thenReturn(true);
    ruleController.rewriteWithRuleCollection(root, ruleList);
    // The count should be one for the first rule.
    verify(firstRule, times(1)).rewritePre(any(), any());
    verify(secondRule, times(0)).rewritePre(any(), any());
    verify(thirdRule, times(0)).rewritePre(any(), any());
    // Case 3: a mixture of returning true/false.
    //  Iteration1: R1 true, R2 true, R3 false
    //  Iteration2: R1 false, R2 true, R3 false
    //  Iteration3: R1 false, R2 false, R3 false
    // So, the iteration should be stopped after the iteration 3.
    reset(firstRule);
    reset(secondRule);
    reset(thirdRule);
    PowerMockito.when(firstRule.rewritePre(any(), any())).thenReturn(true).thenReturn(false);
    PowerMockito.when(secondRule.rewritePre(any(), any())).thenReturn(true).thenReturn(true).thenReturn(false);
    PowerMockito.when(thirdRule.rewritePre(any(), any())).thenReturn(false);
    ruleController.rewriteWithRuleCollection(root, ruleList);
    // The count should be three for all rules.
    verify(firstRule, times(3)).rewritePre(any(), any());
    verify(secondRule, times(3)).rewritePre(any(), any());
    verify(thirdRule, times(3)).rewritePre(any(), any());
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) IAlgebraicRewriteRule(org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

IAlgebraicRewriteRule (org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule)31 LinkedList (java.util.LinkedList)25 RemoveUnusedAssignAndAggregateRule (org.apache.hyracks.algebricks.rewriter.rules.RemoveUnusedAssignAndAggregateRule)7 ArrayList (java.util.ArrayList)5 Pair (org.apache.hyracks.algebricks.common.utils.Pair)4 SequentialOnceRuleController (org.apache.hyracks.algebricks.compiler.rewriter.rulecontrollers.SequentialOnceRuleController)4 PushProjectDownRule (org.apache.hyracks.algebricks.rewriter.rules.PushProjectDownRule)4 PushSelectDownRule (org.apache.hyracks.algebricks.rewriter.rules.PushSelectDownRule)4 SetExecutionModeRule (org.apache.hyracks.algebricks.rewriter.rules.SetExecutionModeRule)4 EliminateSubplanRule (org.apache.hyracks.algebricks.rewriter.rules.subplan.EliminateSubplanRule)4 ConstantFoldingRule (org.apache.asterix.optimizer.rules.ConstantFoldingRule)3 ConsolidateAssignsRule (org.apache.hyracks.algebricks.rewriter.rules.ConsolidateAssignsRule)3 CopyLimitDownRule (org.apache.hyracks.algebricks.rewriter.rules.CopyLimitDownRule)3 InferTypesRule (org.apache.hyracks.algebricks.rewriter.rules.InferTypesRule)3 List (java.util.List)2 AsterixInlineVariablesRule (org.apache.asterix.optimizer.rules.AsterixInlineVariablesRule)2 ByNameToByIndexFieldAccessRule (org.apache.asterix.optimizer.rules.ByNameToByIndexFieldAccessRule)2 IntroduceDynamicTypeCastForExternalFunctionRule (org.apache.asterix.optimizer.rules.IntroduceDynamicTypeCastForExternalFunctionRule)2 IntroduceDynamicTypeCastRule (org.apache.asterix.optimizer.rules.IntroduceDynamicTypeCastRule)2 RemoveRedundantListifyRule (org.apache.asterix.optimizer.rules.RemoveRedundantListifyRule)2