org.makumba.providers.query.mql
Class MqlSqlWalker

java.lang.Object
  extended by antlr.TreeParser
      extended by org.makumba.providers.query.mql.MqlSqlBaseWalker
          extended by org.makumba.providers.query.mql.MqlSqlWalker
All Implemented Interfaces:
HqlSqlTokenTypes
Direct Known Subclasses:
InlinerMqlSqlWalker

public class MqlSqlWalker
extends MqlSqlBaseWalker

Analysis operations. This extends the class produced by mql-sql.g which is adapted from Hibernate. To simplify porting of new versions, the class mostly redefines methods declared in mql-sql.g.

Version:
$Id: MqlSqlGenerator.java,v 1.1 Aug 5, 2008 5:47:16 PM cristi Exp $
Author:
Cristian Bogdan

Nested Class Summary
(package private) static class MqlSqlWalker.ParamInfo
           
 
Field Summary
(package private)  boolean autoLeftJoin
           
(package private)  LinkedHashMap<String,Object> constantValues
          some queries have only constant projections. they need no data from a database to be evaluated. if they are simple enough they don't need to be sent to the db engine.
protected  QueryContext currentContext
           
protected  DataDefinitionProvider ddp
           
protected  antlr.RecognitionException error
           
(package private)  antlr.ASTFactory fact
           
(package private)  boolean hasSubqueries
           
(package private)  DataDefinition knownLabels
          Labels known a-priori.
(package private)  Set<String> multiTypeParams
          The set of parameters that have different types on different positions (multi-type parameters)
(package private)  boolean optimizeJoins
           
protected  HashMap<String,FunctionCall> orderedFunctionCalls
           
(package private)  DataDefinition paramInfoByName
          Parameters as name=type, where name is the string after $ for named parameters or paramX for numbered parameters, where X is the parameter number (not its query position!).
(package private)  DataDefinition paramInfoByPosition
          Parameters as paramN=type, where N is the parameter position in the query.
(package private) static PrintWriter pw
           
(package private)  String query
           
protected  QueryContext rootContext
           
(package private)  Collection<String> warnings
           
 
Fields inherited from class org.makumba.providers.query.mql.MqlSqlBaseWalker
_tokenNames, _tokenSet_0, _tokenSet_1, inFunctionCall
 
Fields inherited from class antlr.TreeParser
_retTree, astFactory, ASTNULL, inputState, returnAST, tokenNames, traceDepth
 
Fields inherited from interface org.makumba.providers.query.mql.HqlSqlTokenTypes
AGGREGATE, ALIAS, ALIAS_REF, ALL, AND, ANY, AS, ASCENDING, AVG, BETWEEN, BOGUS, BOTH, CASE, CASE2, CLASS, CLOSE, CLOSE_BRACKET, COLON, COMMA, CONCAT, CONSTANT, CONSTRUCTOR, COUNT, DELETE, DESCENDING, DISTINCT, DIV, DOT, ELEMENTS, ELSE, EMPTY, END, EOF, EQ, ESCAPE, ESCqs, EXISTS, EXPONENT, EXPR_LIST, FALSE, FETCH, FILTER_ENTITY, FILTERS, FLOAT_SUFFIX, FROM, FROM_FRAGMENT, FULL, GE, GROUP, GT, HAVING, HEX_DIGIT, ID_LETTER, ID_START_LETTER, IDENT, IMPLIED_FROM, IN, IN_LIST, INDEX_OP, INDICES, INNER, INSERT, INTO, IS, IS_NOT_NULL, IS_NULL, JAVA_CONSTANT, JOIN, JOIN_FRAGMENT, LE, LEADING, LEFT, LEFT_OUTER, LIKE, LITERAL_ascending, LITERAL_by, LITERAL_descending, LT, MAX, MEMBER, METHOD_CALL, METHOD_NAME, MIN, MINUS, NAMED_PARAM, NE, NEW, NOT, NOT_BETWEEN, NOT_IN, NOT_LIKE, NULL, NULL_TREE_LOOKAHEAD, NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG, OBJECT, OF, ON, OPEN, OPEN_BRACKET, OR, ORDER, ORDER_ELEMENT, OUTER, PARAM, PLUS, PROPERTIES, PROPERTY_REF, QUERY, QUOTED_STRING, RANGE, RIGHT, RIGHT_OUTER, ROW_STAR, SELECT, SELECT_CLAUSE, SELECT_COLUMNS, SELECT_EXPR, SELECT_FROM, SET, SOME, SQL_NE, SQL_TOKEN, STAR, SUM, THEN, THETA_JOINS, TRAILING, TRUE, UNARY_MINUS, UNARY_PLUS, UNION, UPDATE, VECTOR_EXPR, VERSIONED, WEIRD_IDENT, WHEN, WHERE, WITH, WS
 
