abdullah alamoudi has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/1098
Change subject: Add Record Literal and Byte Array Value Reference
......................................................................
Add Record Literal and Byte Array Value Reference
This change include 3 different parts:
1. It introduced record literals in order to enable the use of
constant records as function input.
2. It introduces ByteArrayValueReference which is a mutable
reference that can be wrapped around byte[].
3. It improves the Schemaless record serializer deserializer.
Change-Id: I25c5054a361128a3bee4241d7b9b40da7e61373f
---
M
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ConstantHelper.java
M
asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Literal.java
A
asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/literal/RecordLiteral.java
M
asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java
M
asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
M
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/ConstantExpressionUtil.java
A
hyracks-fullstack/hyracks/hyracks-dataflow-common/src/main/java/org/apache/hyracks/dataflow/common/data/accessors/ByteArrayValueReference.java
7 files changed, 137 insertions(+), 8 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/98/1098/1
diff --git
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ConstantHelper.java
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ConstantHelper.java
index 8ded10b..51861cb 100644
---
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ConstantHelper.java
+++
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/ConstantHelper.java
@@ -23,6 +23,7 @@
import org.apache.asterix.lang.common.literal.FloatLiteral;
import org.apache.asterix.lang.common.literal.IntegerLiteral;
import org.apache.asterix.lang.common.literal.LongIntegerLiteral;
+import org.apache.asterix.lang.common.literal.RecordLiteral;
import org.apache.asterix.lang.common.literal.StringLiteral;
import org.apache.asterix.om.base.ABoolean;
import org.apache.asterix.om.base.ADouble;
@@ -31,6 +32,7 @@
import org.apache.asterix.om.base.AInt64;
import org.apache.asterix.om.base.AMissing;
import org.apache.asterix.om.base.ANull;
+import org.apache.asterix.om.base.ARecord;
import org.apache.asterix.om.base.AString;
import org.apache.asterix.om.base.IAObject;
@@ -61,6 +63,8 @@
return new AString(sl.getValue());
case TRUE:
return ABoolean.TRUE;
+ case RECORD:
+ return (ARecord) ((RecordLiteral) valLiteral).getValue();
default:
throw new IllegalStateException();
}
diff --git
a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Literal.java
b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Literal.java
index 1ca8ac4..ede8689 100644
---
a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Literal.java
+++
b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Literal.java
@@ -35,7 +35,8 @@
FALSE,
FLOAT,
DOUBLE,
- LONG
+ LONG,
+ RECORD
}
abstract public Object getValue();
diff --git
a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/literal/RecordLiteral.java
b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/literal/RecordLiteral.java
new file mode 100644
index 0000000..59eb144
--- /dev/null
+++
b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/literal/RecordLiteral.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.asterix.lang.common.literal;
+
+import org.apache.asterix.lang.common.base.Literal;
+import org.apache.asterix.om.base.ARecord;
+
+public class RecordLiteral extends Literal {
+
+ private static final long serialVersionUID = 1L;
+ private final ARecord record;
+
+ public RecordLiteral(ARecord record) {
+ this.record = record;
+ }
+
+ @Override
+ public Object getValue() {
+ return record;
+ }
+
+ @Override
+ public Type getLiteralType() {
+ return Type.RECORD;
+ }
+
+}
diff --git
a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java
b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java
index 94144c6..a604315 100644
---
a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java
+++
b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/LangRecordParseUtil.java
@@ -68,7 +68,7 @@
parseLiteral((LiteralExpr) expr, serialized);
break;
case RECORD_CONSTRUCTOR_EXPRESSION:
- parseRecord((RecordConstructor) expr, serialized);
+ parseRecord((RecordConstructor) expr, serialized, true);
break;
case LIST_CONSTRUCTOR_EXPRESSION:
parseList((ListConstructor) expr, serialized);
@@ -82,7 +82,7 @@
}
}
- public static void parseRecord(RecordConstructor recordValue,
ArrayBackedValueStorage serialized)
+ public static void parseRecord(RecordConstructor recordValue,
ArrayBackedValueStorage serialized, boolean tagged)
throws HyracksDataException {
AMutableString fieldNameString = new AMutableString(null);
ArrayBackedValueStorage fieldName = new ArrayBackedValueStorage();
@@ -112,7 +112,7 @@
parseExpression(fb.getRightExpr(), fieldValue);
recordBuilder.addField(fieldName, fieldValue);
}
- recordBuilder.write(serialized.getDataOutput(), true);
+ recordBuilder.write(serialized.getDataOutput(), tagged);
}
private static void parseList(ListConstructor valueExpr,
ArrayBackedValueStorage serialized)
diff --git
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
index c922054..c69c89e 100644
---
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
+++
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.asterix.dataflow.data.nontagged.serde;
import java.io.DataInput;
@@ -32,13 +31,14 @@
import org.apache.asterix.om.base.AMissing;
import org.apache.asterix.om.base.ANull;
import org.apache.asterix.om.base.ARecord;
+import org.apache.asterix.om.base.AString;
import org.apache.asterix.om.base.IAObject;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.ATypeTag;
import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.util.NonTaggedFormatUtil;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
import org.apache.hyracks.api.dataflow.value.IBinaryHashFunction;
import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
@@ -153,7 +153,7 @@
IAObject[] mergedFields = mergeFields(closedFields,
openFields);
return new ARecord(mergedRecordType, mergedFields);
} else {
- return new ARecord(this.recordType, openFields);
+ return new ARecord(openPartRecType, openFields);
}
} else {
return new ARecord(this.recordType, closedFields);
@@ -184,10 +184,32 @@
}
recordBuilder.write(out, writeTypeTag);
} else {
- throw new NotImplementedException("Serializer for schemaless
records is not implemented.");
+ serializeSchemalessRecord(instance, out, writeTypeTag);
}
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static void serializeSchemalessRecord(ARecord record, DataOutput
dataOutput, boolean writeTypeTag)
+ throws HyracksDataException {
+ ISerializerDeserializer<AString> stringSerde =
AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ASTRING);
+ RecordBuilder confRecordBuilder = new RecordBuilder();
+ confRecordBuilder.reset(ARecordType.FULLY_OPEN_RECORD_TYPE);
+ ArrayBackedValueStorage fieldNameBytes = new ArrayBackedValueStorage();
+ ArrayBackedValueStorage fieldValueBytes = new
ArrayBackedValueStorage();
+ for (int i = 0; i < record.getType().getFieldNames().length; i++) {
+ String fieldName = record.getType().getFieldNames()[i];
+ fieldValueBytes.reset();
+ fieldNameBytes.reset();
+ stringSerde.serialize(new AString(fieldName),
fieldNameBytes.getDataOutput());
+ ISerializerDeserializer valueSerde =
AqlSerializerDeserializerProvider.INSTANCE
+
.getSerializerDeserializer(record.getType().getFieldTypes()[i]);
+ valueSerde.serialize(record.getValueByPos(i),
fieldValueBytes.getDataOutput());
+ confRecordBuilder.addField(fieldNameBytes, fieldValueBytes);
+ }
+ confRecordBuilder.write(dataOutput, writeTypeTag);
+ }
+
private IAObject[] mergeFields(IAObject[] closedFields, IAObject[]
openFields) {
IAObject[] fields = new IAObject[closedFields.length +
openFields.length];
int i = 0;
diff --git
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/ConstantExpressionUtil.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/ConstantExpressionUtil.java
index c67030a..f6f88bb 100644
---
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/ConstantExpressionUtil.java
+++
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/util/ConstantExpressionUtil.java
@@ -21,6 +21,7 @@
import org.apache.asterix.om.base.ABoolean;
import org.apache.asterix.om.base.AInt32;
import org.apache.asterix.om.base.AInt64;
+import org.apache.asterix.om.base.ARecord;
import org.apache.asterix.om.base.AString;
import org.apache.asterix.om.base.IAObject;
import org.apache.asterix.om.constants.AsterixConstantValue;
@@ -76,6 +77,10 @@
return getStringConstant(f.getArguments().get(index).getValue());
}
+ public static ARecord getRecordArgument(AbstractFunctionCallExpression f,
int index) {
+ return (ARecord)
getConstantIaObject(f.getArguments().get(index).getValue(), ATypeTag.RECORD);
+ }
+
public static Integer getIntArgument(ILogicalExpression expr, int index) {
return expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL
? getIntArgument((AbstractFunctionCallExpression) expr, index)
: null;
diff --git
a/hyracks-fullstack/hyracks/hyracks-dataflow-common/src/main/java/org/apache/hyracks/dataflow/common/data/accessors/ByteArrayValueReference.java
b/hyracks-fullstack/hyracks/hyracks-dataflow-common/src/main/java/org/apache/hyracks/dataflow/common/data/accessors/ByteArrayValueReference.java
new file mode 100644
index 0000000..564f445
--- /dev/null
+++
b/hyracks-fullstack/hyracks/hyracks-dataflow-common/src/main/java/org/apache/hyracks/dataflow/common/data/accessors/ByteArrayValueReference.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.dataflow.common.data.accessors;
+
+import org.apache.hyracks.data.std.api.IValueReference;
+
+public class ByteArrayValueReference implements IValueReference {
+
+ private byte[] bytes;
+
+ public ByteArrayValueReference(byte[] bytes) {
+ this.setBytes(bytes);
+ }
+
+ @Override
+ public byte[] getByteArray() {
+ return getBytes();
+ }
+
+ @Override
+ public int getStartOffset() {
+ return 0;
+ }
+
+ @Override
+ public int getLength() {
+ return getBytes().length;
+ }
+
+ public byte[] getBytes() {
+ return bytes;
+ }
+
+ public void setBytes(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+}
--
To view, visit https://asterix-gerrit.ics.uci.edu/1098
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I25c5054a361128a3bee4241d7b9b40da7e61373f
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: abdullah alamoudi <[email protected]>