Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csvutil/csvdriver: add ability to name columns #39

Open
sbinet opened this issue Mar 10, 2017 · 1 comment
Open

csvutil/csvdriver: add ability to name columns #39

sbinet opened this issue Mar 10, 2017 · 1 comment

Comments

@sbinet
Copy link
Member

sbinet commented Mar 10, 2017

From @sbinet on November 16, 2016 9:15

right now, opening a CSV connection is done like so:

func foo() {
	// Open the CSV file as a database table.
	db, err := csvdriver.Conn{
		File:    "../data/iris.csv",
		Comment: '#',
		Comma:   ',',
	}.Open()
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	// Start a database transaction.
	tx, err := db.Begin()
	if err != nil {
		log.Fatal(err)
	}
	defer tx.Commit()

	// Define a SQL query that we will execute against the CSV file.
	query := "SELECT var3, var4, var5 FROM csv WHERE var5 = \"Iris-versicolor\""

	// etc...
}

this makes a query rather cumbersome to read.

it should be possible to open a CSV connection with an optional Columns []string field:

// Open the CSV file as a database table.
db, err := csvdriver.Conn{
	File:    "../data/iris.csv",
	Comment: '#',
	Comma:   ',',
	Columns: []string{"sepal_length", "sepal_width", "petal_length", "petal_width", "species"},
}.Open()

such that the query reads:

// Define a SQL query that we will execute against the CSV file.
query := `SELECT petal_length, petal_width, species FROM csv WHERE species = "Iris-versicolor"`

What do you think @dwhitena ?

Copied from original issue: go-hep/csvutil#2

@sbinet sbinet changed the title csvdriver: add ability to name columns csvutil/csvdriver: add ability to name columns Mar 10, 2017
@sbinet sbinet removed the go-hep-mig label Mar 10, 2017
@dwhitena
Copy link

Yes, I like that. In fact you could call this "schema" if you like, because we are really interacting as if it were a database. I guess it depends on how we want the user to think about the interaction. If we are thinking in terms of a DB interaction, I think schema makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants