|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.sql.advise.SqlAdvisor
public class SqlAdvisor
An assistant which offers hints and corrections to a partially-formed SQL statement. It is used in the SQL editor user-interface.
Nested Class Summary | |
---|---|
class |
SqlAdvisor.ValidateErrorInfo
An inner class that represents error message text and position info of a validator or parser exception |
Field Summary | |
---|---|
private String |
hintToken
|
static Logger |
tracer
|
private SqlValidatorWithHints |
validator
|
Constructor Summary | |
---|---|
SqlAdvisor(SqlValidatorWithHints validator)
Creates a SqlAdvisor with a validator instance |
Method Summary | |
---|---|
protected SqlNode |
collectParserError(String sql,
List<SqlAdvisor.ValidateErrorInfo> errorList)
Attempts to parse a SQL statement and adds to the errorList if any syntax error is found. |
List<SqlMoniker> |
getCompletionHints(String sql,
int cursor,
String[] replaced)
Gets completion hints for a partially completed or syntatically incorrect sql statement with cursor pointing to the position where completion hints are requested. |
List<SqlMoniker> |
getCompletionHints(String sql,
SqlParserPos pos)
Gets completion hints for a syntatically correct sql statement with dummy SqlIdentifier |
List<SqlMoniker> |
getCompletionHints0(String sql,
int cursor)
|
protected SqlAbstractParserImpl |
getParserImpl()
Returns the underlying Parser implementation class. |
SqlMoniker |
getQualifiedName(String sql,
int cursor)
Gets the fully qualified name for a SqlIdentifier at a given
position of a sql statement. |
List<String> |
getReservedAndKeyWords()
Return an array of SQL reserved and keywords |
boolean |
isValid(String sql)
Attempts to complete and validate a given partially completed sql statement, and returns whether it is valid. |
protected SqlNode |
parseQuery(String sql)
Wrapper function to parse a SQL query (SELECT or VALUES, but not INSERT, UPDATE, DELETE, CREATE, DROP etc.), throwing a SqlParseException
if the statement is not syntactically valid. |
String |
simplifySql(String sql,
int cursor)
Turns a partially completed or syntatically incorrect sql statement into a simplified, valid one that can be passed into getCompletionHints() |
private SqlNode |
tryParse(String sql,
List<SqlMoniker> hintList)
Tries to parse a SQL statement. |
List<SqlAdvisor.ValidateErrorInfo> |
validate(String sql)
Attempts to parse and validate a SQL statement. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Logger tracer
private final SqlValidatorWithHints validator
private final String hintToken
Constructor Detail |
---|
public SqlAdvisor(SqlValidatorWithHints validator)
validator
- ValidatorMethod Detail |
---|
public List<SqlMoniker> getCompletionHints(String sql, int cursor, String[] replaced)
Writes into replaced[0]
the string that is being
replaced. Includes the cursor and the preceding identifier. For example,
if sql
is "select abc^de from t", sets
replaced[0]
to "abc". If the cursor is in the middle of
whitespace, the replaced string is empty. The replaced string is never
null.
sql
- A partial or syntatically incorrect sql statement for which to
retrieve completion hintscursor
- to indicate the 0-based cursor position in the query atreplaced
- String which is being replaced (output)
public List<SqlMoniker> getCompletionHints0(String sql, int cursor)
public List<SqlMoniker> getCompletionHints(String sql, SqlParserPos pos)
sql
- A syntatically correct sql statement for which to retrieve
completion hintspos
- to indicate the line and column position in the query at which
completion hints need to be retrieved. For example, "select a.ename,
b.deptno from sales.emp a join sales.dept b "on a.deptno=b.deptno where
empno=1"; setting pos to 'Line 1, Column 17' returns all the possible
column names that can be selected from sales.dept table setting pos to
'Line 1, Column 31' returns all the possible table names in 'sales'
schema
SqlMoniker
) that can fill in at the
indicated positionprivate SqlNode tryParse(String sql, List<SqlMoniker> hintList)
If succeeds, returns the parse tree node; if fails, populates the list of hints and returns null.
sql
- SQL statementhintList
- List of hints suggesting allowable tokens at the point of
failure
public SqlMoniker getQualifiedName(String sql, int cursor)
SqlIdentifier
at a given
position of a sql statement.
sql
- A syntactically correct sql statement for which to retrieve a
fully qualified SQL identifier namecursor
- to indicate the 0-based cursor position in the query that
represents a SQL identifier for which its fully qualified name is to be
returned.
SqlMoniker
that contains the fully qualified name of
the specified SQL identifier, returns null if none is found or the SQL
statement is invalid.public boolean isValid(String sql)
sql
- A partial or syntatically incorrect sql statement to validate
public List<SqlAdvisor.ValidateErrorInfo> validate(String sql)
sql
- A user-input sql statement to be validated
public String simplifySql(String sql, int cursor)
sql
- A partial or syntatically incorrect sql statementcursor
- to indicate column position in the query at which
completion hints need to be retrieved.
public List<String> getReservedAndKeyWords()
protected SqlAbstractParserImpl getParserImpl()
To use a different parser (recognizing a different dialect of SQL), derived class should override.
SqlAbstractParserImpl
instanceprotected SqlNode parseQuery(String sql) throws SqlParseException
SqlParseException
if the statement is not syntactically valid.
sql
- SQL statement
SqlParseException
- if not syntactically validprotected SqlNode collectParserError(String sql, List<SqlAdvisor.ValidateErrorInfo> errorList)
SqlParser
. Subclass can
re-implement this with a different parser implementation
sql
- A user-input sql statement to be parsederrorList
- A List
of error to be added to
SqlNode
that is root of the parse tree, null if the sql
is not valid
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |