Search in sources :

Example 36 with ARecordType

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;
}
Also used : MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) RemoteException(java.rmi.RemoteException) ARecordType(org.apache.asterix.om.types.ARecordType) MetadataException(org.apache.asterix.metadata.MetadataException) Datatype(org.apache.asterix.metadata.entities.Datatype) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 37 with ARecordType

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);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ARecordPointable(org.apache.asterix.om.pointables.nonvisitor.ARecordPointable) ARecordType(org.apache.asterix.om.types.ARecordType)

Example 38 with ARecordType

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;
}
Also used : BuiltinType(org.apache.asterix.om.types.BuiltinType) AUnionType(org.apache.asterix.om.types.AUnionType) ArrayList(java.util.ArrayList) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) ARecordType(org.apache.asterix.om.types.ARecordType) Datatype(org.apache.asterix.metadata.entities.Datatype) IAType(org.apache.asterix.om.types.IAType)

Example 39 with ARecordType

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);
}
Also used : AOrderedListType(org.apache.asterix.om.types.AOrderedListType) AString(org.apache.asterix.om.base.AString) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType)

Example 40 with ARecordType

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()));
}
Also used : AUnionType(org.apache.asterix.om.types.AUnionType) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) ArrayList(java.util.ArrayList) ARecordType(org.apache.asterix.om.types.ARecordType) AUnorderedListType(org.apache.asterix.om.types.AUnorderedListType) IAType(org.apache.asterix.om.types.IAType) Test(org.junit.Test)

Aggregations

ARecordType (org.apache.asterix.om.types.ARecordType)105 IAType (org.apache.asterix.om.types.IAType)73 ArrayList (java.util.ArrayList)48 List (java.util.List)24 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)22 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)20 Dataset (org.apache.asterix.metadata.entities.Dataset)19 AString (org.apache.asterix.om.base.AString)19 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)19 Test (org.junit.Test)16 AsterixException (org.apache.asterix.common.exceptions.AsterixException)15 Index (org.apache.asterix.metadata.entities.Index)15 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)15 CompilationException (org.apache.asterix.common.exceptions.CompilationException)13 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)13 Mutable (org.apache.commons.lang3.mutable.Mutable)13 IOException (java.io.IOException)12 MetadataException (org.apache.asterix.metadata.MetadataException)12 AUnionType (org.apache.asterix.om.types.AUnionType)11 Pair (org.apache.hyracks.algebricks.common.utils.Pair)10