use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.
the class HiveHookIT method testAlterTableLocation.
@Test
public void testAlterTableLocation() throws Exception {
//Its an external table, so the HDFS location should also be registered as an entity
String tableName = createTable(true, true, false);
final String testPath = createTestDFSPath("testBaseDir");
String query = "alter table " + tableName + " set location '" + testPath + "'";
runCommand(query);
assertTableIsRegistered(DEFAULT_DB, tableName, new AssertPredicate() {
@Override
public void assertOnEntity(Referenceable tableRef) throws Exception {
Referenceable sdRef = (Referenceable) tableRef.get(HiveMetaStoreBridge.STORAGE_DESC);
Assert.assertEquals(new Path((String) sdRef.get(HiveMetaStoreBridge.LOCATION)).toString(), new Path(testPath).toString());
}
});
String processQualifiedName = getTableProcessQualifiedName(DEFAULT_DB, tableName);
String processId = assertEntityIsRegistered(HiveDataTypes.HIVE_PROCESS.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, processQualifiedName, null);
Referenceable processReference = atlasClient.getEntity(processId);
validateHDFSPaths(processReference, INPUTS, testPath);
}
use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.
the class HiveHookIT method testInsertIntoDFSDirPartitioned.
@Test
public void testInsertIntoDFSDirPartitioned() throws Exception {
//Test with partitioned table
String tableName = createTable(true);
String pFile1 = createTestDFSPath("somedfspath1");
String query = "insert overwrite DIRECTORY '" + pFile1 + "' select id, name from " + tableName + " where dt = '" + PART_FILE + "'";
runCommand(query);
Set<ReadEntity> inputs = getInputs(tableName, Entity.Type.TABLE);
final Set<WriteEntity> outputs = getOutputs(pFile1, Entity.Type.DFS_DIR);
outputs.iterator().next().setWriteType(WriteEntity.WriteType.PATH_WRITE);
final Set<ReadEntity> partitionIps = new LinkedHashSet<>(inputs);
partitionIps.addAll(getInputs(DEFAULT_DB + "@" + tableName + "@dt='" + PART_FILE + "'", Entity.Type.PARTITION));
Referenceable processReference = validateProcess(constructEvent(query, HiveOperation.QUERY, partitionIps, outputs), inputs, outputs);
//Rerun same query with different HDFS path. Should not create another process and should update it.
final String pFile2 = createTestDFSPath("somedfspath2");
query = "insert overwrite DIRECTORY '" + pFile2 + "' select id, name from " + tableName + " where dt = '" + PART_FILE + "'";
runCommand(query);
final Set<WriteEntity> pFile2Outputs = getOutputs(pFile2, Entity.Type.DFS_DIR);
pFile2Outputs.iterator().next().setWriteType(WriteEntity.WriteType.PATH_WRITE);
//Now the process has 2 paths - one older with deleted reference to partition and another with the the latest partition
Set<WriteEntity> p2Outputs = new LinkedHashSet<WriteEntity>() {
{
addAll(pFile2Outputs);
addAll(outputs);
}
};
Referenceable process2Reference = validateProcess(constructEvent(query, HiveOperation.QUERY, partitionIps, pFile2Outputs), inputs, p2Outputs);
validateHDFSPaths(process2Reference, OUTPUTS, pFile2);
Assert.assertEquals(process2Reference.getId()._getId(), processReference.getId()._getId());
}
use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.
the class TestUtils method createDBEntity.
public static Referenceable createDBEntity() {
Referenceable entity = new Referenceable(DATABASE_TYPE);
String dbName = RandomStringUtils.randomAlphanumeric(10);
entity.set(NAME, dbName);
entity.set("description", "us db");
return entity;
}
use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.
the class TestUtils method findReferencedObjects.
private static void findReferencedObjects(Referenceable ref, Map<Id, Referenceable> seen) {
Id guid = ref.getId();
if (seen.containsKey(guid)) {
return;
}
seen.put(guid, ref);
for (Map.Entry<String, Object> attr : ref.getValuesMap().entrySet()) {
Object value = attr.getValue();
if (value instanceof Referenceable) {
findReferencedObjects((Referenceable) value, seen);
} else if (value instanceof List) {
for (Object o : (List) value) {
if (o instanceof Referenceable) {
findReferencedObjects((Referenceable) o, seen);
}
}
} else if (value instanceof Map) {
for (Object o : ((Map) value).values()) {
if (o instanceof Referenceable) {
findReferencedObjects((Referenceable) o, seen);
}
}
}
}
}
use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.
the class BaseRepositoryTest method column.
protected Referenceable column(String name, String dataType, String comment, String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set("dataType", dataType);
referenceable.set("comment", comment);
return referenceable;
}
Aggregations