Skip to content

Commit

Permalink
Fix oracle interval sql visit npe (#28552)
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu authored Sep 22, 2023
1 parent 8187db6 commit 1305c71
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public ASTNode visitPrivateExprOfDb(final PrivateExprOfDbContext ctx) {
@Override
public ASTNode visitIntervalExpression(final IntervalExpressionContext ctx) {
IntervalExpressionProjection result = new IntervalExpressionProjection(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ExpressionSegment) visit(ctx.expr(0)),
(ExpressionSegment) visit(ctx.MINUS_()), (ExpressionSegment) visit(ctx.expr(1)));
(ExpressionSegment) visit(ctx.MINUS_()), (ExpressionSegment) visit(ctx.expr(1)), getOriginalText(ctx));
if (null != ctx.intervalDayToSecondExpression()) {
result.setDayToSecondExpression((IntervalDayToSecondExpression) visit(ctx.intervalDayToSecondExpression()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ private ASTNode createProjectionForExpressionSegment(final ASTNode projection, f
if (projection instanceof IntervalExpressionProjection) {
IntervalExpressionProjection intervalExpressionProjection = (IntervalExpressionProjection) projection;
IntervalExpressionProjection result = new IntervalExpressionProjection(intervalExpressionProjection.getStartIndex(), intervalExpressionProjection.getStopIndex(),
intervalExpressionProjection.getLeft(), intervalExpressionProjection.getMinus(), intervalExpressionProjection.getRight());
intervalExpressionProjection.getLeft(), intervalExpressionProjection.getMinus(), intervalExpressionProjection.getRight(), intervalExpressionProjection.getText());
if (null != intervalExpressionProjection.getDayToSecondExpression()) {
result.setDayToSecondExpression(intervalExpressionProjection.getDayToSecondExpression());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
@RequiredArgsConstructor
@Getter
@Setter
public final class IntervalExpressionProjection implements ExpressionSegment, ProjectionSegment {

private final int startIndex;
Expand All @@ -42,6 +41,8 @@ public final class IntervalExpressionProjection implements ExpressionSegment, Pr

private final ExpressionSegment right;

private final String expression;

@Setter
private IntervalDayToSecondExpression dayToSecondExpression;

Expand All @@ -50,7 +51,7 @@ public final class IntervalExpressionProjection implements ExpressionSegment, Pr

@Override
public String getText() {
return minus.getText();
return expression;
}

@Override
Expand Down
52 changes: 52 additions & 0 deletions test/it/parser/src/main/resources/case/dml/insert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2563,4 +2563,56 @@
</value>
</values>
</insert>

<insert sql-case-id="insert_with_oracle_datetime_type">
<table name="t_order" start-index="12" stop-index="18" />
<columns start-index="20" stop-index="93">
<column name="create_date" start-index="21" stop-index="31" />
<column name="create_timestamp" start-index="34" stop-index="49" />
<column name="create_interval_year" start-index="52" stop-index="71" />
<column name="create_interval_day" start-index="74" stop-index="92" />
</columns>
<values>
<value>
<assignment-value>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="103" stop-index="125" />
</assignment-value>
<assignment-value>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="128" stop-index="150" />
</assignment-value>
<assignment-value>
<interval-expression start-index="153" stop-index="217" text="(TO_DATE('2009', 'YYYY') - TO_DATE('2009', 'YYYY')) year to MONTH">
<left>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="154" stop-index="176" />
</left>
<operator>-</operator>
<right>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="180" stop-index="202" />
</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">
<left>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="221" stop-index="243" />
</left>
<operator>-</operator>
<right>
<function function-name="TO_DATE" text="TO_DATE('2009', 'YYYY')" start-index="247" stop-index="269" />
</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>
</values>
</insert>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@
<sql-case id="insert_with_content_keyword" value="INSERT INTO SYS_MQ_MSG (ID, CONTENT) VALUES (1, 'test');" db-types="Oracle" />
<sql-case id="insert_with_connect_by_and_prior" value="Insert Into t (c1,c2,c3,c4,c5) select c1,c2,regexp_substr(c3, '[^,]+', 1, l) c3,c4,c5 from t where id=1 connect by l &lt;= regexp_count(c3, ',') + 1 and ID = prior ID and prior dbms_random.value is not null;" db-types="Oracle" />
<sql-case id="insert_with_national_character_set" value="INSERT INTO customers VALUES (1000, TO_NCHAR('John Smith'),N'500 Oracle Parkway',sysdate);" db-types="Oracle" />
<sql-case id="insert_with_oracle_datetime_type" value="INSERT INTO t_order (create_date, create_timestamp, create_interval_year, create_interval_day) VALUES (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);" db-types="Oracle" />
</sql-cases>

0 comments on commit 1305c71

Please sign in to comment.