Workshop not supporting function return value

Hello,

I’m trying to play around with the Foundry AIP and I’m running into a problem while trying to use a User Defined Function in either the Pipeline Builder or the Workshop of my project. All the data I’m using is made up just for practice, but I keep on running into this error where even though my function returns a list(or array) of dictionaries, the Workshop and Pipeline Builder both say it is returning a map(dictionary). I’m confused because every test I’ve ran in the code repository has indicated that my function indeed returns a list at the top level. Code pasted below, error message in Workshop is “Unsupported function return type: map” when I try to use it as an Object Set, and the function doesn’t even appear when I try to use it’s output as a struct array.

Code:

# Returns ShipName, HullName, and CountOf(Jobs) for each hull of each ship

@function

def gather_ship_jobs() → List[Dict[str, str]]:

client = FoundryClient()

results = (

    client.ontology.objects.ShipJob

    .group_by(ShipJob.object_type.ship_name.exact())

    .group_by(ShipJob.object_type.ship_hull.exact())

    .count()

    .compute()

)



job_list = \[

    {

        "Ship Name": str(row.group\["shipName"\]),

        "Ship Hull": str(row.group\["shipHull"\]),

        "Job Count": str(int(row.metrics\[0\].value))

    }

    for row in results.data

\]

return job_list

#Count Buckets will take gathered ship Jobs and return a string that reads:

#“{Ship Name} – {Ship Hull} – {Count(Jobs)} – {proper bucket} jobs”

#buckets are 0-5, 6-10, and 10+ jobs

@function

def countBuckets() → List[Dict[str, str]]:

hulls = gather_ship_jobs()

for hull in hulls:

    if int(hull\["Job Count"\]) < 6:

        hull\["Bucket"\] = "0-5 Jobs"

    elif int(hull\["Job Count"\]) < 10:

        hull\["Bucket"\] = "6-10 Jobs"

    else:

        hull\["Bucket"\] = "10+ Jobs"

return hulls

It looks like creating an actual struct would work much better in your case.
In python it would look like this:

from dataclasses import dataclass
from functions.api import function, Integer

@dataclass
class ShipJobStruct:
    ship_name: str
    ship_hull: str
    job_count: Integer
    bucket: str | None

# Returns ShipName, HullName, and CountOf(Jobs) for each hull of each ship

@function
def gather_ship_jobs() → List[ShipJobStruct]:
    client = FoundryClient()

    results = (
        client.ontology.objects.ShipJob
        .group_by(ShipJob.object_type.ship_name.exact())
        .group_by(ShipJob.object_type.ship_hull.exact())
        .count()
        .compute()
    )

    job_list = [
        ShipJobStruct(
            ship_name=str(row.group["shipName"]),
            ship_hull=str(row.group["shipHull"]),
            job_count=int(row.metrics[0].value),
            bucket=None,
        )
        for row in results.data
    ]
    
    return job_list
#Count Buckets will take gathered ship Jobs and return a string that reads:

#“{Ship Name} – {Ship Hull} – {Count(Jobs)} – {proper bucket} jobs”

#buckets are 0-5, 6-10, and 10+ jobs

@function
def countBuckets() → List[ShipJobStruct]:
    hulls = gather_ship_jobs()
    for hull in hulls:
        if hull.job_count < 6:
            hull.bucket = "0-5 Jobs"
        elif hull.job_count < 10:
            hull.bucket = "6-10 Jobs"
        else:
            hull.bucket = "10+ Jobs"
    
    return hulls

Let me know if this works for you and if you have any questions.

With kindest regards

Confirming that Workshop does support structs and does not support map return type.

I’ll update this error message to recommend a struct as a supported alternative.