Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Esegue il mapping di un iteratore di batch nel dataframe corrente usando una funzione nativa Python eseguita su pyarrow.RecordBatch sia come input che come output e restituisce il risultato come dataframe.
Sintassi
mapInArrow(func: "ArrowMapIterFunction", schema: Union[StructType, str], barrier: bool = False, profile: Optional[ResourceProfile] = None)
Parametri
| Parametro | Tipo | Descrizione |
|---|---|---|
func |
funzione | una funzione nativa di Python che accetta un iteratore di pyarrow.RecordBatchs e restituisce un iteratore di pyarrow.RecordBatchs. |
schema |
DataType o str | tipo restituito func di in PySpark. Il valore può essere un pyspark.sql.types.DataType oggetto o una stringa di tipo DDL formattato. |
barrier |
bool, facoltativo, false predefinito | Usare l'esecuzione della modalità barriera, assicurandosi che tutti i ruoli di lavoro Python nella fase vengano avviati simultaneamente. |
profile |
ResourceProfile, facoltativo | ResourceProfile facoltativo da usare per mapInArrow. |
Restituzioni
DataFrame
Examples
import pyarrow as pa
df = spark.createDataFrame([(1, 21), (2, 30)], ("id", "age"))
def filter_func(iterator):
for batch in iterator:
pdf = batch.to_pandas()
yield pa.RecordBatch.from_pandas(pdf[pdf.id == 1])
df.mapInArrow(filter_func, df.schema).show()
# +---+---+
# | id|age|
# +---+---+
# | 1| 21|
# +---+---+
df.mapInArrow(filter_func, df.schema, barrier=True).collect()
# [Row(id=1, age=21)]