FSharp.Data icon indicating copy to clipboard operation
FSharp.Data copied to clipboard

Generate enums in csv type provider

Open ovatsus opened this issue 12 years ago • 12 comments

If a column is infered as string, and there are many repeated values, it's probably an enumeration, so we could generate an enum. If the inference geets it wrong, we could always override (#19). We could use something like (number of distinct values / number of rows) < 0.2 to trigger this

ovatsus avatar Jan 28 '13 15:01 ovatsus

This is an interesting thought. Is it actually possible to generate enums in a type provider?

tpetricek avatar Jan 28 '13 15:01 tpetricek

There's no ProvidedEnum in ProvidedTypes.fs, but maybe it's possible to add it. It's not an F# only type, so I'm guessing it it should be possible

ovatsus avatar Jan 28 '13 16:01 ovatsus

http://stackoverflow.com/questions/15174637/how-to-generate-enums-in-a-f-type-provider

ovatsus avatar Nov 22 '13 23:11 ovatsus

Cool, it would make sense to have this in. The only sad things is that it will require fully qualified access. But even then, this looks pretty good to me:

type Foo = CsvProvider<....>
[ for r in Foo().Data do
    if r.Bar = Foo.ColumnName.CaseName then yield r.Other ]

(I think we probably do not need to hide the enums in DomainTypes - that would make them hard to discover.)

tpetricek avatar Nov 23 '13 05:11 tpetricek

Actually, the CsvProvider doesn't have a DomainTypes right now, because it only has one inner type, unlike JsonProvider & XmlProvider which can have multiple. I think we should keep it that way

ovatsus avatar Nov 23 '13 11:11 ovatsus

If this is an ongoing requirement, I can take this on. The above discussion should give me enough detail to implement this feature.

ChrisBallard avatar Jun 26 '14 09:06 ChrisBallard

That would be great, though I'm under the impression that it's only possible to make enums work in generated TPs. In any case, it needs investigation to confirm that. We have another item to switch to the generated model

ovatsus avatar Jun 26 '14 09:06 ovatsus

Ah thanks - I hadn't noticed that. I'll do some research first and report back. If necessary we can shelve until we switch to generated.

ChrisBallard avatar Jun 26 '14 13:06 ChrisBallard

Or you could move CSV to generated as part of this :)

ovatsus avatar Jun 26 '14 13:06 ovatsus

Of course - actually I was trying to find that item to see if it was up for grabs - I didn't spot it though?

ChrisBallard avatar Jun 26 '14 13:06 ChrisBallard

It's here: https://github.com/fsharp/FSharp.Data/issues/134

ovatsus avatar Jun 26 '14 14:06 ovatsus

nice point! is there any news on this one? seems like a pretty cool functionality

jkone27 avatar Jan 18 '22 10:01 jkone27