El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Optimizing SQL Query of Data of Multiple Sources

Updated on 2022-12-14 GMT+08:00

Scenario

This section describes how to enable or disable the query optimization for inter-source complex SQL.

Procedure

  • (Optional) Prepare for connecting to the MPPDB data source.

    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:

    1. Move gsjdbc4-VXXXRXXXCXXSPCXXX.jar from Spark. Spark running does not depend on this JAR file. Therefore, moving this JAR file to another directory (for example, the /tmp directory) will not affect Spark running.
      1. Log in to the Spark server and move gsjdbc4-VXXXRXXXCXXSPCXXX.jar from the ${BIGDATA_HOME}/FusionInsight_Spark2x_8.1.2.2/install/FusionInsight-Spark2x-3.1.1/spark/jars directory.
      2. Log in to the Spark client host and move gsjdbc4-VXXXRXXXCXXSPCXXX.jar from the /opt/client/Spark2x/spark/jars directory.
    2. Obtain the MPPDB Driver file gsjdbc4.jar from the MPPDB installation package and upload the file to the following directories:
      • /${BIGDATA_HOME}/FusionInsight_Spark2x_8.1.2.2/install/FusionInsight-Spark2x-3.1.1/spark/jars on the Spark server.
      • /opt/client/Spark2x/spark/jars on the Spark client.
    3. Update the /user/spark2x/jars/8.1.2.2/spark-archive-2x.zip package stored in the HDFS.
      1. Log in to the node where the client is installed as a client installation user. Run the following command to switch to the client installation directory, for example, /opt/client:

        cd /opt/client

      2. Run the following command to configure environment variables:

        source bigdata_env

      3. If the cluster is in security mode, run the following command to get authenticated:

        kinit Component service user

      4. Run the following commands to create the temporary file ./tmp, obtain spark-archive-2x.zip from HDFS, and decompress it to the tmp directory:

        mkdir tmp

        hdfs dfs -get /user/spark2x/jars/8.1.2.2/spark-archive-2x.zip ./

        unzip spark-archive-2x.zip -d ./tmp

      5. Switch to the tmp directory, delete the gsjdbc4-VXXXRXXXCXXSPCXXX.jar file, upload the MPPDB Driver file gsjdbc4.jar to the tmp directory, and run the following command to compress the file again:

        zip -r spark-archive-2x.zip *.jar

      6. Delete spark-archive-2x.zip from the HDFS and update the spark-archive-2x.zip package generated in 3.e to the /user/spark2x/jars/8.1.2.2/ directory in the HDFS.

        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

    4. Restart the Spark service. After the Spark service is restarted, restart the Spark client.
  • Enable the optimization function.

    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:

    • Global (valid for all data sources):

      SET spark.sql.datasource.jdbc = project,aggregate,orderby-limit

    • Data sources:

      SET spark.sql.datasource.${url} = project,aggregate,orderby-limit

    • Tables:

      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.

    Table 1 Parameters of 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:

    • ${url} = jdbc:mysql://ip2:3306/test
    • ${table} = mysqldata
    NOTE:
    • On the right of the equal sign (=) is the operators (separated by commas) to be enabled by pushdown.
    • Priority: table > data source > global. If the table switch is set, the global switch of the data source is invalid for the table. If a data source switch is set, the global switch is invalid for the data source.
    • The equal sign (=) is not allowed in URL. Equal signs (=) are automatically deleted in the SET clause.
    • After multiple SET operations, results with different keys will not overwrite each other.
  • Add functions that support query pushdown.

    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

  • Reset the configuration set by the SET command.

    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.

Precautions

Only MySQL, MPPDB, Hive, oracle, and PostgreSQL data sources are supported.

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback