Package org.apache.solr.analytics
Class ExpressionFactory
- java.lang.Object
-
- org.apache.solr.analytics.ExpressionFactory
-
public class ExpressionFactory extends Object
A factory to parse and create expressions, and capture information about those expressions along the way.In order to use, first call
startRequest()and create all ungrouped expressions, then callcreateReductionManager(boolean)to get the ungrouped reduction manager.
Then for each grouping callstartGrouping()first then create all expressions within that grouping, finally callingcreateGroupingReductionManager(boolean)to get the reduction manager for that grouping.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceExpressionFactory.ConstantFunctionUsed to initialize analytics constants.static interfaceExpressionFactory.CreatorFunctionUsed for system analytics functions for initialization.
-
Field Summary
Fields Modifier and Type Field Description static charvariableForEachParamThe character used to denote the looped parameter in the for each lambda expressionstatic charvariableForEachSepThe character used to denote the start of a for each lambda expressionstatic StringvariableLengthParamSuffixUsed to denote a variable length parameter.
-
Constructor Summary
Constructors Constructor Description ExpressionFactory(IndexSchema schema)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExpressionFactoryaddSystemFunction(String functionName, ExpressionFactory.CreatorFunction functionCreator)Add a system function to the expression factory.voidaddSystemFunctions()Add the natively supported functionality.ExpressionFactoryaddSystemVariableFunction(String functionName, String functionParams, String returnSignature)Add a variable function that will be treated like a system function.ExpressionFactoryaddUserDefinedVariableFunction(String functionSignature, String returnSignature)Add a variable function that was defined in an analytics request.AnalyticsValueStreamcreateExpression(String expressionStr)Parse and build an expression from the given expression string.ReductionCollectionManagercreateGroupingReductionManager(boolean isCloudCollection)Create a reduction manager to manage the collection of all expressions that have been created sincestartGrouping()was called.ReductionCollectionManagercreateReductionManager(boolean isCloudCollection)Create a reduction manager to manage the collection of all expressions that have been created sincestartRequest()was called.IndexSchemagetSchema()Get the index schema used by this factory.voidstartGrouping()Prepare the factory to start building the next grouping.voidstartRequest()Prepare the factory to start building the request.
-
-
-
Field Detail
-
variableLengthParamSuffix
public static final String variableLengthParamSuffix
Used to denote a variable length parameter.- See Also:
- Constant Field Values
-
variableForEachSep
public static final char variableForEachSep
The character used to denote the start of a for each lambda expression- See Also:
- Constant Field Values
-
variableForEachParam
public static final char variableForEachParam
The character used to denote the looped parameter in the for each lambda expression- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExpressionFactory
public ExpressionFactory(IndexSchema schema)
-
-
Method Detail
-
getSchema
public IndexSchema getSchema()
Get the index schema used by this factory.- Returns:
- the index schema
-
startRequest
public void startRequest()
Prepare the factory to start building the request.
-
startGrouping
public void startGrouping()
Prepare the factory to start building the next grouping.
NOTE: MUST be called before each new grouping.
-
addSystemFunction
public ExpressionFactory addSystemFunction(String functionName, ExpressionFactory.CreatorFunction functionCreator) throws org.apache.solr.common.SolrException
Add a system function to the expression factory. This will be treated as a native function and not a variable function.- Parameters:
functionName- the unique name for the functionfunctionCreator- the creator function to generate an expression- Returns:
- this factory, to easily chain function adds
- Throws:
org.apache.solr.common.SolrException- if the functionName is not unique
-
addSystemVariableFunction
public ExpressionFactory addSystemVariableFunction(String functionName, String functionParams, String returnSignature) throws org.apache.solr.common.SolrException
Add a variable function that will be treated like a system function.- Parameters:
functionName- the function's namefunctionParams- the comma separated and ordered parameters of the function (e.g."a,b")returnSignature- the return signature of the variable function (e.g.div(sum(a,b),count(b)))- Returns:
- this factory, to easily chain function adds
- Throws:
org.apache.solr.common.SolrException- if the name of the function is not unique or the syntax of either signature is incorrect
-
addUserDefinedVariableFunction
public ExpressionFactory addUserDefinedVariableFunction(String functionSignature, String returnSignature) throws org.apache.solr.common.SolrException
Add a variable function that was defined in an analytics request.- Parameters:
functionSignature- the function signature of the variable function (e.g.func(a,b))returnSignature- the return signature of the variable function (e.g.div(sum(a,b),count(b)))- Returns:
- this factory, to easily chain function adds
- Throws:
org.apache.solr.common.SolrException- if the name of the function is not unique or the syntax of either signature is incorrect
-
createReductionManager
public ReductionCollectionManager createReductionManager(boolean isCloudCollection)
Create a reduction manager to manage the collection of all expressions that have been created sincestartRequest()was called.- Parameters:
isCloudCollection- whether the request is a distributed request- Returns:
- a reduction manager
-
createGroupingReductionManager
public ReductionCollectionManager createGroupingReductionManager(boolean isCloudCollection)
Create a reduction manager to manage the collection of all expressions that have been created sincestartGrouping()was called.- Parameters:
isCloudCollection- whether the request is a distributed request- Returns:
- a reduction manager
-
createExpression
public AnalyticsValueStream createExpression(String expressionStr) throws org.apache.solr.common.SolrException
Parse and build an expression from the given expression string.- Parameters:
expressionStr- string that represents the desired expression- Returns:
- the object representation of the expression
- Throws:
org.apache.solr.common.SolrException- if an error occurs while constructing the expression
-
addSystemFunctions
public void addSystemFunctions()
Add the natively supported functionality.
-
-