Record Class SingleTableConfig

java.lang.Object
java.lang.Record
de.calamanari.adl.sql.config.SingleTableConfig
Record Components:
tableName - native (fully qualified) name of a table
idColumnName - native name of the id-column in that table
tableNature - characteristics of the table
tableFilters - optional list of filter columns to be added on each selection from this table, null means empty
argColumnMap - argument to column definition mapping
autoMappingPolicy - optional policy for argNames not covered explicitly
All Implemented Interfaces:
de.calamanari.adl.cnv.tps.ArgMetaInfoLookup, DataTableConfig, TableMetaInfo, Serializable

public record SingleTableConfig(String tableName, String idColumnName, TableNature tableNature, List<FilterColumn> tableFilters, Map<String, ArgColumnAssignment> argColumnMap, AutoMappingPolicy autoMappingPolicy) extends Record implements DataTableConfig, TableMetaInfo
A SingleTableConfig describes the mappings of argNames to columns of one particular table.

Hint: If any column is marked DataColumn.isAlwaysKnown() then the table will be automatically configured with TableNature.containsAllIds()=true.

On sparse data:

We call it sparse data if the data of a table is irregular.

Example 1: data copied but not merged from multiple sources

+------+-------+-------+-------+---------+
|  ID  | COLOR | SHAPE | RX0   | RX1     |
+------+-------+-------+-------+---------+
| 8231 | blue  | rect  | NULL  | NULL    |
+------+-------+-------+-------+---------+
| 8231 | NULL  | NULL  | 1     | NULL    |
+------+-------+-------+-------+---------+
| 8231 | NULL  | NULL  | NULL  | 1       |
+------+-------+-------+-------+---------+
| 9555 | ...   | ...   | ...   | ...     |
+------+-------+-------+-------+---------+

Interestingly, none of the columns in the example above is DataColumn.isMultiRow(), or in other words: none of the attributes is a collection (ArgMetaInfo.isCollection()). The problem is that the data has not been merged. To get the full picture, data from several rows must be considered.

Example 2: multi-row (collection) attribute with missing repetition

+------+-------+-------+--------+---------+
|  ID  | NAME  | BRAND | TYPE   | WEEKDAY |
+------+-------+-------+--------+---------+
| 8231 | CROW  | SKIRT | M365   | SUN     |
+------+-------+-------+--------+---------+
| 8231 | CROW  | NULL  | NULL   | MON     |
+------+-------+-------+--------+---------+
| 8231 | CROW  | NULL  | NULL   | WED     |
+------+-------+-------+--------+---------+
| 9555 | ...   | ...   | ...    | ...     |
+------+-------+-------+--------+---------+

Here, WEEKDAY may contain multiple values (in multiple rows), but unfortunately, the values for some other fields have not been repeated since the first occurrence of the record 8231 on Sunday. Again, a query may have to consider multiple rows to get the full picture.

In general it is recommended to streamline the onboarding process to avoid any sparse data tables for performance reasons and to avoid logical problems.
Sparse data makes all attributes multi-row and thus independent from each other. For example if you query brand = foo AND product = bar with the two columns BRAND and PRODUCT side-by-side you would expect to include rows with both conditions true for a single row. By marking the table as sparse or both columns as multi-row you lose this dependency. Consequently, the query would also match if there are two rows, (BRAND:xyz, PRODUCT:bar) and (BRAND:foo, PRODUCT:hugo).

Note: For convenience reasons this class implements ArgMetaInfoLookup to play nicely with some core features.

Instances are deeply immutable.

Author:
Karl Eilebrecht
See Also:
  • Constructor Details

  • Method Details

    • forTable

      public static ConfigBuilderInterfaces.SingleTableStep2 forTable(String tableName)
      Entry point for fluently setting up a table in the the physical data model and along with it the logical data model (mapped argNames)

      This is more for testing convenience. The recommended way is first creating a logical data model with all the argNames and then calling forTable(String, ArgMetaInfoLookup) to setup the table(s) and create a mapping.

      Parameters:
      tableName - physical table name
      Returns:
      builder
    • forTable

      public static ConfigBuilderInterfaces.SingleTableStep2 forTable(String tableName, de.calamanari.adl.cnv.tps.ArgMetaInfoLookup argMetaInfoLookup)
      Entry point for setting up a table and for mapping it to existing argNames
      Parameters:
      tableName -
      argMetaInfoLookup - (logical data model with all the argNames)
      Returns:
      builder
    • lookupAssignment

      public ArgColumnAssignment lookupAssignment(String argName, de.calamanari.adl.ProcessContext ctx)
      Description copied from interface: DataTableConfig
      Determines the column assignment for the given argName.
      Specified by:
      lookupAssignment in interface DataTableConfig
      Parameters:
      argName -
      ctx -
      Returns:
      the configured ArgColumnAssignment if ArgMetaInfoLookup.contains(String)=true, otherwise throws exception
    • contains

      public boolean contains(String argName)
      Specified by:
      contains in interface de.calamanari.adl.cnv.tps.ArgMetaInfoLookup
    • numberOfTables

      public int numberOfTables()
      Description copied from interface: DataTableConfig
      Returns the total number of tables in this configuration
      Specified by:
      numberOfTables in interface DataTableConfig
      Returns:
      number of tables this config is based on, >=1
    • lookupTableMetaInfo

      public TableMetaInfo lookupTableMetaInfo(String argName, de.calamanari.adl.ProcessContext ctx)
      Description copied from interface: DataTableConfig
      Returns the table meta infos for the column that is mapped to the given argName
      Specified by:
      lookupTableMetaInfo in interface DataTableConfig
      Parameters:
      argName -
      ctx -
      Returns:
      meta data
    • allTableMetaInfos

      public List<TableMetaInfo> allTableMetaInfos()
      Description copied from interface: DataTableConfig
      Returns the meta information for all the tables in this configuration.

      Important: Although the order is not defined, best case the order in the list reflects the order of configuration.
      In any case it must be stable and it should be deterministic because this is the order the default implementations of several other methods relies on. If the result is composed from an underlying set, then the list should be sorted before returning to avoid indeterministic behavior like flaky tests or unexplainable variations when generating queries.

      Specified by:
      allTableMetaInfos in interface DataTableConfig
      Returns:
      all configured tables
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • tableName

      public String tableName()
      Returns the value of the tableName record component.
      Specified by:
      tableName in interface TableMetaInfo
      Returns:
      the value of the tableName record component
    • idColumnName

      public String idColumnName()
      Returns the value of the idColumnName record component.
      Specified by:
      idColumnName in interface TableMetaInfo
      Returns:
      the value of the idColumnName record component
    • tableNature

      public TableNature tableNature()
      Returns the value of the tableNature record component.
      Specified by:
      tableNature in interface TableMetaInfo
      Returns:
      the value of the tableNature record component
    • tableFilters

      public List<FilterColumn> tableFilters()
      Returns the value of the tableFilters record component.
      Specified by:
      tableFilters in interface TableMetaInfo
      Returns:
      the value of the tableFilters record component
    • argColumnMap

      public Map<String, ArgColumnAssignment> argColumnMap()
      Returns the value of the argColumnMap record component.
      Returns:
      the value of the argColumnMap record component
    • autoMappingPolicy

      public AutoMappingPolicy autoMappingPolicy()
      Returns the value of the autoMappingPolicy record component.
      Returns:
      the value of the autoMappingPolicy record component