X-Pack Spark使用[FAQ]

概述

本文主要列出在使用X-Pack Spark的FAQ。

Spark集群使用问题

  1. x-pack spark如何监控核心指标
    https://developer.aliyun.com/ask/138207?groupCode=bigdata

Spark Connectors

主要列举Spark 对接其它数据源遇到的问题

Spark on HBase

  1. Spark on HBase Connector:如何在Spark侧设置HBase参数

Spark on Phoenix

  1. Spark on Phoenix 4.x Connector:如何在Spark侧设置Phoenix参数

Spark SQL

主要列出Spark SQL相关的。

spark 2.4.3以上版本thriftserver对于data类型的字段作为分区,查询不到数据?

答:在查询的时候需要对“2019-06-23”这样的字符串条件过滤使用date做转换

spark SQL 保存结果时如何设置并行度

答:如果使用 Spark 默认的并行度可能会导致 Spark SQL 运行的结果文件产生大量的小文件。一种简单的方法是在保存结果的过程中手动设置并行度。在 Spark 2.4 之前是不支持在 SQL 中设置并行度的,如果你使用 Spark 2.4,可以在 SQL 中使用 Repartition Hint,比如

spark.sql("create table test as select /*+ REPARTITION(4) */ age,count(*) from person where age between 10 and 20 group by age")

spark.sql("insert overwrite test as select /*+ REPARTITION(4) */ age,count(*) from person where age between 10 and 20 group by age")

注意:这种方法设置并行度并不是对如何场景都合适的,最好的办法是提前计算好结果文件的大小,然后每个文件保存多大,再算出一个并行度。

Spark 查询 MySQL、Phoenix等数据库时过滤条件如何下推?

比如我们使用 Spark 的 JDBC 查询 MySQL 的数据有如下的过滤条件

scala> mysql.filter("times1 >= '2019-06-20 00:00:00' and times1 < '2019-06-20 01:00:10'").explain 
== Physical Plan == 
*(1) Filter ((cast(TIMES1#129 as string) >= 2019-06-20 00:00:00) && (cast(TIMES1#129 as string) < 2019-06-20 01:00:10)) 
+- *(1) Scan JDBCRelation(test) [numPartitions=1][ID#126L,IP#127,count#128L,TIMES1#129,TOTAL#130L,TIMES2#131,TIMES3#132,TIME4#133] PushedFilters: [*IsNotNull(TIMES1)], ReadSchema: struct<ID:bigint,IP:string,count:bigint,TIMES1:timestamp,TOTAL:bigint,TIMES2:date,TIMES3:string,T... 

从上面的例子可以看出,过滤条件其实是没有下推的,这样的话查询性能非常差,我们可以如下修改:

scala> mysql.filter("times1 >= to_timestamp('2019-06-20 00:00:00') and times1 < to_timestamp('2019-06-20 01:00:10')").explain 
== Physical Plan == 
*(1) Scan JDBCRelation(test) [numPartitions=1][ID#126L,IP#127,count#128L,TIMES1#129,TOTAL#130L,TIMES2#131,TIMES3#132,TIME4#133] PushedFilters: [*IsNotNull(TIMES1), *GreaterThanOrEqual(TIMES,2019-06-20 00:00:00.0), *LessThan(TIMES,2019-06-20 ..., ReadSchema: struct<ID:bigint,IP:string,count:bigint,TIMES1:timestamp,TOTAL:bigint,TIMES2:date,TIMES3:string,T... 

SparkStreming

SparkStreming使用Checkpoint创建StreamingContext修改executor-cores、executor-memory等资源信息不生效。

答:使用StreamingContext.getOrCreate(checkpointDirectory, functionToCreateContext _)创建StreamingContext会从Checkpoint路径中读取Spark的配置信息,不会从控制台读取。所以如果要更改Spark配置信息需要清除Checkpoint路径中的内容或者更改Checkpoint路径。详细原因请参考:详细原因

猜你喜欢

转载自yq.aliyun.com/articles/710782
今日推荐