我在PySpark中有以下功能
import pyspark.sql.functions as func
def get_num(self, spark, id):
df = spark \
.read \
.format("org.elasticsearch.spark.sql") \
.load("myindex") \
.filter(func.col("id") == id) \
.groupBy("id") \
.agg(
func.count(func.lit(1)).alias("number_occurrences_today"),
func.countDistinct("host_id").alias("number_hosts")
)
如果df
是None,函数应该返回0,0。否则,它应该为id
返回number_occurrences_today
和number_hosts
的值
我怎么做
这就是我迄今为止所尝试的:
if (df is None):
return 0, 0
else:
return df["number_occurrences_today"], df["number_hosts"]
目前没有回答
相关问题 更多 >
编程相关推荐