Took care of Zach's comments.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix-fix-issue-113@259 eaa15691-b419-025a-1212-ee371bd00084
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 c9507d9..7f6769e 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
@@ -233,7 +233,7 @@
                     }
                     case CREATE_INDEX: {
                         CompiledCreateIndexStatement cis = (CompiledCreateIndexStatement) stmt;
-                        JobSpecification jobSpec = IndexOperations.buildCreateIndexJobSpec(cis, metadata);
+                        JobSpecification jobSpec = IndexOperations.buildSecondaryIndexLoadingJobSpec(cis, metadata);
                         dmlJobs.add(new Job(jobSpec));
                         break;
                     }
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/DdlTranslator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/DdlTranslator.java
index 5948445..91e770a 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/DdlTranslator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/DdlTranslator.java
@@ -216,7 +216,7 @@
                             new Dataset(compiledDeclarations.getDataverseName(), datasetName, itemTypeName,
                                     datasetDetails, dsType));
                     if (dd.getDatasetType() == DatasetType.INTERNAL || dd.getDatasetType() == DatasetType.FEED) {
-                        compileDatasetDeclStatement(hcc, datasetName);
+                        runCreateDatasetJob(hcc, datasetName);
                     }
                     break;
                 }
@@ -243,7 +243,7 @@
                         MetadataManager.INSTANCE.addIndex(mdTxnCtx, new Index(compiledDeclarations.getDataverseName(),
                                 datasetName, indexName, stmtCreateIndex.getIndexType(),
                                 stmtCreateIndex.getFieldExprs(), false));
-                        compileCreateIndexStatement(hcc, stmtCreateIndex);
+                        runCreateIndexJob(hcc, stmtCreateIndex);
                     }                            
                     break;
                 }
@@ -479,22 +479,22 @@
         }
     }
 
-    private void compileDatasetDeclStatement(IHyracksClientConnection hcc, String datasetName) throws AsterixException,
+    private void runCreateDatasetJob(IHyracksClientConnection hcc, String datasetName) throws AsterixException,
             AlgebricksException, Exception {
         runJob(hcc, DatasetOperations.createDatasetJobSpec(datasetName, compiledDeclarations));
     }
     
