Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Add ability to have sentinel values for Clustering Columns #71

Merged
merged 4 commits into from
Sep 20, 2021

Conversation

suhailpatel
Copy link
Member

In services like Keyspaces, it is not permitted to have empty string/blob clustering values. This PR introduces a sentinel value that can stand-in in these cases because applications may wish to have empty values (since Cassandra does allow you to do so)

…ing queries

This allows a pre-mediated value to stand in when generating queries for
systems (like Keyspaces) that don't support having empty clustering
columns
kjgorman
kjgorman previously approved these changes Sep 9, 2021
Copy link

@kjgorman kjgorman left a comment

Choose a reason for hiding this comment

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

Pretty gruesome stuff overall but looks like it ought to work... a few minor questions and maybe some naming bike-shedding but nothing really blocking.

switch {
case val.Kind() == reflect.String:
if val.String() == ClusteringSentinel {
return true, reflect.New(val.Type()).Elem().Interface()
Copy link

Choose a reason for hiding this comment

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

is there a scenario where reflect.New(val.Type()).Elem().Interface() will not just be "" here? could we just return that?

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 initially had that but we need to consider if you have a type alias for which that doesn't work

}

elem := reflect.ValueOf(ptr).Elem()
if isSentinel, nonSentinelValue := isClusteringSentinelValue(elem.Interface()); isSentinel {
Copy link

Choose a reason for hiding this comment

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

to what degree (if any) should we be thinking about potential performance regressions by adding an extra step of reflection/value comparison for every field pointer now, do 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.

We can benchmark this using the existing benchmarks

Before:

goos: darwin
goarch: amd64
pkg: github.com/monzo/gocassa
cpu: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
BenchmarkDecodeBlogSliceNoBody
BenchmarkDecodeBlogSliceNoBody-8       	   29456	     34640 ns/op
BenchmarkDecodeBlogStruct
BenchmarkDecodeBlogStruct-8            	  578539	      1841 ns/op
BenchmarkDecodeBlogStructEmptyBody
BenchmarkDecodeBlogStructEmptyBody-8   	  649267	      1840 ns/op
BenchmarkDecodeAlphaSlice
BenchmarkDecodeAlphaSlice-8            	   10000	    101197 ns/op
BenchmarkDecodeAlphaStruct
BenchmarkDecodeAlphaStruct-8           	  236494	      4842 ns/op
BenchmarkStatementMapTable
BenchmarkStatementMapTable-8           	  412954	      2773 ns/op	    3664 B/op	      33 allocs/op
PASS
ok  	github.com/monzo/gocassa	7.574s

After:

goos: darwin
goarch: amd64
pkg: github.com/monzo/gocassa
cpu: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
BenchmarkDecodeBlogSliceNoBody
BenchmarkDecodeBlogSliceNoBody-8       	   31040	     39350 ns/op
BenchmarkDecodeBlogStruct
BenchmarkDecodeBlogStruct-8            	  538323	      2429 ns/op
BenchmarkDecodeBlogStructEmptyBody
BenchmarkDecodeBlogStructEmptyBody-8   	  524773	      2916 ns/op
BenchmarkDecodeAlphaSlice
BenchmarkDecodeAlphaSlice-8            	    8732	    133401 ns/op
BenchmarkDecodeAlphaStruct
BenchmarkDecodeAlphaStruct-8           	  181543	      6072 ns/op
BenchmarkStatementMapTable
BenchmarkStatementMapTable-8           	  432660	      2886 ns/op	    3728 B/op	      33 allocs/op
PASS
ok  	github.com/monzo/gocassa	9.648s

I think we can probably optimise this codepath a bit more (the before is quite optimised since #68)

statement.go Show resolved Hide resolved
@leesio leesio merged commit 3c7568d into master Sep 20, 2021
@leesio leesio deleted the gocassa-clustering-sentinal branch September 20, 2021 09:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants