Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract parameters from oracle TO_DATE function #28571

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 56 additions & 20 deletions test/it/parser/src/main/resources/case/dml/insert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2575,41 +2575,77 @@
<values>
<value>
<assignment-value>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="103" stop-index="125" />
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="103" stop-index="125" literal-start-index="103" literal-stop-index="125">
<parameter>
<literal-expression value="'2009'" start-index="111" stop-index="116" literal-start-index="111" literal-stop-index="116" />
</parameter>
<parameter>
<literal-expression value="'YYYY'" start-index="119" stop-index="124" literal-start-index="119" literal-stop-index="124" />
</parameter>
<literalText>TO_DATE('2009', 'YYYY')</literalText>
</function>
</assignment-value>
<assignment-value>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="128" stop-index="150" />
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="128" stop-index="150" literal-start-index="128" literal-stop-index="150">
<parameter>
<literal-expression value="'2009'" start-index="136" stop-index="141" literal-start-index="136" literal-stop-index="141" />
</parameter>
<parameter>
<literal-expression value="'YYYY'" start-index="144" stop-index="149" literal-start-index="144" literal-stop-index="149" />
</parameter>
<literalText>TO_DATE('2009', 'YYYY')</literalText>
</function>
</assignment-value>
<assignment-value>
<interval-expression start-index="153" stop-index="217" text="(TO_DATE('2009', 'YYYY') - TO_DATE('2009', 'YYYY')) year to MONTH">
<interval-expression>
<left>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="154" stop-index="176" />
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="154" stop-index="176" literal-start-index="154" literal-stop-index="176">
<parameter>
<literal-expression value="'2009'" start-index="162" stop-index="167" literal-start-index="162" literal-stop-index="167" />
</parameter>
<parameter>
<literal-expression value="'YYYY'" start-index="170" stop-index="175" literal-start-index="170" literal-stop-index="175" />
</parameter>
<literalText>TO_DATE('2009', 'YYYY')</literalText>
</function>
</left>
<operator>-</operator>
<right>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="180" stop-index="202" />
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="180" stop-index="202" literal-start-index="180" literal-stop-index="202">
<parameter>
<literal-expression value="'2009'" start-index="188" stop-index="193" literal-start-index="188" literal-stop-index="193" />
</parameter>
<parameter>
<literal-expression value="'YYYY'" start-index="196" stop-index="201" literal-start-index="196" literal-stop-index="201" />
</parameter>
<literalText>TO_DATE('2009', 'YYYY')</literalText>
</function>
</right>
<interval-year-to-month-expr start-index="205" stop-index="217">
<year>year</year>
<to>to</to>
<month>MONTH</month>
</interval-year-to-month-expr>
</interval-expression>
</assignment-value>
<assignment-value>
<interval-expression start-index="220" stop-index="284" text="(TO_DATE('2009', 'YYYY') - TO_DATE('2009', 'YYYY')) DAY TO SECOND">
<interval-expression>
<left>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="221" stop-index="243" />
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="221" stop-index="243" literal-start-index="221" literal-stop-index="243">
<parameter>
<literal-expression value="'2009'" start-index="229" stop-index="234" literal-start-index="229" literal-stop-index="234" />
</parameter>
<parameter>
<literal-expression value="'YYYY'" start-index="237" stop-index="242" literal-start-index="237" literal-stop-index="242" />
</parameter>
<literalText>TO_DATE('2009', 'YYYY')</literalText>
</function>
</left>
<operator>-</operator>
<right>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="247" stop-index="269" />
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="247" stop-index="269" literal-start-index="247" literal-stop-index="269">
<parameter>
<literal-expression value="'2009'" start-index="255" stop-index="260" literal-start-index="255" literal-stop-index="260" />
</parameter>
<parameter>
<literal-expression value="'YYYY'" start-index="263" stop-index="268" literal-start-index="263" literal-stop-index="268" />
</parameter>
<literalText>TO_DATE('2009', 'YYYY')</literalText>
</function>
</right>
<interval-day-to-second-expr start-index="272" stop-index="284">
<day>DAY</day>
<to>TO</to>
<second>SECOND</second>
</interval-day-to-second-expr>
</interval-expression>
</assignment-value>
</value>
Expand Down
18 changes: 16 additions & 2 deletions test/it/parser/src/main/resources/case/dml/select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6839,7 +6839,21 @@
<expression-projection text="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.')" start-index="7" stop-index="133" literal-start-index="7" literal-stop-index="133">
<literalText>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.')</literalText>
<expr>
<function function-name="TO_DATE" text="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.')" start-index="7" stop-index="133" literal-start-index="7" literal-stop-index="133">
<function function-name="TO_DATE"
text="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.')"
start-index="7" stop-index="133" literal-start-index="7" literal-stop-index="133">
<parameter>
<literal-expression value="'Febuary 15, 2016, 11:00 A.M.'" start-index="15" stop-index="44"
literal-start-index="15" literal-stop-index="44"/>
</parameter>
<parameter>
<literal-expression value="'January 01, 2016 12:00 A.M.'" start-index="54" stop-index="82"
literal-start-index="54" literal-stop-index="82"/>
</parameter>
<parameter>
<literal-expression value="'Month dd, YYYY, HH:MI A.M.'" start-index="105" stop-index="132"
literal-start-index="105" literal-stop-index="132"/>
</parameter>
<literalText>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.')</literalText>
</function>
</expr>
Expand All @@ -6851,7 +6865,7 @@
</select>
<select sql-case-id="select_with_expressions_in_projection">
<projections start-index="7" stop-index="81" literal-start-index="7" literal-stop-index="81">
<column-projection name="empid" start-index="75" stop-index="81" literal-start-index="75" literal-stop-index="81">
<column-projection name="empid" start-index="75" stop-index="81" literal-start-index="75" literal-stop-index="81">`
<owner name="a" start-index="75" stop-index="75" literal-start-index="75" literal-stop-index="75" />
</column-projection>
<expression-projection text="a.enddate - term + term2 + 1) / (last_day(term) - term + 1" alias="cnt" start-index="8" stop-index="72" literal-start-index="8" literal-stop-index="72">
Expand Down