【问题标题】:Azure Data Factory Python SDK - Convert PipelineResource to JSONAzure 数据工厂 Python SDK - 将 PipelineResource 转换为 JSON
【发布时间】:2022-07-06 15:10:23
【问题描述】:

我正在使用 Python SDK (azure.mgmt.datafactory.models.PipelineResource) 创建 Azure 数据工厂管道。我需要将 PipelineResource 对象转换为 JSON 文件。有没有可能?

我试过json.loads(pipeline_object)json.dumps(pipeline_object),但没有运气。

【问题讨论】:

    标签: python azure azure-data-factory azure-python-sdk


    【解决方案1】:

    你可以用这个。

    # Create a copy activity
    act_name = 'copyBlobtoBlob'
    blob_source = BlobSource()
    blob_sink = BlobSink()
    dsin_ref = DatasetReference(reference_name=ds_name)
    dsOut_ref = DatasetReference(reference_name=dsOut_name)
    copy_activity = CopyActivity(name=act_name,inputs=[dsin_ref], outputs=[dsOut_ref], source=blob_source, sink=blob_sink)
    
    #Create a pipeline with the copy activity
    
    #Note1: To pass parameters to the pipeline, add them to the json string params_for_pipeline shown below in the format { “ParameterName1” : “ParameterValue1” } for each of the parameters needed in the pipeline.
    #Note2: To pass parameters to a dataflow, create a pipeline parameter to hold the parameter name/value, and then consume the pipeline parameter in the dataflow parameter in the format @pipeline().parameters.parametername.
    
    p_name = 'copyPipeline'
    params_for_pipeline = {}
    
    p_name = 'copyPipeline'
    params_for_pipeline = {}
    p_obj = PipelineResource(activities=[copy_activity], parameters=params_for_pipeline)
    p = adf_client.pipelines.create_or_update(rg_name, df_name, p_name, p_obj)
    print_item(p)
    

    【讨论】:

      【解决方案2】:

      我需要将 PipelineResource 对象转换为 JSON 文件。有没有可能?

      您可以按照mccoyp的建议尝试以下代码sn-p:

      您可以向json.dumps 添加一个默认参数,以使不是JSON 的对象可序列化为dict

      import json
      from azure.mgmt.datafactory.models import Activity, PipelineResource
      
      activity = Activity(name="activity-name")
      resource = PipelineResource(activities=[activity])
      
      json_dict = json.dumps(resource, default=lambda obj: obj.__dict__)
      print(json_dict)
      

      【讨论】:

        猜你喜欢
        • 2022-07-17
        • 2021-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-29
        • 2021-11-27
        • 1970-01-01
        相关资源
        最近更新 更多