Classe DropNullFields
Rejette tous les champs null dans un DynamicFrame dont le type est NullType. Il s'agit des champs comportant des valeurs manquantes ou nulles dans chaque enregistrement de l'ensemble de données DynamicFrame.
exemple
Cet exemple utilise DropNullFields pour créer un nouveau DynamicFrame où les champs de type NullType ont été abandonnés. Afin de démontrer DropNullFields, nous ajoutons une nouvelle colonne nommée empty_column de type null pour le jeu de données persons déjà chargé.
Note
Pour accéder au jeu de données utilisé dans cet exemple, voir Exemple de code : Données de jonction et de mise en relation et suivez les instructions de la sectionÉtape 1 : analyser les données dans le compartiment Amazon S3.
# Example: Use DropNullFields to create a new DynamicFrame without NullType fields from pyspark.context import SparkContext from awsglue.context import GlueContext from pyspark.sql.functions import lit from pyspark.sql.types import NullType from awsglue.dynamicframe import DynamicFrame from awsglue.transforms import DropNullFields # Create GlueContext sc = SparkContext.getOrCreate() glueContext = GlueContext(sc) # Create DynamicFrame persons = glueContext.create_dynamic_frame.from_catalog( database="legislators", table_name="persons_json" ) print("Schema for the persons DynamicFrame:") persons.printSchema() # Add new column "empty_column" with NullType persons_with_nulls = persons.toDF().withColumn("empty_column", lit(None).cast(NullType())) persons_with_nulls_dyf = DynamicFrame.fromDF(persons_with_nulls, glueContext, "persons_with_nulls") print("Schema for the persons_with_nulls_dyf DynamicFrame:") persons_with_nulls_dyf.printSchema() # Remove the NullType field persons_no_nulls = DropNullFields.apply(persons_with_nulls_dyf) print("Schema for the persons_no_nulls DynamicFrame:") persons_no_nulls.printSchema()
Schema for the persons DynamicFrame: root |-- family_name: string |-- name: string |-- links: array | |-- element: struct | | |-- note: string | | |-- url: string |-- gender: string |-- image: string |-- identifiers: array | |-- element: struct | | |-- scheme: string | | |-- identifier: string |-- other_names: array | |-- element: struct | | |-- lang: string | | |-- note: string | | |-- name: string |-- sort_name: string |-- images: array | |-- element: struct | | |-- url: string |-- given_name: string |-- birth_date: string |-- id: string |-- contact_details: array | |-- element: struct | | |-- type: string | | |-- value: string |-- death_date: string Schema for the persons_with_nulls_dyf DynamicFrame: root |-- family_name: string |-- name: string |-- links: array | |-- element: struct | | |-- note: string | | |-- url: string |-- gender: string |-- image: string |-- identifiers: array | |-- element: struct | | |-- scheme: string | | |-- identifier: string |-- other_names: array | |-- element: struct | | |-- lang: string | | |-- note: string | | |-- name: string |-- sort_name: string |-- images: array | |-- element: struct | | |-- url: string |-- given_name: string |-- birth_date: string |-- id: string |-- contact_details: array | |-- element: struct | | |-- type: string | | |-- value: string |-- death_date: string |-- empty_column: null null_fields ['empty_column'] Schema for the persons_no_nulls DynamicFrame: root |-- family_name: string |-- name: string |-- links: array | |-- element: struct | | |-- note: string | | |-- url: string |-- gender: string |-- image: string |-- identifiers: array | |-- element: struct | | |-- scheme: string | | |-- identifier: string |-- other_names: array | |-- element: struct | | |-- lang: string | | |-- note: string | | |-- name: string |-- sort_name: string |-- images: array | |-- element: struct | | |-- url: string |-- given_name: string |-- birth_date: string |-- id: string |-- contact_details: array | |-- element: struct | | |-- type: string | | |-- value: string |-- death_date: string
Méthodes
__call__(frame, transformation_ctx = "", info = "", stageThreshold = 0, totalThreshold = 0)
Rejette tous les champs null dans un DynamicFrame dont le type est NullType. Il s'agit des champs comportant des valeurs manquantes ou nulles dans chaque enregistrement de l'ensemble de données DynamicFrame.
frame–DynamicFramedans lequel déposer les champs nuls (obligatoire).transformation_ctx– Chaîne unique utilisée pour identifier les informations sur l'état (facultatif).info– Chaîne associée à des erreurs dans la transformation (facultatif).stageThreshold– nombre maximal d'erreurs qui peuvent avoir lieu dans la transformation avant qu'elle ne soit arrêtée.(facultatif) La valeur par défaut est zéro.totalThreshold– nombre maximal d'erreurs pouvant se produire globalement avant que le processus de traitement des erreurs ne soit arrêté.(facultatif) La valeur par défaut est zéro.
Renvoie un nouveau DynamicFrame sans champ null.
apply(cls, *args, **kwargs)
cls– cls
name(cls)
cls– cls
describeArgs(cls)
cls– cls
describeReturn(cls)
cls– cls
describeTransform(cls)
cls– cls
describeErrors(cls)
cls– cls
describe(cls)
cls– cls