Merged asterix_stabilization.
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix-fix-issue-109@184 eaa15691-b419-025a-1212-ee371bd00084
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
index 9e2150c..798e92d 100644
--- 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
@@ -12,6 +12,7 @@
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;
@@ -27,7 +28,6 @@
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.expression.ControlFeedStatement.OperationType;
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;
@@ -39,6 +39,7 @@
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;
@@ -70,16 +71,28 @@
return compiledDmlStatements;
}
- private List<ICompiledDmlStatement> compileDmlStatements() throws AlgebricksException {
+ 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 st1 = (LoadFromFileStatement) stmt;
- CompiledLoadFromFileStatement cls = new CompiledLoadFromFileStatement(st1.getDatasetName()
- .getValue(), st1.getAdapter(), st1.getProperties(), st1.dataIsAlreadySorted());
+ 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.getIndexType());
+ dmlStatements.add(cis);
+ }
break;
}
case WRITE_FROM_QUERY_RESULT: {
@@ -91,11 +104,27 @@
}
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.getIndexType());
dmlStatements.add(ccis);
- }
+ }
break;
}
case INSERT: {
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
index b0b27ed..a5e28a5 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
@@ -195,19 +195,6 @@
case LOAD_FROM_FILE: {
CompiledLoadFromFileStatement stmtLoad = (CompiledLoadFromFileStatement) stmt;
dmlJobs.addAll(DatasetOperations.createLoadDatasetJobSpec(stmtLoad, metadata));
- // Also load the dataset's secondary indexes.
- List<Index> datasetIndexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx,
- dataverseName, stmtLoad.getDatasetName());
- for (Index index : datasetIndexes) {
- if (!index.isSecondaryIndex()) {
- continue;
- }
- // Recreate CompiledCreateIndexStatement from metadata entity 'index'.
- CompiledCreateIndexStatement cis = new CompiledCreateIndexStatement(index.getIndexName(),
- index.getDatasetName(), index.getKeyFieldNames(), index.getIndexType());
- JobSpecification jobSpec = IndexOperations.buildCreateIndexJobSpec(cis, metadata);
- dmlJobs.add(new Job(jobSpec));
- }
break;
}
case WRITE_FROM_QUERY_RESULT: {