Constructor Summary
MqlSqlWalker(String query, DataDefinition insertIn, boolean optimizeJoins, boolean autoLeftJoin, DataDefinition knownLabels)
           
 
Method Summary
protected  void addFunctionCall(FunctionCall c)
          makes sure we don't override another function call with the same signature but in a different place
 void addWarning(String msg)
           
protected  antlr.collections.AST createFromElement(String path, antlr.collections.AST alias, antlr.collections.AST propertyFetch)
           
protected  void createFromJoinElement(antlr.collections.AST path, antlr.collections.AST alias, int joinType, antlr.collections.AST fetch, antlr.collections.AST propertyFetch, antlr.collections.AST with)
           
protected  antlr.collections.AST generateNamedParameter(antlr.collections.AST delimiterNode, antlr.collections.AST nameNode)
           
protected  antlr.collections.AST generatePositionalParameter(antlr.collections.AST inputNode)
           
(package private)  FieldDefinition getFunctionType(MqlNode child)
          Computes the type of function, based on their path.
 boolean isAnalysisQuery()
           
protected  antlr.collections.AST lookupProperty(antlr.collections.AST dot, boolean root, boolean inSelect)
           
protected  void processFunction(antlr.collections.AST functionCall)
           
protected  void processQuery(antlr.collections.AST select, antlr.collections.AST query)
           
protected  void pushFromClause(antlr.collections.AST fromClause, antlr.collections.AST inputFromNode)
          Sets the current 'FROM' context.
 void reportError(antlr.RecognitionException e)
           
 void reportError(String s)
           
 void reportWarning(String s)
           
protected  void resolve(antlr.collections.AST node)
           
protected  void setAlias(antlr.collections.AST selectExpr, antlr.collections.AST ident)
           
protected  void setFromEnded()
           
(package private)  void setParameterType(MqlNode param, FieldDefinition likewise)
           
(package private)  void setProjectionTypes(DataDefinition proj)
           
 
Methods inherited from class org.makumba.providers.query.mql.MqlSqlBaseWalker
addrExpr, addrExprLhs, aggregateExpr, aliasedSelectExpr, aliasRef, arithmeticExpr, assignment, beforeSelectClause, caseExpr, collectionFunction, collectionFunctionOrSubselect, comparisonExpr, constant, constructor, count, createFromFilterElement, createIntoClause, deleteStatement, evaluateAssignment, expr, exprOrSubquery, fromClause, fromElement, fromElementList, functionCall, getCurrentClauseType, getCurrentStatementType, getCurrentTopLevelClauseType, getStatementType, groupClause, identifier, inRhs, insertablePropertySpec, insertStatement, intoClause, isComparativeExpressionClause, isInCase, isInFrom, isInFunctionCall, isInSelect, isNonQualifiedPropertyRef, isSelectStatement, isSubQuery, joinElement, joinType, literal, logicalExpr, logicalExprOrFunctionCall, lookupAlias, lookupNonQualifiedProperty, newValue, numericInteger, orderClause, orderExprs, parameter, path, pathAsIdent, postProcessDelete, postProcessInsert, postProcessUpdate, prepareArithmeticOperator, prepareFromClauseInputTree, prepareLogicOperator, prepareVersioned, processBoolean, processConstant, processConstructor, processIndex, processNumericLiteral, propertyName, propertyRef, propertyRefLhs, query, resolveSelectExpression, selectClause, selectExpr, selectExprList, selectStatement, setBooleanType, setClause, setImpliedJoinType, statement, updateStatement, whereClause, withClause
 
Methods inherited from class antlr.TreeParser
getAST, getASTFactory, getTokenName, getTokenNames, match, match, matchNot, panic, setASTFactory, setASTNodeClass, setASTNodeType, traceIn, traceIndent, traceOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ddp

protected DataDefinitionProvider ddp

fact

antlr.ASTFactory fact

error

protected antlr.RecognitionException error

currentContext

protected QueryContext currentContext

pw

static PrintWriter pw

paramInfoByPosition

DataDefinition paramInfoByPosition
Parameters as paramN=type, where N is the parameter position in the query. This is normally the structure returned to the query analyzer clients. It allows for a parameter to have different types on different positions (multi-type parameters).


paramInfoByName

