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

Allow using client indices for *string columns #387

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

npinaeva
Copy link
Member

@npinaeva npinaeva commented Aug 7, 2024

When getting cache values, dereference pointers.
This allows using pointer fields (e.g. *string) as client indices.

Addresses #386

cache/cache.go Outdated
@@ -1251,7 +1251,7 @@ func valueFromIndex(info *mapper.Info, columnKeys []model.ColumnKey) (interface{
}

func valueFromColumnKey(info *mapper.Info, columnKey model.ColumnKey) (interface{}, error) {
val, err := info.FieldByColumn(columnKey.Column)
val, err := info.DerefFieldByColumn(columnKey.Column)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the logic applies the same on val either returned from FieldByColumn or valueFromMap so i would just probably apply the logic on val at the end of this method.

@jcaamano
Copy link
Collaborator

jcaamano commented Aug 7, 2024

The README can probably take an update too

README.md Outdated
@@ -120,6 +120,26 @@ can now be improved with:
// quick indexed result
ovn.Where(lb).List(ctx, &results)

Client indexes support using pointer Columns, for example if a column "optional_string" has Model type `*string`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I will probably write this from the functional perspective rather than the implementation perspective. Something like

Unlike schema indexes, client indexes can be used with optional columns and rows with no value are indexed as well

You can probably join this sentence, with the other one above that also starts with Unlike schema indexes so that differences are highlighted together.
Other than that small mention I don't much else is needed. The example doesn't really add much value I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure if I got your suggestion right, lmk if I should change it more.

cache/cache.go Outdated
Comment on lines 1264 to 1268
v := reflect.ValueOf(val)
if v.Kind() == reflect.Ptr && !v.IsNil() {
v = v.Elem()
}
return v.Interface(), err
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this work?

// if the value is a non-nil pointer of an optional, dereference
v := reflect.ValueOf(val)
if v.Kind() == reflect.Ptr && !v.IsNil() {
   val = v.Elem().Interface()
}
return val, err


var nilString *string

func TestRowCacheCreateReferenceClientIndex(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does Reference stand for here? Maybe TestRowCacheCreateOptionalColumnClientIndex?

err = json.Unmarshal(getTestSchema(""), &schema)
require.Nil(t, err)
testData := Data{
"Open_vSwitch": map[string]model.Model{"bar": &testModel{Datapath: getStringPtr("bar")}}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: closing brace on a new line

Copy link
Collaborator

@jcaamano jcaamano 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, minor nits.

Have you had the chance to test this with ovn-k CI? It's a good additional and reassuring thing we can do to make sure we are not breaking anything.

@npinaeva
Copy link
Member Author

Looks good, minor nits.

Have you had the chance to test this with ovn-k CI? It's a good additional and reassuring thing we can do to make sure we are not breaking anything.

let me do an ovn-k pr with that

@npinaeva
Copy link
Member Author

let me do an ovn-k pr with that

Looks green enough :) ovn-org/ovn-kubernetes#4619

README.md Outdated
Comment on lines 123 to 125
Unlike schema indexes, client indexes can be used with optional columns and rows with no value are indexed as well.
For example, if a column "optional_string" has Model type `*string`, it can be used in a client index.
The indexing will happen based on dereferenced value, but `nil` will be considered a valid value.
Copy link
Collaborator

Choose a reason for hiding this comment

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

So above we have the phrase

...the columns that compose the index. Unlike schema indexes, a key within a column can be addressed if the column
type is a map.

I was thinking on something like:

...the columns that compose the index. However, unlike schema indexes, client indexes:
* can be used with columns that are optional, where no-value columns are indexed as well.
* can be used with columns that are maps, where specific map keys can be indexed (see example below).

This way we have the two main differences together. Let me know what you think.

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 like this description! I just missed that we already have a similar sentence in the doc.

This allows using optional pointer fields (e.g. *string)
as client indices.

Signed-off-by: Nadia Pinaeva <[email protected]>
@jcaamano jcaamano merged commit ce19516 into ovn-org:main Aug 20, 2024
7 checks passed
@npinaeva npinaeva deleted the pointer-column branch August 20, 2024 19:06
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

Successfully merging this pull request may close these issues.

3 participants