【问题标题】:How to union several datasets with the same schema in Palantir Foundry?如何在 Palantir Foundry 中合并多个具有相同模式的数据集?
【发布时间】:2022-07-06 20:58:48
【问题描述】:

我想在 Palantir Foundry 中合并几个数据集。我提前知道数据集是什么。所有数据集的架构都是相同的(即它们具有相同的列名和列类型)。

组合(联合)这些数据集的最佳方法是什么?

数据集 A:

col1 col2
1 a
2 b

数据集 B:

col1 col2
2 c
3 d

数据集 C:

col1 col2
1 e
1 f

期望的输出:

col1 col2
1 a
2 b
2 c
3 d
1 e
1 f

【问题讨论】:

    标签: palantir-foundry


    【解决方案1】:

    您可以为此使用数据集视图。数据集视图是 Palantir Foundry 数据集,它不包含任何包含数据的文件,但在读取时由其他数据集(称为支持数据集)的联合组成。这意味着构建视图的速度非常快,而且视图非常节省空间,因为它们不会复制数据。

    创建视图:

    1. 导航到要创建视图的位置
    2. 点击绿色的+ New 按钮,然后在下拉菜单中选择“查看”
    3. 在新创建的视图中,查看“详细信息”选项卡。
    4. 单击+ Add backing dataset 按钮并添加要合并的数据集

    然后您可以使用视图,就好像它是数据集并集的结果一样。例如,您可以将其用作轮廓分析的基础数据集或支持本体对象。

    通过搜索“视图”产品,可以在 Foundry 平台内文档中找到有关视图的更多文档。

    【讨论】:

      【解决方案2】:

      要在 Foundry Code Repositories 或 Code Workbook 中使用两个数据集在 Python 转换中执行此操作,您可以使用 PySpark 的 unionByName 函数:

      from transforms.api import transform_df, Input, Output
      
      @transform_df(
          Output("/path/to/dataset/unioned"),
          source_df_1=Input("/path/to/dataset/one"),
          source_df_2=Input("/path/to/dataset/two"),
      )
      def compute(source_df_1, source_df_2):
          return source_df_1.unionByName(source_df_2)
      

      【讨论】:

        【解决方案3】:

        要在 Foundry Code Repositories 或 Code Workbook 中包含多个数据集的 Python 转换中执行此操作,您可以使用转换动词帮助器 D.union_many:

        from transforms.api import transform_df, Input, Output
        from transforms.verbs import dataframes as D
        
        @transform_df(
            Output("/path/to/dataset/unioned"),
            source_df_1=Input("/path/to/dataset/one"),
            source_df_2=Input("/path/to/dataset/two"),
            source_df_3=Input("/path/to/dataset/three"),
        )
        def compute(source_df_1, source_df_2, source_df_3):
            return D.union_many(
                source_df_1,
                source_df_2,
                source_df_3,
            )
        

        【讨论】:

          猜你喜欢
          • 2021-06-23
          • 2022-08-19
          • 2011-06-07
          • 2012-11-26
          • 1970-01-01
          • 2021-03-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多