Search in sources :

Example 1 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class HardDeleteHandlerV1Test method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.

@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(String structContainerGuid) throws Exception {
    // Verify that the unidirectional references from the struct and trait instances
    // to the deleted entities were disconnected.
    ITypedReferenceableInstance structContainerConvertedEntity = metadataService.getEntityDefinition(structContainerGuid);
    ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
    assertNull(struct.get("target"));
    IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
    assertNotNull(trait);
    assertNull(trait.get("target"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct)

Example 2 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class SoftDeleteHandlerV1Test method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.

@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(final String structContainerGuid) throws Exception {
    // Verify that the unidirectional references from the struct and trait instances
    // to the deleted entities were not disconnected.
    ITypedReferenceableInstance structContainerConvertedEntity = metadataService.getEntityDefinition(structContainerGuid);
    ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
    assertNotNull(struct.get("target"));
    IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
    assertNotNull(trait);
    assertNotNull(trait.get("target"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct)

Example 3 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class TraitTest method test1.

/*
     * Type Hierarchy is:
     *   A(a,b,c,d)
     *   B(b) extends A
     *   C(c) extends A
     *   D(d) extends B,C
     *
     * - There are a total of 11 fields in an instance of D
     * - an attribute that is hidden by a SubType can referenced by prefixing it with the
     * complete Path.
     *   For e.g. the 'b' attribute in A (that is a superType for B) is hidden the 'b' attribute
     *   in B.
     *   So it is available by the name 'A.B.D.b'
     *
     * - Another way to set attributes is to cast. Casting a 'D' instance of 'B' makes the 'A.B.D
     * .b' attribute
     *   available as 'A.B.b'. Casting one more time to an 'A' makes the 'A.B.b' attribute
     *   available as 'b'.
     */
@Test
public void test1() throws AtlasException {
    HierarchicalTypeDefinition A = createTraitTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
    HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
    HierarchicalTypeDefinition C = createTraitTypeDef("C", ImmutableSet.of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
    HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableSet.of("B", "C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
    defineTraits(A, B, C, D);
    TraitType DType = getTypeSystem().getDataType(TraitType.class, "D");
    // for(String aName : DType.fieldMapping().fields.keySet()) {
    // System.out.println(String.format("nameToQualifiedName.put(\"%s\", \"%s\");", aName, DType
    // .getQualifiedName(aName)));
    // }
    Map<String, String> nameToQualifiedName = new HashMap();
    {
        nameToQualifiedName.put("d", "D.d");
        nameToQualifiedName.put("b", "B.b");
        nameToQualifiedName.put("c", "C.c");
        nameToQualifiedName.put("a", "A.a");
        nameToQualifiedName.put("A.B.D.b", "A.B.D.b");
        nameToQualifiedName.put("A.B.D.c", "A.B.D.c");
        nameToQualifiedName.put("A.B.D.d", "A.B.D.d");
        nameToQualifiedName.put("A.C.D.a", "A.C.D.a");
        nameToQualifiedName.put("A.C.D.b", "A.C.D.b");
        nameToQualifiedName.put("A.C.D.c", "A.C.D.c");
        nameToQualifiedName.put("A.C.D.d", "A.C.D.d");
    }
    Struct s1 = new Struct("D");
    s1.set("d", 1);
    s1.set("c", 1);
    s1.set("b", true);
    s1.set("a", 1);
    s1.set("A.B.D.b", true);
    s1.set("A.B.D.c", 2);
    s1.set("A.B.D.d", 2);
    s1.set("A.C.D.a", 3);
    s1.set("A.C.D.b", false);
    s1.set("A.C.D.c", 3);
    s1.set("A.C.D.d", 3);
    ITypedStruct ts = DType.convert(s1, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\td : \t1\n" + "\tb : \ttrue\n" + "\tc : \t1\n" + "\ta : \t1\n" + "\tA.B.D.b : \ttrue\n" + "\tA.B.D.c : \t2\n" + "\tA.B.D.d : \t2\n" + "\tA.C.D.a : \t3\n" + "\tA.C.D.b : \tfalse\n" + "\tA.C.D.c : \t3\n" + "\tA.C.D.d : \t3\n" + "}");
    /*
         * cast to B and set the 'b' attribute on A.
         */
    TraitType BType = getTypeSystem().getDataType(TraitType.class, "B");
    IStruct s2 = DType.castAs(ts, "B");
    s2.set("A.B.b", false);
    Assert.assertEquals(ts.toString(), "{\n" + "\td : \t1\n" + "\tb : \ttrue\n" + "\tc : \t1\n" + "\ta : \t1\n" + "\tA.B.D.b : \tfalse\n" + "\tA.B.D.c : \t2\n" + "\tA.B.D.d : \t2\n" + "\tA.C.D.a : \t3\n" + "\tA.C.D.b : \tfalse\n" + "\tA.C.D.c : \t3\n" + "\tA.C.D.d : \t3\n" + "}");
    /*
         * cast again to A and set the 'b' attribute on A.
         */
    TraitType AType = getTypeSystem().getDataType(TraitType.class, "A");
    IStruct s3 = BType.castAs(s2, "A");
    s3.set("b", true);
    Assert.assertEquals(ts.toString(), "{\n" + "\td : \t1\n" + "\tb : \ttrue\n" + "\tc : \t1\n" + "\ta : \t1\n" + "\tA.B.D.b : \ttrue\n" + "\tA.B.D.c : \t2\n" + "\tA.B.D.d : \t2\n" + "\tA.C.D.a : \t3\n" + "\tA.C.D.b : \tfalse\n" + "\tA.C.D.c : \t3\n" + "\tA.C.D.d : \t3\n" + "}");
}
Also used : HashMap(java.util.HashMap) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) IStruct(org.apache.atlas.typesystem.IStruct) Test(org.testng.annotations.Test)

Example 4 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class EnumTest method testStruct.

@Test
public void testStruct() throws AtlasException {
    TypeSystem ts = getTypeSystem();
    defineEnums(ts);
    StructType structType = ts.defineStructType("ts", true, createRequiredAttrDef("a", DataTypes.INT_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE), createOptionalAttrDef("d", DataTypes.SHORT_TYPE), createOptionalAttrDef("enum1", ts.getDataType(EnumType.class, "HiveObjectType")), createOptionalAttrDef("e", DataTypes.INT_TYPE), createOptionalAttrDef("f", DataTypes.INT_TYPE), createOptionalAttrDef("g", DataTypes.LONG_TYPE), createOptionalAttrDef("enum2", ts.getDataType(EnumType.class, "PrincipalType")), createOptionalAttrDef("h", DataTypes.FLOAT_TYPE), createOptionalAttrDef("i", DataTypes.DOUBLE_TYPE), createOptionalAttrDef("j", DataTypes.BIGINTEGER_TYPE), createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE), createOptionalAttrDef("enum3", ts.getDataType(EnumType.class, "TxnState")), createOptionalAttrDef("l", DataTypes.DATE_TYPE), createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)), createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), createOptionalAttrDef("o", ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)), createOptionalAttrDef("enum4", ts.getDataType(EnumType.class, "LockLevel")));
    Struct s = createStructWithEnum("ts");
    ITypedStruct typedS = structType.convert(s, Multiplicity.REQUIRED);
    Assert.assertEquals(typedS.toString(), "{\n" + "\ta : \t1\n" + "\tb : \ttrue\n" + "\tc : \t1\n" + "\td : \t2\n" + "\tenum1 : \tGLOBAL\n" + "\te : \t1\n" + "\tf : \t1\n" + "\tg : \t1\n" + "\tenum2 : \tUSER\n" + "\th : \t1.0\n" + "\ti : \t1.0\n" + "\tj : \t1\n" + "\tk : \t1\n" + "\tenum3 : \tCOMMITTED\n" + "\tl : \t" + TEST_DATE + "\n" + "\tm : \t[1, 1]\n" + "\tn : \t[1.1, 1.1]\n" + "\to : \t{a=1.0, b=2.0}\n" + "\tenum4 : \tPARTITION\n" + "}");
}
Also used : ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 5 with ITypedStruct

