com.espertech.esper.epl.expression.core
Class ExprNodeUtility

java.lang.Object
  extended by com.espertech.esper.epl.expression.core.ExprNodeUtility

public class ExprNodeUtility
extends java.lang.Object


Nested Class Summary
static class ExprNodeUtility.MappedPropertyParseResult
          Encapsulates the parse result parsing a mapped property as a class and method name with args.
 
Field Summary
static ExprDeclaredNode[] EMPTY_DECLARED_ARR
           
static ExprNode[] EMPTY_EXPR_ARRAY
           
 
Constructor Summary
ExprNodeUtility()
           
 
Method Summary
static void acceptChain(ExprNodeVisitor visitor, java.util.List<ExprChainedSpec> chainSpec)
           
static void acceptChain(ExprNodeVisitorWithParent visitor, java.util.List<ExprChainedSpec> chainSpec)
           
static void acceptChain(ExprNodeVisitorWithParent visitor, java.util.List<ExprChainedSpec> chainSpec, ExprNode parent)
           
static void addNonAggregatedProps(ExprNode exprNode, ExprNodePropOrStreamSet set, EventType[] types, ContextPropertyRegistry contextPropertyRegistry)
           
static boolean applyFilterExpression(ExprEvaluator filter, EventBean[] eventsPerStream, ExprEvaluatorContext exprEvaluatorContext)
          Apply a filter expression returning a pass indicator.
static EventBean[] applyFilterExpression(ExprEvaluator filter, EventBean streamZeroEvent, EventBean[] streamOneEvents, ExprEvaluatorContext exprEvaluatorContext)
          Apply a filter expression.
static void applyFilterExpressionIterable(java.util.Iterator<EventBean> iterator, ExprEvaluator filterExpression, ExprEvaluatorContext exprEvaluatorContext, java.util.Collection<EventBean> eventsInWindow)
           
static void applyFilterExpressionsIterable(java.lang.Iterable<EventBean> iterable, java.util.List<ExprNode> filterExpressions, ExprEvaluatorContext exprEvaluatorContext, java.util.Collection<EventBean> eventsInWindow)
           
static Pair<java.lang.String,ExprNode> checkGetAssignmentToProp(ExprNode node)
           
static Pair<java.lang.String,ExprNode> checkGetAssignmentToVariableOrProp(ExprNode node)
           
static java.util.List<ExprNode> collectChainParameters(java.util.List<ExprChainedSpec> chainSpec)
           
static ExprAndNode connectExpressionsByLogicalAnd(java.util.Collection<ExprNode> nodes)
           
static ExprNode connectExpressionsByLogicalAnd(java.util.List<ExprNode> nodes, ExprNode optionalAdditionalFilter)
           
static boolean deepEquals(ExprNode[] one, ExprNode[] two)
          Compares two expression nodes via deep comparison, considering all child nodes of either side.
static boolean deepEquals(ExprNode nodeOne, ExprNode nodeTwo)
          Compare two expression nodes and their children in exact child-node sequence, returning true if the 2 expression nodes trees are equals, or false if they are not equals.
static boolean deepEquals(java.util.List<ExprNode> one, java.util.List<ExprNode> two)
           
static boolean deepEqualsIgnoreDupAndOrder(ExprNode[] setOne, ExprNode[] setTwo)
           
static boolean deepEqualsIsSubset(ExprNode[] subset, ExprNode[] superset)
           
static java.lang.Object[] evaluateExpressions(ExprEvaluator[] parameters, ExprEvaluatorContext exprEvaluatorContext)
           
static java.util.List<Pair<ExprNode,ExprNode>> findExpression(ExprNode selectExpression, ExprNode searchExpression)
           
static ExprNodePropOrStreamSet getAggregatedProperties(java.util.List<ExprAggregateNode> aggregateNodes)
           
static java.util.Map<ExprDeclaredNode,java.util.List<ExprDeclaredNode>> getDeclaredExpressionCallHierarchy(ExprDeclaredNode[] declaredExpressions)
           
static ExprEvaluator[] getEvaluators(ExprNode[] exprNodes)
           
static ExprEvaluator[] getEvaluators(java.util.List<ExprNode> childNodes)
           
static java.util.List<Pair<java.lang.Integer,java.lang.String>> getExpressionProperties(ExprNode exprNode, boolean visitAggregateNodes)
          Walk expression returning properties used.
static ExprIdentNode getExprIdentNode(EventType[] typesPerStream, int streamId, java.lang.String property)
           
static java.lang.Class[] getExprResultTypes(ExprEvaluator[] evaluators)
           
static java.lang.Class[] getExprResultTypes(ExprNode[] groupByNodes)
           
static java.lang.Class[] getExprResultTypes(java.util.List<ExprNode> expressions)
           
static ExprNodePropOrStreamSet getGroupByPropertiesValidateHasOne(ExprNode[] groupByNodes)
           
static java.lang.String[] getIdentResolvedPropertyNames(ExprNode[] nodes)
           
static java.util.Set<java.lang.Integer> getIdentStreamNumbers(ExprNode child)
           
static java.util.Map<java.lang.String,ExprNamedParameterNode> getNamedExpressionsHandleDups(java.util.List<ExprNode> parameters)
           
static ExprNodePropOrStreamSet getNonAggregatedProps(EventType[] types, java.util.List<ExprNode> exprNodes, ContextPropertyRegistry contextPropertyRegistry)
           
static java.util.Set<java.lang.String> getPropertyNamesIfAllProps(ExprNode[] expressions)
           
static ExprNode getValidatedAssignment(OnTriggerSetAssignment assignment, ExprValidationContext validationContext)
           
static void getValidatedSubtree(ExprNodeOrigin origin, ExprNode[][] exprNode, ExprValidationContext validationContext)
           
static void getValidatedSubtree(ExprNodeOrigin origin, ExprNode[] exprNode, ExprValidationContext validationContext)
           
static ExprNode getValidatedSubtree(ExprNodeOrigin origin, ExprNode exprNode, ExprValidationContext validationContext)
          Validates the expression node subtree that has this node as root.
static boolean hasRemoveStreamForAggregations(ExprNode child, StreamTypeService streamTypeService, boolean unidirectionalJoin)
          Returns true if all properties within the expression are witin data window'd streams.
static boolean hasStreamSelect(java.util.List<ExprNode> exprNodes)
           
static boolean isAllConstants(java.util.List<ExprNode> parameters)
           
static boolean isConstantValueExpr(ExprNode exprNode)
           
static java.lang.String isMinimalExpression(ExprNode expression)
          Check if the expression is minimal: does not have a subselect, aggregation and does not need view resources
static ExprEvaluator makeUnderlyingEvaluator(int streamNum, java.lang.Class resultType, TableMetadata tableMetadata)
           
static ExprNodeUtility.MappedPropertyParseResult parseMappedProperty(java.lang.String property)
          Parse the mapped property into classname, method and string argument.
static java.lang.String printEvaluators(ExprEvaluator[] evaluators)
           
static void replaceChainChildNode(ExprNode nodeToReplace, ExprNode newNode, java.util.List<ExprChainedSpec> chainSpec)
           
static void replaceChildNode(ExprNode parentNode, ExprNode nodeToReplace, ExprNode newNode)
           
static ExprNodeUtilMethodDesc resolveMethodAllowWildcardAndStream(java.lang.String className, java.lang.Class optionalClass, java.lang.String methodName, java.util.List<ExprNode> parameters, MethodResolutionService methodResolutionService, EventAdapterService eventAdapterService, java.lang.String statementId, boolean allowWildcard, EventType wildcardType, ExprNodeUtilResolveExceptionHandler exceptionHandler, java.lang.String functionName, TableService tableService)
           
static ExprNode[] toArray(java.util.Collection<ExprNode> expressions)
           
static ExprDeclaredNode[] toArray(java.util.List<ExprDeclaredNode> declaredNodes)
           
static ScheduleSpec toCrontabSchedule(ExprNodeOrigin origin, java.util.List<ExprNode> scheduleSpecExpressionList, StatementContext context, boolean allowBindingConsumption)
           
