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);
}
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" + "}");
}
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" + "}");
}
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" + "}");
}
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" + "}");
}
Aggregations