-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
[Windowing] Handle null values in partitions #141
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -274,6 +274,9 @@ type WindowFuncStatus struct { | |||||||||||||
OrderBy []*WindowOrderBy | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// windowNilPartitionValue Placeholder value for nil | ||||||||||||||
const windowNilPartitionValue = StringValue("^^^ZETASQLITE_NIL^^^") | ||||||||||||||
|
||||||||||||||
func (s *WindowFuncStatus) Partition() (string, error) { | ||||||||||||||
partitions := make([]string, 0, len(s.Partitions)) | ||||||||||||||
for _, p := range s.Partitions { | ||||||||||||||
|
@@ -314,7 +317,11 @@ func parseWindowOptions(args ...Value) ([]Value, *WindowFuncStatus, error) { | |||||||||||||
case WindowFuncOptionEnd: | ||||||||||||||
opt.End = v.Value.(*WindowBoundary) | ||||||||||||||
case WindowFuncOptionPartition: | ||||||||||||||
opt.Partitions = append(opt.Partitions, v.Value.(Value)) | ||||||||||||||
if v.Value != nil { | ||||||||||||||
opt.Partitions = append(opt.Partitions, v.Value.(Value)) | ||||||||||||||
} else { | ||||||||||||||
opt.Partitions = append(opt.Partitions, windowNilPartitionValue) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would The intention is that windowed rows that share common WITH toks as (
SELECT 'a' as prop1, null as prop2, 'aa' as prop3
UNION ALL SELECT 'a' as prop1, 'aa' as prop2, null as prop3
)
SELECT prop1, ROW_NUMBER() over (PARTITION BY prop2, prop3) AS rn FROM toks Expected:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A guard expression against nil must be inserted before the join process.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the query above, wouldn't that result in the following?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. Then it looks like we should add constant Example.
type NullValue struct {
zeroValue Value
}
&NullValue{zeroValue: IntValue(0)} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try to do this as I think it is the right approach, too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you !! Generics seems to be a better choice. 😃 type NullValue[T Value] struct {
zeroValue T
} |
||||||||||||||
} | ||||||||||||||
case WindowFuncOptionRowID: | ||||||||||||||
opt.RowID = v.Value.(int64) | ||||||||||||||
case WindowFuncOptionOrderBy: | ||||||||||||||
|
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.
@goccy While exploring other issues, it seems this case comes up often.
Does it make sense to introduce a new
NilValue
class instead?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.
NULL
is not the first class's value. So I want to deal with this by handling null properly.