Skip to content

Error converting to Int64 in quoted field with embedded comma #310

@mhsimkin

Description

@mhsimkin

Hi:

My sample data is similar to the below:

Term,Visits,Hits
,,
harry potter,"68,705","143,345"
James Patterson,"10,860","31,503"
nora roberts,"9,852","30,073"

When I attempt to read the data from the file using the DelimitedFileEngine, I receive the following error:

? e
{"Error Converting '\"68' to type: 'Int64'. "}
    ColumnNumber: 14
    Data: {System.Collections.ListDictionaryInternal}
    FieldName: "<Visits>k__BackingField"
    FieldStringValue: "\"68"
    FieldType: {Name = "Int64" FullName = "System.Int64"}
    HResult: -2146233088
    HelpLink: null
    InnerException: null
    LineNumber: 3
    Message: "Error Converting '\"68' to type: 'Int64'. "
    MessageExtra: ""
    MessageOriginal: "Error Converting '\"68' to type: 'Int64'. "
    Source: "FileHelpers"
    StackTrace: "   at FileHelpers.ConvertHelpers.Int64Converter.ParseString(String from)\r\n   at FileHelpers.FieldBase.AssignFromString(ExtractedInfo fieldString, LineInfo line)\r\n   at FileHelpers.FieldBase.ExtractFieldValue(LineInfo line)\r\n   at FileHelpers.RecordOperations.StringToRecord(Object record, LineInfo line, Object[] values)\r\n   at FileHelpers.FileHelperEngine`1.ReadStreamAsList(TextReader reader, Int32 maxRecords, DataTable dt)\r\n   at FileHelpers.FileHelperEngine`1.ReadStream(TextReader reader, Int32 maxRecords)\r\n   at FileHelpers.FileHelperEngine`1.ReadFile(String fileName, Int32 maxRecords)\r\n   at SaFileIngestion.FileProcessorEngine.Process(CancellationToken cancellationToken) in D:\\Work\\BN\\ProductDataSystemsGitRepos\\Tools\\searchaugmentation\\SaFileIngestion\\FileProcessorEngine.cs:line 54"
    TargetSite: {System.Object ParseString(System.String)}

```

I have defined my record class as:

```
    [DelimitedRecord(",")]
    [IgnoreEmptyLines]
    [IgnoreFirst(2)]

    internal class SearchTermRecord : SearchTermInfo
    {
        public override string Term { get; set; }

        [FieldQuoted]
        //[FieldConverter(ConverterKind.Int64)]
        public override long Visits { get; set; }

        [FieldQuoted]
        //[FieldConverter(ConverterKind.Int64)]
        public override long Hits { get; set; }

    }

```

What attributes do I need to set so that the library can handle processing a field that is surrounded by quotes and has an embedded comma?

Thanks

-marc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions