Skip to content

Navigation tables and connection checks

Mechanism

AsanaNavTable builds a one-row table with the columns Name, Data, ItemKind, ItemName, and IsLeaf. Its Data cell holds Asana.View(link). The view's GetType and GetRows handlers reach web requests through AsanaSchema and GetTasks; see Table.View. The navigation call passes Name as the key and maps each role to a column name.1

The name Table.ToNavigationTable is bound locally to Table.ToNavigationTable.pqm through Extension.LoadFunction. That module builds a table key with Type.AddTableKey(tableType, keyColumns, true) and stores the supplied column names as navigation metadata. It uses the ItemName argument for Preview.DelayColumn. Inspect this local implementation when adapting the call; the helper's name alone does not establish its behavior.23

The connector record declares TestConnection = (dataSourcePath) => {"Asana.Tables", dataSourcePath} (line 82). That handler names the shared function and passes the stored path as its only argument. It is a separate entry point from the navigation table. It does not build any navigation rows.4

The same record also declares Authentication and OAuth handlers, which are not part of navigation. The navigation metadata can instead be declared on a type. EnvironmentListType in CommonDataService (lines 134–150) sets NavigationTable.NameColumn, NavigationTable.DataColumn, and NavigationTable.SupportsIndirection directly on the table type, and keys the table on Name. It needs no local helper.5

Adaptation and failure paths

Choose the local-helper approach when the navigation table is built at runtime from a #table value and you want the mapping in one call. Choose type metadata, as CommonDataService does, when the table shape is fixed and you want no helper file. Choose schema handling when the question is the declared return type rather than navigation roles.

Column roles are the main risk. If you rename Data in the #table but not in the call, the mapping points at a column that no longer exists. The local copy stores names as metadata and does not check that they exist in the table. Test the navigation table after any rename.31

TestConnection assumes that the path is exactly the argument list. Asana passes the path through unchanged, which is correct for its one link parameter. A connector with several parameters must parse the stored path. MarkLogic's TestConnection parses JSON with Json.Document and reads server and port before returning them (lines 347–353).6 AmazonAthena splits its path on ; (ParseResourcePath, line 218) and returns the parts as the argument list.7

The local copy is loaded with Extension.Contents (line 245), so the .pqm file must be packaged with the connector. If it is missing from the package, that call fails. Test the packaged output rather than the source tree.2

Adaptation checklist:

  • Keep the five column roles (key, data, item kind, item name, leaf flag) explicit in both the #table and the call.
  • Decide whether to use the local helper or type metadata, and document which one the connector uses.
  • Test TestConnection with the exact path format that the UI stores, including any delimiter.
  • Read one Data cell to confirm that it returns rows, not only that the navigation list displays.
  • Confirm that every .pqm helper is packaged. See packaging.

See Table.View, schema metadata, and packaged resources.

Examples

The first excerpt, copied from Asana/Asana.m lines 26–34, builds the navigation row and calls the navigation helper with the column roles.1

Asana/Asana.m · lines 26–34 Open original source ↗

AsanaNavTable = (link as text) as table =>
    let
        source = #table(
            { "Name",      "Data",           "ItemKind", "ItemName", "IsLeaf"}, {
            { "Tasks",      Asana.View(link), "Table",    "Table",     true }            }
        ),
        navTable = Table.ToNavigationTable(source, {"Name"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf")
    in
        navTable;

The second excerpt, copied from Asana/Asana.m lines 81–90, is the connector record. It contains the TestConnection handler and the authentication fields it sits beside.4

Asana/Asana.m · lines 81–90 Open original source ↗

Asana = [
    TestConnection = (dataSourcePath) => {"Asana.Tables", dataSourcePath},
    Authentication = [
        OAuth = [
            StartLogin=StartLogin,
            FinishLogin=FinishLogin,
            Label=Extension.LoadString("AuthenticationLabel")
        ]
    ]
];

The third excerpt, copied from Asana/Asana.m lines 243–250, is the loader that replaces the built-in name. It is the reason the navigation helper in this connector is not the standard library function.2

Asana/Asana.m · lines 243–250 Open original source ↗

Extension.LoadFunction = (name as text) =>
    let
        binary = Extension.Contents(name),
        asText = Text.FromBinary(binary)
    in
        Expression.Evaluate(asText, #shared);

Table.ToNavigationTable = Extension.LoadFunction("Table.ToNavigationTable.pqm");

The fourth excerpt, copied from CommonDataService/CommonDataService.pq lines 134–150, is the contrasting type-metadata approach. It is a type declaration, not a navigation function.5

CommonDataService/CommonDataService.pq · lines 134–150 Open original source ↗

EnvironmentListType = Type.AddTableKey(
    type table [
        DisplayName = text,
        Name = text,
        Location = text,
        IsDefault = logical,
        Data = (type table meta [
            NavigationTable.ItemKind = "Database",
            Preview.Delay = "Table"
        ])
    ] meta [
        NavigationTable.NameColumn = "DisplayName",
        NavigationTable.DataColumn = "Data",
        NavigationTable.SupportsIndirection = true
    ],
    {"Name"},
    true);

  1. Asana/Asana.m lines 26–34: AsanaNavTable builds the one-row #table and calls Table.ToNavigationTable with Name as the key and the four role columns. ↩↩↩

  2. Asana/Asana.m lines 243–250: Extension.LoadFunction evaluates a packaged .pqm file, and line 250 binds Table.ToNavigationTable to it. ↩↩↩

  3. Asana/Table.ToNavigationTable.pqm lines 1–22: the local function applies Type.AddTableKey and stores the name, data, item-kind, item-name, and leaf column names as metadata. ↩↩

  4. Asana/Asana.m lines 81–90: the connector record declares TestConnection, which returns the shared function name and the stored path, plus the OAuth fields. ↩↩

  5. CommonDataService/CommonDataService.pq lines 134–150: EnvironmentListType attaches navigation metadata to a table type and keys it on Name. ↩↩

  6. MarkLogicODBC/MarkLogicODBC.m lines 347–353: TestConnection parses the stored path with Json.Document and returns the function name with server and port. ↩

  7. AmazonAthena/AmazonAthena.m lines 218–220: ParseResourcePath splits the path on ;, and TestConnection prepends the function name to the parts. ↩