AWS胶 - iLlegalargumentException:路径的重复值

发布于 2025-01-29 11:27:31 字数 1595 浏览 3 评论 0原文

我有一个混乱的数据源,其中某些字段值可以带有两个不同的名称,但应映射到输出上的一个符合的字段名称。

例如,数据源包含update_datemodified_date,并且两个都应映射到timestamp

两个字段名称永远不会同时存在于同一行数据上。

胶脚本看起来像这样。有些线已被编辑为清晰:

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

args = getResolvedOptions(sys.argv, ["JOB_NAME"])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args["JOB_NAME"], args)

# Script generated for node Data Catalog table
DataCatalogtable_node1 = glueContext.create_dynamic_frame.from_catalog(
    database="mydb",
    table_name="crawl_rawdata",
    transformation_ctx="DataCatalogtable_node1",
)

# Script generated for node ApplyMapping
ApplyMapping_node2 = ApplyMapping.apply(
    frame=DataCatalogtable_node1,
    mappings=[
        ...
        ("update_date", "string", "timestamp", "string"),
        ...
        ("modified_date", "string", "timestamp", "string"),
        ...
    ],
    transformation_ctx="ApplyMapping_node2",
)

# Script generated for node S3 bucket
S3bucket_node3 = glueContext.write_dynamic_frame.from_options(
    frame=ApplyMapping_node2,
    connection_type="s3",
    format="orc",
    connection_options={
        "path": "s3://mybucket/data-lake/glue/",
        "compression": "snappy",
        "partitionKeys": [ ... ],
    },
    transformation_ctx="S3bucket_node3",
)

job.commit()

如何使其运行?

I have a messy data source where some field values can come in with two different names but should map to one conformed field name on the output.

e.g. data source contains update_date or modified_date and both should map to timestamp.

Both field names are never present simultaneously on the same row of data.

The glue script looks like this. Some lines have been redacted for clarity:

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

args = getResolvedOptions(sys.argv, ["JOB_NAME"])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args["JOB_NAME"], args)

# Script generated for node Data Catalog table
DataCatalogtable_node1 = glueContext.create_dynamic_frame.from_catalog(
    database="mydb",
    table_name="crawl_rawdata",
    transformation_ctx="DataCatalogtable_node1",
)

# Script generated for node ApplyMapping
ApplyMapping_node2 = ApplyMapping.apply(
    frame=DataCatalogtable_node1,
    mappings=[
        ...
        ("update_date", "string", "timestamp", "string"),
        ...
        ("modified_date", "string", "timestamp", "string"),
        ...
    ],
    transformation_ctx="ApplyMapping_node2",
)

# Script generated for node S3 bucket
S3bucket_node3 = glueContext.write_dynamic_frame.from_options(
    frame=ApplyMapping_node2,
    connection_type="s3",
    format="orc",
    connection_options={
        "path": "s3://mybucket/data-lake/glue/",
        "compression": "snappy",
        "partitionKeys": [ ... ],
    },
    transformation_ctx="S3bucket_node3",
)

job.commit()

How to make it work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2025-02-05 11:27:31

您能否提供有关引起此错误的行的信息?您可以在AWS日志中找到它。我也遇到了同样的错误。就我而言,解决方案只是用此字符串列表替换一个字符串列表。让我向您展示一个代码:

#This raises the IllegalArgumentException: Duplicate value for path
list_of_columns = ["col_a","col_b"]
data.select_fields(list_of_columns)

#This raises no error
data.select_fields( ["col_a","col_b"])

Could you provide the information about the line that is provoking this error? You can find it in AWS logs. I also experienced the same error. In my case, the solution was just replacing a variable with a list of strings with this list of strings. Let me show you a piece of code:

#This raises the IllegalArgumentException: Duplicate value for path
list_of_columns = ["col_a","col_b"]
data.select_fields(list_of_columns)

#This raises no error
data.select_fields( ["col_a","col_b"])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文