use of org.apache.atlas.typesystem.ITypedStruct in project incubator-atlas by apache.

the class StructTest method test1.

@Test
public void test1() throws AtlasException {
    Struct s = createStruct();
    ITypedStruct ts = structType.convert(s, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\ta : \t1\n" + "\tb : \ttrue\n" + "\tc : \t1\n" + "\td : \t2\n" + "\te : \t1\n" + "\tf : \t1\n" + "\tg : \t1\n" + "\th : \t1.0\n" + "\ti : \t1.0\n" + "\tj : \t1\n" + "\tk : \t1\n" + "\tl : \t" + TEST_DATE + "\n" + "\tm : \t[1, 1]\n" + "\tn : \t[1.1, 1.1]\n" + "\to : \t{a=1.0, b=2.0}\n" + "\tp : \t\n" + "\tq : \t<null>\n" + "\tr : \t{a=}\n" + "}");
}
Also used : ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Aggregations

ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)29 Test (org.testng.annotations.Test)14 IStruct (org.apache.atlas.typesystem.IStruct)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 Struct (org.apache.atlas.typesystem.Struct)11 TraitType (org.apache.atlas.typesystem.types.TraitType)6 AtlasException (org.apache.atlas.AtlasException)5 ImmutableList (com.google.common.collect.ImmutableList)4 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)4 List (java.util.List)3 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ArrayList (java.util.ArrayList)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)2 Referenceable (org.apache.atlas.typesystem.Referenceable)2 TypesDef (org.apache.atlas.typesystem.TypesDef)2 StructType (org.apache.atlas.typesystem.types.StructType)2 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)2 BeforeTest (org.testng.annotations.BeforeTest)2