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

feat(xlsx): initial support for xlsx data format, identity dsio #170

Merged
merged 2 commits into from
Feb 5, 2019
Merged

Conversation

b5
Copy link
Member

@b5 b5 commented Feb 4, 2019

in a world where we have more time I'd break these commits up. This adds initial support for the xlsx data format as readers/writers.

Also added: initial support for "identity" dsio read/write for data that's already been parsed. We're going to need this later on for working with inlined dataset bodies. currently not in use, and shouldn't be used until we have tests.

The one change this does require is adding a Close method on dsio.EntryReader, which to me should probably be there anyway.

also fixed an issue with dsutil.FormFileDataset that wasn't properly assigning form values to the returned dataset.

@b5 b5 added feat A code change that adds functionality Fix A bug fix dsio issues surrounding dataset input/output labels Feb 4, 2019
@b5 b5 self-assigned this Feb 4, 2019
@ghost ghost added the in progress label Feb 4, 2019
in a world where we have more time I'd break these commits up. This adds initial support for the xlsx data format as readers/writers.

Also added: initial support for "identity" dsio read/write for data that's already been parsed. We're going to need this later on for working with inlined dataset bodies. currently not in use, and shouldn't be used until we have tests.

also fixed an issue with dsutil.FormFileDataset that wasn't properly assigning form values to the returned dataset.
Copy link
Collaborator

@dustmop dustmop left a comment

Choose a reason for hiding this comment

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

LGTM! Got only a few comments.

data_format.go Outdated
@@ -30,9 +30,9 @@ const (
// XMLDataFormat specifies eXtensible Markup Language-formatted data
// currently not supported.
XMLDataFormat
// XLSDataFormat specifies microsoft excel formatted data
// XLSXDataFormat specifies microsoft excel formatted data
// currently not supported.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove "currently not supported". I understand this is only partial support, but I think it's enough that it moves beyond "not supported".


// Map structures XLSXOptions as a map of string keys to values
func (o *XLSXOptions) Map() map[string]interface{} {
if o == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to check nil here? In the rest of codebase, we're assuming that interface types won't contains a nil pointer value, for example see lib/datasets.go. Seems like an anti-pattern to support it here, and the code will just crash a few lines below where we try to resolve o.SheetName.

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally agreed with this. All three FormatConfig variants have this quirk, so I'd like to remove it in a separate PR with some proper checks. I'll file an issue

Copy link
Member Author

Choose a reason for hiding this comment

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

dsio/xslx.go Outdated
rdr.r, rdr.err = rdr.file.Rows(rdr.sheetName)
}

return rdr, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm unsure, but should this be return rdr, rdr.err? Otherwise the error from Rows is being ignored.

dsio/xslx.go Outdated

// Get the largestDenominator that is a multiple of a basedDenominator
// and fits at least once into a given numerator.
func getLargestDenominator(numerator, multiple, baseDenominator, power int) (int, int) {
Copy link
Collaborator

@dustmop dustmop Feb 4, 2019

Choose a reason for hiding this comment

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

I realize this function is coming from another source, but I find it pretty confusing, and a bit over complicated. How about:

// largestLesserExponent returns the largest exponent of base that does not exceed num
// equivalent to pow(floor(log(num, base)), base)
func largestLesserExponent(num, base int) int {
  prev := 1
  exp := base
  for num >= exp {
    prev = exp
    exp = exp * base
  }
  return prev
}

Copy link
Member Author

Choose a reason for hiding this comment

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

this is delightful.

@b5 b5 merged commit d20b4dc into master Feb 5, 2019
@ghost ghost removed the in progress label Feb 5, 2019
@b5 b5 deleted the xlsx branch February 5, 2019 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dsio issues surrounding dataset input/output feat A code change that adds functionality Fix A bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants