This is an automated email from the ASF dual-hosted git repository.
chengzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 621320c3caf Support Oracle PREDICTION function parse (#28005)
621320c3caf is described below
commit 621320c3caf71b3fb07bbe988003fe27d4a8bb8e
Author: Zichao <[email protected]>
AuthorDate: Thu Aug 10 20:06:32 2023 +1200
Support Oracle PREDICTION function parse (#28005)
* Support Oracle PREDICTION function parse
* Support Oracle PREDICTION function parse
---
.../src/main/antlr4/imports/oracle/BaseRule.g4 | 11 ++++++++---
.../main/resources/case/dml/select-expression.xml | 22 ++++++++++++++++++++++
.../sql/supported/dml/select-expression.xml | 1 +
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git
a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
index b4cf261c50b..53d92557450 100644
--- a/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
+++ b/parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4
@@ -788,15 +788,20 @@ setFunction
featureFunction
: featureFunctionName LP_ (schemaName DOT_)? modelName (COMMA_ featureId)?
(COMMA_ numberLiterals (COMMA_ numberLiterals)?)?
- (DESC | ASC | ABS)? (COST MODEL (AUTO)?)? miningAttributeClause (AND
miningAttributeClause)? RP_
+ (DESC | ASC | ABS)? cost_matrix_clause? miningAttributeClause (AND
miningAttributeClause)? RP_
;
featureFunctionName
- : FEATURE_COMPARE | FEATURE_DETAILS | FEATURE_SET | FEATURE_ID |
FEATURE_VALUE | CLUSTER_DETAILS | CLUSTER_DISTANCE | CLUSTER_ID |
CLUSTER_PROBABILITY | CLUSTER_SET | PREDICTION_PROBABILITY | PREDICTION_SET |
PREDICTION_BOUNDS
+ : FEATURE_COMPARE | FEATURE_DETAILS | FEATURE_SET | FEATURE_ID |
FEATURE_VALUE | CLUSTER_DETAILS | CLUSTER_DISTANCE | CLUSTER_ID |
CLUSTER_PROBABILITY | CLUSTER_SET
+ | PREDICTION_PROBABILITY | PREDICTION_SET | PREDICTION_BOUNDS | PREDICTION
+ ;
+
+cost_matrix_clause
+ : COST (MODEL (AUTO)?)? | LP_ literals RP_ (COMMA_ LP_ literals RP_)*
VALUES LP_ LP_ literals (COMMA_ literals)* RP_ (COMMA_ LP_ literals (COMMA_
literals)* RP_) RP_
;
miningAttributeClause
- : USING (ASTERISK_ | (schemaName DOT_)? tableName DOT_ ASTERISK_ | expr
(AS? alias)?)
+ : USING (ASTERISK_ | ((schemaName DOT_)? tableName DOT_ ASTERISK_ | expr
(AS? alias)?) (COMMA_ ((schemaName DOT_)? tableName DOT_ ASTERISK_ | expr (AS?
alias)?))*)
;
trimFunction
diff --git a/test/it/parser/src/main/resources/case/dml/select-expression.xml
b/test/it/parser/src/main/resources/case/dml/select-expression.xml
index 491c2febf3c..8df051d1af1 100644
--- a/test/it/parser/src/main/resources/case/dml/select-expression.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-expression.xml
@@ -2852,4 +2852,26 @@
</expr>
</where>
</select>
+
+ <select sql-case-id="select_prediction_function">
+ <projections start-index="7" stop-index="17">
+ <column-projection name="cust_gender" start-index="7"
stop-index="17" />
+ </projections>
+ <from>
+ <simple-table name="mining_data_apply_v" start-index="24"
stop-index="42" />
+ </from>
+ <where start-index="44" stop-index="153">
+ <expr>
+ <binary-operation-expression start-index="50" stop-index="153">
+ <left>
+ <function function-name="PREDICTION" start-index="50"
stop-index="149" text="PREDICTION (nb_sh_clas_sample COST MODEL AUTO USING
cust_marital_status, aeducation, household_size)" />
+ </left>
+ <operator>=</operator>
+ <right>
+ <literal-expression value="1" start-index="153"
stop-index="153" />
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
</sql-parser-test-cases>
diff --git
a/test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml
b/test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml
index 20e7320239e..2046b99d4c7 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml
@@ -120,4 +120,5 @@
<sql-case id="select_prediction_set_function" value="SELECT
PREDICTION_SET(dt_sh_clas_sample COST MODEL USING *) pset FROM
mining_data_apply_v WHERE cust_id = 100011" db-types="Oracle" />
<sql-case id="select_cursor_function" value="SELECT CURSOR(SELECT salary,
commission_pct FROM employees e WHERE e.department_id = d.department_id) FROM
departments d;" db-types="Oracle" />
<sql-case id="select_prediction_bounds_function" value="SELECT cust_id
FROM mining_data_apply_v WHERE PREDICTION_BOUNDS(glmr_sh_regr_sample,0.98 USING
*).LOWER = 24;" db-types="Oracle" />
+ <sql-case id="select_prediction_function" value="SELECT cust_gender FROM
mining_data_apply_v WHERE PREDICTION (nb_sh_clas_sample COST MODEL AUTO USING
cust_marital_status, aeducation, household_size) = 1;" db-types="Oracle" />
</sql-cases>