Addressed code review comments.
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
index 0540417..cc8c45c 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
@@ -519,6 +519,8 @@
String datasetName = null;
String indexName = null;
Dataset ds = null;
+ Index index = null;
+ JobSpecification spec = null;
try {
CreateIndexStatement stmtCreateIndex = (CreateIndexStatement) stmt;
dataverseName = stmtCreateIndex.getDataverseName() == null ? activeDefaultDataverse == null ? null
@@ -550,7 +552,7 @@
}
//#. add a new index with PendingAddOp
- Index index = new Index(dataverseName, datasetName, indexName, stmtCreateIndex.getIndexType(),
+ index = new Index(dataverseName, datasetName, indexName, stmtCreateIndex.getIndexType(),
stmtCreateIndex.getFieldExprs(), stmtCreateIndex.getGramLength(), false,
IMetadataEntity.PENDING_ADD_OP);
MetadataManager.INSTANCE.addIndex(metadataProvider.getMetadataTxnContext(), index);
@@ -558,7 +560,7 @@
//#. create the index artifact in NC.
CompiledCreateIndexStatement cis = new CompiledCreateIndexStatement(index.getIndexName(), dataverseName,
index.getDatasetName(), index.getKeyFieldNames(), index.getGramLength(), index.getIndexType());
- JobSpecification spec = IndexOperations.buildSecondaryIndexCreationJobSpec(cis, metadataProvider);
+ spec = IndexOperations.buildSecondaryIndexCreationJobSpec(cis, metadataProvider);
if (spec == null) {
throw new AsterixException("Failed to create job spec for creating index '"
+ stmtCreateIndex.getDatasetName() + "." + stmtCreateIndex.getIndexName() + "'");
@@ -600,7 +602,7 @@
MetadataManager.INSTANCE.abortTransaction(mdTxnCtx);
}
- if (ds != null) {
+ if (ds != null && index != null && spec != null) {
//#. execute compensation operations
// remove the index in NC
mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
diff --git a/asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error/issue_272_create_index_error.1.ddl.aql b/asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error_1/issue_272_create_index_error_1.1.ddl.aql
similarity index 67%
rename from asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error/issue_272_create_index_error.1.ddl.aql
rename to asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error_1/issue_272_create_index_error_1.1.ddl.aql
index f35a83e..6ba4d86 100644
--- a/asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error/issue_272_create_index_error.1.ddl.aql
+++ b/asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error_1/issue_272_create_index_error_1.1.ddl.aql
@@ -9,13 +9,5 @@
create dataverse test;
use dataverse test;
-
-create type TestType as open {
- id: int32,
- name: string,
- loc: point
-}
-
-create dataset TestDS(TestType) primary key id;
create index loc_index on Foo(name);
diff --git a/asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error_2/issue_272_create_index_error_2.1.ddl.aql b/asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error_2/issue_272_create_index_error_2.1.ddl.aql
new file mode 100644
index 0000000..a1f9771
--- /dev/null
+++ b/asterix-app/src/test/resources/metadata/queries/exception/issue_272_create_index_error_2/issue_272_create_index_error_2.1.ddl.aql
@@ -0,0 +1,14 @@
+/*
+ * Description : create an index on a non-existent dataset
+ * Expected Res : Failure
+ * Date : 14 April 2013
+ * Issue : 272
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create index loc_index if not exists on Foo(name);
+
diff --git a/asterix-app/src/test/resources/metadata/testsuite.xml b/asterix-app/src/test/resources/metadata/testsuite.xml
index a2aac74..17d7bf2 100644
--- a/asterix-app/src/test/resources/metadata/testsuite.xml
+++ b/asterix-app/src/test/resources/metadata/testsuite.xml
@@ -213,9 +213,15 @@
</compilation-unit>
</test-case>
<test-case FilePath="exception">
- <compilation-unit name="issue_272_create_index_error">
+ <compilation-unit name="issue_272_create_index_error_1">
<output-dir compare="Text">none</output-dir>
- <expected-error>AlgebricksException</expected-error>
+ <expected-error>edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException</expected-error>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="exception">
+ <compilation-unit name="issue_272_create_index_error_2">
+ <output-dir compare="Text">none</output-dir>
+ <expected-error>edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException</expected-error>
</compilation-unit>
</test-case>
</test-group>
@@ -239,4 +245,4 @@
</compilation-unit>
</test-case>
</test-group>
-</test-suite>
+</test-suite>
\ No newline at end of file