【问题标题】:How to delete a file from dataset view in Foundry?如何从 Foundry 的数据集视图中删除文件?
【发布时间】:2022-11-07 20:35:15
【问题描述】:

我在数据集视图中有几个文件:

如何删除“test.json”? UI 似乎不提供这种可能性。如何使用 API 做到这一点?

【问题讨论】:

    标签: file dataset delete-file palantir-foundry palantir-foundry-api


    【解决方案1】:

    可以使用多个目录 API 调用:
    startTransaction
    setTransactionType
    addFilesToDeleteTransaction
    commitTransaction

    import requests
    
    token = 'your_token'
    fullhost = 'https://your_hostname'
    dataset_rid = 'ri.foundry.main.dataset.d2c177b6-5331-4fa1-b09c-bc9b2d18b292'
    branch_id = 'master'
    file = 'test.json'
    headers={
        'content-type': 'application/json',
        'Authorization': 'Bearer ' + token
    }
    
    # Start transaction
    response = requests.post(
        url=f'{fullhost}/foundry-catalog/api/catalog/datasets/{dataset_rid}/transactions',
        headers=headers,
        data=f'{{"branchId": "{branch_id}"}}'
    )
    tx_rid = response.json()['rid']
    
    # Set transaction type (delete)
    response = requests.post(
        url=f'{fullhost}/foundry-catalog/api/catalog/datasets/{dataset_rid}/transactions/{tx_rid}',
        headers=headers,
        data='"DELETE"'
    )
    
    # Specify the file to be deleted
    response = requests.post(
        url=f'{fullhost}/foundry-catalog/api/catalog/datasets/{dataset_rid}/transactions/{tx_rid}/files/addToDeleteTransaction',
        headers=headers,
        data=f'{{"logicalPaths": ["{file}"]}}'
    )
    
    # Commit transaction
    response = requests.post(
        url=f'{fullhost}/foundry-catalog/api/catalog/datasets/{dataset_rid}/transactions/{tx_rid}/commit',
        headers=headers,
        data='{}'
    )
    

    结果:

    【讨论】:

      猜你喜欢
      • 2022-11-02
      • 2020-10-10
      • 1970-01-01
      • 1970-01-01
      • 2018-12-17
      • 2017-02-10
      • 2014-12-19
      • 2015-08-23
      • 1970-01-01
      相关资源
      最近更新 更多