-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
oracle interval keyword parser failed, throw NoViableAltException #31236
Comments
@xigongxiaoche Thank you for your feedback, I will check on this issue. |
can you give me some suggestion to solve the bug? |
At first I think it it because of sysdate keyword not in the antlr rule of 5.3.2 oracle. I add keyword sysdate, but it is invalid |
Hi @xigongxiaoche, can you test with master branch? After testing, the following SQL statement can be parsed correctly in the master. select
age
from
(
select
'0-1岁' age
, count(*) countNum
, '0' sortNum
from
T_EMPI_PATIENT_INFO t
where
t.birth > to_char((sysdate - interval '1' year(3)), 'yyyymmdd')
) |
Ok, I'll try it |
sql not parse successfully in master or 5.4.1,
console output:
|
@xigongxiaoche You claim there are obvious errors here, the WHERE clause is in the subquery; the correct assertion should be <select sql-case-id="select_interval_with_subquery">
<projections start-index="7" stop-index="9">
<column-projection name="age" start-index="7" stop-index="9"/>
</projections>
<from>
<subquery-table>
<subquery>
<select>
<projections start-index="24" stop-index="64">
<expression-projection text="0-1岁" start-index="24" stop-index="33" alias="age"/>
<aggregation-projection type="COUNT" start-index="35" stop-index="42" expression="count(*)" alias="countNum"/>
<expression-projection text="0" start-index="54" stop-index="64" alias="sortNum"/>
</projections>
<from start-index="71" stop-index="91">
<simple-table name="T_EMPI_PATIENT_INFO" start-index="71" stop-index="91" alias="t"/>
</from>
<where start-index="93" stop-index="161">
<expr>
<binary-operation-expression start-index="99" stop-index="161">
<operator>></operator>
<left>
<column name="birth" start-index="99" stop-index="105">
<owner name="t" start-index="99" stop-index="99"/>
</column>
</left>
<right>
<function text="to_char((sysdate - interval '1' year(3)), 'yyyymmdd')" function-name="to_char" start-index="109" stop-index="161">
<parameter>
<binary-operation-expression start-index="118" stop-index="147">
<operator>-</operator>
<left>
<column name="sysdate" start-index="118" stop-index="124"/>
</left>
<right>
<common-expression text="interval '1' year(3)" start-index="128" stop-index="147"/>
</right>
</binary-operation-expression>
</parameter>
<parameter>
<literal-expression value="yyyymmdd" start-index="151" stop-index="160"/>
</parameter>
</function>
</right>
</binary-operation-expression>
</expr>
</where>
</select>
</subquery>
</subquery-table>
</from>
</select> |
@TherChenYang
console failed message:
|
@xigongxiaoche This is just a standard format of an assertion. You need to supplement start-Index and stop-Index according to your SQL, which is not related to SQL parsing itself. This is just for testing. |
According to your advice, my unit tests passed on 5.4.1 and master. Thank you very much.
|
This bug only occurs in version 5.3.2., version 5.4.1 and master all passed |
Currently, I am using version 5.3.2. If I want to address this bug based on this version, could you please inform me which parts need to be modified? Presently, my understanding is that the file requiring modification is sql-parser/dialect/oracle/src/main/antlr4/imports/oracle/BaseRule.g4 and sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleStatementSQLVisitor.java @TherChenYang
|
@xigongxiaoche You can refer to this link for processing. parser module The main parts that need to be modified
|
Thank you very much |
After 5.3.2 oracle BaseRule.g4, the bug fixed |
Bug Report
oracle sql parse failed, but the failed sql can execute in oracle, the failed sql is vaild in antlr rule
version
shardingsphere version: 5.3.2
oracle verion: oracle 11g
stacktrace
The text was updated successfully, but these errors were encountered: