Konstantin Orlov created IGNITE-20227:
-----------------------------------------
Summary: Sql. Upgrade JavaCC version
Key: IGNITE-20227
URL: https://issues.apache.org/jira/browse/IGNITE-20227
Project: Ignite
Issue Type: Improvement
Components: sql
Reporter: Konstantin Orlov
After IGNITE-20196, the version of JavaCC was decreased from 4.2 to 4.0. The
reason is changes in generated {{jj_add_error_token}} method:
{code:java}
// generated by JavaCC 4.0
private void jj_add_error_token(int kind, int pos) {
if (pos >= 100) return;
if (pos == jj_endpos + 1) {
jj_lasttokens[jj_endpos++] = kind;
} else if (jj_endpos != 0) {
jj_expentry = new int[jj_endpos];
for (int i = 0; i < jj_endpos; i++) {
jj_expentry[i] = jj_lasttokens[i];
}
boolean exists = false;
for (java.util.Enumeration e = jj_expentries.elements();
e.hasMoreElements();) {
int[] oldentry = (int[])(e.nextElement());
if (oldentry.length == jj_expentry.length) {
exists = true;
for (int i = 0; i < jj_expentry.length; i++) {
if (oldentry[i] != jj_expentry[i]) {
exists = false;
break;
}
}
if (exists) break;
}
}
if (!exists) jj_expentries.addElement(jj_expentry);
if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
}
}
// generated by JavaCC 4.2
private void jj_add_error_token(int kind, int pos) {
if (pos >= 100) return;
if (pos == jj_endpos + 1) {
jj_lasttokens[jj_endpos++] = kind;
} else if (jj_endpos != 0) {
jj_expentry = new int[jj_endpos];
for (int i = 0; i < jj_endpos; i++) {
jj_expentry[i] = jj_lasttokens[i];
}
jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator();
it.hasNext();) {
int[] oldentry = (int[])(it.next());
if (oldentry.length == jj_expentry.length) {
for (int i = 0; i < jj_expentry.length; i++) {
if (oldentry[i] != jj_expentry[i]) {
continue jj_entries_loop;
}
}
jj_expentries.add(jj_expentry);
break jj_entries_loop;
}
}
if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
}
}
{code}
In JavaCC 4.0, if collection {{jj_expentries}} is empty, all visited tokes
(represented by {{jj_expentry}}) will be added to these collection. In JavaCC
4.2, the collection {{jj_expentries}} is updated only if it is _not_ empty.
This change broke
{{org.apache.calcite.sql.parser.SqlAbstractParserImpl.Metadata}}, because
initialisation of meta is relied on properly filled {{jj_expentries}}
collection. Besides, this affects generation of parsing exception: without
{{jj_expentries}}, only tokens reachable by LA(1) will be presented in possible
options (currently, default LA is set to 2).
Let's figure out what the benefits would be with upgrading to the most recent
version (7.0.12 at the time the ticket was created), and if any, make an
upgrade plan.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)