运行 SQL 源端的脚本在单个 Glue 作业中的多个 tables 与 S3 的相应 table 命名约定

Running SQL script on the source side on multiple tables in a single Glue Job with corresponding table naming convention to S3

sql_list = ['(select * from table1 where rownum <= 100) alias1','(select * from table2 where rownum <= 100) alias2']

for sql_statement in sql_list: df = spark.read.format("jdbc").option("driver", jdbc_driver_name).option("url", db_url).option("dbtable", sql_statement).option("user", db_username).option("password", db_password).option("fetchSize", 100000).load()

df.write.format("parquet").mode("overwrite").save("s3://s3-location/" + sql_statement)

来源是 Oracle 数据库

我能够 运行 查询数组并将其存储在镶木地板的 S3 上,但使用的命名与 sql_list 中列出的相同,我想存储数据到 S3,分别命名为 alias1 和 alias2。

考虑使用字典而不是列表,因为它更整洁、更灵活。

    sql_list = {'alias1':'(select * from table1 where rownum <= 100) alias1',
                'alias2': '(select * from table2 where rownum <= 100) alias2'}

    for table,sql_statement in sql_list.items():
        df = spark.read.format("jdbc").option("driver", jdbc_driver_name)\
            .option("url",db_url)\
            .option("dbtable", sql_statement)\
            .option("user", db_username)\
            .option("password", db_password)\
            .option("fetchSize",100000).load()

        df.write.format("parquet").mode("overwrite").save("s3://s3-location/" + table)

否则你需要做一些肮脏的分裂

df.write.format("parquet").mode("overwrite").save("s3://s3-location/" + sql_statement.split(' ')[-1])