Poznámka:
Přístup k této stránce vyžaduje autorizaci. Můžete se zkusit přihlásit nebo změnit adresáře.
Přístup k této stránce vyžaduje autorizaci. Můžete zkusit změnit adresáře.
Agregační funkce: Vrátí zřetězení jedinečných vstupních hodnot, které nejsou null oddělené oddělovačem. Alias .listagg_distinct
Syntaxe
import pyspark.sql.functions as sf
sf.string_agg_distinct(col=<col>)
# With delimiter
sf.string_agg_distinct(col=<col>, delimiter=<delimiter>)
Parametry
| Parameter | Typ | Description |
|---|---|---|
col |
pyspark.sql.Column nebo str |
Cílový sloupec pro výpočet. |
delimiter |
pyspark.sql.Column, str nebo bytes |
Optional. Oddělovač pro oddělení hodnot. Výchozí hodnota je None. |
Návraty
pyspark.sql.Column: sloupec pro vypočítané výsledky.
Examples
Příklad 1: Použití funkce string_agg_distinct
import pyspark.sql.functions as sf
df = spark.createDataFrame([('a',), ('b',), (None,), ('c',), ('b',)], ['strings'])
df.select(sf.string_agg_distinct('strings')).show()
+----------------------------------+
|string_agg(DISTINCT strings, NULL)|
+----------------------------------+
| abc|
+----------------------------------+
Příklad 2: Použití funkce string_agg_distinct s oddělovačem
import pyspark.sql.functions as sf
df = spark.createDataFrame([('a',), ('b',), (None,), ('c',), ('b',)], ['strings'])
df.select(sf.string_agg_distinct('strings', ', ')).show()
+--------------------------------+
|string_agg(DISTINCT strings, , )|
+--------------------------------+
| a, b, c|
+--------------------------------+
Příklad 3: Použití funkce string_agg_distinct s binárním sloupcem a oddělovačem
import pyspark.sql.functions as sf
df = spark.createDataFrame([(b'\x01',), (b'\x02',), (None,), (b'\x03',), (b'\x02',)],
['bytes'])
df.select(sf.string_agg_distinct('bytes', b'\x42')).show()
+---------------------------------+
|string_agg(DISTINCT bytes, X'42')|
+---------------------------------+
| [01 42 02 42 03]|
+---------------------------------+
Příklad 4: Použití funkce string_agg_distinct ve sloupci se všemi hodnotami None
import pyspark.sql.functions as sf
from pyspark.sql.types import StructType, StructField, StringType
schema = StructType([StructField("strings", StringType(), True)])
df = spark.createDataFrame([(None,), (None,), (None,), (None,)], schema=schema)
df.select(sf.string_agg_distinct('strings')).show()
+----------------------------------+
|string_agg(DISTINCT strings, NULL)|
+----------------------------------+
| NULL|
+----------------------------------+