2

有人使用 curl 和 V2 REST API 成功更新了 Apache Atlas 中的类型吗?

例如:我会尝试向 rdbms_table 类型添加字段,例如:

    {
        "name": "business_contact_info",
        "typeName": "string",
        "isOptional": true,
        "cardinality": "SINGLE",
        "valuesMinCount": 0,
        "valuesMaxCount": 1,
        "isUnique": false,
        "isIndexable": false,
        "includeInNotification": false
    }

我围绕这个命令尝试了几种解决方案:

curl -u username:password -d @./typedef-rdbms_table.json -X PUT http://c7402.ambari.apache.org:21000/api/atlas/v2/types/typedefs -H ‘Content-Type:application/json; charset=UTF-8’

一个 json 文件看起来像:

{
  "classificationDefs" : [],
  "entityDefs": [
   {
    "category": "ENTITY",
    "guid": "ef3d3dd6-c2ac-4f0b-a566-9b8036c3b03b",
    "createdBy": "atlas",
    "updatedBy": "atlas",
    "createTime": 1541616267291,
    "updateTime": 1541616267291,
    "version": 1,
    "name": "rdbms_table",
    "description": "a table in an rdbms database (schema)",
    "typeVersion": "1.0",
    "attributeDefs": [
        {
            "name": "db",
            "typeName": "rdbms_db",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false,
            "constraints": [
                {
                    "type": "inverseRef",
                    "params": {
                        "attribute": "tables"
                    }
                }
            ]
        },
        {
            "name": "name_path",
            "typeName": "string",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false
        },
        {
            "name": "createTime",
            "typeName": "date",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false
        },
        {
            "name": "comment",
            "typeName": "string",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false
        },
        {
            "name": "type",
            "typeName": "string",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false
        },
        {
            "name": "contact_info",
            "typeName": "string",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false
        },
        {
            "name": "business_contact_info",
            "typeName": "string",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false
        },
        {
            "name": "quality_kpi",
            "typeName": "int",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false
        },
        {
            "name": "business_name",
            "typeName": "string",
            "isOptional": true,
            "cardinality": "SINGLE",
            "valuesMinCount": 0,
            "valuesMaxCount": 1,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false
        },
        {
            "name": "columns",
            "typeName": "array<rdbms_column>",
            "isOptional": true,
            "cardinality": "SET",
            "valuesMinCount": 0,
            "valuesMaxCount": 2147483647,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false,
            "constraints": [
                {
                    "type": "ownedRef"
                }
            ]
        },
        {
            "name": "indexes",
            "typeName": "array<rdbms_index>",
            "isOptional": true,
            "cardinality": "SET",
            "valuesMinCount": 0,
            "valuesMaxCount": 2147483647,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false,
            "constraints": [
                {
                    "type": "ownedRef"
                }
            ]
        },
        {
            "name": "foreign_keys",
            "typeName": "array<rdbms_foreign_key>",
            "isOptional": true,
            "cardinality": "SET",
            "valuesMinCount": 0,
            "valuesMaxCount": 2147483647,
            "isUnique": false,
            "isIndexable": false,
            "includeInNotification": false,
            "constraints": [
                {
                    "type": "ownedRef"
                }
            ]
        }
    ],
    "superTypes": [
        "DataSet",
        "Asset"
    ],
    "subTypes": []
   }
 ],
  "enumDefs" : [],
  "relationshipDefs" : [],
  "structDefs" : []
}

谢谢!

4

1 回答 1

2

Apache Atlas 允许使用可选属性更新 typeDef。可以通过以下方式创建和更新类型定义:

初始 typeDef: POST: /api/atlas/v2/types/typedefs

{
    "entityDefs": [
        {
            "name": "test",
            "description": "test type",
            "superTypes": [
                "DataSet"
            ],
            "typeVersion": "1.0",
            "attributeDefs": [
                {
                    "name": "subject_area_name",
                    "typeName": "string",
                    "isOptional": true,
                    "cardinality": "SINGLE",
                    "isUnique": false,
                    "isIndexable": true
                }
            ]
        }
    ]
}

添加可选属性:

{
    "name": "subject_area_id",
    "typeName": "string",
    "isOptional": true,
    "cardinality": "SINGLE",
    "isUnique": false,
    "isIndexable": true
}

放置:/api/atlas/v2/types/typedefs

{
    "enumDefs": [],
    "structDefs": [],
    "classificationDefs": [],
    "entityDefs": [
        {
            "category": "ENTITY",
            "guid": "d711c846-06a4-4965-b490-f603e16ca29e",
            "createdBy": "admin",
            "updatedBy": "admin",
            "createTime": 1549344291502,
            "updateTime": 1549344291502,
            "version": 1,
            "name": "test",
            "description": "test type",
            "typeVersion": "1.0",
            "attributeDefs": [
                {
                    "name": "subject_area_id",
                    "typeName": "string",
                    "isOptional": true,
                    "cardinality": "SINGLE",
                    "isUnique": false,
                    "isIndexable": true
                },
                {
                    "name": "subject_area_name",
                    "typeName": "string",
                    "isOptional": true,
                    "cardinality": "SINGLE",
                    "valuesMinCount": 0,
                    "valuesMaxCount": 1,
                    "isUnique": false,
                    "isIndexable": true,
                    "includeInNotification": false
                }
            ],
            "superTypes": [
                "DataSet"
            ],
            "subTypes": []
        }
    ],
    "relationshipDefs": []
}

这将使用附加属性更新类型。 详细的 REST 文档可以在这里找到

于 2019-02-05T05:41:02.460 回答