LoginSignup
0
1

More than 5 years have passed since last update.

Sparkチートシート

Last updated at Posted at 2018-01-25

カラムが存在するかどうか知りたいとき

def has_column(df, col):
    df.createOrReplaceTempView('df')
    try:
        spark.sql("""select {0} from df""".format(col))
        return True
    except :
        return False

if has_column(dataframe, "hogehoge"):
    print("yes")
else:
    print("no")

pythonライブラリを全ノードに配布したいとき

必要なpyをdependencies.zipに圧縮する。このとき、ライブラリがdependencies.zipのトップに来るようにすること

spark-submit --py-files dependencies.zip main.py

次のようにすると全ノードにpip install したものを配布できる
https://stackoverflow.com/questions/36461054/i-cant-seem-to-get-py-files-on-spark-to-work
http://blog.danielcorin.com/code/2015/11/10/pyspark.html

pip install -t dependencies -r requirements.txt
cd dependencies
zip -r ../dependencies.zip .
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1