Giter VIP home page Giter VIP logo

Comments (8)

jakubmaguza avatar jakubmaguza commented on August 24, 2024

Can you provide any test data? I create random data with 2000 columns and 2000 rows and there is no exception.

from csvreader.

kirikintha avatar kirikintha commented on August 24, 2024

@jakubmaguza - I sure can, let me put together a sample. Thanks for the help!

from csvreader.

jakubmaguza avatar jakubmaguza commented on August 24, 2024

@kirikintha Hi. Unfortunatelly the url is broken. Can you send it one more time?

from csvreader.

kirikintha avatar kirikintha commented on August 24, 2024

@jakubmaguza - here is another attachment. Let's see how this goes. The columns have fairly long names in some places, and some eccentricity, but they are all quoted.

Audit-Large Column List.txt

from csvreader.

jakubmaguza avatar jakubmaguza commented on August 24, 2024

@kirikintha File works gr8, but I can see only one column in this file with 196 rows.

from csvreader.

jakubmaguza avatar jakubmaguza commented on August 24, 2024

I took a quick look at this file and it's braking at last row, where you don't have comma as last character.

from csvreader.

phatcher avatar phatcher commented on August 24, 2024

@kirikintha Looking at the sample test @jakubmaguza provided the issue is the parsing mode for the file.

By default the action on a missing field error is ParseError which means if you have a malformed line, the parser will throw an exception.

However you could set this to ReplaceByNull or ReplaceByEmpty, you may still have a issue with SQLBulkCopy as it is very particular about column types but this may be helped with the column default value setting.

I've added further tests around the MissingFieldAction into the code...

    [Test]
    public void MissingFieldNull()
    {
        using (var csv = new CsvReader(new StringReader("a,b,\nc,d"), false))
        {
            csv.SkipEmptyLines = true;
            csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;

            RowCheck(csv, "a", "b", string.Empty);
            RowCheck(csv, "c", "d", null);

            Assert.That(csv.ReadNextRecord, Is.False);
        }
    }

    [Test]
    public void MissingFieldEmpty()
    {
        using (var csv = new CsvReader(new StringReader("a,b,\nc,d"), false))
        {
            csv.SkipEmptyLines = true;
            csv.MissingFieldAction = MissingFieldAction.ReplaceByEmpty;

            RowCheck(csv, "a", "b", string.Empty);
            RowCheck(csv, "c", "d", string.Empty);

            Assert.That(csv.ReadNextRecord, Is.False);
        }
    }

    [Test]
    public void MissingFieldException()
    {
        using (var csv = new CsvReader(new StringReader("a,b,\nc,d"), false))
        {
            csv.SkipEmptyLines = true;
            csv.MissingFieldAction = MissingFieldAction.ParseError;

            RowCheck(csv, "a", "b", string.Empty);
            RowCheck(csv, "c", "d");

            Assert.Throws<MissingFieldCsvException>(() => { var x = csv[2]; });
        }
    }

from csvreader.

kirikintha avatar kirikintha commented on August 24, 2024

Hi everyone, thank you kindly for the update on how to handle the parse errors - I am working with the missing field exception examples and getting farther down the road. I also did an analysis on the file and it is malformed so I am having to go in and try some variation on the DDL and see if I can make it work.

Thank you so much for your help and analysis!

from csvreader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.