Skip to content

Actions and table mutation handlers

Mechanism

GetWarehouseDatabaseView uses cached endpoint data only when it is non-null and passes Sql.ValidateInstance. Otherwise it tries Workspace[GetTDSEndPoint], with lookup errors becoming null. It builds stateTableInsert with CacheTableInsertBuilder and passes that action to GenerateViewForWarehouseSqlTableData with the Sql.Contents navigation table. When no endpoint is found, it returns null.2

GenerateViewForWarehouseSqlTableData (lines 994–1035) receives content and cacheTableInsertAction as parameters. Its inner view helper (lines 1001–1025) wraps each table's data in a Table.View with OnInvoke and TableDefault, and declares no mutation handlers. The outer Table.View (lines 1030–1035) wraps renamedColumns and defines GetExpression, OnInsertRows, OnUpdateRows, and OnDeleteRows.1

Each mutation handler returns Diagnostics.Trace(...) around Action.Sequence({cacheTableInsertAction, TableAction.X(...)}). The cache action runs first, then the table mutation. The mutations target content, not renamedColumns. Insert uses content directly. Update and delete use Table.SelectRows(content, selector). The trace records carry only an event name and an empty Data record.1

CacheTableInsertBuilder (lines 2802–2816) returns Action.Sequence of cache actions only when UseFileCache is true, the URL is not a private-link workspace, and both cache IDs are non-null. Otherwise it returns Action.DoNothing. UseFileCache reads the MashupFlight_UseFileCache feature switch, which defaults to false. By default, the cache step is therefore a no-op.36

When the cache is enabled, CacheTableAction (lines 2772–2797) checks whether the key exists. If it does, it touches the entry. If it does not, it creates the cache folder if needed and inserts the entry. tryCacheActions (lines 2863–2869) wraps the cache action in Action.Try. On error, it emits a warning trace and returns Action.DoNothing, so the mutation still runs.45

Adaptation and failure paths

Use this shape when the host drives row-level writes through a Table.View and the connector must keep a side cache in step. If the connector writes to an API directly, prefer explicit request handling in web requests. For the handler shape itself, see Table.View handlers.

Writes do not use the renamed view. A column rename applied to renamedColumns changes what the view exposes, but the insert, update, and delete handlers still reference content. Test a write after any rename, because the write path may not follow the rename.1

Selector scope is the main risk. Table.SelectRows(content, selector) decides which rows an update or delete touches. A selector that matches extra rows widens the mutation, and a selector that matches none may succeed without changing anything. Test exact, zero, and many matches.1

The cache step runs first, and its failures are warned and swallowed by tryCacheActions. A cache error therefore does not stop the write. These handlers show no compensating action if the later mutation fails after the cache action succeeds. That does not establish the driver's or host's transaction guarantees; test the combined failure path in the target environment.45

The mutation handlers do not wrap a retry. Nothing in them checks for an existing row before TableAction.InsertRows, so a repeated insert action could add a duplicate. This source does not show whether the host retries actions, so check that behavior before adding a retry.1

If the endpoint is not found, the caller returns null (line 984) instead of a view. The catch(e) => error e on line 982 rethrows the error unchanged. Test both branches. Also check the UseFileCache setting for the target environment, since the same write can take different paths.26

Adaptation checklist:

  • Identify the target of each mutation (content or the renamed view), and test a write after each rename.
  • Decide whether the cache step must run. Check the MashupFlight_UseFileCache default and the private-link condition for your environment.
  • Test each selector with zero, one, and many matching rows.
  • Decide whether a cache failure should be surfaced, since tryCacheActions currently only warns.
  • Check idempotence for insert, and test a duplicate action after a simulated failure.
  • Run writes against a staging workspace before you use them against production data.

See Table.View handlers, diagnostics, and structured errors.

Examples

The first excerpt, copied from LakeHouse/LakeHouse.pq lines 994–1035, is the complete GenerateViewForWarehouseSqlTableData function. It includes the per-table view, the renamed-column step, and the three mutation handlers that use cacheTableInsertAction.1

LakeHouse/LakeHouse.pq · lines 994–1035 Open original source ↗

GenerateViewForWarehouseSqlTableData = (
    content as table,
    dwName as text,
    dwServerInstance as text,
    cacheTableInsertAction,
    options as record) as table =>
