marten icon indicating copy to clipboard operation
marten copied to clipboard

Test to support custom field sources.

Open elexisvenator opened this issue 2 years ago • 7 comments

Still a work in progress.

Using string-backed struct as a custom object. Currently works with CustomId and CustomId?. Does not yet work with CustomId[].

Once working, can be added to documentation.

elexisvenator avatar Mar 29 '22 05:03 elexisvenator

@jeremydmiller I might need some help to make the CustomId[] scenario work, I'm a bit lost with how to make detection of arrays work.

elexisvenator avatar Apr 03 '22 23:04 elexisvenator

I cleared a bunch of issues by registering a mapping for CustomId to dbtype in the PostgresqlProvider. That leaves array contains, which i know what this issue is - In most places where a constant value for the custom id is passed in, it hits the CustomIdField.CreateComparison() method. This allows me to coerce the constant CustomId that is passed in into the raw value type the db needs.

            var def = new CommandParameter(((CustomId)value.Value).Value);
            return new ComparisonFilter(this, def, op);

But for the array.contains scenario specifically this doesn't happen. Instead the field maps to ArrayField, and the constant is converted to a CommandParameter in the ContainsIdSelectorStatement constructor. The CommandParameter correctly asserts what the dbparametertype should be but doesnt do any conversion on the CustomId, so the npgsql command fails when it executes, not knowing how to process CustomId as varchar.

I think what needs to happen is when registering a mapping in the PostgresProvider for the custom id, some sort of function needs to be passed in eg Func<TInputType, TRawType>. This could then be used to preprocess the custom id whenever a lookup is done. This would be a pretty significant change in weasel though.

elexisvenator avatar Apr 06 '22 14:04 elexisvenator

I think there's an evil downcast in the Linq parsing code to ArrayField that's messing this up.

jeremydmiller avatar Apr 06 '22 16:04 jeremydmiller

@elexisvenator Is the only thing missing at this point the Contains() operation?

jeremydmiller avatar Apr 08 '22 10:04 jeremydmiller

Oh, and I could probably try to finish this off on Monday if you wanted.

jeremydmiller avatar Apr 08 '22 20:04 jeremydmiller

I went through all documented functions and this is the list of functions that fail:

  • CustomId,IsOneOf()
  • CustomId[].Any() (with predicate)
  • !CustomId[].Any() (with predicate)
  • CustomId[].Contains()
  • !CustomId[].Contains()
  • CustomId[].IsOneOf()

They all seem to be failing on the same reason. (Can't map a customid value to a varchar postgres value).

elexisvenator avatar Apr 10 '22 04:04 elexisvenator

Tried working around this and found even more hurdles.

While queries against projections with a customid DuplicateField will generate without failing, the code to create the index in the first place will fail. As will the generated db functions for creating/upserting records. All of these fail with the same issue - npgsql fails to figure out what primitive type to use.

elexisvenator avatar May 25 '22 09:05 elexisvenator