В этом примере он не заменяет значение my_struct.struct_string< /код>:
Код: Выделить всё
from awsglue.context import GlueContext
from pyspark.context import SparkContext
from pyspark.sql.functions import col
from pyspark.sql.types import StringType, StructType, StructField
glueContext = GlueContext(SparkContext.getOrCreate())
data = [
("null", {"struct_string": "null"}),
]
schema = StructType([
StructField("a_string", StringType(), True),
StructField(
"my_struct",
StructType([
StructField("struct_string", StringType(), True),
]),
True
)
])
df = spark.createDataFrame(data, schema)
df = df.replace("null", None)
df_astring = df.filter(col("a_string").isNotNull())
df_struct_string = df.filter(col("my_struct.struct_string").isNotNull())
print("My df_astring")
df_astring.show()
print("My df_struct_string")
df_struct_string.show()
Код: Выделить всё
My df_astring
+--------+---------+
|a_string|my_struct|
+--------+---------+
+--------+---------+
My df_struct_string
+--------+---------+
|a_string|my_struct|
+--------+---------+
| null| {null}|
+--------+---------+
Решение должно быть динамическим, поэтому оно не будет вручную точно указывать имя столбца, строка.
Подробнее здесь: https://stackoverflow.com/questions/792 ... -structure
Мобильная версия