Interface ModelFormulaContextReadWrite
- All Superinterfaces:
ModelFormulaContextReadOnly
- All Known Subinterfaces:
ModelCalculationFormulaContext,ModelParallelCalculationFormulaInitContext,ModelParallelCalculationFormulaSummaryContext
-
Method Summary
Modifier and TypeMethodDescriptionAdd a table in the model.booleandropAttachment(String name) Delete all versions of the attachment with the name.voiddropTable(DatamartContext.Table table) longloadTable(DatamartContext.Table table, DatamartContext.Query query, boolean truncate) Deprecated.longloadTable(DatamartContext.Table table, DatamartContext.SqlQuery query, boolean truncate) Deprecated.longloadTable(DatamartContext.Table table, PipelineStage query, boolean truncate) Sample code:longloadTable(DatamartContext.Table table, PipelineStage query, boolean truncate, boolean updateRows) Same asloadTable(DatamartContext.Table, PipelineStage, boolean)but allows controlling whether unmentioned columns are nullified (delete+insert) or preserved (merge) for rows with matching key values.voidstartJobTriggerCalculation(String imageName, String imageTag, String parameters, String jobName) It is the responsibility of the caller to serializeparametershowever they are required by the image.voidMethods inherited from interface ModelFormulaContextReadOnly
attachmentDownloadURL, currentStep, inputs, label, outputs, pmmlContext, rContext, table, tableNames, typedId, uniqueName
-
Method Details
-
addTable
Add a table in the model. If the table already exists, it is replaced by this new table.As with all Field Collections in Pricefx, labels must be unique.
The
tableSpecsmap supports the following entries:label(optional): the table label. Defaults to the table name.fields(required): a non-emptyListof field definitions. Each field definition is aMapwith the following entries:name(required): the field name. It must start with a letter, followed by letters, digits or underscores. It must not be the name of a system field.type(required): the name of aFieldTypevalue, e.g."TEXT"or"MONEY". The value is case-insensitive.label(optional): the field label.key(optional):trueif the field is part of the table's primary key. Only the typesTEXT,INTEGER,CURRENCY,UOM,DATEandDATETIMEare supported for key fields. A key field is always a dimension.dimension(optional):trueif the field is a dimension. Only applies to the typesTEXT,INTEGER,CURRENCY,UOM,DATEandDATETIME. For other types, it is ignored.format(optional): the display format of a numeric field (NUMBER,INTEGER,QUANTITYorMONEY). See Formatting Numbers for the supported formats.rank(optional): the position of the field in the table. If no field has a rank, the order of thefieldslist is used.metaDescription(optional): a description of the field.
Sample code:
model.addTable("RevenueByProduct", [ label: "Revenue By Product", fields: [ [ name:"productId", label:"Product ID", type:"TEXT", key:true], [ name:"productGroup", label:"ProductGroup", type:"TEXT", dimension:true], [ name:"revenue", label:"Revenue", type:"MONEY"], ] ])- Parameters:
name- The table name to be created in this modeltableSpecs- The definition of the table to be created, see above.- Returns:
- The created model table
- Since:
- 8.0 - Godfather
-
loadTable
@Deprecated long loadTable(DatamartContext.Table table, DatamartContext.Query query, boolean truncate) throws InterruptedException Deprecated.Sample code:def ctx = api.getDatamartContext() def query = ctx.newQuery(ctx.getDataSource("txDS")) .select("sku", "P") .select("SUM(amount)", "R") def table = model.getTable('MyTable') def nbRowAdded = model.loadTable(table, query, false)- Parameters:
table- A table in this modelquery- The query to load into the tabletruncate- If the table should be truncated before loading- Returns:
- The number of rows added
- Throws:
InterruptedException- Since:
- 8.0 - Godfather
- See Also:
-
loadTable
@Deprecated long loadTable(DatamartContext.Table table, DatamartContext.SqlQuery query, boolean truncate) throws InterruptedException Deprecated.Sample code:def ctx = api.getDatamartContext() def t1 = ctx.newQuery(ctx.getDataSource("txDS")) .select("sku", "P") .select("SUM(amount)", "R") def query = ctx.newSqlQuery() query.addSource(t1) query.setQuery('SELECT P, R::numeric as R FROM T1 ORDER BY P') def table = model.getTable('MyTable') def nbRowAdded = model.loadTable(table, query, false)- Parameters:
table- A table in this modelquery- The query to load into the tabletruncate- If the table should be truncated before loading- Returns:
- The number of rows added
- Throws:
InterruptedException- Since:
- 8.0 - Godfather
- See Also:
-
loadTable
long loadTable(DatamartContext.Table table, PipelineStage query, boolean truncate) throws InterruptedException Sample code:def qapi = api.queryApi() def ds = qapi.tables().dataSource("txDS") def query = qapi .source(ds, [ds.sku, ds.amount]) .aggregateBy({ t -> [t.sku] }, { t -> [t.sku.as("P"), qapi.exprs().sum(t.amount).as("R")] }) .sortBy { t -> [qapi.orders().ascNullsLast(t.P)] } def table = model.getTable('MyTable') def nbRowAdded = model.loadTable(table, query, false)- Parameters:
table- A table in this modelquery- The query to load into the tabletruncate- If the table should be truncated before loading- Returns:
- The number of row added
- Throws:
InterruptedException- Since:
- 15.0 - Southside
- See Also:
-
loadTable
long loadTable(DatamartContext.Table table, PipelineStage query, boolean truncate, boolean updateRows) throws InterruptedException Same asloadTable(DatamartContext.Table, PipelineStage, boolean)but allows controlling whether unmentioned columns are nullified (delete+insert) or preserved (merge) for rows with matching key values.- Parameters:
table- A table in this modelquery- The query to load into the tabletruncate- If the table should be truncated before loadingupdateRows- Iftrue, for rows with matching keys, only mentioned columns are updated (merge semantics). Iffalse, those rows are deleted and re-inserted so any unmentioned columns becomenull(delete+insert semantics, ADR_0008 REPLACE-like behavior).- Returns:
- The number of rows added
- Throws:
InterruptedException- Since:
- 17.0
-
truncateTable
- Parameters:
table- A table in the model- Since:
- 8.0 - Godfather
-
dropTable
- Parameters:
table- A table in the model- Since:
- 8.0 - Godfather
-
startJobTriggerCalculation
void startJobTriggerCalculation(String imageName, String imageTag, String parameters, String jobName) It is the responsibility of the caller to serializeparametershowever they are required by the image.parametersshould only contain a few values. Because of infrastructure limitations, its max length is 131000 bytes. If you need to give a large amount of data, you should consider using model tables.jobNameshould be unique inside the step and model formula calculation that triggers them. Since Job Trigger Calculations are created from within an existing formula calculation, its full name will be constructed from the calculation name and the job name passed to this method:calculationName:jobName. This name can be used to access the Job Trigger Calculation results withModelFormulaContextReadOnly.outputs(String, String).Multiple job trigger calculation in a given formula calculation will run in parallel.
- Parameters:
imageName- A docker image name, without the tagimageTag- A tag for the docker image nameparameters- Some parameters understood by the image usedjobName- A name for the job, unique per current step and calculation- Since:
- 8.0 - Godfather
-
dropAttachment
Delete all versions of the attachment with the name.- Parameters:
name- name of the attachment(s) to delete- Returns:
trueif attachment(s) were deleted- Since:
- 15.0 - Southside
-
lookupTablesContext
ModelLookupTablesContextReadWrite lookupTablesContext()- Specified by:
lookupTablesContextin interfaceModelFormulaContextReadOnly- Returns:
- a context for read/write operations on the lookup tables of this model
- Since:
- 9.0 - Hurricane
-
filterTreesContext
ModelFilterTreesContextReadWrite filterTreesContext()- Specified by:
filterTreesContextin interfaceModelFormulaContextReadOnly- Returns:
- a context for read/write operations on the filter trees of this model
- Since:
- 9.0 - Hurricane
-
schedulesContext
ModelSchedulesContextReadWrite schedulesContext()- Specified by:
schedulesContextin interfaceModelFormulaContextReadOnly- Returns:
- a context for manipulating Model Schedules
- Since:
- 11.0 - Paper Plane
-
loadTable(DatamartContext.Table, PipelineStage, boolean)instead