static void toExpressionString(java.util.List<ExprChainedSpec> chainSpec, java.io.StringWriter buffer, boolean prefixDot, java.lang.String functionName)
           
static void toExpressionStringIncludeParen(java.util.List<ExprNode> parameters, java.io.StringWriter buffer)
           
static java.lang.String toExpressionStringMinPrecedence(ExprNode[] nodes)
           
static java.lang.String toExpressionStringMinPrecedenceSafe(ExprNode node)
           
static void toExpressionStringParameterList(ExprNode[] childNodes, java.io.StringWriter buffer)
           
static void toExpressionStringParameterList(java.util.List<ExprNode> parameters, java.io.StringWriter buffer)
           
static void toExpressionStringParams(java.io.StringWriter writer, ExprNode[] params)
           
static java.lang.String[] toExpressionStringsMinPrecedence(ExprNode[] expressions)
           
static void toExpressionStringWFunctionName(java.lang.String functionName, ExprNode[] childNodes, java.io.StringWriter writer)
           
static void validate(ExprNodeOrigin origin, java.util.List<ExprChainedSpec> chainSpec, ExprValidationContext validationContext)
           
static void validateNamed(java.util.Map<java.lang.String,ExprNamedParameterNode> namedExpressions, java.lang.String[] namedParameters)
           
static boolean validateNamedExpectType(ExprNamedParameterNode namedParameterNode, java.lang.Class[] expectedTypes)
           
static void validateNoSpecialsGroupByExpressions(ExprNode[] groupByNodes)
           
static void validatePlainExpression(ExprNodeOrigin origin, java.lang.String expressionTextualName, ExprNode expression)
           
static ExprNode validateSimpleGetSubtree(ExprNodeOrigin origin, ExprNode expression, StatementContext statementContext, EventType optionalEventType, boolean allowBindingConsumption)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_EXPR_ARRAY

public static final ExprNode[] EMPTY_EXPR_ARRAY

EMPTY_DECLARED_ARR

public static final ExprDeclaredNode[] EMPTY_DECLARED_ARR
Constructor Detail

ExprNodeUtility

public ExprNodeUtility()
Method Detail

deepEqualsIsSubset

public static boolean deepEqualsIsSubset(ExprNode[] subset,
                                         ExprNode[] superset)

deepEqualsIgnoreDupAndOrder

public static boolean deepEqualsIgnoreDupAndOrder(ExprNode[] setOne,
                                                  ExprNode[] setTwo)

getDeclaredExpressionCallHierarchy

public static java.util.Map<ExprDeclaredNode,java.util.List<ExprDeclaredNode>> getDeclaredExpressionCallHierarchy(ExprDeclaredNode[] declaredExpressions)

toExpressionStringMinPrecedenceSafe

public static java.lang.String toExpressionStringMinPrecedenceSafe(ExprNode node)

toExpressionStringMinPrecedence

public static java.lang.String toExpressionStringMinPrecedence(ExprNode[] nodes)

checkGetAssignmentToProp

public static Pair<java.lang.String,ExprNode> checkGetAssignmentToProp(ExprNode node)

checkGetAssignmentToVariableOrProp

public static Pair<java.lang.String,ExprNode> checkGetAssignmentToVariableOrProp(ExprNode node)
                                                                          throws ExprValidationException
Throws:
ExprValidationException

applyFilterExpressionsIterable

public static void applyFilterExpressionsIterable(java.lang.Iterable<EventBean> iterable,
                                                  java.util.List<ExprNode> filterExpressions,
                                                  ExprEvaluatorContext exprEvaluatorContext,
                                                  java.util.Collection<EventBean> eventsInWindow)

applyFilterExpressionIterable

public static void applyFilterExpressionIterable(java.util.Iterator<EventBean> iterator,
                                                 ExprEvaluator filterExpression,
                                                 ExprEvaluatorContext exprEvaluatorContext,
                                                 java.util.Collection<EventBean> eventsInWindow)

connectExpressionsByLogicalAnd

public static ExprNode connectExpressionsByLogicalAnd(java.util.List<ExprNode> nodes,
                                                      ExprNode optionalAdditionalFilter)

connectExpressionsByLogicalAnd

public static ExprAndNode connectExpressionsByLogicalAnd(java.util.Collection<ExprNode> nodes)

getExpressionProperties

public static java.util.List<Pair<java.lang.Integer,java.lang.String>> getExpressionProperties(ExprNode exprNode,
                                                                                               boolean visitAggregateNodes)
Walk expression returning properties used.

Parameters:
exprNode - to walk
visitAggregateNodes - true to visit aggregation nodes
Returns:
list of props

isConstantValueExpr

public static boolean isConstantValueExpr(ExprNode exprNode)

getValidatedSubtree

public static ExprNode getValidatedSubtree(ExprNodeOrigin origin,
                                           ExprNode exprNode,
                                           ExprValidationContext validationContext)
                                    throws ExprValidationException
Validates the expression node subtree that has this node as root. Some of the nodes of the tree, including the root, might be replaced in the process.

Returns:
the root node of the validated subtree, possibly different than the root node of the unvalidated subtree
Throws:
ExprValidationException - when the validation fails

getValidatedSubtree

public static void getValidatedSubtree(ExprNodeOrigin origin,
                                       ExprNode[] exprNode,
                                       ExprValidationContext validationContext)
                                throws ExprValidationException
Throws:
ExprValidationException

getValidatedSubtree

public static void getValidatedSubtree(ExprNodeOrigin origin,
                                       ExprNode[][] exprNode,
                                       ExprValidationContext validationContext)
                                throws ExprValidationException
Throws:
ExprValidationException

getValidatedAssignment

public static ExprNode getValidatedAssignment(OnTriggerSetAssignment assignment,
                                              ExprValidationContext validationContext)
                                       throws ExprValidationException
Throws:
ExprValidationException

parseMappedProperty

public static ExprNodeUtility.MappedPropertyParseResult parseMappedProperty(java.lang.String property)
Parse the mapped property into classname, method and string argument. Mind this has been parsed already and is a valid mapped property.

Parameters:
property - is the string property to be passed as a static method invocation
Returns:
descriptor object

isAllConstants

public static boolean isAllConstants(java.util.List<ExprNode> parameters)

getExprIdentNode

public static ExprIdentNode getExprIdentNode(EventType[] typesPerStream,
                                             int streamId,
                                             java.lang.String property)

getExprResultTypes

public static java.lang.Class[] getExprResultTypes(ExprEvaluator[] evaluators)

getExprResultTypes

public static java.lang.Class[] getExprResultTypes(java.util.List<ExprNode> expressions)

resolveMethodAllowWildcardAndStream

public static ExprNodeUtilMethodDesc resolveMethodAllowWildcardAndStream(java.lang.String className,
                                                                         java.lang.Class optionalClass,
                                                                         java.lang.String methodName,
                                                                         java.util.List<ExprNode> parameters,
                                                                         MethodResolutionService methodResolutionService,
                                                                         EventAdapterService eventAdapterService,
                                                                         java.lang.String statementId,
                                                                         boolean allowWildcard,
                                                                         EventType wildcardType,
                                                                         ExprNodeUtilResolveExceptionHandler exceptionHandler,
                                                                         java.lang.String functionName,
                                                                         TableService tableService)
                                                                  throws ExprValidationException
Throws:
ExprValidationException

validatePlainExpression

public static void validatePlainExpression(ExprNodeOrigin origin,
                                           java.lang.String expressionTextualName,
                                           ExprNode expression)
                                    throws ExprValidationException
Throws:
ExprValidationException

validateSimpleGetSubtree

public static ExprNode validateSimpleGetSubtree(ExprNodeOrigin origin,
                                                ExprNode expression,
                                                StatementContext statementContext,
                                                EventType optionalEventType,
                                                boolean allowBindingConsumption)
                                         throws ExprValidationException
Throws:
ExprValidationException

getPropertyNamesIfAllProps

public static java.util.Set<java.lang.String> getPropertyNamesIfAllProps(ExprNode[] expressions)

toExpressionStringsMinPrecedence

public static java.lang.String[] toExpressionStringsMinPrecedence(ExprNode[] expressions)

findExpression

public static java.util.List<Pair<ExprNode,ExprNode>> findExpression(ExprNode selectExpression,
                                                                     ExprNode searchExpression)

toExpressionStringParameterList

public static void toExpressionStringParameterList(ExprNode[] childNodes,
                                                   java.io.StringWriter buffer)

toExpressionStringWFunctionName

public static void toExpressionStringWFunctionName(java.lang.String functionName,
                                                   ExprNode[] childNodes,
                                                   java.io.StringWriter writer)

getIdentResolvedPropertyNames

public static java.lang.String[] getIdentResolvedPropertyNames(ExprNode[] nodes)

getExprResultTypes

public static java.lang.Class[] getExprResultTypes(ExprNode[] groupByNodes)

makeUnderlyingEvaluator

public static ExprEvaluator makeUnderlyingEvaluator(int streamNum,
                                                    java.lang.Class resultType,
                                                    TableMetadata tableMetadata)

hasStreamSelect

public static boolean hasStreamSelect(java.util.List<ExprNode> exprNodes)

validateNoSpecialsGroupByExpressions

public static void validateNoSpecialsGroupByExpressions(ExprNode[] groupByNodes)
                                                 throws ExprValidationException
Throws:
ExprValidationException

getNamedExpressionsHandleDups

public static java.util.Map<java.lang.String,ExprNamedParameterNode> getNamedExpressionsHandleDups(java.util.List<ExprNode> parameters)
                                                                                            throws ExprValidationException
Throws:
ExprValidationException

validateNamed

public static void validateNamed(java.util.Map<java.lang.String,ExprNamedParameterNode> namedExpressions,
                                 java.lang.String[] namedParameters)
                          throws ExprValidationException
Throws:
ExprValidationException

validateNamedExpectType

public static boolean validateNamedExpectType(ExprNamedParameterNode namedParameterNode,
                                              java.lang.Class[] expectedTypes)
                                       throws ExprValidationException
Throws:
ExprValidationException

acceptChain

public static void acceptChain(ExprNodeVisitor visitor,
                               java.util.List<ExprChainedSpec> chainSpec)

acceptChain

public static void acceptChain(ExprNodeVisitorWithParent visitor,
                               java.util.List<ExprChainedSpec> chainSpec)

acceptChain

public static void acceptChain(ExprNodeVisitorWithParent visitor,
                               java.util.List<ExprChainedSpec> chainSpec,
                               ExprNode parent)

replaceChildNode

public static void replaceChildNode(ExprNode parentNode,
                                    ExprNode nodeToReplace,
                                    ExprNode newNode)

replaceChainChildNode

public static void replaceChainChildNode(ExprNode nodeToReplace,
                                         ExprNode newNode,
                                         java.util.List<ExprChainedSpec> chainSpec)

getNonAggregatedProps

public static ExprNodePropOrStreamSet getNonAggregatedProps(EventType[] types,
                                                            java.util.List<ExprNode> exprNodes,
                                                            ContextPropertyRegistry contextPropertyRegistry)

addNonAggregatedProps

public static void addNonAggregatedProps(ExprNode exprNode,
                                         ExprNodePropOrStreamSet set,
                                         EventType[] types,
                                         ContextPropertyRegistry contextPropertyRegistry)

getAggregatedProperties

public static ExprNodePropOrStreamSet getAggregatedProperties(java.util.List<ExprAggregateNode> aggregateNodes)

getEvaluators

public static ExprEvaluator[] getEvaluators(ExprNode[] exprNodes)

getEvaluators

public static ExprEvaluator[] getEvaluators(java.util.List<ExprNode> childNodes)

getIdentStreamNumbers

public static java.util.Set<java.lang.Integer> getIdentStreamNumbers(ExprNode child)

hasRemoveStreamForAggregations

public static boolean hasRemoveStreamForAggregations(ExprNode child,
                                                     StreamTypeService streamTypeService,
                                                     boolean unidirectionalJoin)
Returns true if all properties within the expression are witin data window'd streams.

Parameters:
child - expression to interrogate
streamTypeService - streams
Returns:
indicator

applyFilterExpression

