diff --git a/.gitignore b/.gitignore index 49d0fbf5..a924d2f1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,10 @@ tmp # OS X (Mac) .DS_Store -*/gen +*/gen/org/teiid/query/parser/v7/**/*.java +*/gen/org/teiid/query/parser/v8/**/*.java +*/gen/org/teiid/query/sql/lang/**/*.java + **/commandOutput.txt **/_remote.repositories diff --git a/komodo-teiid-client/gen/javacc/Teiid7ClientParser.jjt b/komodo-teiid-client/gen/javacc/Teiid7ClientParser.jjt new file mode 100644 index 00000000..acdfd2f2 --- /dev/null +++ b/komodo-teiid-client/gen/javacc/Teiid7ClientParser.jjt @@ -0,0 +1,4787 @@ +/* +* JBoss, Home of Professional Open Source. +* See the COPYRIGHT.txt file distributed with this work for information +* regarding copyright ownership. Some portions may be licensed +* to Red Hat, Inc. under one or more contributor license agreements. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301 USA. +*/ + +options { + STATIC = false; + ERROR_REPORTING = true; + JAVA_UNICODE_ESCAPE = true; + UNICODE_INPUT = false; + IGNORE_CASE = true; + MULTI = true; + BUILD_NODE_FILES = false; + NODE_PREFIX = ""; + NODE_SCOPE_HOOK = false; + NODE_USES_PARSER = true; + NODE_PACKAGE = "org.teiid.query.sql.lang"; + VISITOR = false; + VISITOR_RETURN_TYPE = "void"; + GRAMMAR_ENCODING="UTF-8"; + KEEP_LINE_COLUMN = true; + NODE_FACTORY = "TeiidNodeFactory"; +} + +PARSER_BEGIN(Teiid7ClientParser) + +/* +* JBoss, Home of Professional Open Source. +* See the COPYRIGHT.txt file distributed with this work for information +* regarding copyright ownership. Some portions may be licensed +* to Red Hat, Inc. under one or more contributor license agreements. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301 USA. +*/ +package org.teiid.query.parser.v7; + +import java.math.BigInteger; +import java.util.*; +import java.util.regex.Matcher; +import org.komodo.spi.runtime.version.TeiidVersion; +import org.komodo.spi.runtime.version.DefaultTeiidVersion; +import org.komodo.spi.query.sql.lang.MatchCriteria.MatchMode; +import org.komodo.spi.query.sql.lang.JoinType; +import org.teiid.runtime.client.Messages; +import org.teiid.language.SortSpecification.NullOrdering; +import org.teiid.metadata.Column; +import org.teiid.metadata.BaseColumn.NullType; +import org.teiid.metadata.Table; +import org.teiid.query.parser.AbstractTeiidClientParser; +import org.teiid.query.parser.ParsedDataType; +import org.teiid.query.parser.ParseInfo; +import org.teiid.query.parser.TeiidNodeFactory; +import org.teiid.query.parser.TeiidNodeFactory.ASTNodes; +import org.teiid.query.sql.lang.*; +import org.teiid.query.sql.lang.CriteriaOperator.Operator; +import org.teiid.query.sql.lang.SubqueryCompareCriteriaImpl.PredicateQuantifier; +import org.teiid.query.sql.proc.*; +import org.teiid.query.sql.symbol.*; +import org.teiid.core.types.DefaultDataTypeManager; +import org.teiid.core.util.StringUtil; + +/** + *
The SQLParser is a JavaCC-generated parser that reads a SQL string and produces a + * Query object. The SQLParser.java file is generated by JavaCC from the SQLParser.jj + * file. WARNING: DO NOT MODIFY the SQLParser.java file as it will be + * regenerated from the .jj file and your changes will be lost!
+ */ +@SuppressWarnings({"nls", "unused", "javadoc"}) +public class Teiid7ClientParser extends AbstractTeiidClientParser { + + private String getComment(Token t) { + Token optToken = t.specialToken; + if (optToken == null) { + return ""; //$NON-NLS-1$ + } + + //handle nested comments + String image = optToken.image; + while (optToken.specialToken != null) { + optToken = optToken.specialToken; + image = optToken.image + image; + } + + String hint = image.substring(2, image.length() - 2); + if (hint.startsWith("+")) { //$NON-NLS-1$ + hint = hint.substring(1); + } + + return hint; + } + + private boolean isNonStrictHint(Token t) { + String[] parts = getComment(t).split("\\s"); //$NON-NLS-1$ + for (int i = 0; i < parts.length; i++) { + if (parts[i].equalsIgnoreCase(LimitImpl.NON_STRICT)) { + return true; + } + } + return false; + } + + private SourceHintImpl getSourceHint(Token t) { + String comment = getComment(t); + Matcher matcher = SOURCE_HINT.matcher(comment); + if (!matcher.find()) { + return null; + } + SourceHintImpl sourceHint = new SourceHintImpl(); + String generalHint = matcher.group(1); + if (generalHint != null) { + sourceHint.setGeneralHint(normalizeStringLiteral(generalHint)); + } + int end = matcher.end(); + matcher = SOURCE_HINT_ARG.matcher(comment); + while (matcher.find(end)) { + end = matcher.end(); + sourceHint.setSourceHint(matcher.group(1), normalizeStringLiteral(matcher.group(2)), false); + } + return sourceHint; + } + + private SubqueryHint getSubqueryHint(Token t) { + SubqueryHint hint = new SubqueryHint(); + String[] parts = getComment(t).split("\\s"); //$NON-NLS-1$ + for (int i = 0; i < parts.length; i++) { + if (parts[i].equalsIgnoreCase(SubqueryHint.MJ)) { + hint.setMergeJoin(true); + } else if (parts[i].equalsIgnoreCase(SubqueryHint.NOUNNEST)) { + hint.setNoUnnest(true); + } else if (parts[i].equalsIgnoreCase(SubqueryHint.DJ)) { + hint.setDepJoin(); + } + } + return hint; + } + + private void setFromClauseOptions(Token groupID, FromClauseImpl fromClause){ + String[] parts = getComment(groupID).split("\\s"); //$NON-NLS-1$ + + for (int i = 0; i < parts.length; i++) { + if (parts[i].equalsIgnoreCase(OptionImpl.OPTIONAL)) { + fromClause.setOptional(true); + } else if (parts[i].equalsIgnoreCase(OptionImpl.MAKEDEP)) { + fromClause.setMakeDep(true); + } else if (parts[i].equalsIgnoreCase(OptionImpl.MAKENOTDEP)) { + fromClause.setMakeNotDep(true); + } else if (parts[i].equalsIgnoreCase(FromClauseImpl.MAKEIND)) { + fromClause.setMakeInd(true); + } else if (parts[i].equalsIgnoreCase(SubqueryHint.NOUNNEST)) { + fromClause.setNoUnnest(true); + } + } + } + + /** + * Generate an expression name based on the function type and previous names. + * @param info Parse info, including counts for each function type + * @param functionType Null for expression, the function name for aggregates + * @return New unique function name + */ + private String generateFunctionName(ParseInfo info, String functionType) { + if (functionType == null) { + functionType = "expr"; //$NON-NLS-1$ + } else { + functionType = functionType.toLowerCase(); + } + if (info.nameCounts == null) { + info.nameCounts = new HashMap