Search in sources :

Example 46 with Struct

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

the class GraphBackedMetadataRepositoryTest method createHiveTableInstance.

private ITypedReferenceableInstance createHiveTableInstance(Referenceable databaseInstance) throws Exception {
    Referenceable tableInstance = new Referenceable(TestUtils.TABLE_TYPE, TestUtils.CLASSIFICATION);
    tableInstance.set("name", TestUtils.TABLE_NAME);
    tableInstance.set("description", "bar table");
    tableInstance.set("type", "managed");
    tableInstance.set("created", new Date(TestUtils.TEST_DATE_IN_LONG));
    // enum
    tableInstance.set("tableType", 1);
    // super type
    tableInstance.set("namespace", "colo:cluster:hive:db:table");
    tableInstance.set("cluster", "cluster-1");
    tableInstance.set("colo", "colo-1");
    // refer to an existing class
    tableInstance.set("database", databaseInstance);
    ArrayList<String> columnNames = new ArrayList<>();
    columnNames.add("first_name");
    columnNames.add("last_name");
    tableInstance.set("columnNames", columnNames);
    Struct traitInstance = (Struct) tableInstance.getTrait(TestUtils.CLASSIFICATION);
    traitInstance.set("tag", "foundation_etl");
    Struct serde1Instance = new Struct("serdeType");
    serde1Instance.set("name", "serde1");
    serde1Instance.set("serde", "serde1");
    tableInstance.set("serde1", serde1Instance);
    Struct serde2Instance = new Struct("serdeType");
    serde2Instance.set("name", "serde2");
    serde2Instance.set("serde", "serde2");
    tableInstance.set("serde2", serde2Instance);
    // HashMap<String, Referenceable> columnsMap = new HashMap<>();
    ArrayList<Referenceable> columns = new ArrayList<>();
    for (int index = 0; index < 5; index++) {
        Referenceable columnInstance = new Referenceable("column_type");
        final String name = "column_" + index;
        columnInstance.set("name", name);
        columnInstance.set("type", "string");
        columns.add(columnInstance);
    // columnsMap.put(name, columnInstance);
    }
    tableInstance.set("columns", columns);
    // tableInstance.set("columnsMap", columnsMap);
    //        HashMap<String, Struct> partitionsMap = new HashMap<>();
    ArrayList<Struct> partitions = new ArrayList<>();
    for (int index = 0; index < 5; index++) {
        Struct partitionInstance = new Struct(TestUtils.PARTITION_STRUCT_TYPE);
        final String name = "partition_" + index;
        partitionInstance.set("name", name);
        partitions.add(partitionInstance);
    //            partitionsMap.put(name, partitionInstance);
    }
    tableInstance.set("partitions", partitions);
    //        tableInstance.set("partitionsMap", partitionsMap);
    HashMap<String, String> parametersMap = new HashMap<>();
    parametersMap.put("foo", "bar");
    parametersMap.put("bar", "baz");
    parametersMap.put("some", "thing");
    tableInstance.set("parametersMap", parametersMap);
    ClassType tableType = typeSystem.getDataType(ClassType.class, TestUtils.TABLE_TYPE);
    return tableType.convert(tableInstance, Multiplicity.REQUIRED);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) Date(java.util.Date) IStruct(org.apache.atlas.typesystem.IStruct) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 47 with Struct

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

the class TypeInheritanceTest method testSimpleInheritanceWithOverrides.

/*
     * Type Hierarchy is:
     *   A(a, b)
     *   B(b) extends A
     */
@Test
public void testSimpleInheritanceWithOverrides() throws AtlasException {
    HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE), createRequiredAttrDef("b", DataTypes.BOOLEAN_TYPE));
    HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
    defineClasses(A, B);
    ClassType BType = getTypeSystem().getDataType(ClassType.class, "B");
    Struct s1 = new Struct("B");
    s1.set("b", true);
    s1.set("a", 1);
    s1.set("A.B.b", false);
    ITypedInstance ts = BType.convert(s1, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\tid : (type: B, id: <unassigned>)\n" + "\tb : \ttrue\n" + "\ta : \t1\n" + "\tA.B.b : \tfalse\n" + "}");
}
Also used : ITypedInstance(org.apache.atlas.typesystem.ITypedInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 48 with Struct

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

the class TypeInheritanceTest method testSimpleInheritance.

/*
     * Type Hierarchy is:
     *   A(a)
     *   B(b) extends A
     */
@Test
public void testSimpleInheritance() throws AtlasException {
    HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
    HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
    defineClasses(A, B);
    ClassType BType = getTypeSystem().getDataType(ClassType.class, "B");
    Struct s1 = new Struct("B");
    s1.set("b", true);
    s1.set("a", 1);
    ITypedInstance ts = BType.convert(s1, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\tid : (type: B, id: <unassigned>)\n" + "\tb : \ttrue\n" + "\ta : \t1\n" + "}");
}
Also used : ITypedInstance(org.apache.atlas.typesystem.ITypedInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 49 with Struct

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

the class TypeInheritanceTest method testMultiLevelInheritance.

/*
     * Type Hierarchy is:
     *   A(a)
     *   B(b) extends A
     *   C(c) extends B
     *   D(d) extends C
     */
@Test
public void testMultiLevelInheritance() throws AtlasException {
    HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
    HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
    HierarchicalTypeDefinition C = createClassTypeDef("C", ImmutableSet.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
    HierarchicalTypeDefinition D = createClassTypeDef("D", ImmutableSet.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
    defineClasses(A, B, C, D);
    ClassType DType = getTypeSystem().getDataType(ClassType.class, "D");
    Struct s1 = new Struct("D");
    s1.set("d", 1);
    s1.set("c", 1);
    s1.set("b", true);
    s1.set("a", 1);
    ITypedInstance ts = DType.convert(s1, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\tid : (type: D, id: <unassigned>)\n" + "\td : \t1\n" + "\tc : \t1\n" + "\tb : \ttrue\n" + "\ta : \t1\n" + "}");
}
Also used : ITypedInstance(org.apache.atlas.typesystem.ITypedInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 50 with Struct

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

the class StructTest method testRecursive.

@Test
public void testRecursive() throws AtlasException {
    Struct s1 = new Struct(recursiveStructType.getName());
    s1.set("a", 1);
    Struct s2 = new Struct(recursiveStructType.getName());
    s2.set("a", 1);
    s2.set("s", s1);
    ITypedStruct ts = recursiveStructType.convert(s2, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\ta : \t1\n" + "\ts : \t{\n" + "\t\ta : \t\t1\n" + "\t\ts : <null>\n" + "\n" + "\t}\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

Struct (org.apache.atlas.typesystem.Struct)56 Test (org.testng.annotations.Test)36 IStruct (org.apache.atlas.typesystem.IStruct)29 Referenceable (org.apache.atlas.typesystem.Referenceable)25 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)17 TraitType (org.apache.atlas.typesystem.types.TraitType)12 ArrayList (java.util.ArrayList)9 LinkedList (java.util.LinkedList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Id (org.apache.atlas.typesystem.persistence.Id)7 JSONObject (org.codehaus.jettison.json.JSONObject)7 BeforeTest (org.testng.annotations.BeforeTest)6 AfterTest (org.testng.annotations.AfterTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 ITypedInstance (org.apache.atlas.typesystem.ITypedInstance)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)4 Date (java.util.Date)3