public static EventBean[] applyFilterExpression(ExprEvaluator filter,
                                                EventBean streamZeroEvent,
                                                EventBean[] streamOneEvents,
                                                ExprEvaluatorContext exprEvaluatorContext)
Apply a filter expression.

Parameters:
filter - expression
streamZeroEvent - the event that represents stream zero
streamOneEvents - all events thate are stream one events
exprEvaluatorContext - context for expression evaluation
Returns:
filtered stream one events

applyFilterExpression

public static boolean applyFilterExpression(ExprEvaluator filter,
                                            EventBean[] eventsPerStream,
                                            ExprEvaluatorContext exprEvaluatorContext)
Apply a filter expression returning a pass indicator.

Parameters:
filter - to apply
eventsPerStream - events per stream
exprEvaluatorContext - context for expression evaluation
Returns:
pass indicator

deepEquals

public static boolean deepEquals(ExprNode nodeOne,
                                 ExprNode nodeTwo)
Compare two expression nodes and their children in exact child-node sequence, returning true if the 2 expression nodes trees are equals, or false if they are not equals.

Recursive call since it uses this method to compare child nodes in the same exact sequence. Nodes are compared using the equalsNode method.

Parameters:
nodeOne - - first expression top node of the tree to compare
nodeTwo - - second expression top node of the tree to compare
Returns:
false if this or all child nodes are not equal, true if equal

deepEquals

public static boolean deepEquals(ExprNode[] one,
                                 ExprNode[] two)
Compares two expression nodes via deep comparison, considering all child nodes of either side.

Parameters:
one - array of expressions
two - array of expressions
Returns:
true if the expressions are equal, false if not

deepEquals

public static boolean deepEquals(java.util.List<ExprNode> one,
                                 java.util.List<ExprNode> two)

isMinimalExpression

public static java.lang.String isMinimalExpression(ExprNode expression)
Check if the expression is minimal: does not have a subselect, aggregation and does not need view resources

Parameters:
expression - to inspect
Returns:
null if minimal, otherwise name of offending sub-expression

toExpressionString

public static void toExpressionString(java.util.List<ExprChainedSpec> chainSpec,
                                      java.io.StringWriter buffer,
                                      boolean prefixDot,
                                      java.lang.String functionName)

toExpressionStringParameterList

public static void toExpressionStringParameterList(java.util.List<ExprNode> parameters,
                                                   java.io.StringWriter buffer)

toExpressionStringIncludeParen

public static void toExpressionStringIncludeParen(java.util.List<ExprNode> parameters,
                                                  java.io.StringWriter buffer)

validate

public static void validate(ExprNodeOrigin origin,
                            java.util.List<ExprChainedSpec> chainSpec,
                            ExprValidationContext validationContext)
                     throws ExprValidationException
Throws:
ExprValidationException

collectChainParameters

public static java.util.List<ExprNode> collectChainParameters(java.util.List<ExprChainedSpec> chainSpec)

toExpressionStringParams

public static void toExpressionStringParams(java.io.StringWriter writer,
                                            ExprNode[] params)

printEvaluators

public static java.lang.String printEvaluators(ExprEvaluator[] evaluators)

toCrontabSchedule

public static ScheduleSpec toCrontabSchedule(ExprNodeOrigin origin,
                                             java.util.List<ExprNode> scheduleSpecExpressionList,
                                             StatementContext context,
                                             boolean allowBindingConsumption)
                                      throws ExprValidationException
Throws:
ExprValidationException

evaluateExpressions

public static java.lang.Object[] evaluateExpressions(ExprEvaluator[] parameters,
                                                     ExprEvaluatorContext exprEvaluatorContext)

toArray

public static ExprNode[] toArray(java.util.Collection<ExprNode> expressions)

toArray

public static ExprDeclaredNode[] toArray(java.util.List<ExprDeclaredNode> declaredNodes)

getGroupByPropertiesValidateHasOne

public static ExprNodePropOrStreamSet getGroupByPropertiesValidateHasOne(ExprNode[] groupByNodes)
                                                                  throws ExprValidationException
Throws:
ExprValidationException

© 2006-2015 EsperTech Inc.
All rights reserved.
Visit us at espertech.com