Interface ModelFormulaContext

All Superinterfaces:
DistFormulaContext

public interface ModelFormulaContext extends DistFormulaContext
The ModelFormulaContext is exposed to model logics through the model binding. It provides access to a PO specific API, not available in any of the other Pricefx modules. API calls that add, update or delete objects are only possible in a model calculation step.

When called in the 'Definition', 'Analysis' or 'Evaluation' context, no action will be taken, and if any value is to be returned, this value will be null.
A PO model has at least one stage: 'Definition'. This is the context of the PO logic called when saving or updating a model.

It should be noted that the UI updates a model before triggering a calculation (though this is client specific behaviour, not required or enforced by the Pricefx backend). A model is therefore typically updated multiple times in its life cycle, as when first created, it tends to be (re-)calculated many times thereafter.

While not mandatory, a PO model is not likely to be useful, or even needed, when no Calculation steps are defined. Costly, i.e. computationally expensive, time consuming jobs are normally required to be run to prepare a model for future use. In machine learning terminology, one might refer to this as the 'training' phase. Once trained, one might talk about using the model for prediction, or classification. In Pricefx this is achieved by evaluating the model. While, again, optional, a useful model tends to define an 'Evaluation' logic that performs this function.

The ModelType is what pieces this together. Models are created from a chosen ModelType.
The ModelType defines these key characteristics:

  • logic: UniqueName of the main logic; this is the logic that as minimum implements the 'Definition' behaviour. It can also, selectively, define the behaviour in other stages by virtue of setting the 'Calculation Context' on the logic element. (see further down for a list of valid calculation contexts).
  • libLogic: Optional. UniqueName of a logic that serves as a library specific to this ModelType. Its elements can be accessed through the lib binding.
  • analysisLogic: Optional. UniqueName of the logic that is evaluated when triggering an analysis or inspection from the UI. What this looks like is specific to the UI. What is important is that it is a triggered by a datamart.modeleval/analysis request to the JSON API.
  • evalLogic: Optional. UniqueName of the logic that is evaluated when using ('evaluating') a prepared model from other modules, for example from Pricing logic in QuoteConfigurator or PriceBuilder. See ModelEvaluator for details.
  • recordLogic: Optional. UniqueName
  • generatesData: True or false. Indicates that the module will use its PA backing table to store data, result etc. A client can use this flag to decide on whether to show a data table for the model or not.
  • generatesTables: True or false. Indicates that the module will create additional DMTables. A client can use this flag to decide on whether to show a section where these tables can be accessed.
  • generatesRecords: True or false. Indicates that the module will generate ModelRecords (the technical name) aka 'Policy Records' (the UI name). A client can use this flag to decide on whether to show a section where these records can be accessed.
  • generatesTrees: True or false. Indicates that the module will generate one or more trees (see addTree(String, Collection)). A client can use this flag to decide on whether to show a section where these trees can be accessed.
  • calcSteps: Optional. Defines a List, of which each can be triggered independently and in any other, though the expectation is that they would, at least initially, be executed in sequence. Some steps, depending entirely on the PO logic implementation, might be skipped, and some steps might be rerun after the initial calculation. There are no enforced rules; the ModelType documentation should clarify the allowed and desired behaviour.

A CalcStep is defined as:

  • name: The name of the calculation step, to be unique across all steps. This is the value returned by a getCalculationStep() call.
  • label: An optional label or description that can be used by the UI.
  • category: An optional category, that allows a UI to group calculation steps together. In the Unity PO UI, for the Segmentation model type, calculation steps are divided in 'Analysis' steps (not to be confused with the analysis logic behaviour) and 'Calculation' steps. In Segmentation, the 'Analysis' steps are "DataPrep', 'DataProfile' and 'PriceDrivers'. The 'Calculation' steps are 'Segmentation', 'Scoring' and 'Pricing'.
  • logic: The optional UniqueName of the logic to be executed for this step. When not set, the calculation step's logic is assumed to be implemented by the (mandatory) main logic specified in the ModelType.logic attribute.
  • distributed: True or false. Indicates whether this step can be executed in distributed mode. For a non-distributed step, no additional logic level configuration is required. PO will simply execute this step using the associated logic. For a distributed step, however, there is a pre-condition in that some previous step in the model calculation is assumed to have created so called CalculationItems, representing units of work for this step. Each such unit of work can then be executed by one of the workers in a distributed execution pool. There is in fact a threshold, below which the distributed calculation will not kick in (100 by default, set by the formulaEngine.script.optimizer.slaveCalcItemThreshold instance parameter), in order to avoid creating overhead for low number of work units. See addOrUpdateCalcItem(Object, Object, Object) and its variations for more details.

The list of Calculation Contexts is

  • definition: Evaluated when a model is saved
  • calculation: Evaluated in a calculation step
  • calculation-init: Evaluated when calculating a distributed step, once, before the individual CalculationItems are processed
  • calculation-summary: Evaluated when calculating a distributed step, once, after all the individual CalculationItems have been processed
  • analysis: Evaluated in in the Analysis (Classic) and Results (Unity) sections of the UI
  • evaluation: Evaluated when ModelEvaluator.evaluate(Map) is invoked
  • record: Evaluated after a record using addRecord(String, TimePeriod, Map, Map, boolean...) when the calculate == true

  • Method Details

    • getUniqueName

      String getUniqueName()
      Returns:
      The unique name of the model
    • getLabel

      String getLabel()
      Returns:
      The label name of the model
    • getSourceName

      String getSourceName()
      Returns the source name of this model, which is often needed as a parameter in queries, charts and such on the model in the analysis phase; and avoids retreiving the whole model with get().
      Typically used when building a query against the model's backing table, and when defining charts with the model as a source.

      In the 'Segmentation' logic for example, the 'DataPrep' step filters and loads the transaction data in the model's table, and subsequent steps then query the model's table for better performance.

      Note: The source name for a PO model has the form 'DMM.'.

      Returns:
      The source name of the model
    • getDef

      Map<String,Object> getDef()
      A typical (set of) PO logic(s) covers various stages: definition, calculation, analysis, record and evaluation.
      Not all are always needed - the ModelType defines which one are. Still, a persisted data object accessible to all stages is usually required.
      In the 'Segmentation' model type, for example, the selected transactions source and field mapping (product, customer etc. fields) are stored by the Definition logic in the built-in model.def map.

      Note: As the map is persisted in the model, it is important not to put any non-serializable objects in it. When in doubt, stick to Collections of (Collections of...) primitives, String, Number, Date etc.

      Sample code:

      
       model.def.policyStartDate = api.dateUserEntry("Start Date")
       model.def.policyEndDate = api.dateUserEntry("End Date")
       

      Returns:
      The model.def map
    • getDefaults

      Map<String,Object> getDefaults()
      When a clients retrieves the required input parameters for a given stage (definition, calculation step, analysis...), there is the option to set an initial value for a parameter. This is done with code like this snippet:

      
        def PARAM = "Floor Percentile"
        model.def.floorPercentile = api.integerUserEntry(PARAM)
        model.defaults[PARAM] = 50
       

      In a new model, the UI will render this input having the initial 50 value, but then the user can override it and save.
      Returns:
      The map of default parameters
    • getInput

      Map<String,Object> getInput()
      Exposes all the input values passed in with a ModelEval request (user entries), or all of the inputs persisted in the model, when in a calculation. Note that in the ModelEval scenario, the inputs are not necessarily stored in the model yet. In this use case, the logic leverages knowledge of already provided input values (provided by the client/UI) to determine additionally required inputs.
      Returns:
      A map of input parameter (name,value) pairs.
    • addField

      ModelFormulaContext addField(Object fieldDef)
      Each model is backed by a table in the PA DB. This way, a model can be used as a source to a query or chart.
      But unlike for example a DataSource, the user or configuration engineer is not expected to define its fields in the UI.
      Instead, the model dynamically - in the definition logic - defines its fields using this method. The fields to be added normally depend on user inputs, such as the selected revenue, volume and margin fields in the Segmentation logic example.

      Sample code:

      
        def ctx = api.getDatamartContext()
        def sourceName = ctx.sourceSelectionEntry("Transaction Source", "DM", "DMDS")    // allow selection from DMs and DSs
        def source = ctx.getFieldCollection(sourceName)
        if (source) {
            def fields = source.fc.fields.collectEntries{ [it.name, it] }
            def fieldName = ctx.fieldSelectionEntry("Product Field", source, "DIM")
            if (fieldName) {
                def field = fields[fieldName]
                model.addField(field)      // leverage the field definition from the source
                model.addField( [name:field.name, label:field.label, type:field.type, dimension:true, key:false] )    // or define it explicitly
            }
       

      Parameters:
      fieldDef - The field definition as a map of (property, values) pairs
      Returns:
      The model binding. to facilitate a builder pattern
    • getFields

      Collection<DMField> getFields()
      Retrieves the field definitions previously added using addField(Object).
      Note that as DMField is a non-whitelisted type, the Groovy sandbox will convert the DMField objects to maps, resulting in the same field definition representation as used in addField(Object).
      Returns:
      Collection of field definitions previously added using addField(Object)
    • getSourceQuery

      DatamartContext.Query getSourceQuery()
    • setSourceQuery

      void setSourceQuery(DatamartContext.Query query)
    • getCalculationStep

      Object getCalculationStep()
      A ModelType definition, optionally (but usually) defines a number of calculation steps. When the user, or a 3rd party via the JSON API, or a schedule ModelCalculation DataLoad, request a calculation, the step to execute is identified by the DataLoad's calculationContext attribute. This allows PO to identify the step, and hence the logic to be executed. When there is no dedicated logic defined for each calculation step, this method exposed the name of the calculation step being executed to the logic, so it can selectively evaluate the relevant elements.
      Returns:
      A map representation of the CalcStep being executed. Usually CalcStep.name is sufficient to drive any conditional Groovy code execution.
    • addTree

      Long addTree(String treeName, Collection<String> levelNames)
      Adds a tree to this model, which is effectively a FilterNode object that acts as the root of the tree, i.e. one that does not point to a parent FilterNode. The levelNames are persisted in the FilterNode.output attribute, later used to construct a more readable map representation of the node's path (see getFilterNodePath() and getFilterNodePath(Long).
      If a tree with the given name already exists, the id of the root node is returned, and no further action is taken.
      Parameters:
      treeName - Name to be set on the root node (FilterNode.name)
      levelNames - Names of the first, second etc. level of the tree
      Returns:
      The id of the root node of the tree
    • addTree

      List<Long> addTree(String treeName, Matrix2D data, Collection<String> levelCols)
      Adds a tree to this model, consisting of nodes constructed from a data set, usually a PA query result.
      The root node is the same as created by addTree(String, Collection).
      The immediate descendents of the root node are created from the values found in the first level column (as dictated by the levelCols argument).
      The second level descendants are created from the values in the second level column, if any. And so on.

      Example: creating a tree with name 'Segments' from data set

       Region,        Channel
       EMEA,  Retail
       APAC,  Retail
       APAC,  Industry
       

      results in the following tree, when the level columns are chosen to be 'Region' and 'Channel', in that order.

       Segments
            |
               + EMEA
               |    |
               |    + Retail
               |
               + APAC
                    |
                        + Retail
                        |
                        + Industry
       


      If a tree with the given name already exists, it is deleted before the new one is created.
      Parameters:
      treeName - Name of the tree to be created, i.e. FilterNode.name of the root node
      data - Data from which to construct the tree
      levelCols - Labels of the columns in data to be used to 1) name the tree levels and 2) identify the column to populate each level from
      Returns:
      All of the added tree nodes' ids
    • addTree

      List<Long> addTree(String treeName, Matrix2D data, Collection<String> levelCols, Collection<String> labelCols, String outputColName, String outputColFormat)
      Creates or replaces a tree as in addTree(String, Matrix2D, Collection), with the additional specification of an output or output format, and/or labels. Whereas in the previous method tree nodes are created with FilterNode.output == null and Filter.label -- null, this method sets:

      • output field to the value found in the column identified by outputColName (== column label). If outputColName is null and outputColFormat is not, then the output value is constructed as String.format(outputColFormat, n);, with n being the (n-1)th node created (i.e. n=0 for the root node).
      • label field to "[val1, val2, ...]" where val1, val2, ... are the values found in the columns identified by labelCols respectively.

      Parameters:
      treeName - Name of the tree to be created, i.e. FilterNode.name of the root node
      data - Data from which to construct the tree
      levelCols - Labels of the columns in data to be used to 1) name the tree levels and 2) identify the column to populate each level from
      labelCols - Labels of the columns in data from which to construct the label (sets FilterNode.label)
      outputColName - Label of the column in data from which to pick the output value (sets FilterNode.output)
      outputColFormat - The format from which to construct the output value when outputColName == null
      Returns:
      All of the added tree nodes' ids
    • deleteTree

      void deleteTree(String treeName)
      Deletes the tree with the given name, if it exists. No action is taken and no error returned if it doesn't. Note that deleting a tree means deleting the root node as well as all of its direct and indirect descendents.
      Parameters:
      treeName - Name of the tree, i.e. name of root FilterNode, to delete
    • addTreeNode

      Long addTreeNode(Long parentId, String name, String label, String output, Filter filter)
      Adds a descendent to an existing tree node, identified by its parentId.
      If the parent node does not exist, no action is taken and no error is returned.
      Parameters:
      parentId - Id of the parent node
      name - To be FilterNode.name (of the added node)
      label - To be FilterNode.label
      output - To be FilterNode.output
      filter - To be FilterNode.filter
      Returns:
      The id of the added tree node, or null if the parent node doesn't exist
    • findTreeNode

      Long findTreeNode(String treeName, List<String> path)
      Finds the tree node, if it exists, in the given tree with the given path.
      The path is the list of values for the first, second etc. level of the tree (see e.g. addTree(String, Collection)).
      Note: to find a leaf node, values for all levels are to be provided. Fewer values will result in an intermediate level node to be returned, if such a node exists of course.
      Parameters:
      treeName - Name of the tree to be created, i.e. FilterNode.name of the root node
      path - List of values for the various levels in the tree.
      Returns:
      The id of the FilterNode with the given path (from the root node). See also getFilterNodePath(Long)
    • getFilterNodePath

      Map<String,Object> getFilterNodePath(Long nodeId)
      Given the id of a FilterNode, in some tree previously added to the model, this method returns the logical path from the root to that node.

      Example: if the identified node in the below tree is 'Retail' in EMEA, then the filter node path is [Region:"EMEA", Channel:"Retail"], with 'Region' and 'Channel' assumed to be the level names, in that order, defined when first creating the tree (see addTree(String, Collection)).

       Segments
            |
               + EMEA
               |    |
               |    + Retail
               |
               + APAC
                    |
                        + Retail
                        |
                        + Industry
       

      Parameters:
      nodeId - The id of a FilterNode that exists in a tree previously added to the model
      Returns:
      The path to the given FilterNode as a map of (level,value) pairs
    • getFilterNode

      FilterNode getFilterNode()
      In the context of a call to the datamart.modeleval end point (JSON API), the client request can specify the 'filterNodeId' parameter.
      The value of this parameter is to be the id of a FilterNode object, previously created by the model. In the 'Segmentation' model type, for example, the 'Segmentation' calculation step creates a 'Segments' tree, in which each node, including the root node, is a FilterNode object.
      In the 'Results' section in the Unity UI, when the user selects a node in the Segments tree, a subsequent modeleval call retrieves the details of the selected segment.
      Returns:
      A map representation of the selected FilterNode
    • getFilterNodePath

      Map<String,Object> getFilterNodePath()
      Like getFilterNodePath(Long), but for the preset FilterNode revealed by getFilterNode() only.
      Returns:
      The path to the selected FilterNode as a map of (level,value) pairs
    • addRecord

      Object addRecord(String name, CalendarUtil.TimePeriod period, Map<String,?> attributeValues, Map<String,FieldFormatType> fieldFormatTypesByColLabel, boolean... calculate)
      Adds a new record with the given name if none exist yet with that name in the DRAFT status (workflowStatus == WorkflowStatus.DRAFT). Otherwise, that existing record is updated instead. Note that there can be multiple records with the same name, as long as there is only one in the DRAFT state. Usually these records will then also have varying validity periods (for ex. one valid and approved for Q1, with a new one, yet to be approved for Q2).
      Parameters:
      name - Name of the record to be added/updated.
      period - The validity period for the record, i.e. defining its startDate and endDate (both inclusive)
      attributeValues - Map of attribute (label, value) pairs. Note that this is a map from the field's label (not name)
      fieldFormatTypesByColLabel - Map of attribute (label, FieldFormatType), defining the type of each record attribute to be set. Entries in the attributeValues argument for which no FieldFormatType is defined, are ignored, i.e. are not set.
      calculate - Optional flag, indicating that once the record is added/updated, a second, embedded, evaluation takes place, in which the record being calculated is identified by the result of getRecord(). See also the MethodType.recordLogic property.
      Returns:
      A map representation of the added/updated ModelRecord
    • getRecord

      Map<String,Object> getRecord()
      Gets the ModelRecord ('PolicyRecord' in the UI) set as context in the 'record' logic evaluation (the logic set in the ModelType.recordLogic attribute). The evaluation is done when a record is added using addRecord(String, TimePeriod, Map, Map, boolean...) when the calculate argument is true.
      Returns:
      A map representation of the ModelRecord
    • deleteRecords

      int deleteRecords()
      Deletes all ModelRecords associated with the model, which are not yet submitted into the workflow.
      Returns:
      The number of records created.
    • findRecord

      Map<String,Object> findRecord(String name, Date validOnDate, String wfStatus)
      Finds the ModelRecord, if it exists, with the given name, valid on the given day (record.startDate <= validOnDate <= record.endDate), and with the given workflow status, if not null. If wfStatus is null, there is no filter condition on record.workStatus.

      Valid workflow statuses are:

      • DRAFT
      • SUBMITTED
      • DENIED
      • APPROVED
      • NO_APPROVAL_REQUIRED
      • WITHDRAWN

      Parameters:
      name - The name of the record give when first creating it, using addRecord(String, TimePeriod, Map, Map, boolean...)}
      validOnDate - The date on which the record is to be valid
      wfStatus - The workflow status the records needs to be in, ignored if null
      Returns:
      A map representation of the record
    • findRecords

      List<Map<String,Object>> findRecords(Filter filter, String... sortBy)
      Finds ModelRecords associated to this model using only Filter criteria.
      Parameters:
      filter - The criteria the records needs toad here to
      sortBy - Optional sort fields
      Returns:
      A list of map representations of the records, empty of none matched the criteria.
    • addOrUpdateCalcItem

      Object addOrUpdateCalcItem(Object calcStep, Object id, Object value)
      Creates a new or updates an existing calculation item (entry in the Model CalcItems PP) for a given calculation step. For example, a 'Segmentation' step may create a CalcItem for scoring 'Segment 001', injected into the logic context when the calculation of the 'Scoring' step for that segment is initiated.
      Specified by:
      addOrUpdateCalcItem in interface DistFormulaContext
      Parameters:
      calcStep - The name of the calculation step in which the added item is to be calculated; this goes into Key1
      id - Key2 of the calculation item
      value - A JSON-serializable value to be stored in the Value attribute of the calculation item
      Returns:
    • getParams

      Map<String,Object> getParams()
      Gets all the entries of the LookupTable (PP) named 'Model Params <model.uniqueName>'. All the user entries for the model are automatically stored in that PP. In addition, the logic can add parameters programmatically (cf. setParam(String, Object, boolean...)).
      Returns:
      A map of param (name, value) pairs
    • setParam

      Object setParam(String name, Object value, boolean... ifMissing)
      Adds a new parameter, or overwrites an existing parameter value, being an entry in the 'Model Params <model.uniqueName>' PP.
      Parameters:
      name - Name of the parameter
      value - The parameter value, which needs to be JSON-serializable
      ifMissing - If true, an existing parameter's value will not be overwritten. This makes it easier to add default parameters, not overwriting the value that was set by an end user.
      Returns:
      The added PP entry, as a map. Mostly useful to get the id of the added/updated entry.
    • getAttachments

      List<String> getAttachments() throws IOException
      Returns:
      The names of all the files attached to the model. This can for example be used to populate a dropdown user entry.
      Throws:
      IOException
    • addTable

      DatamartContext.Table addTable(String tableName, Object source) throws Exception
      Creates a table, represented by a DMTable object in the PA DB, modelled on and populated from the given source.
      The uniqueName of the table is a combination of the model's typedId and the passed in tableName. The table's label is set to the given tableName or from the source.
      If a DMTable with this tableName (i.e. with equal derived uniqueNames) already exists, that table is updated and truncated rather than dropped and recreated. If this is not desirable, then the existing table can be dropped beforehand.
      Note that when directly using a DatamartContext.SqlQuery, the types of the selected fields must be made explicit via casting for the resulting table to have the proper types.
      If a query is passed as a source, the projections become the fields of the new/updated table, and the result is used to populate the table.

      Note: Can only be used in a model calculation.


      Sample code:
      
            def ctx = api.getDatamartContext()
                  def ds = ctx.getDataSource("txDS")
                  def t1 = ctx.newQuery(ds)
                  t1.select("sku", "P")
                  t1.select("SUM(amount)", "R")
                  def query = ctx.newSqlQuery()
                  query.addSource(t1)
                  query.setQuery('SELECT P, R::numeric as R FROM T1 ORDER BY P')
                  // add table using a query definition
                  model.addTable('MyTable', query)
                  // add table using fields definitions
                  model.addTable("RevenueByProduct", [
                     [ name:"productId", label:"Product ID", type:"TEXT", key:true],
                     [ name:"productGroup", label:"ProductGroup", type:"TEXT", dimension:true],
                     [ name:"revenue", label:"Revenue", type:"MONEY"]
            ])
                  // add table using full definitions
                  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:
      tableName - The name of the table, unique over all tables associated to this model.
      source - One of the following types
      Note: For table field types, please refer to Enum FieldType

      .

      Returns:
      A DatamartContext.Table object that can be used as a source to a query in the DatamartContext. It is the same DatamartContext.Table object that can be retrieved using getTable(String).
      Throws:
      Exception - in case of error.
    • loadTable

      long loadTable(DatamartContext.Table table, Object source) throws Exception
      Load data into an existing table without truncating it.
      The the projections of the query passed as a source must match the fields of the table, and the result of the query is used to populate the table.
      Note that when directly using a DatamartContext.SqlQuery, the types of the selected fields must be made explicit via casting for the resulting table to have the proper types.

      Note: Can only be used in a model calculation.


      Sample code:
      
            def ctx = api.getDatamartContext()
                  def ds = ctx.getDataSource("txDS")
                  def t1 = ctx.newQuery(ds)
                  t1.select("sku", "P")
                  t1.select("SUM(amount)", "R")
                  def query = ctx.newSqlQuery()
                  query.addSource(t1)
                  query.setQuery('SELECT P, R::numeric as R FROM T1 ORDER BY P')
                  // load table using a query definition
                  def table = model.getTable('MyTable')
                  model.loadTable(table, query)
       
      Parameters:
      table - The table object, see getTable(String) or addTable(String, Object) to retrieve it.
      source - One of the following query types
      Returns:
      The number of row added.
      Throws:
      Exception - in case of error.
    • loadTable

      long loadTable(DatamartContext.Table table, Object source, boolean truncate) throws Exception
      Load data into an existing table, optionally truncating it.
      The the projections of the query passed as a source must match the fields of the table, and the result of the query is used to populate the table.
      Note that when directly using a DatamartContext.SqlQuery, the types of the selected fields must be made explicit via casting for the resulting table to have the proper types.

      Note: Can only be used in a model calculation.


      Sample code:
      
            def ctx = api.getDatamartContext()
                  def ds = ctx.getDataSource("txDS")
                  def t1 = ctx.newQuery(ds)
                  t1.select("sku", "P")
                  t1.select("SUM(amount)", "R")
                  def query = ctx.newSqlQuery()
                  query.addSource(t1)
                  query.setQuery('SELECT P, R::numeric as R FROM T1 ORDER BY P')
                  // load table using a query definition
                  def table = model.getTable('MyTable')
                  model.loadTable(table, query, true)
       
      Parameters:
      table - The table object, see getTable(String) or addTable(String, Object) to retrieve it.
      source - One of the following query types
      truncate - If the table should be truncated before loading the data.
      Returns:
      The number of row added.
      Throws:
      Exception - in case of error.
    • getTable

      DatamartContext.Table getTable(String tableName)
      Gets a table object representing the DMTable with the given name, which was previously created using the addTable(String, Object) method while calculating the model. A reference to this table can then be used when building a DatamartContext.Query on that DMTable.
      Parameters:
      tableName - The table name.
      Returns:
      The Table object with the given tableName if it exists, or null if not.
    • dropTable

      boolean dropTable(String tableName)
      Drops the table, uniquely identified by tableName within this model.

      Note: Can only be used in a model calculation.


      Sample code:
      
                  model.dropTable('MyTable')
       
      Parameters:
      tableName - The table name.
      Returns:
      True if that table existed, false otherwise.
    • truncateTable

      void truncateTable(DatamartContext.Table table)
      Truncate the table.

      Note: Can only be used in a model calculation.


      Sample code:
      
            def table = model.getTable('MyTable')
            model.truncateTable(table)
       
      Parameters:
      table - The table.