Support Questions

Find answers, ask questions, and share your expertise

How to create attribute sets and collections using Atlas REST API

Contributor

Please could you advise the correct way of setting up collection and set attributes in the Atlas REST API . I have used the following but I don't know if I've properly assigned the set or collection to the attribute as I only know how to check the attributes in the UI... but that's pretty basic in 0.6 so really I'd like to know how to do this in the backend.

{        
       "enumTypes": [],
       "structTypes": [],
       "traitTypes": [
                {
                        "superTypes": [],
                        "hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.TraitType",
                        "typeName": "api_test_set",
                        "attributeDefinitions": [
                          {
           		  	"name": "set_test",
           			"dataTypeName": "array<string>",
           			"multiplicity": "set",
           			"isComposite": false,
           			"isUnique": false,
           			"isIndexable": true,
           			"reverseAttributeName": null
         			},
                          {
                          	"name": "collection_test",
           			"dataTypeName": "array<string>",
           			"multiplicity": "collection",
           			"isComposite": false,
           			"isUnique": false,
           			"isIndexable": true,
           			"reverseAttributeName": null
         			}
                        ]
                }
        ],
        "classTypes": []
}


1 ACCEPTED SOLUTION

Guru

@Laura Ngo

I ran your type definition through the REST API for Atlas 0.6. It is valid and does show up as a valid tag in the Atlas UI. From the AtlasUI, I added the tag to a hive table entity successfully and then gave the tag some attributes. It does not look like the UI is able to show or edit the array type attributes for the tags but I was able to call the REST API (the GUID on the end of the URI is the entity id):

curl -X GET http://localhost:21000/api/atlas/entities/a6f3e6c8-57f6-45ce-98e7-ea14a1f29211

and get the following result:

{
  "requestId": "qtp1635546341-110 - 8bb20991-84e5-4dc5-a678-3dbe81cb52a2",
  "GUID": "a6f3e6c8-57f6-45ce-98e7-ea14a1f29211",
  "definition": {
    "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Reference",
    "id": {
      "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Id",
      "id": "a6f3e6c8-57f6-45ce-98e7-ea14a1f29211",
      "version": 0,
      "typeName": "hive_column"
    },
    "typeName": "hive_column",
    "values": {
      "comment": null,
      "qualifiedName": "hr.employee.location@erietp",
      "type": "string",
      "name": "location"
    },
    "traitNames": [
      "PII",
      "api_test_set"
    ],
    "traits": {
      "PII": {
        "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Struct",
        "typeName": "PII",
        "values": {
          
        }
      },
      "api_test_set": {
        "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Struct",
        "typeName": "api_test_set",
        "values": {
          "collection_test": [
            "test"
          ],
          "set_test": [
            "test"
          ]
        }
      }
    }
  }
}

Notice that the collection_test and set_test values show up as arrays denoted by [ ] and they are populated. As stated before, this will not show up in the UI but the value are persisted. I have not tried to add more elements to the arrays within the trait through the REST API but I don't see any reason why that would not work. If you were planning to use the value within the tags for some custom purpose you should be good to go.

View solution in original post

1 REPLY 1

Guru

@Laura Ngo

I ran your type definition through the REST API for Atlas 0.6. It is valid and does show up as a valid tag in the Atlas UI. From the AtlasUI, I added the tag to a hive table entity successfully and then gave the tag some attributes. It does not look like the UI is able to show or edit the array type attributes for the tags but I was able to call the REST API (the GUID on the end of the URI is the entity id):

curl -X GET http://localhost:21000/api/atlas/entities/a6f3e6c8-57f6-45ce-98e7-ea14a1f29211

and get the following result:

{
  "requestId": "qtp1635546341-110 - 8bb20991-84e5-4dc5-a678-3dbe81cb52a2",
  "GUID": "a6f3e6c8-57f6-45ce-98e7-ea14a1f29211",
  "definition": {
    "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Reference",
    "id": {
      "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Id",
      "id": "a6f3e6c8-57f6-45ce-98e7-ea14a1f29211",
      "version": 0,
      "typeName": "hive_column"
    },
    "typeName": "hive_column",
    "values": {
      "comment": null,
      "qualifiedName": "hr.employee.location@erietp",
      "type": "string",
      "name": "location"
    },
    "traitNames": [
      "PII",
      "api_test_set"
    ],
    "traits": {
      "PII": {
        "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Struct",
        "typeName": "PII",
        "values": {
          
        }
      },
      "api_test_set": {
        "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Struct",
        "typeName": "api_test_set",
        "values": {
          "collection_test": [
            "test"
          ],
          "set_test": [
            "test"
          ]
        }
      }
    }
  }
}

Notice that the collection_test and set_test values show up as arrays denoted by [ ] and they are populated. As stated before, this will not show up in the UI but the value are persisted. I have not tried to add more elements to the arrays within the trait through the REST API but I don't see any reason why that would not work. If you were planning to use the value within the tags for some custom purpose you should be good to go.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.