Merged asterix_statement_model_fix into asterix_stabilization
1) Asterix now has a revised statement model.
a) Each statement (definition includes a query) is executed as an independent transaction.
b) Statements are executed in the order of submission with no implicit re-orderings.
c) Asterix does not differentiate between DDL and DML statements. This is unlike the previous model which executed DDL statements prior to DML statements.
d) Asterix bails out at the failure in execution of a statement. As stated in (a), the failing statement is rolled back and has no impact on previously executed statements.
e) Forward references during type creation are not supported. This is not a regression, as these did not work in the previous model either.
f) Amongst the submitted statements, you could have multiple queries.
2) Asterix has support for AQL bodied functions. You can create AQL bodied fucntions and may use them in subsequent sessions.
3) Asterix has support for cross dataverse statements. You can invoke statements/queries that refer to entities belonging to different dataverses.
4) Other Issues resolved: 25, 62, 100, 124, 148, 165, 202
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization@860 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/BTreeSearchPOperator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/BTreeSearchPOperator.java
index e653b82..09a4c6b 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/BTreeSearchPOperator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/BTreeSearchPOperator.java
@@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.declared.AqlSourceId;
import edu.uci.ics.asterix.metadata.entities.Dataset;
@@ -80,16 +79,15 @@
int[] lowKeyIndexes = getKeyIndexes(jobGenParams.getLowKeyVarList(), inputSchemas);
int[] highKeyIndexes = getKeyIndexes(jobGenParams.getHighKeyVarList(), inputSchemas);
AqlMetadataProvider metadataProvider = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations metadata = metadataProvider.getMetadataDeclarations();
- Dataset dataset = metadata.findDataset(jobGenParams.getDatasetName());
+ Dataset dataset = metadataProvider.findDataset(jobGenParams.getDataverseName(), jobGenParams.getDatasetName());
IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(op);
List<LogicalVariable> outputVars = unnestMap.getVariables();
if (jobGenParams.getRetainInput()) {
outputVars = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(unnestMap, outputVars);
}
- Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> btreeSearch = AqlMetadataProvider.buildBtreeRuntime(
- builder.getJobSpec(), outputVars, opSchema, typeEnv, metadata, context, jobGenParams.getRetainInput(),
+ Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> btreeSearch = metadataProvider.buildBtreeRuntime(
+ builder.getJobSpec(), outputVars, opSchema, typeEnv, context, jobGenParams.getRetainInput(),
dataset, jobGenParams.getIndexName(), lowKeyIndexes, highKeyIndexes, jobGenParams.isLowKeyInclusive(),
jobGenParams.isHighKeyInclusive());
builder.contributeHyracksOperator(unnestMap, btreeSearch.first);
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/InvertedIndexPOperator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/InvertedIndexPOperator.java
index 60c4155..510aa4c 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/InvertedIndexPOperator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/InvertedIndexPOperator.java
@@ -4,7 +4,8 @@
import java.util.List;
import edu.uci.ics.asterix.common.dataflow.IAsterixApplicationContextInfo;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
+import edu.uci.ics.asterix.metadata.MetadataException;
+import edu.uci.ics.asterix.metadata.MetadataManager;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.declared.AqlSourceId;
import edu.uci.ics.asterix.metadata.entities.Dataset;
@@ -50,7 +51,8 @@
import edu.uci.ics.hyracks.storage.am.invertedindex.tokenizers.IBinaryTokenizerFactory;
/**
- * Contributes the runtime operator for an unnest-map representing an inverted-index search.
+ * Contributes the runtime operator for an unnest-map representing an
+ * inverted-index search.
*/
public class InvertedIndexPOperator extends IndexSearchPOperator {
public InvertedIndexPOperator(IDataSourceIndex<String, AqlSourceId> idx, boolean requiresBroadcast) {
@@ -79,13 +81,18 @@
jobGenParams.readFromFuncArgs(unnestFuncExpr.getArguments());
AqlMetadataProvider metadataProvider = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations metadata = metadataProvider.getMetadataDeclarations();
- Dataset dataset = metadata.findDataset(jobGenParams.getDatasetName());
+ Dataset dataset;
+ try {
+ dataset = MetadataManager.INSTANCE.getDataset(metadataProvider.getMetadataTxnContext(),
+ jobGenParams.getDataverseName(), jobGenParams.getDatasetName());
+ } catch (MetadataException e) {
+ throw new AlgebricksException(e);
+ }
int[] keyIndexes = getKeyIndexes(jobGenParams.getKeyVarList(), inputSchemas);
// Build runtime.
- Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> invIndexSearch = buildInvertedIndexRuntime(metadata,
- context, builder.getJobSpec(), unnestMapOp, opSchema, jobGenParams.getRetainInput(),
+ Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> invIndexSearch = buildInvertedIndexRuntime(
+ metadataProvider, context, builder.getJobSpec(), unnestMapOp, opSchema, jobGenParams.getRetainInput(),
jobGenParams.getDatasetName(), dataset, jobGenParams.getIndexName(), jobGenParams.getSearchKeyType(),
keyIndexes, jobGenParams.getSearchModifierType(), jobGenParams.getSimilarityThreshold());
// Contribute operator in hyracks job.
@@ -95,81 +102,93 @@
builder.contributeGraphEdge(srcExchange, 0, unnestMapOp, 0);
}
- public static Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> buildInvertedIndexRuntime(
- AqlCompiledMetadataDeclarations metadata, JobGenContext context, JobSpecification jobSpec,
+ public Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> buildInvertedIndexRuntime(
+ AqlMetadataProvider metadataProvider, JobGenContext context, JobSpecification jobSpec,
UnnestMapOperator unnestMap, IOperatorSchema opSchema, boolean retainInput, String datasetName,
Dataset dataset, String indexName, ATypeTag searchKeyType, int[] keyFields,
SearchModifierType searchModifierType, IAlgebricksConstantValue similarityThreshold)
throws AlgebricksException {
- IAObject simThresh = ((AsterixConstantValue) similarityThreshold).getObject();
- IAType itemType = metadata.findType(dataset.getItemTypeName());
- int numPrimaryKeys = DatasetUtils.getPartitioningKeys(dataset).size();
- Index secondaryIndex = metadata.getIndex(dataset.getDataverseName(), dataset.getDatasetName(), indexName);
- if (secondaryIndex == null) {
- throw new AlgebricksException("Code generation error: no index " + indexName + " for dataset "
- + datasetName);
- }
- List<String> secondaryKeyFields = secondaryIndex.getKeyFieldNames();
- int numSecondaryKeys = secondaryKeyFields.size();
- if (numSecondaryKeys != 1) {
- throw new AlgebricksException(
- "Cannot use "
- + numSecondaryKeys
- + " fields as a key for an inverted index. There can be only one field as a key for the inverted index index.");
- }
- if (itemType.getTypeTag() != ATypeTag.RECORD) {
- throw new AlgebricksException("Only record types can be indexed.");
- }
- ARecordType recordType = (ARecordType) itemType;
- Pair<IAType, Boolean> keyPairType = Index.getNonNullableKeyFieldType(secondaryKeyFields.get(0), recordType);
- IAType secondaryKeyType = keyPairType.first;
- if (secondaryKeyType == null) {
- throw new AlgebricksException("Could not find field " + secondaryKeyFields.get(0) + " in the schema.");
- }
+ try {
+ IAObject simThresh = ((AsterixConstantValue) similarityThreshold).getObject();
+ IAType itemType = MetadataManager.INSTANCE.getDatatype(metadataProvider.getMetadataTxnContext(),
+ dataset.getDataverseName(), dataset.getItemTypeName()).getDatatype();
+ int numPrimaryKeys = DatasetUtils.getPartitioningKeys(dataset).size();
+ Index secondaryIndex = MetadataManager.INSTANCE.getIndex(metadataProvider.getMetadataTxnContext(),
+ dataset.getDataverseName(), dataset.getDatasetName(), indexName);
+ if (secondaryIndex == null) {
+ throw new AlgebricksException("Code generation error: no index " + indexName + " for dataset "
+ + datasetName);
+ }
+ List<String> secondaryKeyFields = secondaryIndex.getKeyFieldNames();
+ int numSecondaryKeys = secondaryKeyFields.size();
+ if (numSecondaryKeys != 1) {
+ throw new AlgebricksException(
+ "Cannot use "
+ + numSecondaryKeys
+ + " fields as a key for an inverted index. There can be only one field as a key for the inverted index index.");
+ }
+ if (itemType.getTypeTag() != ATypeTag.RECORD) {
+ throw new AlgebricksException("Only record types can be indexed.");
+ }
+ ARecordType recordType = (ARecordType) itemType;
+ Pair<IAType, Boolean> keyPairType = Index.getNonNullableKeyFieldType(secondaryKeyFields.get(0), recordType);
+ IAType secondaryKeyType = keyPairType.first;
+ if (secondaryKeyType == null) {
+ throw new AlgebricksException("Could not find field " + secondaryKeyFields.get(0) + " in the schema.");
+ }
- // TODO: For now we assume the type of the generated tokens is the same as the indexed field.
- // We need a better way of expressing this because tokens may be hashed, or an inverted-index may index a list type, etc.
- ITypeTraits[] tokenTypeTraits = new ITypeTraits[numSecondaryKeys];
- IBinaryComparatorFactory[] tokenComparatorFactories = new IBinaryComparatorFactory[numSecondaryKeys];
- for (int i = 0; i < numSecondaryKeys; i++) {
- tokenComparatorFactories[i] = InvertedIndexAccessMethod.getTokenBinaryComparatorFactory(secondaryKeyType);
- tokenTypeTraits[i] = InvertedIndexAccessMethod.getTokenTypeTrait(secondaryKeyType);
+ // TODO: For now we assume the type of the generated tokens is the
+ // same
+ // as the indexed field.
+ // We need a better way of expressing this because tokens may be
+ // hashed,
+ // or an inverted-index may index a list type, etc.
+ ITypeTraits[] tokenTypeTraits = new ITypeTraits[numSecondaryKeys];
+ IBinaryComparatorFactory[] tokenComparatorFactories = new IBinaryComparatorFactory[numSecondaryKeys];
+ for (int i = 0; i < numSecondaryKeys; i++) {
+ tokenComparatorFactories[i] = InvertedIndexAccessMethod
+ .getTokenBinaryComparatorFactory(secondaryKeyType);
+ tokenTypeTraits[i] = InvertedIndexAccessMethod.getTokenTypeTrait(secondaryKeyType);
+ }
+
+ IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(unnestMap);
+ List<LogicalVariable> outputVars = unnestMap.getVariables();
+ if (retainInput) {
+ outputVars = new ArrayList<LogicalVariable>();
+ VariableUtilities.getLiveVariables(unnestMap, outputVars);
+ }
+ RecordDescriptor outputRecDesc = JobGenHelper.mkRecordDescriptor(typeEnv, opSchema, context);
+
+ int start = outputRecDesc.getFieldCount() - numPrimaryKeys;
+ IBinaryComparatorFactory[] invListsComparatorFactories = JobGenHelper
+ .variablesToAscBinaryComparatorFactories(outputVars, start, numPrimaryKeys, typeEnv, context);
+ ITypeTraits[] invListsTypeTraits = JobGenHelper.variablesToTypeTraits(outputVars, start, numPrimaryKeys,
+ typeEnv, context);
+
+ IAsterixApplicationContextInfo appContext = (IAsterixApplicationContextInfo) context.getAppContext();
+ Pair<IFileSplitProvider, AlgebricksPartitionConstraint> secondarySplitsAndConstraint = metadataProvider
+ .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(dataset.getDataverseName(),
+ datasetName, indexName);
+ Pair<IFileSplitProvider, IFileSplitProvider> fileSplitProviders = metadataProvider
+ .getInvertedIndexFileSplitProviders(secondarySplitsAndConstraint.first);
+
+ // TODO: Here we assume there is only one search key field.
+ int queryField = keyFields[0];
+ // Get tokenizer and search modifier factories.
+ IInvertedIndexSearchModifierFactory searchModifierFactory = InvertedIndexAccessMethod
+ .getSearchModifierFactory(searchModifierType, simThresh, secondaryIndex);
+ IBinaryTokenizerFactory queryTokenizerFactory = InvertedIndexAccessMethod.getBinaryTokenizerFactory(
+ searchModifierType, searchKeyType, secondaryIndex);
+ InvertedIndexSearchOperatorDescriptor invIndexSearchOp = new InvertedIndexSearchOperatorDescriptor(jobSpec,
+ queryField, appContext.getStorageManagerInterface(), fileSplitProviders.first,
+ fileSplitProviders.second, appContext.getIndexRegistryProvider(), tokenTypeTraits,
+ tokenComparatorFactories, invListsTypeTraits, invListsComparatorFactories,
+ new BTreeDataflowHelperFactory(), queryTokenizerFactory, searchModifierFactory, outputRecDesc,
+ retainInput, NoOpOperationCallbackProvider.INSTANCE);
+ return new Pair<IOperatorDescriptor, AlgebricksPartitionConstraint>(invIndexSearchOp,
+ secondarySplitsAndConstraint.second);
+ } catch (MetadataException e) {
+ throw new AlgebricksException(e);
}
-
- IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(unnestMap);
- List<LogicalVariable> outputVars = unnestMap.getVariables();
- if (retainInput) {
- outputVars = new ArrayList<LogicalVariable>();
- VariableUtilities.getLiveVariables(unnestMap, outputVars);
- }
- RecordDescriptor outputRecDesc = JobGenHelper.mkRecordDescriptor(typeEnv, opSchema, context);
-
- int start = outputRecDesc.getFieldCount() - numPrimaryKeys;
- IBinaryComparatorFactory[] invListsComparatorFactories = JobGenHelper.variablesToAscBinaryComparatorFactories(
- outputVars, start, numPrimaryKeys, typeEnv, context);
- ITypeTraits[] invListsTypeTraits = JobGenHelper.variablesToTypeTraits(outputVars, start, numPrimaryKeys,
- typeEnv, context);
-
- IAsterixApplicationContextInfo appContext = (IAsterixApplicationContextInfo) context.getAppContext();
- Pair<IFileSplitProvider, AlgebricksPartitionConstraint> secondarySplitsAndConstraint = metadata
- .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(datasetName, indexName);
- Pair<IFileSplitProvider, IFileSplitProvider> fileSplitProviders = metadata
- .getInvertedIndexFileSplitProviders(secondarySplitsAndConstraint.first);
-
- // TODO: Here we assume there is only one search key field.
- int queryField = keyFields[0];
- // Get tokenizer and search modifier factories.
- IInvertedIndexSearchModifierFactory searchModifierFactory = InvertedIndexAccessMethod.getSearchModifierFactory(
- searchModifierType, simThresh, secondaryIndex);
- IBinaryTokenizerFactory queryTokenizerFactory = InvertedIndexAccessMethod.getBinaryTokenizerFactory(
- searchModifierType, searchKeyType, secondaryIndex);
- InvertedIndexSearchOperatorDescriptor invIndexSearchOp = new InvertedIndexSearchOperatorDescriptor(jobSpec,
- queryField, appContext.getStorageManagerInterface(), fileSplitProviders.first,
- fileSplitProviders.second, appContext.getIndexRegistryProvider(), tokenTypeTraits,
- tokenComparatorFactories, invListsTypeTraits, invListsComparatorFactories,
- new BTreeDataflowHelperFactory(), queryTokenizerFactory, searchModifierFactory, outputRecDesc,
- retainInput, NoOpOperationCallbackProvider.INSTANCE);
- return new Pair<IOperatorDescriptor, AlgebricksPartitionConstraint>(invIndexSearchOp,
- secondarySplitsAndConstraint.second);
}
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/RTreeSearchPOperator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/RTreeSearchPOperator.java
index ca973f9..ab66457 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/RTreeSearchPOperator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/RTreeSearchPOperator.java
@@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.declared.AqlSourceId;
import edu.uci.ics.asterix.metadata.entities.Dataset;
@@ -29,7 +28,8 @@
import edu.uci.ics.hyracks.api.dataflow.IOperatorDescriptor;
/**
- * Contributes the runtime operator for an unnest-map representing a RTree search.
+ * Contributes the runtime operator for an unnest-map representing a RTree
+ * search.
*/
public class RTreeSearchPOperator extends IndexSearchPOperator {
@@ -60,20 +60,20 @@
jobGenParams.readFromFuncArgs(unnestFuncExpr.getArguments());
int[] keyIndexes = getKeyIndexes(jobGenParams.getKeyVarList(), inputSchemas);
AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations metadata = mp.getMetadataDeclarations();
- Dataset dataset = metadata.findDataset(jobGenParams.getDatasetName());
+ Dataset dataset = mp.findDataset(jobGenParams.getDataverseName(), jobGenParams.getDatasetName());
IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(unnestMap);
List<LogicalVariable> outputVars = unnestMap.getVariables();
if (jobGenParams.getRetainInput()) {
outputVars = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(unnestMap, outputVars);
}
- Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> rtreeSearch = AqlMetadataProvider.buildRtreeRuntime(
- builder.getJobSpec(), outputVars, opSchema, typeEnv, metadata, context, jobGenParams.getRetainInput(),
- dataset, jobGenParams.getIndexName(), keyIndexes);
+ Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> rtreeSearch = mp.buildRtreeRuntime(
+ builder.getJobSpec(), outputVars, opSchema, typeEnv, context, jobGenParams.getRetainInput(), dataset,
+ jobGenParams.getIndexName(), keyIndexes);
builder.contributeHyracksOperator(unnestMap, rtreeSearch.first);
builder.contributeAlgebricksPartitionConstraint(rtreeSearch.first, rtreeSearch.second);
ILogicalOperator srcExchange = unnestMap.getInputs().get(0).getValue();
builder.contributeGraphEdge(srcExchange, 0, unnestMap, 0);
}
+
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/jobgen/AqlLogicalExpressionJobGen.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/jobgen/AqlLogicalExpressionJobGen.java
index f515516..dd8791f 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/jobgen/AqlLogicalExpressionJobGen.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/jobgen/AqlLogicalExpressionJobGen.java
@@ -6,7 +6,6 @@
import edu.uci.ics.asterix.common.functions.FunctionDescriptorTag;
import edu.uci.ics.asterix.formats.base.IDataFormat;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
@@ -126,7 +125,7 @@
IFunctionDescriptor fd = null;
AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- IDataFormat format = mp == null ? FormatUtils.getDefaultFormat() : mp.getMetadataDeclarations().getFormat();
+ IDataFormat format = FormatUtils.getDefaultFormat();
fd = format.resolveFunction(expr, env);
return fd.createEvaluatorFactory(args);
}
@@ -134,7 +133,7 @@
private ICopyEvaluatorFactory createConstantEvaluatorFactory(ConstantExpression expr,
IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException {
AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- IDataFormat format = mp == null ? FormatUtils.getDefaultFormat() : mp.getMetadataDeclarations().getFormat();
+ IDataFormat format = FormatUtils.getDefaultFormat();
return format.getConstantEvalFactory(expr.getValue());
}
@@ -185,8 +184,7 @@
IVariableTypeEnvironment env, JobGenContext context) throws AlgebricksException {
IFunctionDescriptor fd;
AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations compiledDecls = mp.getMetadataDeclarations();
- fd = compiledDecls.getFormat().resolveFunction(expr, env);
+ fd = FormatUtils.getDefaultFormat().resolveFunction(expr, env);
return fd;
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/AnalysisUtil.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/AnalysisUtil.java
index 94a00cb..644996a 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/AnalysisUtil.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/AnalysisUtil.java
@@ -8,6 +8,7 @@
import edu.uci.ics.asterix.metadata.declared.AqlSourceId;
import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
@@ -106,9 +107,9 @@
return false;
}
- public static String getDatasetName(DataSourceScanOperator op) throws AlgebricksException {
+ public static Pair<String, String> getDatasetInfo(DataSourceScanOperator op) throws AlgebricksException {
AqlSourceId srcId = (AqlSourceId) op.getDataSource().getId();
- return srcId.getDatasetName();
+ return new Pair<String, String>(srcId.getDataverseName(), srcId.getDatasetName());
}
private static List<FunctionIdentifier> fieldAccessFunctions = new ArrayList<FunctionIdentifier>();
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/FuzzyUtils.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/FuzzyUtils.java
index 0c274b9..89d78f2 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/FuzzyUtils.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/FuzzyUtils.java
@@ -5,7 +5,7 @@
import org.apache.commons.lang3.mutable.Mutable;
import edu.uci.ics.asterix.aql.util.FunctionUtils;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
+import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.om.base.AFloat;
import edu.uci.ics.asterix.om.base.AInt32;
import edu.uci.ics.asterix.om.base.IAObject;
@@ -41,7 +41,7 @@
}
}
- public static IAObject getSimThreshold(AqlCompiledMetadataDeclarations metadata, String simFuncName) {
+ public static IAObject getSimThreshold(AqlMetadataProvider metadata, String simFuncName) {
String simThresholValue = metadata.getPropertyValue(SIM_THRESHOLD_PROP_NAME);
IAObject ret = null;
if (simFuncName.equals(JACCARD_FUNCTION_NAME)) {
@@ -83,7 +83,7 @@
return null;
}
- public static float getSimThreshold(AqlCompiledMetadataDeclarations metadata) {
+ public static float getSimThreshold(AqlMetadataProvider metadata) {
float simThreshold = JACCARD_DEFAULT_SIM_THRESHOLD;
String simThresholValue = metadata.getPropertyValue(SIM_THRESHOLD_PROP_NAME);
if (simThresholValue != null) {
@@ -93,7 +93,7 @@
}
// TODO: The default function depend on the input types.
- public static String getSimFunction(AqlCompiledMetadataDeclarations metadata) {
+ public static String getSimFunction(AqlMetadataProvider metadata) {
String simFunction = metadata.getPropertyValue(SIM_FUNCTION_PROP_NAME);
if (simFunction == null) {
simFunction = DEFAULT_SIM_FUNCTION;
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
index 2fa2dc9..9d77e5c 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
@@ -79,6 +79,7 @@
import edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSelectDownRule;
import edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSelectIntoJoinRule;
import edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSubplanWithAggregateDownThroughProductRule;
+import edu.uci.ics.asterix.optimizer.rules.PushAggFuncIntoStandaloneAggregateRule;
import edu.uci.ics.hyracks.algebricks.rewriter.rules.ReinferAllTypesRule;
import edu.uci.ics.hyracks.algebricks.rewriter.rules.RemoveRedundantGroupByDecorVars;
import edu.uci.ics.hyracks.algebricks.rewriter.rules.RemoveRedundantVariablesRule;
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/FuzzyEqRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/FuzzyEqRule.java
index 1a2cd2a..77c719d 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/FuzzyEqRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/FuzzyEqRule.java
@@ -7,7 +7,6 @@
import org.apache.commons.lang3.mutable.MutableObject;
import edu.uci.ics.asterix.aql.util.FunctionUtils;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.om.base.IAObject;
import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
@@ -56,11 +55,10 @@
return false;
}
- AqlCompiledMetadataDeclarations aqlMetadata = ((AqlMetadataProvider) context.getMetadataProvider())
- .getMetadataDeclarations();
+ AqlMetadataProvider metadataProvider = ((AqlMetadataProvider) context.getMetadataProvider());
IVariableTypeEnvironment env = context.getOutputTypeEnvironment(op);
- if (expandFuzzyEq(expRef, context, env, aqlMetadata)) {
+ if (expandFuzzyEq(expRef, context, env, metadataProvider)) {
context.computeAndSetTypeEnvironmentForOperator(op);
return true;
}
@@ -68,7 +66,7 @@
}
private boolean expandFuzzyEq(Mutable<ILogicalExpression> expRef, IOptimizationContext context,
- IVariableTypeEnvironment env, AqlCompiledMetadataDeclarations aqlMetadata) throws AlgebricksException {
+ IVariableTypeEnvironment env, AqlMetadataProvider metadataProvider) throws AlgebricksException {
ILogicalExpression exp = expRef.getValue();
if (exp.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
@@ -85,7 +83,7 @@
// We change the behavior of this rule for the specific cases of const-var, or for edit-distance functions.
boolean useExprAsIs = false;
- String simFuncName = FuzzyUtils.getSimFunction(aqlMetadata);
+ String simFuncName = FuzzyUtils.getSimFunction(metadataProvider);
ArrayList<Mutable<ILogicalExpression>> similarityArgs = new ArrayList<Mutable<ILogicalExpression>>();
List<ATypeTag> inputExprTypes = new ArrayList<ATypeTag>();
for (int i = 0; i < 2; i++) {
@@ -144,7 +142,7 @@
similarityExp.getAnnotations().putAll(funcExp.getAnnotations());
ArrayList<Mutable<ILogicalExpression>> cmpArgs = new ArrayList<Mutable<ILogicalExpression>>();
cmpArgs.add(new MutableObject<ILogicalExpression>(similarityExp));
- IAObject simThreshold = FuzzyUtils.getSimThreshold(aqlMetadata, simFuncName);
+ IAObject simThreshold = FuzzyUtils.getSimThreshold(metadataProvider, simFuncName);
cmpArgs.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(
simThreshold))));
ScalarFunctionCallExpression cmpExpr = FuzzyUtils.getComparisonExpr(simFuncName, cmpArgs);
@@ -152,7 +150,7 @@
return true;
} else if (fi.equals(AlgebricksBuiltinFunctions.AND) || fi.equals(AlgebricksBuiltinFunctions.OR)) {
for (int i = 0; i < 2; i++) {
- if (expandFuzzyEq(funcExp.getArguments().get(i), context, env, aqlMetadata)) {
+ if (expandFuzzyEq(funcExp.getArguments().get(i), context, env, metadataProvider)) {
expanded = true;
}
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/FuzzyJoinRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/FuzzyJoinRule.java
index e700971..5961c32 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/FuzzyJoinRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/FuzzyJoinRule.java
@@ -15,7 +15,6 @@
import edu.uci.ics.asterix.aqlplus.parser.AQLPlusParser;
import edu.uci.ics.asterix.aqlplus.parser.ParseException;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
import edu.uci.ics.asterix.om.types.IAType;
@@ -47,11 +46,11 @@
public class FuzzyJoinRule implements IAlgebraicRewriteRule {
- private static HashSet<FunctionIdentifier> simFuncs = new HashSet<FunctionIdentifier>();
+ private static HashSet<FunctionIdentifier> simFuncs = new HashSet<FunctionIdentifier>();
static {
simFuncs.add(AsterixBuiltinFunctions.SIMILARITY_JACCARD_CHECK);
}
-
+
private static final String AQLPLUS = ""
//
// -- - Stage 3 - --
@@ -131,7 +130,8 @@
private Collection<LogicalVariable> liveVars = new HashSet<LogicalVariable>();
@Override
- public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
+ public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+ throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
// current opperator is join
if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN
@@ -149,15 +149,15 @@
// Check if the GET_ITEM function is on one of the supported similarity-check functions.
AbstractFunctionCallExpression getItemFuncExpr = (AbstractFunctionCallExpression) getItemExprRef.getValue();
Mutable<ILogicalExpression> argRef = getItemFuncExpr.getArguments().get(0);
- AbstractFunctionCallExpression simFuncExpr = (AbstractFunctionCallExpression) argRef.getValue();
+ AbstractFunctionCallExpression simFuncExpr = (AbstractFunctionCallExpression) argRef.getValue();
if (!simFuncs.contains(simFuncExpr.getFunctionIdentifier())) {
- return false;
+ return false;
}
// Skip this rule based on annotations.
if (simFuncExpr.getAnnotations().containsKey(IndexedNLJoinExpressionAnnotation.INSTANCE)) {
- return false;
+ return false;
}
-
+
List<Mutable<ILogicalOperator>> inputOps = joinOp.getInputs();
ILogicalOperator leftInputOp = inputOps.get(0).getValue();
ILogicalOperator rightInputOp = inputOps.get(1).getValue();
@@ -206,8 +206,7 @@
//
// -- - FIRE - --
//
- AqlCompiledMetadataDeclarations metadata = ((AqlMetadataProvider) context.getMetadataProvider())
- .getMetadataDeclarations();
+ AqlMetadataProvider metadataProvider = ((AqlMetadataProvider) context.getMetadataProvider());
FunctionIdentifier funcId = FuzzyUtils.getTokenizer(leftType.getTypeTag());
String tokenizer;
if (funcId == null) {
@@ -216,8 +215,8 @@
tokenizer = funcId.getName();
}
- float simThreshold = FuzzyUtils.getSimThreshold(metadata);
- String simFunction = FuzzyUtils.getSimFunction(metadata);
+ float simThreshold = FuzzyUtils.getSimThreshold(metadataProvider);
+ String simFunction = FuzzyUtils.getSimFunction(metadataProvider);
// finalize AQL+ query
String prepareJoin;
@@ -263,9 +262,8 @@
}
// The translator will compile metadata internally. Run this compilation
// under the same transaction id as the "outer" compilation.
- AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- AqlPlusExpressionToPlanTranslator translator = new AqlPlusExpressionToPlanTranslator(mp.getTxnId(),
- metadata.getMetadataTransactionContext(), counter, null);
+ AqlPlusExpressionToPlanTranslator translator = new AqlPlusExpressionToPlanTranslator(
+ metadataProvider.getTxnId(), metadataProvider, counter, null, null);
LogicalOperatorDeepCopyVisitor deepCopyVisitor = new LogicalOperatorDeepCopyVisitor(counter);
@@ -367,7 +365,7 @@
if (exp.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) exp;
if (funcExpr.getFunctionIdentifier().equals(AsterixBuiltinFunctions.GET_ITEM)) {
- return expRef;
+ return expRef;
}
if (funcExpr.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.AND)) {
for (int i = 0; i < 2; i++) {
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
index a9de14f..3310f4d 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
@@ -9,7 +9,6 @@
import edu.uci.ics.asterix.aql.util.FunctionUtils;
import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlDataSource;
import edu.uci.ics.asterix.metadata.declared.AqlIndex;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
@@ -89,11 +88,11 @@
InsertDeleteOperator insertOp = (InsertDeleteOperator) op1;
AqlDataSource datasetSource = (AqlDataSource) insertOp.getDataSource();
AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations metadata = mp.getMetadataDeclarations();
+ String dataverseName = datasetSource.getId().getDataverseName();
String datasetName = datasetSource.getId().getDatasetName();
- Dataset dataset = metadata.findDataset(datasetName);
+ Dataset dataset = mp.findDataset(dataverseName, datasetName);
if (dataset == null) {
- throw new AlgebricksException("Unknown dataset " + datasetName);
+ throw new AlgebricksException("Unknown dataset " + datasetName + " in dataverse " + dataverseName);
}
if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
return false;
@@ -103,12 +102,12 @@
VariableUtilities.getUsedVariables(op1, projectVars);
// Create operators for secondary index insert/delete.
String itemTypeName = dataset.getItemTypeName();
- IAType itemType = metadata.findType(itemTypeName);
+ IAType itemType = mp.findType(dataset.getDataverseName(), itemTypeName);
if (itemType.getTypeTag() != ATypeTag.RECORD) {
throw new AlgebricksException("Only record types can be indexed.");
}
ARecordType recType = (ARecordType) itemType;
- List<Index> indexes = metadata.getDatasetIndexes(dataset.getDataverseName(), dataset.getDatasetName());
+ List<Index> indexes = mp.getDatasetIndexes(dataset.getDataverseName(), dataset.getDatasetName());
ILogicalOperator currentTop = op1;
boolean hasSecondaryIndex = false;
for (Index index : indexes) {
@@ -154,7 +153,7 @@
}
Mutable<ILogicalExpression> filterExpression = createFilterExpression(secondaryKeyVars,
context.getOutputTypeEnvironment(assign), false);
- AqlIndex dataSourceIndex = new AqlIndex(index, metadata, datasetName);
+ AqlIndex dataSourceIndex = new AqlIndex(index, dataverseName, datasetName, mp);
IndexInsertDeleteOperator indexUpdate = new IndexInsertDeleteOperator(dataSourceIndex,
insertOp.getPrimaryKeyExpressions(), secondaryExpressions, filterExpression,
insertOp.getOperation());
@@ -196,7 +195,7 @@
boolean forceFilter = keyPairType.second;
Mutable<ILogicalExpression> filterExpression = createFilterExpression(keyVarList,
context.getOutputTypeEnvironment(assignCoordinates), forceFilter);
- AqlIndex dataSourceIndex = new AqlIndex(index, metadata, datasetName);
+ AqlIndex dataSourceIndex = new AqlIndex(index, dataverseName, datasetName, mp);
IndexInsertDeleteOperator indexUpdate = new IndexInsertDeleteOperator(dataSourceIndex,
insertOp.getPrimaryKeyExpressions(), secondaryExpressions, filterExpression,
insertOp.getOperation());
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushFieldAccessRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushFieldAccessRule.java
index de0ee38..da96872 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushFieldAccessRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushFieldAccessRule.java
@@ -11,7 +11,6 @@
import edu.uci.ics.asterix.algebra.base.AsterixOperatorAnnotations;
import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
import edu.uci.ics.asterix.common.exceptions.AsterixRuntimeException;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.declared.AqlSourceId;
import edu.uci.ics.asterix.metadata.entities.Dataset;
@@ -115,9 +114,8 @@
return false;
}
AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations metadata = mp.getMetadataDeclarations();
AqlSourceId asid = ((IDataSource<AqlSourceId>) scan.getDataSource()).getId();
- Dataset dataset = metadata.findDataset(asid.getDatasetName());
+ Dataset dataset = mp.findDataset(asid.getDataverseName(), asid.getDatasetName());
if (dataset == null) {
throw new AlgebricksException("Dataset " + asid.getDatasetName() + " not found.");
}
@@ -136,7 +134,7 @@
} else {
int pos = ((AInt32) obj).getIntegerValue();
String tName = dataset.getItemTypeName();
- IAType t = metadata.findType(tName);
+ IAType t = mp.findType(dataset.getDataverseName(), tName);
if (t.getTypeTag() != ATypeTag.RECORD) {
return false;
}
@@ -147,7 +145,7 @@
fldName = rt.getFieldNames()[pos];
}
- List<Index> datasetIndexes = metadata.getDatasetIndexes(dataset.getDataverseName(), dataset.getDatasetName());
+ List<Index> datasetIndexes = mp.getDatasetIndexes(dataset.getDataverseName(), dataset.getDatasetName());
boolean hasSecondaryIndex = false;
for (Index index : datasetIndexes) {
if (index.isSecondaryIndex()) {
@@ -292,8 +290,7 @@
IDataSource<AqlSourceId> dataSource = (IDataSource<AqlSourceId>) scan.getDataSource();
AqlSourceId asid = dataSource.getId();
AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations metadata = mp.getMetadataDeclarations();
- Dataset dataset = metadata.findDataset(asid.getDatasetName());
+ Dataset dataset = mp.findDataset(asid.getDataverseName(), asid.getDatasetName());
if (dataset == null) {
throw new AlgebricksException("Dataset " + asid.getDatasetName() + " not found.");
}
@@ -310,7 +307,7 @@
} else {
int pos = ((AInt32) obj).getIntegerValue();
String tName = dataset.getItemTypeName();
- IAType t = metadata.findType(tName);
+ IAType t = mp.findType(dataset.getDataverseName(), tName);
if (t.getTypeTag() != ATypeTag.RECORD) {
return false;
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/SetAsterixPhysicalOperatorsRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/SetAsterixPhysicalOperatorsRule.java
index f57cfb4..19791e3 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/SetAsterixPhysicalOperatorsRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/SetAsterixPhysicalOperatorsRule.java
@@ -150,8 +150,8 @@
AccessMethodJobGenParams jobGenParams = new AccessMethodJobGenParams();
jobGenParams.readFromFuncArgs(f.getArguments());
AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- String dataverseName = mp.getMetadataDeclarations().getDataverseName();
- AqlSourceId dataSourceId = new AqlSourceId(dataverseName, jobGenParams.getDatasetName());
+ AqlSourceId dataSourceId = new AqlSourceId(jobGenParams.getDataverseName(),
+ jobGenParams.getDatasetName());
IDataSourceIndex<String, AqlSourceId> dsi = mp.findDataSourceIndex(jobGenParams.getIndexName(),
dataSourceId);
if (dsi == null) {
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/UnnestToDataScanRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/UnnestToDataScanRule.java
index f25a671..34c5739 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/UnnestToDataScanRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/UnnestToDataScanRule.java
@@ -6,12 +6,12 @@
import org.apache.commons.lang3.mutable.Mutable;
import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlDataSource;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.declared.AqlSourceId;
import edu.uci.ics.asterix.metadata.declared.ExternalFeedDataSource;
import edu.uci.ics.asterix.metadata.entities.Dataset;
+import edu.uci.ics.asterix.metadata.entities.Dataverse;
import edu.uci.ics.asterix.metadata.utils.DatasetUtils;
import edu.uci.ics.asterix.om.base.AString;
import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
@@ -19,6 +19,7 @@
import edu.uci.ics.asterix.om.types.ATypeTag;
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
@@ -73,16 +74,19 @@
if (acv2.getObject().getType().getTypeTag() != ATypeTag.STRING) {
return false;
}
- String datasetName = ((AString) acv2.getObject()).getStringValue();
+ String datasetArg = ((AString) acv2.getObject()).getStringValue();
- AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations metadata = mp.getMetadataDeclarations();
- Dataset dataset = metadata.findDataset(datasetName);
+ AqlMetadataProvider metadataProvider = (AqlMetadataProvider) context.getMetadataProvider();
+ Pair<String, String> datasetReference = parseDatasetReference(metadataProvider, datasetArg);
+ String dataverseName = datasetReference.first;
+ String datasetName = datasetReference.second;
+ Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName);
if (dataset == null) {
- throw new AlgebricksException("Could not find dataset " + datasetName);
+ throw new AlgebricksException("Could not find dataset " + datasetName + " in dataverse "
+ + dataverseName);
}
- AqlSourceId asid = new AqlSourceId(metadata.getDataverseName(), datasetName);
+ AqlSourceId asid = new AqlSourceId(dataverseName, datasetName);
ArrayList<LogicalVariable> v = new ArrayList<LogicalVariable>();
@@ -94,7 +98,7 @@
}
v.add(unnest.getVariable());
- DataSourceScanOperator scan = new DataSourceScanOperator(v, mp.findDataSource(asid));
+ DataSourceScanOperator scan = new DataSourceScanOperator(v, metadataProvider.findDataSource(asid));
List<Mutable<ILogicalOperator>> scanInpList = scan.getInputs();
scanInpList.addAll(unnest.getInputs());
opRef.setValue(scan);
@@ -121,12 +125,13 @@
if (acv2.getObject().getType().getTypeTag() != ATypeTag.STRING) {
return false;
}
- String datasetName = ((AString) acv2.getObject()).getStringValue();
+ String datasetArg = ((AString) acv2.getObject()).getStringValue();
- AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
- AqlCompiledMetadataDeclarations metadata = mp.getMetadataDeclarations();
- Dataset dataset = metadata.findDataset(datasetName);
-
+ AqlMetadataProvider metadataProvider = (AqlMetadataProvider) context.getMetadataProvider();
+ Pair<String, String> datasetReference = parseDatasetReference(metadataProvider, datasetArg);
+ String dataverseName = datasetReference.first;
+ String datasetName = datasetReference.second;
+ Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName);
if (dataset == null) {
throw new AlgebricksException("Could not find dataset " + datasetName);
}
@@ -135,20 +140,12 @@
throw new IllegalArgumentException("invalid dataset type:" + dataset.getDatasetType());
}
- AqlSourceId asid = new AqlSourceId(metadata.getDataverseName(), datasetName);
-
+ AqlSourceId asid = new AqlSourceId(dataverseName, datasetName);
ArrayList<LogicalVariable> v = new ArrayList<LogicalVariable>();
-
- /*
- int numPrimaryKeys = DatasetUtils.getPartitioningFunctions(acdd).size();
- for (int i = 0; i < numPrimaryKeys; i++) {
- v.add(context.newVar());
- }*/
-
v.add(unnest.getVariable());
DataSourceScanOperator scan = new DataSourceScanOperator(v, createDummyFeedDataSource(asid, dataset,
- metadata));
+ metadataProvider));
List<Mutable<ILogicalOperator>> scanInpList = scan.getInputs();
scanInpList.addAll(unnest.getInputs());
@@ -163,18 +160,6 @@
return false;
}
- private AqlDataSource createDummyFeedDataSource(AqlSourceId aqlId, Dataset dataset,
- AqlCompiledMetadataDeclarations metadata) throws AlgebricksException {
- if (!aqlId.getDataverseName().equals(metadata.getDataverseName())) {
- return null;
- }
- String tName = dataset.getItemTypeName();
- IAType itemType = metadata.findType(tName);
- ExternalFeedDataSource extDataSource = new ExternalFeedDataSource(aqlId, dataset, itemType,
- AqlDataSource.AqlDataSourceType.EXTERNAL_FEED);
- return extDataSource;
- }
-
public void addPrimaryKey(List<LogicalVariable> scanVariables, IOptimizationContext context) {
int n = scanVariables.size();
List<LogicalVariable> head = new ArrayList<LogicalVariable>(scanVariables.subList(0, n - 1));
@@ -183,4 +168,37 @@
FunctionalDependency pk = new FunctionalDependency(head, tail);
context.addPrimaryKey(pk);
}
+
+ private AqlDataSource createDummyFeedDataSource(AqlSourceId aqlId, Dataset dataset,
+ AqlMetadataProvider metadataProvider) throws AlgebricksException {
+ if (!aqlId.getDataverseName().equals(
+ metadataProvider.getDefaultDataverse() == null ? null : metadataProvider.getDefaultDataverse()
+ .getDataverseName())) {
+ return null;
+ }
+ String tName = dataset.getItemTypeName();
+ IAType itemType = metadataProvider.findType(dataset.getDataverseName(), tName);
+ ExternalFeedDataSource extDataSource = new ExternalFeedDataSource(aqlId, dataset, itemType,
+ AqlDataSource.AqlDataSourceType.EXTERNAL_FEED);
+ return extDataSource;
+ }
+
+ private Pair<String, String> parseDatasetReference(AqlMetadataProvider metadataProvider, String datasetArg)
+ throws AlgebricksException {
+ String[] datasetNameComponents = datasetArg.split("\\.");
+ String dataverseName;
+ String datasetName;
+ if (datasetNameComponents.length == 1) {
+ Dataverse defaultDataverse = metadataProvider.getDefaultDataverse();
+ if (defaultDataverse == null) {
+ throw new AlgebricksException("Unresolved dataset " + datasetArg + " Dataverse not specified.");
+ }
+ dataverseName = defaultDataverse.getDataverseName();
+ datasetName = datasetNameComponents[0];
+ } else {
+ dataverseName = datasetNameComponents[0];
+ datasetName = datasetNameComponents[1];
+ }
+ return new Pair<String, String>(dataverseName, datasetName);
+ }
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
index c7cdd57..8bfef17 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
@@ -7,7 +7,6 @@
import org.apache.commons.lang3.mutable.Mutable;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.entities.Dataset;
import edu.uci.ics.asterix.metadata.entities.Index;
@@ -37,7 +36,7 @@
*/
public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRewriteRule {
- private AqlCompiledMetadataDeclarations metadata;
+ private AqlMetadataProvider metadataProvider;
public abstract Map<FunctionIdentifier, List<IAccessMethod>> getAccessMethods();
@@ -60,8 +59,7 @@
}
protected void setMetadataDeclarations(IOptimizationContext context) {
- AqlMetadataProvider metadataProvider = (AqlMetadataProvider) context.getMetadataProvider();
- metadata = metadataProvider.getMetadataDeclarations();
+ metadataProvider = (AqlMetadataProvider) context.getMetadataProvider();
}
protected void fillSubTreeIndexExprs(OptimizableOperatorSubTree subTree,
@@ -234,7 +232,8 @@
*/
protected boolean fillIndexExprs(String fieldName, int matchedFuncExprIndex, Dataset dataset,
AccessMethodAnalysisContext analysisCtx) throws AlgebricksException {
- List<Index> datasetIndexes = metadata.getDatasetIndexes(dataset.getDataverseName(), dataset.getDatasetName());
+ List<Index> datasetIndexes = metadataProvider.getDatasetIndexes(dataset.getDataverseName(),
+ dataset.getDatasetName());
List<Index> indexCandidates = new ArrayList<Index>();
// Add an index to the candidates if one of the indexed fields is fieldName.
for (Index index : datasetIndexes) {
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodJobGenParams.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodJobGenParams.java
index 93099e9..e3a9e91 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodJobGenParams.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodJobGenParams.java
@@ -20,20 +20,22 @@
public class AccessMethodJobGenParams {
protected String indexName;
protected IndexType indexType;
+ protected String dataverseName;
protected String datasetName;
protected boolean retainInput;
protected boolean requiresBroadcast;
protected boolean isPrimaryIndex;
-
- private final int NUM_PARAMS = 5;
+
+ private final int NUM_PARAMS = 6;
public AccessMethodJobGenParams() {
}
- public AccessMethodJobGenParams(String indexName, IndexType indexType, String datasetName, boolean retainInput,
- boolean requiresBroadcast) {
+ public AccessMethodJobGenParams(String indexName, IndexType indexType, String dataverseName, String datasetName,
+ boolean retainInput, boolean requiresBroadcast) {
this.indexName = indexName;
this.indexType = indexType;
+ this.dataverseName = dataverseName;
this.datasetName = datasetName;
this.retainInput = retainInput;
this.requiresBroadcast = requiresBroadcast;
@@ -43,6 +45,7 @@
public void writeToFuncArgs(List<Mutable<ILogicalExpression>> funcArgs) {
funcArgs.add(new MutableObject<ILogicalExpression>(AccessMethodUtils.createStringConstant(indexName)));
funcArgs.add(new MutableObject<ILogicalExpression>(AccessMethodUtils.createInt32Constant(indexType.ordinal())));
+ funcArgs.add(new MutableObject<ILogicalExpression>(AccessMethodUtils.createStringConstant(dataverseName)));
funcArgs.add(new MutableObject<ILogicalExpression>(AccessMethodUtils.createStringConstant(datasetName)));
funcArgs.add(new MutableObject<ILogicalExpression>(AccessMethodUtils.createBooleanConstant(retainInput)));
funcArgs.add(new MutableObject<ILogicalExpression>(AccessMethodUtils.createBooleanConstant(requiresBroadcast)));
@@ -51,9 +54,11 @@
public void readFromFuncArgs(List<Mutable<ILogicalExpression>> funcArgs) {
indexName = AccessMethodUtils.getStringConstant(funcArgs.get(0));
indexType = IndexType.values()[AccessMethodUtils.getInt32Constant(funcArgs.get(1))];
- datasetName = AccessMethodUtils.getStringConstant(funcArgs.get(2));
- retainInput = AccessMethodUtils.getBooleanConstant(funcArgs.get(3));
- requiresBroadcast = AccessMethodUtils.getBooleanConstant(funcArgs.get(4));
+ dataverseName = AccessMethodUtils.getStringConstant(funcArgs.get(2));
+ datasetName = AccessMethodUtils.getStringConstant(funcArgs.get(3));
+ retainInput = AccessMethodUtils.getBooleanConstant(funcArgs.get(4));
+ requiresBroadcast = AccessMethodUtils.getBooleanConstant(funcArgs.get(5));
+ isPrimaryIndex = datasetName.equals(indexName);
isPrimaryIndex = datasetName.equals(indexName);
}
@@ -65,6 +70,10 @@
return indexType;
}
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
public String getDatasetName() {
return datasetName;
}
@@ -103,7 +112,7 @@
protected int getNumParams() {
return NUM_PARAMS;
}
-
+
public boolean isPrimaryIndex() {
return isPrimaryIndex;
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodUtils.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodUtils.java
index 24bd8ed..3215707 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodUtils.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodUtils.java
@@ -287,7 +287,7 @@
// The job gen parameters are transferred to the actual job gen via the UnnestMapOperator's function arguments.
List<Mutable<ILogicalExpression>> primaryIndexFuncArgs = new ArrayList<Mutable<ILogicalExpression>>();
BTreeJobGenParams jobGenParams = new BTreeJobGenParams(dataset.getDatasetName(), IndexType.BTREE,
- dataset.getDatasetName(), retainInput, requiresBroadcast);
+ dataset.getDataverseName(), dataset.getDatasetName(), retainInput, requiresBroadcast);
// Set low/high inclusive to true for a point lookup.
jobGenParams.setLowKeyInclusive(true);
jobGenParams.setHighKeyInclusive(true);
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeAccessMethod.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeAccessMethod.java
index 9580d37..970cd89 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeAccessMethod.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeAccessMethod.java
@@ -145,14 +145,14 @@
indexSubTree = rightSubTree;
probeSubTree = leftSubTree;
}
- ILogicalOperator primaryIndexUnnestOp = createSecondaryToPrimaryPlan(joinRef, conditionRef, indexSubTree, probeSubTree,
- chosenIndex, analysisCtx, true, true, context);
+ ILogicalOperator primaryIndexUnnestOp = createSecondaryToPrimaryPlan(joinRef, conditionRef, indexSubTree,
+ probeSubTree, chosenIndex, analysisCtx, true, true, context);
if (primaryIndexUnnestOp == null) {
return false;
}
// If there are conditions left, add a new select operator on top.
indexSubTree.dataSourceScanRef.setValue(primaryIndexUnnestOp);
- if (conditionRef.getValue() != null) {
+ if (conditionRef.getValue() != null) {
SelectOperator topSelect = new SelectOperator(conditionRef);
topSelect.getInputs().add(indexSubTree.rootRef);
topSelect.setExecutionMode(ExecutionMode.LOCAL);
@@ -164,9 +164,9 @@
}
return true;
}
-
- private ILogicalOperator createSecondaryToPrimaryPlan(Mutable<ILogicalOperator> topOpRef, Mutable<ILogicalExpression> conditionRef,
- OptimizableOperatorSubTree indexSubTree,
+
+ private ILogicalOperator createSecondaryToPrimaryPlan(Mutable<ILogicalOperator> topOpRef,
+ Mutable<ILogicalExpression> conditionRef, OptimizableOperatorSubTree indexSubTree,
OptimizableOperatorSubTree probeSubTree, Index chosenIndex, AccessMethodAnalysisContext analysisCtx,
boolean retainInput, boolean requiresBroadcast, IOptimizationContext context) throws AlgebricksException {
Dataset dataset = indexSubTree.dataset;
@@ -219,10 +219,9 @@
}
// TODO: For now don't consider prefix searches.
// If high and low keys are set, we exit for now.
- if (setLowKeys.cardinality() == numSecondaryKeys
- && setHighKeys.cardinality() == numSecondaryKeys) {
+ if (setLowKeys.cardinality() == numSecondaryKeys && setHighKeys.cardinality() == numSecondaryKeys) {
doneWithExprs = true;
- }
+ }
break;
}
case HIGH_EXCLUSIVE: {
@@ -312,12 +311,14 @@
ArrayList<LogicalVariable> keyVarList = new ArrayList<LogicalVariable>();
// List of variables and expressions for the assign.
ArrayList<LogicalVariable> assignKeyVarList = new ArrayList<LogicalVariable>();
- ArrayList<Mutable<ILogicalExpression>> assignKeyExprList = new ArrayList<Mutable<ILogicalExpression>>();
- int numLowKeys = createKeyVarsAndExprs(lowKeyLimits, lowKeyExprs, assignKeyVarList, assignKeyExprList, keyVarList, context);
- int numHighKeys = createKeyVarsAndExprs(highKeyLimits, highKeyExprs, assignKeyVarList, assignKeyExprList, keyVarList, context);
+ ArrayList<Mutable<ILogicalExpression>> assignKeyExprList = new ArrayList<Mutable<ILogicalExpression>>();
+ int numLowKeys = createKeyVarsAndExprs(lowKeyLimits, lowKeyExprs, assignKeyVarList, assignKeyExprList,
+ keyVarList, context);
+ int numHighKeys = createKeyVarsAndExprs(highKeyLimits, highKeyExprs, assignKeyVarList, assignKeyExprList,
+ keyVarList, context);
BTreeJobGenParams jobGenParams = new BTreeJobGenParams(chosenIndex.getIndexName(), IndexType.BTREE,
- dataset.getDatasetName(), retainInput, requiresBroadcast);
+ dataset.getDataverseName(), dataset.getDatasetName(), retainInput, requiresBroadcast);
jobGenParams.setLowKeyInclusive(lowKeyInclusive[0]);
jobGenParams.setHighKeyInclusive(highKeyInclusive[0]);
jobGenParams.setLowKeyVarList(keyVarList, 0, numLowKeys);
@@ -364,7 +365,7 @@
}
return primaryIndexUnnestOp;
}
-
+
private int createKeyVarsAndExprs(LimitType[] keyLimits, ILogicalExpression[] searchKeyExprs,
ArrayList<LogicalVariable> assignKeyVarList, ArrayList<Mutable<ILogicalExpression>> assignKeyExprList,
ArrayList<LogicalVariable> keyVarList, IOptimizationContext context) {
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeJobGenParams.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeJobGenParams.java
index c377a34..9a735c9 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeJobGenParams.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeJobGenParams.java
@@ -27,9 +27,9 @@
super();
}
- public BTreeJobGenParams(String indexName, IndexType indexType, String datasetName, boolean retainInput,
+ public BTreeJobGenParams(String indexName, IndexType indexType, String dataverseName, String datasetName, boolean retainInput,
boolean requiresBroadcast) {
- super(indexName, indexType, datasetName, retainInput, requiresBroadcast);
+ super(indexName, indexType, dataverseName, datasetName, retainInput, requiresBroadcast);
}
public void setLowKeyVarList(List<LogicalVariable> keyVarList, int startIndex, int numKeys) {
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
index 1715c97..0ab749d 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
@@ -320,7 +320,8 @@
DataSourceScanOperator dataSourceScan = indexSubTree.dataSourceScan;
InvertedIndexJobGenParams jobGenParams = new InvertedIndexJobGenParams(chosenIndex.getIndexName(),
- chosenIndex.getIndexType(), dataset.getDatasetName(), retainInput, requiresBroadcast);
+ chosenIndex.getIndexType(), dataset.getDataverseName(), dataset.getDatasetName(), retainInput,
+ requiresBroadcast);
// Add function-specific args such as search modifier, and possibly a similarity threshold.
addFunctionSpecificArgs(optFuncExpr, jobGenParams);
// Add the type of search key from the optFuncExpr.
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexJobGenParams.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexJobGenParams.java
index 530606e..65473c7 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexJobGenParams.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexJobGenParams.java
@@ -30,9 +30,9 @@
public InvertedIndexJobGenParams() {
}
- public InvertedIndexJobGenParams(String indexName, IndexType indexType, String datasetName, boolean retainInput,
- boolean requiresBroadcast) {
- super(indexName, indexType, datasetName, retainInput, requiresBroadcast);
+ public InvertedIndexJobGenParams(String indexName, IndexType indexType, String dataverseName, String datasetName,
+ boolean retainInput, boolean requiresBroadcast) {
+ super(indexName, indexType, dataverseName, datasetName, retainInput, requiresBroadcast);
}
public void setSearchModifierType(SearchModifierType searchModifierType) {
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/OptimizableOperatorSubTree.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/OptimizableOperatorSubTree.java
index 812bb14..3269be7 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/OptimizableOperatorSubTree.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/OptimizableOperatorSubTree.java
@@ -6,7 +6,6 @@
import org.apache.commons.lang3.mutable.Mutable;
import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.entities.Dataset;
import edu.uci.ics.asterix.om.types.ARecordType;
@@ -14,6 +13,7 @@
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.asterix.optimizer.base.AnalysisUtil;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
@@ -88,12 +88,13 @@
return false;
}
// Find the dataset corresponding to the datasource scan in the metadata.
- String datasetName = AnalysisUtil.getDatasetName(dataSourceScan);
- if (datasetName == null) {
+ Pair<String, String> datasetInfo = AnalysisUtil.getDatasetInfo(dataSourceScan);
+ String dataverseName = datasetInfo.first;
+ String datasetName = datasetInfo.second;
+ if (dataverseName == null || datasetName == null) {
return false;
}
- AqlCompiledMetadataDeclarations metadata = metadataProvider.getMetadataDeclarations();
- dataset = metadata.findDataset(datasetName);
+ dataset = metadataProvider.findDataset(dataverseName, datasetName);
if (dataset == null) {
throw new AlgebricksException("No metadata for dataset " + datasetName);
}
@@ -101,7 +102,7 @@
return false;
}
// Get the record type for that dataset.
- IAType itemType = metadata.findType(dataset.getItemTypeName());
+ IAType itemType = metadataProvider.findType(dataverseName, dataset.getItemTypeName());
if (itemType.getTypeTag() != ATypeTag.RECORD) {
return false;
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeAccessMethod.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeAccessMethod.java
index 231a6d8..45cce9c 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeAccessMethod.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeAccessMethod.java
@@ -136,7 +136,7 @@
DataSourceScanOperator dataSourceScan = indexSubTree.dataSourceScan;
RTreeJobGenParams jobGenParams = new RTreeJobGenParams(chosenIndex.getIndexName(), IndexType.RTREE,
- dataset.getDatasetName(), retainInput, requiresBroadcast);
+ dataset.getDataverseName(), dataset.getDatasetName(), retainInput, requiresBroadcast);
// A spatial object is serialized in the constant of the func expr we are optimizing.
// The R-Tree expects as input an MBR represented with 1 field per dimension.
// Here we generate vars and funcs for extracting MBR fields from the constant into fields of a tuple (as the R-Tree expects them).
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeJobGenParams.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeJobGenParams.java
index b3153f9..846bcb6 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeJobGenParams.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/RTreeJobGenParams.java
@@ -20,9 +20,9 @@
public RTreeJobGenParams() {
}
- public RTreeJobGenParams(String indexName, IndexType indexType, String datasetName, boolean retainInput,
- boolean requiresBroadcast) {
- super(indexName, indexType, datasetName, retainInput, requiresBroadcast);
+ public RTreeJobGenParams(String indexName, IndexType indexType, String dataverseName, String datasetName,
+ boolean retainInput, boolean requiresBroadcast) {
+ super(indexName, indexType, dataverseName, datasetName, retainInput, requiresBroadcast);
}
public void writeToFuncArgs(List<Mutable<ILogicalExpression>> funcArgs) {
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AbstractAqlTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AbstractAqlTranslator.java
index 5f31bd1..a908363 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AbstractAqlTranslator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AbstractAqlTranslator.java
@@ -1,89 +1,77 @@
package edu.uci.ics.asterix.translator;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import edu.uci.ics.asterix.aql.base.Statement;
-import edu.uci.ics.asterix.aql.expression.DataverseDecl;
-import edu.uci.ics.asterix.aql.expression.SetStatement;
-import edu.uci.ics.asterix.aql.expression.TypeDecl;
-import edu.uci.ics.asterix.aql.expression.WriteStatement;
-import edu.uci.ics.asterix.metadata.MetadataException;
-import edu.uci.ics.asterix.metadata.MetadataTransactionContext;
+import edu.uci.ics.asterix.aql.expression.DataverseDropStatement;
+import edu.uci.ics.asterix.aql.expression.DropStatement;
+import edu.uci.ics.asterix.aql.expression.FunctionDropStatement;
+import edu.uci.ics.asterix.aql.expression.NodeGroupDropStatement;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.common.functions.FunctionSignature;
import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.data.IAWriterFactory;
-import edu.uci.ics.hyracks.algebricks.runtime.writers.PrinterBasedWriterFactory;
-import edu.uci.ics.hyracks.api.io.FileReference;
-import edu.uci.ics.hyracks.dataflow.std.file.FileSplit;
+import edu.uci.ics.asterix.metadata.entities.AsterixBuiltinArtifactMap;
+import edu.uci.ics.asterix.metadata.entities.AsterixBuiltinArtifactMap.ARTIFACT_KIND;
+import edu.uci.ics.asterix.metadata.entities.AsterixBuiltinTypeMap;
+import edu.uci.ics.asterix.metadata.entities.Dataverse;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
public abstract class AbstractAqlTranslator {
- public AqlCompiledMetadataDeclarations compileMetadata(MetadataTransactionContext mdTxnCtx,
- List<Statement> statements, boolean online) throws AlgebricksException, MetadataException {
- List<TypeDecl> typeDeclarations = new ArrayList<TypeDecl>();
- Map<String, String> config = new HashMap<String, String>();
+ protected static final Map<String, BuiltinType> builtinTypeMap = AsterixBuiltinTypeMap.getBuiltinTypes();
- FileSplit outputFile = null;
- IAWriterFactory writerFactory = null;
- String dataverseName = MetadataConstants.METADATA_DATAVERSE_NAME;
- for (Statement stmt : statements) {
+ public void validateOperation(Dataverse dataverse, Statement stmt) throws AsterixException {
+ String dataverseName = dataverse != null ? dataverse.getDataverseName() : null;
+ if (dataverseName != null && dataverseName.equals(MetadataConstants.METADATA_DATAVERSE_NAME)) {
+
+ boolean invalidOperation = false;
+ String message = null;
switch (stmt.getKind()) {
- case TYPE_DECL: {
- typeDeclarations.add((TypeDecl) stmt);
+ case INSERT:
+ case UPDATE:
+ case DELETE:
+ invalidOperation = true;
+ message = " Operation " + stmt.getKind() + " not permitted in system dataverse " + "'"
+ + MetadataConstants.METADATA_DATAVERSE_NAME + "'";
break;
- }
- case DATAVERSE_DECL: {
- DataverseDecl dstmt = (DataverseDecl) stmt;
- dataverseName = dstmt.getDataverseName().toString();
- break;
- }
- case WRITE: {
- if (outputFile != null) {
- throw new AlgebricksException("Multiple 'write' statements.");
- }
- WriteStatement ws = (WriteStatement) stmt;
- File f = new File(ws.getFileName());
- outputFile = new FileSplit(ws.getNcName().getValue(), new FileReference(f));
- if (ws.getWriterClassName() != null) {
- try {
- writerFactory = (IAWriterFactory) Class.forName(ws.getWriterClassName()).newInstance();
- } catch (Exception e) {
- throw new AlgebricksException(e);
- }
+ case FUNCTION_DROP:
+ FunctionSignature signature = ((FunctionDropStatement) stmt).getFunctionSignature();
+ FunctionIdentifier fId = new FunctionIdentifier(signature.getNamespace(), signature.getName(),
+ signature.getArity());
+ if (dataverseName.equals(MetadataConstants.METADATA_DATAVERSE_NAME)
+ && AsterixBuiltinArtifactMap.isSystemProtectedArtifact(ARTIFACT_KIND.FUNCTION, fId)) {
+ invalidOperation = true;
+ message = "Cannot drop function " + signature + " (protected by system)";
}
break;
- }
- case SET: {
- SetStatement ss = (SetStatement) stmt;
- String pname = ss.getPropName();
- String pvalue = ss.getPropValue();
- config.put(pname, pvalue);
+ case NODEGROUP_DROP:
+ NodeGroupDropStatement nodeGroupDropStmt = (NodeGroupDropStatement) stmt;
+ String nodegroupName = nodeGroupDropStmt.getNodeGroupName().getValue();
+ if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(ARTIFACT_KIND.NODEGROUP, nodegroupName)) {
+ message = "Cannot drop nodegroup " + nodegroupName + " (protected by system)";
+ invalidOperation = true;
+ }
break;
- }
+ case DATAVERSE_DROP:
+ DataverseDropStatement dvDropStmt = (DataverseDropStatement) stmt;
+ String dvName = dvDropStmt.getDataverseName().getValue();
+ if (dvName.equals(MetadataConstants.METADATA_DATAVERSE_NAME)) {
+ message = "Cannot drop dataverse " + dvName + " (protected by system)";
+ invalidOperation = true;
+ }
+ break;
+ case DATASET_DROP:
+ DropStatement dropStmt = (DropStatement) stmt;
+ String datasetName = dropStmt.getDatasetName().getValue();
+ if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(ARTIFACT_KIND.DATASET, datasetName)) {
+ invalidOperation = true;
+ message = "Cannot drop dataset " + datasetName + " (protected by system)";
+ }
+ break;
}
- }
- if (writerFactory == null) {
- writerFactory = PrinterBasedWriterFactory.INSTANCE;
- }
-
- MetadataDeclTranslator metadataTranslator = new MetadataDeclTranslator(mdTxnCtx, dataverseName, outputFile,
- writerFactory, config, typeDeclarations);
- return metadataTranslator.computeMetadataDeclarations(online);
- }
-
- public void validateOperation(AqlCompiledMetadataDeclarations compiledDeclarations, Statement stmt)
- throws AlgebricksException {
- if (compiledDeclarations.getDataverseName() != null
- && compiledDeclarations.getDataverseName().equals(MetadataConstants.METADATA_DATAVERSE_NAME)) {
- if (stmt.getKind() == Statement.Kind.INSERT || stmt.getKind() == Statement.Kind.UPDATE
- || stmt.getKind() == Statement.Kind.DELETE) {
- throw new AlgebricksException(" Operation " + stmt.getKind() + " not permitted in system dataverse-"
- + MetadataConstants.METADATA_DATAVERSE_NAME);
+ if (invalidOperation) {
+ throw new AsterixException(message);
}
}
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
index e5712df..59d5291 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
@@ -12,7 +12,6 @@
import edu.uci.ics.asterix.aql.base.Clause;
import edu.uci.ics.asterix.aql.base.Expression;
import edu.uci.ics.asterix.aql.base.Expression.Kind;
-import edu.uci.ics.asterix.aql.base.Statement;
import edu.uci.ics.asterix.aql.expression.BeginFeedStatement;
import edu.uci.ics.asterix.aql.expression.CallExpr;
import edu.uci.ics.asterix.aql.expression.ControlFeedStatement;
@@ -76,27 +75,28 @@
import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.functions.FunctionSignature;
import edu.uci.ics.asterix.formats.base.IDataFormat;
import edu.uci.ics.asterix.metadata.MetadataException;
-import edu.uci.ics.asterix.metadata.MetadataTransactionContext;
+import edu.uci.ics.asterix.metadata.MetadataManager;
import edu.uci.ics.asterix.metadata.bootstrap.AsterixProperties;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
import edu.uci.ics.asterix.metadata.declared.AqlDataSource;
-import edu.uci.ics.asterix.metadata.declared.AqlLogicalPlanAndMetadataImpl;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.declared.AqlSourceId;
import edu.uci.ics.asterix.metadata.declared.FileSplitDataSink;
import edu.uci.ics.asterix.metadata.declared.FileSplitSinkId;
import edu.uci.ics.asterix.metadata.entities.Dataset;
+import edu.uci.ics.asterix.metadata.entities.Function;
import edu.uci.ics.asterix.metadata.utils.DatasetUtils;
import edu.uci.ics.asterix.om.base.AInt32;
import edu.uci.ics.asterix.om.base.AString;
import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.asterix.om.functions.AsterixFunction;
import edu.uci.ics.asterix.om.functions.AsterixFunctionInfo;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.runtime.formats.FormatUtils;
+import edu.uci.ics.asterix.translator.CompiledStatements.ICompiledDmlStatement;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
@@ -105,7 +105,6 @@
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlanAndMetadata;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.OperatorAnnotations;
@@ -155,1521 +154,1297 @@
* source for the current subtree.
*/
-public class AqlExpressionToPlanTranslator extends AbstractAqlTranslator
- implements
- IAqlExpressionVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
+public class AqlExpressionToPlanTranslator extends AbstractAqlTranslator implements
+ IAqlExpressionVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
- private final MetadataTransactionContext mdTxnCtx;
- private final long txnId;
- private TranslationContext context;
- private String outputDatasetName;
- private Statement.Kind dmlKind;
- private static AtomicLong outputFileID = new AtomicLong(0);
- private static final String OUTPUT_FILE_PREFIX = "OUTPUT_";
+ private final AqlMetadataProvider metadataProvider;
+ private final TranslationContext context;
+ private final String outputDatasetName;
+ private final ICompiledDmlStatement stmt;
+ private static AtomicLong outputFileID = new AtomicLong(0);
+ private static final String OUTPUT_FILE_PREFIX = "OUTPUT_";
- private static LogicalVariable METADATA_DUMMY_VAR = new LogicalVariable(-1);
+ private static LogicalVariable METADATA_DUMMY_VAR = new LogicalVariable(-1);
- public AqlExpressionToPlanTranslator(long txnId,
- MetadataTransactionContext mdTxnCtx, int currentVarCounter,
- String outputDatasetName, Statement.Kind dmlKind) {
- this.mdTxnCtx = mdTxnCtx;
- this.txnId = txnId;
- this.context = new TranslationContext(new Counter(currentVarCounter));
- this.outputDatasetName = outputDatasetName;
- this.dmlKind = dmlKind;
- }
+ public AqlExpressionToPlanTranslator(AqlMetadataProvider metadataProvider, int currentVarCounter,
+ String outputDatasetName, ICompiledDmlStatement stmt) {
+ this.context = new TranslationContext(new Counter(currentVarCounter));
+ this.outputDatasetName = outputDatasetName;
+ this.stmt = stmt;
+ this.metadataProvider = metadataProvider;
+ }
- public int getVarCounter() {
- return context.getVarCounter();
- }
+ public int getVarCounter() {
+ return context.getVarCounter();
+ }
- public ILogicalPlanAndMetadata translate(Query expr,
- AqlCompiledMetadataDeclarations compiledDeclarations)
- throws AlgebricksException, AsterixException {
- if (expr == null) {
- return null;
- }
- if (compiledDeclarations == null) {
- compiledDeclarations = compileMetadata(mdTxnCtx,
- expr.getPrologDeclList(), true);
- }
- if (!compiledDeclarations.isConnectedToDataverse())
- compiledDeclarations.connectToDataverse(compiledDeclarations
- .getDataverseName());
- IDataFormat format = compiledDeclarations.getFormat();
- if (format == null) {
- throw new AlgebricksException("Data format has not been set.");
- }
- format.registerRuntimeFunctions();
- Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
- new MutableObject<ILogicalOperator>(
- new EmptyTupleSourceOperator()));
+ public ILogicalPlan translate(Query expr) throws AlgebricksException, AsterixException {
+ IDataFormat format = FormatUtils.getDefaultFormat();
+ format.registerRuntimeFunctions();
- ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
+ Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, new MutableObject<ILogicalOperator>(
+ new EmptyTupleSourceOperator()));
- boolean isTransactionalWrite = false;
- ILogicalOperator topOp = p.first;
- ProjectOperator project = (ProjectOperator) topOp;
- LogicalVariable resVar = project.getVariables().get(0);
- if (outputDatasetName == null) {
- FileSplit outputFileSplit = compiledDeclarations.getOutputFile();
- if (outputFileSplit == null) {
- outputFileSplit = getDefaultOutputFileLocation();
- }
- compiledDeclarations.setOutputFile(outputFileSplit);
- List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- writeExprList.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(resVar)));
- FileSplitSinkId fssi = new FileSplitSinkId(outputFileSplit);
- FileSplitDataSink sink = new FileSplitDataSink(fssi, null);
- topOp = new WriteOperator(writeExprList, sink);
- topOp.getInputs().add(new MutableObject<ILogicalOperator>(project));
- } else {
- String dataVerseName = compiledDeclarations.getDataverseName();
- Dataset dataset = compiledDeclarations
- .findDataset(outputDatasetName);
- if (dataset == null) {
- throw new AlgebricksException("Cannot find dataset "
- + outputDatasetName);
- }
+ ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
- AqlSourceId sourceId = new AqlSourceId(dataVerseName,
- outputDatasetName);
- String itemTypeName = dataset.getItemTypeName();
- IAType itemType = compiledDeclarations.findType(itemTypeName);
- AqlDataSource dataSource = new AqlDataSource(sourceId, dataset,
- itemType);
- if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
- throw new AlgebricksException(
- "Cannot write output to an external dataset.");
- }
- ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>();
- ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
- List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>();
+ boolean isTransactionalWrite = false;
+ ILogicalOperator topOp = p.first;
+ ProjectOperator project = (ProjectOperator) topOp;
+ LogicalVariable resVar = project.getVariables().get(0);
+ if (outputDatasetName == null) {
+ FileSplit outputFileSplit = metadataProvider.getOutputFile();
+ if (outputFileSplit == null) {
+ outputFileSplit = getDefaultOutputFileLocation();
+ }
+ metadataProvider.setOutputFile(outputFileSplit);
+ List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(1);
+ writeExprList.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(resVar)));
+ FileSplitSinkId fssi = new FileSplitSinkId(outputFileSplit);
+ FileSplitDataSink sink = new FileSplitDataSink(fssi, null);
+ topOp = new WriteOperator(writeExprList, sink);
+ topOp.getInputs().add(new MutableObject<ILogicalOperator>(project));
+ } else {
- List<String> partitionKeys = DatasetUtils
- .getPartitioningKeys(dataset);
- for (String keyFieldName : partitionKeys) {
- IFunctionInfo finfoAccess = AsterixBuiltinFunctions
- .getAsterixFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME);
- @SuppressWarnings("unchecked")
- ScalarFunctionCallExpression f = new ScalarFunctionCallExpression(
- finfoAccess, new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(
- METADATA_DUMMY_VAR)),
- new MutableObject<ILogicalExpression>(
- new ConstantExpression(
- new AsterixConstantValue(new AString(
- keyFieldName)))));
- f.substituteVar(METADATA_DUMMY_VAR, resVar);
- exprs.add(new MutableObject<ILogicalExpression>(f));
- LogicalVariable v = context.newVar();
- vars.add(v);
- varRefsForLoading.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(v)));
- }
- AssignOperator assign = new AssignOperator(vars, exprs);
- assign.getInputs()
- .add(new MutableObject<ILogicalOperator>(project));
+ AqlDataSource targetDatasource = validateDatasetInfo(metadataProvider, stmt.getDataverseName(),
+ stmt.getDatasetName());
- Mutable<ILogicalExpression> varRef = new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(resVar));
- ILogicalOperator load = null;
+ ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>();
+ ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
+ List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>();
- switch (dmlKind) {
- case WRITE_FROM_QUERY_RESULT: {
- load = new WriteResultOperator(dataSource, varRef,
- varRefsForLoading);
- load.getInputs().add(
- new MutableObject<ILogicalOperator>(assign));
- break;
- }
- case INSERT: {
- ILogicalOperator insertOp = new InsertDeleteOperator(
- dataSource, varRef, varRefsForLoading,
- InsertDeleteOperator.Kind.INSERT);
- insertOp.getInputs().add(
- new MutableObject<ILogicalOperator>(assign));
- load = new SinkOperator();
- load.getInputs().add(
- new MutableObject<ILogicalOperator>(insertOp));
- isTransactionalWrite = true;
- break;
- }
- case DELETE: {
- ILogicalOperator deleteOp = new InsertDeleteOperator(
- dataSource, varRef, varRefsForLoading,
- InsertDeleteOperator.Kind.DELETE);
- deleteOp.getInputs().add(
- new MutableObject<ILogicalOperator>(assign));
- load = new SinkOperator();
- load.getInputs().add(
- new MutableObject<ILogicalOperator>(deleteOp));
- isTransactionalWrite = true;
- break;
- }
- case BEGIN_FEED: {
- ILogicalOperator insertOp = new InsertDeleteOperator(
- dataSource, varRef, varRefsForLoading,
- InsertDeleteOperator.Kind.INSERT);
- insertOp.getInputs().add(
- new MutableObject<ILogicalOperator>(assign));
- load = new SinkOperator();
- load.getInputs().add(
- new MutableObject<ILogicalOperator>(insertOp));
- isTransactionalWrite = false;
- break;
- }
- }
- topOp = load;
- }
+ List<String> partitionKeys = DatasetUtils.getPartitioningKeys(targetDatasource.getDataset());
+ for (String keyFieldName : partitionKeys) {
+ IFunctionInfo finfoAccess = AsterixBuiltinFunctions
+ .getAsterixFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME);
+ @SuppressWarnings("unchecked")
+ ScalarFunctionCallExpression f = new ScalarFunctionCallExpression(finfoAccess,
+ new MutableObject<ILogicalExpression>(new VariableReferenceExpression(METADATA_DUMMY_VAR)),
+ new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(
+ new AString(keyFieldName)))));
+ f.substituteVar(METADATA_DUMMY_VAR, resVar);
+ exprs.add(new MutableObject<ILogicalExpression>(f));
+ LogicalVariable v = context.newVar();
+ vars.add(v);
+ varRefsForLoading.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v)));
+ }
+ AssignOperator assign = new AssignOperator(vars, exprs);
+ assign.getInputs().add(new MutableObject<ILogicalOperator>(project));
- globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
- ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
- AqlMetadataProvider metadataProvider = new AqlMetadataProvider(txnId,
- isTransactionalWrite, compiledDeclarations);
- ILogicalPlanAndMetadata planAndMetadata = new AqlLogicalPlanAndMetadataImpl(
- plan, metadataProvider);
- return planAndMetadata;
- }
+ Mutable<ILogicalExpression> varRef = new MutableObject<ILogicalExpression>(new VariableReferenceExpression(
+ resVar));
+ ILogicalOperator leafOperator = null;
- private FileSplit getDefaultOutputFileLocation() throws MetadataException {
- if (AsterixProperties.INSTANCE.getOutputDir() == null) {
- throw new MetadataException(
- "Output location for query result not specified at the time of deployment, must specify explicitly using 'write output to ..' statement");
- }
- String filePath = AsterixProperties.INSTANCE.getOutputDir()
- + System.getProperty("file.separator") + OUTPUT_FILE_PREFIX
- + outputFileID.incrementAndGet();
- return new FileSplit(AsterixProperties.INSTANCE.getMetadataNodeName(),
- new FileReference(new File(filePath)));
- }
+ switch (stmt.getKind()) {
+ case WRITE_FROM_QUERY_RESULT: {
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitForClause(ForClause fc,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- LogicalVariable v = context.newVar(fc.getVarExpr());
+ leafOperator = new WriteResultOperator(targetDatasource, varRef, varRefsForLoading);
+ leafOperator.getInputs().add(new MutableObject<ILogicalOperator>(assign));
+ break;
+ }
+ case INSERT: {
+ ILogicalOperator insertOp = new InsertDeleteOperator(targetDatasource, varRef, varRefsForLoading,
+ InsertDeleteOperator.Kind.INSERT);
+ insertOp.getInputs().add(new MutableObject<ILogicalOperator>(assign));
+ leafOperator = new SinkOperator();
+ leafOperator.getInputs().add(new MutableObject<ILogicalOperator>(insertOp));
+ isTransactionalWrite = true;
+ break;
+ }
+ case DELETE: {
+ ILogicalOperator deleteOp = new InsertDeleteOperator(targetDatasource, varRef, varRefsForLoading,
+ InsertDeleteOperator.Kind.DELETE);
+ deleteOp.getInputs().add(new MutableObject<ILogicalOperator>(assign));
+ leafOperator = new SinkOperator();
+ leafOperator.getInputs().add(new MutableObject<ILogicalOperator>(deleteOp));
+ isTransactionalWrite = true;
+ break;
+ }
+ case BEGIN_FEED: {
+ ILogicalOperator insertOp = new InsertDeleteOperator(targetDatasource, varRef, varRefsForLoading,
+ InsertDeleteOperator.Kind.INSERT);
+ insertOp.getInputs().add(new MutableObject<ILogicalOperator>(assign));
+ leafOperator = new SinkOperator();
+ leafOperator.getInputs().add(new MutableObject<ILogicalOperator>(insertOp));
+ isTransactionalWrite = false;
+ break;
+ }
+ }
+ topOp = leafOperator;
+ }
- Expression inExpr = fc.getInExpr();
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- inExpr, tupSource);
- ILogicalOperator returnedOp;
+ globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
+ ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
+ return plan;
+ }
- if (fc.getPosVarExpr() == null) {
- returnedOp = new UnnestOperator(v,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(eo.first)));
- } else {
- LogicalVariable pVar = context.newVar(fc.getPosVarExpr());
- returnedOp = new UnnestOperator(v,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(eo.first)), pVar,
- BuiltinType.AINT32);
- }
- returnedOp.getInputs().add(eo.second);
+ private AqlDataSource validateDatasetInfo(AqlMetadataProvider metadataProvider, String dataverseName,
+ String datasetName) throws AlgebricksException {
+ Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName);
+ if (dataset == null) {
+ throw new AlgebricksException("Cannot find dataset " + datasetName + " in dataverse " + dataverseName);
+ }
- return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
- }
+ AqlSourceId sourceId = new AqlSourceId(dataverseName, datasetName);
+ String itemTypeName = dataset.getItemTypeName();
+ IAType itemType = metadataProvider.findType(dataverseName, itemTypeName);
+ AqlDataSource dataSource = new AqlDataSource(sourceId, dataset, itemType);
+ if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
+ throw new AlgebricksException("Cannot write output to an external dataset.");
+ }
+ return dataSource;
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLetClause(LetClause lc,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- LogicalVariable v;
- ILogicalOperator returnedOp;
+ }
- switch (lc.getBindingExpr().getKind()) {
- case VARIABLE_EXPRESSION: {
- v = context.newVar(lc.getVarExpr());
- LogicalVariable prev = context.getVar(((VariableExpr) lc
- .getBindingExpr()).getVar().getId());
- returnedOp = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(prev)));
- returnedOp.getInputs().add(tupSource);
- break;
- }
- default: {
- v = context.newVar(lc.getVarExpr());
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- lc.getBindingExpr(), tupSource);
- returnedOp = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(eo.first));
- returnedOp.getInputs().add(eo.second);
- break;
- }
- }
- return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
- }
+ private FileSplit getDefaultOutputFileLocation() throws MetadataException {
+ if (AsterixProperties.INSTANCE.getOutputDir() == null) {
+ throw new MetadataException(
+ "Output location for query result not specified at the time of deployment, must specify explicitly using 'write output to ..' statement");
+ }
+ String filePath = AsterixProperties.INSTANCE.getOutputDir() + System.getProperty("file.separator")
+ + OUTPUT_FILE_PREFIX + outputFileID.incrementAndGet();
+ return new FileSplit(AsterixProperties.INSTANCE.getMetadataNodeName(), new FileReference(new File(filePath)));
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitFlworExpression(
- FLWOGRExpression flwor, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Mutable<ILogicalOperator> flworPlan = tupSource;
- boolean isTop = context.isTopFlwor();
- if (isTop) {
- context.setTopFlwor(false);
- }
- for (Clause c : flwor.getClauseList()) {
- Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this,
- flworPlan);
- flworPlan = new MutableObject<ILogicalOperator>(pC.first);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitForClause(ForClause fc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ LogicalVariable v = context.newVar(fc.getVarExpr());
- Expression r = flwor.getReturnExpr();
- boolean noFlworClause = flwor.noForClause();
+ Expression inExpr = fc.getInExpr();
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(inExpr, tupSource);
+ ILogicalOperator returnedOp;
- if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
- VariableExpr v = (VariableExpr) r;
- LogicalVariable var = context.getVar(v.getVar().getId());
+ if (fc.getPosVarExpr() == null) {
+ returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)));
+ } else {
+ LogicalVariable pVar = context.newVar(fc.getPosVarExpr());
+ returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)),
+ pVar, BuiltinType.AINT32);
+ }
+ returnedOp.getInputs().add(eo.second);
- return produceFlwrResult(noFlworClause, isTop, flworPlan, var);
+ return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
+ }
- } else {
- Mutable<ILogicalOperator> baseOp = new MutableObject<ILogicalOperator>(
- flworPlan.getValue());
- Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this,
- baseOp);
- ILogicalOperator rOp = rRes.first;
- ILogicalOperator resOp;
- if (expressionNeedsNoNesting(r)) {
- baseOp.setValue(flworPlan.getValue());
- resOp = rOp;
- } else {
- SubplanOperator s = new SubplanOperator(rOp);
- s.getInputs().add(flworPlan);
- resOp = s;
- baseOp.setValue(new NestedTupleSourceOperator(
- new MutableObject<ILogicalOperator>(s)));
- }
- Mutable<ILogicalOperator> resOpRef = new MutableObject<ILogicalOperator>(
- resOp);
- return produceFlwrResult(noFlworClause, isTop, resOpRef,
- rRes.second);
- }
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLetClause(LetClause lc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ LogicalVariable v;
+ ILogicalOperator returnedOp;
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitFieldAccessor(
- FieldAccessor fa, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- fa.getExpr(), tupSource);
- LogicalVariable v = context.newVar();
- AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME));
- fldAccess.getArguments().add(
- new MutableObject<ILogicalExpression>(p.first));
- ILogicalExpression faExpr = new ConstantExpression(
- new AsterixConstantValue(new AString(fa.getIdent().getValue())));
- fldAccess.getArguments().add(
- new MutableObject<ILogicalExpression>(faExpr));
- AssignOperator a = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(fldAccess));
- a.getInputs().add(p.second);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v);
+ switch (lc.getBindingExpr().getKind()) {
+ case VARIABLE_EXPRESSION: {
+ v = context.newVar(lc.getVarExpr());
+ LogicalVariable prev = context.getVar(((VariableExpr) lc.getBindingExpr()).getVar().getId());
+ returnedOp = new AssignOperator(v, new MutableObject<ILogicalExpression>(
+ new VariableReferenceExpression(prev)));
+ returnedOp.getInputs().add(tupSource);
+ break;
+ }
+ default: {
+ v = context.newVar(lc.getVarExpr());
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(lc.getBindingExpr(),
+ tupSource);
+ returnedOp = new AssignOperator(v, new MutableObject<ILogicalExpression>(eo.first));
+ returnedOp.getInputs().add(eo.second);
+ break;
+ }
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
+ }
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitFlworExpression(FLWOGRExpression flwor,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Mutable<ILogicalOperator> flworPlan = tupSource;
+ boolean isTop = context.isTopFlwor();
+ if (isTop) {
+ context.setTopFlwor(false);
+ }
+ for (Clause c : flwor.getClauseList()) {
+ Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this, flworPlan);
+ flworPlan = new MutableObject<ILogicalOperator>(pC.first);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitIndexAccessor(
- IndexAccessor ia, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- ia.getExpr(), tupSource);
- LogicalVariable v = context.newVar();
- AbstractFunctionCallExpression f;
- int i = ia.getIndex();
- if (i == IndexAccessor.ANY) {
- f = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
- f.getArguments()
- .add(new MutableObject<ILogicalExpression>(p.first));
- } else {
- f = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
- f.getArguments()
- .add(new MutableObject<ILogicalExpression>(p.first));
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(
- new ConstantExpression(new AsterixConstantValue(
- new AInt32(i)))));
- }
- AssignOperator a = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(f));
- a.getInputs().add(p.second);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v);
- }
+ Expression r = flwor.getReturnExpr();
+ boolean noFlworClause = flwor.noForClause();
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitCallExpr(
- CallExpr fcall, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- LogicalVariable v = context.newVar();
- AsterixFunction fid = fcall.getIdent();
- List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
- Mutable<ILogicalOperator> topOp = tupSource;
+ if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
+ VariableExpr v = (VariableExpr) r;
+ LogicalVariable var = context.getVar(v.getVar().getId());
- for (Expression expr : fcall.getExprList()) {
- switch (expr.getKind()) {
- case VARIABLE_EXPRESSION: {
- LogicalVariable var = context.getVar(((VariableExpr) expr)
- .getVar().getId());
- args.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(var)));
- break;
- }
- case LITERAL_EXPRESSION: {
- LiteralExpr val = (LiteralExpr) expr;
- args.add(new MutableObject<ILogicalExpression>(
- new ConstantExpression(
- new AsterixConstantValue(ConstantHelper
- .objectFromLiteral(val.getValue())))));
- break;
- }
- default: {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- expr, topOp);
- AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second
- .getValue();
- args.add(new MutableObject<ILogicalExpression>(eo.first));
- if (o1 != null
- && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(
- o1, topOp))) {
- topOp = eo.second;
- }
- break;
- }
- }
- }
+ return produceFlwrResult(noFlworClause, isTop, flworPlan, var);
- FunctionIdentifier fi = new FunctionIdentifier(
- AlgebricksBuiltinFunctions.ALGEBRICKS_NS, fid.getFunctionName());
- AsterixFunctionInfo afi = AsterixBuiltinFunctions.lookupFunction(fi);
- FunctionIdentifier builtinAquafi = afi == null ? null : afi
- .getFunctionIdentifier();
+ } else {
+ Mutable<ILogicalOperator> baseOp = new MutableObject<ILogicalOperator>(flworPlan.getValue());
+ Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this, baseOp);
+ ILogicalOperator rOp = rRes.first;
+ ILogicalOperator resOp;
+ if (expressionNeedsNoNesting(r)) {
+ baseOp.setValue(flworPlan.getValue());
+ resOp = rOp;
+ } else {
+ SubplanOperator s = new SubplanOperator(rOp);
+ s.getInputs().add(flworPlan);
+ resOp = s;
+ baseOp.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
+ }
+ Mutable<ILogicalOperator> resOpRef = new MutableObject<ILogicalOperator>(resOp);
+ return produceFlwrResult(noFlworClause, isTop, resOpRef, rRes.second);
+ }
+ }
- if (builtinAquafi != null) {
- fi = builtinAquafi;
- } else {
- fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
- fid.getFunctionName());
- FunctionIdentifier builtinAsterixFi = AsterixBuiltinFunctions
- .getBuiltinFunctionIdentifier(fi);
- if (builtinAsterixFi != null) {
- fi = builtinAsterixFi;
- }
- }
- AbstractFunctionCallExpression f;
- if (AsterixBuiltinFunctions.isBuiltinAggregateFunction(fi)) {
- f = AsterixBuiltinFunctions.makeAggregateFunctionExpression(fi,
- args);
- } else if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(fi)) {
- UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(
- FunctionUtils.getFunctionInfo(fi), args);
- ufce.setReturnsUniqueValues(AsterixBuiltinFunctions
- .returnsUniqueValues(fi));
- f = ufce;
- } else {
- f = new ScalarFunctionCallExpression(
- FunctionUtils.getFunctionInfo(fi), args);
- }
- // Put hints into function call expr.
- if (fcall.hasHints()) {
- for (IExpressionAnnotation hint : fcall.getHints()) {
- f.getAnnotations().put(hint, hint);
- }
- }
- AssignOperator op = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(f));
- if (topOp != null) {
- op.getInputs().add(topOp);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitFieldAccessor(FieldAccessor fa,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(fa.getExpr(), tupSource);
+ LogicalVariable v = context.newVar();
+ AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME));
+ fldAccess.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
+ ILogicalExpression faExpr = new ConstantExpression(new AsterixConstantValue(new AString(fa.getIdent()
+ .getValue())));
+ fldAccess.getArguments().add(new MutableObject<ILogicalExpression>(faExpr));
+ AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(fldAccess));
+ a.getInputs().add(p.second);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v);
- return new Pair<ILogicalOperator, LogicalVariable>(op, v);
- }
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitFunctionDecl(
- FunctionDecl fd, Mutable<ILogicalOperator> tupSource) {
- // TODO Auto-generated method stub
- throw new NotImplementedException();
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitIndexAccessor(IndexAccessor ia,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(ia.getExpr(), tupSource);
+ LogicalVariable v = context.newVar();
+ AbstractFunctionCallExpression f;
+ int i = ia.getIndex();
+ if (i == IndexAccessor.ANY) {
+ f = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
+ f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
+ } else {
+ f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
+ f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
+ f.getArguments().add(
+ new MutableObject<ILogicalExpression>(new ConstantExpression(
+ new AsterixConstantValue(new AInt32(i)))));
+ }
+ AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
+ a.getInputs().add(p.second);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitGroupbyClause(
- GroupbyClause gc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- GroupByOperator gOp = new GroupByOperator();
- Mutable<ILogicalOperator> topOp = tupSource;
- for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
- LogicalVariable v;
- VariableExpr vexpr = ve.getVar();
- if (vexpr != null) {
- v = context.newVar(vexpr);
- } else {
- v = context.newVar();
- }
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- ve.getExpr(), topOp);
- gOp.addGbyExpression(v, eo.first);
- topOp = eo.second;
- }
- for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
- LogicalVariable v;
- VariableExpr vexpr = ve.getVar();
- if (vexpr != null) {
- v = context.newVar(vexpr);
- } else {
- v = context.newVar();
- }
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- ve.getExpr(), topOp);
- gOp.addDecorExpression(v, eo.first);
- topOp = eo.second;
- }
- gOp.getInputs().add(topOp);
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitCallExpr(CallExpr fcall, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ LogicalVariable v = context.newVar();
+ FunctionSignature signature = fcall.getFunctionSignature();
+ List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
+ Mutable<ILogicalOperator> topOp = tupSource;
- for (VariableExpr var : gc.getWithVarList()) {
- LogicalVariable aggVar = context.newVar();
- LogicalVariable oldVar = context.getVar(var);
- List<Mutable<ILogicalExpression>> flArgs = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- flArgs.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(oldVar)));
- AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions
- .makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.LISTIFY, flArgs);
- AggregateOperator agg = new AggregateOperator(
- mkSingletonArrayList(aggVar),
- (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
- fListify)));
+ for (Expression expr : fcall.getExprList()) {
+ switch (expr.getKind()) {
+ case VARIABLE_EXPRESSION: {
+ LogicalVariable var = context.getVar(((VariableExpr) expr).getVar().getId());
+ args.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
+ break;
+ }
+ case LITERAL_EXPRESSION: {
+ LiteralExpr val = (LiteralExpr) expr;
+ args.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(
+ ConstantHelper.objectFromLiteral(val.getValue())))));
+ break;
+ }
+ default: {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, topOp);
+ AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second.getValue();
+ args.add(new MutableObject<ILogicalExpression>(eo.first));
+ if (o1 != null && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(o1, topOp))) {
+ topOp = eo.second;
+ }
+ break;
+ }
+ }
+ }
- agg.getInputs().add(
- new MutableObject<ILogicalOperator>(
- new NestedTupleSourceOperator(
- new MutableObject<ILogicalOperator>(gOp))));
- ILogicalPlan plan = new ALogicalPlanImpl(
- new MutableObject<ILogicalOperator>(agg));
- gOp.getNestedPlans().add(plan);
- // Hide the variable that was part of the "with", replacing it with
- // the one bound by the aggregation op.
- context.setVar(var, aggVar);
- }
+ AbstractFunctionCallExpression f;
+ if ((f = lookupUserDefinedFunction(signature, args)) == null) {
+ f = lookupBuiltinFunction(signature.getName(), signature.getArity(), args);
+ }
- gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY,
- gc.hasHashGroupByHint());
- return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
- }
+ if (f == null) {
+ throw new AsterixException(" Unknown function " + signature);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitIfExpr(IfExpr ifexpr,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- // In the most general case, IfThenElse is translated in the following
- // way.
- //
- // We assign the result of the condition to one variable varCond.
- // We create one subplan which contains the plan for the "then" branch,
- // on top of which there is a selection whose condition is varCond.
- // Similarly, we create one subplan for the "else" branch, in which the
- // selection is not(varCond).
- // Finally, we concatenate the results. (??)
+ // Put hints into function call expr.
+ if (fcall.hasHints()) {
+ for (IExpressionAnnotation hint : fcall.getHints()) {
+ f.getAnnotations().put(hint, hint);
+ }
+ }
- Pair<ILogicalOperator, LogicalVariable> pCond = ifexpr.getCondExpr()
- .accept(this, tupSource);
- ILogicalOperator opCond = pCond.first;
- LogicalVariable varCond = pCond.second;
+ AssignOperator op = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
+ if (topOp != null) {
+ op.getInputs().add(topOp);
+ }
- SubplanOperator sp = new SubplanOperator();
- Mutable<ILogicalOperator> nestedSource = new MutableObject<ILogicalOperator>(
- new NestedTupleSourceOperator(
- new MutableObject<ILogicalOperator>(sp)));
+ return new Pair<ILogicalOperator, LogicalVariable>(op, v);
+ }
- Pair<ILogicalOperator, LogicalVariable> pThen = ifexpr.getThenExpr()
- .accept(this, nestedSource);
- SelectOperator sel1 = new SelectOperator(
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(varCond)));
- sel1.getInputs().add(new MutableObject<ILogicalOperator>(pThen.first));
+ private AbstractFunctionCallExpression lookupUserDefinedFunction(FunctionSignature signature,
+ List<Mutable<ILogicalExpression>> args) throws MetadataException {
+ if (signature.getNamespace() == null) {
+ return null;
+ }
+ Function function = MetadataManager.INSTANCE.getFunction(metadataProvider.getMetadataTxnContext(), signature);
+ if (function == null) {
+ return null;
+ }
+ AbstractFunctionCallExpression f = null;
+ if (function.getLanguage().equalsIgnoreCase(Function.LANGUAGE_AQL)) {
+ IFunctionInfo finfo = new AsterixFunctionInfo(signature);
+ return new ScalarFunctionCallExpression(finfo, args);
+ } else {
+ throw new MetadataException(" User defined functions written in " + function.getLanguage()
+ + " are not supported");
+ }
+ }
- Pair<ILogicalOperator, LogicalVariable> pElse = ifexpr.getElseExpr()
- .accept(this, nestedSource);
- AbstractFunctionCallExpression notVarCond = new ScalarFunctionCallExpression(
- FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT),
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(varCond)));
- SelectOperator sel2 = new SelectOperator(
- new MutableObject<ILogicalExpression>(notVarCond));
- sel2.getInputs().add(new MutableObject<ILogicalOperator>(pElse.first));
+ private AbstractFunctionCallExpression lookupBuiltinFunction(String functionName, int arity,
+ List<Mutable<ILogicalExpression>> args) {
+ AbstractFunctionCallExpression f = null;
- ILogicalPlan p1 = new ALogicalPlanImpl(
- new MutableObject<ILogicalOperator>(sel1));
- sp.getNestedPlans().add(p1);
- ILogicalPlan p2 = new ALogicalPlanImpl(
- new MutableObject<ILogicalOperator>(sel2));
- sp.getNestedPlans().add(p2);
+ FunctionIdentifier fi = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS, functionName, arity);
+ AsterixFunctionInfo afi = AsterixBuiltinFunctions.lookupFunction(fi);
+ FunctionIdentifier builtinAquafi = afi == null ? null : afi.getFunctionIdentifier();
- Mutable<ILogicalOperator> opCondRef = new MutableObject<ILogicalOperator>(
- opCond);
- sp.getInputs().add(opCondRef);
+ if (builtinAquafi != null) {
+ fi = builtinAquafi;
+ } else {
+ fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, functionName, arity);
+ FunctionIdentifier builtinAsterixFi = AsterixBuiltinFunctions.getBuiltinFunctionIdentifier(fi);
+ if (builtinAsterixFi != null) {
+ fi = builtinAsterixFi;
+ }
+ }
+ if (AsterixBuiltinFunctions.isBuiltinAggregateFunction(fi)) {
+ f = AsterixBuiltinFunctions.makeAggregateFunctionExpression(fi, args);
+ } else if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(fi)) {
+ UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(fi), args);
+ ufce.setReturnsUniqueValues(AsterixBuiltinFunctions.returnsUniqueValues(fi));
+ f = ufce;
+ } else {
+ f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fi), args);
+ }
+ return f;
+ }
- LogicalVariable resV = context.newVar();
- AbstractFunctionCallExpression concatNonNull = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.CONCAT_NON_NULL),
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(pThen.second)),
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(pElse.second)));
- AssignOperator a = new AssignOperator(resV,
- new MutableObject<ILogicalExpression>(concatNonNull));
- a.getInputs().add(new MutableObject<ILogicalOperator>(sp));
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitFunctionDecl(FunctionDecl fd,
+ Mutable<ILogicalOperator> tupSource) {
+ // TODO Auto-generated method stub
+ throw new NotImplementedException();
+ }
- return new Pair<ILogicalOperator, LogicalVariable>(a, resV);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitGroupbyClause(GroupbyClause gc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ GroupByOperator gOp = new GroupByOperator();
+ Mutable<ILogicalOperator> topOp = tupSource;
+ for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
+ LogicalVariable v;
+ VariableExpr vexpr = ve.getVar();
+ if (vexpr != null) {
+ v = context.newVar(vexpr);
+ } else {
+ v = context.newVar();
+ }
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(ve.getExpr(), topOp);
+ gOp.addGbyExpression(v, eo.first);
+ topOp = eo.second;
+ }
+ for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
+ LogicalVariable v;
+ VariableExpr vexpr = ve.getVar();
+ if (vexpr != null) {
+ v = context.newVar(vexpr);
+ } else {
+ v = context.newVar();
+ }
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(ve.getExpr(), topOp);
+ gOp.addDecorExpression(v, eo.first);
+ topOp = eo.second;
+ }
+ gOp.getInputs().add(topOp);
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLiteralExpr(
- LiteralExpr l, Mutable<ILogicalOperator> tupSource) {
- LogicalVariable var = context.newVar();
- AssignOperator a = new AssignOperator(var,
- new MutableObject<ILogicalExpression>(new ConstantExpression(
- new AsterixConstantValue(ConstantHelper
- .objectFromLiteral(l.getValue())))));
- if (tupSource != null) {
- a.getInputs().add(tupSource);
- }
- return new Pair<ILogicalOperator, LogicalVariable>(a, var);
- }
+ for (VariableExpr var : gc.getWithVarList()) {
+ LogicalVariable aggVar = context.newVar();
+ LogicalVariable oldVar = context.getVar(var);
+ List<Mutable<ILogicalExpression>> flArgs = new ArrayList<Mutable<ILogicalExpression>>(1);
+ flArgs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(oldVar)));
+ AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+ AsterixBuiltinFunctions.LISTIFY, flArgs);
+ AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(aggVar),
+ (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(fListify)));
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitOperatorExpr(
- OperatorExpr op, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- ArrayList<OperatorType> ops = op.getOpList();
- int nOps = ops.size();
+ agg.getInputs().add(
+ new MutableObject<ILogicalOperator>(new NestedTupleSourceOperator(
+ new MutableObject<ILogicalOperator>(gOp))));
+ ILogicalPlan plan = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(agg));
+ gOp.getNestedPlans().add(plan);
+ // Hide the variable that was part of the "with", replacing it with
+ // the one bound by the aggregation op.
+ context.setVar(var, aggVar);
+ }
- if (nOps > 0
- && (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
- return visitAndOrOperator(op, tupSource);
- }
+ gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, gc.hasHashGroupByHint());
+ return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
+ }
- ArrayList<Expression> exprs = op.getExprList();
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitIfExpr(IfExpr ifexpr, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ // In the most general case, IfThenElse is translated in the following
+ // way.
+ //
+ // We assign the result of the condition to one variable varCond.
+ // We create one subplan which contains the plan for the "then" branch,
+ // on top of which there is a selection whose condition is varCond.
+ // Similarly, we create one subplan for the "else" branch, in which the
+ // selection is not(varCond).
+ // Finally, we concatenate the results. (??)
- Mutable<ILogicalOperator> topOp = tupSource;
+ Pair<ILogicalOperator, LogicalVariable> pCond = ifexpr.getCondExpr().accept(this, tupSource);
+ ILogicalOperator opCond = pCond.first;
+ LogicalVariable varCond = pCond.second;
- ILogicalExpression currExpr = null;
- for (int i = 0; i <= nOps; i++) {
+ SubplanOperator sp = new SubplanOperator();
+ Mutable<ILogicalOperator> nestedSource = new MutableObject<ILogicalOperator>(new NestedTupleSourceOperator(
+ new MutableObject<ILogicalOperator>(sp)));
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- exprs.get(i), topOp);
- topOp = p.second;
- ILogicalExpression e = p.first;
- // now look at the operator
- if (i < nOps) {
- if (OperatorExpr.opIsComparison(ops.get(i))) {
- AbstractFunctionCallExpression c = createComparisonExpression(ops
- .get(i));
+ Pair<ILogicalOperator, LogicalVariable> pThen = ifexpr.getThenExpr().accept(this, nestedSource);
+ SelectOperator sel1 = new SelectOperator(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(
+ varCond)));
+ sel1.getInputs().add(new MutableObject<ILogicalOperator>(pThen.first));
- // chain the operators
- if (i == 0) {
- c.getArguments().add(
- new MutableObject<ILogicalExpression>(e));
- currExpr = c;
- if (op.isBroadcastOperand(i)) {
- BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
- bcast.setObject(BroadcastSide.LEFT);
- c.getAnnotations()
- .put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
- bcast);
- }
- } else {
- ((AbstractFunctionCallExpression) currExpr)
- .getArguments()
- .add(new MutableObject<ILogicalExpression>(e));
- c.getArguments()
- .add(new MutableObject<ILogicalExpression>(
- currExpr));
- currExpr = c;
- if (i == 1 && op.isBroadcastOperand(i)) {
- BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
- bcast.setObject(BroadcastSide.RIGHT);
- c.getAnnotations()
- .put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
- bcast);
- }
- }
- } else {
- AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops
- .get(i));
+ Pair<ILogicalOperator, LogicalVariable> pElse = ifexpr.getElseExpr().accept(this, nestedSource);
+ AbstractFunctionCallExpression notVarCond = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), new MutableObject<ILogicalExpression>(
+ new VariableReferenceExpression(varCond)));
+ SelectOperator sel2 = new SelectOperator(new MutableObject<ILogicalExpression>(notVarCond));
+ sel2.getInputs().add(new MutableObject<ILogicalOperator>(pElse.first));
- if (i == 0) {
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(e));
- currExpr = f;
- } else {
- ((AbstractFunctionCallExpression) currExpr)
- .getArguments()
- .add(new MutableObject<ILogicalExpression>(e));
- f.getArguments()
- .add(new MutableObject<ILogicalExpression>(
- currExpr));
- currExpr = f;
- }
- }
- } else { // don't forget the last expression...
- ((AbstractFunctionCallExpression) currExpr).getArguments().add(
- new MutableObject<ILogicalExpression>(e));
- if (i == 1 && op.isBroadcastOperand(i)) {
- BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
- bcast.setObject(BroadcastSide.RIGHT);
- ((AbstractFunctionCallExpression) currExpr)
- .getAnnotations()
- .put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
- bcast);
- }
- }
- }
+ ILogicalPlan p1 = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(sel1));
+ sp.getNestedPlans().add(p1);
+ ILogicalPlan p2 = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(sel2));
+ sp.getNestedPlans().add(p2);
- // Add hints as annotations.
- if (op.hasHints() && currExpr instanceof AbstractFunctionCallExpression) {
- AbstractFunctionCallExpression currFuncExpr = (AbstractFunctionCallExpression) currExpr;
- for (IExpressionAnnotation hint : op.getHints()) {
- currFuncExpr.getAnnotations().put(hint, hint);
- }
- }
-
- LogicalVariable assignedVar = context.newVar();
- AssignOperator a = new AssignOperator(assignedVar,
- new MutableObject<ILogicalExpression>(currExpr));
+ Mutable<ILogicalOperator> opCondRef = new MutableObject<ILogicalOperator>(opCond);
+ sp.getInputs().add(opCondRef);
- a.getInputs().add(topOp);
+ LogicalVariable resV = context.newVar();
+ AbstractFunctionCallExpression concatNonNull = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.CONCAT_NON_NULL),
+ new MutableObject<ILogicalExpression>(new VariableReferenceExpression(pThen.second)),
+ new MutableObject<ILogicalExpression>(new VariableReferenceExpression(pElse.second)));
+ AssignOperator a = new AssignOperator(resV, new MutableObject<ILogicalExpression>(concatNonNull));
+ a.getInputs().add(new MutableObject<ILogicalOperator>(sp));
- return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
- }
+ return new Pair<ILogicalOperator, LogicalVariable>(a, resV);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitOrderbyClause(
- OrderbyClause oc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLiteralExpr(LiteralExpr l, Mutable<ILogicalOperator> tupSource) {
+ LogicalVariable var = context.newVar();
+ AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(new ConstantExpression(
+ new AsterixConstantValue(ConstantHelper.objectFromLiteral(l.getValue())))));
+ if (tupSource != null) {
+ a.getInputs().add(tupSource);
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+ }
- OrderOperator ord = new OrderOperator();
- Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
- Mutable<ILogicalOperator> topOp = tupSource;
- for (Expression e : oc.getOrderbyList()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- e, topOp);
- OrderModifier m = modifIter.next();
- OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER
- : OrderOperator.DESC_ORDER;
- ord.getOrderExpressions().add(
- new Pair<IOrder, Mutable<ILogicalExpression>>(comp,
- new MutableObject<ILogicalExpression>(p.first)));
- topOp = p.second;
- }
- ord.getInputs().add(topOp);
- if (oc.getNumTuples() > 0) {
- ord.getAnnotations().put(OperatorAnnotations.CARDINALITY,
- oc.getNumTuples());
- }
- if (oc.getNumFrames() > 0) {
- ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES,
- oc.getNumFrames());
- }
- return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitOperatorExpr(OperatorExpr op,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ ArrayList<OperatorType> ops = op.getOpList();
+ int nOps = ops.size();
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitQuantifiedExpression(
- QuantifiedExpression qe, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Mutable<ILogicalOperator> topOp = tupSource;
+ if (nOps > 0 && (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
+ return visitAndOrOperator(op, tupSource);
+ }
- ILogicalOperator firstOp = null;
- Mutable<ILogicalOperator> lastOp = null;
+ ArrayList<Expression> exprs = op.getExprList();
- for (QuantifiedPair qt : qe.getQuantifiedList()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(
- qt.getExpr(), topOp);
- topOp = eo1.second;
- LogicalVariable uVar = context.newVar(qt.getVarExpr());
- ILogicalOperator u = new UnnestOperator(uVar,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(eo1.first)));
+ Mutable<ILogicalOperator> topOp = tupSource;
- if (firstOp == null) {
- firstOp = u;
- }
- if (lastOp != null) {
- u.getInputs().add(lastOp);
- }
- lastOp = new MutableObject<ILogicalOperator>(u);
- }
+ ILogicalExpression currExpr = null;
+ for (int i = 0; i <= nOps; i++) {
- // We make all the unnest correspond. to quantif. vars. sit on top
- // in the hope of enabling joins & other optimiz.
- firstOp.getInputs().add(topOp);
- topOp = lastOp;
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(exprs.get(i), topOp);
+ topOp = p.second;
+ ILogicalExpression e = p.first;
+ // now look at the operator
+ if (i < nOps) {
+ if (OperatorExpr.opIsComparison(ops.get(i))) {
+ AbstractFunctionCallExpression c = createComparisonExpression(ops.get(i));
+
+ // chain the operators
+ if (i == 0) {
+ c.getArguments().add(new MutableObject<ILogicalExpression>(e));
+ currExpr = c;
+ if (op.isBroadcastOperand(i)) {
+ BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+ bcast.setObject(BroadcastSide.LEFT);
+ c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
+ }
+ } else {
+ ((AbstractFunctionCallExpression) currExpr).getArguments().add(
+ new MutableObject<ILogicalExpression>(e));
+ c.getArguments().add(new MutableObject<ILogicalExpression>(currExpr));
+ currExpr = c;
+ if (i == 1 && op.isBroadcastOperand(i)) {
+ BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+ bcast.setObject(BroadcastSide.RIGHT);
+ c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
+ }
+ }
+ } else {
+ AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops.get(i));
+
+ if (i == 0) {
+ f.getArguments().add(new MutableObject<ILogicalExpression>(e));
+ currExpr = f;
+ } else {
+ ((AbstractFunctionCallExpression) currExpr).getArguments().add(
+ new MutableObject<ILogicalExpression>(e));
+ f.getArguments().add(new MutableObject<ILogicalExpression>(currExpr));
+ currExpr = f;
+ }
+ }
+ } else { // don't forget the last expression...
+ ((AbstractFunctionCallExpression) currExpr).getArguments()
+ .add(new MutableObject<ILogicalExpression>(e));
+ if (i == 1 && op.isBroadcastOperand(i)) {
+ BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+ bcast.setObject(BroadcastSide.RIGHT);
+ ((AbstractFunctionCallExpression) currExpr).getAnnotations().put(
+ BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
+ }
+ }
+ }
+
+ // Add hints as annotations.
+ if (op.hasHints() && currExpr instanceof AbstractFunctionCallExpression) {
+ AbstractFunctionCallExpression currFuncExpr = (AbstractFunctionCallExpression) currExpr;
+ for (IExpressionAnnotation hint : op.getHints()) {
+ currFuncExpr.getAnnotations().put(hint, hint);
+ }
+ }
+
+ LogicalVariable assignedVar = context.newVar();
+ AssignOperator a = new AssignOperator(assignedVar, new MutableObject<ILogicalExpression>(currExpr));
+
+ a.getInputs().add(topOp);
+
+ return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
+ }
+
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitOrderbyClause(OrderbyClause oc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+
+ OrderOperator ord = new OrderOperator();
+ Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
+ Mutable<ILogicalOperator> topOp = tupSource;
+ for (Expression e : oc.getOrderbyList()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(e, topOp);
+ OrderModifier m = modifIter.next();
+ OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
+ ord.getOrderExpressions()
+ .add(new Pair<IOrder, Mutable<ILogicalExpression>>(comp, new MutableObject<ILogicalExpression>(
+ p.first)));
+ topOp = p.second;
+ }
+ ord.getInputs().add(topOp);
+ if (oc.getNumTuples() > 0) {
+ ord.getAnnotations().put(OperatorAnnotations.CARDINALITY, oc.getNumTuples());
+ }
+ if (oc.getNumFrames() > 0) {
+ ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames());
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
+ }
+
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitQuantifiedExpression(QuantifiedExpression qe,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Mutable<ILogicalOperator> topOp = tupSource;
+
+ ILogicalOperator firstOp = null;
+ Mutable<ILogicalOperator> lastOp = null;
+
+ for (QuantifiedPair qt : qe.getQuantifiedList()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(qt.getExpr(), topOp);
+ topOp = eo1.second;
+ LogicalVariable uVar = context.newVar(qt.getVarExpr());
+ ILogicalOperator u = new UnnestOperator(uVar, new MutableObject<ILogicalExpression>(
+ makeUnnestExpression(eo1.first)));
+
+ if (firstOp == null) {
+ firstOp = u;
+ }
+ if (lastOp != null) {
+ u.getInputs().add(lastOp);
+ }
+ lastOp = new MutableObject<ILogicalOperator>(u);
+ }
+
+ // We make all the unnest correspond. to quantif. vars. sit on top
+ // in the hope of enabling joins & other optimiz.
+ firstOp.getInputs().add(topOp);
+ topOp = lastOp;
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(
- qe.getSatisfiesExpr(), topOp);
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(qe.getSatisfiesExpr(), topOp);
- AggregateFunctionCallExpression fAgg;
- SelectOperator s;
- if (qe.getQuantifier() == Quantifier.SOME) {
- s = new SelectOperator(new MutableObject<ILogicalExpression>(
- eo2.first));
- s.getInputs().add(eo2.second);
- fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.NON_EMPTY_STREAM,
- new ArrayList<Mutable<ILogicalExpression>>());
- } else { // EVERY
- List<Mutable<ILogicalExpression>> satExprList = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- satExprList.add(new MutableObject<ILogicalExpression>(eo2.first));
- s = new SelectOperator(new MutableObject<ILogicalExpression>(
- new ScalarFunctionCallExpression(FunctionUtils
- .getFunctionInfo(AlgebricksBuiltinFunctions.NOT),
- satExprList)));
- s.getInputs().add(eo2.second);
- fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.EMPTY_STREAM,
- new ArrayList<Mutable<ILogicalExpression>>());
- }
- LogicalVariable qeVar = context.newVar();
- AggregateOperator a = new AggregateOperator(
- mkSingletonArrayList(qeVar),
- (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
- fAgg)));
- a.getInputs().add(new MutableObject<ILogicalOperator>(s));
- return new Pair<ILogicalOperator, LogicalVariable>(a, qeVar);
- }
+ AggregateFunctionCallExpression fAgg;
+ SelectOperator s;
+ if (qe.getQuantifier() == Quantifier.SOME) {
+ s = new SelectOperator(new MutableObject<ILogicalExpression>(eo2.first));
+ s.getInputs().add(eo2.second);
+ fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(AsterixBuiltinFunctions.NON_EMPTY_STREAM,
+ new ArrayList<Mutable<ILogicalExpression>>());
+ } else { // EVERY
+ List<Mutable<ILogicalExpression>> satExprList = new ArrayList<Mutable<ILogicalExpression>>(1);
+ satExprList.add(new MutableObject<ILogicalExpression>(eo2.first));
+ s = new SelectOperator(new MutableObject<ILogicalExpression>(new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), satExprList)));
+ s.getInputs().add(eo2.second);
+ fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(AsterixBuiltinFunctions.EMPTY_STREAM,
+ new ArrayList<Mutable<ILogicalExpression>>());
+ }
+ LogicalVariable qeVar = context.newVar();
+ AggregateOperator a = new AggregateOperator(mkSingletonArrayList(qeVar),
+ (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(fAgg)));
+ a.getInputs().add(new MutableObject<ILogicalOperator>(s));
+ return new Pair<ILogicalOperator, LogicalVariable>(a, qeVar);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitQuery(Query q,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- return q.getBody().accept(this, tupSource);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitQuery(Query q, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ return q.getBody().accept(this, tupSource);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitRecordConstructor(
- RecordConstructor rc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
- LogicalVariable v1 = context.newVar();
- AssignOperator a = new AssignOperator(v1,
- new MutableObject<ILogicalExpression>(f));
- Mutable<ILogicalOperator> topOp = tupSource;
- for (FieldBinding fb : rc.getFbList()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(
- fb.getLeftExpr(), topOp);
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(eo1.first));
- topOp = eo1.second;
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(
- fb.getRightExpr(), topOp);
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(eo2.first));
- topOp = eo2.second;
- }
- a.getInputs().add(topOp);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitRecordConstructor(RecordConstructor rc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
+ LogicalVariable v1 = context.newVar();
+ AssignOperator a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(f));
+ Mutable<ILogicalOperator> topOp = tupSource;
+ for (FieldBinding fb : rc.getFbList()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(fb.getLeftExpr(), topOp);
+ f.getArguments().add(new MutableObject<ILogicalExpression>(eo1.first));
+ topOp = eo1.second;
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(fb.getRightExpr(), topOp);
+ f.getArguments().add(new MutableObject<ILogicalExpression>(eo2.first));
+ topOp = eo2.second;
+ }
+ a.getInputs().add(topOp);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitListConstructor(
- ListConstructor lc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR) ? AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR
- : AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
- AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
- FunctionUtils.getFunctionInfo(fid));
- LogicalVariable v1 = context.newVar();
- AssignOperator a = new AssignOperator(v1,
- new MutableObject<ILogicalExpression>(f));
- Mutable<ILogicalOperator> topOp = tupSource;
- for (Expression expr : lc.getExprList()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- expr, topOp);
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(eo.first));
- topOp = eo.second;
- }
- a.getInputs().add(topOp);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitListConstructor(ListConstructor lc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR) ? AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR
+ : AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
+ AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fid));
+ LogicalVariable v1 = context.newVar();
+ AssignOperator a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(f));
+ Mutable<ILogicalOperator> topOp = tupSource;
+ for (Expression expr : lc.getExprList()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, topOp);
+ f.getArguments().add(new MutableObject<ILogicalExpression>(eo.first));
+ topOp = eo.second;
+ }
+ a.getInputs().add(topOp);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUnaryExpr(UnaryExpr u,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- Expression expr = u.getExpr();
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- expr, tupSource);
- LogicalVariable v1 = context.newVar();
- AssignOperator a;
- if (u.getSign() == Sign.POSITIVE) {
- a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(
- eo.first));
- } else {
- AbstractFunctionCallExpression m = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS));
- m.getArguments().add(
- new MutableObject<ILogicalExpression>(eo.first));
- a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(m));
- }
- a.getInputs().add(eo.second);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUnaryExpr(UnaryExpr u, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ Expression expr = u.getExpr();
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, tupSource);
+ LogicalVariable v1 = context.newVar();
+ AssignOperator a;
+ if (u.getSign() == Sign.POSITIVE) {
+ a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(eo.first));
+ } else {
+ AbstractFunctionCallExpression m = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS));
+ m.getArguments().add(new MutableObject<ILogicalExpression>(eo.first));
+ a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(m));
+ }
+ a.getInputs().add(eo.second);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitVariableExpr(
- VariableExpr v, Mutable<ILogicalOperator> tupSource) {
- // Should we ever get to this method?
- LogicalVariable var = context.newVar();
- LogicalVariable oldV = context.getVar(v.getVar().getId());
- AssignOperator a = new AssignOperator(var,
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(oldV)));
- a.getInputs().add(tupSource);
- return new Pair<ILogicalOperator, LogicalVariable>(a, var);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitVariableExpr(VariableExpr v, Mutable<ILogicalOperator> tupSource) {
+ // Should we ever get to this method?
+ LogicalVariable var = context.newVar();
+ LogicalVariable oldV = context.getVar(v.getVar().getId());
+ AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(
+ new VariableReferenceExpression(oldV)));
+ a.getInputs().add(tupSource);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitWhereClause(
- WhereClause w, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- w.getWhereExpr(), tupSource);
- SelectOperator s = new SelectOperator(
- new MutableObject<ILogicalExpression>(p.first));
- s.getInputs().add(p.second);
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitWhereClause(WhereClause w, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(w.getWhereExpr(), tupSource);
+ SelectOperator s = new SelectOperator(new MutableObject<ILogicalExpression>(p.first));
+ s.getInputs().add(p.second);
- return new Pair<ILogicalOperator, LogicalVariable>(s, null);
- }
+ return new Pair<ILogicalOperator, LogicalVariable>(s, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLimitClause(
- LimitClause lc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(
- lc.getLimitExpr(), tupSource);
- LimitOperator opLim;
- Expression offset = lc.getOffset();
- if (offset != null) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p2 = aqlExprToAlgExpression(
- offset, p1.second);
- opLim = new LimitOperator(p1.first, p2.first);
- opLim.getInputs().add(p2.second);
- } else {
- opLim = new LimitOperator(p1.first);
- opLim.getInputs().add(p1.second);
- }
- return new Pair<ILogicalOperator, LogicalVariable>(opLim, null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLimitClause(LimitClause lc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getLimitExpr(), tupSource);
+ LimitOperator opLim;
+ Expression offset = lc.getOffset();
+ if (offset != null) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p2 = aqlExprToAlgExpression(offset, p1.second);
+ opLim = new LimitOperator(p1.first, p2.first);
+ opLim.getInputs().add(p2.second);
+ } else {
+ opLim = new LimitOperator(p1.first);
+ opLim.getInputs().add(p1.second);
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(opLim, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDieClause(DieClause lc,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(
- lc.getDieExpr(), tupSource);
- DieOperator opDie = new DieOperator(p1.first);
- opDie.getInputs().add(p1.second);
- return new Pair<ILogicalOperator, LogicalVariable>(opDie, null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDieClause(DieClause lc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getDieExpr(), tupSource);
+ DieOperator opDie = new DieOperator(p1.first);
+ opDie.getInputs().add(p1.second);
+ return new Pair<ILogicalOperator, LogicalVariable>(opDie, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDistinctClause(
- DistinctClause dc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
- Mutable<ILogicalOperator> input = null;
- for (Expression expr : dc.getDistinctByExpr()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- expr, tupSource);
- exprList.add(new MutableObject<ILogicalExpression>(p.first));
- input = p.second;
- }
- DistinctOperator opDistinct = new DistinctOperator(exprList);
- opDistinct.getInputs().add(input);
- return new Pair<ILogicalOperator, LogicalVariable>(opDistinct, null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDistinctClause(DistinctClause dc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
+ Mutable<ILogicalOperator> input = null;
+ for (Expression expr : dc.getDistinctByExpr()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(expr, tupSource);
+ exprList.add(new MutableObject<ILogicalExpression>(p.first));
+ input = p.second;
+ }
+ DistinctOperator opDistinct = new DistinctOperator(exprList);
+ opDistinct.getInputs().add(input);
+ return new Pair<ILogicalOperator, LogicalVariable>(opDistinct, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUnionExpr(
- UnionExpr unionExpr, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Mutable<ILogicalOperator> ts = tupSource;
- ILogicalOperator lastOp = null;
- LogicalVariable lastVar = null;
- boolean first = true;
- for (Expression e : unionExpr.getExprs()) {
- if (first) {
- first = false;
- } else {
- ts = new MutableObject<ILogicalOperator>(
- new EmptyTupleSourceOperator());
- }
- Pair<ILogicalOperator, LogicalVariable> p1 = e.accept(this, ts);
- if (lastOp == null) {
- lastOp = p1.first;
- lastVar = p1.second;
- } else {
- LogicalVariable unnestVar1 = context.newVar();
- UnnestOperator unnest1 = new UnnestOperator(
- unnestVar1,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(new VariableReferenceExpression(
- lastVar))));
- unnest1.getInputs().add(
- new MutableObject<ILogicalOperator>(lastOp));
- LogicalVariable unnestVar2 = context.newVar();
- UnnestOperator unnest2 = new UnnestOperator(
- unnestVar2,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(new VariableReferenceExpression(
- p1.second))));
- unnest2.getInputs().add(
- new MutableObject<ILogicalOperator>(p1.first));
- List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(
- 1);
- LogicalVariable resultVar = context.newVar();
- Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
- unnestVar1, unnestVar2, resultVar);
- varMap.add(triple);
- UnionAllOperator unionOp = new UnionAllOperator(varMap);
- unionOp.getInputs().add(
- new MutableObject<ILogicalOperator>(unnest1));
- unionOp.getInputs().add(
- new MutableObject<ILogicalOperator>(unnest2));
- lastVar = resultVar;
- lastOp = unionOp;
- }
- }
- LogicalVariable aggVar = context.newVar();
- ArrayList<LogicalVariable> aggregVars = new ArrayList<LogicalVariable>(
- 1);
- aggregVars.add(aggVar);
- List<Mutable<ILogicalExpression>> afcExprs = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- afcExprs.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(lastVar)));
- AggregateFunctionCallExpression afc = AsterixBuiltinFunctions
- .makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.LISTIFY, afcExprs);
- ArrayList<Mutable<ILogicalExpression>> aggregExprs = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- aggregExprs.add(new MutableObject<ILogicalExpression>(afc));
- AggregateOperator agg = new AggregateOperator(aggregVars, aggregExprs);
- agg.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
- return new Pair<ILogicalOperator, LogicalVariable>(agg, aggVar);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUnionExpr(UnionExpr unionExpr,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Mutable<ILogicalOperator> ts = tupSource;
+ ILogicalOperator lastOp = null;
+ LogicalVariable lastVar = null;
+ boolean first = true;
+ for (Expression e : unionExpr.getExprs()) {
+ if (first) {
+ first = false;
+ } else {
+ ts = new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator());
+ }
+ Pair<ILogicalOperator, LogicalVariable> p1 = e.accept(this, ts);
+ if (lastOp == null) {
+ lastOp = p1.first;
+ lastVar = p1.second;
+ } else {
+ LogicalVariable unnestVar1 = context.newVar();
+ UnnestOperator unnest1 = new UnnestOperator(unnestVar1, new MutableObject<ILogicalExpression>(
+ makeUnnestExpression(new VariableReferenceExpression(lastVar))));
+ unnest1.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
+ LogicalVariable unnestVar2 = context.newVar();
+ UnnestOperator unnest2 = new UnnestOperator(unnestVar2, new MutableObject<ILogicalExpression>(
+ makeUnnestExpression(new VariableReferenceExpression(p1.second))));
+ unnest2.getInputs().add(new MutableObject<ILogicalOperator>(p1.first));
+ List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(
+ 1);
+ LogicalVariable resultVar = context.newVar();
+ Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
+ unnestVar1, unnestVar2, resultVar);
+ varMap.add(triple);
+ UnionAllOperator unionOp = new UnionAllOperator(varMap);
+ unionOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest1));
+ unionOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest2));
+ lastVar = resultVar;
+ lastOp = unionOp;
+ }
+ }
+ LogicalVariable aggVar = context.newVar();
+ ArrayList<LogicalVariable> aggregVars = new ArrayList<LogicalVariable>(1);
+ aggregVars.add(aggVar);
+ List<Mutable<ILogicalExpression>> afcExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
+ afcExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(lastVar)));
+ AggregateFunctionCallExpression afc = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+ AsterixBuiltinFunctions.LISTIFY, afcExprs);
+ ArrayList<Mutable<ILogicalExpression>> aggregExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
+ aggregExprs.add(new MutableObject<ILogicalExpression>(afc));
+ AggregateOperator agg = new AggregateOperator(aggregVars, aggregExprs);
+ agg.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
+ return new Pair<ILogicalOperator, LogicalVariable>(agg, aggVar);
+ }
- private AbstractFunctionCallExpression createComparisonExpression(
- OperatorType t) {
- FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
- IFunctionInfo finfo = FunctionUtils.getFunctionInfo(fi);
- return new ScalarFunctionCallExpression(finfo);
- }
+ private AbstractFunctionCallExpression createComparisonExpression(OperatorType t) {
+ FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
+ IFunctionInfo finfo = FunctionUtils.getFunctionInfo(fi);
+ return new ScalarFunctionCallExpression(finfo);
+ }
- private FunctionIdentifier operatorTypeToFunctionIdentifier(OperatorType t) {
- switch (t) {
- case EQ: {
- return AlgebricksBuiltinFunctions.EQ;
- }
- case NEQ: {
- return AlgebricksBuiltinFunctions.NEQ;
- }
- case GT: {
- return AlgebricksBuiltinFunctions.GT;
- }
- case GE: {
- return AlgebricksBuiltinFunctions.GE;
- }
- case LT: {
- return AlgebricksBuiltinFunctions.LT;
- }
- case LE: {
- return AlgebricksBuiltinFunctions.LE;
- }
- default: {
- throw new IllegalStateException();
- }
- }
- }
+ private FunctionIdentifier operatorTypeToFunctionIdentifier(OperatorType t) {
+ switch (t) {
+ case EQ: {
+ return AlgebricksBuiltinFunctions.EQ;
+ }
+ case NEQ: {
+ return AlgebricksBuiltinFunctions.NEQ;
+ }
+ case GT: {
+ return AlgebricksBuiltinFunctions.GT;
+ }
+ case GE: {
+ return AlgebricksBuiltinFunctions.GE;
+ }
+ case LT: {
+ return AlgebricksBuiltinFunctions.LT;
+ }
+ case LE: {
+ return AlgebricksBuiltinFunctions.LE;
+ }
+ default: {
+ throw new IllegalStateException();
+ }
+ }
+ }
- private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(
- OperatorType t) throws AsterixException {
+ private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(OperatorType t)
+ throws AsterixException {
- FunctionIdentifier fid = null;
- switch (t) {
- case PLUS: {
- fid = AlgebricksBuiltinFunctions.NUMERIC_ADD;
- break;
- }
- case MINUS: {
- fid = AsterixBuiltinFunctions.NUMERIC_SUBTRACT;
- break;
- }
- case MUL: {
- fid = AsterixBuiltinFunctions.NUMERIC_MULTIPLY;
- break;
- }
- case DIV: {
- fid = AsterixBuiltinFunctions.NUMERIC_DIVIDE;
- break;
- }
- case MOD: {
- fid = AsterixBuiltinFunctions.NUMERIC_MOD;
- break;
- }
- case IDIV: {
- fid = AsterixBuiltinFunctions.NUMERIC_IDIV;
- break;
- }
- case CARET: {
- fid = AsterixBuiltinFunctions.CARET;
- break;
- }
- case AND: {
- fid = AlgebricksBuiltinFunctions.AND;
- break;
- }
- case OR: {
- fid = AlgebricksBuiltinFunctions.OR;
- break;
- }
- case FUZZY_EQ: {
- fid = AsterixBuiltinFunctions.FUZZY_EQ;
- break;
- }
+ FunctionIdentifier fid = null;
+ switch (t) {
+ case PLUS: {
+ fid = AlgebricksBuiltinFunctions.NUMERIC_ADD;
+ break;
+ }
+ case MINUS: {
+ fid = AsterixBuiltinFunctions.NUMERIC_SUBTRACT;
+ break;
+ }
+ case MUL: {
+ fid = AsterixBuiltinFunctions.NUMERIC_MULTIPLY;
+ break;
+ }
+ case DIV: {
+ fid = AsterixBuiltinFunctions.NUMERIC_DIVIDE;
+ break;
+ }
+ case MOD: {
+ fid = AsterixBuiltinFunctions.NUMERIC_MOD;
+ break;
+ }
+ case IDIV: {
+ fid = AsterixBuiltinFunctions.NUMERIC_IDIV;
+ break;
+ }
+ case CARET: {
+ fid = AsterixBuiltinFunctions.CARET;
+ break;
+ }
+ case AND: {
+ fid = AlgebricksBuiltinFunctions.AND;
+ break;
+ }
+ case OR: {
+ fid = AlgebricksBuiltinFunctions.OR;
+ break;
+ }
+ case FUZZY_EQ: {
+ fid = AsterixBuiltinFunctions.FUZZY_EQ;
+ break;
+ }
- default: {
- throw new NotImplementedException("Operator " + t
- + " is not yet implemented");
- }
- }
- return new ScalarFunctionCallExpression(
- FunctionUtils.getFunctionInfo(fid));
- }
+ default: {
+ throw new NotImplementedException("Operator " + t + " is not yet implemented");
+ }
+ }
+ return new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fid));
+ }
- private static boolean hasOnlyChild(ILogicalOperator parent,
- Mutable<ILogicalOperator> childCandidate) {
- List<Mutable<ILogicalOperator>> inp = parent.getInputs();
- if (inp == null || inp.size() != 1) {
- return false;
- }
- return inp.get(0) == childCandidate;
- }
+ private static boolean hasOnlyChild(ILogicalOperator parent, Mutable<ILogicalOperator> childCandidate) {
+ List<Mutable<ILogicalOperator>> inp = parent.getInputs();
+ if (inp == null || inp.size() != 1) {
+ return false;
+ }
+ return inp.get(0) == childCandidate;
+ }
- private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(
- Expression expr, Mutable<ILogicalOperator> topOp)
- throws AsterixException {
- switch (expr.getKind()) {
- case VARIABLE_EXPRESSION: {
- VariableReferenceExpression ve = new VariableReferenceExpression(
- context.getVar(((VariableExpr) expr).getVar().getId()));
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve,
- topOp);
- }
- case LITERAL_EXPRESSION: {
- LiteralExpr val = (LiteralExpr) expr;
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
- new ConstantExpression(new AsterixConstantValue(
- ConstantHelper.objectFromLiteral(val.getValue()))),
- topOp);
- }
- default: {
- // Mutable<ILogicalOperator> src = new
- // Mutable<ILogicalOperator>();
- // Mutable<ILogicalOperator> src = topOp;
- if (expressionNeedsNoNesting(expr)) {
- Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
- topOp);
- ILogicalExpression exp = ((AssignOperator) p.first)
- .getExpressions().get(0).getValue();
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
- exp, p.first.getInputs().get(0));
- } else {
- Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>();
+ private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(Expression expr,
+ Mutable<ILogicalOperator> topOp) throws AsterixException {
+ switch (expr.getKind()) {
+ case VARIABLE_EXPRESSION: {
+ VariableReferenceExpression ve = new VariableReferenceExpression(context.getVar(((VariableExpr) expr)
+ .getVar().getId()));
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve, topOp);
+ }
+ case LITERAL_EXPRESSION: {
+ LiteralExpr val = (LiteralExpr) expr;
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new ConstantExpression(
+ new AsterixConstantValue(ConstantHelper.objectFromLiteral(val.getValue()))), topOp);
+ }
+ default: {
+ // Mutable<ILogicalOperator> src = new
+ // Mutable<ILogicalOperator>();
+ // Mutable<ILogicalOperator> src = topOp;
+ if (expressionNeedsNoNesting(expr)) {
+ Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, topOp);
+ ILogicalExpression exp = ((AssignOperator) p.first).getExpressions().get(0).getValue();
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(exp, p.first.getInputs().get(0));
+ } else {
+ Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>();
- Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
- src);
+ Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, src);
- if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
- // src.setOperator(topOp.getOperator());
- Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(
- p.first);
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
- new VariableReferenceExpression(p.second), top2);
- } else {
- SubplanOperator s = new SubplanOperator();
- s.getInputs().add(topOp);
- src.setValue(new NestedTupleSourceOperator(
- new MutableObject<ILogicalOperator>(s)));
- Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(
- p.first);
- s.setRootOp(planRoot);
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
- new VariableReferenceExpression(p.second),
- new MutableObject<ILogicalOperator>(s));
- }
- }
- }
- }
+ if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
+ // src.setOperator(topOp.getOperator());
+ Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(p.first);
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new VariableReferenceExpression(
+ p.second), top2);
+ } else {
+ SubplanOperator s = new SubplanOperator();
+ s.getInputs().add(topOp);
+ src.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
+ Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(p.first);
+ s.setRootOp(planRoot);
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new VariableReferenceExpression(
+ p.second), new MutableObject<ILogicalOperator>(s));
+ }
+ }
+ }
+ }
- }
+ }
- private Pair<ILogicalOperator, LogicalVariable> produceFlwrResult(
- boolean noForClause, boolean isTop,
- Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
- if (isTop) {
- ProjectOperator pr = new ProjectOperator(resVar);
- pr.getInputs().add(resOpRef);
- return new Pair<ILogicalOperator, LogicalVariable>(pr, resVar);
+ private Pair<ILogicalOperator, LogicalVariable> produceFlwrResult(boolean noForClause, boolean isTop,
+ Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
+ if (isTop) {
+ ProjectOperator pr = new ProjectOperator(resVar);
+ pr.getInputs().add(resOpRef);
+ return new Pair<ILogicalOperator, LogicalVariable>(pr, resVar);
- } else if (noForClause) {
- return new Pair<ILogicalOperator, LogicalVariable>(
- resOpRef.getValue(), resVar);
- } else {
- return aggListify(resVar, resOpRef, false);
- }
- }
+ } else if (noForClause) {
+ return new Pair<ILogicalOperator, LogicalVariable>(resOpRef.getValue(), resVar);
+ } else {
+ return aggListify(resVar, resOpRef, false);
+ }
+ }
- private Pair<ILogicalOperator, LogicalVariable> aggListify(
- LogicalVariable var, Mutable<ILogicalOperator> opRef,
- boolean bProject) {
- AggregateFunctionCallExpression funAgg = AsterixBuiltinFunctions
- .makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.LISTIFY,
- new ArrayList<Mutable<ILogicalExpression>>());
- funAgg.getArguments().add(
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(var)));
- LogicalVariable varListified = context.newVar();
- AggregateOperator agg = new AggregateOperator(
- mkSingletonArrayList(varListified),
- (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
- funAgg)));
- agg.getInputs().add(opRef);
- ILogicalOperator res;
- if (bProject) {
- ProjectOperator pr = new ProjectOperator(varListified);
- pr.getInputs().add(new MutableObject<ILogicalOperator>(agg));
- res = pr;
- } else {
- res = agg;
- }
- return new Pair<ILogicalOperator, LogicalVariable>(res, varListified);
- }
+ private Pair<ILogicalOperator, LogicalVariable> aggListify(LogicalVariable var, Mutable<ILogicalOperator> opRef,
+ boolean bProject) {
+ AggregateFunctionCallExpression funAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+ AsterixBuiltinFunctions.LISTIFY, new ArrayList<Mutable<ILogicalExpression>>());
+ funAgg.getArguments().add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
+ LogicalVariable varListified = context.newVar();
+ AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(varListified),
+ (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(funAgg)));
+ agg.getInputs().add(opRef);
+ ILogicalOperator res;
+ if (bProject) {
+ ProjectOperator pr = new ProjectOperator(varListified);
+ pr.getInputs().add(new MutableObject<ILogicalOperator>(agg));
+ res = pr;
+ } else {
+ res = agg;
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(res, varListified);
+ }
- private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(
- OperatorExpr op, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- ArrayList<OperatorType> ops = op.getOpList();
- int nOps = ops.size();
+ private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(OperatorExpr op,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ ArrayList<OperatorType> ops = op.getOpList();
+ int nOps = ops.size();
- ArrayList<Expression> exprs = op.getExprList();
+ ArrayList<Expression> exprs = op.getExprList();
- Mutable<ILogicalOperator> topOp = tupSource;
+ Mutable<ILogicalOperator> topOp = tupSource;
- OperatorType opLogical = ops.get(0);
- AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
+ OperatorType opLogical = ops.get(0);
+ AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
- for (int i = 0; i <= nOps; i++) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- exprs.get(i), topOp);
- topOp = p.second;
- // now look at the operator
- if (i < nOps) {
- if (ops.get(i) != opLogical) {
- throw new TranslationException("Unexpected operator "
- + ops.get(i) + " in an OperatorExpr starting with "
- + opLogical);
- }
- }
- f.getArguments()
- .add(new MutableObject<ILogicalExpression>(p.first));
- }
+ for (int i = 0; i <= nOps; i++) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(exprs.get(i), topOp);
+ topOp = p.second;
+ // now look at the operator
+ if (i < nOps) {
+ if (ops.get(i) != opLogical) {
+ throw new TranslationException("Unexpected operator " + ops.get(i)
+ + " in an OperatorExpr starting with " + opLogical);
+ }
+ }
+ f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
+ }
- LogicalVariable assignedVar = context.newVar();
- AssignOperator a = new AssignOperator(assignedVar,
- new MutableObject<ILogicalExpression>(f));
- a.getInputs().add(topOp);
+ LogicalVariable assignedVar = context.newVar();
+ AssignOperator a = new AssignOperator(assignedVar, new MutableObject<ILogicalExpression>(f));
+ a.getInputs().add(topOp);
- return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
- }
+ }
- private static boolean expressionNeedsNoNesting(Expression expr) {
- Kind k = expr.getKind();
- return k == Kind.LITERAL_EXPRESSION
- || k == Kind.LIST_CONSTRUCTOR_EXPRESSION
- || k == Kind.RECORD_CONSTRUCTOR_EXPRESSION
- || k == Kind.VARIABLE_EXPRESSION || k == Kind.CALL_EXPRESSION
- || k == Kind.OP_EXPRESSION
- || k == Kind.FIELD_ACCESSOR_EXPRESSION
- || k == Kind.INDEX_ACCESSOR_EXPRESSION
- || k == Kind.UNARY_EXPRESSION;
- }
+ private static boolean expressionNeedsNoNesting(Expression expr) {
+ Kind k = expr.getKind();
+ return k == Kind.LITERAL_EXPRESSION || k == Kind.LIST_CONSTRUCTOR_EXPRESSION
+ || k == Kind.RECORD_CONSTRUCTOR_EXPRESSION || k == Kind.VARIABLE_EXPRESSION
+ || k == Kind.CALL_EXPRESSION || k == Kind.OP_EXPRESSION || k == Kind.FIELD_ACCESSOR_EXPRESSION
+ || k == Kind.INDEX_ACCESSOR_EXPRESSION || k == Kind.UNARY_EXPRESSION;
+ }
- private <T> ArrayList<T> mkSingletonArrayList(T item) {
- ArrayList<T> array = new ArrayList<T>(1);
- array.add(item);
- return array;
- }
+ private <T> ArrayList<T> mkSingletonArrayList(T item) {
+ ArrayList<T> array = new ArrayList<T>(1);
+ array.add(item);
+ return array;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitTypeDecl(TypeDecl td,
- Mutable<ILogicalOperator> arg) throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitTypeDecl(TypeDecl td, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitRecordTypeDefiniton(
- RecordTypeDefinition tre, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitRecordTypeDefiniton(RecordTypeDefinition tre,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitTypeReferenceExpression(
- TypeReferenceExpression tre, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitTypeReferenceExpression(TypeReferenceExpression tre,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitNodegroupDecl(
- NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitNodegroupDecl(NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLoadFromFileStatement(
- LoadFromFileStatement stmtLoad, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLoadFromFileStatement(LoadFromFileStatement stmtLoad,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitWriteFromQueryResultStatement(
- WriteFromQueryResultStatement stmtLoad,
- Mutable<ILogicalOperator> arg) throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitWriteFromQueryResultStatement(
+ WriteFromQueryResultStatement stmtLoad, Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDropStatement(
- DropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDropStatement(DropStatement del, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitControlFeedStatement(
- ControlFeedStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitControlFeedStatement(ControlFeedStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitCreateIndexStatement(
- CreateIndexStatement cis, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitCreateIndexStatement(CreateIndexStatement cis,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitOrderedListTypeDefiniton(
- OrderedListTypeDefinition olte, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitOrderedListTypeDefiniton(OrderedListTypeDefinition olte,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUnorderedListTypeDefiniton(
- UnorderedListTypeDefinition ulte, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUnorderedListTypeDefiniton(UnorderedListTypeDefinition ulte,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- private ILogicalExpression makeUnnestExpression(ILogicalExpression expr) {
- switch (expr.getExpressionTag()) {
- case VARIABLE: {
- return new UnnestingFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
- new MutableObject<ILogicalExpression>(expr));
- }
- case FUNCTION_CALL: {
- AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
- if (fce.getKind() == FunctionKind.UNNEST) {
- return expr;
- } else {
- return new UnnestingFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
- new MutableObject<ILogicalExpression>(expr));
- }
- }
- default: {
- return expr;
- }
- }
- }
+ private ILogicalExpression makeUnnestExpression(ILogicalExpression expr) {
+ switch (expr.getExpressionTag()) {
+ case VARIABLE: {
+ return new UnnestingFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
+ new MutableObject<ILogicalExpression>(expr));
+ }
+ case FUNCTION_CALL: {
+ AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
+ if (fce.getKind() == FunctionKind.UNNEST) {
+ return expr;
+ } else {
+ return new UnnestingFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
+ new MutableObject<ILogicalExpression>(expr));
+ }
+ }
+ default: {
+ return expr;
+ }
+ }
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitInsertStatement(
- InsertStatement insert, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitInsertStatement(InsertStatement insert,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDeleteStatement(
- DeleteStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDeleteStatement(DeleteStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUpdateStatement(
- UpdateStatement update, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUpdateStatement(UpdateStatement update,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUpdateClause(
- UpdateClause del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUpdateClause(UpdateClause del, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDataverseDecl(
- DataverseDecl dv, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDataverseDecl(DataverseDecl dv, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDatasetDecl(
- DatasetDecl dd, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDatasetDecl(DatasetDecl dd, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitSetStatement(
- SetStatement ss, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitSetStatement(SetStatement ss, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitWriteStatement(
- WriteStatement ws, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitWriteStatement(WriteStatement ws, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLoadFromQueryResultStatement(
- WriteFromQueryResultStatement stmtLoad,
- Mutable<ILogicalOperator> arg) throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLoadFromQueryResultStatement(
+ WriteFromQueryResultStatement stmtLoad, Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitCreateDataverseStatement(
- CreateDataverseStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitCreateDataverseStatement(CreateDataverseStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitIndexDropStatement(
- IndexDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitIndexDropStatement(IndexDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitNodeGroupDropStatement(
- NodeGroupDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitNodeGroupDropStatement(NodeGroupDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDataverseDropStatement(
- DataverseDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDataverseDropStatement(DataverseDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitTypeDropStatement(
- TypeDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitTypeDropStatement(TypeDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visit(
- CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visit(CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitFunctionDropStatement(
- FunctionDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitFunctionDropStatement(FunctionDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitBeginFeedStatement(
- BeginFeedStatement bf, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitBeginFeedStatement(BeginFeedStatement bf,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
index 4fc1fc8..be6e2af 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
@@ -79,10 +79,8 @@
import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.functions.FunctionSignature;
import edu.uci.ics.asterix.formats.base.IDataFormat;
-import edu.uci.ics.asterix.metadata.MetadataTransactionContext;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
-import edu.uci.ics.asterix.metadata.declared.AqlLogicalPlanAndMetadataImpl;
import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
import edu.uci.ics.asterix.metadata.declared.FileSplitDataSink;
import edu.uci.ics.asterix.metadata.declared.FileSplitSinkId;
@@ -92,11 +90,11 @@
import edu.uci.ics.asterix.om.base.AString;
import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.asterix.om.functions.AsterixFunction;
import edu.uci.ics.asterix.om.functions.AsterixFunctionInfo;
import edu.uci.ics.asterix.om.types.ARecordType;
import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.translator.CompiledStatements.ICompiledDmlStatement;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
@@ -105,7 +103,6 @@
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlanAndMetadata;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.OperatorAnnotations;
@@ -153,1576 +150,1315 @@
* source for the current subtree.
*/
-public class AqlPlusExpressionToPlanTranslator extends AbstractAqlTranslator
- implements
- IAqlPlusExpressionVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
+public class AqlPlusExpressionToPlanTranslator extends AbstractAqlTranslator implements
+ IAqlPlusExpressionVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
- private static final Logger LOGGER = Logger
- .getLogger(AqlPlusExpressionToPlanTranslator.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(AqlPlusExpressionToPlanTranslator.class.getName());
- private class MetaScopeLogicalVariable {
- private HashMap<Identifier, LogicalVariable> map = new HashMap<Identifier, LogicalVariable>();
+ private class MetaScopeLogicalVariable {
+ private HashMap<Identifier, LogicalVariable> map = new HashMap<Identifier, LogicalVariable>();
- public VariableReferenceExpression getVariableReferenceExpression(
- Identifier id) throws AsterixException {
- LogicalVariable var = map.get(id);
- LOGGER.fine("get:" + id + ":" + var);
- if (var == null) {
- throw new AsterixException("Identifier " + id
- + " not found in AQL+ meta-scope.");
- }
- return new VariableReferenceExpression(var);
- }
+ public VariableReferenceExpression getVariableReferenceExpression(Identifier id) throws AsterixException {
+ LogicalVariable var = map.get(id);
+ LOGGER.fine("get:" + id + ":" + var);
+ if (var == null) {
+ throw new AsterixException("Identifier " + id + " not found in AQL+ meta-scope.");
+ }
+ return new VariableReferenceExpression(var);
+ }
- public void put(Identifier id, LogicalVariable var) {
- LOGGER.fine("put:" + id + ":" + var);
- map.put(id, var);
- }
- }
+ public void put(Identifier id, LogicalVariable var) {
+ LOGGER.fine("put:" + id + ":" + var);
+ map.put(id, var);
+ }
+ }
- private class MetaScopeILogicalOperator {
- private HashMap<Identifier, ILogicalOperator> map = new HashMap<Identifier, ILogicalOperator>();
+ private class MetaScopeILogicalOperator {
+ private HashMap<Identifier, ILogicalOperator> map = new HashMap<Identifier, ILogicalOperator>();
- public ILogicalOperator get(Identifier id) throws AsterixException {
- ILogicalOperator op = map.get(id);
- if (op == null) {
- throw new AsterixException("Identifier " + id
- + " not found in AQL+ meta-scope.");
- }
- return op;
- }
+ public ILogicalOperator get(Identifier id) throws AsterixException {
+ ILogicalOperator op = map.get(id);
+ if (op == null) {
+ throw new AsterixException("Identifier " + id + " not found in AQL+ meta-scope.");
+ }
+ return op;
+ }
- public void put(Identifier id, ILogicalOperator op) {
- LOGGER.fine("put:" + id + ":" + op);
- map.put(id, op);
- }
- }
+ public void put(Identifier id, ILogicalOperator op) {
+ LOGGER.fine("put:" + id + ":" + op);
+ map.put(id, op);
+ }
+ }
- private final long txnId;
- private final MetadataTransactionContext mdTxnCtx;
- private TranslationContext context;
- private String outputDatasetName;
- private MetaScopeLogicalVariable metaScopeExp = new MetaScopeLogicalVariable();
- private MetaScopeILogicalOperator metaScopeOp = new MetaScopeILogicalOperator();
- private static LogicalVariable METADATA_DUMMY_VAR = new LogicalVariable(-1);
+ private final long txnId;
+ private TranslationContext context;
+ private String outputDatasetName;
+ private ICompiledDmlStatement stmt;
+ private AqlMetadataProvider metadataProvider;
- public AqlPlusExpressionToPlanTranslator(long txnId,
- MetadataTransactionContext mdTxnCtx, Counter currentVarCounter,
- String outputDatasetName) {
- this.txnId = txnId;
- this.mdTxnCtx = mdTxnCtx;
- this.context = new TranslationContext(currentVarCounter);
- this.outputDatasetName = outputDatasetName;
- this.context.setTopFlwor(false);
- }
+ private MetaScopeLogicalVariable metaScopeExp = new MetaScopeLogicalVariable();
+ private MetaScopeILogicalOperator metaScopeOp = new MetaScopeILogicalOperator();
+ private static LogicalVariable METADATA_DUMMY_VAR = new LogicalVariable(-1);
- public int getVarCounter() {
- return context.getVarCounter();
- }
+
+
+ public AqlPlusExpressionToPlanTranslator(long txnId, AqlMetadataProvider metadataProvider,
+ Counter currentVarCounter, String outputDatasetName, ICompiledDmlStatement stmt) {
+ this.txnId = txnId;
+ this.metadataProvider = metadataProvider;
+ this.context = new TranslationContext(currentVarCounter);
+ this.outputDatasetName = outputDatasetName;
+ this.stmt = stmt;
+ this.context.setTopFlwor(false);
+ }
- public ILogicalPlanAndMetadata translate(Query expr)
- throws AlgebricksException, AsterixException {
- return translate(expr, null);
- }
+ public int getVarCounter() {
+ return context.getVarCounter();
+ }
- public ILogicalPlanAndMetadata translate(Query expr,
- AqlCompiledMetadataDeclarations compiledDeclarations)
- throws AlgebricksException, AsterixException {
- if (expr == null) {
- return null;
- }
- if (compiledDeclarations == null) {
- compiledDeclarations = compileMetadata(mdTxnCtx,
- expr.getPrologDeclList(), true);
- }
- if (!compiledDeclarations.isConnectedToDataverse())
- compiledDeclarations.connectToDataverse(compiledDeclarations
- .getDataverseName());
- IDataFormat format = compiledDeclarations.getFormat();
- if (format == null) {
- throw new AlgebricksException("Data format has not been set.");
- }
- format.registerRuntimeFunctions();
- Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
- new MutableObject<ILogicalOperator>(
- new EmptyTupleSourceOperator()));
+ public ILogicalPlan translate(Query expr) throws AlgebricksException, AsterixException {
+ return translate(expr, null);
+ }
- ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
+ public ILogicalPlan translate(Query expr, AqlMetadataProvider metadata)
+ throws AlgebricksException, AsterixException {
+ IDataFormat format = metadata.getFormat();
+ if (format == null) {
+ throw new AlgebricksException("Data format has not been set.");
+ }
+ format.registerRuntimeFunctions();
+ Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, new MutableObject<ILogicalOperator>(
+ new EmptyTupleSourceOperator()));
- boolean isTransactionalWrite = false;
- ILogicalOperator topOp = p.first;
- ProjectOperator project = (ProjectOperator) topOp;
- LogicalVariable resVar = project.getVariables().get(0);
- if (outputDatasetName == null) {
- List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- writeExprList.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(resVar)));
- FileSplitSinkId fssi = new FileSplitSinkId(
- compiledDeclarations.getOutputFile());
- FileSplitDataSink sink = new FileSplitDataSink(fssi, null);
- topOp = new WriteOperator(writeExprList, sink);
- topOp.getInputs().add(new MutableObject<ILogicalOperator>(project));
- } else {
- Dataset dataset = compiledDeclarations
- .findDataset(outputDatasetName);
- if (dataset == null) {
- throw new AlgebricksException("Cannot find dataset "
- + outputDatasetName);
- }
- if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
- throw new AlgebricksException(
- "Cannot write output to an external dataset.");
- }
- ARecordType itemType = (ARecordType) compiledDeclarations
- .findType(dataset.getItemTypeName());
- List<String> partitioningKeys = DatasetUtils
- .getPartitioningKeys(dataset);
- ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>();
- ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
- List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>();
- for (String partitioningKey : partitioningKeys) {
- Triple<ICopyEvaluatorFactory, ScalarFunctionCallExpression, IAType> partitioner = format
- .partitioningEvaluatorFactory(itemType, partitioningKey);
- AbstractFunctionCallExpression f = partitioner.second
- .cloneExpression();
- f.substituteVar(METADATA_DUMMY_VAR, resVar);
- exprs.add(new MutableObject<ILogicalExpression>(f));
- LogicalVariable v = context.newVar();
- vars.add(v);
- varRefsForLoading.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(v)));
- }
- AssignOperator assign = new AssignOperator(vars, exprs);
- assign.getInputs()
- .add(new MutableObject<ILogicalOperator>(project));
- }
+ ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
- globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
- ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
- AqlMetadataProvider metadataProvider = new AqlMetadataProvider(txnId,
- isTransactionalWrite, compiledDeclarations);
- ILogicalPlanAndMetadata planAndMetadata = new AqlLogicalPlanAndMetadataImpl(
- plan, metadataProvider);
- return planAndMetadata;
- }
+ boolean isTransactionalWrite = false;
+ ILogicalOperator topOp = p.first;
+ ProjectOperator project = (ProjectOperator) topOp;
+ LogicalVariable resVar = project.getVariables().get(0);
+ if (outputDatasetName == null) {
+ List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(1);
+ writeExprList.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(resVar)));
+ FileSplitSinkId fssi = new FileSplitSinkId(metadata.getOutputFile());
+ FileSplitDataSink sink = new FileSplitDataSink(fssi, null);
+ topOp = new WriteOperator(writeExprList, sink);
+ topOp.getInputs().add(new MutableObject<ILogicalOperator>(project));
+ } else {
+ Dataset dataset = metadata.findDataset(stmt.getDataverseName(), outputDatasetName);
+ if (dataset == null) {
+ throw new AlgebricksException("Cannot find dataset " + outputDatasetName);
+ }
+ if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
+ throw new AlgebricksException("Cannot write output to an external dataset.");
+ }
+ ARecordType itemType = (ARecordType) metadata.findType(dataset.getDataverseName(),
+ dataset.getItemTypeName());
+ List<String> partitioningKeys = DatasetUtils.getPartitioningKeys(dataset);
+ ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>();
+ ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
+ List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>();
+ for (String partitioningKey : partitioningKeys) {
+ Triple<ICopyEvaluatorFactory, ScalarFunctionCallExpression, IAType> partitioner = format
+ .partitioningEvaluatorFactory(itemType, partitioningKey);
+ AbstractFunctionCallExpression f = partitioner.second.cloneExpression();
+ f.substituteVar(METADATA_DUMMY_VAR, resVar);
+ exprs.add(new MutableObject<ILogicalExpression>(f));
+ LogicalVariable v = context.newVar();
+ vars.add(v);
+ varRefsForLoading.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v)));
+ }
+ AssignOperator assign = new AssignOperator(vars, exprs);
+ assign.getInputs().add(new MutableObject<ILogicalOperator>(project));
+ }
- public ILogicalPlan translate(List<Clause> clauses)
- throws AlgebricksException, AsterixException {
+ globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
+ ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
+ return plan;
+ }
- if (clauses == null) {
- return null;
- }
+ public ILogicalPlan translate(List<Clause> clauses) throws AlgebricksException, AsterixException {
- Mutable<ILogicalOperator> opRef = new MutableObject<ILogicalOperator>(
- new EmptyTupleSourceOperator());
- Pair<ILogicalOperator, LogicalVariable> p = null;
- for (Clause c : clauses) {
- p = c.accept(this, opRef);
- opRef = new MutableObject<ILogicalOperator>(p.first);
- }
+ if (clauses == null) {
+ return null;
+ }
- ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
+ Mutable<ILogicalOperator> opRef = new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator());
+ Pair<ILogicalOperator, LogicalVariable> p = null;
+ for (Clause c : clauses) {
+ p = c.accept(this, opRef);
+ opRef = new MutableObject<ILogicalOperator>(p.first);
+ }
- ILogicalOperator topOp = p.first;
+ ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
- globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
- ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
- return plan;
- }
+ ILogicalOperator topOp = p.first;
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitForClause(ForClause fc,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- LogicalVariable v = context.newVar(fc.getVarExpr());
+ globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
+ ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
+ return plan;
+ }
- Expression inExpr = fc.getInExpr();
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- inExpr, tupSource);
- ILogicalOperator returnedOp;
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitForClause(ForClause fc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ LogicalVariable v = context.newVar(fc.getVarExpr());
- if (fc.getPosVarExpr() == null) {
- returnedOp = new UnnestOperator(v,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(eo.first)));
- } else {
- LogicalVariable pVar = context.newVar(fc.getPosVarExpr());
- returnedOp = new UnnestOperator(v,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(eo.first)), pVar,
- BuiltinType.AINT32);
- }
- returnedOp.getInputs().add(eo.second);
+ Expression inExpr = fc.getInExpr();
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(inExpr, tupSource);
+ ILogicalOperator returnedOp;
- return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
- }
+ if (fc.getPosVarExpr() == null) {
+ returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)));
+ } else {
+ LogicalVariable pVar = context.newVar(fc.getPosVarExpr());
+ returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)),
+ pVar, BuiltinType.AINT32);
+ }
+ returnedOp.getInputs().add(eo.second);
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLetClause(LetClause lc,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- LogicalVariable v;
- ILogicalOperator returnedOp;
+ return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
+ }
- switch (lc.getBindingExpr().getKind()) {
- case VARIABLE_EXPRESSION: {
- v = context.newVar(lc.getVarExpr());
- LogicalVariable prev = context.getVar(((VariableExpr) lc
- .getBindingExpr()).getVar().getId());
- returnedOp = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(prev)));
- returnedOp.getInputs().add(tupSource);
- break;
- }
- default: {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- lc.getBindingExpr(), tupSource);
- v = context.newVar(lc.getVarExpr());
- returnedOp = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(eo.first));
- returnedOp.getInputs().add(eo.second);
- break;
- }
- }
- return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLetClause(LetClause lc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ LogicalVariable v;
+ ILogicalOperator returnedOp;
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitFlworExpression(
- FLWOGRExpression flwor, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Mutable<ILogicalOperator> flworPlan = tupSource;
- boolean isTop = context.isTopFlwor();
- if (isTop) {
- context.setTopFlwor(false);
- }
- for (Clause c : flwor.getClauseList()) {
- Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this,
- flworPlan);
- flworPlan = new MutableObject<ILogicalOperator>(pC.first);
- }
+ switch (lc.getBindingExpr().getKind()) {
+ case VARIABLE_EXPRESSION: {
+ v = context.newVar(lc.getVarExpr());
+ LogicalVariable prev = context.getVar(((VariableExpr) lc.getBindingExpr()).getVar().getId());
+ returnedOp = new AssignOperator(v, new MutableObject<ILogicalExpression>(
+ new VariableReferenceExpression(prev)));
+ returnedOp.getInputs().add(tupSource);
+ break;
+ }
+ default: {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(lc.getBindingExpr(),
+ tupSource);
+ v = context.newVar(lc.getVarExpr());
+ returnedOp = new AssignOperator(v, new MutableObject<ILogicalExpression>(eo.first));
+ returnedOp.getInputs().add(eo.second);
+ break;
+ }
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
+ }
- Expression r = flwor.getReturnExpr();
- boolean noFlworClause = flwor.noForClause();
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitFlworExpression(FLWOGRExpression flwor,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Mutable<ILogicalOperator> flworPlan = tupSource;
+ boolean isTop = context.isTopFlwor();
+ if (isTop) {
+ context.setTopFlwor(false);
+ }
+ for (Clause c : flwor.getClauseList()) {
+ Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this, flworPlan);
+ flworPlan = new MutableObject<ILogicalOperator>(pC.first);
+ }
- if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
- VariableExpr v = (VariableExpr) r;
- LogicalVariable var = context.getVar(v.getVar().getId());
+ Expression r = flwor.getReturnExpr();
+ boolean noFlworClause = flwor.noForClause();
- return produceFlwrResult(noFlworClause, isTop, flworPlan, var);
+ if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
+ VariableExpr v = (VariableExpr) r;
+ LogicalVariable var = context.getVar(v.getVar().getId());
- } else {
- Mutable<ILogicalOperator> baseOp = new MutableObject<ILogicalOperator>(
- flworPlan.getValue());
- Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this,
- baseOp);
- ILogicalOperator rOp = rRes.first;
- ILogicalOperator resOp;
- if (expressionNeedsNoNesting(r)) {
- baseOp.setValue(flworPlan.getValue());
- resOp = rOp;
- } else {
- SubplanOperator s = new SubplanOperator(rOp);
- s.getInputs().add(flworPlan);
- resOp = s;
- baseOp.setValue(new NestedTupleSourceOperator(
- new MutableObject<ILogicalOperator>(s)));
- }
- Mutable<ILogicalOperator> resOpRef = new MutableObject<ILogicalOperator>(
- resOp);
- return produceFlwrResult(noFlworClause, isTop, resOpRef,
- rRes.second);
- }
- }
+ return produceFlwrResult(noFlworClause, isTop, flworPlan, var);
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitFieldAccessor(
- FieldAccessor fa, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- fa.getExpr(), tupSource);
- LogicalVariable v = context.newVar();
- AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME));
- fldAccess.getArguments().add(
- new MutableObject<ILogicalExpression>(p.first));
- ILogicalExpression faExpr = new ConstantExpression(
- new AsterixConstantValue(new AString(fa.getIdent().getValue())));
- fldAccess.getArguments().add(
- new MutableObject<ILogicalExpression>(faExpr));
- AssignOperator a = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(fldAccess));
- a.getInputs().add(p.second);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v);
+ } else {
+ Mutable<ILogicalOperator> baseOp = new MutableObject<ILogicalOperator>(flworPlan.getValue());
+ Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this, baseOp);
+ ILogicalOperator rOp = rRes.first;
+ ILogicalOperator resOp;
+ if (expressionNeedsNoNesting(r)) {
+ baseOp.setValue(flworPlan.getValue());
+ resOp = rOp;
+ } else {
+ SubplanOperator s = new SubplanOperator(rOp);
+ s.getInputs().add(flworPlan);
+ resOp = s;
+ baseOp.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
+ }
+ Mutable<ILogicalOperator> resOpRef = new MutableObject<ILogicalOperator>(resOp);
+ return produceFlwrResult(noFlworClause, isTop, resOpRef, rRes.second);
+ }
+ }
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitFieldAccessor(FieldAccessor fa,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(fa.getExpr(), tupSource);
+ LogicalVariable v = context.newVar();
+ AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME));
+ fldAccess.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
+ ILogicalExpression faExpr = new ConstantExpression(new AsterixConstantValue(new AString(fa.getIdent()
+ .getValue())));
+ fldAccess.getArguments().add(new MutableObject<ILogicalExpression>(faExpr));
+ AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(fldAccess));
+ a.getInputs().add(p.second);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v);
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitIndexAccessor(
- IndexAccessor ia, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- ia.getExpr(), tupSource);
- LogicalVariable v = context.newVar();
- AbstractFunctionCallExpression f;
- int i = ia.getIndex();
- if (i == IndexAccessor.ANY) {
- f = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
- f.getArguments()
- .add(new MutableObject<ILogicalExpression>(p.first));
- } else {
- f = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
- f.getArguments()
- .add(new MutableObject<ILogicalExpression>(p.first));
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(
- new ConstantExpression(new AsterixConstantValue(
- new AInt32(i)))));
- }
- AssignOperator a = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(f));
- a.getInputs().add(p.second);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v);
- }
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitCallExpr(
- CallExpr fcall, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- LogicalVariable v = context.newVar();
- AsterixFunction fid = fcall.getIdent();
- List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
- Mutable<ILogicalOperator> topOp = tupSource;
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitIndexAccessor(IndexAccessor ia,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(ia.getExpr(), tupSource);
+ LogicalVariable v = context.newVar();
+ AbstractFunctionCallExpression f;
+ int i = ia.getIndex();
+ if (i == IndexAccessor.ANY) {
+ f = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
+ f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
+ } else {
+ f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
+ f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
+ f.getArguments().add(
+ new MutableObject<ILogicalExpression>(new ConstantExpression(
+ new AsterixConstantValue(new AInt32(i)))));
+ }
+ AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
+ a.getInputs().add(p.second);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v);
+ }
- for (Expression expr : fcall.getExprList()) {
- switch (expr.getKind()) {
- case VARIABLE_EXPRESSION: {
- LogicalVariable var = context.getVar(((VariableExpr) expr)
- .getVar().getId());
- args.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(var)));
- break;
- }
- case LITERAL_EXPRESSION: {
- LiteralExpr val = (LiteralExpr) expr;
- args.add(new MutableObject<ILogicalExpression>(
- new ConstantExpression(
- new AsterixConstantValue(ConstantHelper
- .objectFromLiteral(val.getValue())))));
- break;
- }
- default: {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- expr, topOp);
- AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second
- .getValue();
- args.add(new MutableObject<ILogicalExpression>(eo.first));
- if (o1 != null
- && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(
- o1, topOp))) {
- topOp = eo.second;
- }
- break;
- }
- }
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitCallExpr(CallExpr fcall, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ LogicalVariable v = context.newVar();
+ FunctionSignature signature = fcall.getFunctionSignature();
+ List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
+ Mutable<ILogicalOperator> topOp = tupSource;
- FunctionIdentifier fi = new FunctionIdentifier(
- AlgebricksBuiltinFunctions.ALGEBRICKS_NS, fid.getFunctionName());
- AsterixFunctionInfo afi = AsterixBuiltinFunctions.lookupFunction(fi);
- FunctionIdentifier builtinAquafi = afi == null ? null : afi
- .getFunctionIdentifier();
+ for (Expression expr : fcall.getExprList()) {
+ switch (expr.getKind()) {
+ case VARIABLE_EXPRESSION: {
+ LogicalVariable var = context.getVar(((VariableExpr) expr).getVar().getId());
+ args.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
+ break;
+ }
+ case LITERAL_EXPRESSION: {
+ LiteralExpr val = (LiteralExpr) expr;
+ args.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(
+ ConstantHelper.objectFromLiteral(val.getValue())))));
+ break;
+ }
+ default: {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, topOp);
+ AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second.getValue();
+ args.add(new MutableObject<ILogicalExpression>(eo.first));
+ if (o1 != null && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(o1, topOp))) {
+ topOp = eo.second;
+ }
+ break;
+ }
+ }
+ }
- if (builtinAquafi != null) {
- fi = builtinAquafi;
- } else {
- fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
- fid.getFunctionName());
- FunctionIdentifier builtinAsterixFi = AsterixBuiltinFunctions
- .getBuiltinFunctionIdentifier(fi);
- if (builtinAsterixFi != null) {
- fi = builtinAsterixFi;
- }
- }
- AbstractFunctionCallExpression f;
- if (AsterixBuiltinFunctions.isBuiltinAggregateFunction(fi)) {
- f = AsterixBuiltinFunctions.makeAggregateFunctionExpression(fi,
- args);
- } else if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(fi)) {
- UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(
- FunctionUtils.getFunctionInfo(fi), args);
- ufce.setReturnsUniqueValues(AsterixBuiltinFunctions
- .returnsUniqueValues(fi));
- f = ufce;
- } else {
- f = new ScalarFunctionCallExpression(
- FunctionUtils.getFunctionInfo(fi), args);
- }
- AssignOperator op = new AssignOperator(v,
- new MutableObject<ILogicalExpression>(f));
- if (topOp != null) {
- op.getInputs().add(topOp);
- }
+ FunctionIdentifier fi = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS, signature.getName());
+ AsterixFunctionInfo afi = AsterixBuiltinFunctions.lookupFunction(fi);
+ FunctionIdentifier builtinAquafi = afi == null ? null : afi.getFunctionIdentifier();
- return new Pair<ILogicalOperator, LogicalVariable>(op, v);
- }
+ if (builtinAquafi != null) {
+ fi = builtinAquafi;
+ } else {
+ fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, signature.getName());
+ FunctionIdentifier builtinAsterixFi = AsterixBuiltinFunctions.getBuiltinFunctionIdentifier(fi);
+ if (builtinAsterixFi != null) {
+ fi = builtinAsterixFi;
+ }
+ }
+ AbstractFunctionCallExpression f;
+ if (AsterixBuiltinFunctions.isBuiltinAggregateFunction(fi)) {
+ f = AsterixBuiltinFunctions.makeAggregateFunctionExpression(fi, args);
+ } else if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(fi)) {
+ UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(fi), args);
+ ufce.setReturnsUniqueValues(AsterixBuiltinFunctions.returnsUniqueValues(fi));
+ f = ufce;
+ } else {
+ f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fi), args);
+ }
+ AssignOperator op = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
+ if (topOp != null) {
+ op.getInputs().add(topOp);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitFunctionDecl(
- FunctionDecl fd, Mutable<ILogicalOperator> tupSource) {
- // TODO Auto-generated method stub
- throw new NotImplementedException();
- }
+ return new Pair<ILogicalOperator, LogicalVariable>(op, v);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitGroupbyClause(
- GroupbyClause gc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- GroupByOperator gOp = new GroupByOperator();
- Mutable<ILogicalOperator> topOp = tupSource;
- for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
- LogicalVariable v;
- VariableExpr vexpr = ve.getVar();
- if (vexpr != null) {
- v = context.newVar(vexpr);
- } else {
- v = context.newVar();
- }
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- ve.getExpr(), topOp);
- gOp.addGbyExpression(v, eo.first);
- topOp = eo.second;
- }
- for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
- LogicalVariable v;
- VariableExpr vexpr = ve.getVar();
- if (vexpr != null) {
- v = context.newVar(vexpr);
- } else {
- v = context.newVar();
- }
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- ve.getExpr(), topOp);
- gOp.addDecorExpression(v, eo.first);
- topOp = eo.second;
- }
- gOp.getInputs().add(topOp);
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitFunctionDecl(FunctionDecl fd,
+ Mutable<ILogicalOperator> tupSource) {
+ // TODO Auto-generated method stub
+ throw new NotImplementedException();
+ }
- for (VariableExpr var : gc.getWithVarList()) {
- LogicalVariable aggVar = context.newVar();
- LogicalVariable oldVar = context.getVar(var);
- List<Mutable<ILogicalExpression>> flArgs = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- flArgs.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(oldVar)));
- AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions
- .makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.LISTIFY, flArgs);
- AggregateOperator agg = new AggregateOperator(
- mkSingletonArrayList(aggVar),
- (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
- fListify)));
- agg.getInputs().add(
- new MutableObject<ILogicalOperator>(
- new NestedTupleSourceOperator(
- new MutableObject<ILogicalOperator>(gOp))));
- ILogicalPlan plan = new ALogicalPlanImpl(
- new MutableObject<ILogicalOperator>(agg));
- gOp.getNestedPlans().add(plan);
- // Hide the variable that was part of the "with", replacing it with
- // the one bound by the aggregation op.
- context.setVar(var, aggVar);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitGroupbyClause(GroupbyClause gc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ GroupByOperator gOp = new GroupByOperator();
+ Mutable<ILogicalOperator> topOp = tupSource;
+ for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
+ LogicalVariable v;
+ VariableExpr vexpr = ve.getVar();
+ if (vexpr != null) {
+ v = context.newVar(vexpr);
+ } else {
+ v = context.newVar();
+ }
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(ve.getExpr(), topOp);
+ gOp.addGbyExpression(v, eo.first);
+ topOp = eo.second;
+ }
+ for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
+ LogicalVariable v;
+ VariableExpr vexpr = ve.getVar();
+ if (vexpr != null) {
+ v = context.newVar(vexpr);
+ } else {
+ v = context.newVar();
+ }
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(ve.getExpr(), topOp);
+ gOp.addDecorExpression(v, eo.first);
+ topOp = eo.second;
+ }
+ gOp.getInputs().add(topOp);
- gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY,
- gc.hasHashGroupByHint());
- return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
- }
+ for (VariableExpr var : gc.getWithVarList()) {
+ LogicalVariable aggVar = context.newVar();
+ LogicalVariable oldVar = context.getVar(var);
+ List<Mutable<ILogicalExpression>> flArgs = new ArrayList<Mutable<ILogicalExpression>>(1);
+ flArgs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(oldVar)));
+ AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+ AsterixBuiltinFunctions.LISTIFY, flArgs);
+ AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(aggVar),
+ (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(fListify)));
+ agg.getInputs().add(
+ new MutableObject<ILogicalOperator>(new NestedTupleSourceOperator(
+ new MutableObject<ILogicalOperator>(gOp))));
+ ILogicalPlan plan = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(agg));
+ gOp.getNestedPlans().add(plan);
+ // Hide the variable that was part of the "with", replacing it with
+ // the one bound by the aggregation op.
+ context.setVar(var, aggVar);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitIfExpr(IfExpr ifexpr,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- // In the most general case, IfThenElse is translated in the following
- // way.
- //
- // We assign the result of the condition to one variable varCond.
- // We create one subplan which contains the plan for the "then" branch,
- // on top of which there is a selection whose condition is varCond.
- // Similarly, we create one subplan for the "else" branch, in which the
- // selection is not(varCond).
- // Finally, we concatenate the results. (??)
+ gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, gc.hasHashGroupByHint());
+ return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
+ }
- Pair<ILogicalOperator, LogicalVariable> pCond = ifexpr.getCondExpr()
- .accept(this, tupSource);
- ILogicalOperator opCond = pCond.first;
- LogicalVariable varCond = pCond.second;
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitIfExpr(IfExpr ifexpr, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ // In the most general case, IfThenElse is translated in the following
+ // way.
+ //
+ // We assign the result of the condition to one variable varCond.
+ // We create one subplan which contains the plan for the "then" branch,
+ // on top of which there is a selection whose condition is varCond.
+ // Similarly, we create one subplan for the "else" branch, in which the
+ // selection is not(varCond).
+ // Finally, we concatenate the results. (??)
- SubplanOperator sp = new SubplanOperator();
- Mutable<ILogicalOperator> nestedSource = new MutableObject<ILogicalOperator>(
- new NestedTupleSourceOperator(
- new MutableObject<ILogicalOperator>(sp)));
+ Pair<ILogicalOperator, LogicalVariable> pCond = ifexpr.getCondExpr().accept(this, tupSource);
+ ILogicalOperator opCond = pCond.first;
+ LogicalVariable varCond = pCond.second;
- Pair<ILogicalOperator, LogicalVariable> pThen = ifexpr.getThenExpr()
- .accept(this, nestedSource);
- SelectOperator sel1 = new SelectOperator(
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(varCond)));
- sel1.getInputs().add(new MutableObject<ILogicalOperator>(pThen.first));
+ SubplanOperator sp = new SubplanOperator();
+ Mutable<ILogicalOperator> nestedSource = new MutableObject<ILogicalOperator>(new NestedTupleSourceOperator(
+ new MutableObject<ILogicalOperator>(sp)));
- Pair<ILogicalOperator, LogicalVariable> pElse = ifexpr.getElseExpr()
- .accept(this, nestedSource);
- AbstractFunctionCallExpression notVarCond = new ScalarFunctionCallExpression(
- FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT),
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(varCond)));
- SelectOperator sel2 = new SelectOperator(
- new MutableObject<ILogicalExpression>(notVarCond));
- sel2.getInputs().add(new MutableObject<ILogicalOperator>(pElse.first));
+ Pair<ILogicalOperator, LogicalVariable> pThen = ifexpr.getThenExpr().accept(this, nestedSource);
+ SelectOperator sel1 = new SelectOperator(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(
+ varCond)));
+ sel1.getInputs().add(new MutableObject<ILogicalOperator>(pThen.first));
- ILogicalPlan p1 = new ALogicalPlanImpl(
- new MutableObject<ILogicalOperator>(sel1));
- sp.getNestedPlans().add(p1);
- ILogicalPlan p2 = new ALogicalPlanImpl(
- new MutableObject<ILogicalOperator>(sel2));
- sp.getNestedPlans().add(p2);
+ Pair<ILogicalOperator, LogicalVariable> pElse = ifexpr.getElseExpr().accept(this, nestedSource);
+ AbstractFunctionCallExpression notVarCond = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), new MutableObject<ILogicalExpression>(
+ new VariableReferenceExpression(varCond)));
+ SelectOperator sel2 = new SelectOperator(new MutableObject<ILogicalExpression>(notVarCond));
+ sel2.getInputs().add(new MutableObject<ILogicalOperator>(pElse.first));
- Mutable<ILogicalOperator> opCondRef = new MutableObject<ILogicalOperator>(
- opCond);
- sp.getInputs().add(opCondRef);
+ ILogicalPlan p1 = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(sel1));
+ sp.getNestedPlans().add(p1);
+ ILogicalPlan p2 = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(sel2));
+ sp.getNestedPlans().add(p2);
- LogicalVariable resV = context.newVar();
- AbstractFunctionCallExpression concatNonNull = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.CONCAT_NON_NULL),
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(pThen.second)),
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(pElse.second)));
- AssignOperator a = new AssignOperator(resV,
- new MutableObject<ILogicalExpression>(concatNonNull));
- a.getInputs().add(new MutableObject<ILogicalOperator>(sp));
+ Mutable<ILogicalOperator> opCondRef = new MutableObject<ILogicalOperator>(opCond);
+ sp.getInputs().add(opCondRef);
- return new Pair<ILogicalOperator, LogicalVariable>(a, resV);
- }
+ LogicalVariable resV = context.newVar();
+ AbstractFunctionCallExpression concatNonNull = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.CONCAT_NON_NULL),
+ new MutableObject<ILogicalExpression>(new VariableReferenceExpression(pThen.second)),
+ new MutableObject<ILogicalExpression>(new VariableReferenceExpression(pElse.second)));
+ AssignOperator a = new AssignOperator(resV, new MutableObject<ILogicalExpression>(concatNonNull));
+ a.getInputs().add(new MutableObject<ILogicalOperator>(sp));
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLiteralExpr(
- LiteralExpr l, Mutable<ILogicalOperator> tupSource) {
- LogicalVariable var = context.newVar();
- AssignOperator a = new AssignOperator(var,
- new MutableObject<ILogicalExpression>(new ConstantExpression(
- new AsterixConstantValue(ConstantHelper
- .objectFromLiteral(l.getValue())))));
- if (tupSource != null) {
- a.getInputs().add(tupSource);
- }
- return new Pair<ILogicalOperator, LogicalVariable>(a, var);
- }
+ return new Pair<ILogicalOperator, LogicalVariable>(a, resV);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitOperatorExpr(
- OperatorExpr op, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- ArrayList<OperatorType> ops = op.getOpList();
- int nOps = ops.size();
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLiteralExpr(LiteralExpr l, Mutable<ILogicalOperator> tupSource) {
+ LogicalVariable var = context.newVar();
+ AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(new ConstantExpression(
+ new AsterixConstantValue(ConstantHelper.objectFromLiteral(l.getValue())))));
+ if (tupSource != null) {
+ a.getInputs().add(tupSource);
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+ }
- if (nOps > 0
- && (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
- return visitAndOrOperator(op, tupSource);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitOperatorExpr(OperatorExpr op,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ ArrayList<OperatorType> ops = op.getOpList();
+ int nOps = ops.size();
- ArrayList<Expression> exprs = op.getExprList();
+ if (nOps > 0 && (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
+ return visitAndOrOperator(op, tupSource);
+ }
- Mutable<ILogicalOperator> topOp = tupSource;
+ ArrayList<Expression> exprs = op.getExprList();
- ILogicalExpression currExpr = null;
- for (int i = 0; i <= nOps; i++) {
+ Mutable<ILogicalOperator> topOp = tupSource;
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- exprs.get(i), topOp);
- topOp = p.second;
- ILogicalExpression e = p.first;
- // now look at the operator
- if (i < nOps) {
- if (OperatorExpr.opIsComparison(ops.get(i))) {
- AbstractFunctionCallExpression c = createComparisonExpression(ops
- .get(i));
+ ILogicalExpression currExpr = null;
+ for (int i = 0; i <= nOps; i++) {
- // chain the operators
- if (i == 0) {
- c.getArguments().add(
- new MutableObject<ILogicalExpression>(e));
- currExpr = c;
- if (op.isBroadcastOperand(i)) {
- BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
- bcast.setObject(BroadcastSide.LEFT);
- c.getAnnotations()
- .put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
- bcast);
- }
- } else {
- ((AbstractFunctionCallExpression) currExpr)
- .getArguments()
- .add(new MutableObject<ILogicalExpression>(e));
- c.getArguments()
- .add(new MutableObject<ILogicalExpression>(
- currExpr));
- currExpr = c;
- if (i == 1 && op.isBroadcastOperand(i)) {
- BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
- bcast.setObject(BroadcastSide.RIGHT);
- c.getAnnotations()
- .put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
- bcast);
- }
- }
- } else {
- AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops
- .get(i));
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(exprs.get(i), topOp);
+ topOp = p.second;
+ ILogicalExpression e = p.first;
+ // now look at the operator
+ if (i < nOps) {
+ if (OperatorExpr.opIsComparison(ops.get(i))) {
+ AbstractFunctionCallExpression c = createComparisonExpression(ops.get(i));
- if (i == 0) {
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(e));
- currExpr = f;
- } else {
- ((AbstractFunctionCallExpression) currExpr)
- .getArguments()
- .add(new MutableObject<ILogicalExpression>(e));
- f.getArguments()
- .add(new MutableObject<ILogicalExpression>(
- currExpr));
- currExpr = f;
- }
- }
- } else { // don't forget the last expression...
- ((AbstractFunctionCallExpression) currExpr).getArguments().add(
- new MutableObject<ILogicalExpression>(e));
- if (i == 1 && op.isBroadcastOperand(i)) {
- BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
- bcast.setObject(BroadcastSide.RIGHT);
- ((AbstractFunctionCallExpression) currExpr)
- .getAnnotations()
- .put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
- bcast);
- }
- }
- }
+ // chain the operators
+ if (i == 0) {
+ c.getArguments().add(new MutableObject<ILogicalExpression>(e));
+ currExpr = c;
+ if (op.isBroadcastOperand(i)) {
+ BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+ bcast.setObject(BroadcastSide.LEFT);
+ c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
+ }
+ } else {
+ ((AbstractFunctionCallExpression) currExpr).getArguments().add(
+ new MutableObject<ILogicalExpression>(e));
+ c.getArguments().add(new MutableObject<ILogicalExpression>(currExpr));
+ currExpr = c;
+ if (i == 1 && op.isBroadcastOperand(i)) {
+ BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+ bcast.setObject(BroadcastSide.RIGHT);
+ c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
+ }
+ }
+ } else {
+ AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops.get(i));
- LogicalVariable assignedVar = context.newVar();
- AssignOperator a = new AssignOperator(assignedVar,
- new MutableObject<ILogicalExpression>(currExpr));
+ if (i == 0) {
+ f.getArguments().add(new MutableObject<ILogicalExpression>(e));
+ currExpr = f;
+ } else {
+ ((AbstractFunctionCallExpression) currExpr).getArguments().add(
+ new MutableObject<ILogicalExpression>(e));
+ f.getArguments().add(new MutableObject<ILogicalExpression>(currExpr));
+ currExpr = f;
+ }
+ }
+ } else { // don't forget the last expression...
+ ((AbstractFunctionCallExpression) currExpr).getArguments()
+ .add(new MutableObject<ILogicalExpression>(e));
+ if (i == 1 && op.isBroadcastOperand(i)) {
+ BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+ bcast.setObject(BroadcastSide.RIGHT);
+ ((AbstractFunctionCallExpression) currExpr).getAnnotations().put(
+ BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
+ }
+ }
+ }
- a.getInputs().add(topOp);
+ LogicalVariable assignedVar = context.newVar();
+ AssignOperator a = new AssignOperator(assignedVar, new MutableObject<ILogicalExpression>(currExpr));
- return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
- }
+ a.getInputs().add(topOp);
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitOrderbyClause(
- OrderbyClause oc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
+ return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
+ }
- OrderOperator ord = new OrderOperator();
- Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
- Mutable<ILogicalOperator> topOp = tupSource;
- for (Expression e : oc.getOrderbyList()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- e, topOp);
- OrderModifier m = modifIter.next();
- OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER
- : OrderOperator.DESC_ORDER;
- ord.getOrderExpressions().add(
- new Pair<IOrder, Mutable<ILogicalExpression>>(comp,
- new MutableObject<ILogicalExpression>(p.first)));
- topOp = p.second;
- }
- ord.getInputs().add(topOp);
- if (oc.getNumTuples() > 0) {
- ord.getAnnotations().put(OperatorAnnotations.CARDINALITY,
- oc.getNumTuples());
- }
- if (oc.getNumFrames() > 0) {
- ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES,
- oc.getNumFrames());
- }
- return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitOrderbyClause(OrderbyClause oc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitQuantifiedExpression(
- QuantifiedExpression qe, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Mutable<ILogicalOperator> topOp = tupSource;
+ OrderOperator ord = new OrderOperator();
+ Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
+ Mutable<ILogicalOperator> topOp = tupSource;
+ for (Expression e : oc.getOrderbyList()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(e, topOp);
+ OrderModifier m = modifIter.next();
+ OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
+ ord.getOrderExpressions()
+ .add(new Pair<IOrder, Mutable<ILogicalExpression>>(comp, new MutableObject<ILogicalExpression>(
+ p.first)));
+ topOp = p.second;
+ }
+ ord.getInputs().add(topOp);
+ if (oc.getNumTuples() > 0) {
+ ord.getAnnotations().put(OperatorAnnotations.CARDINALITY, oc.getNumTuples());
+ }
+ if (oc.getNumFrames() > 0) {
+ ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames());
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
+ }
- ILogicalOperator firstOp = null;
- Mutable<ILogicalOperator> lastOp = null;
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitQuantifiedExpression(QuantifiedExpression qe,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Mutable<ILogicalOperator> topOp = tupSource;
- for (QuantifiedPair qt : qe.getQuantifiedList()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(
- qt.getExpr(), topOp);
- topOp = eo1.second;
- LogicalVariable uVar = context.newVar(qt.getVarExpr());
- ILogicalOperator u = new UnnestOperator(uVar,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(eo1.first)));
+ ILogicalOperator firstOp = null;
+ Mutable<ILogicalOperator> lastOp = null;
- if (firstOp == null) {
- firstOp = u;
- }
- if (lastOp != null) {
- u.getInputs().add(lastOp);
- }
- lastOp = new MutableObject<ILogicalOperator>(u);
- }
+ for (QuantifiedPair qt : qe.getQuantifiedList()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(qt.getExpr(), topOp);
+ topOp = eo1.second;
+ LogicalVariable uVar = context.newVar(qt.getVarExpr());
+ ILogicalOperator u = new UnnestOperator(uVar, new MutableObject<ILogicalExpression>(
+ makeUnnestExpression(eo1.first)));
- // We make all the unnest correspond. to quantif. vars. sit on top
- // in the hope of enabling joins & other optimiz.
- firstOp.getInputs().add(topOp);
- topOp = lastOp;
+ if (firstOp == null) {
+ firstOp = u;
+ }
+ if (lastOp != null) {
+ u.getInputs().add(lastOp);
+ }
+ lastOp = new MutableObject<ILogicalOperator>(u);
+ }
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(
- qe.getSatisfiesExpr(), topOp);
+ // We make all the unnest correspond. to quantif. vars. sit on top
+ // in the hope of enabling joins & other optimiz.
+ firstOp.getInputs().add(topOp);
+ topOp = lastOp;
- AggregateFunctionCallExpression fAgg;
- SelectOperator s;
- if (qe.getQuantifier() == Quantifier.SOME) {
- s = new SelectOperator(new MutableObject<ILogicalExpression>(
- eo2.first));
- s.getInputs().add(eo2.second);
- fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.NON_EMPTY_STREAM,
- new ArrayList<Mutable<ILogicalExpression>>());
- } else { // EVERY
- List<Mutable<ILogicalExpression>> satExprList = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- satExprList.add(new MutableObject<ILogicalExpression>(eo2.first));
- s = new SelectOperator(new MutableObject<ILogicalExpression>(
- new ScalarFunctionCallExpression(FunctionUtils
- .getFunctionInfo(AlgebricksBuiltinFunctions.NOT),
- satExprList)));
- s.getInputs().add(eo2.second);
- fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.EMPTY_STREAM,
- new ArrayList<Mutable<ILogicalExpression>>());
- }
- LogicalVariable qeVar = context.newVar();
- AggregateOperator a = new AggregateOperator(
- mkSingletonArrayList(qeVar),
- (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
- fAgg)));
- a.getInputs().add(new MutableObject<ILogicalOperator>(s));
- return new Pair<ILogicalOperator, LogicalVariable>(a, qeVar);
- }
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(qe.getSatisfiesExpr(), topOp);
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitQuery(Query q,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- return q.getBody().accept(this, tupSource);
- }
+ AggregateFunctionCallExpression fAgg;
+ SelectOperator s;
+ if (qe.getQuantifier() == Quantifier.SOME) {
+ s = new SelectOperator(new MutableObject<ILogicalExpression>(eo2.first));
+ s.getInputs().add(eo2.second);
+ fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(AsterixBuiltinFunctions.NON_EMPTY_STREAM,
+ new ArrayList<Mutable<ILogicalExpression>>());
+ } else { // EVERY
+ List<Mutable<ILogicalExpression>> satExprList = new ArrayList<Mutable<ILogicalExpression>>(1);
+ satExprList.add(new MutableObject<ILogicalExpression>(eo2.first));
+ s = new SelectOperator(new MutableObject<ILogicalExpression>(new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), satExprList)));
+ s.getInputs().add(eo2.second);
+ fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(AsterixBuiltinFunctions.EMPTY_STREAM,
+ new ArrayList<Mutable<ILogicalExpression>>());
+ }
+ LogicalVariable qeVar = context.newVar();
+ AggregateOperator a = new AggregateOperator(mkSingletonArrayList(qeVar),
+ (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(fAgg)));
+ a.getInputs().add(new MutableObject<ILogicalOperator>(s));
+ return new Pair<ILogicalOperator, LogicalVariable>(a, qeVar);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitRecordConstructor(
- RecordConstructor rc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
- LogicalVariable v1 = context.newVar();
- AssignOperator a = new AssignOperator(v1,
- new MutableObject<ILogicalExpression>(f));
- Mutable<ILogicalOperator> topOp = tupSource;
- for (FieldBinding fb : rc.getFbList()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(
- fb.getLeftExpr(), topOp);
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(eo1.first));
- topOp = eo1.second;
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(
- fb.getRightExpr(), topOp);
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(eo2.first));
- topOp = eo2.second;
- }
- a.getInputs().add(topOp);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitQuery(Query q, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ return q.getBody().accept(this, tupSource);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitListConstructor(
- ListConstructor lc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR) ? AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR
- : AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
- AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
- FunctionUtils.getFunctionInfo(fid));
- LogicalVariable v1 = context.newVar();
- AssignOperator a = new AssignOperator(v1,
- new MutableObject<ILogicalExpression>(f));
- Mutable<ILogicalOperator> topOp = tupSource;
- for (Expression expr : lc.getExprList()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- expr, topOp);
- f.getArguments().add(
- new MutableObject<ILogicalExpression>(eo.first));
- topOp = eo.second;
- }
- a.getInputs().add(topOp);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitRecordConstructor(RecordConstructor rc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
+ LogicalVariable v1 = context.newVar();
+ AssignOperator a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(f));
+ Mutable<ILogicalOperator> topOp = tupSource;
+ for (FieldBinding fb : rc.getFbList()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(fb.getLeftExpr(), topOp);
+ f.getArguments().add(new MutableObject<ILogicalExpression>(eo1.first));
+ topOp = eo1.second;
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(fb.getRightExpr(), topOp);
+ f.getArguments().add(new MutableObject<ILogicalExpression>(eo2.first));
+ topOp = eo2.second;
+ }
+ a.getInputs().add(topOp);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+ }
+
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitListConstructor(ListConstructor lc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR) ? AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR
+ : AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
+ AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fid));
+ LogicalVariable v1 = context.newVar();
+ AssignOperator a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(f));
+ Mutable<ILogicalOperator> topOp = tupSource;
+ for (Expression expr : lc.getExprList()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, topOp);
+ f.getArguments().add(new MutableObject<ILogicalExpression>(eo.first));
+ topOp = eo.second;
+ }
+ a.getInputs().add(topOp);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUnaryExpr(UnaryExpr u,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- Expression expr = u.getExpr();
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
- expr, tupSource);
- LogicalVariable v1 = context.newVar();
- AssignOperator a;
- if (u.getSign() == Sign.POSITIVE) {
- a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(
- eo.first));
- } else {
- AbstractFunctionCallExpression m = new ScalarFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS));
- m.getArguments().add(
- new MutableObject<ILogicalExpression>(eo.first));
- a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(m));
- }
- a.getInputs().add(eo.second);
- return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUnaryExpr(UnaryExpr u, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ Expression expr = u.getExpr();
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, tupSource);
+ LogicalVariable v1 = context.newVar();
+ AssignOperator a;
+ if (u.getSign() == Sign.POSITIVE) {
+ a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(eo.first));
+ } else {
+ AbstractFunctionCallExpression m = new ScalarFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS));
+ m.getArguments().add(new MutableObject<ILogicalExpression>(eo.first));
+ a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(m));
+ }
+ a.getInputs().add(eo.second);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitVariableExpr(
- VariableExpr v, Mutable<ILogicalOperator> tupSource) {
- // Should we ever get to this method?
- LogicalVariable var = context.newVar();
- LogicalVariable oldV = context.getVar(v.getVar().getId());
- AssignOperator a = new AssignOperator(var,
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(oldV)));
- a.getInputs().add(tupSource);
- return new Pair<ILogicalOperator, LogicalVariable>(a, var);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitVariableExpr(VariableExpr v, Mutable<ILogicalOperator> tupSource) {
+ // Should we ever get to this method?
+ LogicalVariable var = context.newVar();
+ LogicalVariable oldV = context.getVar(v.getVar().getId());
+ AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(
+ new VariableReferenceExpression(oldV)));
+ a.getInputs().add(tupSource);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitWhereClause(
- WhereClause w, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- w.getWhereExpr(), tupSource);
- SelectOperator s = new SelectOperator(
- new MutableObject<ILogicalExpression>(p.first));
- s.getInputs().add(p.second);
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitWhereClause(WhereClause w, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(w.getWhereExpr(), tupSource);
+ SelectOperator s = new SelectOperator(new MutableObject<ILogicalExpression>(p.first));
+ s.getInputs().add(p.second);
- return new Pair<ILogicalOperator, LogicalVariable>(s, null);
- }
+ return new Pair<ILogicalOperator, LogicalVariable>(s, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLimitClause(
- LimitClause lc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(
- lc.getLimitExpr(), tupSource);
- LimitOperator opLim;
- Expression offset = lc.getOffset();
- if (offset != null) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p2 = aqlExprToAlgExpression(
- offset, p1.second);
- opLim = new LimitOperator(p1.first, p2.first);
- opLim.getInputs().add(p2.second);
- } else {
- opLim = new LimitOperator(p1.first);
- opLim.getInputs().add(p1.second);
- }
- return new Pair<ILogicalOperator, LogicalVariable>(opLim, null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLimitClause(LimitClause lc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getLimitExpr(), tupSource);
+ LimitOperator opLim;
+ Expression offset = lc.getOffset();
+ if (offset != null) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p2 = aqlExprToAlgExpression(offset, p1.second);
+ opLim = new LimitOperator(p1.first, p2.first);
+ opLim.getInputs().add(p2.second);
+ } else {
+ opLim = new LimitOperator(p1.first);
+ opLim.getInputs().add(p1.second);
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(opLim, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDieClause(DieClause lc,
- Mutable<ILogicalOperator> tupSource) throws AsterixException {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(
- lc.getDieExpr(), tupSource);
- DieOperator opDie = new DieOperator(p1.first);
- opDie.getInputs().add(p1.second);
- return new Pair<ILogicalOperator, LogicalVariable>(opDie, null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDieClause(DieClause lc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getDieExpr(), tupSource);
+ DieOperator opDie = new DieOperator(p1.first);
+ opDie.getInputs().add(p1.second);
+ return new Pair<ILogicalOperator, LogicalVariable>(opDie, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDistinctClause(
- DistinctClause dc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
- Mutable<ILogicalOperator> input = null;
- for (Expression expr : dc.getDistinctByExpr()) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- expr, tupSource);
- exprList.add(new MutableObject<ILogicalExpression>(p.first));
- input = p.second;
- }
- DistinctOperator opDistinct = new DistinctOperator(exprList);
- opDistinct.getInputs().add(input);
- return new Pair<ILogicalOperator, LogicalVariable>(opDistinct, null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDistinctClause(DistinctClause dc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
+ Mutable<ILogicalOperator> input = null;
+ for (Expression expr : dc.getDistinctByExpr()) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(expr, tupSource);
+ exprList.add(new MutableObject<ILogicalExpression>(p.first));
+ input = p.second;
+ }
+ DistinctOperator opDistinct = new DistinctOperator(exprList);
+ opDistinct.getInputs().add(input);
+ return new Pair<ILogicalOperator, LogicalVariable>(opDistinct, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUnionExpr(
- UnionExpr unionExpr, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- Mutable<ILogicalOperator> ts = tupSource;
- ILogicalOperator lastOp = null;
- LogicalVariable lastVar = null;
- boolean first = true;
- for (Expression e : unionExpr.getExprs()) {
- if (first) {
- first = false;
- } else {
- ts = new MutableObject<ILogicalOperator>(
- new EmptyTupleSourceOperator());
- }
- Pair<ILogicalOperator, LogicalVariable> p1 = e.accept(this, ts);
- if (lastOp == null) {
- lastOp = p1.first;
- lastVar = p1.second;
- } else {
- LogicalVariable unnestVar1 = context.newVar();
- UnnestOperator unnest1 = new UnnestOperator(
- unnestVar1,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(new VariableReferenceExpression(
- lastVar))));
- unnest1.getInputs().add(
- new MutableObject<ILogicalOperator>(lastOp));
- LogicalVariable unnestVar2 = context.newVar();
- UnnestOperator unnest2 = new UnnestOperator(
- unnestVar2,
- new MutableObject<ILogicalExpression>(
- makeUnnestExpression(new VariableReferenceExpression(
- p1.second))));
- unnest2.getInputs().add(
- new MutableObject<ILogicalOperator>(p1.first));
- List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(
- 1);
- LogicalVariable resultVar = context.newVar();
- Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
- unnestVar1, unnestVar2, resultVar);
- varMap.add(triple);
- UnionAllOperator unionOp = new UnionAllOperator(varMap);
- unionOp.getInputs().add(
- new MutableObject<ILogicalOperator>(unnest1));
- unionOp.getInputs().add(
- new MutableObject<ILogicalOperator>(unnest2));
- lastVar = resultVar;
- lastOp = unionOp;
- }
- }
- LogicalVariable aggVar = context.newVar();
- ArrayList<LogicalVariable> aggregVars = new ArrayList<LogicalVariable>(
- 1);
- aggregVars.add(aggVar);
- List<Mutable<ILogicalExpression>> afcExprs = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- afcExprs.add(new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(lastVar)));
- AggregateFunctionCallExpression afc = AsterixBuiltinFunctions
- .makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.LISTIFY, afcExprs);
- ArrayList<Mutable<ILogicalExpression>> aggregExprs = new ArrayList<Mutable<ILogicalExpression>>(
- 1);
- aggregExprs.add(new MutableObject<ILogicalExpression>(afc));
- AggregateOperator agg = new AggregateOperator(aggregVars, aggregExprs);
- agg.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
- return new Pair<ILogicalOperator, LogicalVariable>(agg, aggVar);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUnionExpr(UnionExpr unionExpr,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ Mutable<ILogicalOperator> ts = tupSource;
+ ILogicalOperator lastOp = null;
+ LogicalVariable lastVar = null;
+ boolean first = true;
+ for (Expression e : unionExpr.getExprs()) {
+ if (first) {
+ first = false;
+ } else {
+ ts = new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator());
+ }
+ Pair<ILogicalOperator, LogicalVariable> p1 = e.accept(this, ts);
+ if (lastOp == null) {
+ lastOp = p1.first;
+ lastVar = p1.second;
+ } else {
+ LogicalVariable unnestVar1 = context.newVar();
+ UnnestOperator unnest1 = new UnnestOperator(unnestVar1, new MutableObject<ILogicalExpression>(
+ makeUnnestExpression(new VariableReferenceExpression(lastVar))));
+ unnest1.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
+ LogicalVariable unnestVar2 = context.newVar();
+ UnnestOperator unnest2 = new UnnestOperator(unnestVar2, new MutableObject<ILogicalExpression>(
+ makeUnnestExpression(new VariableReferenceExpression(p1.second))));
+ unnest2.getInputs().add(new MutableObject<ILogicalOperator>(p1.first));
+ List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(
+ 1);
+ LogicalVariable resultVar = context.newVar();
+ Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
+ unnestVar1, unnestVar2, resultVar);
+ varMap.add(triple);
+ UnionAllOperator unionOp = new UnionAllOperator(varMap);
+ unionOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest1));
+ unionOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest2));
+ lastVar = resultVar;
+ lastOp = unionOp;
+ }
+ }
+ LogicalVariable aggVar = context.newVar();
+ ArrayList<LogicalVariable> aggregVars = new ArrayList<LogicalVariable>(1);
+ aggregVars.add(aggVar);
+ List<Mutable<ILogicalExpression>> afcExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
+ afcExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(lastVar)));
+ AggregateFunctionCallExpression afc = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+ AsterixBuiltinFunctions.LISTIFY, afcExprs);
+ ArrayList<Mutable<ILogicalExpression>> aggregExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
+ aggregExprs.add(new MutableObject<ILogicalExpression>(afc));
+ AggregateOperator agg = new AggregateOperator(aggregVars, aggregExprs);
+ agg.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
+ return new Pair<ILogicalOperator, LogicalVariable>(agg, aggVar);
+ }
- private AbstractFunctionCallExpression createComparisonExpression(
- OperatorType t) {
- FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
- IFunctionInfo finfo = FunctionUtils.getFunctionInfo(fi);
- return new ScalarFunctionCallExpression(finfo);
- }
+ private AbstractFunctionCallExpression createComparisonExpression(OperatorType t) {
+ FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
+ IFunctionInfo finfo = FunctionUtils.getFunctionInfo(fi);
+ return new ScalarFunctionCallExpression(finfo);
+ }
- private FunctionIdentifier operatorTypeToFunctionIdentifier(OperatorType t) {
- switch (t) {
- case EQ: {
- return AlgebricksBuiltinFunctions.EQ;
- }
- case NEQ: {
- return AlgebricksBuiltinFunctions.NEQ;
- }
- case GT: {
- return AlgebricksBuiltinFunctions.GT;
- }
- case GE: {
- return AlgebricksBuiltinFunctions.GE;
- }
- case LT: {
- return AlgebricksBuiltinFunctions.LT;
- }
- case LE: {
- return AlgebricksBuiltinFunctions.LE;
- }
- default: {
- throw new IllegalStateException();
- }
- }
- }
+ private FunctionIdentifier operatorTypeToFunctionIdentifier(OperatorType t) {
+ switch (t) {
+ case EQ: {
+ return AlgebricksBuiltinFunctions.EQ;
+ }
+ case NEQ: {
+ return AlgebricksBuiltinFunctions.NEQ;
+ }
+ case GT: {
+ return AlgebricksBuiltinFunctions.GT;
+ }
+ case GE: {
+ return AlgebricksBuiltinFunctions.GE;
+ }
+ case LT: {
+ return AlgebricksBuiltinFunctions.LT;
+ }
+ case LE: {
+ return AlgebricksBuiltinFunctions.LE;
+ }
+ default: {
+ throw new IllegalStateException();
+ }
+ }
+ }
- private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(
- OperatorType t) throws AsterixException {
+ private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(OperatorType t)
+ throws AsterixException {
- FunctionIdentifier fid = null;
- switch (t) {
- case PLUS: {
- fid = AlgebricksBuiltinFunctions.NUMERIC_ADD;
- break;
- }
- case MINUS: {
- fid = AsterixBuiltinFunctions.NUMERIC_SUBTRACT;
- break;
- }
- case MUL: {
- fid = AsterixBuiltinFunctions.NUMERIC_MULTIPLY;
- break;
- }
- case DIV: {
- fid = AsterixBuiltinFunctions.NUMERIC_DIVIDE;
- break;
- }
- case MOD: {
- fid = AsterixBuiltinFunctions.NUMERIC_MOD;
- break;
- }
- case IDIV: {
- fid = AsterixBuiltinFunctions.NUMERIC_IDIV;
- break;
- }
- case CARET: {
- fid = AsterixBuiltinFunctions.CARET;
- break;
- }
- case AND: {
- fid = AlgebricksBuiltinFunctions.AND;
- break;
- }
- case OR: {
- fid = AlgebricksBuiltinFunctions.OR;
- break;
- }
- case FUZZY_EQ: {
- fid = AsterixBuiltinFunctions.FUZZY_EQ;
- break;
- }
+ FunctionIdentifier fid = null;
+ switch (t) {
+ case PLUS: {
+ fid = AlgebricksBuiltinFunctions.NUMERIC_ADD;
+ break;
+ }
+ case MINUS: {
+ fid = AsterixBuiltinFunctions.NUMERIC_SUBTRACT;
+ break;
+ }
+ case MUL: {
+ fid = AsterixBuiltinFunctions.NUMERIC_MULTIPLY;
+ break;
+ }
+ case DIV: {
+ fid = AsterixBuiltinFunctions.NUMERIC_DIVIDE;
+ break;
+ }
+ case MOD: {
+ fid = AsterixBuiltinFunctions.NUMERIC_MOD;
+ break;
+ }
+ case IDIV: {
+ fid = AsterixBuiltinFunctions.NUMERIC_IDIV;
+ break;
+ }
+ case CARET: {
+ fid = AsterixBuiltinFunctions.CARET;
+ break;
+ }
+ case AND: {
+ fid = AlgebricksBuiltinFunctions.AND;
+ break;
+ }
+ case OR: {
+ fid = AlgebricksBuiltinFunctions.OR;
+ break;
+ }
+ case FUZZY_EQ: {
+ fid = AsterixBuiltinFunctions.FUZZY_EQ;
+ break;
+ }
- default: {
- throw new NotImplementedException("Operator " + t
- + " is not yet implemented");
- }
- }
- return new ScalarFunctionCallExpression(
- FunctionUtils.getFunctionInfo(fid));
- }
+ default: {
+ throw new NotImplementedException("Operator " + t + " is not yet implemented");
+ }
+ }
+ return new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fid));
+ }
- private static boolean hasOnlyChild(ILogicalOperator parent,
- Mutable<ILogicalOperator> childCandidate) {
- List<Mutable<ILogicalOperator>> inp = parent.getInputs();
- if (inp == null || inp.size() != 1) {
- return false;
- }
- return inp.get(0) == childCandidate;
- }
+ private static boolean hasOnlyChild(ILogicalOperator parent, Mutable<ILogicalOperator> childCandidate) {
+ List<Mutable<ILogicalOperator>> inp = parent.getInputs();
+ if (inp == null || inp.size() != 1) {
+ return false;
+ }
+ return inp.get(0) == childCandidate;
+ }
- private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(
- Expression expr, Mutable<ILogicalOperator> topOp)
- throws AsterixException {
- switch (expr.getKind()) {
- case VARIABLE_EXPRESSION: {
- VariableReferenceExpression ve = new VariableReferenceExpression(
- context.getVar(((VariableExpr) expr).getVar().getId()));
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve,
- topOp);
- }
- case METAVARIABLE_EXPRESSION: {
- ILogicalExpression le = metaScopeExp
- .getVariableReferenceExpression(((VariableExpr) expr)
- .getVar());
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(le,
- topOp);
- }
- case LITERAL_EXPRESSION: {
- LiteralExpr val = (LiteralExpr) expr;
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
- new ConstantExpression(new AsterixConstantValue(
- ConstantHelper.objectFromLiteral(val.getValue()))),
- topOp);
- }
- default: {
- // Mutable<ILogicalExpression> src = new
- // Mutable<ILogicalExpression>();
- // Mutable<ILogicalExpression> src = topOp;
- if (expressionNeedsNoNesting(expr)) {
- Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
- topOp);
- ILogicalExpression exp = ((AssignOperator) p.first)
- .getExpressions().get(0).getValue();
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
- exp, p.first.getInputs().get(0));
- } else {
- Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>();
+ private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(Expression expr,
+ Mutable<ILogicalOperator> topOp) throws AsterixException {
+ switch (expr.getKind()) {
+ case VARIABLE_EXPRESSION: {
+ VariableReferenceExpression ve = new VariableReferenceExpression(context.getVar(((VariableExpr) expr)
+ .getVar().getId()));
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve, topOp);
+ }
+ case METAVARIABLE_EXPRESSION: {
+ ILogicalExpression le = metaScopeExp.getVariableReferenceExpression(((VariableExpr) expr).getVar());
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(le, topOp);
+ }
+ case LITERAL_EXPRESSION: {
+ LiteralExpr val = (LiteralExpr) expr;
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new ConstantExpression(
+ new AsterixConstantValue(ConstantHelper.objectFromLiteral(val.getValue()))), topOp);
+ }
+ default: {
+ // Mutable<ILogicalExpression> src = new
+ // Mutable<ILogicalExpression>();
+ // Mutable<ILogicalExpression> src = topOp;
+ if (expressionNeedsNoNesting(expr)) {
+ Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, topOp);
+ ILogicalExpression exp = ((AssignOperator) p.first).getExpressions().get(0).getValue();
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(exp, p.first.getInputs().get(0));
+ } else {
+ Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>();
- Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
- src);
+ Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, src);
- if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
- // src.setOperator(topOp.getOperator());
- Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(
- p.first);
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
- new VariableReferenceExpression(p.second), top2);
- } else {
- SubplanOperator s = new SubplanOperator();
- s.getInputs().add(topOp);
- src.setValue(new NestedTupleSourceOperator(
- new MutableObject<ILogicalOperator>(s)));
- Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(
- p.first);
- s.setRootOp(planRoot);
- return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
- new VariableReferenceExpression(p.second),
- new MutableObject<ILogicalOperator>(s));
- }
- }
- }
- }
+ if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
+ // src.setOperator(topOp.getOperator());
+ Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(p.first);
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new VariableReferenceExpression(
+ p.second), top2);
+ } else {
+ SubplanOperator s = new SubplanOperator();
+ s.getInputs().add(topOp);
+ src.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
+ Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(p.first);
+ s.setRootOp(planRoot);
+ return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new VariableReferenceExpression(
+ p.second), new MutableObject<ILogicalOperator>(s));
+ }
+ }
+ }
+ }
- }
+ }
- private Pair<ILogicalOperator, LogicalVariable> produceFlwrResult(
- boolean noForClause, boolean isTop,
- Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
- if (isTop) {
- ProjectOperator pr = new ProjectOperator(resVar);
- pr.getInputs().add(resOpRef);
- return new Pair<ILogicalOperator, LogicalVariable>(pr, resVar);
+ private Pair<ILogicalOperator, LogicalVariable> produceFlwrResult(boolean noForClause, boolean isTop,
+ Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
+ if (isTop) {
+ ProjectOperator pr = new ProjectOperator(resVar);
+ pr.getInputs().add(resOpRef);
+ return new Pair<ILogicalOperator, LogicalVariable>(pr, resVar);
- } else if (noForClause) {
- return new Pair<ILogicalOperator, LogicalVariable>(
- resOpRef.getValue(), resVar);
- } else {
- return aggListify(resVar, resOpRef, false);
- }
- }
+ } else if (noForClause) {
+ return new Pair<ILogicalOperator, LogicalVariable>(resOpRef.getValue(), resVar);
+ } else {
+ return aggListify(resVar, resOpRef, false);
+ }
+ }
- private Pair<ILogicalOperator, LogicalVariable> aggListify(
- LogicalVariable var, Mutable<ILogicalOperator> opRef,
- boolean bProject) {
- AggregateFunctionCallExpression funAgg = AsterixBuiltinFunctions
- .makeAggregateFunctionExpression(
- AsterixBuiltinFunctions.LISTIFY,
- new ArrayList<Mutable<ILogicalExpression>>());
- funAgg.getArguments().add(
- new MutableObject<ILogicalExpression>(
- new VariableReferenceExpression(var)));
- LogicalVariable varListified = context.newVar();
- AggregateOperator agg = new AggregateOperator(
- mkSingletonArrayList(varListified),
- (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
- funAgg)));
- agg.getInputs().add(opRef);
- ILogicalOperator res;
- if (bProject) {
- ProjectOperator pr = new ProjectOperator(varListified);
- pr.getInputs().add(new MutableObject<ILogicalOperator>(agg));
- res = pr;
- } else {
- res = agg;
- }
- return new Pair<ILogicalOperator, LogicalVariable>(res, varListified);
- }
+ private Pair<ILogicalOperator, LogicalVariable> aggListify(LogicalVariable var, Mutable<ILogicalOperator> opRef,
+ boolean bProject) {
+ AggregateFunctionCallExpression funAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+ AsterixBuiltinFunctions.LISTIFY, new ArrayList<Mutable<ILogicalExpression>>());
+ funAgg.getArguments().add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
+ LogicalVariable varListified = context.newVar();
+ AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(varListified),
+ (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(funAgg)));
+ agg.getInputs().add(opRef);
+ ILogicalOperator res;
+ if (bProject) {
+ ProjectOperator pr = new ProjectOperator(varListified);
+ pr.getInputs().add(new MutableObject<ILogicalOperator>(agg));
+ res = pr;
+ } else {
+ res = agg;
+ }
+ return new Pair<ILogicalOperator, LogicalVariable>(res, varListified);
+ }
- private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(
- OperatorExpr op, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- ArrayList<OperatorType> ops = op.getOpList();
- int nOps = ops.size();
+ private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(OperatorExpr op,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ ArrayList<OperatorType> ops = op.getOpList();
+ int nOps = ops.size();
- ArrayList<Expression> exprs = op.getExprList();
+ ArrayList<Expression> exprs = op.getExprList();
- Mutable<ILogicalOperator> topOp = tupSource;
+ Mutable<ILogicalOperator> topOp = tupSource;
- OperatorType opLogical = ops.get(0);
- AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
+ OperatorType opLogical = ops.get(0);
+ AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
- for (int i = 0; i <= nOps; i++) {
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
- exprs.get(i), topOp);
- topOp = p.second;
- // now look at the operator
- if (i < nOps) {
- if (ops.get(i) != opLogical) {
- throw new TranslationException("Unexpected operator "
- + ops.get(i) + " in an OperatorExpr starting with "
- + opLogical);
- }
- }
- f.getArguments()
- .add(new MutableObject<ILogicalExpression>(p.first));
- }
+ for (int i = 0; i <= nOps; i++) {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(exprs.get(i), topOp);
+ topOp = p.second;
+ // now look at the operator
+ if (i < nOps) {
+ if (ops.get(i) != opLogical) {
+ throw new TranslationException("Unexpected operator " + ops.get(i)
+ + " in an OperatorExpr starting with " + opLogical);
+ }
+ }
+ f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
+ }
- LogicalVariable assignedVar = context.newVar();
- AssignOperator a = new AssignOperator(assignedVar,
- new MutableObject<ILogicalExpression>(f));
- a.getInputs().add(topOp);
+ LogicalVariable assignedVar = context.newVar();
+ AssignOperator a = new AssignOperator(assignedVar, new MutableObject<ILogicalExpression>(f));
+ a.getInputs().add(topOp);
- return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
- }
+ }
- private static boolean expressionNeedsNoNesting(Expression expr) {
- Kind k = expr.getKind();
- return k == Kind.LITERAL_EXPRESSION
- || k == Kind.LIST_CONSTRUCTOR_EXPRESSION
- || k == Kind.RECORD_CONSTRUCTOR_EXPRESSION
- || k == Kind.VARIABLE_EXPRESSION || k == Kind.CALL_EXPRESSION
- || k == Kind.OP_EXPRESSION
- || k == Kind.FIELD_ACCESSOR_EXPRESSION
- || k == Kind.INDEX_ACCESSOR_EXPRESSION
- || k == Kind.UNARY_EXPRESSION;
- }
+ private static boolean expressionNeedsNoNesting(Expression expr) {
+ Kind k = expr.getKind();
+ return k == Kind.LITERAL_EXPRESSION || k == Kind.LIST_CONSTRUCTOR_EXPRESSION
+ || k == Kind.RECORD_CONSTRUCTOR_EXPRESSION || k == Kind.VARIABLE_EXPRESSION
+ || k == Kind.CALL_EXPRESSION || k == Kind.OP_EXPRESSION || k == Kind.FIELD_ACCESSOR_EXPRESSION
+ || k == Kind.INDEX_ACCESSOR_EXPRESSION || k == Kind.UNARY_EXPRESSION;
+ }
- private <T> ArrayList<T> mkSingletonArrayList(T item) {
- ArrayList<T> array = new ArrayList<T>(1);
- array.add(item);
- return array;
- }
+ private <T> ArrayList<T> mkSingletonArrayList(T item) {
+ ArrayList<T> array = new ArrayList<T>(1);
+ array.add(item);
+ return array;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitTypeDecl(TypeDecl td,
- Mutable<ILogicalOperator> arg) throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitTypeDecl(TypeDecl td, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitRecordTypeDefiniton(
- RecordTypeDefinition tre, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitRecordTypeDefiniton(RecordTypeDefinition tre,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitTypeReferenceExpression(
- TypeReferenceExpression tre, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitTypeReferenceExpression(TypeReferenceExpression tre,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitNodegroupDecl(
- NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitNodegroupDecl(NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLoadFromFileStatement(
- LoadFromFileStatement stmtLoad, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLoadFromFileStatement(LoadFromFileStatement stmtLoad,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitWriteFromQueryResultStatement(
- WriteFromQueryResultStatement stmtLoad,
- Mutable<ILogicalOperator> arg) throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitWriteFromQueryResultStatement(
+ WriteFromQueryResultStatement stmtLoad, Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDropStatement(
- DropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDropStatement(DropStatement del, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitCreateIndexStatement(
- CreateIndexStatement cis, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitCreateIndexStatement(CreateIndexStatement cis,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitOrderedListTypeDefiniton(
- OrderedListTypeDefinition olte, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitOrderedListTypeDefiniton(OrderedListTypeDefinition olte,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUnorderedListTypeDefiniton(
- UnorderedListTypeDefinition ulte, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUnorderedListTypeDefiniton(UnorderedListTypeDefinition ulte,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableClause(
- MetaVariableClause mc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- return new Pair<ILogicalOperator, LogicalVariable>(metaScopeOp.get(mc
- .getVar()), null);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableClause(MetaVariableClause mc,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ return new Pair<ILogicalOperator, LogicalVariable>(metaScopeOp.get(mc.getVar()), null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitJoinClause(
- JoinClause jc, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- // Pair<ILogicalOperator, LogicalVariable> leftSide =
- // jc.getLeftExpr().accept(this, tupSource);
- Mutable<ILogicalOperator> opRef = tupSource;
- Pair<ILogicalOperator, LogicalVariable> leftSide = null;
- for (Clause c : jc.getLeftClauses()) {
- leftSide = c.accept(this, opRef);
- opRef = new MutableObject<ILogicalOperator>(leftSide.first);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitJoinClause(JoinClause jc, Mutable<ILogicalOperator> tupSource)
+ throws AsterixException {
+ // Pair<ILogicalOperator, LogicalVariable> leftSide =
+ // jc.getLeftExpr().accept(this, tupSource);
+ Mutable<ILogicalOperator> opRef = tupSource;
+ Pair<ILogicalOperator, LogicalVariable> leftSide = null;
+ for (Clause c : jc.getLeftClauses()) {
+ leftSide = c.accept(this, opRef);
+ opRef = new MutableObject<ILogicalOperator>(leftSide.first);
+ }
- // Pair<ILogicalOperator, LogicalVariable> rightSide =
- // jc.getRightExpr().accept(this, tupSource);
- opRef = tupSource;
- Pair<ILogicalOperator, LogicalVariable> rightSide = null;
- for (Clause c : jc.getRightClauses()) {
- rightSide = c.accept(this, opRef);
- opRef = new MutableObject<ILogicalOperator>(rightSide.first);
- }
+ // Pair<ILogicalOperator, LogicalVariable> rightSide =
+ // jc.getRightExpr().accept(this, tupSource);
+ opRef = tupSource;
+ Pair<ILogicalOperator, LogicalVariable> rightSide = null;
+ for (Clause c : jc.getRightClauses()) {
+ rightSide = c.accept(this, opRef);
+ opRef = new MutableObject<ILogicalOperator>(rightSide.first);
+ }
- Pair<ILogicalExpression, Mutable<ILogicalOperator>> whereCond = aqlExprToAlgExpression(
- jc.getWhereExpr(), tupSource);
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> whereCond = aqlExprToAlgExpression(jc.getWhereExpr(),
+ tupSource);
- AbstractBinaryJoinOperator join;
- switch (jc.getKind()) {
- case INNER: {
- join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(
- whereCond.first));
- break;
- }
- case LEFT_OUTER: {
- join = new LeftOuterJoinOperator(
- new MutableObject<ILogicalExpression>(whereCond.first));
- break;
- }
- default: {
- throw new IllegalStateException();
- }
- }
- join.getInputs().add(
- new MutableObject<ILogicalOperator>(leftSide.first));
- join.getInputs().add(
- new MutableObject<ILogicalOperator>(rightSide.first));
- return new Pair<ILogicalOperator, LogicalVariable>(join, null);
- }
+ AbstractBinaryJoinOperator join;
+ switch (jc.getKind()) {
+ case INNER: {
+ join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
+ break;
+ }
+ case LEFT_OUTER: {
+ join = new LeftOuterJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
+ break;
+ }
+ default: {
+ throw new IllegalStateException();
+ }
+ }
+ join.getInputs().add(new MutableObject<ILogicalOperator>(leftSide.first));
+ join.getInputs().add(new MutableObject<ILogicalOperator>(rightSide.first));
+ return new Pair<ILogicalOperator, LogicalVariable>(join, null);
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableExpr(
- MetaVariableExpr me, Mutable<ILogicalOperator> tupSource)
- throws AsterixException {
- LogicalVariable var = context.newVar();
- AssignOperator a = new AssignOperator(var,
- new MutableObject<ILogicalExpression>(metaScopeExp
- .getVariableReferenceExpression(me.getVar())));
- a.getInputs().add(tupSource);
- return new Pair<ILogicalOperator, LogicalVariable>(a, var);
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableExpr(MetaVariableExpr me,
+ Mutable<ILogicalOperator> tupSource) throws AsterixException {
+ LogicalVariable var = context.newVar();
+ AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(
+ metaScopeExp.getVariableReferenceExpression(me.getVar())));
+ a.getInputs().add(tupSource);
+ return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+ }
- public void addOperatorToMetaScope(Identifier id, ILogicalOperator op) {
- metaScopeOp.put(id, op);
- }
+ public void addOperatorToMetaScope(Identifier id, ILogicalOperator op) {
+ metaScopeOp.put(id, op);
+ }
- public void addVariableToMetaScope(Identifier id, LogicalVariable var) {
- metaScopeExp.put(id, var);
- }
+ public void addVariableToMetaScope(Identifier id, LogicalVariable var) {
+ metaScopeExp.put(id, var);
+ }
- private ILogicalExpression makeUnnestExpression(ILogicalExpression expr) {
- switch (expr.getExpressionTag()) {
- case VARIABLE: {
- return new UnnestingFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
- new MutableObject<ILogicalExpression>(expr));
- }
- case FUNCTION_CALL: {
- AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
- if (fce.getKind() == FunctionKind.UNNEST) {
- return expr;
- } else {
- return new UnnestingFunctionCallExpression(
- FunctionUtils
- .getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
- new MutableObject<ILogicalExpression>(expr));
- }
- }
- default: {
- return expr;
- }
- }
- }
+ private ILogicalExpression makeUnnestExpression(ILogicalExpression expr) {
+ switch (expr.getExpressionTag()) {
+ case VARIABLE: {
+ return new UnnestingFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
+ new MutableObject<ILogicalExpression>(expr));
+ }
+ case FUNCTION_CALL: {
+ AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
+ if (fce.getKind() == FunctionKind.UNNEST) {
+ return expr;
+ } else {
+ return new UnnestingFunctionCallExpression(
+ FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
+ new MutableObject<ILogicalExpression>(expr));
+ }
+ }
+ default: {
+ return expr;
+ }
+ }
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitInsertStatement(
- InsertStatement insert, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitInsertStatement(InsertStatement insert,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDeleteStatement(
- DeleteStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDeleteStatement(DeleteStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUpdateStatement(
- UpdateStatement update, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUpdateStatement(UpdateStatement update,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitUpdateClause(
- UpdateClause del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitUpdateClause(UpdateClause del, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDataverseDecl(
- DataverseDecl dv, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDataverseDecl(DataverseDecl dv, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDatasetDecl(
- DatasetDecl dd, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDatasetDecl(DatasetDecl dd, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitSetStatement(
- SetStatement ss, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitSetStatement(SetStatement ss, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitWriteStatement(
- WriteStatement ws, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitWriteStatement(WriteStatement ws, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitLoadFromQueryResultStatement(
- WriteFromQueryResultStatement stmtLoad,
- Mutable<ILogicalOperator> arg) throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitLoadFromQueryResultStatement(
+ WriteFromQueryResultStatement stmtLoad, Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitCreateDataverseStatement(
- CreateDataverseStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitCreateDataverseStatement(CreateDataverseStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitIndexDropStatement(
- IndexDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitIndexDropStatement(IndexDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitNodeGroupDropStatement(
- NodeGroupDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitNodeGroupDropStatement(NodeGroupDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitDataverseDropStatement(
- DataverseDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitDataverseDropStatement(DataverseDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitTypeDropStatement(
- TypeDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitTypeDropStatement(TypeDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitControlFeedStatement(
- ControlFeedStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitControlFeedStatement(ControlFeedStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visit(
- CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visit(CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
+ throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitFunctionDropStatement(
- FunctionDropStatement del, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitFunctionDropStatement(FunctionDropStatement del,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
- @Override
- public Pair<ILogicalOperator, LogicalVariable> visitBeginFeedStatement(
- BeginFeedStatement bf, Mutable<ILogicalOperator> arg)
- throws AsterixException {
- // TODO Auto-generated method stub
- return null;
- }
+ @Override
+ public Pair<ILogicalOperator, LogicalVariable> visitBeginFeedStatement(BeginFeedStatement bf,
+ Mutable<ILogicalOperator> arg) throws AsterixException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/CompiledStatements.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/CompiledStatements.java
new file mode 100644
index 0000000..6d52b8f
--- /dev/null
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/CompiledStatements.java
@@ -0,0 +1,543 @@
+/*
+ * Copyright 2009-2011 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.asterix.translator;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import edu.uci.ics.asterix.aql.base.Clause;
+import edu.uci.ics.asterix.aql.base.Expression;
+import edu.uci.ics.asterix.aql.base.Statement.Kind;
+import edu.uci.ics.asterix.aql.expression.CallExpr;
+import edu.uci.ics.asterix.aql.expression.ControlFeedStatement.OperationType;
+import edu.uci.ics.asterix.aql.expression.FLWOGRExpression;
+import edu.uci.ics.asterix.aql.expression.FieldAccessor;
+import edu.uci.ics.asterix.aql.expression.FieldBinding;
+import edu.uci.ics.asterix.aql.expression.ForClause;
+import edu.uci.ics.asterix.aql.expression.Identifier;
+import edu.uci.ics.asterix.aql.expression.LiteralExpr;
+import edu.uci.ics.asterix.aql.expression.Query;
+import edu.uci.ics.asterix.aql.expression.RecordConstructor;
+import edu.uci.ics.asterix.aql.expression.VariableExpr;
+import edu.uci.ics.asterix.aql.expression.WhereClause;
+import edu.uci.ics.asterix.aql.literal.StringLiteral;
+import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.functions.FunctionSignature;
+import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
+import edu.uci.ics.asterix.metadata.entities.Dataset;
+import edu.uci.ics.asterix.om.types.ARecordType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+
+public class CompiledStatements {
+
+ public static interface ICompiledStatement {
+
+ public Kind getKind();
+ }
+
+ public static class CompiledWriteFromQueryResultStatement implements ICompiledDmlStatement {
+
+ private String dataverseName;
+ private String datasetName;
+ private Query query;
+ private int varCounter;
+
+ public CompiledWriteFromQueryResultStatement(String dataverseName, String datasetName, Query query,
+ int varCounter) {
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ this.query = query;
+ this.varCounter = varCounter;
+ }
+
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ public int getVarCounter() {
+ return varCounter;
+ }
+
+ public Query getQuery() {
+ return query;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.WRITE_FROM_QUERY_RESULT;
+ }
+
+ }
+
+ public static class CompiledDatasetDropStatement implements ICompiledStatement {
+ private final String dataverseName;
+ private final String datasetName;
+
+ public CompiledDatasetDropStatement(String dataverseName, String datasetName) {
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ }
+
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.DATASET_DROP;
+ }
+ }
+
+ // added by yasser
+ public static class CompiledCreateDataverseStatement implements ICompiledStatement {
+ private String dataverseName;
+ private String format;
+
+ public CompiledCreateDataverseStatement(String dataverseName, String format) {
+ this.dataverseName = dataverseName;
+ this.format = format;
+ }
+
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.CREATE_DATAVERSE;
+ }
+ }
+
+ public static class CompiledNodeGroupDropStatement implements ICompiledStatement {
+ private String nodeGroupName;
+
+ public CompiledNodeGroupDropStatement(String nodeGroupName) {
+ this.nodeGroupName = nodeGroupName;
+ }
+
+ public String getNodeGroupName() {
+ return nodeGroupName;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.NODEGROUP_DROP;
+ }
+ }
+
+ public static class CompiledIndexDropStatement implements ICompiledStatement {
+ private String dataverseName;
+ private String datasetName;
+ private String indexName;
+
+ public CompiledIndexDropStatement(String dataverseName, String datasetName, String indexName) {
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ this.indexName = indexName;
+ }
+
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ public String getIndexName() {
+ return indexName;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.INDEX_DROP;
+ }
+ }
+
+ public static class CompiledDataverseDropStatement implements ICompiledStatement {
+ private String dataverseName;
+ private boolean ifExists;
+
+ public CompiledDataverseDropStatement(String dataverseName, boolean ifExists) {
+ this.dataverseName = dataverseName;
+ this.ifExists = ifExists;
+ }
+
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public boolean getIfExists() {
+ return ifExists;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.DATAVERSE_DROP;
+ }
+ }
+
+ public static class CompiledTypeDropStatement implements ICompiledStatement {
+ private String typeName;
+
+ public CompiledTypeDropStatement(String nodeGroupName) {
+ this.typeName = nodeGroupName;
+ }
+
+ public String getTypeName() {
+ return typeName;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.TYPE_DROP;
+ }
+ }
+
+ public static interface ICompiledDmlStatement extends ICompiledStatement {
+
+ public String getDataverseName();
+
+ public String getDatasetName();
+ }
+
+ public static class CompiledCreateIndexStatement implements ICompiledDmlStatement {
+ private final String indexName;
+ private final String dataverseName;
+ private final String datasetName;
+ private final List<String> keyFields;
+ private final IndexType indexType;
+
+ // Specific to NGram index.
+ private final int gramLength;
+
+ public CompiledCreateIndexStatement(String indexName, String dataverseName, String datasetName,
+ List<String> keyFields, int gramLength, IndexType indexType) {
+ this.indexName = indexName;
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ this.keyFields = keyFields;
+ this.gramLength = gramLength;
+ this.indexType = indexType;
+ }
+
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public String getIndexName() {
+ return indexName;
+ }
+
+ public List<String> getKeyFields() {
+ return keyFields;
+ }
+
+ public IndexType getIndexType() {
+ return indexType;
+ }
+
+ public int getGramLength() {
+ return gramLength;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.CREATE_INDEX;
+ }
+ }
+
+ public static class CompiledLoadFromFileStatement implements ICompiledDmlStatement {
+ private String dataverseName;
+ private String datasetName;
+ private boolean alreadySorted;
+ private String adapter;
+ private Map<String, String> properties;
+
+ public CompiledLoadFromFileStatement(String dataverseName, String datasetName, String adapter,
+ Map<String, String> properties, boolean alreadySorted) {
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ this.alreadySorted = alreadySorted;
+ this.adapter = adapter;
+ this.properties = properties;
+ }
+
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ public boolean alreadySorted() {
+ return alreadySorted;
+ }
+
+ public String getAdapter() {
+ return adapter;
+ }
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.LOAD_FROM_FILE;
+ }
+ }
+
+ public static class CompiledInsertStatement implements ICompiledDmlStatement {
+ private final String dataverseName;
+ private final String datasetName;
+ private final Query query;
+ private final int varCounter;
+
+ public CompiledInsertStatement(String dataverseName, String datasetName, Query query, int varCounter) {
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ this.query = query;
+ this.varCounter = varCounter;
+ }
+
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ public int getVarCounter() {
+ return varCounter;
+ }
+
+ public Query getQuery() {
+ return query;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.INSERT;
+ }
+ }
+
+ public static class CompiledBeginFeedStatement implements ICompiledDmlStatement {
+ private String dataverseName;
+ private String datasetName;
+ private Query query;
+ private int varCounter;
+
+ public CompiledBeginFeedStatement(String dataverseName, String datasetName, Query query, int varCounter) {
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ this.query = query;
+ this.varCounter = varCounter;
+ }
+
+ @Override
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ @Override
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ public int getVarCounter() {
+ return varCounter;
+ }
+
+ public Query getQuery() {
+ return query;
+ }
+
+ public void setQuery(Query query) {
+ this.query = query;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.BEGIN_FEED;
+ }
+ }
+
+ public static class CompiledControlFeedStatement implements ICompiledDmlStatement {
+ private String dataverseName;
+ private String datasetName;
+ private OperationType operationType;
+ private Query query;
+ private int varCounter;
+ private Map<String, String> alteredParams;
+
+ public CompiledControlFeedStatement(OperationType operationType, String dataverseName, String datasetName,
+ Map<String, String> alteredParams) {
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ this.operationType = operationType;
+ this.alteredParams = alteredParams;
+ }
+
+ @Override
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ @Override
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ public OperationType getOperationType() {
+ return operationType;
+ }
+
+ public int getVarCounter() {
+ return varCounter;
+ }
+
+ public Query getQuery() {
+ return query;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.CONTROL_FEED;
+ }
+
+ public Map<String, String> getProperties() {
+ return alteredParams;
+ }
+
+ public void setProperties(Map<String, String> properties) {
+ this.alteredParams = properties;
+ }
+ }
+
+ public static class CompiledDeleteStatement implements ICompiledDmlStatement {
+ private VariableExpr var;
+ private String dataverseName;
+ private String datasetName;
+ private Expression condition;
+ private Clause dieClause;
+ private int varCounter;
+ private AqlMetadataProvider metadataProvider;
+
+ public CompiledDeleteStatement(VariableExpr var, String dataverseName, String datasetName,
+ Expression condition, Clause dieClause, int varCounter, AqlMetadataProvider metadataProvider) {
+ this.var = var;
+ this.dataverseName = dataverseName;
+ this.datasetName = datasetName;
+ this.condition = condition;
+ this.dieClause = dieClause;
+ this.varCounter = varCounter;
+ this.metadataProvider = metadataProvider;
+ }
+
+ @Override
+ public String getDatasetName() {
+ return datasetName;
+ }
+
+ @Override
+ public String getDataverseName() {
+ return dataverseName;
+ }
+
+ public int getVarCounter() {
+ return varCounter;
+ }
+
+ public Expression getCondition() {
+ return condition;
+ }
+
+ public Clause getDieClause() {
+ return dieClause;
+ }
+
+ public Query getQuery() throws AlgebricksException {
+
+ List<Expression> arguments = new ArrayList<Expression>();
+ String arg = dataverseName == null ? datasetName : dataverseName + "." + datasetName;
+ LiteralExpr argumentLiteral = new LiteralExpr(new StringLiteral(arg));
+ arguments.add(argumentLiteral);
+
+ CallExpr callExpression = new CallExpr(new FunctionSignature(FunctionConstants.ASTERIX_NS, "dataset", 1),
+ arguments);
+ List<Clause> clauseList = new ArrayList<Clause>();
+ Clause forClause = new ForClause(var, callExpression);
+ clauseList.add(forClause);
+ Clause whereClause = null;
+ if (condition != null) {
+ whereClause = new WhereClause(condition);
+ clauseList.add(whereClause);
+ }
+ if (dieClause != null) {
+ clauseList.add(dieClause);
+ }
+
+ Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName);
+ if (dataset == null) {
+ throw new AlgebricksException("Unknown dataset " + datasetName);
+ }
+ String itemTypeName = dataset.getItemTypeName();
+ IAType itemType = metadataProvider.findType(dataset.getDataverseName(), itemTypeName);
+ ARecordType recType = (ARecordType) itemType;
+ String[] fieldNames = recType.getFieldNames();
+ List<FieldBinding> fieldBindings = new ArrayList<FieldBinding>();
+ for (int i = 0; i < fieldNames.length; i++) {
+ FieldAccessor fa = new FieldAccessor(var, new Identifier(fieldNames[i]));
+ FieldBinding fb = new FieldBinding(new LiteralExpr(new StringLiteral(fieldNames[i])), fa);
+ fieldBindings.add(fb);
+ }
+ RecordConstructor rc = new RecordConstructor(fieldBindings);
+
+ FLWOGRExpression flowgr = new FLWOGRExpression(clauseList, rc);
+ Query query = new Query();
+ query.setBody(flowgr);
+ return query;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.DELETE;
+ }
+
+ }
+
+}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/DmlTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/DmlTranslator.java
deleted file mode 100644
index c8b1079..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/DmlTranslator.java
+++ /dev/null
@@ -1,492 +0,0 @@
-package edu.uci.ics.asterix.translator;
-
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import edu.uci.ics.asterix.aql.base.Clause;
-import edu.uci.ics.asterix.aql.base.Expression;
-import edu.uci.ics.asterix.aql.base.Statement;
-import edu.uci.ics.asterix.aql.base.Statement.Kind;
-import edu.uci.ics.asterix.aql.expression.BeginFeedStatement;
-import edu.uci.ics.asterix.aql.expression.CallExpr;
-import edu.uci.ics.asterix.aql.expression.ControlFeedStatement;
-import edu.uci.ics.asterix.aql.expression.ControlFeedStatement.OperationType;
-import edu.uci.ics.asterix.aql.expression.CreateIndexStatement;
-import edu.uci.ics.asterix.aql.expression.DeleteStatement;
-import edu.uci.ics.asterix.aql.expression.FLWOGRExpression;
-import edu.uci.ics.asterix.aql.expression.FieldAccessor;
-import edu.uci.ics.asterix.aql.expression.FieldBinding;
-import edu.uci.ics.asterix.aql.expression.ForClause;
-import edu.uci.ics.asterix.aql.expression.Identifier;
-import edu.uci.ics.asterix.aql.expression.InsertStatement;
-import edu.uci.ics.asterix.aql.expression.LiteralExpr;
-import edu.uci.ics.asterix.aql.expression.LoadFromFileStatement;
-import edu.uci.ics.asterix.aql.expression.Query;
-import edu.uci.ics.asterix.aql.expression.RecordConstructor;
-import edu.uci.ics.asterix.aql.expression.VariableExpr;
-import edu.uci.ics.asterix.aql.expression.WhereClause;
-import edu.uci.ics.asterix.aql.expression.WriteFromQueryResultStatement;
-import edu.uci.ics.asterix.aql.literal.StringLiteral;
-import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
-import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
-import edu.uci.ics.asterix.metadata.IDatasetDetails;
-import edu.uci.ics.asterix.metadata.MetadataException;
-import edu.uci.ics.asterix.metadata.MetadataManager;
-import edu.uci.ics.asterix.metadata.MetadataTransactionContext;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
-import edu.uci.ics.asterix.metadata.entities.Dataset;
-import edu.uci.ics.asterix.metadata.entities.FeedDatasetDetails;
-import edu.uci.ics.asterix.metadata.entities.Index;
-import edu.uci.ics.asterix.om.functions.AsterixFunction;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-
-public class DmlTranslator extends AbstractAqlTranslator {
-
- private final MetadataTransactionContext mdTxnCtx;
- private final List<Statement> aqlStatements;
- private AqlCompiledMetadataDeclarations compiledDeclarations;
- private List<ICompiledDmlStatement> compiledDmlStatements;
-
- public DmlTranslator(MetadataTransactionContext mdTxnCtx, List<Statement> aqlStatements) {
- this.mdTxnCtx = mdTxnCtx;
- this.aqlStatements = aqlStatements;
- }
-
- public void translate() throws AlgebricksException, RemoteException, ACIDException, MetadataException {
- compiledDeclarations = compileMetadata(mdTxnCtx, aqlStatements, true);
- compiledDmlStatements = compileDmlStatements();
- }
-
- public AqlCompiledMetadataDeclarations getCompiledDeclarations() {
- return compiledDeclarations;
- }
-
- public List<ICompiledDmlStatement> getCompiledDmlStatements() {
- return compiledDmlStatements;
- }
-
- private List<ICompiledDmlStatement> compileDmlStatements() throws AlgebricksException, MetadataException {
- List<ICompiledDmlStatement> dmlStatements = new ArrayList<ICompiledDmlStatement>();
- for (Statement stmt : aqlStatements) {
- validateOperation(compiledDeclarations, stmt);
- switch (stmt.getKind()) {
- case LOAD_FROM_FILE: {
- LoadFromFileStatement loadStmt = (LoadFromFileStatement) stmt;
- CompiledLoadFromFileStatement cls = new CompiledLoadFromFileStatement(loadStmt.getDatasetName()
- .getValue(), loadStmt.getAdapter(), loadStmt.getProperties(),
- loadStmt.dataIsAlreadySorted());
- dmlStatements.add(cls);
- // Also load the dataset's secondary indexes.
- List<Index> datasetIndexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx,
- compiledDeclarations.getDataverseName(), loadStmt.getDatasetName().getValue());
- for (Index index : datasetIndexes) {
- if (!index.isSecondaryIndex()) {
- continue;
- }
- // Create CompiledCreateIndexStatement from metadata entity 'index'.
- CompiledCreateIndexStatement cis = new CompiledCreateIndexStatement(index.getIndexName(),
- index.getDatasetName(), index.getKeyFieldNames(), index.getGramLength(),
- index.getIndexType());
- dmlStatements.add(cis);
- }
- break;
- }
- case WRITE_FROM_QUERY_RESULT: {
- WriteFromQueryResultStatement st1 = (WriteFromQueryResultStatement) stmt;
- CompiledWriteFromQueryResultStatement clfrqs = new CompiledWriteFromQueryResultStatement(st1
- .getDatasetName().getValue(), st1.getQuery(), st1.getVarCounter());
- dmlStatements.add(clfrqs);
- break;
- }
- case CREATE_INDEX: {
- CreateIndexStatement cis = (CreateIndexStatement) stmt;
- // Assumptions: We first processed the DDL, which added the secondary index to the metadata.
- // If the index's dataset is being loaded in this 'session', then let the load add
- // the CompiledCreateIndexStatement to dmlStatements, and don't add it again here.
- // It's better to have the load handle this because:
- // 1. There may be more secondary indexes to load, which were possibly created in an earlier session.
- // 2. If the create index stmt came before the load stmt, then we would first create an empty index only to load it again later.
- // This may cause problems because the index would be considered loaded (even though it was loaded empty).
- for (Statement s : aqlStatements) {
- if (s.getKind() != Kind.LOAD_FROM_FILE) {
- continue;
- }
- LoadFromFileStatement loadStmt = (LoadFromFileStatement) s;
- if (loadStmt.getDatasetName().equals(cis.getDatasetName())) {
- cis.setNeedToCreate(false);
- }
- }
- if (cis.getNeedToCreate()) {
- CompiledCreateIndexStatement ccis = new CompiledCreateIndexStatement(cis.getIndexName()
- .getValue(), cis.getDatasetName().getValue(), cis.getFieldExprs(), cis.getGramLength(),
- cis.getIndexType());
- dmlStatements.add(ccis);
- }
- break;
- }
- case INSERT: {
- InsertStatement is = (InsertStatement) stmt;
- CompiledInsertStatement clfrqs = new CompiledInsertStatement(is.getDatasetName().getValue(),
- is.getQuery(), is.getVarCounter());
- dmlStatements.add(clfrqs);
- break;
- }
- case DELETE: {
- DeleteStatement ds = (DeleteStatement) stmt;
- CompiledDeleteStatement clfrqs = new CompiledDeleteStatement(ds.getVariableExpr(),
- ds.getDatasetName(), ds.getCondition(), ds.getDieClause(), ds.getVarCounter(),
- compiledDeclarations);
- dmlStatements.add(clfrqs);
- break;
- }
-
- case BEGIN_FEED: {
- BeginFeedStatement bfs = (BeginFeedStatement) stmt;
- CompiledBeginFeedStatement cbfs = new CompiledBeginFeedStatement(bfs.getDatasetName(),
- bfs.getQuery(), bfs.getVarCounter());
- dmlStatements.add(cbfs);
- Dataset dataset;
- try {
- dataset = MetadataManager.INSTANCE.getDataset(mdTxnCtx,
- compiledDeclarations.getDataverseName(), bfs.getDatasetName().getValue());
- } catch (MetadataException me) {
- throw new AlgebricksException(me);
- }
- IDatasetDetails datasetDetails = dataset.getDatasetDetails();
- if (datasetDetails.getDatasetType() != DatasetType.FEED) {
- throw new IllegalArgumentException("Dataset " + bfs.getDatasetName().getValue()
- + " is not a feed dataset");
- }
- bfs.initialize((FeedDatasetDetails) datasetDetails);
- cbfs.setQuery(bfs.getQuery());
- break;
- }
-
- case CONTROL_FEED: {
- ControlFeedStatement cfs = (ControlFeedStatement) stmt;
- CompiledControlFeedStatement clcfs = new CompiledControlFeedStatement(cfs.getOperationType(),
- cfs.getDatasetName(), cfs.getAlterAdapterConfParams());
- dmlStatements.add(clcfs);
- break;
-
- }
- }
- }
- return dmlStatements;
- }
-
- public static interface ICompiledDmlStatement {
-
- public abstract Kind getKind();
- }
-
- public static class CompiledCreateIndexStatement implements ICompiledDmlStatement {
- private final String indexName;
- private final String datasetName;
- private final List<String> keyFields;
- private final IndexType indexType;
-
- // Specific to NGram index.
- private final int gramLength;
-
- public CompiledCreateIndexStatement(String indexName, String datasetName, List<String> keyFields,
- int gramLength, IndexType indexType) {
- this.indexName = indexName;
- this.datasetName = datasetName;
- this.keyFields = keyFields;
- this.gramLength = gramLength;
- this.indexType = indexType;
- }
-
- public String getDatasetName() {
- return datasetName;
- }
-
- public String getIndexName() {
- return indexName;
- }
-
- public List<String> getKeyFields() {
- return keyFields;
- }
-
- public IndexType getIndexType() {
- return indexType;
- }
-
- public int getGramLength() {
- return gramLength;
- }
-
- @Override
- public Kind getKind() {
- return Kind.CREATE_INDEX;
- }
- }
-
- public static class CompiledLoadFromFileStatement implements ICompiledDmlStatement {
- private String datasetName;
- private boolean alreadySorted;
- private String adapter;
- private Map<String, String> properties;
-
- public CompiledLoadFromFileStatement(String datasetName, String adapter, Map<String, String> properties,
- boolean alreadySorted) {
- this.datasetName = datasetName;
- this.alreadySorted = alreadySorted;
- this.adapter = adapter;
- this.properties = properties;
- }
-
- public String getDatasetName() {
- return datasetName;
- }
-
- public boolean alreadySorted() {
- return alreadySorted;
- }
-
- public String getAdapter() {
- return adapter;
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- @Override
- public Kind getKind() {
- return Kind.LOAD_FROM_FILE;
- }
- }
-
- public static class CompiledWriteFromQueryResultStatement implements ICompiledDmlStatement {
-
- private String datasetName;
- private Query query;
- private int varCounter;
-
- public CompiledWriteFromQueryResultStatement(String datasetName, Query query, int varCounter) {
- this.datasetName = datasetName;
- this.query = query;
- this.varCounter = varCounter;
- }
-
- public String getDatasetName() {
- return datasetName;
- }
-
- public int getVarCounter() {
- return varCounter;
- }
-
- public Query getQuery() {
- return query;
- }
-
- @Override
- public Kind getKind() {
- return Kind.WRITE_FROM_QUERY_RESULT;
- }
-
- }
-
- public static class CompiledInsertStatement implements ICompiledDmlStatement {
- private String datasetName;
- private Query query;
- private int varCounter;
-
- public CompiledInsertStatement(String datasetName, Query query, int varCounter) {
- this.datasetName = datasetName;
- this.query = query;
- this.varCounter = varCounter;
- }
-
- public String getDatasetName() {
- return datasetName;
- }
-
- public int getVarCounter() {
- return varCounter;
- }
-
- public Query getQuery() {
- return query;
- }
-
- @Override
- public Kind getKind() {
- return Kind.INSERT;
- }
- }
-
- public static class CompiledBeginFeedStatement implements ICompiledDmlStatement {
- private Identifier datasetName;
- private Query query;
- private int varCounter;
-
- public CompiledBeginFeedStatement(Identifier datasetName, Query query, int varCounter) {
- this.datasetName = datasetName;
- this.query = query;
- this.varCounter = varCounter;
- }
-
- public Identifier getDatasetName() {
- return datasetName;
- }
-
- public int getVarCounter() {
- return varCounter;
- }
-
- public Query getQuery() {
- return query;
- }
-
- public void setQuery(Query query) {
- this.query = query;
- }
-
- @Override
- public Kind getKind() {
- return Kind.BEGIN_FEED;
- }
- }
-
- public static class CompiledControlFeedStatement implements ICompiledDmlStatement {
- private Identifier datasetName;
- private OperationType operationType;
- private Query query;
- private int varCounter;
- private Map<String, String> alteredParams;
-
- public CompiledControlFeedStatement(OperationType operationType, Identifier datasetName,
- Map<String, String> alteredParams) {
- this.datasetName = datasetName;
- this.operationType = operationType;
- this.alteredParams = alteredParams;
- }
-
- public Identifier getDatasetName() {
- return datasetName;
- }
-
- public OperationType getOperationType() {
- return operationType;
- }
-
- public int getVarCounter() {
- return varCounter;
- }
-
- public Query getQuery() {
- return query;
- }
-
- @Override
- public Kind getKind() {
- return Kind.CONTROL_FEED;
- }
-
- public Map<String, String> getProperties() {
- return alteredParams;
- }
-
- public void setProperties(Map<String, String> properties) {
- this.alteredParams = properties;
- }
- }
-
- public static class CompiledDeleteStatement implements ICompiledDmlStatement {
- private VariableExpr var;
- private Identifier dataset;
- private Expression condition;
- private Clause dieClause;
- private int varCounter;
- private AqlCompiledMetadataDeclarations compiledDeclarations;
-
- public CompiledDeleteStatement(VariableExpr var, Identifier dataset, Expression condition, Clause dieClause,
- int varCounter, AqlCompiledMetadataDeclarations compiledDeclarations) {
- this.var = var;
- this.dataset = dataset;
- this.condition = condition;
- this.dieClause = dieClause;
- this.varCounter = varCounter;
- this.compiledDeclarations = compiledDeclarations;
- }
-
- public Identifier getDataset() {
- return dataset;
- }
-
- public String getDatasetName() {
- return dataset.getValue();
- }
-
- public int getVarCounter() {
- return varCounter;
- }
-
- public Expression getCondition() {
- return condition;
- }
-
- public Clause getDieClause() {
- return dieClause;
- }
-
- public Query getQuery() throws AlgebricksException {
- String datasetName = dataset.getValue();
-
- List<Expression> arguments = new ArrayList<Expression>();
- LiteralExpr argumentLiteral = new LiteralExpr(new StringLiteral(datasetName));
- arguments.add(argumentLiteral);
-
- CallExpr callExpression = new CallExpr(new AsterixFunction("dataset", 1), arguments);
- List<Clause> clauseList = new ArrayList<Clause>();
- Clause forClause = new ForClause(var, callExpression);
- clauseList.add(forClause);
- Clause whereClause = null;
- if (condition != null) {
- whereClause = new WhereClause(condition);
- clauseList.add(whereClause);
- }
- if (dieClause != null) {
- clauseList.add(dieClause);
- }
-
- Dataset dataset = compiledDeclarations.findDataset(datasetName);
- if (dataset == null) {
- throw new AlgebricksException("Unknown dataset " + datasetName);
- }
- String itemTypeName = dataset.getItemTypeName();
- IAType itemType = compiledDeclarations.findType(itemTypeName);
- ARecordType recType = (ARecordType) itemType;
- String[] fieldNames = recType.getFieldNames();
- List<FieldBinding> fieldBindings = new ArrayList<FieldBinding>();
- for (int i = 0; i < fieldNames.length; i++) {
- FieldAccessor fa = new FieldAccessor(var, new Identifier(fieldNames[i]));
- FieldBinding fb = new FieldBinding(new LiteralExpr(new StringLiteral(fieldNames[i])), fa);
- fieldBindings.add(fb);
- }
- RecordConstructor rc = new RecordConstructor(fieldBindings);
-
- FLWOGRExpression flowgr = new FLWOGRExpression(clauseList, rc);
- Query query = new Query();
- query.setBody(flowgr);
- return query;
- }
-
- @Override
- public Kind getKind() {
- return Kind.DELETE;
- }
-
- }
-
-}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/MetadataDeclTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/MetadataDeclTranslator.java
deleted file mode 100644
index 77b8a04..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/MetadataDeclTranslator.java
+++ /dev/null
@@ -1,366 +0,0 @@
-package edu.uci.ics.asterix.translator;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import edu.uci.ics.asterix.aql.expression.OrderedListTypeDefinition;
-import edu.uci.ics.asterix.aql.expression.RecordTypeDefinition;
-import edu.uci.ics.asterix.aql.expression.RecordTypeDefinition.RecordKind;
-import edu.uci.ics.asterix.aql.expression.TypeDecl;
-import edu.uci.ics.asterix.aql.expression.TypeExpression;
-import edu.uci.ics.asterix.aql.expression.TypeReferenceExpression;
-import edu.uci.ics.asterix.aql.expression.UnorderedListTypeDefinition;
-import edu.uci.ics.asterix.common.annotations.IRecordFieldDataGen;
-import edu.uci.ics.asterix.common.annotations.RecordDataGenAnnotation;
-import edu.uci.ics.asterix.common.annotations.TypeDataGen;
-import edu.uci.ics.asterix.metadata.MetadataException;
-import edu.uci.ics.asterix.metadata.MetadataManager;
-import edu.uci.ics.asterix.metadata.MetadataTransactionContext;
-import edu.uci.ics.asterix.metadata.bootstrap.AsterixProperties;
-import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
-import edu.uci.ics.asterix.metadata.entities.AsterixBuiltinTypeMap;
-import edu.uci.ics.asterix.metadata.entities.Datatype;
-import edu.uci.ics.asterix.om.types.AOrderedListType;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.AUnionType;
-import edu.uci.ics.asterix.om.types.AUnorderedListType;
-import edu.uci.ics.asterix.om.types.AbstractCollectionType;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.data.IAWriterFactory;
-import edu.uci.ics.hyracks.dataflow.std.file.FileSplit;
-
-public final class MetadataDeclTranslator {
- private final MetadataTransactionContext mdTxnCtx;
- private final String dataverseName;
- private final List<TypeDecl> typeDeclarations;
- private final FileSplit outputFile;
- private final Map<String, String> config;
- private final IAWriterFactory writerFactory;
-
- public MetadataDeclTranslator(MetadataTransactionContext mdTxnCtx, String dataverseName, FileSplit outputFile,
- IAWriterFactory writerFactory, Map<String, String> config, List<TypeDecl> typeDeclarations) {
- this.mdTxnCtx = mdTxnCtx;
- this.dataverseName = dataverseName;
- this.outputFile = outputFile;
- this.writerFactory = writerFactory;
- this.config = config;
- this.typeDeclarations = typeDeclarations;
- }
-
- // TODO: Should this not throw an AsterixException?
- public AqlCompiledMetadataDeclarations computeMetadataDeclarations(boolean online) throws AlgebricksException,
- MetadataException {
- Map<String, TypeDataGen> typeDataGenMap = new HashMap<String, TypeDataGen>();
- for (TypeDecl td : typeDeclarations) {
- TypeDataGen tdg = td.getDatagenAnnotation();
- if (tdg != null) {
- typeDataGenMap.put(td.getIdent().getValue(), tdg);
- }
- }
- Map<String, IAType> typeMap = computeTypes();
- Map<String, String[]> stores = AsterixProperties.INSTANCE.getStores();
- return new AqlCompiledMetadataDeclarations(mdTxnCtx, dataverseName, outputFile, config, stores, typeMap,
- typeDataGenMap, writerFactory, online);
- }
-
- private Map<String, IAType> computeTypes() throws AlgebricksException, MetadataException {
- Map<String, IAType> typeMap = new HashMap<String, IAType>();
- Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes = new HashMap<String, Map<ARecordType, List<Integer>>>();
- Map<String, List<AbstractCollectionType>> incompleteItemTypes = new HashMap<String, List<AbstractCollectionType>>();
- Map<String, List<String>> incompleteTopLevelTypeReferences = new HashMap<String, List<String>>();
-
- firstPass(typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences);
- secondPass(typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences);
- return typeMap;
- }
-
- private void secondPass(Map<String, IAType> typeMap,
- Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
- Map<String, List<AbstractCollectionType>> incompleteItemTypes,
- Map<String, List<String>> incompleteTopLevelTypeReferences) throws AlgebricksException, MetadataException {
- // solve remaining top level references
- for (String trefName : incompleteTopLevelTypeReferences.keySet()) {
- IAType t = typeMap.get(trefName);
- if (t == null) {
- throw new AlgebricksException("Could not resolve type " + trefName);
- }
- for (String tname : incompleteTopLevelTypeReferences.get(trefName)) {
- typeMap.put(tname, t);
- }
- }
- // solve remaining field type references
- for (String trefName : incompleteFieldTypes.keySet()) {
- IAType t = typeMap.get(trefName);
- if (t == null) {
- // Try to get type from the metadata manager.
- Datatype metadataDataType = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, dataverseName, trefName);
- if (metadataDataType == null) {
- throw new AlgebricksException("Could not resolve type " + trefName);
- }
- t = metadataDataType.getDatatype();
- typeMap.put(trefName, t);
- }
- Map<ARecordType, List<Integer>> fieldsToFix = incompleteFieldTypes.get(trefName);
- for (ARecordType recType : fieldsToFix.keySet()) {
- List<Integer> positions = fieldsToFix.get(recType);
- IAType[] fldTypes = recType.getFieldTypes();
- for (Integer pos : positions) {
- if (fldTypes[pos] == null) {
- fldTypes[pos] = t;
- } else { // nullable
- AUnionType nullableUnion = (AUnionType) fldTypes[pos];
- nullableUnion.setTypeAtIndex(t, 1);
- }
- }
- }
- }
- // solve remaining item type references
- for (String trefName : incompleteItemTypes.keySet()) {
- IAType t = typeMap.get(trefName);
- if (t == null) {
- throw new AlgebricksException("Could not resolve type " + trefName);
- }
- for (AbstractCollectionType act : incompleteItemTypes.get(trefName)) {
- act.setItemType(t);
- }
- }
- }
-
- private void firstPass(Map<String, IAType> typeMap,
- Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
- Map<String, List<AbstractCollectionType>> incompleteItemTypes,
- Map<String, List<String>> incompleteTopLevelTypeReferences) throws AlgebricksException {
- for (TypeDecl td : typeDeclarations) {
- TypeExpression texpr = td.getTypeDef();
- String tdname = td.getIdent().getValue();
- if (AsterixBuiltinTypeMap.getBuiltinTypes().get(tdname) != null) {
- throw new AlgebricksException("Cannot redefine builtin type " + tdname + " .");
- }
- switch (texpr.getTypeKind()) {
- case TYPEREFERENCE: {
- TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
- IAType t = solveTypeReference(tre, typeMap);
- if (t != null) {
- typeMap.put(tdname, t);
- } else {
- addIncompleteTopLevelTypeReference(tdname, tre, incompleteTopLevelTypeReferences);
- }
- break;
- }
- case RECORD: {
- RecordTypeDefinition rtd = (RecordTypeDefinition) texpr;
- ARecordType recType = computeRecordType(tdname, rtd, typeMap, incompleteFieldTypes,
- incompleteItemTypes);
- typeMap.put(tdname, recType);
- break;
- }
- case ORDEREDLIST: {
- OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
- AOrderedListType olType = computeOrderedListType(tdname, oltd, typeMap, incompleteItemTypes,
- incompleteFieldTypes);
- typeMap.put(tdname, olType);
- break;
- }
- case UNORDEREDLIST: {
- UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
- AUnorderedListType ulType = computeUnorderedListType(tdname, ultd, typeMap, incompleteItemTypes,
- incompleteFieldTypes);
- typeMap.put(tdname, ulType);
- break;
- }
- default: {
- throw new IllegalStateException();
- }
- }
- }
- }
-
- private AOrderedListType computeOrderedListType(String typeName, OrderedListTypeDefinition oltd,
- Map<String, IAType> typeMap, Map<String, List<AbstractCollectionType>> incompleteItemTypes,
- Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
- TypeExpression tExpr = oltd.getItemTypeExpression();
- AOrderedListType aolt = new AOrderedListType(null, typeName);
- setCollectionItemType(tExpr, typeMap, incompleteItemTypes, incompleteFieldTypes, aolt);
- return aolt;
- }
-
- private AUnorderedListType computeUnorderedListType(String typeName, UnorderedListTypeDefinition ultd,
- Map<String, IAType> typeMap, Map<String, List<AbstractCollectionType>> incompleteItemTypes,
- Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
- TypeExpression tExpr = ultd.getItemTypeExpression();
- AUnorderedListType ault = new AUnorderedListType(null, typeName);
- setCollectionItemType(tExpr, typeMap, incompleteItemTypes, incompleteFieldTypes, ault);
- return ault;
- }
-
- private void setCollectionItemType(TypeExpression tExpr, Map<String, IAType> typeMap,
- Map<String, List<AbstractCollectionType>> incompleteItemTypes,
- Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, AbstractCollectionType act) {
- switch (tExpr.getTypeKind()) {
- case ORDEREDLIST: {
- OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) tExpr;
- IAType t = computeOrderedListType(null, oltd, typeMap, incompleteItemTypes, incompleteFieldTypes);
- act.setItemType(t);
- break;
- }
- case UNORDEREDLIST: {
- UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) tExpr;
- IAType t = computeUnorderedListType(null, ultd, typeMap, incompleteItemTypes, incompleteFieldTypes);
- act.setItemType(t);
- break;
- }
- case RECORD: {
- RecordTypeDefinition rtd = (RecordTypeDefinition) tExpr;
- IAType t = computeRecordType(null, rtd, typeMap, incompleteFieldTypes, incompleteItemTypes);
- act.setItemType(t);
- break;
- }
- case TYPEREFERENCE: {
- TypeReferenceExpression tre = (TypeReferenceExpression) tExpr;
- IAType tref = solveTypeReference(tre, typeMap);
- if (tref != null) {
- act.setItemType(tref);
- } else {
- addIncompleteCollectionTypeReference(act, tre, incompleteItemTypes);
- }
- break;
- }
- default: {
- throw new IllegalStateException();
- }
- }
- }
-
- private ARecordType computeRecordType(String typeName, RecordTypeDefinition rtd, Map<String, IAType> typeMap,
- Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
- Map<String, List<AbstractCollectionType>> incompleteItemTypes) {
- List<String> names = rtd.getFieldNames();
- int n = names.size();
- String[] fldNames = new String[n];
- IAType[] fldTypes = new IAType[n];
- int i = 0;
- for (String s : names) {
- fldNames[i++] = s;
- }
- boolean isOpen = rtd.getRecordKind() == RecordKind.OPEN;
- ARecordType recType = new ARecordType(typeName, fldNames, fldTypes, isOpen);
-
- List<IRecordFieldDataGen> fieldDataGen = rtd.getFieldDataGen();
- if (fieldDataGen.size() == n) {
- IRecordFieldDataGen[] rfdg = new IRecordFieldDataGen[n];
- rfdg = fieldDataGen.toArray(rfdg);
- recType.getAnnotations().add(new RecordDataGenAnnotation(rfdg, rtd.getUndeclaredFieldsDataGen()));
- }
-
- for (int j = 0; j < n; j++) {
- TypeExpression texpr = rtd.getFieldTypes().get(j);
- switch (texpr.getTypeKind()) {
- case TYPEREFERENCE: {
- TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
- IAType tref = solveTypeReference(tre, typeMap);
- if (tref != null) {
- if (!rtd.getNullableFields().get(j)) { // not nullable
- fldTypes[j] = tref;
- } else { // nullable
- fldTypes[j] = makeUnionWithNull(null, tref);
- }
- } else {
- addIncompleteFieldTypeReference(recType, j, tre, incompleteFieldTypes);
- if (rtd.getNullableFields().get(j)) {
- fldTypes[j] = makeUnionWithNull(null, null);
- }
- }
- break;
- }
- case RECORD: {
- RecordTypeDefinition recTypeDef2 = (RecordTypeDefinition) texpr;
- IAType t2 = computeRecordType(null, recTypeDef2, typeMap, incompleteFieldTypes, incompleteItemTypes);
- if (!rtd.getNullableFields().get(j)) { // not nullable
- fldTypes[j] = t2;
- } else { // nullable
- fldTypes[j] = makeUnionWithNull(null, t2);
- }
- break;
- }
- case ORDEREDLIST: {
- OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
- IAType t2 = computeOrderedListType(null, oltd, typeMap, incompleteItemTypes, incompleteFieldTypes);
- fldTypes[j] = (rtd.getNullableFields().get(j)) ? makeUnionWithNull(null, t2) : t2;
- break;
- }
- case UNORDEREDLIST: {
- UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
- IAType t2 = computeUnorderedListType(null, ultd, typeMap, incompleteItemTypes, incompleteFieldTypes);
- fldTypes[j] = (rtd.getNullableFields().get(j)) ? makeUnionWithNull(null, t2) : t2;
- break;
- }
- default: {
- throw new IllegalStateException();
- }
- }
-
- }
-
- return recType;
- }
-
- private AUnionType makeUnionWithNull(String unionTypeName, IAType type) {
- ArrayList<IAType> unionList = new ArrayList<IAType>(2);
- unionList.add(BuiltinType.ANULL);
- unionList.add(type);
- return new AUnionType(unionList, unionTypeName);
- }
-
- private void addIncompleteCollectionTypeReference(AbstractCollectionType collType, TypeReferenceExpression tre,
- Map<String, List<AbstractCollectionType>> incompleteItemTypes) {
- String typeName = tre.getIdent().getValue();
- List<AbstractCollectionType> typeList = incompleteItemTypes.get(typeName);
- if (typeList == null) {
- typeList = new LinkedList<AbstractCollectionType>();
- incompleteItemTypes.put(typeName, typeList);
- }
- typeList.add(collType);
- }
-
- private void addIncompleteFieldTypeReference(ARecordType recType, int fldPosition, TypeReferenceExpression tre,
- Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
- String typeName = tre.getIdent().getValue();
- Map<ARecordType, List<Integer>> refMap = incompleteFieldTypes.get(typeName);
- if (refMap == null) {
- refMap = new HashMap<ARecordType, List<Integer>>();
- incompleteFieldTypes.put(typeName, refMap);
- }
- List<Integer> typeList = refMap.get(recType);
- if (typeList == null) {
- typeList = new ArrayList<Integer>();
- refMap.put(recType, typeList);
- }
- typeList.add(fldPosition);
- }
-
- private void addIncompleteTopLevelTypeReference(String tdeclName, TypeReferenceExpression tre,
- Map<String, List<String>> incompleteTopLevelTypeReferences) {
- String name = tre.getIdent().getValue();
- List<String> refList = incompleteTopLevelTypeReferences.get(name);
- if (refList == null) {
- refList = new LinkedList<String>();
- incompleteTopLevelTypeReferences.put(name, refList);
- }
- refList.add(tdeclName);
- }
-
- private IAType solveTypeReference(TypeReferenceExpression tre, Map<String, IAType> typeMap) {
- String name = tre.getIdent().getValue();
- IAType builtin = AsterixBuiltinTypeMap.getBuiltinTypes().get(name);
- if (builtin != null) {
- return builtin;
- } else {
- return typeMap.get(name);
- }
- }
-}
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/TypeTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/TypeTranslator.java
new file mode 100644
index 0000000..83572e2
--- /dev/null
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/TypeTranslator.java
@@ -0,0 +1,393 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.asterix.translator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import edu.uci.ics.asterix.aql.expression.OrderedListTypeDefinition;
+import edu.uci.ics.asterix.aql.expression.RecordTypeDefinition;
+import edu.uci.ics.asterix.aql.expression.RecordTypeDefinition.RecordKind;
+import edu.uci.ics.asterix.aql.expression.TypeDecl;
+import edu.uci.ics.asterix.aql.expression.TypeExpression;
+import edu.uci.ics.asterix.aql.expression.TypeReferenceExpression;
+import edu.uci.ics.asterix.aql.expression.UnorderedListTypeDefinition;
+import edu.uci.ics.asterix.common.annotations.IRecordFieldDataGen;
+import edu.uci.ics.asterix.common.annotations.RecordDataGenAnnotation;
+import edu.uci.ics.asterix.metadata.MetadataException;
+import edu.uci.ics.asterix.metadata.MetadataManager;
+import edu.uci.ics.asterix.metadata.MetadataTransactionContext;
+import edu.uci.ics.asterix.metadata.entities.AsterixBuiltinTypeMap;
+import edu.uci.ics.asterix.metadata.entities.Datatype;
+import edu.uci.ics.asterix.om.types.AOrderedListType;
+import edu.uci.ics.asterix.om.types.ARecordType;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.AUnorderedListType;
+import edu.uci.ics.asterix.om.types.AbstractCollectionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeSignature;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+
+public class TypeTranslator {
+
+ public static Map<TypeSignature, IAType> computeTypes(MetadataTransactionContext mdTxnCtx, TypeDecl tDec,
+ String defaultDataverse) throws AlgebricksException, MetadataException {
+ Map<TypeSignature, IAType> typeMap = new HashMap<TypeSignature, IAType>();
+ Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes = new HashMap<String, Map<ARecordType, List<Integer>>>();
+ Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes = new HashMap<TypeSignature, List<AbstractCollectionType>>();
+ Map<TypeSignature, List<TypeSignature>> incompleteTopLevelTypeReferences = new HashMap<TypeSignature, List<TypeSignature>>();
+ String typeDataverse = tDec.getDataverseName() == null ? defaultDataverse : tDec.getDataverseName().getValue();
+ firstPass(tDec, typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences,
+ typeDataverse);
+ secondPass(mdTxnCtx, typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences,
+ typeDataverse);
+
+ return typeMap;
+ }
+
+ public static Map<TypeSignature, IAType> computeTypes(MetadataTransactionContext mdTxnCtx, TypeDecl tDec,
+ String defaultDataverse, Map<TypeSignature, IAType> typeMap) throws AlgebricksException, MetadataException {
+ Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes = new HashMap<String, Map<ARecordType, List<Integer>>>();
+ Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes = new HashMap<TypeSignature, List<AbstractCollectionType>>();
+ Map<TypeSignature, List<TypeSignature>> incompleteTopLevelTypeReferences = new HashMap<TypeSignature, List<TypeSignature>>();
+ String typeDataverse = tDec.getDataverseName() == null ? defaultDataverse : tDec.getDataverseName().getValue();
+ firstPass(tDec, typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences,
+ typeDataverse);
+ secondPass(mdTxnCtx, typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences,
+ typeDataverse);
+
+ return typeMap;
+ }
+
+ private static Map<String, BuiltinType> builtinTypeMap = AsterixBuiltinTypeMap.getBuiltinTypes();
+
+ private static void firstPass(TypeDecl td, Map<TypeSignature, IAType> typeMap,
+ Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
+ Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
+ Map<TypeSignature, List<TypeSignature>> incompleteTopLevelTypeReferences, String typeDataverse)
+ throws AlgebricksException {
+
+ TypeExpression texpr = td.getTypeDef();
+ String tdname = td.getIdent().getValue();
+ if (builtinTypeMap.get(tdname) != null) {
+ throw new AlgebricksException("Cannot redefine builtin type " + tdname + " .");
+ }
+ TypeSignature typeSignature = new TypeSignature(typeDataverse, tdname);
+ switch (texpr.getTypeKind()) {
+ case TYPEREFERENCE: {
+ TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
+ IAType t = solveTypeReference(typeSignature, typeMap);
+ if (t != null) {
+ typeMap.put(typeSignature, t);
+ } else {
+ addIncompleteTopLevelTypeReference(tdname, tre, incompleteTopLevelTypeReferences, typeDataverse);
+ }
+ break;
+ }
+ case RECORD: {
+ RecordTypeDefinition rtd = (RecordTypeDefinition) texpr;
+ ARecordType recType = computeRecordType(typeSignature, rtd, typeMap, incompleteFieldTypes,
+ incompleteItemTypes, typeDataverse);
+ typeMap.put(typeSignature, recType);
+ break;
+ }
+ case ORDEREDLIST: {
+ OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
+ AOrderedListType olType = computeOrderedListType(typeSignature, oltd, typeMap, incompleteItemTypes,
+ incompleteFieldTypes, typeDataverse);
+ typeMap.put(typeSignature, olType);
+ break;
+ }
+ case UNORDEREDLIST: {
+ UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
+ AUnorderedListType ulType = computeUnorderedListType(typeSignature, ultd, typeMap, incompleteItemTypes,
+ incompleteFieldTypes, typeDataverse);
+ typeMap.put(typeSignature, ulType);
+ break;
+ }
+ default: {
+ throw new IllegalStateException();
+ }
+ }
+ }
+
+ private static void secondPass(MetadataTransactionContext mdTxnCtx, Map<TypeSignature, IAType> typeMap,
+ Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
+ Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
+ Map<TypeSignature, List<TypeSignature>> incompleteTopLevelTypeReferences, String typeDataverse)
+ throws AlgebricksException, MetadataException {
+ // solve remaining top level references
+
+ for (TypeSignature typeSignature : incompleteTopLevelTypeReferences.keySet()) {
+ IAType t;// = typeMap.get(trefName);
+ System.out.println("METADATA MGR : " + MetadataManager.INSTANCE);
+ Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeSignature.getNamespace(),
+ typeSignature.getName());
+ if (dt == null) {
+ throw new AlgebricksException("Could not resolve type " + typeSignature);
+ } else
+ t = dt.getDatatype();
+ for (TypeSignature sign : incompleteTopLevelTypeReferences.get(typeSignature)) {
+ typeMap.put(sign, t);
+ }
+ }
+ // solve remaining field type references
+ for (String trefName : incompleteFieldTypes.keySet()) {
+ IAType t;// = typeMap.get(trefName);
+ System.out.println("METADATA MGR : " + MetadataManager.INSTANCE);
+ Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeDataverse, trefName);
+ if (dt == null) {
+ throw new AlgebricksException("Could not resolve type " + trefName);
+ } else
+ t = dt.getDatatype();
+ Map<ARecordType, List<Integer>> fieldsToFix = incompleteFieldTypes.get(trefName);
+ for (ARecordType recType : fieldsToFix.keySet()) {
+ List<Integer> positions = fieldsToFix.get(recType);
+ IAType[] fldTypes = recType.getFieldTypes();
+ for (Integer pos : positions) {
+ if (fldTypes[pos] == null) {
+ fldTypes[pos] = t;
+ } else { // nullable
+ AUnionType nullableUnion = (AUnionType) fldTypes[pos];
+ nullableUnion.setTypeAtIndex(t, 1);
+ }
+ }
+ }
+ }
+
+ // solve remaining item type references
+ for (TypeSignature typeSignature : incompleteItemTypes.keySet()) {
+ IAType t;// = typeMap.get(trefName);
+ Datatype dt = null;
+ if (MetadataManager.INSTANCE != null) {
+ dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeSignature.getNamespace(),
+ typeSignature.getName());
+ if (dt == null) {
+ throw new AlgebricksException("Could not resolve type " + typeSignature);
+ }
+ t = dt.getDatatype();
+ } else {
+ t = typeMap.get(typeSignature);
+ }
+ for (AbstractCollectionType act : incompleteItemTypes.get(typeSignature)) {
+ act.setItemType(t);
+ }
+ }
+ }
+
+ private static AOrderedListType computeOrderedListType(TypeSignature typeSignature, OrderedListTypeDefinition oltd,
+ Map<TypeSignature, IAType> typeMap, Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
+ Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, String defaultDataverse) {
+ TypeExpression tExpr = oltd.getItemTypeExpression();
+ String typeName = typeSignature != null ? typeSignature.getName() : null;
+ AOrderedListType aolt = new AOrderedListType(null, typeName);
+ setCollectionItemType(tExpr, typeMap, incompleteItemTypes, incompleteFieldTypes, aolt, defaultDataverse);
+ return aolt;
+ }
+
+ private static AUnorderedListType computeUnorderedListType(TypeSignature typeSignature,
+ UnorderedListTypeDefinition ultd, Map<TypeSignature, IAType> typeMap,
+ Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
+ Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, String defaulDataverse) {
+ TypeExpression tExpr = ultd.getItemTypeExpression();
+ String typeName = typeSignature != null ? typeSignature.getName() : null;
+ AUnorderedListType ault = new AUnorderedListType(null, typeName);
+ setCollectionItemType(tExpr, typeMap, incompleteItemTypes, incompleteFieldTypes, ault, defaulDataverse);
+ return ault;
+ }
+
+ private static void setCollectionItemType(TypeExpression tExpr, Map<TypeSignature, IAType> typeMap,
+ Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
+ Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, AbstractCollectionType act,
+ String defaultDataverse) {
+ switch (tExpr.getTypeKind()) {
+ case ORDEREDLIST: {
+ OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) tExpr;
+ IAType t = computeOrderedListType(null, oltd, typeMap, incompleteItemTypes, incompleteFieldTypes,
+ defaultDataverse);
+ act.setItemType(t);
+ break;
+ }
+ case UNORDEREDLIST: {
+ UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) tExpr;
+ IAType t = computeUnorderedListType(null, ultd, typeMap, incompleteItemTypes, incompleteFieldTypes,
+ defaultDataverse);
+ act.setItemType(t);
+ break;
+ }
+ case RECORD: {
+ RecordTypeDefinition rtd = (RecordTypeDefinition) tExpr;
+ IAType t = computeRecordType(null, rtd, typeMap, incompleteFieldTypes, incompleteItemTypes,
+ defaultDataverse);
+ act.setItemType(t);
+ break;
+ }
+ case TYPEREFERENCE: {
+ TypeReferenceExpression tre = (TypeReferenceExpression) tExpr;
+ TypeSignature signature = new TypeSignature(defaultDataverse, tre.getIdent().getValue());
+ IAType tref = solveTypeReference(signature, typeMap);
+ if (tref != null) {
+ act.setItemType(tref);
+ } else {
+ addIncompleteCollectionTypeReference(act, tre, incompleteItemTypes, defaultDataverse);
+ }
+ break;
+ }
+ default: {
+ throw new IllegalStateException();
+ }
+ }
+ }
+
+ private static void addIncompleteCollectionTypeReference(AbstractCollectionType collType,
+ TypeReferenceExpression tre, Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
+ String defaultDataverse) {
+ String typeName = tre.getIdent().getValue();
+ TypeSignature typeSignature = new TypeSignature(defaultDataverse, typeName);
+ List<AbstractCollectionType> typeList = incompleteItemTypes.get(typeName);
+ if (typeList == null) {
+ typeList = new LinkedList<AbstractCollectionType>();
+ incompleteItemTypes.put(typeSignature, typeList);
+ }
+ typeList.add(collType);
+ }
+
+ private static void addIncompleteFieldTypeReference(ARecordType recType, int fldPosition,
+ TypeReferenceExpression tre, Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
+ String typeName = tre.getIdent().getValue();
+ Map<ARecordType, List<Integer>> refMap = incompleteFieldTypes.get(typeName);
+ if (refMap == null) {
+ refMap = new HashMap<ARecordType, List<Integer>>();
+ incompleteFieldTypes.put(typeName, refMap);
+ }
+ List<Integer> typeList = refMap.get(recType);
+ if (typeList == null) {
+ typeList = new ArrayList<Integer>();
+ refMap.put(recType, typeList);
+ }
+ typeList.add(fldPosition);
+ }
+
+ private static void addIncompleteTopLevelTypeReference(String tdeclName, TypeReferenceExpression tre,
+ Map<TypeSignature, List<TypeSignature>> incompleteTopLevelTypeReferences, String defaultDataverse) {
+ String name = tre.getIdent().getValue();
+ TypeSignature typeSignature = new TypeSignature(defaultDataverse, name);
+ List<TypeSignature> refList = incompleteTopLevelTypeReferences.get(name);
+ if (refList == null) {
+ refList = new LinkedList<TypeSignature>();
+ incompleteTopLevelTypeReferences.put(new TypeSignature(defaultDataverse, tre.getIdent().getValue()),
+ refList);
+ }
+ refList.add(typeSignature);
+ }
+
+ private static IAType solveTypeReference(TypeSignature typeSignature, Map<TypeSignature, IAType> typeMap) {
+ IAType builtin = builtinTypeMap.get(typeSignature.getName());
+ if (builtin != null) {
+ return builtin;
+ } else {
+ return typeMap.get(typeSignature);
+ }
+ }
+
+ private static ARecordType computeRecordType(TypeSignature typeSignature, RecordTypeDefinition rtd,
+ Map<TypeSignature, IAType> typeMap, Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
+ Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes, String defaultDataverse) {
+ List<String> names = rtd.getFieldNames();
+ int n = names.size();
+ String[] fldNames = new String[n];
+ IAType[] fldTypes = new IAType[n];
+ int i = 0;
+ for (String s : names) {
+ fldNames[i++] = s;
+ }
+ boolean isOpen = rtd.getRecordKind() == RecordKind.OPEN;
+ ARecordType recType = new ARecordType(typeSignature == null ? null : typeSignature.getName(), fldNames,
+ fldTypes, isOpen);
+
+ List<IRecordFieldDataGen> fieldDataGen = rtd.getFieldDataGen();
+ if (fieldDataGen.size() == n) {
+ IRecordFieldDataGen[] rfdg = new IRecordFieldDataGen[n];
+ rfdg = fieldDataGen.toArray(rfdg);
+ recType.getAnnotations().add(new RecordDataGenAnnotation(rfdg, rtd.getUndeclaredFieldsDataGen()));
+ }
+
+ for (int j = 0; j < n; j++) {
+ TypeExpression texpr = rtd.getFieldTypes().get(j);
+ switch (texpr.getTypeKind()) {
+ case TYPEREFERENCE: {
+ TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
+ TypeSignature signature = new TypeSignature(defaultDataverse, tre.getIdent().getValue());
+ IAType tref = solveTypeReference(signature, typeMap);
+ if (tref != null) {
+ if (!rtd.getNullableFields().get(j)) { // not nullable
+ fldTypes[j] = tref;
+ } else { // nullable
+ fldTypes[j] = makeUnionWithNull(null, tref);
+ }
+ } else {
+ addIncompleteFieldTypeReference(recType, j, tre, incompleteFieldTypes);
+ if (rtd.getNullableFields().get(j)) {
+ fldTypes[j] = makeUnionWithNull(null, null);
+ }
+ }
+ break;
+ }
+ case RECORD: {
+ RecordTypeDefinition recTypeDef2 = (RecordTypeDefinition) texpr;
+ IAType t2 = computeRecordType(null, recTypeDef2, typeMap, incompleteFieldTypes,
+ incompleteItemTypes, defaultDataverse);
+ if (!rtd.getNullableFields().get(j)) { // not nullable
+ fldTypes[j] = t2;
+ } else { // nullable
+ fldTypes[j] = makeUnionWithNull(null, t2);
+ }
+ break;
+ }
+ case ORDEREDLIST: {
+ OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
+ IAType t2 = computeOrderedListType(null, oltd, typeMap, incompleteItemTypes, incompleteFieldTypes,
+ defaultDataverse);
+ fldTypes[j] = (rtd.getNullableFields().get(j)) ? makeUnionWithNull(null, t2) : t2;
+ break;
+ }
+ case UNORDEREDLIST: {
+ UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
+ IAType t2 = computeUnorderedListType(null, ultd, typeMap, incompleteItemTypes,
+ incompleteFieldTypes, defaultDataverse);
+ fldTypes[j] = (rtd.getNullableFields().get(j)) ? makeUnionWithNull(null, t2) : t2;
+ break;
+ }
+ default: {
+ throw new IllegalStateException();
+ }
+ }
+
+ }
+
+ return recType;
+ }
+
+ private static AUnionType makeUnionWithNull(String unionTypeName, IAType type) {
+ ArrayList<IAType> unionList = new ArrayList<IAType>(2);
+ unionList.add(BuiltinType.ANULL);
+ unionList.add(type);
+ return new AUnionType(unionList, unionTypeName);
+ }
+}
diff --git a/asterix-algebra/src/main/javacc/AQLPlus.jj b/asterix-algebra/src/main/javacc/AQLPlus.jj
index 3422652..5b97d04 100644
--- a/asterix-algebra/src/main/javacc/AQLPlus.jj
+++ b/asterix-algebra/src/main/javacc/AQLPlus.jj
@@ -26,7 +26,6 @@
import edu.uci.ics.asterix.aql.literal.NullLiteral;
import edu.uci.ics.asterix.aql.literal.StringLiteral;
import edu.uci.ics.asterix.aql.literal.TrueLiteral;
-
import edu.uci.ics.asterix.aql.parser.ScopeChecker;
import edu.uci.ics.asterix.aql.base.*;
import edu.uci.ics.asterix.aql.expression.*;
@@ -36,8 +35,15 @@
import edu.uci.ics.asterix.aql.context.Scope;
import edu.uci.ics.asterix.aql.context.RootScopeFactory;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
-
import edu.uci.ics.asterix.om.functions.AsterixFunction;
+import edu.uci.ics.asterix.common.functions.FunctionSignature;
+import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
+
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
+import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
+
+
public class AQLPlusParser extends ScopeChecker {
@@ -57,6 +63,8 @@
private static final String HASH_GROUP_BY_HINT = "hash";
private static final String BROADCAST_JOIN_HINT = "bcast";
private static final String INMEMORY_HINT = "inmem";
+ private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
+
private static String getHint(Token t) {
@@ -75,17 +83,7 @@
File file = new File(args[0]);
Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
AQLPlusParser parser = new AQLPlusParser(fis);
- Statement st = parser.Statement();
- st.accept(new AQLPrintVisitor(), 0);
-
-// System.out.println("FunctionCalls not found:");
-// for(FunctionDescriptor fd: notFoundFunctionList)
-// {
-// if(lookupFunctionSignature(fd.getValue(), fd.getArity())!=null)
-// notFoundFunctionList.remove(fd);
-// }
-// System.out.println(notFoundFunctionList.toString());
-
+ List<Statement> st = parser.Statement();
}
public void initScope() {
@@ -96,7 +94,7 @@
PARSER_END(AQLPlusParser)
-Statement Statement() throws ParseException:
+List<Statement> Statement() throws ParseException:
{
Query query = null;
// scopeStack.push(RootScopeFactory.createRootScope(this));
@@ -129,26 +127,20 @@
| "set" {
decls.add(SetStatement());
}
+ |
+ {
+ decls.add(Query()) ;
+ } ";"
+
)*
- (query = Query())?
)
<EOF>
)
{
- if (query == null) {
- query = new Query(true);
- }
- query.setPrologDeclList(decls);
-
-// for(FunctionDecl fdc : fdList)
-// {
-// FunctionDescriptor fd = (FunctionDescriptor) fdc.getIdent();
-// notFoundFunctionList.remove(fd);
-// }
-// }
- return query;
+
+ return decls;
}
}
@@ -187,7 +179,7 @@
<DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); }
<LEFTPAREN> query = Query() <RIGHTPAREN>
{
- stmt = new WriteFromQueryResultStatement(datasetName, query, getVarCounter());
+ stmt = new WriteFromQueryResultStatement(null, datasetName, query, getVarCounter());
} ))
";"
@@ -201,10 +193,10 @@
Identifier dvName = null;
}
{
- "dataverse" <IDENTIFIER> { dvName = new Identifier(token.image); }
+ "dataverse" <IDENTIFIER> { defaultDataverse = token.image;}
";"
{
- return new DataverseDecl(dvName);
+ return new DataverseDecl(new Identifier(defaultDataverse));
}
}
@@ -272,7 +264,7 @@
";"
{
- return new LoadFromFileStatement(datasetName, adapter, properties, alreadySorted);
+ return new LoadFromFileStatement(null, datasetName, adapter, properties, alreadySorted);
}
}
@@ -289,7 +281,7 @@
"as"
( typeExpr = TypeExpr() )
{
- return new TypeDecl(ident, typeExpr);
+ return new TypeDecl(null, ident, typeExpr);
}
}
@@ -393,8 +385,8 @@
FunctionDecl FunctionDeclaration() throws ParseException:
{
- FunctionDecl func = new FunctionDecl();
- AsterixFunction ident;
+ FunctionDecl funcDecl;
+ FunctionSignature signature;
String functionName;
int arity = 0;
List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
@@ -427,12 +419,10 @@
})*)? <RIGHTPAREN> "{" funcBody = Expression() "}"
{
- ident = new AsterixFunction(functionName, arity);
- getCurrentScope().addFunctionDescriptor(ident, false);
- func.setIdent(ident);
- func.setFuncBody(funcBody);
- func.setParamList(paramList);
- return func;
+ signature = new FunctionSignature(defaultDataverse, functionName, arity);
+ getCurrentScope().addFunctionDescriptor(signature, false);
+ funcDecl = new FunctionDecl(signature, paramList, funcBody);
+ return funcDecl;
}
}
@@ -1044,16 +1034,24 @@
Expression FunctionCallExpr() throws ParseException:
{
- CallExpr pf = new CallExpr();
- List<Expression > argList = new ArrayList<Expression >();
+ CallExpr callExpr;
+ List<Expression> argList = new ArrayList<Expression>();
Expression tmp;
int arity = 0;
- Token funcName;
+ String funcName;
+ String dataverse;
+ String hint=null;
+ String id1=null;
+ String id2=null;
}
-{
- ( <IDENTIFIER> | <DATASET> )
+{
+ ( <IDENTIFIER> { dataverse = defaultDataverse; funcName = token.image;}
+ ("." <IDENTIFIER> { dataverse = funcName; funcName = token.image;})?
+ |
+ <DATASET> {dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; funcName = getToken(0).toString();}
+ )
{
- funcName = getToken(0);
+ hint=getHint(token);
}
<LEFTPAREN> (tmp = Expression()
{
@@ -1062,16 +1060,16 @@
} ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN>
{
- AsterixFunction fd = lookupFunctionSignature(funcName.toString(), arity);
- if(fd == null)
- {
- fd = new AsterixFunction(funcName.toString(), arity);
-// notFoundFunctionList.add(fd);
- }
-// throw new ParseException("can't find function "+ funcName.toString() + "@" + arity);
- pf.setIdent(fd);
- pf.setExprList(argList);
- return pf;
+ FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity);
+ if(signature == null)
+ {
+ signature = new FunctionSignature(dataverse, funcName.toString(), arity);
+ }
+ callExpr = new CallExpr(signature,argList);
+ if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
+ callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
+ }
+ return callExpr;
}
}