Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

CSV file structure Validation

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to validate CSV file structure.
CSV file will have different data-types and different data-types will have different fields.
we want to check number of data-types records against value we have in different count file and predefined fields in each data-type records.
fields will be separated by "|".
Simple Example of CSV file is like

if I have 3 different Data types Acccount-10,Person-20,Order-30
Account have 2 record count,
Person will have 3 records count
and Order will have 5 record count

Account will have field value like Account Number,AmountinAccount,AccountComments
Person will have filed like PersonID,PersonName,PersonAdress
Order will have field like Orderid,OrderName


The CSV file like

10|12|2500|Active
10|12|2500|Active
20|1|Mark|US
20|2|Adren|UK
20|3|David|IN
30|Ship
30|Car
30|Pizza
30|Bricks
30|containers


this will be example of CSV file structure
where 10,20 and 30 are number for Data type.

please suggest me away to validate the structure of this type of CSV files.



 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe try to read the file using one of the CSV libraries listed in the https://coderanch.com/how-to/java/AccessingFileFormats page and check if they throw an exception. Be sure to choose one that can handle vertical bars as separators.
 
Yashwant Palkar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i validate this particular CSV against this format which I have mentioned?
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yashwant Palkar wrote:how can i validate this particular CSV against this format which I have mentioned?



With the lack of detailed syntax for the format I don't think you can validate since the third field is ambiguous for these records


As a starting point you should do as has already been suggested and use a CSV parser to extract the basic fields. Then when you have a syntax for each field check each field against the syntax.
 
Yashwant Palkar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me state my requirement once again….

We have Counter File which contains following details for each record types.
Struture : RecordType|RecordCount|FieldCount
Example
1|27|9 –Means 27 records of record type 1, and each record has 9 fields
2|34|5 –Means 34 records of record type 2, and each record has 5 fields

We have Data File which contain actual records ordered by record type. Frist field of reach record contains value of Record Type.

Example
1|field1| field2| field3| field4| field5| field6| field7| field8| field9|
1|field1| field2| field3| field4| field5| field6| field7| field8| field9|
1|field1| field2| field3| field4| field5| field6| field7| field8| field9|
.
.
.
Like total 27 records
2|field1| field2| field3| field4| field5|
2|field1| field2| field3| field4| field5|
2|field1| field2| field3| field4| field5|
.
.
.
Like total 34 records

We want to validate Data File against details present in Counter File. More spesifically we want to vaklidate following two things
(1) Number of records per Record Type
(2) Number of fields for each Record Type
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yashwant Palkar wrote:Let me state my requirement once again….

We have Counter File which contains following details for each record types.
Struture : RecordType|RecordCount|FieldCount
Example
1|27|9 –Means 27 records of record type 1, and each record has 9 fields
2|34|5 –Means 34 records of record type 2, and each record has 5 fields

We have Data File which contain actual records ordered by record type. Frist field of reach record contains value of Record Type.

Examplehad
1|field1| field2| field3| field4| field5| field6| field7| field8| field9|
1|field1| field2| field3| field4| field5| field6| field7| field8| field9|
1|field1| field2| field3| field4| field5| field6| field7| field8| field9|
.
.
.
Like total 27 records
2|field1| field2| field3| field4| field5|
2|field1| field2| field3| field4| field5|
2|field1| field2| field3| field4| field5|
.
.
.
Like total 34 records

We want to validate Data File against details present in Counter File. More spesifically we want to vaklidate following two things
(1) Number of records per Record Type
(2) Number of fields for each Record Type



Once more we are presented with creeping requirements. So you validate the CSV file against a file defining what should be in the file. Then, as has been said twice before, using one of the CSV libraries to read the CSV file. You can then read the definition file to see what should have been in your CSV file and make sure it matches.

I'm a little lost as to why you are having trouble with this.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK - how about turn the CSV into an XML document using something like ServingXML - open source toolkit and then validating values with a Schema followed by checking your other requirements in XML?

Bill
 
Marshal
Posts: 74693
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to JavaRanch
reply
    Bookmark Topic Watch Topic
  • New Topic