From 346762c3533f41b12537ca29d80d981b33093b11 Mon Sep 17 00:00:00 2001 From: ZhangCheng Date: Mon, 25 Sep 2023 10:46:05 +0800 Subject: [PATCH 01/13] Extract parameters from oracle TO_DATE function (#28571) --- .../statement/OracleStatementVisitor.java | 6 +- .../src/main/resources/case/dml/insert.xml | 76 ++++++++++++++----- .../src/main/resources/case/dml/select.xml | 18 ++++- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java index ca737d7d20cf2..5480eb38c10df 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java @@ -1000,7 +1000,11 @@ public ASTNode visitCursorFunction(final CursorFunctionContext ctx) { @Override public ASTNode visitToDateFunction(final ToDateFunctionContext ctx) { - return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.TO_DATE().getText(), getOriginalText(ctx)); + FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.TO_DATE().getText(), getOriginalText(ctx)); + if (null != ctx.STRING_()) { + ctx.STRING_().forEach(each -> result.getParameters().add(new LiteralExpressionSegment(each.getSymbol().getStartIndex(), each.getSymbol().getStopIndex(), each.getSymbol().getText()))); + } + return result; } @Override diff --git a/test/it/parser/src/main/resources/case/dml/insert.xml b/test/it/parser/src/main/resources/case/dml/insert.xml index 197fccd0f65bb..441c2d12fae0b 100644 --- a/test/it/parser/src/main/resources/case/dml/insert.xml +++ b/test/it/parser/src/main/resources/case/dml/insert.xml @@ -2575,41 +2575,77 @@ - + + + + + + + + TO_DATE('2009', 'YYYY') + - + + + + + + + + TO_DATE('2009', 'YYYY') + - + - + + + + + + + + TO_DATE('2009', 'YYYY') + - - - + + + + + + + + TO_DATE('2009', 'YYYY') + - - year - to - MONTH - - + - + + + + + + + + TO_DATE('2009', 'YYYY') + - - - + + + + + + + + TO_DATE('2009', 'YYYY') + - - DAY - TO - SECOND - diff --git a/test/it/parser/src/main/resources/case/dml/select.xml b/test/it/parser/src/main/resources/case/dml/select.xml index 38059feba3ec8..9dd07a52faf19 100644 --- a/test/it/parser/src/main/resources/case/dml/select.xml +++ b/test/it/parser/src/main/resources/case/dml/select.xml @@ -6839,7 +6839,21 @@ TO_DATE('Febuary 15, 2016, 11:00 A.M.' DEFAULT 'January 01, 2016 12:00 A.M.' ON CONVERSION ERROR, 'Month dd, YYYY, HH:MI A.M.') - + + + + + + + + + + TO_DATE('Febuary 15, 2016, 11:00 A.M.' DEFAULT 'January 01, 2016 12:00 A.M.' ON CONVERSION ERROR, 'Month dd, YYYY, HH:MI A.M.') @@ -6851,7 +6865,7 @@