[NO ISSUE][OTH] Make IAType IJsonSerializable
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
This change is to make Asterix types IJsonSerializable.
Change-Id: I26b57494da1c63497b63ceb0d4172b5768d3a614
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3228
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/io/PersistedResourceRegistry.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/io/PersistedResourceRegistry.java
index d4c217b..11d1b26 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/io/PersistedResourceRegistry.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/io/PersistedResourceRegistry.java
@@ -59,6 +59,11 @@
import org.apache.asterix.om.pointables.nonvisitor.AIntervalPointable;
import org.apache.asterix.om.pointables.nonvisitor.AListPointable;
import org.apache.asterix.om.pointables.nonvisitor.ARecordPointable;
+import org.apache.asterix.om.types.AOrderedListType;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.AUnorderedListType;
+import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.runtime.compression.CompressionManager;
import org.apache.asterix.runtime.utils.RuntimeComponentsProvider;
import org.apache.asterix.transaction.management.opcallbacks.PrimaryIndexOperationTrackerFactory;
@@ -250,6 +255,13 @@
REGISTERED_CLASSES.put("UTF8WordTokenFactory", UTF8WordTokenFactory.class);
REGISTERED_CLASSES.put("RTreePolicyType", RTreePolicyType.class);
+ // IAType
+ REGISTERED_CLASSES.put("BuiltinType", BuiltinType.class);
+ REGISTERED_CLASSES.put("AOrderedListType", AOrderedListType.class);
+ REGISTERED_CLASSES.put("ARecordType", ARecordType.class);
+ REGISTERED_CLASSES.put("AUnionType", AUnionType.class);
+ REGISTERED_CLASSES.put("AUnorderedListType", AUnorderedListType.class);
+
//ICompressorDecompressorFactory
CompressionManager.registerCompressorDecompressorsFactoryClasses(REGISTERED_CLASSES);
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AOrderedListType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AOrderedListType.java
index 7cb383f..097b4a7 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AOrderedListType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AOrderedListType.java
@@ -19,7 +19,11 @@
package org.apache.asterix.om.types;
import org.apache.asterix.om.base.IAObject;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.IJsonSerializable;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -84,4 +88,14 @@
type.set("item-type", itemType.toJSON());
return type;
}
+
+ @Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) throws HyracksDataException {
+ return convertToJson(registry, getClass(), serialVersionUID);
+ }
+
+ public static IJsonSerializable fromJson(IPersistedResourceRegistry registry, JsonNode json)
+ throws HyracksDataException {
+ return convertToObject(registry, json, true);
+ }
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
index 1c04986..b91b4ae 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
@@ -33,7 +33,12 @@
import org.apache.asterix.om.base.IAObject;
import org.apache.asterix.om.utils.NonTaggedFormatUtil;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.IJsonSerializable;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -47,6 +52,11 @@
public class ARecordType extends AbstractComplexType {
private static final long serialVersionUID = 1L;
+ private static final JavaType SET = OBJECT_MAPPER.getTypeFactory().constructCollectionType(Set.class, String.class);
+ private static final String IS_OPEN = "isOpen";
+ private static final String FIELD_NAMES = "fieldNames";
+ private static final String FIELD_TYPES = "fieldTypes";
+ private static final String ADDITIONAL_FIELDS = "additionalFieldNames";
private final String[] fieldNames;
private final IAType[] fieldTypes;
private final Map<String, Integer> fieldNameToIndexMap = new HashMap<>();
@@ -372,6 +382,35 @@
return type;
}
+ @Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) throws HyracksDataException {
+ final ObjectNode jsonObject = registry.getClassIdentifier(getClass(), serialVersionUID);
+ addToJson(jsonObject);
+ jsonObject.put(IS_OPEN, isOpen);
+ jsonObject.putPOJO(FIELD_NAMES, fieldNames);
+ jsonObject.putPOJO(ADDITIONAL_FIELDS, allPossibleAdditionalFieldNames);
+ ArrayNode fieldTypesArray = OBJECT_MAPPER.createArrayNode();
+ for (int i = 0; i < fieldTypes.length; i++) {
+ fieldTypesArray.add(fieldTypes[i].toJson(registry));
+ }
+ jsonObject.set(FIELD_TYPES, fieldTypesArray);
+ return jsonObject;
+ }
+
+ public static IJsonSerializable fromJson(IPersistedResourceRegistry registry, JsonNode json)
+ throws HyracksDataException {
+ String typeName = json.get(TYPE_NAME_FIELD).asText();
+ boolean isOpen = json.get(IS_OPEN).asBoolean();
+ String[] fieldNames = OBJECT_MAPPER.convertValue(json.get(FIELD_NAMES), String[].class);
+ Set<String> additionalFields = OBJECT_MAPPER.convertValue(json.get(ADDITIONAL_FIELDS), SET);
+ ArrayNode fieldTypesNode = (ArrayNode) json.get(FIELD_TYPES);
+ IAType[] fieldTypes = new IAType[fieldTypesNode.size()];
+ for (int i = 0; i < fieldTypesNode.size(); i++) {
+ fieldTypes[i] = (IAType) registry.deserialize(fieldTypesNode.get(i));
+ }
+ return new ARecordType(typeName, fieldNames, fieldTypes, isOpen, additionalFields);
+ }
+
public List<IAType> getFieldTypes(List<List<String>> fields) throws AlgebricksException {
List<IAType> typeList = new ArrayList<>();
for (List<String> field : fields) {
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnionType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnionType.java
index f8ae7f8..7ef18d4 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnionType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnionType.java
@@ -23,7 +23,11 @@
import java.util.List;
import org.apache.asterix.om.base.IAObject;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.IJsonSerializable;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -32,6 +36,7 @@
private static final long serialVersionUID = 1L;
private static final int OPTIONAL_TYPE_INDEX_IN_UNION_LIST = 0;
+ private static final String UNION_LIST_FIELD = "unionList";
private final List<IAType> unionList;
public AUnionType(List<IAType> unionList, String typeName) {
@@ -223,4 +228,27 @@
type.set("fields", fields);
return type;
}
+
+ @Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) throws HyracksDataException {
+ final ObjectNode jsonObject = registry.getClassIdentifier(getClass(), serialVersionUID);
+ addToJson(jsonObject);
+ ArrayNode fieldTypesArray = OBJECT_MAPPER.createArrayNode();
+ for (int i = 0; i < unionList.size(); i++) {
+ fieldTypesArray.add(unionList.get(i).toJson(registry));
+ }
+ jsonObject.set(UNION_LIST_FIELD, fieldTypesArray);
+ return jsonObject;
+ }
+
+ public static IJsonSerializable fromJson(IPersistedResourceRegistry registry, JsonNode json)
+ throws HyracksDataException {
+ String typeName = json.get(TYPE_NAME_FIELD).asText();
+ ArrayNode unionListJson = (ArrayNode) json.get(UNION_LIST_FIELD);
+ List<IAType> unionList = new ArrayList<>();
+ for (int i = 0; i < unionListJson.size(); i++) {
+ unionList.add((IAType) registry.deserialize(unionListJson.get(i)));
+ }
+ return new AUnionType(unionList, typeName);
+ }
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnorderedListType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnorderedListType.java
index 8d088f7..0b458dd 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnorderedListType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AUnorderedListType.java
@@ -19,7 +19,11 @@
package org.apache.asterix.om.types;
import org.apache.asterix.om.base.IAObject;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.IJsonSerializable;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -84,4 +88,14 @@
type.set("item-type", itemType.toJSON());
return type;
}
+
+ @Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) throws HyracksDataException {
+ return convertToJson(registry, getClass(), serialVersionUID);
+ }
+
+ public static IJsonSerializable fromJson(IPersistedResourceRegistry registry, JsonNode json)
+ throws HyracksDataException {
+ return convertToObject(registry, json, false);
+ }
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AbstractCollectionType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AbstractCollectionType.java
index f6f10f4..1b2b8fe 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AbstractCollectionType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AbstractCollectionType.java
@@ -18,10 +18,17 @@
*/
package org.apache.asterix.om.types;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.IJsonSerializable;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
public abstract class AbstractCollectionType extends AbstractComplexType {
private static final long serialVersionUID = 1L;
-
+ private static final String ITEM_TYPE_FIELD = "itemType";
protected IAType itemType;
AbstractCollectionType(IAType itemType, String typeName) {
@@ -59,4 +66,20 @@
public boolean containsType(IAType type) {
return isTyped() && itemType.getTypeName().equals(type.getTypeName());
}
+
+ protected JsonNode convertToJson(IPersistedResourceRegistry registry, Class<? extends IJsonSerializable> clazz,
+ long version) throws HyracksDataException {
+ final ObjectNode jsonObject = registry.getClassIdentifier(clazz, version);
+ addToJson(jsonObject);
+ jsonObject.set(ITEM_TYPE_FIELD, itemType.toJson(registry));
+ return jsonObject;
+ }
+
+ protected static IJsonSerializable convertToObject(IPersistedResourceRegistry registry, JsonNode json,
+ boolean ordered) throws HyracksDataException {
+ String typeName = json.get(TYPE_NAME_FIELD).asText();
+ JsonNode itemTypeJson = json.get(ITEM_TYPE_FIELD);
+ IAType itemType = (IAType) registry.deserialize(itemTypeJson);
+ return ordered ? new AOrderedListType(itemType, typeName) : new AUnorderedListType(itemType, typeName);
+ }
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AbstractComplexType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AbstractComplexType.java
index f8b1d60..16f83f5 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AbstractComplexType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/AbstractComplexType.java
@@ -20,9 +20,14 @@
import org.apache.asterix.om.base.IAObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
public abstract class AbstractComplexType implements IAType {
private static final long serialVersionUID = 1L;
+ protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+ protected static final String TYPE_NAME_FIELD = "typeName";
protected String typeName;
public AbstractComplexType(String typeName) {
@@ -45,5 +50,9 @@
return object instanceof IAObject && deepEqual((IAObject) object);
}
+ protected void addToJson(final ObjectNode json) {
+ json.put(TYPE_NAME_FIELD, typeName);
+ }
+
public abstract boolean containsType(IAType type);
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
index 2e48127..4fc146f 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/BuiltinType.java
@@ -18,14 +18,20 @@
*/
package org.apache.asterix.om.types;
-import org.apache.asterix.om.base.IAObject;
+import static org.apache.asterix.om.types.ATypeTag.VALUE_TYPE_MAPPING;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.hyracks.api.io.IJsonSerializable;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
public abstract class BuiltinType implements IAType {
private static final long serialVersionUID = 1L;
+ private static final String TAG_FIELD = "tag";
public abstract static class LowerCaseConstructorType extends BuiltinType {
private static final long serialVersionUID = 1L;
@@ -62,6 +68,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -90,6 +101,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -118,6 +134,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -146,6 +167,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -174,6 +200,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -202,6 +233,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -230,6 +266,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -258,6 +299,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -286,6 +332,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -314,6 +365,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -342,6 +398,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -370,6 +431,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -398,6 +464,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -426,6 +497,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -454,6 +530,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -482,6 +563,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -510,6 +596,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -538,6 +629,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -566,6 +662,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
return null;
}
@@ -591,6 +692,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -619,6 +725,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -647,6 +758,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -675,6 +791,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -703,6 +824,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectNode type = new ObjectMapper().createObjectNode();
type.put("type", "AGEOMETRY");
@@ -730,6 +856,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -758,6 +889,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -786,6 +922,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -813,6 +954,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -846,6 +992,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -879,6 +1030,11 @@
}
@Override
+ public JsonNode toJson(IPersistedResourceRegistry registry) {
+ return convertToJson(registry, getTypeTag().serialize(), serialVersionUID);
+ }
+
+ @Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode type = om.createObjectNode();
@@ -925,4 +1081,79 @@
return getType().getTypeTag().serialize();
}
+ private static JsonNode convertToJson(IPersistedResourceRegistry registry, short tag, long version) {
+ ObjectNode jsonNode = registry.getClassIdentifier(BuiltinType.class, version);
+ jsonNode.put(TAG_FIELD, tag);
+ return jsonNode;
+ }
+
+ @SuppressWarnings("squid:S1172") // unused parameter
+ public static IJsonSerializable fromJson(IPersistedResourceRegistry registry, JsonNode json) {
+ byte tag = (byte) json.get(TAG_FIELD).shortValue();
+ ATypeTag typeTag = VALUE_TYPE_MAPPING[tag];
+ switch (typeTag) {
+ case TYPE:
+ return ALL_TYPE;
+ case TINYINT:
+ return AINT8;
+ case SMALLINT:
+ return AINT16;
+ case INTEGER:
+ return AINT32;
+ case BIGINT:
+ return AINT64;
+ case FLOAT:
+ return AFLOAT;
+ case DOUBLE:
+ return ADOUBLE;
+ case STRING:
+ return ASTRING;
+ case BINARY:
+ return ABINARY;
+ case MISSING:
+ return AMISSING;
+ case NULL:
+ return ANULL;
+ case BOOLEAN:
+ return ABOOLEAN;
+ case TIME:
+ return ATIME;
+ case DATE:
+ return ADATE;
+ case DATETIME:
+ return ADATETIME;
+ case DURATION:
+ return ADURATION;
+ case YEARMONTHDURATION:
+ return AYEARMONTHDURATION;
+ case DAYTIMEDURATION:
+ return ADAYTIMEDURATION;
+ case INTERVAL:
+ return AINTERVAL;
+ case POINT:
+ return APOINT;
+ case POINT3D:
+ return APOINT3D;
+ case LINE:
+ return ALINE;
+ case POLYGON:
+ return APOLYGON;
+ case GEOMETRY:
+ return AGEOMETRY;
+ case CIRCLE:
+ return ACIRCLE;
+ case RECTANGLE:
+ return ARECTANGLE;
+ case BITARRAY:
+ return ABITARRAY;
+ case UUID:
+ return AUUID;
+ case ANY:
+ return ANY;
+ case SHORTWITHOUTTYPEINFO:
+ return SHORTWITHOUTTYPEINFO;
+ default:
+ throw new IllegalStateException();
+ }
+ }
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/IAType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/IAType.java
index aa9ce99..0e6cc4f 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/IAType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/IAType.java
@@ -21,8 +21,9 @@
import java.io.Serializable;
import org.apache.asterix.om.base.IAObject;
+import org.apache.hyracks.api.io.IJsonSerializable;
-public interface IAType extends IAObject, Serializable {
+public interface IAType extends IAObject, Serializable, IJsonSerializable {
public ATypeTag getTypeTag();