let
    view = (content2, tableName) => Table.View(
        content2,
        [
            GetExpression = () => Value.Expression(Value.Optimize(content2)),
            OnInvoke = (function, args, index) =>
                if (Function.EqualsByName(function, "Lakehouse.SqlTable")) then content2
                else if (Function.EqualsByName(function, "Lakehouse.DeltaTableFastCopy")) then
                    Diagnostics.Trace(
                        TraceLevel.Information,
                        [
                            Name = "GenerateViewForWarehouseSqlTableData/DeltaTableFastCopy", 
                            Data = [Source = Utils[NonPii]("Warehouse"), TableName = tableName, DwServerInstance = dwServerInstance]
                        ],
                        // Restrict this check for reads from Staging Warehouse.
                        [
                            // Run a query to check if DeltaLogPublishing is enabled for StagingDW.
                            Enabled = options[IsModelStorage]? = true and DeltaTableFastCopy[CheckIfDeltaLogPublishingIsEnabled](content, dwName),
                            Source = "Warehouse",
                            ReadFromDW = true,
                            TableName = tableName,
                            DwServerInstance = dwServerInstance
                        ])
                else Function.Invoke(function, List.ReplaceRange(args, index, 1, {content2})),
            TableDefault = (newTable) => @view(newTable, tableName)
        ]),
    withView = Table.AddColumn(content, "TransformedData", (_) => view(_[Data], _[Name])),
    removedDataColumn = Table.RemoveColumns(withView, {"Data"}),
    renamedColumns = Table.RenameColumns(removedDataColumn, {{"TransformedData", "Data"}})
in
    Table.View(renamedColumns, [
        GetExpression = () => Value.Expression(Value.Optimize(content)),
        OnInsertRows = (rows) => Diagnostics.Trace(TraceLevel.Information, [Name = "StagingWarehouseInsert", Data = []] , Action.Sequence({ cacheTableInsertAction, TableAction.InsertRows(content, rows) })),
        OnUpdateRows = (updates, selector) => Diagnostics.Trace(TraceLevel.Information, [Name = "StagingWarehouseUpdate", Data = [] ], Action.Sequence({ cacheTableInsertAction, TableAction.UpdateRows(Table.SelectRows(content, selector), updates) })),
        OnDeleteRows = (selector) => Diagnostics.Trace(TraceLevel.Information, [Name = "StagingWarehouseDelete", Data = []], Action.Sequence({ cacheTableInsertAction, TableAction.DeleteRows(Table.SelectRows(content, selector)) }))
    ]);

The second excerpt, copied from LakeHouse/LakeHouse.pq lines 2863–2869, is the failure wrapper for every cache action. It is the reason a cache error does not stop the write.5

LakeHouse/LakeHouse.pq · lines 2863–2869 Open original source ↗

tryCacheActions = (actions, actionName) => Action.Sequence
        ({
            () => Action.Try(actions),
            (r) => if (r[HasError]) then
                        Diagnostics.Trace(TraceLevel.Warning, [Name = actionName, Data = [Exception = Utils[Value.ToText](r[Error])]], Action.DoNothing)
                    else Action.Return(r[Value])
        });

Coverage is limited to LakeHouse. connectors/Warehouse/WarehouseOutputInterceptor.pqm also defines OnInsertRows, OnUpdateRows, and OnDeleteRows handlers. This page does not cover that file, so do not treat it as a second example of this pattern.


  1. LakeHouse/LakeHouse.pq lines 994–1035: GenerateViewForWarehouseSqlTableData receives content and cacheTableInsertAction, builds per-table views, and defines insert, update, and delete handlers on the renamed view that mutate content. ↩↩↩↩↩↩

  2. LakeHouse/LakeHouse.pq lines 958–986: GetWarehouseDatabaseView resolves the endpoint, builds stateTableInsert with CacheTableInsertBuilder, calls GenerateViewForWarehouseSqlTableData, and returns null when no endpoint is found. ↩↩

  3. LakeHouse/LakeHouse.pq lines 2802–2816: CacheTableInsertBuilder returns Action.Sequence of cache actions only when the cache is enabled, the URL is not private-link, and both IDs are non-null; otherwise it returns Action.DoNothing. ↩

  4. LakeHouse/LakeHouse.pq lines 2772–2797: CacheTableAction touches an existing cache entry, or creates the folder and inserts a new entry, and wraps both paths in tryCacheActions. ↩↩

  5. LakeHouse/LakeHouse.pq lines 2863–2869: tryCacheActions wraps an action in Action.Try, emits a warning trace on error, and returns Action.DoNothing. ↩↩↩

  6. LakeHouse/LakeHouse.pq line 57: UseFileCache reads the MashupFlight_UseFileCache feature switch with a default of false. ↩↩