Package org.openrefine.operations
Class ExpressionBasedOperation
- java.lang.Object
-
- org.openrefine.operations.EngineDependentOperation
-
- org.openrefine.operations.RowMapOperation
-
- org.openrefine.operations.ExpressionBasedOperation
-
- All Implemented Interfaces:
Operation
- Direct Known Subclasses:
ColumnAdditionByFetchingURLsOperation
,ColumnAdditionOperation
,MassEditOperation
,TextTransformOperation
public abstract class ExpressionBasedOperation extends RowMapOperation
Base class for an operation which evaluates an expression on rows or records, and then uses it to derive the new grid. Depending on whether the expression is local or not, the operation will compute it lazily (with aRowMapper
orRecordMapper
) or will evaluate it eagerly and store the evaluation results in aChangeData
object, so that expensive evaluations (or expressions with side effects) are not evaluated multiple times.- Author:
- Antonin Delpeuch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ExpressionBasedOperation.NegativeRowMapper
protected static class
ExpressionBasedOperation.PositiveRowMapper
Row mapper which calls a change data producer (to evaluate the expression) and directly calls the corresponding change data joiner (to insert the results in the row).-
Nested classes/interfaces inherited from class org.openrefine.operations.RowMapOperation
RowMapOperation.GridMap
-
-
Field Summary
Fields Modifier and Type Field Description protected String
_baseColumnName
protected String
_changeDataId
protected Evaluable
_eval
protected String
_expression
protected boolean
_forceEagerEvaluation
protected OnError
_onError
protected int
_repeatCount
-
Fields inherited from class org.openrefine.operations.EngineDependentOperation
_engineConfig
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExpressionBasedOperation(EngineConfig engineConfig, String expression, String baseColumnName, OnError onError, int repeatCount)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ChangeResult
apply(Grid projectState, ChangeContext context)
Derives the new grid state from the current grid state.protected abstract RowInRecordChangeDataJoiner
changeDataJoiner(Grid grid, ChangeContext context)
Returns the joiner used to insert the result of the evaluation of the expression into a row or record.static RowInRecordChangeDataProducer<Cell>
evaluatingChangeDataProducer(int columnIndex, String baseColumnName, OnError onError, int repeatCount, Evaluable eval, ColumnModel columnModel, Map<String,OverlayModel> overlayModels, long projectId)
protected RowInRecordChangeDataProducer<Cell>
getChangeDataProducer(Grid state, ChangeContext context)
protected Evaluable
getEvaluable()
protected RowMapOperation.GridMap
getGridMap(Grid state, ChangeContext context)
Returns the function that is applied to each row and row index, the new column model applied to the grid, and the new overlay models.protected ColumnModel
getNewColumnModel(Grid state, ChangeContext context, Evaluable eval)
Returns the new column model after the operation has run.protected Map<String,OverlayModel>
getNewOverlayModels(Grid state, ChangeContext context, Evaluable evaluable)
Returns the new overlay models after this change is applied.protected Grid
postTransform(Grid state, ChangeContext context, Evaluable eval)
-
Methods inherited from class org.openrefine.operations.RowMapOperation
getNegativeRowMapper, getNewColumnModel, getNewOverlayModels, getPositiveRowMapper, postTransform
-
Methods inherited from class org.openrefine.operations.EngineDependentOperation
getEngine, getEngineConfig
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openrefine.operations.Operation
getDescription, getOperationId, isReproducible
-
-
-
-
Field Detail
-
_expression
protected final String _expression
-
_baseColumnName
protected final String _baseColumnName
-
_onError
protected final OnError _onError
-
_repeatCount
protected final int _repeatCount
-
_changeDataId
protected String _changeDataId
-
_forceEagerEvaluation
protected boolean _forceEagerEvaluation
-
_eval
protected Evaluable _eval
-
-
Constructor Detail
-
ExpressionBasedOperation
protected ExpressionBasedOperation(EngineConfig engineConfig, String expression, String baseColumnName, OnError onError, int repeatCount)
-
-
Method Detail
-
changeDataJoiner
protected abstract RowInRecordChangeDataJoiner changeDataJoiner(Grid grid, ChangeContext context) throws OperationException
Returns the joiner used to insert the result of the evaluation of the expression into a row or record. Depending on whether the expression is local or not (seeEvaluable.isLocal()
), this will either be used to build a row / record mapper to apply the change lazily on the grid, or the results of the evaluation will be stored in aChangeData
object which will then be joined by this joiner.- Parameters:
grid
- the initial state of the grid- Throws:
OperationException
-
getNewColumnModel
protected ColumnModel getNewColumnModel(Grid state, ChangeContext context, Evaluable eval) throws OperationException
Returns the new column model after the operation has run.- Throws:
OperationException
-
getNewOverlayModels
protected Map<String,OverlayModel> getNewOverlayModels(Grid state, ChangeContext context, Evaluable evaluable) throws OperationException
Returns the new overlay models after this change is applied.- Throws:
OperationException
-
postTransform
protected Grid postTransform(Grid state, ChangeContext context, Evaluable eval) throws OperationException
- Throws:
OperationException
-
apply
public ChangeResult apply(Grid projectState, ChangeContext context) throws OperationException
Description copied from interface:Operation
Derives the new grid state from the current grid state. Executing this method should be quick (even on large datasets) since it is expected to just derive the new grid from the existing one without actually executing any expensive computation. Long-running computations should rather go in the derivation of aChangeData
which will be fetched asynchronously.- Specified by:
apply
in interfaceOperation
- Overrides:
apply
in classRowMapOperation
- Parameters:
projectState
- the state of the grid before the change- Returns:
- an object which bundles up various pieces of information produced by the operation: primarily, the new grid after applying the operation. This object can be subclassed to expose more information, which should be serializable with Jackson so that it reaches the frontend.
- Throws:
OperationException
- when the change cannot be applied to the given grid
-
getEvaluable
protected Evaluable getEvaluable() throws OperationException
- Throws:
OperationException
-
getGridMap
protected RowMapOperation.GridMap getGridMap(Grid state, ChangeContext context) throws OperationException
Description copied from class:RowMapOperation
Returns the function that is applied to each row and row index, the new column model applied to the grid, and the new overlay models. Computing these in one go can be useful in certain situations, for instance when the number of columns added to the column model depends on the data. If a subclass needs to return only one non-default value out of mapper, column model and overlay models it can instead override the corresponding method.- Overrides:
getGridMap
in classRowMapOperation
- Parameters:
state
- the initial column model- Throws:
OperationException
- if the change does not apply to the given grid
-
getChangeDataProducer
protected RowInRecordChangeDataProducer<Cell> getChangeDataProducer(Grid state, ChangeContext context) throws OperationException
- Throws:
OperationException
-
evaluatingChangeDataProducer
public static RowInRecordChangeDataProducer<Cell> evaluatingChangeDataProducer(int columnIndex, String baseColumnName, OnError onError, int repeatCount, Evaluable eval, ColumnModel columnModel, Map<String,OverlayModel> overlayModels, long projectId)
-
-