首页 > 解决方案 > 通过 Matillion AWS 在 Jython 中使用 org.python.core.PyList

问题描述

我在 Matillion ETL 中为 Redshift 运行 Python 脚本组件。该组件使用 Jython,代码如下。由于对象转换错误,我在 context.updateGridVariable 行上收到错误。

我想知道如何实例化一个 org.python.core.PyList 对象,以便我可以填充它,而不是我得到的 java.lang.String。

输出

[u's3://bucket-landingzone/inbox/dt_employees_20180614.csv'] java.lang.ClassCastException: java.lang.ClassCastException: java.lang.String 无法在行号处转换为 org.python.core.PyList 26

代码

import boto3
import json

s3 = boto3.resource('s3')
bucket = "bucket-landingzone"
name = "inbox/dt_employee_20180615"
file_list = []

manifest_object = s3.Object(bucket,name)

file_content = manifest_object.get()['Body'].read().decode('utf-8')
json_content = json.loads(file_content)

for entry in json_content['entries']:
  for attribute, value in entry.iteritems():
    if attribute == 'url':
        file_list.append(value)

print(file_list)

context.updateGridVariable('manifest_entries', file_list)

print(context.getGridVariable('manifest_entries'))

标签: pythonamazon-web-servicesjythonmatillion

解决方案


推荐阅读