Framework to parser user input into an abstract function library and translate that input to the correct sql statement depending on database dialect.
- Instantiate object of
Parsingclass as a singleton in your application (just aspublic static finalvariable or through DI containers such as Spring or Guice). - Use
Parsing.parse(String)method to instantiateFormulaobject. - Use
Formulaobject to perform main operations (such as generating sql clauses). - Use
Hintsobject to generate hints for user input.
For more details please see javadoc and test cases for methods of Formula and Hints classes.
If you need to add new dialect:
- Create new class that implemented
Dialectinterface or extended existed implementation such asGenericSQLorTeradataSQL. - Implement functions that supported by your own dialect.
- Methods have to throw
UnsupportedOperationExceptionif dialect doesn't support appropriate operation.
Please take into account that you should instantiate/use appropriate dialect depending on your database.
For example, you should manually check that your Teradata database has version >= 14 and instantiate Teradata14SQL dialect,
but for the other versions, you should instantiate TeradataSQL dialect.
If you need to add new function:
- Create a class implemented
FormulaElementinterface or extended one of the classes such asScalar2orAggregation. - Set class name that is the name of the function.
- Registry function in one of the following class -
Aggregations,Scalars,Olap. See current implementations and javadoc inFunctionBuilderclass.
If you need to traverse the formula tree and do some action with its elements,
please see implementation of Formula.entityNames or Formula.windowParameters methods.
Just implement what you need in the same way.