Comments (2)
-
I'm assuming your file has a header row? Otherwise, you wouldn't be able to map my name alone as the columns don't have names. You can use the Schema type to map the named columns to their own name: Schema.Parse("Name>Name,LastName>LastName,BirthDay>BirthDay:DateTime"). This ">" syntax maps the "base column name" (the name in the file) to the name that it will be exposed as through the CsvDataReader. You could also implement your own mapping mechanism by implementing your own CsvSchemaProvider.
-
Using the above mapping technique, you can check via GetOrdinal which will throw an exception if the name doesn't exist. Or, you can use the GetColumnSchema method to get the exposed schema and verify that all the expected columns are present.
-
I would expect that to "just work", so maybe I don't understand what you're asking.
-
You can use the Validate or ValidateSchema extension methods (in Sylvan.Data) which allow you to handle data validations. These methods allow you to provide a validation method, which will be called for all rows (Validate), or only called for rows that don't match the expected schema (ValidateSchema). ValidateSchema is probably what you want; your validation method will only be called when the date value can't be parsed correctly. In your validation method you can try to "repair" the data. The DataValidationContext parameter has methods to determine what columns have errors (GetErrors/GetException), and methods to allow you to provide a value (SetValue). You can return
true
if you could repair the data and want it to be yielded from the reader, or false to skip the row altogether, and maybe log the failed row somewhere.
Hopefully that helps, but I'm not sure I was understanding your issues so let me know if I did.
from sylvan.
I'll assume, at this point, that you got things working...
from sylvan.
Related Issues (20)
- Exception messages could be made more helpful? HOT 3
- Suggestion: Enable support for [NotMapped] attribute to tell the binder a class property has no mapping to the datasource HOT 2
- Doc error HOT 2
- Ordering of columns HOT 3
- Nullable string from an empty string HOT 2
- Write headers when no data? HOT 1
- Cannot parse a CR delimited file HOT 2
- Non-descript exception thrown for Sylvan.Data.Csv HOT 3
- Processing files with large numbers of errors is rather slow HOT 3
- Csv headers with "" HOT 3
- Skipping over rows that throw CsvFormatException HOT 2
- passing an IAsyncEnumerable to ObjectDataReader.Builder HOT 2
- As is. The Object to CSV Writer example doesn't compile HOT 1
- Clone a CsvDataReader HOT 1
- CsvDataWriter to append to a file HOT 1
- Configuration adjustments for CSV parsing HOT 1
- Records Count and Max Length of each Column HOT 1
- A 19kb record throws CsvRecordTooLargeException HOT 3
- Fields ending in escaped character return the wrong character HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sylvan.