fixed bug in open-closed fieldname conflict check; added test cases for open-open, open-closed, and closed-closed conflicts

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_issue_173@1212 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/runtimets/queries/records/closed-closed-fieldname-conflict_issue173.aql b/asterix-app/src/test/resources/runtimets/queries/records/closed-closed-fieldname-conflict_issue173.aql
new file mode 100644
index 0000000..6963f23
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/records/closed-closed-fieldname-conflict_issue173.aql
@@ -0,0 +1,6 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+let $x := {"name": "john", "name": "smith"}
+return $x
diff --git a/asterix-app/src/test/resources/runtimets/queries/records/open-closed-fieldname-conflict_issue173.aql b/asterix-app/src/test/resources/runtimets/queries/records/open-closed-fieldname-conflict_issue173.aql
new file mode 100644
index 0000000..5457bea
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/records/open-closed-fieldname-conflict_issue173.aql
@@ -0,0 +1,15 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type opentype as open {
+id:int32,
+fname:string
+}
+
+create dataset testds(opentype) primary key id; 
+
+insert into dataset testds({'id': 1, 'fname': "name"});
+
+for $x in dataset('testds')
+return {$x.fname: "smith", lowercase("NAME"): "john"}
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/records/open-open-fieldname-conflict_issue173.aql b/asterix-app/src/test/resources/runtimets/queries/records/open-open-fieldname-conflict_issue173.aql
new file mode 100644
index 0000000..391e9b0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/records/open-open-fieldname-conflict_issue173.aql
@@ -0,0 +1,15 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type opentype as open {
+fname1: string,
+fname2: string
+}
+
+create dataset testds(opentype) primary key fname1; 
+
+insert into dataset testds({'fname1': "name", 'fname2': "name"});
+
+for $x in dataset('testds')
+return {$x.fname1: "john", $x.fname2: "smith"}
\ 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 6956e4b..de694cd 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -2626,6 +2626,24 @@
         <output-file compare="Text">open-record-constructor_02.adm</output-file>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="records">
+      <compilation-unit name="closed-closed-fieldname-conflict_issue173">
+        <output-file compare="Text">closed-closed-fieldname-conflict_issue173.adm</output-file>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
+  <test-case FilePath="records">
+      <compilation-unit name="open-closed-fieldname-conflict_issue173">
+        <output-file compare="Text">open-closed-fieldname-conflict_issue173.adm</output-file>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="records">
+      <compilation-unit name="open-open-fieldname-conflict_issue173">
+        <output-file compare="Text">open-open-fieldname-conflict_issue173.adm</output-file>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="scan">
     <test-case FilePath="scan">
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/builders/RecordBuilder.java b/asterix-om/src/main/java/edu/uci/ics/asterix/builders/RecordBuilder.java
index 2442634..1530f97 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/builders/RecordBuilder.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/builders/RecordBuilder.java
@@ -151,9 +151,9 @@
         if (recType != null) {
             int cFieldPos = recType.findFieldPosition(name.getByteArray(), name.getStartOffset() + 1,
                     name.getLength() - 1);
-            if (cFieldPos > 0) {
-                throw new AsterixException("Open field has the same field name as closed field " + cFieldPos + " \""
-                        + recType.getFieldNames()[cFieldPos] + "\"");
+            if (cFieldPos >= 0) {
+                throw new AsterixException("Open field \"" + recType.getFieldNames()[cFieldPos]
+                        + "\" has the same field name as closed field at index " + cFieldPos);
             }
         }
         openPartOffsets[this.numberOfOpenFields] = fieldNameHashCode;