在使用pyspark进行sql开发时,很多时候需要往sql中传入参数,这个和scala的使用方式不一样,采用下面的方式可以实现
from pyspark.sql import SparkSession
spark = SparkSession \
.builder \
.appName("Python Spark SQL Hive integration example") \
.enableHiveSupport() \
.getOrCreate()
date = spark.conf.get("spark.date")
print '参数:',date
spark.sql('''select * from table1
where date = '{0}'
'''.format(date)).show()
提交命令:
spark-submit \
--master yarn \
--deploy-mode client \
--num-executors 50 \
--driver-memory 16G \
--driver-cores 8 \
--executor-memory 8G \
--executor-cores 4 \
--conf spark.driver.maxResultSize=16G \
--conf spark.network.timeout=500 \
--conf spark.sql.shuffle.partitions=600 \
--conf spark.yarn.executor.memoryOverhead=8G \
--conf spark.date='20220131' \
test.py