DataDefinition paramInfoByName
Parameters as name=type, where name is the string after $ for named parameters or paramX for numbered parameters, where X is the parameter number (not its query position!). This is used if a parameter is mentioned more times in a query and the type for some of these mentions cannot be determined


multiTypeParams

Set<String> multiTypeParams
The set of parameters that have different types on different positions (multi-type parameters)


rootContext

protected QueryContext rootContext

orderedFunctionCalls

protected HashMap<String,FunctionCall> orderedFunctionCalls

hasSubqueries

boolean hasSubqueries

query

String query

optimizeJoins

boolean optimizeJoins

autoLeftJoin

boolean autoLeftJoin

constantValues

LinkedHashMap<String,Object> constantValues
some queries have only constant projections. they need no data from a database to be evaluated. if they are simple enough they don't need to be sent to the db engine. If constantValues is null, it means that we found at least one non-constant projection or one that is not easy to evaluate, so we gave up


knownLabels

DataDefinition knownLabels
Labels known a-priori. This is needed for analysis of query fragment parameters


warnings

Collection<String> warnings
Constructor Detail

MqlSqlWalker

public MqlSqlWalker(String query,
                    DataDefinition insertIn,
                    boolean optimizeJoins,
                    boolean autoLeftJoin,
                    DataDefinition knownLabels)
Method Detail

reportError

public void reportError(antlr.RecognitionException e)
Overrides:
reportError in class antlr.TreeParser

reportError

public void reportError(String s)
Overrides:
reportError in class antlr.TreeParser

addFunctionCall

protected void addFunctionCall(FunctionCall c)
makes sure we don't override another function call with the same signature but in a different place


processFunction

protected void processFunction(antlr.collections.AST functionCall)
                        throws antlr.SemanticException
Overrides:
processFunction in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

getFunctionType

FieldDefinition getFunctionType(MqlNode child)
Computes the type of function, based on their path. Note that MDD functions are inlined so their type doesn't need to be computed. For actor functions, computation happens after the complete sub-tree is built, in the grammar.

Parameters:
child - TODO

reportWarning

public void reportWarning(String s)
Overrides:
reportWarning in class antlr.TreeParser

pushFromClause

protected void pushFromClause(antlr.collections.AST fromClause,
                              antlr.collections.AST inputFromNode)
Description copied from class: MqlSqlBaseWalker
Sets the current 'FROM' context.

Overrides:
pushFromClause in class MqlSqlBaseWalker

setFromEnded

protected void setFromEnded()
                     throws antlr.SemanticException
Overrides:
setFromEnded in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

processQuery

protected void processQuery(antlr.collections.AST select,
                            antlr.collections.AST query)
                     throws antlr.SemanticException
Overrides:
processQuery in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

createFromElement

protected antlr.collections.AST createFromElement(String path,
                                                  antlr.collections.AST alias,
                                                  antlr.collections.AST propertyFetch)
                                           throws antlr.SemanticException
Overrides:
createFromElement in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

createFromJoinElement

protected void createFromJoinElement(antlr.collections.AST path,
                                     antlr.collections.AST alias,
                                     int joinType,
                                     antlr.collections.AST fetch,
                                     antlr.collections.AST propertyFetch,
                                     antlr.collections.AST with)
                              throws antlr.SemanticException
Overrides:
createFromJoinElement in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

lookupProperty

protected antlr.collections.AST lookupProperty(antlr.collections.AST dot,
                                               boolean root,
                                               boolean inSelect)
                                        throws antlr.SemanticException
Overrides:
lookupProperty in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

resolve

protected void resolve(antlr.collections.AST node)
                throws antlr.SemanticException
Overrides:
resolve in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

setAlias

protected void setAlias(antlr.collections.AST selectExpr,
                        antlr.collections.AST ident)
Overrides:
setAlias in class MqlSqlBaseWalker

generateNamedParameter

protected antlr.collections.AST generateNamedParameter(antlr.collections.AST delimiterNode,
                                                       antlr.collections.AST nameNode)
                                                throws antlr.SemanticException
Overrides:
generateNamedParameter in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

generatePositionalParameter

protected antlr.collections.AST generatePositionalParameter(antlr.collections.AST inputNode)
                                                     throws antlr.SemanticException
Overrides:
generatePositionalParameter in class MqlSqlBaseWalker
Throws:
antlr.SemanticException

setParameterType

void setParameterType(MqlNode param,
                      FieldDefinition likewise)

setProjectionTypes

void setProjectionTypes(DataDefinition proj)

isAnalysisQuery

public boolean isAnalysisQuery()

addWarning

public void addWarning(String msg)