>From Ali Alsuliman <[email protected]>: Ali Alsuliman has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21056?usp=email )
Change subject: [ASTERIXDB-3747][COMP] Introduce compiler property for hash-based OR threshold ...................................................................... [ASTERIXDB-3747][COMP] Introduce compiler property for hash-based OR threshold - user model changes: no - storage format changes: no - interface changes: no Ext-ref: MB-71169 Change-Id: If65b44c0a8ae36a6643397395fdab21b0174d5ea Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21056 Reviewed-by: Ali Alsuliman <[email protected]> Tested-by: Ali Alsuliman <[email protected]> --- M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/SqlppCompilationProvider.java M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java D asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/HashBasedOrRule.java M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java D asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashBasedOrDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionTypeInferers.java M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/config/AlgebricksConfig.java 8 files changed, 29 insertions(+), 381 deletions(-) Approvals: Ali Alsuliman: Looks good to me, approved; Verified 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 cfc47c6..5dea91d 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 @@ -37,7 +37,6 @@ import org.apache.asterix.lang.sqlpp.visitor.SqlppAstPrintVisitorFactory; import org.apache.asterix.optimizer.base.FuzzyUtils; import org.apache.asterix.optimizer.rules.DisjunctivePredicateToJoinRule; -import org.apache.asterix.optimizer.rules.HashBasedOrRule; import org.apache.asterix.optimizer.rules.SetAsterixPhysicalOperatorsRule; import org.apache.asterix.optimizer.rules.cbo.JoinEnum; import org.apache.asterix.optimizer.rules.util.EquivalenceClassUtils; @@ -98,15 +97,14 @@ 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_COLUMN_FILTER_KEY, CompilerProperties.COMPILER_BATCH_LOOKUP_KEY, - FunctionUtil.IMPORT_PRIVATE_FUNCTIONS, + CompilerProperties.COMPILER_DISJUNCTION_HASH_THRESHOLD, FunctionUtil.IMPORT_PRIVATE_FUNCTIONS, CompilerProperties.COMPILER_MAX_VARIABLE_OCCURRENCES_INLINING_KEY, CompilerProperties.COMPILER_DELTALAKE_FILESPLITS_KEY, CompilerProperties.COMPILER_MAX_EXPRESSION_TREE_SIZE_KEY, 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, - HashBasedOrRule.HASH_BASED_OR_OPTION, "hash_merge", "output-record-type", - DisjunctivePredicateToJoinRule.REWRITE_OR_AS_JOIN_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, JoinEnum.CBO_FULL_ENUM_LEVEL_KEY, JoinEnum.CBO_CP_ENUM_KEY, 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 ed3b213..d786e9d 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 @@ -469,7 +469,6 @@ prepareForJobGenRewrites.add(new EnsureColumnarSupportedTypesRule()); // EmbedProjectRule should run last. The assumption is that this rules set will run once prepareForJobGenRewrites.add(new EmbedProjectRule()); - //prepareForJobGenRewrites.add(new HashBasedOrRule()); return prepareForJobGenRewrites; } } diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/HashBasedOrRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/HashBasedOrRule.java deleted file mode 100644 index 30f4db2..0000000 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/HashBasedOrRule.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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.asterix.optimizer.rules; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.asterix.metadata.declared.MetadataProvider; -import org.apache.asterix.om.constants.AsterixConstantValue; -import org.apache.asterix.om.functions.BuiltinFunctions; -import org.apache.asterix.om.types.ATypeTag; -import org.apache.asterix.om.types.hierachy.ATypeHierarchy; -import org.apache.commons.lang3.mutable.Mutable; -import org.apache.commons.lang3.mutable.MutableObject; -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.LogicalExpressionTag; -import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable; -import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression; -import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression; -import org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression; -import org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression; -import org.apache.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions; -import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator; -import org.apache.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionReferenceTransform; -import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule; - -public class HashBasedOrRule implements IAlgebraicRewriteRule { - - public static final String HASH_BASED_OR_OPTION = "hash_based_or"; - private static final boolean HASH_BASED_OR_OPTION_DEFAULT = false; - - private final HashBasedOrTransformer transform = new HashBasedOrTransformer(); - private Boolean isRuleEnabled; - - @Override - public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) - throws AlgebricksException { - MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider(); - if (isRuleEnabled == null) { - isRuleEnabled = metadataProvider.getBooleanProperty(HASH_BASED_OR_OPTION, HASH_BASED_OR_OPTION_DEFAULT); - } - if (!isRuleEnabled) { - return false; - } - - AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); - if (context.checkIfInDontApplySet(this, op)) { - return false; - } - context.addToDontApplySet(this, op); - return op.acceptExpressionTransform(transform); - } - - private static class HashBasedOrTransformer implements ILogicalExpressionReferenceTransform { - - @Override - public boolean transform(Mutable<ILogicalExpression> exprRef) throws AlgebricksException { - ILogicalExpression expr = exprRef.getValue(); - if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { - return false; - } - - AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr; - - boolean changed = false; - for (Mutable<ILogicalExpression> arg : funcExpr.getArguments()) { - changed |= transform(arg); - } - if (funcExpr.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.OR)) { - changed |= tryRewriteOr(exprRef, funcExpr); - } - - return changed; - } - - private static boolean tryRewriteOr(Mutable<ILogicalExpression> exprRef, - AbstractFunctionCallExpression funcExpr) { - List<Mutable<ILogicalExpression>> orArgs = funcExpr.getArguments(); - LogicalVariable commonVar = null; - List<ILogicalExpression> constants = new ArrayList<>(); - ATypeTag tag = null; - - for (Mutable<ILogicalExpression> arg : orArgs) { - ILogicalExpression argExpr = arg.getValue(); - if (!apply(argExpr)) { - return false; - } - - AbstractFunctionCallExpression eqExpr = (AbstractFunctionCallExpression) argExpr; - List<Mutable<ILogicalExpression>> eqArgs = eqExpr.getArguments(); - ILogicalExpression left = eqArgs.get(0).getValue(); - ILogicalExpression right = eqArgs.get(1).getValue(); - VariableReferenceExpression varExpr; - ConstantExpression constExpr; - if (left.getExpressionTag() == LogicalExpressionTag.VARIABLE - && right.getExpressionTag() == LogicalExpressionTag.CONSTANT) { - varExpr = (VariableReferenceExpression) left; - constExpr = (ConstantExpression) right; - } else if (right.getExpressionTag() == LogicalExpressionTag.VARIABLE - && left.getExpressionTag() == LogicalExpressionTag.CONSTANT) { - varExpr = (VariableReferenceExpression) right; - constExpr = (ConstantExpression) left; - } else { - return false; - } - - if (tag == null) { - tag = ((AsterixConstantValue) constExpr.getValue()).getObject().getType().getTypeTag(); - } else if (!ATypeHierarchy.isCompatible(tag, - ((AsterixConstantValue) constExpr.getValue()).getObject().getType().getTypeTag())) { - return false; - } - LogicalVariable var = varExpr.getVariableReference(); - if (commonVar == null) { - commonVar = var; - } else if (!commonVar.equals(var)) { - return false; - } - constants.add(constExpr); - } - - if (commonVar == null || constants.size() < 2) { - return false; - } - - ScalarFunctionCallExpression hashmapOrExpr = new ScalarFunctionCallExpression( - BuiltinFunctions.getBuiltinFunctionInfo(BuiltinFunctions.HASH_BASED_OR)); - hashmapOrExpr.setSourceLocation(funcExpr.getSourceLocation()); - - VariableReferenceExpression newVarRef = new VariableReferenceExpression(commonVar); - newVarRef.setSourceLocation(funcExpr.getSourceLocation()); - hashmapOrExpr.getArguments().add(new MutableObject<>(newVarRef)); - - for (ILogicalExpression constExpr : constants) { - hashmapOrExpr.getArguments().add(new MutableObject<>(constExpr)); - } - - exprRef.setValue(hashmapOrExpr); - return true; - } - } - - private static boolean apply(ILogicalExpression argExpr) { - return argExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL - && ((AbstractFunctionCallExpression) argExpr).getFunctionIdentifier() - .equals(AlgebricksBuiltinFunctions.EQ) - && ((AbstractFunctionCallExpression) argExpr).getArguments().size() == 2; - } -} 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 af2b450..814ec9f 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 @@ -167,7 +167,11 @@ COMPILER_REWRITE_DISJUNCTION( BOOLEAN, AlgebricksConfig.REWRITE_DISJUNCTION_DEFAULT, - "Set the mode for rewriting disjunctions to joins in query plans"); + "Set the mode for rewriting disjunctions to joins in query plans"), + COMPILER_DISJUNCTION_HASH_THRESHOLD( + getRangedIntegerType(-1, Integer.MAX_VALUE), + AlgebricksConfig.HASH_BASED_OR_THRESHOLD_DEFAULT, + "The max number of disjunctions after which a hash-based approach is used for evaluating OR operation"); private final IOptionType type; private final Object defaultValue; @@ -222,8 +226,11 @@ public static final String COMPILER_SORT_SAMPLES_KEY = Option.COMPILER_SORT_SAMPLES.ini(); public static final String COMPILER_INDEXONLY_KEY = Option.COMPILER_INDEXONLY.ini(); + public static final String COMPILER_REWRITE_DISJUNCTION_KEY = Option.COMPILER_REWRITE_DISJUNCTION.ini(); + public static final String COMPILER_DISJUNCTION_HASH_THRESHOLD = Option.COMPILER_DISJUNCTION_HASH_THRESHOLD.ini(); + public static final String COMPILER_INTERNAL_SANITYCHECK_KEY = Option.COMPILER_INTERNAL_SANITYCHECK.ini(); public static final String COMPILER_EXTERNAL_FIELD_PUSHDOWN_KEY = Option.COMPILER_EXTERNAL_FIELD_PUSHDOWN.ini(); @@ -328,6 +335,10 @@ return accessor.getBoolean(Option.COMPILER_REWRITE_DISJUNCTION); } + public int getHashBasedORThreshold() { + return accessor.getInt(Option.COMPILER_DISJUNCTION_HASH_THRESHOLD); + } + public boolean isSanityCheck() { return accessor.getBoolean(Option.COMPILER_INTERNAL_SANITYCHECK); } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashBasedOrDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashBasedOrDescriptor.java deleted file mode 100644 index d0a07d8..0000000 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashBasedOrDescriptor.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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.asterix.runtime.evaluators.functions; - -import java.io.DataOutput; - -import org.apache.asterix.formats.nontagged.BinaryComparatorFactoryProvider; -import org.apache.asterix.formats.nontagged.BinaryHashFunctionFactoryProvider; -import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider; -import org.apache.asterix.om.base.ABoolean; -import org.apache.asterix.om.base.AMissing; -import org.apache.asterix.om.base.ANull; -import org.apache.asterix.om.functions.BuiltinFunctions; -import org.apache.asterix.om.functions.IFunctionDescriptor; -import org.apache.asterix.om.functions.IFunctionDescriptorFactory; -import org.apache.asterix.om.functions.IFunctionTypeInferer; -import org.apache.asterix.om.types.ATypeTag; -import org.apache.asterix.om.types.BuiltinType; -import org.apache.asterix.om.types.EnumDeserializer; -import org.apache.asterix.om.types.IAType; -import org.apache.asterix.om.types.hierachy.ATypeHierarchy; -import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; -import org.apache.asterix.runtime.functions.FunctionTypeInferers; -import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; -import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; -import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; -import org.apache.hyracks.api.context.IEvaluatorContext; -import org.apache.hyracks.api.dataflow.value.IBinaryComparator; -import org.apache.hyracks.api.dataflow.value.IBinaryHashFunction; -import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; -import org.apache.hyracks.api.exceptions.HyracksDataException; -import org.apache.hyracks.data.std.api.IPointable; -import org.apache.hyracks.data.std.primitive.VoidPointable; -import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; -import org.apache.hyracks.data.std.util.BinaryEntry; -import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference; - -public class HashBasedOrDescriptor extends AbstractScalarFunctionDynamicDescriptor { - - private static final long serialVersionUID = 1L; - /** Dummy value for set semantics (BinaryHashMap requires key+value; we only need key presence). */ - private static final byte[] DUMMY_VALUE = new byte[] { 0 }; - - /** Same defaults as RecordAddFieldsDescriptor for BinaryHashMap. */ - private static final int TABLE_SIZE = 100; - private static final int TABLE_FRAME_SIZE = 32768; - - public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { - @Override - public IFunctionDescriptor createFunctionDescriptor() { - return new HashBasedOrDescriptor(); - } - - @Override - public IFunctionTypeInferer createFunctionTypeInferer() { - return FunctionTypeInferers.SET_OR_TYPES; - } - }; - - protected IAType elementType; - - @Override - public void setImmutableStates(Object... types) { - elementType = (IAType) types[0]; - } - - @Override - public FunctionIdentifier getIdentifier() { - return BuiltinFunctions.HASH_BASED_OR; - } - - @Override - public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) { - return new IScalarEvaluatorFactory() { - private static final long serialVersionUID = 1L; - - @Override - public IScalarEvaluator createScalarEvaluator(final IEvaluatorContext ctx) throws HyracksDataException { - final IScalarEvaluator valueEval = args[0].createScalarEvaluator(ctx); - final int numConst = args.length - 1; - final IScalarEvaluator[] constEvals = new IScalarEvaluator[numConst]; - for (int i = 0; i < numConst; i++) { - constEvals[i] = args[i + 1].createScalarEvaluator(ctx); - } - - final IBinaryHashFunction putHashFunc = BinaryHashFunctionFactoryProvider.INSTANCE - .getBinaryHashFunctionFactory(elementType).createBinaryHashFunction(); - final IBinaryHashFunction getHashFunc = BinaryHashFunctionFactoryProvider.INSTANCE - .getBinaryHashFunctionFactory(elementType).createBinaryHashFunction(); - final IBinaryComparator cmp = BinaryComparatorFactoryProvider.INSTANCE - .getBinaryComparatorFactory(elementType, true).createBinaryComparator(); - - return new IScalarEvaluator() { - private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage(); - private final DataOutput output = resultStorage.getDataOutput(); - private final VoidPointable valuePtr = new VoidPointable(); - private final VoidPointable constPtr = new VoidPointable(); - private final BinaryEntry keyEntry = new BinaryEntry(); - private final BinaryEntry valEntry = new BinaryEntry(); - private final BinaryHashMap valueSet = - new BinaryHashMap(TABLE_SIZE, TABLE_FRAME_SIZE, putHashFunc, getHashFunc, cmp); - - private boolean setBuilt = false; - - @SuppressWarnings("unchecked") - private final ISerializerDeserializer<ABoolean> booleanSerde = - SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN); - @SuppressWarnings("unchecked") - private final ISerializerDeserializer<ANull> nullSerde = - SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL); - @SuppressWarnings("unchecked") - private final ISerializerDeserializer<AMissing> missingSerde = - SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING); - - @Override - public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException { - resultStorage.reset(); - buildSetIfNeeded(tuple); - valueEval.evaluate(tuple, valuePtr); - byte[] data = valuePtr.getByteArray(); - int offset = valuePtr.getStartOffset(); - - if (data[offset] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) { - missingSerde.serialize(AMissing.MISSING, output); - result.set(resultStorage); - return; - } - if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) { - nullSerde.serialize(ANull.NULL, output); - result.set(resultStorage); - return; - } - if (!ATypeHierarchy.isCompatible( - EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]), - elementType.getTypeTag())) { - booleanSerde.serialize(ABoolean.FALSE, output); - result.set(resultStorage); - return; - } - - keyEntry.set(data, offset, valuePtr.getLength()); - BinaryEntry found = valueSet.get(keyEntry); - if (found == null) { - booleanSerde.serialize(ABoolean.FALSE, output); - } else { - booleanSerde.serialize(ABoolean.TRUE, output); - } - result.set(resultStorage); - } - - private void buildSetIfNeeded(IFrameTupleReference tuple) throws HyracksDataException { - if (setBuilt) { - return; - } - valEntry.set(DUMMY_VALUE, 0, 1); - for (int i = 0; i < numConst; i++) { - constEvals[i].evaluate(tuple, constPtr); - byte[] data = constPtr.getByteArray(); - int offset = constPtr.getStartOffset(); - if (offset < data.length) { - keyEntry.set(data, offset, constPtr.getLength()); - valueSet.put(keyEntry, valEntry); - } - } - setBuilt = true; - } - }; - } - }; - } -} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java index 8dbb97e..0a544a8 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java @@ -390,7 +390,6 @@ import org.apache.asterix.runtime.evaluators.functions.GetItemDescriptor; import org.apache.asterix.runtime.evaluators.functions.GetJobParameterByNameDescriptor; import org.apache.asterix.runtime.evaluators.functions.GetTypeDescriptor; -import org.apache.asterix.runtime.evaluators.functions.HashBasedOrDescriptor; import org.apache.asterix.runtime.evaluators.functions.IfErrorDescriptor; import org.apache.asterix.runtime.evaluators.functions.IfInfDescriptor; import org.apache.asterix.runtime.evaluators.functions.IfMissingDescriptor; @@ -964,7 +963,6 @@ // boolean functions fc.add(AndDescriptor.FACTORY); fc.add(OrDescriptor.FACTORY); - fc.add(HashBasedOrDescriptor.FACTORY); // Record constructors / functions fc.add(ClosedRecordConstructorDescriptor.FACTORY); diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionTypeInferers.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionTypeInferers.java index e075a70..6d20590 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionTypeInferers.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionTypeInferers.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.apache.asterix.common.config.CompilerProperties; import org.apache.asterix.common.exceptions.CompilationException; @@ -53,7 +54,6 @@ import org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression; import org.apache.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions; import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider; -import org.apache.hyracks.algebricks.core.config.AlgebricksConfig; /** * Implementations of {@link IFunctionTypeInferer} for built-in functions @@ -123,12 +123,6 @@ } }; - public static final IFunctionTypeInferer SET_OR_TYPES = (expr, fd, context, compilerProps, metadataProvider) -> { - AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; - IAType elementType = (IAType) context.getType(fce.getArguments().get(1).getValue()); - fd.setImmutableStates(TypeComputeUtils.getActualType(elementType)); - }; - public static final IFunctionTypeInferer MEDIAN_MEMORY = (expr, fd, context, compilerProps, metadataProvider) -> fd .setImmutableStates(compilerProps.getSortMemoryFrames()); @@ -146,25 +140,28 @@ @Override public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context, CompilerProperties compilerProps, IMetadataProvider<?, ?> mp) throws AlgebricksException { - Object hashBasedOption = mp.getConfig().get(AlgebricksConfig.HASH_BASED_OR_OPTION); - boolean hashBasedOrEnabled = AlgebricksConfig.HASH_BASED_OR_OPTION_DEFAULT; - if (hashBasedOption != null) { - hashBasedOrEnabled = Boolean.parseBoolean(String.valueOf(hashBasedOption)); + int hashBasedThreshold; + Map<String, Object> config = mp.getConfig(); + if (config.containsKey(CompilerProperties.COMPILER_DISJUNCTION_HASH_THRESHOLD)) { + Object hashBasedOptionFromQuery = config.get(CompilerProperties.COMPILER_DISJUNCTION_HASH_THRESHOLD); + hashBasedThreshold = + (hashBasedOptionFromQuery != null) ? Integer.parseInt(String.valueOf(hashBasedOptionFromQuery)) + : compilerProps.getHashBasedORThreshold(); + } else { + hashBasedThreshold = compilerProps.getHashBasedORThreshold(); } - if (!hashBasedOrEnabled) { - return; - } + AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr; - IAType elementType = useHashBased(fce); + IAType elementType = useHashBased(fce, hashBasedThreshold); if (elementType != null) { fd.setImmutableStates((Object[]) new IAType[] { elementType }); } } }; - private static IAType useHashBased(AbstractFunctionCallExpression funcExpr) { + private static IAType useHashBased(AbstractFunctionCallExpression funcExpr, int hashBasedThreshold) { List<Mutable<ILogicalExpression>> orArgs = funcExpr.getArguments(); - if (orArgs.size() < 2) { + if (hashBasedThreshold < 0 || orArgs.size() < 2 || orArgs.size() < hashBasedThreshold) { return null; } LogicalVariable commonVar = null; diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/config/AlgebricksConfig.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/config/AlgebricksConfig.java index b3506f4..672c2dc 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/config/AlgebricksConfig.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/config/AlgebricksConfig.java @@ -49,7 +49,7 @@ public static final boolean COLUMN_FILTER_DEFAULT = true; public static final boolean ORDERED_FIELDS = true; public static final int MAX_VARIABLE_OCCURRENCES_INLINING_DEFAULT = 128; + public static final int HASH_BASED_OR_THRESHOLD_DEFAULT = -1; public static final String HASH_BASED_OR_OPTION = "hash_based_or"; - public static final boolean HASH_BASED_OR_OPTION_DEFAULT = false; public static final int MAX_EXPRESSION_TREE_SIZE_DEFAULT = 10000; } -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21056?usp=email To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: asterixdb Gerrit-Branch: phoenix Gerrit-Change-Id: If65b44c0a8ae36a6643397395fdab21b0174d5ea Gerrit-Change-Number: 21056 Gerrit-PatchSet: 11 Gerrit-Owner: Shahrzad Shirazi <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]>
