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

refactor: Unify Field Kind and Schema properties #2414

Merged

Conversation

AndrewSisley
Copy link
Contributor

Relevant issue(s)

Resolves #2409

Description

Unifies the Field Kind and Schema properties.

Commits should be clean, although most of the work is in the last. Tests have been modified/deleted in other ways besides cid changes as this PR changes public behaviour (heads up in case the first few files make it look like the usual cid change stuff).

@AndrewSisley AndrewSisley added area/schema Related to the schema system refactor This issue specific to or requires *notable* refactoring of existing codebases and components labels Mar 15, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.11 milestone Mar 15, 2024
@AndrewSisley AndrewSisley requested a review from a team March 15, 2024 21:29
@AndrewSisley AndrewSisley self-assigned this Mar 15, 2024
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

Attention: Patch coverage is 75.84270% with 43 lines in your changes are missing coverage. Please review.

Project coverage is 74.91%. Comparing base (d1b1a76) to head (f32d759).

❗ Current head f32d759 differs from pull request most recent head 191228c. Consider uploading reports for the commit 191228c to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2414      +/-   ##
===========================================
- Coverage    74.93%   74.91%   -0.02%     
===========================================
  Files          268      268              
  Lines        25856    25888      +32     
===========================================
+ Hits         19373    19393      +20     
- Misses        5157     5172      +15     
+ Partials      1326     1323       -3     
Flag Coverage Δ
all-tests 74.91% <75.84%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
client/definitions.go 93.94% <ø> (-0.18%) ⬇️
db/collection.go 73.05% <100.00%> (-0.18%) ⬇️
db/collection_update.go 71.28% <100.00%> (ø)
db/errors.go 64.31% <100.00%> (-3.22%) ⬇️
db/index.go 68.04% <100.00%> (+0.44%) ⬆️
db/schema.go 83.06% <100.00%> (-2.16%) ⬇️
planner/mapper/mapper.go 87.43% <100.00%> (ø)
planner/type_join.go 79.14% <100.00%> (ø)
db/backup.go 59.50% <80.00%> (-0.14%) ⬇️
request/graphql/schema/collection.go 90.89% <90.00%> (+0.11%) ⬆️
... and 3 more

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1b1a76...191228c. Read the comment docs.

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

LGTM. I like that it simplifies the code in some areas. Good job!

// Underlying returns the unterlying Kind as a string.
//
// If this is an array, it will return the element kind, else it will return the same as
// [String()].
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: I think that this notation is used in some other places as well but here it threw me off given the context. I was wondering why calling Undelying() on a non array would return String() wrapped in an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Square brackets are how to correctly link stuff in Go docs, although I'm not really sure it works for funcs. I used to use backticks as that feels more normal (and is what rust uses), but the Go devs went with square brackets in 1.19:

https://tip.golang.org/doc/comment#links

Comment on lines +322 to +327
case uint8(FieldKind_BOOL_ARRAY), uint8(FieldKind_INT_ARRAY), uint8(FieldKind_FLOAT_ARRAY),
uint8(FieldKind_STRING_ARRAY), uint8(FieldKind_NILLABLE_BOOL_ARRAY), uint8(FieldKind_NILLABLE_INT_ARRAY),
uint8(FieldKind_NILLABLE_FLOAT_ARRAY), uint8(FieldKind_NILLABLE_STRING_ARRAY):
f.Kind = ScalarArrayKind(intKind)
default:
f.Kind = ScalarKind(intKind)
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: This as the potential to be quite annoying to maintain as we update out list of supported array types. I'm wondering if we should take the hit now and change the assigned number ranges to something like:

  • [0:100] -> Scalar types
  • [100:200] -> Array types

We wont be using the full range but at least if we ever need to do another switch statement it would be a much cleaner check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dislike the current too, however I don't like the range option, and would probably prefer a custom encoding: First bit for nillable, second bit for array, then the scalar id.

As a proper solution would require a bit of thought and an agreed design, I'd prefer if this conversation was out of scope here.

Schema was removed from the path a long time ago, correct error being returned was a coincidence.
The upcoming changes to FieldKind will prevent == checks like this.  That IsObject also returns true for arrays of objects is a bit weird in my opinion, but changing that is out of scope.
Zero will not be a valid value with the upcoming change.
This is dead code and has been for quite a long time.  Maintaining it with the upcoming change will be a pain.
@AndrewSisley AndrewSisley merged commit 85eca12 into sourcenetwork:develop Mar 19, 2024
27 of 28 checks passed
@AndrewSisley AndrewSisley deleted the 2409-unify-field-kind-schema branch March 19, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema Related to the schema system refactor This issue specific to or requires *notable* refactoring of existing codebases and components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify SchemaFieldDescription Kind and Schema
2 participants