This section describes how to enable or disable the query optimization for inter-source complex SQL.
If the data source to be connected is MPPDB, a class name conflict occurs because the MPPDB Driver file gsjdbc4.jar and the Spark JAR package gsjdbc4-VXXXRXXXCXXSPCXXX.jar contain the same class name. Therefore, before connecting to the MPPDB data source, perform the following steps:
cd /opt/client
mkdir tmp
hdfs dfs -get /user/spark2x/jars/8.1.2.2/spark-archive-2x.zip ./
unzip spark-archive-2x.zip -d ./tmp
zip -r spark-archive-2x.zip *.jar
hdfs dfs -rm /user/spark2x/jars/8.1.2.2/spark-archive-2x.zip
hdfs dfs -put ./spark-archive-2x.zip /user/spark2x/jars/8.1.2.2
For all modules that support query pushdown, you can run the SET command on the spark-beeline client to enable the cross-source query optimization function. By default, the function is disabled.
Pushdown configurations can be performed in dimensions of global, data sources, and tables. Commands are as follows:
SET spark.sql.datasource.jdbc = project,aggregate,orderby-limit
SET spark.sql.datasource.${url} = project,aggregate,orderby-limit
SET spark.sql.datasource.${url}.${table} = project,aggregate,orderby-limit
When you run the SET command to configure preceding parameters, you are allowed to specify multiple pushdown modules and separate them by commas. The following table lists parameters of corresponding pushdown modules.
Module |
Parameter Value in the SET Command |
---|---|
project |
project |
aggregate |
aggregate |
order by, limit over project or aggregate |
orderby-limit |
The following is a statement for creating an external table of MySQL:
create table if not exists pdmysql using org.apache.spark.sql.jdbc options(driver "com.mysql.jdbc.Driver", url "jdbc:mysql://ip2:3306/test", user "hive", password "123456", dbtable "mysqldata");
In the preceding statement:
In addition to query pushdown of mathematical, time, and string functions such as abs(), month(), and length(), you can run the SET command to add a data source that supports query pushdown. Run the following command on the Spark-beeline client:
SET park.sql.datasource.${datasource}.functions = fun1,fun2
Currently, you can only run the RESET command on the spark-beeline client to cancel all SET content. After running the RESET command, all values in the SET command will be cleared. Exercise caution when performing this operation.
The SET command is valid in the current session on the client. After the client is shut down, the content in the SET command turns invalid.
Alternatively, change the value of spark.sql.locale.support in the spark-defaults.conf file to true.
Only MySQL, MPPDB, Hive, oracle, and PostgreSQL data sources are supported.