spark-sql 写代码方式
1、idea里面将代码编写好打包上传到集群中运行,上线使用
spark-submit提交
2、spark shell (repl) 里面使用sqlContext 测试使用,简单任务使用 spark-shell --master yarn-client 不能使用yarn-cluster 3、spark-sql spark-sql --master yarn-client 不能使用yarn-cluster 可以整合hive 使用hive的元数据 1、在hive的hive-site.xml修改一行配置,增加了这一行配置之后,以后在使用hive之前都需要先启动元数据服务
3、启动hive元数据服务 hive --service metastore 或 nohup hive --service metastore >> metastore.log 2>&1 & 4、 将hive中的mysql 驱动包复制到saprk jars目录下 cp mysql-connector-java-5.1.49.jar /usr/local/soft/spark-2.4.5/jars/ 整合好之后在spark-sql 里面就可以使用hive的表了 spark-sql --master yarn-client --conf spark.sql.shuffle.partitions=2 不能使用cluster模式 在spark-sql中设置运行参数 set spark.sql.shuffle.partitions=2;
create table student
(
id string,
name string,
age int,
gender string,
clazz string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS textfile
location '/spark/data/stu/input/';
create table score
(
student_id string,
cource_id string,
sco int
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS textfile
location '/data/score/';