Объект Pyspark Raw не обновляетсяPython

Программы на Python
Anonymous
Объект Pyspark Raw не обновляется

Сообщение Anonymous »

Код: Выделить всё

@udf(allPageContentSchemaOutput)
def modifyContent(input_data: List[Row]) -> List[Row]:
modified_data = []
for row in input_data:
item_dict = row.asDict()  # Convert Row to dictionary
components_list = item_dict.get('components', [])
for component in components_list:
component = component.asDict()
if isinstance(component, dict) and 'locale' in component:
component['locale'] = {
'es-us': 'Test',  # Replace with your logic for es-us
'en-us': 'Test2'   # Replace with your logic for en-us
}
modified_data.append(Row(**item_dict))
return modified_data
Я пытаюсь обновить локальный атрибут. Мои входные данные выглядят вот так

Код: Выделить всё

[{"uid":"blt0bbd250f8c97ce90","components":[{"locale":"es-us"}]},{"uid":"blt0bbd250f8c97ce91","components":[{"locale":"es-us"}]}]
Это мой формат выходной схемы

Код: Выделить всё

output_schema = StructType([
StructField("uid", StringType(), True),
StructField("components", ArrayType(StructType([
StructField("locale", MapType(StringType(), StringType()), True)
])), True)
])

# Define the schema for the output data
allPageContentSchemaOutput = ArrayType(output_schema)
В выходной схеме «locale»: null. Похоже, что input_data не изменяется. Можете ли вы помочь в этом, как реструктурировать метод ModifyContent, чтобы изменить input_data и отразить его в allPageContentSchemaOutput.

Подробнее здесь: https://stackoverflow.com/questions/786 ... et-updated

Вернуться в «Python»