如何在 Foundry 中回滚数据集事务?

How can I roll-back a dataset transaction in Foundry?

我在 Foundry 上有一个增量数据集,上传的文件包含不正确的数据。我如何撤销此交易以便我可以使用正确的数据更新数据集?

您可以使用 foundry 的目录 API。您首先需要找到要恢复到的事务的资源 ID(删除),当您 select Monocle 中的数据集时,可以在历史选项卡下找到它。 您还需要删除您的数据集,以及您在铸造厂实例上生成的不记名令牌。 运行 下面在 unix 中 command-line 或者使用 python requests library。 (如果您使用的是 Windows 机器,请求库可能会有用)

curl -X POST \
    "https://<CATALOG_URL>/api/catalog/datasets/<DATASET_RID>/branchesUpdate2/master" \
    -H "Authorization: Bearer <TOKEN>" \
    -H "Content-type: application/json" \
    -d '"'<TRANSACTION_RID>'"' \
    -k \
    -w "\n"

将 <> 之间的内容替换为您的相关变量,我在下面展示了一些示例,以便您在看到变量时能够认出它们。请务必保密您的不记名令牌。

<CATALOG_URL>     <- your.url.com/foundry-catalog
<DATASET_RID>     <- ri.foundry.main.dataset.00000000-bbbb-cccc-dddd-000000000000
<TOKEN>           <- ey00000000...00000000
<TRANSACTION_RID> <- "ri.foundry.main.transaction.00000000-bbbb-cccc-dddd-000000000000"

我做过的其他选择是:

  1. 使用 contour 抓取选择的交易并导出为 CSV,然后上传为静态数据集。
  2. 更新架构以确保它是所需的类型。
  3. 如果使用@incremental 声明符,请转到增量代码并将输出数据帧的 set(‘modify’) 更新为 set(‘replace’)。
  4. 添加输入引用或将其替换为静态数据引用。更新逻辑以引用输出的新输入。
  5. 构建数据集(这应该使用您的静态数据做一个快照)
  6. 改回代码以修改并输入回原始参考,并将任何其他代码模式恢复为原始。从那里开始的任何新构建都会增加你所做的最后一个快照 运行。

可能不是很优雅,但已经做过很多次了。

这里有一个 python 函数来实现与 FJ_OC 的 curl 示例相同的功能:

from urllib.parse import quote_plus
import requests

def update_branch(dataset_rid: str,
                  branch: str,
                  parent_branch_or_transaction_rid: str = None,
                  api_base,
                  token) -> dict:
    """
    Updates the latest transaction of branch 'branch' to the latest transaction
    of branch 'parent_branch' OR to the transaction on the same branch given as parameter
    Args:
        dataset_rid: Unique identifier of the dataset
        branch: The branch to update (e.g. master)
        parent_branch_or_transaction_rid: the name of the branch to copy the last transaction
        from or the transaction on the same branch to reset the dataset to

    Returns: branch response, e.g.:
    {'id': '..',
     'rid': 'ri.foundry.main.branch...',
     'ancestorBranchIds': [],
     'creationTime': '',
     'transactionRid': 'ri.foundry.main.transaction....'
     }

    """
    response = requests.post(f"{api_base}/foundry-catalog/api/catalog/datasets/{dataset_rid}/"
                             f"branchesUpdate2/{quote_plus(branch)}",
                             headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {token}'},
                             data=f'"{parent_branch_or_transaction_rid}"'
                            )
    response.raise_for_status()
    return response.json()