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 a216242..b54ea38 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
@@ -406,12 +406,8 @@
}
List<String> partitioningExprs = ((InternalDetailsDecl) dd.getDatasetDetailsDecl())
.getPartitioningExprs();
- for (String s : partitioningExprs) {
- ARecordType aRecordType = (ARecordType) itemType;
- if (!aRecordType.doesFieldExist(s)) {
- throw new AlgebricksException("A field with this name " + s + " could not be found.");
- }
- }
+ ARecordType aRecordType = (ARecordType) itemType;
+ aRecordType.validateParitioningExpression(partitioningExprs);
String ngName = ((InternalDetailsDecl) dd.getDatasetDetailsDecl()).getNodegroupName().getValue();
datasetDetails = new InternalDatasetDetails(InternalDatasetDetails.FileStructure.BTREE,
InternalDatasetDetails.PartitioningStrategy.HASH, partitioningExprs, partitioningExprs,
@@ -431,12 +427,8 @@
}
List<String> partitioningExprs = ((FeedDetailsDecl) dd.getDatasetDetailsDecl())
.getPartitioningExprs();
- for (String s : partitioningExprs) {
- ARecordType aRecordType = (ARecordType) itemType;
- if (!aRecordType.doesFieldExist(s)) {
- throw new AlgebricksException("A field with this name " + s + " could not be found.");
- }
- }
+ ARecordType aRecordType = (ARecordType) itemType;
+ aRecordType.validateParitioningExpression(partitioningExprs);
String ngName = ((FeedDetailsDecl) dd.getDatasetDetailsDecl()).getNodegroupName().getValue();
String adapter = ((FeedDetailsDecl) dd.getDatasetDetailsDecl()).getAdapterFactoryClassname();
Map<String, String> configuration = ((FeedDetailsDecl) dd.getDatasetDetailsDecl())
diff --git a/asterix-app/src/test/resources/metadata/queries/exception/issue_255_create_dataset_error/issue_255_create_dataset_error.1.ddl.aql b/asterix-app/src/test/resources/metadata/queries/exception/issue_255_create_dataset_error_1/issue_255_create_dataset_error_1.1.ddl.aql
similarity index 100%
rename from asterix-app/src/test/resources/metadata/queries/exception/issue_255_create_dataset_error/issue_255_create_dataset_error.1.ddl.aql
rename to asterix-app/src/test/resources/metadata/queries/exception/issue_255_create_dataset_error_1/issue_255_create_dataset_error_1.1.ddl.aql
diff --git a/asterix-app/src/test/resources/metadata/queries/exception/issue_255_create_dataset_error_2/issue_255_create_dataset_error_2.1.ddl.aql b/asterix-app/src/test/resources/metadata/queries/exception/issue_255_create_dataset_error_2/issue_255_create_dataset_error_2.1.ddl.aql
new file mode 100644
index 0000000..add51df
--- /dev/null
+++ b/asterix-app/src/test/resources/metadata/queries/exception/issue_255_create_dataset_error_2/issue_255_create_dataset_error_2.1.ddl.aql
@@ -0,0 +1,21 @@
+/*
+ * Description : create a dataset partitioned on ARecord type
+ * Expected Res : Failure
+ * Date : 14 April 2013
+ * Issue : 272
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type opentype1 as open {
+id:int32
+}
+
+create type opentype2 as open {
+id:int32,
+open-type:opentype1
+}
+
+create dataset testds(opentype2) primary key open-type;
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/metadata/testsuite.xml b/asterix-app/src/test/resources/metadata/testsuite.xml
index 2a4eaa8..c5277ce 100644
--- a/asterix-app/src/test/resources/metadata/testsuite.xml
+++ b/asterix-app/src/test/resources/metadata/testsuite.xml
@@ -213,7 +213,13 @@
</compilation-unit>
</test-case>
<test-case FilePath="exception">
- <compilation-unit name="issue_255_create_dataset_error">
+ <compilation-unit name="issue_255_create_dataset_error_1">
+ <output-dir compare="Text">none</output-dir>
+ <expected-error>edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException</expected-error>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="exception">
+ <compilation-unit name="issue_255_create_dataset_error_2">
<output-dir compare="Text">none</output-dir>
<expected-error>edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException</expected-error>
</compilation-unit>
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
index 8625032..a63764f 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
@@ -30,6 +30,7 @@
import edu.uci.ics.asterix.common.exceptions.AsterixException;
import edu.uci.ics.asterix.om.base.IAObject;
import edu.uci.ics.asterix.om.visitors.IOMVisitor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
import edu.uci.ics.hyracks.api.dataflow.value.IBinaryHashFunction;
import edu.uci.ics.hyracks.data.std.accessors.PointableBinaryComparatorFactory;
@@ -238,6 +239,17 @@
return findFieldPosition(fieldName) != -1;
}
+ public void validateParitioningExpression(List<String> partitioningExprs) throws AlgebricksException, IOException {
+ for (String fieldName : partitioningExprs) {
+ if (getFieldType(fieldName) == null) {
+ throw new AlgebricksException("A field with this name \"" + fieldName + "\" could not be found.");
+ } else if (getFieldType(fieldName).getTypeTag() == ATypeTag.RECORD) {
+ throw new AlgebricksException("The partitioning key \"" + fieldName + "\" cannot be of type "
+ + ATypeTag.RECORD + ".");
+ }
+ }
+ }
+
public boolean doesFieldExist(String fieldName) {
for (String f : fieldNames) {
if (f.compareTo(fieldName) == 0) {