Search in sources :

Example 51 with Referenceable

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);
}
Also used : Path(org.apache.hadoop.fs.Path) Referenceable(org.apache.atlas.typesystem.Referenceable) ParseException(java.text.ParseException) AtlasServiceException(org.apache.atlas.AtlasServiceException) JSONException(org.codehaus.jettison.json.JSONException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) Test(org.testng.annotations.Test)

Example 52 with Referenceable

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());
}
Also used : ReadEntity(org.apache.hadoop.hive.ql.hooks.ReadEntity) Referenceable(org.apache.atlas.typesystem.Referenceable) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) Test(org.testng.annotations.Test)

Example 53 with Referenceable

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;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable)

Example 54 with Referenceable

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);
                }
            }
        }
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Id(org.apache.atlas.typesystem.persistence.Id) Map(java.util.Map) HashMap(java.util.HashMap)

Example 55 with Referenceable

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;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable)

Aggregations

Referenceable (org.apache.atlas.typesystem.Referenceable)235 Test (org.testng.annotations.Test)114 Id (org.apache.atlas.typesystem.persistence.Id)50 ArrayList (java.util.ArrayList)45 List (java.util.List)25 Struct (org.apache.atlas.typesystem.Struct)25 HashMap (java.util.HashMap)24 BeforeTest (org.testng.annotations.BeforeTest)24 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)22 AfterTest (org.testng.annotations.AfterTest)22 HookNotification (org.apache.atlas.notification.hook.HookNotification)20 IStruct (org.apache.atlas.typesystem.IStruct)18 ClassType (org.apache.atlas.typesystem.types.ClassType)16 JSONObject (org.codehaus.jettison.json.JSONObject)16 ImmutableList (com.google.common.collect.ImmutableList)15 AtlasServiceException (org.apache.atlas.AtlasServiceException)14 TraitType (org.apache.atlas.typesystem.types.TraitType)12 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)12 Date (java.util.Date)11 AtlasException (org.apache.atlas.AtlasException)11