You can configure rules for HetuEngine SQL inspection on FusionInsight Manager and configure rule parameters as you need.
For details about the rules supported by the HetuEngine 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.
cd /opt/hadoopclient
Run the following command to set environment variables:
source bigdata_env
hetu-cli --catalog hive --tenant default --schema default
hetu-cli --catalog hive --tenant default --schema default --user hetu_test
hetu_test is a service user who has at least the tenant role specified by --tenant and cannot be an OS user.
Run the following statement to create a table:
CREATE TABLE table1(id int, name varchar,rank int);
INSERT INTO table1 VALUES(10,'sachin',1),(45,'rohit',2),(46,'rohit',3),(18,'virat',4),(25,'dhawan',5);
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: Occurrence number of 'COUNT(DISTINCT XX)' (6) reaches the hint limitation (2)
Intercepted. Reason: Occurrence number of 'COUNT(DISTINCT XX)' (6) reaches the interception limitation (2)
statement = connection.prepareStatement(sql.trim()); resultSet = statement.executeQuery(); SQLWarning sqlWarning = statement.getWarnings();