Configuring Spark SQL Inspection

Scenario

You can configure rules for Spark SQL inspection on FusionInsight Manager and configure rule parameters as you need.

Prerequisites

Constraints

Procedure

  1. Log in to FusionInsight Manager, click Cluster, and choose SQL Inspector. The SQL Inspector page is displayed.
  2. Add rules for Spark by referring to Adding an SQL Inspection.

    For details about the rules supported by the Spark SQL engine, see MRS SQL Inspection Rules.

    For example, add a rule whose ID is static_0001 to check whether count distinct appears more than two times in the SQL statement. If so, the system displays a hint.

    Figure 1 Adding a Spark SQL inspection rule

  3. Log in to the node where the Spark client is installed and run the following command to switch to the client installation directory.

    cd /opt/hadoopclient

    Run the following command to set environment variables:

    source bigdata_env

    source Spark/component_env

  4. Perform user authentication for clusters in security mode (Kerberos authentication enabled). Skip this step for clusters in normal mode (Kerberos authentication disabled).

    kinit Spark operation user

    Example:

    kinit sparkuser

    Enter the password as prompted and change the password upon your first login.

  5. Run the following command to log in to the spark-sql client:

    cd opt/client/Spark/spark/bin

    ./spark-sql

  6. Run the following SQL statement on the client to check whether the current rule takes effect:

    Run the following statement to create a table:

    create table table1(id int, name string) stored as parquet

    Run the following statement to query data:

    select count(distinct id),count(distinct id),count(distinct id),count(distinct id),count(distinct id),count(distinct id) from table1;

    If the number of times count distinct appears in the statement exceeds the threshold configured in 2, the following information is displayed:

    WARNING:  static_0001 Occurrence num of 'COUNT(DISTINCT)'(6) reaches the hint threshold(2)
    If the action set in the rule is Intercept, the following information is displayed:
    Error in query: static_0001 Occurrence num of 'COUNT(DISTINCT)'(6) reaches the intercept threshold(2)

    In Spark Beeline, you can obtain SQL inspection details from logs.

    1. Log in to FusionInsight Manager and choose Cluster > Services > Yarn. On the Dashboard page, click the link next to ResourceManager WebUI to enter the Yarn web UI.
    2. Click the ID of the target application on the All Applications page. The application details page is displayed.

    3. Click Logs of the application. On the displayed page, click stdout logs to view SQL inspection details.

    1. For more Spark SQL inspection rules, see MRS SQL Inspection Rules.
    2. You can view query info in the /opt/hadoopclient/Spark/spark/audit/query.log path if you are using the Spark client. The log contains detailed running information and the corresponding SQL inspection information.