如何在aws胶水中重新分配到新柱子?

时间:2018-01-11 06:36:28

标签: python amazon-web-services aws-glue

假设datasource(csv)包含2列:code:stringmy_date:date。我尝试添加额外的列 - my_date_string:string并将其写入orc格式,并在该列上使用分区:

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

## @params: [JOB_NAME]
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 = "my_database", table_name = "my_table", transformation_ctx = "datasource0")
applymapping1 = ApplyMapping.apply(frame = datasource0, mappings =[
                   ("code", "string", "code", "string"),
                   ("my_date", "date", "my_date", "date"),
                   ("my_date_string", "string", "my_date_string", "string")
                   ],
    transformation_ctx="applymapping1")
resolvechoice2 = ResolveChoice.apply(frame = applymapping1, choice = "make_struct", transformation_ctx = "resolvechoice2")
dropnullfields3 = DropNullFields.apply(frame = resolvechoice2, transformation_ctx = "dropnullfields3")

partitioned_dataframe = dropnullfields3.toDF().repartition("my_date_string")

partitioned_dataframe.toDF().write.orc(
    "s3://path/my_table",
    mode="append",
    partitionBy=['my_date_string'])

job.commit()

我得到了例外:

IllegalArgumentException: u"requirement failed: The number of columns doesn't match.\nOld column names (2): code" \
                          u", my_date"
New column names (0): "
End of LogType:stdout

看起来根本没有添加新列! :(

但是当我删除重新分区语句时,它会写下所有列(例如所有旧的和新的)。如何解决这个问题? performa column"添加"在重新分配srats之前?

0 个答案:

没有答案