由于ApplyMapping不区分大小写,如何确定需要哪些列?

2024-10-05 15:22:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用一个新的数据库模型更新一个Pyspark脚本,我遇到了一些调用/更新列的问题,因为Pyspark显然将所有列都用大写,但是当我使用ApplyMapping时,它不区分大小写,但是当我与另一个表连接(左)时,它区分大小写,并且我最终得到了多个同名的列但是其中一个是大写的,另一个是小写的,我想使用SelectFields函数。你知道吗

我尝试了完全相同的名称(区分大小写)的列,但它总是带来相同的。你知道吗

我试过打印模式,但唯一不同的是情况不同。你知道吗

testDF = testDF.join(test2DF, "COLUMN",how='left')

test3DF=test3DF.withColumn("column", test3DF['ATTRB'].substr(4,4))

fullDF= testDF.join(test3DF, (testDF['ID'] == test3DF['ID']) )

。。。。。你知道吗

applymappingTest = ApplyMapping.apply(frame = fullDF, mappings = [
    ('ID', 'string', 'identifier', 'string')
    ('column', 'string', 'myColumn', 'string')
    ('COLUMN', 'string', 'someother', 'string')
    ], transformation_ctx = "applymappingTest")

。。。。。。你知道吗

selectfieldsTest= SelectFields.apply(frame = applymappingTest, paths = [
     "identifier",
     "myColumn",
], transformation_ctx = "selectfieldsTest")
Expected result:
myColumn is the column with the name in lowercase.
Actual result: 
myColumn is the column with the name in uppercase.

Tags: theidstringcolumnpyspark区分join大写
1条回答
网友
1楼 · 发布于 2024-10-05 15:22:38

可以在applymapping中设置区分大小写的选项。你知道吗

def applyMapping( mappings : Seq[Product4[String, String, String, String]], caseSensitive : Boolean = true, transformationContext : String = "", callSite : CallSite = CallSite("Not provided", ""), stageThreshold : Long = 0, totalThreshold : Long = 0 ) : DynamicFrame 

https://docs.aws.amazon.com/glue/latest/dg/glue-etl-scala-apis-glue-dynamicframe-class.html#glue-etl-scala-apis-glue-dynamicframe-class-defs-applyMapping

顺便说一句,如果我没有错的话,applyMapping在默认情况下是区分大小写的。但是sparksql在默认情况下是不区分大小写的。要在spark SQL中设置区分大小写,可以使用: spark_session.sql('set spark.sql.caseSensitive=true')

相关问题 更多 >