Search in sources :

Example 81 with ARecordType

use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.

the class ARecordSerializerDeserializerTest method test.

@Test
public void test() {
    // Generates types.
    ARecordType addrRecordType = SerializerDeserializerTestUtils.generateAddressRecordType();
    ARecordType employeeType = SerializerDeserializerTestUtils.generateEmployeeRecordType(addrRecordType);
    //Generates records.
    ARecord[] records = SerializerDeserializerTestUtils.generateRecords(addrRecordType, employeeType);
    ARecordSerializerDeserializer serde = new ARecordSerializerDeserializer(employeeType);
    // Run four test threads to serialize/deserialize records concurrently.
    SerializerDeserializerTestUtils.concurrentSerDeTestRun(serde, records);
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) ARecordType(org.apache.asterix.om.types.ARecordType) Test(org.junit.Test)

Example 82 with ARecordType

use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.

the class TypeResolverUtilTest method testUnorderedListType.

@Test
public void testUnorderedListType() {
    // Constructs input types.
    ARecordType leftRecordType = new ARecordType(null, new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, BuiltinType.AINT32 }, true, Collections.singleton("d"));
    AUnorderedListType leftListType = new AUnorderedListType(leftRecordType, null);
    AUnorderedListType rightListType = new AUnorderedListType(BuiltinType.ASTRING, null);
    // Gets the actual resolved type.
    List<IAType> inputTypes = new ArrayList<>();
    inputTypes.add(leftListType);
    inputTypes.add(rightListType);
    AbstractCollectionType resolvedType = (AbstractCollectionType) TypeResolverUtil.resolve(inputTypes);
    // Compares the resolved type and the expected type.
    Assert.assertEquals(resolvedType, new AUnorderedListType(BuiltinType.ANY, null));
}
Also used : ArrayList(java.util.ArrayList) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType) 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)

Example 83 with ARecordType

use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.

the class TypeResolverUtilTest method testNullType.

@Test
public void testNullType() {
    ARecordType leftRecordType = new ARecordType(null, new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, BuiltinType.AINT32 }, false, null);
    List<IAType> inputTypes = new ArrayList<>();
    inputTypes.add(leftRecordType);
    inputTypes.add(BuiltinType.ANULL);
    IAType resolvedType = TypeResolverUtil.resolve(inputTypes);
    Assert.assertEquals(resolvedType, AUnionType.createUnknownableType(leftRecordType));
}
Also used : ArrayList(java.util.ArrayList) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType) Test(org.junit.Test)

Example 84 with ARecordType

use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.

the class TypeResolverUtilTest method testNestedRecordType.

@Test
public void testNestedRecordType() {
    // Constructs input types.
    ARecordType leftRecordType = new ARecordType("null", new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, new ARecordType(null, new String[] { "c", "d" }, new IAType[] { BuiltinType.ASTRING, BuiltinType.AINT32 }, false, null) }, false, null);
    ARecordType rightRecordType = new ARecordType("null", new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, new ARecordType(null, new String[] { "d", "e" }, new IAType[] { BuiltinType.AINT32, BuiltinType.AINT32 }, false, null) }, false, null);
    // Resolves input types to a generalized type.
    List<IAType> inputTypes = new ArrayList<>();
    inputTypes.add(leftRecordType);
    inputTypes.add(rightRecordType);
    ARecordType resolvedType = (ARecordType) TypeResolverUtil.resolve(inputTypes);
    ARecordType nestedRecordType = (ARecordType) resolvedType.getFieldType("b");
    // Constructs the expected type.
    Set<String> nestedPossibleAdditionalFields = new HashSet<>();
    nestedPossibleAdditionalFields.add("c");
    nestedPossibleAdditionalFields.add("e");
    ARecordType expectedType = new ARecordType(null, new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, new ARecordType(null, new String[] { "d" }, new IAType[] { BuiltinType.AINT32 }, true, nestedPossibleAdditionalFields) }, false, null);
    // Compares the resolved type with the expected type.
    Assert.assertEquals(expectedType, resolvedType);
    Assert.assertEquals(nestedRecordType.getAllPossibleAdditonalFieldNames(), nestedPossibleAdditionalFields);
}
Also used : ArrayList(java.util.ArrayList) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 85 with ARecordType

use of org.apache.asterix.om.types.ARecordType in project asterixdb by apache.

the class TypeResolverUtilTest method testRecordType.

@Test
public void testRecordType() {
    // Constructs input types.
    ARecordType leftRecordType = new ARecordType(null, new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, BuiltinType.AINT32 }, false, null);
    ARecordType rightRecordType = new ARecordType(null, new String[] { "b", "c" }, new IAType[] { BuiltinType.AINT32, BuiltinType.ABINARY }, false, null);
    // Resolves input types to a generalized type.
    List<IAType> inputTypes = new ArrayList<>();
    inputTypes.add(leftRecordType);
    inputTypes.add(rightRecordType);
    ARecordType resolvedType = (ARecordType) TypeResolverUtil.resolve(inputTypes);
    // Constructs the expected type.
    Set<String> possibleAdditionalFields = new HashSet<>();
    possibleAdditionalFields.add("a");
    possibleAdditionalFields.add("c");
    ARecordType expectedType = new ARecordType(null, new String[] { "b" }, new IAType[] { BuiltinType.AINT32 }, true, possibleAdditionalFields);
    // Compares the resolved type with the expected type.
    Assert.assertEquals(resolvedType, expectedType);
    Assert.assertEquals(resolvedType.getAllPossibleAdditonalFieldNames(), expectedType.getAllPossibleAdditonalFieldNames());
}
Also used : ArrayList(java.util.ArrayList) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType) HashSet(java.util.HashSet) 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