Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standards and Best practice: Exporting Tree Structure Data to CSV

Tags:

java

csv

tree

I have a tree structural data(parent child) to export into CSV.

Is there any standard format to display the data in a meaningful way and maybe for future usage?

Currently I am considering using empty "", to denote the next level.

like image 840
seesee Avatar asked Aug 07 '12 03:08

seesee


People also ask

What is the correct format for a CSV file?

CSV , or Comma-separated Values, is an extremely common flat-file format that uses commas as a delimiter between values. Anyone familiar with spreadsheet programs has very likely encountered CSV files before - they're easily consumed by Google Spreadsheet, Microsoft Excel, and countless other applications.

Which of the following command is used to export data to CSV?

SQLite facilitates you to export data from SQLite database to CSV file.

Which character is used to create a new file in CSV?

A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format.

What's the meaning of CSV?

A CSV (comma-separated values) file is a text file that has a specific format which allows data to be saved in a table structured format.


1 Answers

Well, there is no standard here, at least not something I'm aware of. It usually comes to performance aspects, the ease of usage and the size of tree.

I can offer you to store the tree as a pairs of parent son relation, and then you'll be able to recreate the tree.

Example:

Lets assume, you have a tree:

root

a

b

  c

This can be expressed like series of relations:

root --> a

root --> b

b --> c

This is exactly what you can store in the file:

root,a
root,b
b,c

Another interesting method can be used given the fact that the tree (at least binary tree) can be represented as an array

This will let you store the single line in your csv file since the array is linear and it naturally maps into an array I'm sure you can find much more ways to store the tree, the sky is a limit here, I've just pointed you a few.

Hope this helps

like image 158
Mark Bramnik Avatar answered Sep 30 '22 12:09

Mark Bramnik