spark启动方式

1.Spark Sql命令行

'''
// 启动 Spark SQL 命令行(类似 hive 命令)
$SPARK_HOME/bin/spark-sql

// 带参数的启动
$SPARK_HOME/bin/spark-sql
--master local[2]
--conf spark.sql.warehouse.dir=/path/to/warehouse
--database default
'''

2.Spark Shell交互式环境

'''
// 启动 Scala Spark Shell
$SPARK_HOME/bin/spark-shell

// 在 shell 中执行
scala> val df = spark.sql("SELECT * FROM users")
scala> df.show()
scala> :quit
'''

3.PySpark Shell

'''
// 启动 PySpark Shell
$SPARK_HOME/bin/pyspark

// 在 shell 中执行

df = spark.sql("SELECT name, age FROM people")
df.filter(df.age > 30).show()
exit()
'''

4.直接执行sql文件

'''
// 像 hive -f 一样执行 SQL 文件
$SPARK_HOME/bin/spark-sql -f query.sql

// 执行单条 SQL 语句
$SPARK_HOME/bin/spark-sql -e "SHOW TABLES"

// 执行多条 SQL 语句
$SPARK_HOME/bin/spark-sql -e "
SHOW DATABASES;
USE my_database;
SELECT count(*) FROM users;
"
'''

5.执行编译好的jar包

'''
// 提交编译好的 JAR 包
$SPARK_HOME/bin/spark-submit
--class com.mycompany.MySparkJob
--master yarn
--deploy-mode cluster
--executor-memory 2G
--num-executors 10
/path/to/my-spark-job.jar

// 提交 Python 脚本
$SPARK_HOME/bin/spark-submit
--master local[4]
--name "My Python Job"
/path/to/my_script.py
'''