pyspark.sql.SQLContext
Top funcs:
1. 创建DF createDataFrame(data,schema)
2. 从多种数据源读取数据,sqlContext
3. user-define类
registerDataFrameAsTable(df, tableName)
registerFunction(name, f, returnType=StringType)
4. 在sqlContext执行sql语句(Hive-ql)
pyspark.sql.DataFrame
1.
collect
2. 行操作:
filter=where
distinct
dropDuplicates=drop_duplicates
dropna
3. 列操作:
select
withColumn 加列
withColumnRenamed 重命名列
Col.cast(Types) 转换格式
Col.between(l,u)
inSet isin(new)
F.when().when().otherwise() 条件
Col.substr(startPos,len)
alias 别名列
4. groupBy操作
agg
5. Map类
map
flatMap
foreach
6. join, intersect, unionAll, subtract, orderBy
7. DataFrameReader
两种读取方式:
sqlContext.read.format(‘FORMAT’).load(‘PATH’)
sqlContext.read.load(path,format,schema,**options)
8. DataFrameWriter
两种写入方式:
df.write.format(‘FORMAT’).save(path)
df.save(path,format,mode,**options)
saveAsTable
pyspark.sql.types
from pyspark.sql.types import *
StringType
BooleanType
DataType
TimestampType
DecimalType
DoubleType
FloatType
IntegerType
StructType
pyspark.sql.functions