Skip to content

feat: Include CSV headers#30

Merged
kodiakhq[bot] merged 19 commits intomainfrom
include-csv-headers
Jan 18, 2023
Merged

feat: Include CSV headers#30
kodiakhq[bot] merged 19 commits intomainfrom
include-csv-headers

Conversation

@bbernays
Copy link
Copy Markdown
Contributor

@bbernays bbernays commented Jan 13, 2023

Summary

Adds ability to conditionally include headers for CSV files

@github-actions github-actions Bot added feat and removed feat labels Jan 13, 2023
@bbernays bbernays linked an issue Jan 13, 2023 that may be closed by this pull request
4 tasks
Comment thread csv/write.go Outdated
)

func WriteTableBatch(w io.Writer, _ *schema.Table, resources [][]any) error {
func WriteTableBatch(w io.Writer, table *schema.Table, resources [][]any, headers bool) error {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't come up with any other way of injecting this conditional headers argument... Suggestions would be appreciated, or I can just add a nolint to it...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they basically want you to split it into different functions, e.g. WriteTableBatch and WriteTableBatchNoHeaders. It might be better to force users to think about whether they want headers or not though, so I'm fine with adding nolint for this case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I will just add the nolint

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how that can be possible, unless you still had a private function with the header boolean? In that case you could rather have WriteTableBatch write the headers first, then call WriteTableBatchNoHeaders to do the rest

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Or something to that effect - probably won't work just like that) In any case, nolint is fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this some more... the function WriteTableBatch(w io.Writer, table *schema.Table, resources [][]any) is a standard interface used throughout many destinations, and the plugin sdk... Maybe we need a more generic way of passing in arguments...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe it is better to add an entirely new function than it is to break that function signature...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, though I think the filetypes don't need to conform to that interface. (CC @yevgenypats because he'll probably know better)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A generic way of passing arguments sounds good though, as we'll hopefully be adding support for more formats (like parquet) in the not-too-distant future as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the current approach in this PR is the right one as there is no generic interface needed here and the caller need to know wheater they want to use headers or not.

Un related to that if we already add options to that table I would make this just a bit nicer with ...Option so we can extend this later without breaking the interface (For example, if we would want an option of changing a delimiter ).

Comment thread csv/write.go Outdated
Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good but seems the interface needs a bit of change because now we want to add options to write and read which means we actually want a NewClient(...Option) *Client which will have WriteTableBatch and Read methods.

and one option for nowOptionWithHeaders

Comment thread csv/write.go Outdated
)

func WriteTableBatch(w io.Writer, _ *schema.Table, resources [][]any) error {
func WriteTableBatch(w io.Writer, table *schema.Table, resources [][]any, headers bool) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the current approach in this PR is the right one as there is no generic interface needed here and the caller need to know wheater they want to use headers or not.

Un related to that if we already add options to that table I would make this just a bit nicer with ...Option so we can extend this later without breaking the interface (For example, if we would want an option of changing a delimiter ).

Comment thread csv/read.go
}
return err
}
if record[sourceNameIndex] != sourceName {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is removed? also, shouldn't the no header propogate here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed because when there are headers the row does not get read...

Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. few comments.

Comment thread csv/client.go Outdated
Comment thread csv/client.go Outdated
Comment thread client.go Outdated
Comment thread client.go Outdated
Comment thread csv/read.go Outdated
Comment thread csv/client.go Outdated
Comment thread csv/write.go
@yevgenypats yevgenypats added the automerge Add to automerge PRs once requirements are met label Jan 18, 2023
@kodiakhq kodiakhq Bot merged commit 9ab6df8 into main Jan 18, 2023
@kodiakhq kodiakhq Bot deleted the include-csv-headers branch January 18, 2023 16:56
kodiakhq Bot pushed a commit that referenced this pull request Jan 18, 2023
🤖 I have created a release *beep* *boop*
---


## [1.1.0](v1.0.6...v1.1.0) (2023-01-18)


### Features

* Include CSV headers ([#30](#30)) ([9ab6df8](9ab6df8))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Add to automerge PRs once requirements are met feat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update filetype library to support Headers/No headers

3 participants