1. fix a open type access issue, 2. add one more tests
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_opentype@273 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/runtimets/queries/dml/opentype-o2o.aql b/asterix-app/src/test/resources/runtimets/queries/dml/opentype-o2o.aql
new file mode 100644
index 0000000..b2f6d14
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/dml/opentype-o2o.aql
@@ -0,0 +1,45 @@
+drop dataverse testdv2 if exists;
+create dataverse testdv2;
+use dataverse testdv2;
+
+create type testtype as open {
+ id: string,
+ name: string
+}
+
+create type testtype2 as open {
+ id: string,
+ name: string,
+ hobby: string
+}
+
+create dataset testds(testtype) partitioned by key id;
+
+create dataset testds2(testtype2) partitioned by key id;
+
+insert into dataset testds (
+{ "id": "001", "name": "Person Three", "hobby": "music"}
+);
+
+insert into dataset testds (
+{ "id": "002", "name": "Person Three", "hobby": "football", "city":"irvine"}
+);
+
+insert into dataset testds (
+{ "id": "003", "name": "Person Three", "hobby": "movie"}
+);
+
+insert into dataset testds (
+{ "id": "004", "name": "Person Three", "hobby": "swimming", "phone":"102-304-506"}
+);
+
+insert into dataset testds2 (
+ for $d in dataset("testds")
+ return $d
+);
+
+write output to nc1:"rttest/dml_opentype-o2o.adm";
+
+for $d in dataset("testds2")
+order by $d.id
+return $d
diff --git a/asterix-app/src/test/resources/runtimets/results/dml/opentype-o2o.adm b/asterix-app/src/test/resources/runtimets/results/dml/opentype-o2o.adm
new file mode 100644
index 0000000..f5a5985
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/dml/opentype-o2o.adm
@@ -0,0 +1,4 @@
+{ "id": "001", "name": "Person Three", "hobby": "music" }
+{ "id": "002", "name": "Person Three", "hobby": "football", "city": "irvine" }
+{ "id": "003", "name": "Person Three", "hobby": "movie" }
+{ "id": "004", "name": "Person Three", "hobby": "swimming", "phone": "102-304-506" }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/ARecordAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/ARecordAccessor.java
index f02ecee..9a048f5 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/ARecordAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/ARecordAccessor.java
@@ -37,7 +37,7 @@
private int offsetArrayOffset;
private int[] fieldOffsets;
private int fieldCursor = -1;
- private ATypeTag typeTag = ATypeTag.ANY;
+ private ATypeTag typeTag;
private SimpleValueReference nullReference = new SimpleValueReference();
private byte[] data;
@@ -149,24 +149,23 @@
}
}
IAType[] fieldTypes = inputRecType.getFieldTypes();
- ATypeTag tag = ATypeTag.ANY;
int fieldValueLength = 0;
if (fieldTypes[fieldNumber].getTypeTag() == ATypeTag.UNION) {
if (NonTaggedFormatUtil.isOptionalField((AUnionType) fieldTypes[fieldNumber])) {
- tag = ((AUnionType) fieldTypes[fieldNumber]).getUnionList()
+ typeTag = ((AUnionType) fieldTypes[fieldNumber]).getUnionList()
.get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST).getTypeTag();
fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffsets[fieldNumber],
- tag, false);
+ typeTag, false);
}
} else {
- tag = fieldTypes[fieldNumber].getTypeTag();
- fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffsets[fieldNumber], tag,
- false);
+ typeTag = fieldTypes[fieldNumber].getTypeTag();
+ fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffsets[fieldNumber],
+ typeTag, false);
}
// set field value (including the type tag)
int fstart = dataBos.size();
- dataDos.writeByte(tag.serialize());
+ dataDos.writeByte(typeTag.serialize());
dataDos.write(b, fieldOffsets[fieldNumber], fieldValueLength);
int fend = dataBos.size();
nextFieldValue().reset(dataBuffer, fstart, fend - fstart);
@@ -193,7 +192,7 @@
typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(b[fieldOffset]);
// set the field value (already including type tag)
- fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffset, typeTag, true);
+ fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffset, typeTag, true) + 1;
nextFieldValue().reset(b, fieldOffset, fieldValueLength);
fieldOffset += fieldValueLength;
}