SparkSQL內建函式

2021-08-25 05:19:26 字數 689 閱讀 3424

統計每日uv和銷售額

這裡使用內建函式 countdistinct

//每天都有很多使用者來訪問,但是每個使用者可能每天會訪問很多次

//所以uv,指的是,對使用者進行去重以後的訪問次數(去重統計總數)

//首先,對dataframe呼叫groupby()方法,對某一列進行分組

//然後呼叫agg()方法,第乙個引數,必須必須必須傳入之前在groupby()方法中出現的字段

//第二個引數,傳入countdistinct('userid),sum,first等,spark提供的內建函式

//內建函式中,傳入的引數,也是用單引號作為字首的,

useraccesslogrowdf.groupby("date")

.agg('date,countdistinct('userid))

.map(row => row(row(1),row(2)))

.collect()

.foreach(println)

//開始進行每日銷售額的統計

usersalerowdf.groupby("date")

.agg('date,sum('sale))

.map(row => row(row(1),row(2)))

.collect()

.foreach(println)

spark sql內建函式

在spark 1.5.x版本,增加了一系列內建函式到dataframe api中,並且實現了code generation的優化。與普通的函式不同,dataframe的函式並不會執行後立即返回乙個結果值,而是返回乙個column物件,用於在並行作業中進行求值。column可以用在dataframe的...

Spark SQL中開窗函式詳解

row number 開窗函式 其實就是給每個分組的資料,按照其排序的順序,打上乙個分組內的行號,相當於grouptopn,在實際應用中非常廣泛。deptname name salary dept 1 michael 3000 dept 2 andy 5000 dept 1 alex 4500 de...

mysql 檢視內建函式 mysql內建函式

一 字串函式 1.concat s1,s2.sn 把傳入的引數連線成乙個字串 2.insert str,x,y,str 從str的x位置開始,替換y長度的字串為str,select insert abcdefg 2,3,hello 3.lower str upper str 將字串轉換為大寫,小寫 ...