-    private void compileCreateIndexStatement(IHyracksClientConnection hcc, CreateIndexStatement stmtCreateIndex) throws Exception {
+    private void runCreateIndexJob(IHyracksClientConnection hcc, CreateIndexStatement stmtCreateIndex) throws Exception {
         JobSpecification spec = null;
         switch (stmtCreateIndex.getIndexType()) {
             case BTREE: {
-                spec = IndexOperations.createBtreeIndexJobSpec(stmtCreateIndex.getDatasetName().getValue(),
+                spec = IndexOperations.buildBtreeCreationJobSpec(stmtCreateIndex.getDatasetName().getValue(),
                         stmtCreateIndex.getIndexName().getValue(), stmtCreateIndex.getFieldExprs(),
                         compiledDeclarations);
                 break;
             }
             case RTREE: {
-                spec = IndexOperations.createRtreeIndexJobSpec(stmtCreateIndex.getDatasetName().getValue(),
+                spec = IndexOperations.buildRtreeCreationJobSpec(stmtCreateIndex.getDatasetName().getValue(),
                         stmtCreateIndex.getIndexName().getValue(), stmtCreateIndex.getFieldExprs(),
                         compiledDeclarations);
                 break;
@@ -504,9 +504,13 @@
                         + stmtCreateIndex.getIndexType());
             }
         }
-        if (spec != null) {
-            runJob(hcc, spec);
-        }
+		if (spec == null) {
+			throw new AsterixException(
+					"Failed to create job spec for creating index '"
+							+ stmtCreateIndex.getDatasetName() + "."
+							+ stmtCreateIndex.getIndexName() + "'");
+		}
+		runJob(hcc, spec);
     }
 	
     private void compileDatasetDropStatement(IHyracksClientConnection hcc, MetadataTransactionContext mdTxnCtx,
@@ -529,7 +533,7 @@
     private void compileIndexDropStatement(IHyracksClientConnection hcc, MetadataTransactionContext mdTxnCtx,
             String datasetName, String indexName) throws Exception {
         CompiledIndexDropStatement cds = new CompiledIndexDropStatement(datasetName, indexName);
-        runJob(hcc, IndexOperations.createSecondaryIndexDropJobSpec(cds, compiledDeclarations));
+        runJob(hcc, IndexOperations.buildDropSecondaryIndexJobSpec(cds, compiledDeclarations));
         MetadataManager.INSTANCE.dropIndex(mdTxnCtx, compiledDeclarations.getDataverseName(), datasetName, indexName);
     }
 
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
index 13a3fdf..b1ea9af 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
@@ -69,20 +69,20 @@
     private static final PhysicalOptimizationConfig physicalOptimizationConfig = OptimizationConfUtil
             .getPhysicalOptimizationConfig();
 
-    public static JobSpecification buildCreateIndexJobSpec(CompiledCreateIndexStatement createIndexStmt,
+    public static JobSpecification buildSecondaryIndexLoadingJobSpec(CompiledCreateIndexStatement createIndexStmt,
             AqlCompiledMetadataDeclarations datasetDecls) throws AsterixException, AlgebricksException {
 
         switch (createIndexStmt.getIndexType()) {
             case BTREE: {
-                return loadBtreeIndexJobSpec(createIndexStmt, datasetDecls);
+                return buildBtreeLoadingJobSpec(createIndexStmt, datasetDecls);
             }
 
             case RTREE: {
-                return loadRtreeIndexJobSpec(createIndexStmt, datasetDecls);
+                return buildRtreeLoadingJobSpec(createIndexStmt, datasetDecls);
             }
 
             case KEYWORD: {
-                return loadKeywordIndexJobSpec(createIndexStmt, datasetDecls);
+                return buildInvertedIndexLoadingJobSpec(createIndexStmt, datasetDecls);
             }
 
             case QGRAM: {
@@ -97,7 +97,7 @@
         }
     }
     
-    public static JobSpecification createSecondaryIndexDropJobSpec(CompiledIndexDropStatement deleteStmt,
+    public static JobSpecification buildDropSecondaryIndexJobSpec(CompiledIndexDropStatement deleteStmt,
             AqlCompiledMetadataDeclarations datasetDecls) throws AlgebricksException, MetadataException {
         String datasetName = deleteStmt.getDatasetName();
         String indexName = deleteStmt.getIndexName();
@@ -118,7 +118,7 @@
     }
 
     // TODO: Lots of common code in this file. Refactor everything after merging in asterix-fix-issue-9.
-    public static JobSpecification createBtreeIndexJobSpec(String datasetName, String secondaryIndexName, List<String> secondaryKeyFields,
+    public static JobSpecification buildBtreeCreationJobSpec(String datasetName, String secondaryIndexName, List<String> secondaryKeyFields,
             AqlCompiledMetadataDeclarations metadata) throws AsterixException, AlgebricksException {
         JobSpecification spec = new JobSpecification();
 
@@ -179,7 +179,7 @@
     }
     
     @SuppressWarnings("unchecked")
-    public static JobSpecification loadBtreeIndexJobSpec(CompiledCreateIndexStatement createIndexStmt,
+    public static JobSpecification buildBtreeLoadingJobSpec(CompiledCreateIndexStatement createIndexStmt,
             AqlCompiledMetadataDeclarations metadata) throws AsterixException, AlgebricksException {
 
         JobSpecification spec = new JobSpecification();
@@ -382,7 +382,7 @@
     }
 
     // TODO: Lots of common code in this file. Refactor everything after merging in asterix-fix-issue-9.
-    public static JobSpecification createRtreeIndexJobSpec(String datasetName, String secondaryIndexName, List<String> secondaryKeyFields,
+    public static JobSpecification buildRtreeCreationJobSpec(String datasetName, String secondaryIndexName, List<String> secondaryKeyFields,
             AqlCompiledMetadataDeclarations metadata) throws AsterixException, AlgebricksException {
         JobSpecification spec = new JobSpecification();
         String primaryIndexName = datasetName;
@@ -451,7 +451,7 @@
     }
     
     @SuppressWarnings("unchecked")
-    public static JobSpecification loadRtreeIndexJobSpec(CompiledCreateIndexStatement createIndexStmt,
+    public static JobSpecification buildRtreeLoadingJobSpec(CompiledCreateIndexStatement createIndexStmt,
             AqlCompiledMetadataDeclarations metadata) throws AsterixException, AlgebricksException {
 
         JobSpecification spec = new JobSpecification();
@@ -658,7 +658,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    public static JobSpecification loadKeywordIndexJobSpec(CompiledCreateIndexStatement createIndexStmt,
+    public static JobSpecification buildInvertedIndexLoadingJobSpec(CompiledCreateIndexStatement createIndexStmt,
             AqlCompiledMetadataDeclarations datasetDecls) throws AsterixException, AlgebricksException {
 
         JobSpecification spec = new JobSpecification();
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/utils/DatasetUtils.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/utils/DatasetUtils.java
index 3a21bda..b7f0f75 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/utils/DatasetUtils.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/utils/DatasetUtils.java
@@ -12,7 +12,6 @@
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder.OrderKind;
 import edu.uci.ics.hyracks.algebricks.data.IBinaryComparatorFactoryProvider;
 import edu.uci.ics.hyracks.algebricks.data.IBinaryHashFunctionFactoryProvider;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IEvaluatorFactory;