-
-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Currently, the result ofthe scalar function is being passed to the EntryFactory.
This means that EntryFactory based on the value type will try to determine the best possible Entry type.
This approach is problematic, especially in scenarios wherethe expected type is not deterministic.
Let's take a look at following example:
ref('json')->cast(type_list(type_string())); In theory it looks good, but what if json is []?
Then Cast scalar function will return [] and Entry Factory will not have any chance of figuring out that our intention was to create a new ListEntry.
I don't yet have a solution, but since EntryFactory can create entries based on value and Schema Definition, let's introduce a wrapper around Scalar Function returned values.
Something like ScalarFunction/Output(mixed $value, Type $type)
We would still need to expand the EntryFactory create method by Type:
EntryFactory::create(string $entryName, mixed $value, Schema|Definition|Type|null $schema = null) : Entry
But that could potentially also improve transformation pipelines performance by avoiding type guessing and getting the desired type directly from function returned value.