胶水工作成功,但没有插入目标表(Aurora mysql)的数据
我使用以下“视觉”选项卡创建了一个胶水作业。首先,我将数据源连接到MySQL表中,该数据源已经在我的数据目录中。然后,在“转换节点”中,我编写了一个自定义SQL查询,以从源表中选择一个列。用数据预览功能验证,转换节点正常工作。现在,我想将数据写入现有数据库表,该数据库表只有一个带有“字符串”数据类型的列。胶水工作成功了,但我看不到表中的数据。
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
from awsglue import DynamicFrame
def sparkSqlQuery(glueContext, query, mapping, transformation_ctx) -> DynamicFrame:
for alias, frame in mapping.items():
frame.toDF().createOrReplaceTempView(alias)
result = spark.sql(query)
return DynamicFrame.fromDF(result, glueContext, transformation_ctx)
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 MySQL
MySQL_node1650299412376 = glueContext.create_dynamic_frame.from_catalog(
database="glue_rds_test",
table_name="test_customer",
transformation_ctx="MySQL_node1650299412376",
)
# Script generated for node SQL
SqlQuery0 = """
select CUST_CODE from customer
"""
SQL_node1650302847690 = sparkSqlQuery(
glueContext,
query=SqlQuery0,
mapping={"customer": MySQL_node1650299412376},
transformation_ctx="SQL_node1650302847690",
)
# Script generated for node MySQL
MySQL_node1650304163076 = glueContext.write_dynamic_frame.from_catalog(
frame=SQL_node1650302847690,
database="glue_rds_test",
table_name="test_customer2",
transformation_ctx="MySQL_node1650304163076",
)
job.commit()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
for 问题是问题SQL查询中选定字段的双重报价。丢弃使用双引号的使用解决了。在
例如,我“错误地”使用了此查询语法:
而不是此“正确”一个:
您的共享示例代码似乎没有此语法问题,但是我认为将答案放在这里可能有帮助其他的。
For me the problem was the double-quotes of the selected fields in the SQL query. Dropping the use of double quotes solved it. There is no mention of it in the Spark SQL Syntax documentation
For example, I "wrongly" used this query syntax:
instead of this "correct" one :
Your shared sample code does not seem to have this syntax issue, but I thought putting the answer here might be of a help to others.