change datasource scans to retain input (aka propagate all vars); add test case for hoisted let that avoids var inlining
diff --git a/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.1.ddl.aql
new file mode 100644
index 0000000..a90731e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.1.ddl.aql
@@ -0,0 +1,16 @@
+/*
+ * Description : Test hoisting a variable that does not get inlined
+ * Expected Result : Success
+ * Date : 8th November 2013
+ */
+
+drop dataverse foo if exists;
+create dataverse foo if not exists;
+use dataverse foo;
+
+create type fbuser as open {
+id: int32,
+name: string
+};
+
+create dataset fb(fbuser) primary key id;
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.2.update.aql
new file mode 100644
index 0000000..839149f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.2.update.aql
@@ -0,0 +1,15 @@
+/*
+ * Description : Test hoisting a variable that does not get inlined
+ * Expected Result : Success
+ * Date : 8th November 2013
+ */
+
+use dataverse foo;
+
+insert into dataset fb(
+{"id": 1, "name": "Tom"}
+);
+
+insert into dataset fb(
+{"id": 2, "name": "Mike"}
+);
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.3.query.aql
new file mode 100644
index 0000000..22de755
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/flwor/let33/let33.3.query.aql
@@ -0,0 +1,13 @@
+/*
+ * Description : Test hoisting a variable that does not get inlined
+ * Expected Result : Success
+ * Date : 8th November 2013
+ */
+
+use dataverse foo;
+
+let $recs := {{ {"id":1, "name": "Tom"}, {"id":2, "name": "Till"} }}
+for $f in dataset fb
+for $r in $recs
+where $r.name = $f.name
+return {"name": $r.name}
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/flwor/let33/let33.1.adm b/asterix-app/src/test/resources/runtimets/results/flwor/let33/let33.1.adm
new file mode 100644
index 0000000..783934c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/flwor/let33/let33.1.adm
@@ -0,0 +1 @@
+{ "name": "Tom" }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 6dfa587..bb0a7ab 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -50,6 +50,11 @@
</compilation-unit>
</test-case>
</test-group>
+ <test-case FilePath="flwor">
+ <compilation-unit name="let33">
+ <output-dir compare="Text">let33</output-dir>
+ </compilation-unit>
+ </test-case>
<test-group name="aggregate">
<test-case FilePath="aggregate">
<compilation-unit name="issue531_string_min_max">
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
index 1e39694..f598f9d 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
@@ -306,7 +306,7 @@
String dataverseName = asid.getDataverseName();
String datasetName = asid.getDatasetName();
Index primaryIndex = MetadataManager.INSTANCE.getIndex(mdTxnCtx, dataverseName, datasetName, datasetName);
- return buildBtreeRuntime(jobSpec, outputVars, opSchema, typeEnv, context, false,
+ return buildBtreeRuntime(jobSpec, outputVars, opSchema, typeEnv, context, true,
((DatasetDataSource) dataSource).getDataset(), primaryIndex.getIndexName(), null, null, true, true,
implConfig);
}
@@ -482,31 +482,26 @@
}
int numPrimaryKeys = DatasetUtils.getPartitioningKeys(dataset).size();
RecordDescriptor outputRecDesc = JobGenHelper.mkRecordDescriptor(typeEnv, opSchema, context);
- int numKeys = numPrimaryKeys;
- int keysStartIndex = outputRecDesc.getFieldCount() - numKeys - 1;
ITypeTraits[] typeTraits = null;
int[] bloomFilterKeyFields;
if (isSecondary) {
Index secondaryIndex = MetadataManager.INSTANCE.getIndex(mdTxnCtx, dataset.getDataverseName(),
dataset.getDatasetName(), indexName);
int numSecondaryKeys = secondaryIndex.getKeyFieldNames().size();
- numKeys += numSecondaryKeys;
- keysStartIndex = outputVars.size() - numKeys;
typeTraits = JobGenHelper.variablesToTypeTraits(outputVars, 0, outputVars.size(), typeEnv, context);
bloomFilterKeyFields = new int[numSecondaryKeys];
for (int i = 0; i < numSecondaryKeys; i++) {
bloomFilterKeyFields[i] = i;
}
} else {
- typeTraits = JobGenHelper.variablesToTypeTraits(outputVars, 0, outputVars.size(), typeEnv,
- context);
+ typeTraits = JobGenHelper.variablesToTypeTraits(outputVars, 0, outputVars.size(), typeEnv, context);
bloomFilterKeyFields = new int[numPrimaryKeys];
for (int i = 0; i < numPrimaryKeys; i++) {
bloomFilterKeyFields[i] = i;
}
}
IBinaryComparatorFactory[] comparatorFactories = JobGenHelper.variablesToAscBinaryComparatorFactories(
- outputVars, keysStartIndex, numKeys, typeEnv, context);
+ outputVars, 0, outputVars.size(), typeEnv, context);
IAsterixApplicationContextInfo appContext = (IAsterixApplicationContextInfo) context.getAppContext();
Pair<IFileSplitProvider, AlgebricksPartitionConstraint> spPc;