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

chore: introduce encoding factory #3740

Merged
merged 6 commits into from
Aug 21, 2023
Merged

chore: introduce encoding factory #3740

merged 6 commits into from
Aug 21, 2023

Conversation

achettyiitr
Copy link
Member

@achettyiitr achettyiitr commented Aug 11, 2023

Description

  • Encoding manager: Deals with related tasks corresponding to encodings like reading, writing, and loading.
  • Some code cleanup.
  • Removed encoding.Init().

Linear Ticket

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Patch coverage: 86.99% and project coverage change: -0.06% ⚠️

Comparison is base (ff80a1d) 68.78% compared to head (e5c4032) 68.73%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3740      +/-   ##
==========================================
- Coverage   68.78%   68.73%   -0.06%     
==========================================
  Files         345      344       -1     
  Lines       51917    51936      +19     
==========================================
- Hits        35711    35698      -13     
- Misses      13907    13941      +34     
+ Partials     2299     2297       -2     
Files Changed Coverage Δ
runner/runner.go 69.29% <ø> (-0.26%) ⬇️
warehouse/upload_stats.go 58.53% <71.42%> (ø)
warehouse/encoding/jsonreader.go 68.96% <75.00%> (-11.04%) ⬇️
warehouse/upload.go 71.48% <75.57%> (-0.39%) ⬇️
warehouse/encoding/jsonloader.go 84.21% <88.88%> (+0.48%) ⬆️
warehouse/encoding/parquetloader.go 97.43% <97.72%> (+33.23%) ⬆️
warehouse/encoding/csvloader.go 80.64% <100.00%> (+0.64%) ⬆️
warehouse/encoding/csvreader.go 100.00% <100.00%> (ø)
warehouse/encoding/encoding.go 100.00% <100.00%> (ø)
warehouse/encoding/parquetwriter.go 68.08% <100.00%> (-11.92%) ⬇️
... and 8 more

... and 11 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@achettyiitr achettyiitr force-pushed the chore.encoding-init branch 3 times, most recently from 54744d4 to c7d6bf7 Compare August 11, 2023 15:17
Copy link
Collaborator

@fracasula fracasula left a comment

Choose a reason for hiding this comment

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

Sorry for the partial review, I didn't have the time to complete it. Unfortunately I won't have the time to do so until Wednesday. In any case don't consider these comments as blockers, I just wanted to start a discussion.

Comment on lines 21 to 37
type LoadFileWriter interface {
type Writer interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find the old name a bit more specific actually. Writer is a very generic name but this interface has the GetLoadFile for example that makes it really specific.

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense. Reverted it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking in terms of the warehouse module only where:

  1. Readers -> Load file Readers.
  2. Writers -> Load file singular event writers.
  3. Loaders -> Load file singular event loaders.

}
}

type Loader interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we could came up with a better name for this one. It lives in the warehouse/encoding package so if we just call it Loader it doesn't tell us much about what it is supposed to load and for sure it doesn't look like we can use it to load "everything", right?

As a sidenote, it doesn't look very SOLID. I'm not asking for changes in this regard but I think it's beneficial to mention as a part of a broader discussion to gather your feedback. For example in SOLID the S stands for "Single Responsibility". When looking at this interface though we see that whoever is going to implement this interface will have multiple responsibilities (e.g. parsing in order to understand if a column name is a load time column, ability to add columns, ability to write data somewhere, etc...).

An initial step towards a more SOLID approach, we could split this interface into multiple ones. Luckily with Go the same struct can implicitly implement multiple interfaces so we won't have to create more structs as a result, at least at the beginning. Still having more than one interface here can help grasp the code and can help with understanding the dependencies and responsibilities of these components. Usually this is going to help with tests and mocks as well. I hope it makes sense, feel free to share your thoughts.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I completely aggress with having a solid interface.

@fracasula fracasula changed the title chore: introduce encoding manager manager chore: introduce encoding manager+ Aug 16, 2023
@fracasula fracasula changed the title chore: introduce encoding manager+ chore: introduce encoding manager Aug 16, 2023
return []string{}, fmt.Errorf("scanner scan: %w", err)
}
return []string{}, io.EOF
}

lineBytes := js.scanner.Bytes()
jsonData := make(map[string]string)
jsonData := make(map[string]interface{})
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 came across while writing the tests. It's expecting only string which will not be the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are doing cast.ToStringE(jsonData[columnName]) to load into the record.

warehouse/encoding/encoding.go Outdated Show resolved Hide resolved
@achettyiitr achettyiitr changed the title chore: introduce encoding manager chore: introduce encoding factory Aug 18, 2023
@achettyiitr achettyiitr merged commit 188b95c into master Aug 21, 2023
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants