-
Notifications
You must be signed in to change notification settings - Fork 14
CQL Function Handling #176
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
Draft
brandtnewton
wants to merge
4
commits into
GoogleCloudPlatform:main
Choose a base branch
from
brandtnewton:proxy/function-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/global/types/cql_func_avg.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package types | ||
|
|
||
| type FuncAvg struct { | ||
| } | ||
|
|
||
| func (f *FuncAvg) GetValidClauses() []QueryClause { | ||
| return []QueryClause{QueryClauseSelect} | ||
| } | ||
|
|
||
| func (f *FuncAvg) GetName() string { | ||
| return "avg" | ||
| } | ||
|
|
||
| func (f *FuncAvg) GetCode() CqlFuncCode { | ||
| return FuncCodeAvg | ||
| } | ||
|
|
||
| func (f *FuncAvg) GetParameterTypes() []CqlFuncParameter { | ||
| return []CqlFuncParameter{ | ||
| *NewCqlFuncParameter(AllNumericTypes, true, false), | ||
| } | ||
| } | ||
|
|
||
| func (f *FuncAvg) Apply(_ []DynamicValue, value *QueryParameterValues) (GoValue, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (f *FuncAvg) GetReturnType(args []DynamicValue) CqlDataType { | ||
| if len(args) != 1 { | ||
| return TypeDouble | ||
| } | ||
| dt := args[0].GetType() | ||
| if dt.Code() == INT || dt.Code() == BIGINT { | ||
| return TypeFloat | ||
| } | ||
| return dt | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/global/types/cql_func_count.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package types | ||
|
|
||
| type FuncCount struct { | ||
| } | ||
|
|
||
| func (f *FuncCount) GetValidClauses() []QueryClause { | ||
| return []QueryClause{QueryClauseSelect} | ||
| } | ||
|
|
||
| func (f *FuncCount) GetName() string { | ||
| return "count" | ||
| } | ||
|
|
||
| func (f *FuncCount) GetCode() CqlFuncCode { | ||
| return FuncCodeCount | ||
| } | ||
|
|
||
| func (f *FuncCount) GetParameterTypes() []CqlFuncParameter { | ||
| return []CqlFuncParameter{ | ||
| *NewCqlFuncParameter(AllScalarTypes, true, true), | ||
| } | ||
| } | ||
|
|
||
| func (f *FuncCount) Apply(_ []DynamicValue, _ *QueryParameterValues) (GoValue, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (f *FuncCount) GetReturnType(_ []DynamicValue) CqlDataType { | ||
| return TypeBigInt | ||
| } |
33 changes: 33 additions & 0 deletions
33
cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/global/types/cql_func_max.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package types | ||
|
|
||
| type FuncMax struct { | ||
| } | ||
|
|
||
| func (f *FuncMax) GetValidClauses() []QueryClause { | ||
| return []QueryClause{QueryClauseSelect} | ||
| } | ||
|
|
||
| func (f *FuncMax) GetName() string { | ||
| return "max" | ||
| } | ||
|
|
||
| func (f *FuncMax) GetCode() CqlFuncCode { | ||
| return FuncCodeMax | ||
| } | ||
|
|
||
| func (f *FuncMax) GetParameterTypes() []CqlFuncParameter { | ||
| return []CqlFuncParameter{ | ||
| *NewCqlFuncParameter(AllNumericTypes, true, false), | ||
| } | ||
| } | ||
|
|
||
| func (f *FuncMax) Apply(_ []DynamicValue, value *QueryParameterValues) (GoValue, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (f *FuncMax) GetReturnType(args []DynamicValue) CqlDataType { | ||
| if len(args) != 1 { | ||
| return TypeDouble | ||
| } | ||
| return args[0].GetType() | ||
| } |
74 changes: 74 additions & 0 deletions
74
...a-bigtable-migration-tools/cassandra-bigtable-proxy/global/types/cql_func_max_timeuuid.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package types | ||
|
|
||
| import ( | ||
| "github.com/google/uuid" | ||
| "time" | ||
| ) | ||
|
|
||
| type FuncMaxTimeuuid struct { | ||
| } | ||
|
|
||
| func (f *FuncMaxTimeuuid) GetValidClauses() []QueryClause { | ||
| return []QueryClause{QueryClauseWhere, QueryClauseValues} | ||
| } | ||
|
|
||
| func (f *FuncMaxTimeuuid) GetName() string { | ||
| return "maxTimeuuid" | ||
| } | ||
|
|
||
| func (f *FuncMaxTimeuuid) GetCode() CqlFuncCode { | ||
| return FuncCodeMaxTimeuuid | ||
| } | ||
|
|
||
| func (f *FuncMaxTimeuuid) GetParameterTypes() []CqlFuncParameter { | ||
| return []CqlFuncParameter{ | ||
| *NewCqlFuncParameter( | ||
| []CqlDataType{ | ||
| TypeTimestamp, | ||
| }, | ||
| false, | ||
| false), | ||
| } | ||
| } | ||
|
|
||
| func (f *FuncMaxTimeuuid) Apply(args []DynamicValue, values *QueryParameterValues) (GoValue, error) { | ||
| u, err := getTimeArg(0, args, values) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return maxUUIDv1ForTime(u) | ||
| } | ||
|
|
||
| func (f *FuncMaxTimeuuid) GetReturnType(args []DynamicValue) CqlDataType { | ||
| return TypeTimeuuid | ||
| } | ||
|
|
||
| // maxUUIDv1ForTime creates the maximum possible UUIDv1 for a given time.Time. | ||
| // This is achieved by setting the timestamp fields based on the input time, | ||
| // and setting the Clock Sequence and Node ID fields to their maximum values. | ||
| func maxUUIDv1ForTime(t time.Time) (uuid.UUID, error) { | ||
| // For maxTimeuuid, Cassandra adds 9999 to the 100-nanosecond intervals timestamp. | ||
| // 9999 * 100 nanoseconds. | ||
| maxT := t.Add(9999 * 100 * time.Nanosecond) | ||
| u := setUuidV1Time(maxT, [16]byte{}) | ||
|
|
||
| // --- Clock Sequence & Node ID Fields (Maxed Values) --- | ||
| // clock_seq_hi_and_variant (byte 8, 8 bits) | ||
| // The variant bits must be 10 (0x80 to 0xBF). We set the clock sequence to max. | ||
| // 0xBF is 0b10111111 (variant 10 and max 6 bits for the clock sequence high part) | ||
| u[8] = 0xBF | ||
|
|
||
| // clock_seq_low (byte 9, 8 bits) | ||
| u[9] = 0xFF | ||
|
|
||
| // Node ID (bytes 10-15, 48 bits) - set to all F's (max) | ||
| u[10] = 0xFF | ||
| u[11] = 0xFF | ||
| u[12] = 0xFF | ||
| u[13] = 0xFF | ||
| u[14] = 0xFF | ||
| u[15] = 0xFF | ||
|
|
||
| // Create the UUID from the byte array | ||
| return u, nil | ||
| } |
33 changes: 33 additions & 0 deletions
33
cassandra-bigtable-migration-tools/cassandra-bigtable-proxy/global/types/cql_func_min.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package types | ||
|
|
||
| type FuncMin struct { | ||
| } | ||
|
|
||
| func (f *FuncMin) GetValidClauses() []QueryClause { | ||
| return []QueryClause{QueryClauseSelect} | ||
| } | ||
|
|
||
| func (f *FuncMin) GetName() string { | ||
| return "min" | ||
| } | ||
|
|
||
| func (f *FuncMin) GetCode() CqlFuncCode { | ||
| return FuncCodeMin | ||
| } | ||
|
|
||
| func (f *FuncMin) GetParameterTypes() []CqlFuncParameter { | ||
| return []CqlFuncParameter{ | ||
| *NewCqlFuncParameter(AllNumericTypes, true, false), | ||
| } | ||
| } | ||
|
|
||
| func (f *FuncMin) Apply(_ []DynamicValue, value *QueryParameterValues) (GoValue, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (f *FuncMin) GetReturnType(args []DynamicValue) CqlDataType { | ||
| if len(args) != 1 { | ||
| return TypeDouble | ||
| } | ||
| return args[0].GetType() | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Cassandra documentation, the
avgfunction onintorbigintcolumns returns avarint. This implementation returnsTypeFloat. While this might be a deliberate simplification, it deviates from the standard Cassandra behavior. Consider returningTypeVarintfor better compatibility.