简体   繁体   English

AWS Glue连接错误

[英]AWS Glue Join Error

We have data(Tables) in S3 bucket(CSV) and need to apply join transformation and Store the result in S3. 我们在S3存储桶(CSV)中有数据(表),需要应用联接转换并将结果存储在S3中。 The Joining of tables is successful But the resulting Column List in S3 is Jumbled, order is not maintained in Output File. 表连接成功,但是S3中的列列表混乱,输出文件中不保留顺序。 Also output file contains extra quotes(") and dots(.) 输出文件还包含额外的引号(“)和点(。)。

On applying only Mappings the order doesn't change ,Produces proper output without Jumbling. 仅应用映射时,顺序不变,产生正确的输出而不会产生混乱。

Script is in python or Scala. 脚本在python或Scala中。

Script : 剧本:

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)

datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "testdb", table_name = "table1", transformation_ctx = "datasource0")

datasource1 = glueContext.create_dynamic_frame.from_catalog(database = "testdb", table_name = "reftable", transformation_ctx = "datasource1")

datasource2 =datasource1.join(["aaaaaaaaaid"],["aaaaaaaaaid"],datasource0,transformation_ctx="join") 


datasink2 = glueContext.write_dynamic_frame.from_options(frame = datasource2, connection_type = "s3", connection_options = {"path": "s3://testing/Output"}, format = "csv", transformation_ctx = "datasink2")
job.commit()

Need Help !!! 需要帮忙 !!!

Can you try this: 你可以尝试一下:

datasource2  = Join.apply(datasource0, datasource1, 'aaaaaaaaaid', 'aaaaaaaaaid')

This should work. 这应该工作。 Let me know, and also kindly accept/upvote the answer if this helped resolve the problem. 让我知道,如果可以帮助解决问题,也请接受/支持答案。

Regards 问候

Yuva 尤瓦

I know this is old, Just mentioning the approach that worked for me. 我知道这很老,只说对我有用的方法。

  1. Convert to data frames 转换为数据框
  2. Join them. 加入他们。

as mentioned in https://stackoverflow.com/a/54362245/8622986 https://stackoverflow.com/a/54362245/8622986中所述

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM