簡體   English   中英

Palantir foundry 代碼工作簿,從數據集中導出單個 xml

[英]Palantir foundry code workbook, export individual xmls from dataset

我有一個數據集,它有一個 xml 列,我正在嘗試使用 codeworkbook 將單個 xml 導出為文件名在另一列中的文件

在此處輸入圖像描述

我使用下面的代碼過濾了我想要的行

def prepare_input(xml_with_debug):
    from pyspark.sql import functions as F

    filter_column = "key"
    filter_value = "test_key"
    df_filtered = xml_with_debug.filter(filter_value == F.col(filter_column))

    approx_number_of_rows = 1
    sample_percent = float(approx_number_of_rows) / df_filtered.count()

    df_sampled = df_filtered.sample(False, sample_percent, seed=0)

    important_columns = ["key", "xml"]

    return df_sampled.select([F.col(c).cast(F.StringType()).alias(c) for c in important_columns])

它工作到這里。 現在對於最后一部分,我在 python 任務中嘗試了這個,但抱怨參數(我應該錯誤地設置它)。 但即使它有效,我認為它也將作為一個文件。

from transforms.api import transform, Input, Output
@transform(
     output=Output("/path/to/python_csv"),
     my_input=Input("/path/to/input")
)
def my_compute_function(output, my_input):
     output.write_dataframe(my_input.dataframe().coalesce(1), output_format="csv", options={"header": "true"})

我正在嘗試在 GUI 中進行設置,如下所示

在此處輸入圖像描述

我想我的問題是,在准備輸入之后,最后一個 Python 任務(write_file)中的代碼是什么,以便我提取單個 xml(如果可能的話,將它們 zip 放入單個文件以供下載)

您可以訪問 output 數據集文件系統並以您想要的任何格式將文件寫入其中。
相關文檔可在此處找到: https://www.palantir.com/docs/foundry/code-workbook/transforms-unstructured/#writing-files
(如果您想從代碼存儲庫中執行它,它非常相似https://www.palantir.com/docs/foundry/transforms-python/unstructured-files/#writing-files

通過這樣做,您可以創建多個不同的文件,或者您可以創建一個 zip 文件並將其寫入數據集。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM