Commit 4f9cba4b by Suma Shivaprasad

ATLAS-754 InstanceSerialization does not serialize Reference in the values array…

ATLAS-754 InstanceSerialization does not serialize Reference in the values array of Reference. (harishjp via sumasai)
parent 856ee6b5
......@@ -20,6 +20,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset
ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags)
ALL CHANGES:
ATLAS-754 InstanceSerialization does not serialize Reference in the values array of Reference.(harishjp via sumasai)
ATLAS-626 Hive temporary table metadata is captured in atlas (sumasai)
ATLAS-747 Hive CTAS entity registration fails because userName is null (shwethags)
ATLAS-759 HiveHookIT.testAlterTableChangeColumn is consistently failing on master (yhemanth)
......
......@@ -104,7 +104,7 @@ object InstanceSerialization {
refClass <- idClass
typNm <- typeName
i <- id
s <- Some (state)
s <- Some(state)
v <- version
} yield _Id(i, v, typNm, s)
}
......@@ -219,7 +219,6 @@ object InstanceSerialization {
* A Map is an Reference if:
* - it has the correct [[format.typeHintFieldName]]
* - it has a 'typeName'
* - it has an _Id
* - it has a 'values' attribute
* - it has 'traitNames' attribute
* - it has 'traits' attribute
......@@ -229,11 +228,11 @@ object InstanceSerialization {
for {
refClass <- referenceClass
typNm <- typeName
i <- idObject
i <- Some(idObject)
values <- valuesMap
traitNms <- traitNames
ts <- traits
} yield _Reference(Some(i), typNm, values, traitNms.toList, ts)
} yield _Reference(i, typNm, values, traitNms.toList, ts)
}
/**
......
......@@ -53,79 +53,82 @@ class InstanceSerializationTest {
}
@Test def testReferenceArrayWithNoState {
val staticJson = """{
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Reference",
"id": {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Id",
"version": 0,
"typeName": "LoadProcess"
},
"typeName": "LoadProcess",
"values": {
"inputTables": [{
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Id",
"id": "bacfa996-e88e-4d7e-9630-68c9829b10b4",
"version": 0,
"typeName": "Table"
}, {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Id",
"id": "6da06805-3f56-446f-8831-672a65ac2199",
"version": 0,
"typeName": "Table"
}
],
"outputTable": {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Id",
"id": "d5c3d6d0-aa10-44c1-b05d-ed9400d2a5ac",
"version": 0,
"typeName": "Table"
},
"name": "loadSalesDaily"
},
"traitNames": [
"ETL"
],
"traits": {
"ETL": {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Struct",
"typeName": "ETL",
"values": {
}
}
val staticJson = s"""{
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference",
"id": {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
"version": 0,
"typeName": "LoadProcess"
},
"typeName": "LoadProcess",
"values": {
"inputTables": [{
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
"id": "bacfa996-e88e-4d7e-9630-68c9829b10b4",
"version": 0,
"typeName": "Table"
}, {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
"id": "6da06805-3f56-446f-8831-672a65ac2199",
"version": 0,
"typeName": "Table"
}, {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference",
"typeName": "$typeName",
"values": {}
"traitNames": []
"traits": {}
}
],
"outputTable": {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
"id": "d5c3d6d0-aa10-44c1-b05d-ed9400d2a5ac",
"version": 0,
"typeName": "Table"
},
"name": "loadSalesDaily"
},
"traitNames": [
"ETL"
],
"traits": {
"ETL": {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Struct",
"typeName": "ETL",
"values": {
}
}
}
}
""";
val entity: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true)
val outputTable = entity.getValuesMap.get("outputTable")
val inputTables : java.util.List[_] = entity.getValuesMap().get("inputTables").asInstanceOf[java.util.List[_]]
assertTrue(outputTable.isInstanceOf[Id]);
import scala.collection.JavaConversions._
for(inputTable <- inputTables) {
assertTrue(inputTable.isInstanceOf[Id]);
}
""";
val entity: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true)
val outputTable = entity.getValuesMap.get("outputTable")
val inputTables : java.util.List[_] = entity.getValuesMap().get("inputTables").asInstanceOf[java.util.List[_]]
assertTrue(entity.getId.isInstanceOf[Id]);
assertTrue(outputTable.isInstanceOf[Id]);
import scala.collection.JavaConversions._
assertTrue(inputTables(0).isInstanceOf[Id]);
assertTrue(inputTables(1).isInstanceOf[Id]);
assertTrue(inputTables(2).isInstanceOf[Referenceable]);
}
@Test def testMissingStateInId: Unit = {
val entity: Referenceable = new Referenceable(typeName)
val json: String = InstanceSerialization.toJson(entity, true)
val staticJson: String = "{\n" +
" \"jsonClass\":\"org.apache.atlas.typesystem.json.InstanceSerialization$_Reference\",\n" +
" \"id\":{\n" +
" \"jsonClass\":\"org.apache.atlas.typesystem.json.InstanceSerialization$_Id\",\n" +
" \"id\":\"" + entity.getId.id + "\",\n" +
" \"version\":0,\n" +
" \"typeName\":\"" + entity.getTypeName + "\",\n" +
" },\n" +
" \"typeName\":\"" + entity.getTypeName + "\",\n" +
" \"values\":{}\n" +
" \"traitNames\":[]\n" +
" \"traits\":{}\n" +
"}"
val staticJson: String = s"""{
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference",
"id": {
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id",
"id": "${entity.getId.id}",
"version":0,
"typeName": "${entity.getTypeName}",
},
"typeName": "${entity.getTypeName}",
"values": {}
"traitNames": []
"traits": {}
}"""
val entity2: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true)
assertNotNull(entity2)
assertNotNull(entity2.getId)
......@@ -140,14 +143,13 @@ class InstanceSerializationTest {
@Test def testMissingId: Unit = {
val entity: Referenceable = new Referenceable(typeName)
val json: String = InstanceSerialization.toJson(entity, true)
val staticJson: String = "{\n" +
" \"jsonClass\":\"org.apache.atlas.typesystem.json.InstanceSerialization$_Reference\",\n" +
" \"typeName\":\"" + entity.getTypeName + "\",\n" +
" \"values\":{}\n" +
" \"traitNames\":[],\n" +
" \"traits\":{}\n" +
"}"
val staticJson: String = s"""{
"jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference",
"typeName": "${entity.getTypeName}",
"values": {}
"traitNames": []
"traits": {}
}"""
val entity2: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true)
assertNotNull(entity2)
assertNotNull(entity2.getId)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment