Class ADQLParser
- All Implemented Interfaces:
ADQLParserConstants
Query()
function.
This parser is able, thanks to a QueryChecker
object, to check each
ADQLQuery
just after its generation. It could be used to check the
consistency between the ADQL query to parse and the "database" on which the
query must be executed. By default, there is no QueryChecker
. Thus
you must extend QueryChecker
to check semantically all generated
ADQLQuery objects.
To create an object representation of the given ADQL query, this parser uses
a ADQLQueryFactory
object. So if you want customize some object
(ie. CONTAINS) of this representation you just have to extend the
corresponding default object (ie. ContainsFunction) and to extend the
corresponding function of ADQLQueryFactory
(ie. createContains(...)).
Here are the key functions to use:
parseQuery(java.lang.String)
(or any of its alternatives) to parse an input ADQL query String and get its corresponding ADQL treetryQuickFix(java.lang.String)
to try fixing the most common issues with ADQL queries (e.g. Unicode confusable characters, unescaped ADQL identifiers, SQL reserved keywords, ...)
WARNING: To modify this class it's strongly encouraged to modify the .jj file in the section between PARSER_BEGIN and PARSER_END and to re-compile it with JavaCC.
- Version:
- 1.5-2 (10/2020)
- Author:
- Grégory Mantelet (CDS;ARI)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionNext token.protected static final String
Regular expression matching all Unicode alternatives for-
.protected static final String
Regular expression matching all Unicode alternatives for"
.protected static final String
Regular expression matching all Unicode alternatives for=
.protected static final String
Regular expression matching all Unicode alternatives for>
.protected static final String
Regular expression matching all Unicode alternatives for<
.protected static final String
Regular expression matching all Unicode alternatives for+
.protected static final String
Regular expression matching all Unicode alternatives for'
.protected static final String
Regular expression matching all Unicode alternatives forprotected static final String
Regular expression matching all Unicode alternatives for.
.protected static final String
Regular expression matching all Unicode alternatives for_
.All of the most common Unicode confusable characters and their ASCII/UTF-8 alternative.Current token.Generated Token Manager.Fields inherited from interface adql.parser.ADQLParserConstants
ABS, ACOS, AND, AREA, AS, ASC, ASIN, ASTERISK, ATAN, ATAN2, AVG, BETWEEN, BOX, BY, CEILING, CENTROID, CIRCLE, COMMA, CONCAT, CONTAINS, COORD1, COORD2, COORDSYS, COS, COT, COUNT, DEFAULT, DEGREES, DELIMITED_IDENTIFIER, DESC, DIGIT, DISTANCE, DIVIDE, DOT, EOF, EOQ, EQUAL, EXISTS, EXP, FLOOR, FROM, FULL, GREATER_EQUAL_THAN, GREATER_THAN, GROUP, HAVING, IN, INNER, INTERSECTS, IS, JOIN, LEFT, LEFT_PAR, LESS_EQUAL_THAN, LESS_THAN, Letter, LIKE, LOG, LOG10, MAX, MIN, MINUS, MOD, NATURAL, NOT, NOT_EQUAL, NULL, ON, OR, ORDER, OUTER, PI, PLUS, POINT, POLYGON, POWER, QUANTIFIER, RADIANS, RAND, REGION, REGULAR_IDENTIFIER_CANDIDATE, RIGHT, RIGHT_PAR, ROUND, SCIENTIFIC_NUMBER, SELECT, SIN, SQL_RESERVED_WORD, SQRT, STRING_LITERAL, SUM, TAN, tokenImage, TOP, TRUNCATE, UNSIGNED_FLOAT, UNSIGNED_INTEGER, USING, WHERE, WithinDelimitedId, WithinString
-
Constructor Summary
ConstructorsConstructorDescriptionBuilds an ADQL parser without a query to parse.Constructor with generated Token Manager.ADQLParser
(ADQLParserTokenManager tm, ADQLQueryFactory factory) Builds a parser with another token manager.ADQLParser
(ADQLParserTokenManager tm, QueryChecker checker) Builds a parser with another token manager.ADQLParser
(ADQLParserTokenManager tm, QueryChecker checker, ADQLQueryFactory factory) Builds a parser with another token manager.ADQLParser
(ADQLQueryFactory factory) Builds an ADQL parser without a query to parse but with aADQLQueryFactory
.ADQLParser
(QueryChecker checker) Builds an ADQL parser without a query to parse but with aQueryChecker
.ADQLParser
(QueryChecker checker, ADQLQueryFactory factory) Builds an ADQL parser without a query to parse but with aQueryChecker
and aADQLQueryFactory
.ADQLParser
(InputStream stream) Constructor with InputStream.ADQLParser
(InputStream stream, ADQLQueryFactory factory) Builds a parser with a stream containing the query to parse.ADQLParser
(InputStream stream, QueryChecker checker) Builds a parser with a stream containing the query to parse.ADQLParser
(InputStream stream, QueryChecker checker, ADQLQueryFactory factory) Builds a parser with a stream containing the query to parse.ADQLParser
(InputStream stream, String encoding) Constructor with InputStream and supplied encodingADQLParser
(InputStream stream, String encoding, ADQLQueryFactory factory) Builds a parser with a stream containing the query to parse.ADQLParser
(InputStream stream, String encoding, QueryChecker checker) Builds a parser with a stream containing the query to parse.ADQLParser
(InputStream stream, String encoding, QueryChecker checker, ADQLQueryFactory factory) Builds a parser with a stream containing the query to parse.ADQLParser
(Reader stream) Constructor.ADQLParser
(Reader reader, ADQLQueryFactory factory) Builds a parser with a reader containing the query to parse.ADQLParser
(Reader reader, QueryChecker checker) Builds a parser with a reader containing the query to parse.ADQLParser
(Reader reader, QueryChecker checker, ADQLQueryFactory factory) Builds a parser with a reader containing the query to parse. -
Method Summary
Modifier and TypeMethodDescriptionfinal Between
BetweenEnd
(ADQLOperand leftOp) final ADQLColumn
Column()
final IdentifierItems
Extracts the name of a column with its possible catalog, schema and table prefixes.final Comparison
ComparisonEnd
(ADQLOperand leftOp) final ClauseConstraints
ConditionsList
(ClauseConstraints clause) final ADQLConstraint
final ADQLOperand[]
final ADQLOperand
final void
Disable tracing.final void
Enable tracing.final GeometryFunction
final ADQLOperand
Factor()
final void
From()
Generate ParseException.final GeometryFunction
final GeometryFunction
final Token
Get the next Token.final QueryChecker
final ADQLQueryFactory
final Token
getToken
(int index) Get the specific Token.final void
GroupBy()
final void
Having()
final In
InEnd
(ADQLOperand leftOp) protected boolean
Tell whether the given token represents the end of an ADQL query.protected boolean
isFunctionName
(Token token) Tell whether the given token matches to an ADQL function name.final boolean
isRegularIdentifier
(String idCandidate) Tell whether the given string is a valid ADQL regular identifier.final FromContent
final ADQLJoin
JoinSpecification
(FromContent leftTable) static final void
Gets the specified ADQL query and parses the given ADQL query.final MathFunction
protected boolean
mustEscape
(Token token, Token nextToken) Tell whether the given token must be double quoted.final ADQLOperand
final ADQLFunction
final ADQLOperand
final ADQLOperand
final void
OrderBy()
final ADQLOrder
final ADQLQuery
Parses the query given at the creation of this parser or in the ReInit functions.final ADQLQuery
parseQuery
(InputStream stream) Parses the query contained in the stream given in parameter.final ADQLQuery
parseQuery
(String q) Parses the query given in parameter.final PointFunction
Point()
final ADQLConstraint
final ADQLQuery
Query()
Parses the ADQL query given at the parser creation or in theReInit(java.io.InputStream)
or in the parseQuery functions.final ADQLQuery
void
Reinitialise.void
ReInit
(InputStream stream) Reinitialise.void
ReInit
(InputStream stream, String encoding) Reinitialise.void
Reinitialise.protected String
replaceUnicodeConfusables
(String adqlQuery) Replace all Unicode characters that can be confused with other ASCI/UTF-8 characters (e.g.final void
Select()
final SelectItem
final void
setDebug
(boolean debug) final void
setQueryChecker
(QueryChecker checker) final void
setQueryFactory
(ADQLQueryFactory factory) final NumericConstant
final FromContent
final SQLFunction
final StringConstant
String()
final ADQLOperand
final ADQLOperand
final ADQLOperand
final ADQLQuery
final IdentifierItems
Extracts the name of a table with its possible catalog and schema prefixes.final FromContent
TableRef()
final void
testRegularIdentifier
(Token token) Test the given token as an ADQL's regular identifier.protected void
trace_call
(String s) final boolean
Trace enabled.protected void
protected void
trace_scan
(Token t1, int t2) protected void
trace_token
(Token t, String where) final MathFunction
final String
tryQuickFix
(InputStream input) Try fixing tokens/terms of the input ADQL query.tryQuickFix
(String adqlQuery) Try fixing tokens/terms of the given ADQL query.final NumericConstant
final NumericConstant
final UserDefinedFunction
final ADQLOperand
final void
Where()
-
Field Details
-
REGEX_UNICODE_CONFUSABLES
All of the most common Unicode confusable characters and their ASCII/UTF-8 alternative.Keys of this map represent the ASCII character while the values are the regular expression for all possible Unicode alternatives.
Note: All of them have been listed using Unicode Utilities: Confusables.
- Since:
- 1.5
-
REGEX_DASH
Regular expression matching all Unicode alternatives for-
.- Since:
- 1.5
- See Also:
-
REGEX_UNDERSCORE
Regular expression matching all Unicode alternatives for_
.- Since:
- 1.5
- See Also:
-
REGEX_QUOTE
Regular expression matching all Unicode alternatives for'
.- Since:
- 1.5
- See Also:
-
REGEX_DOUBLE_QUOTE
Regular expression matching all Unicode alternatives for"
.- Since:
- 1.5
- See Also:
-
REGEX_STOP
Regular expression matching all Unicode alternatives for.
.- Since:
- 1.5
- See Also:
-
REGEX_PLUS
Regular expression matching all Unicode alternatives for+
.- Since:
- 1.5
- See Also:
-
REGEX_SPACE
Regular expression matching all Unicode alternatives for- Since:
- 1.5
- See Also:
-
REGEX_LESS_THAN
Regular expression matching all Unicode alternatives for<
.- Since:
- 1.5
- See Also:
-
REGEX_GREATER_THAN
Regular expression matching all Unicode alternatives for>
.- Since:
- 1.5
- See Also:
-
REGEX_EQUAL
Regular expression matching all Unicode alternatives for=
.- Since:
- 1.5
- See Also:
-
token_source
Generated Token Manager. -
token
Current token. -
jj_nt
Next token.
-
-
Constructor Details
-
ADQLParser
public ADQLParser()Builds an ADQL parser without a query to parse. -
ADQLParser
Builds an ADQL parser without a query to parse but with aQueryChecker
and aADQLQueryFactory
.- Parameters:
checker
- The object to use to check eachADQLQuery
.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Builds an ADQL parser without a query to parse but with aQueryChecker
.- Parameters:
checker
- The object to use to check eachADQLQuery
.
-
ADQLParser
Builds an ADQL parser without a query to parse but with aADQLQueryFactory
.- Parameters:
factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Builds a parser with a stream containing the query to parse.- Parameters:
stream
- The stream in which the ADQL query to parse is given.checker
- The object to use to check eachADQLQuery
.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Builds a parser with a stream containing the query to parse.- Parameters:
stream
- The stream in which the ADQL query to parse is given.checker
- The object to use to check eachADQLQuery
.
-
ADQLParser
Builds a parser with a stream containing the query to parse.- Parameters:
stream
- The stream in which the ADQL query to parse is given.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
public ADQLParser(InputStream stream, String encoding, QueryChecker checker, ADQLQueryFactory factory) Builds a parser with a stream containing the query to parse.- Parameters:
stream
- The stream in which the ADQL query to parse is given.encoding
- The supplied encoding.checker
- The object to use to check eachADQLQuery
.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Builds a parser with a stream containing the query to parse.- Parameters:
stream
- The stream in which the ADQL query to parse is given.encoding
- The supplied encoding.checker
- The object to use to check eachADQLQuery
.
-
ADQLParser
Builds a parser with a stream containing the query to parse.- Parameters:
stream
- The stream in which the ADQL query to parse is given.encoding
- The supplied encoding.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Builds a parser with a reader containing the query to parse.- Parameters:
reader
- The reader in which the ADQL query to parse is given.checker
- The object to use to check eachADQLQuery
.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Builds a parser with a reader containing the query to parse.- Parameters:
reader
- The reader in which the ADQL query to parse is given.checker
- The object to use to check eachADQLQuery
.
-
ADQLParser
Builds a parser with a reader containing the query to parse.- Parameters:
reader
- The reader in which the ADQL query to parse is given.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Builds a parser with another token manager.- Parameters:
tm
- The manager which associates a token to a numeric code.checker
- The object to use to check eachADQLQuery
.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Builds a parser with another token manager.- Parameters:
tm
- The manager which associates a token to a numeric code.checker
- The object to use to check eachADQLQuery
.
-
ADQLParser
Builds a parser with another token manager.- Parameters:
tm
- The manager which associates a token to a numeric code.factory
- The object to use to build an object representation of the given ADQL query.
-
ADQLParser
Constructor with InputStream. -
ADQLParser
Constructor with InputStream and supplied encoding -
ADQLParser
Constructor. -
ADQLParser
Constructor with generated Token Manager.
-
-
Method Details
-
setDebug
public final void setDebug(boolean debug) -
getQueryChecker
-
setQueryChecker
-
getQueryFactory
-
setQueryFactory
-
isRegularIdentifier
Tell whether the given string is a valid ADQL regular identifier.According to the ADQL-2.0's BNF, a regular identifier (i.e. not delimited ; not between double quotes) must be a letter followed by a letter, digit or underscore. So, the following regular expression:
[a-zA-Z]+[a-zA-Z0-9_]*
This is what this function tests on the given string.
- Parameters:
idCandidate
- The string to test.- Returns:
true
if the given string is a valid regular identifier,false
otherwise.- Since:
- 1.5
- See Also:
-
testRegularIdentifier
Test the given token as an ADQL's regular identifier.This function uses
isRegularIdentifier(java.lang.String)
to test the given token's image. If the test fails, aParseException
is thrown.- Parameters:
token
- The token to test.- Throws:
ParseException
- If the given token is not a valid ADQL regular identifier.- Since:
- 1.5
- See Also:
-
parseQuery
Parses the query given at the creation of this parser or in the ReInit functions.- Returns:
- The object representation of the given ADQL query.
- Throws:
ParseException
- If there is at least one syntactic error.- See Also:
-
parseQuery
Parses the query given in parameter.- Parameters:
q
- The ADQL query to parse.- Returns:
- The object representation of the given ADQL query.
- Throws:
ParseException
- If there is at least one syntactic error.- See Also:
-
parseQuery
Parses the query contained in the stream given in parameter.- Parameters:
stream
- The stream which contains the ADQL query to parse.- Returns:
- The object representation of the given ADQL query.
- Throws:
ParseException
- If there is at least one syntactic error.- See Also:
-
tryQuickFix
Try fixing tokens/terms of the input ADQL query.This function does not try to fix syntactical or semantical errors. It just try to fix the most common issues in ADQL queries, such as:
- some Unicode characters confusable with ASCII characters (like a space, a dash, ...) ; this function replace them by their ASCII alternative,
- any of the following are double quoted:
- non regular ADQL identifiers
(e.g.
_RAJ2000
), - ADQL function names used as identifiers
(e.g.
distance
) - and SQL reserved keywords
(e.g.
public
).
- non regular ADQL identifiers
(e.g.
Note 1: The given stream is NOT closed by this function even if the EOF is reached. It is the responsibility of the caller to close it.
Note 2: This function does not use any instance variable of this parser (especially the InputStream or Reader provided at initialisation or ReInit).
- Parameters:
input
- Stream containing the input ADQL query to fix.- Returns:
- The suggested correction of the input ADQL query.
- Throws:
IOException
- If there is any error while reading from the given input stream.ParseException
- If any unrecognised character is encountered, or if anything else prevented the tokenization of some characters/words/terms.- Since:
- 1.5
- See Also:
-
tryQuickFix
Try fixing tokens/terms of the given ADQL query.This function does not try to fix syntactical or semantical errors. It just try to fix the most common issues in ADQL queries, such as:
- some Unicode characters confusable with ASCII characters (like a space, a dash, ...) ; this function replace them by their ASCII alternative,
- any of the following are double quoted:
- non regular ADQL identifiers
(e.g.
_RAJ2000
), - ADQL function names used as identifiers
(e.g.
distance
) - and SQL reserved keywords
(e.g.
public
).
- non regular ADQL identifiers
(e.g.
Note: This function does not use any instance variable of this parser (especially the InputStream or Reader provided at initialisation or ReInit).
- Parameters:
adqlQuery
- The input ADQL query to fix.- Returns:
- The suggested correction of the given ADQL query.
- Throws:
ParseException
- If any unrecognised character is encountered, or if anything else prevented the tokenization of some characters/words/terms.- Since:
- 1.5
-
replaceUnicodeConfusables
Replace all Unicode characters that can be confused with other ASCI/UTF-8 characters (e.g. different spaces, dashes, ...) in their ASCII version.- Parameters:
adqlQuery
- The ADQL query string in which Unicode confusable characters must be replaced.- Returns:
- The same query without the most common Unicode confusable characters.
- Since:
- 1.5
-
isEnd
Tell whether the given token represents the end of an ADQL query.- Parameters:
token
- Token to analyze.- Returns:
true
if the given token represents a query end,false
otherwise.- Since:
- 1.5
-
mustEscape
Tell whether the given token must be double quoted.This function considers all the following as terms to double quote:
- SQL reserved keywords ,
- unrecognised regular identifiers (e.g. neither a delimited nor a valid ADQL regular identifier)
- and ADQL function name without a parameters list.
- Parameters:
token
- The token to analyze.nextToken
- The following token. (useful to detect the start of a function's parameters list)- Returns:
true
if the given token must be double quoted,false
to keep it as provided.- Since:
- 1.5
-
isFunctionName
Tell whether the given token matches to an ADQL function name.- Parameters:
token
- The token to analyze.- Returns:
true
if the given token is an ADQL function name,false
otherwise.- Since:
- 1.5
-
main
Gets the specified ADQL query and parses the given ADQL query. The SQL translation is then printed if the syntax is correct.ONLY the syntax is checked: the query is NOT EXECUTED !
- Parameters:
args
-- Throws:
Exception
-
Query
Parses the ADQL query given at the parser creation or in theReInit(java.io.InputStream)
or in the parseQuery functions.- Returns:
- The object representation of the query.
- Throws:
ParseException
- If the query syntax is incorrect.
-
QueryExpression
- Throws:
ParseException
-
SubQueryExpression
- Throws:
ParseException
-
Select
- Throws:
ParseException
-
SelectItem
- Throws:
ParseException
-
From
- Throws:
ParseException
-
Where
- Throws:
ParseException
-
GroupBy
- Throws:
ParseException
-
Having
- Throws:
ParseException
-
OrderBy
- Throws:
ParseException
-
Identifier
- Throws:
ParseException
-
TableName
Extracts the name of a table with its possible catalog and schema prefixes.- Returns:
- A
IdentifierItems
which contains at most three items: catalogName, schemaName and tableName. - Throws:
ParseException
-
ColumnName
Extracts the name of a column with its possible catalog, schema and table prefixes.- Returns:
- A
IdentifierItems
which contains at most four items: catalogName, schemaName, tableName and columnName. - Throws:
ParseException
-
Column
- Throws:
ParseException
-
OrderItem
- Throws:
ParseException
-
SimpleTableRef
- Throws:
ParseException
-
TableRef
- Throws:
ParseException
-
JoinedTable
- Throws:
ParseException
-
JoinSpecification
- Throws:
ParseException
-
String
- Throws:
ParseException
-
UnsignedNumeric
- Throws:
ParseException
-
UnsignedFloat
- Throws:
ParseException
-
SignedInteger
- Throws:
ParseException
-
NumericValueExpressionPrimary
- Throws:
ParseException
-
StringValueExpressionPrimary
- Throws:
ParseException
-
ValueExpression
- Throws:
ParseException
-
NumericExpression
- Throws:
ParseException
-
NumericTerm
- Throws:
ParseException
-
Factor
- Throws:
ParseException
-
StringExpression
- Throws:
ParseException
-
StringFactor
- Throws:
ParseException
-
GeometryExpression
public final GeometryFunction.GeometryValue<GeometryFunction> GeometryExpression() throws ParseException- Throws:
ParseException
-
ConditionsList
- Throws:
ParseException
-
Constraint
- Throws:
ParseException
-
Predicate
- Throws:
ParseException
-
ComparisonEnd
- Throws:
ParseException
-
BetweenEnd
- Throws:
ParseException
-
InEnd
- Throws:
ParseException
-
SqlFunction
- Throws:
ParseException
-
Coordinates
- Throws:
ParseException
-
GeometryFunction
- Throws:
ParseException
-
CoordinateSystem
- Throws:
ParseException
-
GeometryValueFunction
- Throws:
ParseException
-
Point
- Throws:
ParseException
-
ExtractCoordSys
- Throws:
ParseException
-
NumericFunction
- Throws:
ParseException
-
MathFunction
- Throws:
ParseException
-
TrigFunction
- Throws:
ParseException
-
UserDefinedFunction
- Throws:
ParseException
-
ReInit
Reinitialise. -
ReInit
Reinitialise. -
ReInit
Reinitialise. -
ReInit
Reinitialise. -
getNextToken
Get the next Token. -
getToken
Get the specific Token. -
generateParseException
Generate ParseException. -
trace_enabled
public final boolean trace_enabled()Trace enabled. -
enable_tracing
public final void enable_tracing()Enable tracing. -
disable_tracing
public final void disable_tracing()Disable tracing. -
trace_call
-
trace_return
-
trace_token
-
trace_scan
-