use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class FeedMetadataUtil method getOutputType.
public static ARecordType getOutputType(IFeed feed, Map<String, String> configuration, String key) throws MetadataException {
ARecordType outputType = null;
String fqOutputType = configuration.get(key);
if (fqOutputType == null) {
return null;
}
String[] dataverseAndType = fqOutputType.split("[.]");
String dataverseName;
String datatypeName;
if (dataverseAndType.length == 1) {
datatypeName = dataverseAndType[0];
dataverseName = feed.getDataverseName();
} else if (dataverseAndType.length == 2) {
dataverseName = dataverseAndType[0];
datatypeName = dataverseAndType[1];
} else {
throw new IllegalArgumentException("Invalid value for the parameter " + key);
}
MetadataTransactionContext ctx = null;
MetadataManager.INSTANCE.acquireReadLatch();
try {
ctx = MetadataManager.INSTANCE.beginTransaction();
Datatype t = MetadataManager.INSTANCE.getDatatype(ctx, dataverseName, datatypeName);
if (t == null || t.getDatatype().getTypeTag() != ATypeTag.OBJECT) {
throw new MetadataException(ErrorCode.FEED_METADATA_UTIL_UNEXPECTED_FEED_DATATYPE, datatypeName);
}
outputType = (ARecordType) t.getDatatype();
MetadataManager.INSTANCE.commitTransaction(ctx);
} catch (ACIDException | RemoteException e) {
if (ctx != null) {
try {
MetadataManager.INSTANCE.abortTransaction(ctx);
} catch (ACIDException | RemoteException e2) {
e.addSuppressed(e2);
}
throw new MetadataException(ErrorCode.FEED_CREATE_FEED_DATATYPE_ERROR, e, datatypeName);
}
} finally {
MetadataManager.INSTANCE.releaseReadLatch();
}
return outputType;
}
use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class RecordFieldsUtil method addNestedField.
public void addNestedField(IValueReference recordArg, IAType fieldType, IARecordBuilder fieldRecordBuilder, int level) throws IOException, AsterixException {
ArrayBackedValueStorage fieldAbvs = getTempBuffer();
ArrayBackedValueStorage valueAbvs = getTempBuffer();
// Name
fieldAbvs.reset();
stringSerde.serialize(nestedName, fieldAbvs.getDataOutput());
// Value
valueAbvs.reset();
ARecordType newType;
if (fieldType == null) {
newType = openType;
} else {
newType = (ARecordType) fieldType;
}
ARecordPointable recordP = getRecordPointable();
recordP.set(recordArg);
processRecord(recordP, newType, valueAbvs.getDataOutput(), level);
fieldRecordBuilder.addField(fieldAbvs, valueAbvs);
}
use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class MetadataNode method getNestedComplexDatatypeNamesForThisDatatype.
private List<String> getNestedComplexDatatypeNamesForThisDatatype(JobId jobId, String dataverseName, String datatypeName) throws MetadataException, RemoteException {
//Return all field types that aren't builtin types
Datatype parentType = getDatatype(jobId, dataverseName, datatypeName);
List<IAType> subTypes = null;
if (parentType.getDatatype().getTypeTag() == ATypeTag.OBJECT) {
ARecordType recType = (ARecordType) parentType.getDatatype();
subTypes = Arrays.asList(recType.getFieldTypes());
} else if (parentType.getDatatype().getTypeTag() == ATypeTag.UNION) {
AUnionType recType = (AUnionType) parentType.getDatatype();
subTypes = recType.getUnionList();
}
List<String> nestedTypes = new ArrayList<>();
if (subTypes != null) {
for (IAType subType : subTypes) {
if (!(subType instanceof BuiltinType)) {
nestedTypes.add(subType.getTypeName());
}
}
}
return nestedTypes;
}
use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class SerializerDeserializerTestUtils method generateEmployeeRecordType.
public static ARecordType generateEmployeeRecordType(ARecordType addrRecordType) {
AOrderedListType addrListType = new AOrderedListType(addrRecordType, "address_list");
String[] fieldNames = new String[] { "id", "name", "addresses_history" };
IAType[] fieldTypes = new IAType[] { BuiltinType.AINT64, BuiltinType.ASTRING, addrListType };
return new ARecordType("employee", fieldNames, fieldTypes, true);
}
use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.
the class JSONDeserializerForTypesTest method test.
@Test
public void test() throws Exception {
// Tests a record type with primitive types.
String[] fieldNames = { "a1", "a2", "a3" };
IAType[] fieldTypes = { BuiltinType.ASTRING, BuiltinType.AINT16, BuiltinType.ABITARRAY };
ARecordType recordType = new ARecordType("ARecord", fieldNames, fieldTypes, true);
Assert.assertEquals(recordType, JSONDeserializerForTypes.convertFromJSON(recordType.toJSON()));
// Tests a record type with a nested record type.
String[] fieldNames2 = { "a1", "a2" };
IAType[] fieldTypes2 = { BuiltinType.ABOOLEAN, recordType };
ARecordType recordType2 = new ARecordType("ARecord2", fieldNames2, fieldTypes2, true);
Assert.assertEquals(recordType2, JSONDeserializerForTypes.convertFromJSON(recordType2.toJSON()));
// Tests a record type with a union type.
String[] fieldNames3 = { "a1", "a2" };
List<IAType> unionTypes = new ArrayList<IAType>();
unionTypes.add(BuiltinType.ADURATION);
unionTypes.add(recordType2);
AUnionType unionType = new AUnionType(unionTypes, "union");
IAType[] fieldTypes3 = { BuiltinType.ABOOLEAN, unionType };
ARecordType recordType3 = new ARecordType("ARecord3", fieldNames3, fieldTypes3, true);
Assert.assertEquals(recordType3, JSONDeserializerForTypes.convertFromJSON(recordType3.toJSON()));
// Tests a record type with an ordered list.
String[] fieldNames4 = { "a1", "a2" };
IAType[] fieldTypes4 = { BuiltinType.ABOOLEAN, new AOrderedListType(BuiltinType.ADATETIME, "list") };
ARecordType recordType4 = new ARecordType("ARecord4", fieldNames4, fieldTypes4, false);
Assert.assertEquals(recordType4, JSONDeserializerForTypes.convertFromJSON(recordType4.toJSON()));
// Tests a record type with an unordered list.
String[] fieldNames5 = { "a1", "a2" };
IAType[] fieldTypes5 = { BuiltinType.ABOOLEAN, new AUnorderedListType(recordType2, "list") };
ARecordType recordType5 = new ARecordType("ARecord5", fieldNames5, fieldTypes5, false);
Assert.assertEquals(recordType5, JSONDeserializerForTypes.convertFromJSON(recordType5.toJSON()));
}
Aggregations