Skip to content

Conversation

@vfrank66
Copy link
Contributor

No description provided.

}),
},
{
name: "Collapse empty list",
Copy link
Contributor

Choose a reason for hiding this comment

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

This test name is wrong, technically this is null, an empty list would be {} as ...

We would probably want tests for both though :)

}),
},
StaticType: &types.List{ElementType: &types.Interval{PointType: types.Integer}},
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some tests for cases that shouldn't be collapsed, both with closed and open intervals?

}),
},
{
name: "Original failing case - sorted order",
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you already have this case on line 2164 consider removing.

"Union",
},
NamesExcludes: []string{
"TestCollapseNull",
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, what error were you getting for this test?

}
}

if len(nonNullIntervals) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also return early here if the length is 1.

}

// Sort temporal intervals by start time
sort.Slice(nonNullIntervals, func(i, j int) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you use the helper function you added above for this?

}

// sortIntervals sorts a list of intervals by their start time
func sortIntervals(intervals []result.Value, evaluationTimestamp time.Time) ([]result.Value, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like where this function is going but I have a few thoughts.

  1. I think sortIntervalsByStartTime would be a more apt name here.
  2. What do you think of using generics here similar to
    func arithmetic[t float64 | int64 | int32](m model.IBinaryExpression, l, r t) (result.Value, error) {

    since sorting for time based values and numerals are such different operations it may make sense to split the two implementations out in this way.

}

// Sort numeric intervals by start value
sort.Slice(nonNullIntervals, func(i, j int) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

same feedback as the above function i think you can reuse your helper here

}
}

func TestCollapse(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think some of the logic for null values like Interval[null, 5] or Interval(null, 5] might not be handled correctly, at least the canMerge functions seem to be marking them all as false for their ability to merge. Mind adding some test cases likecollapse { Inverval[null, 5], Interval[1, 2] } as well as collapse { Inverval(null, 5], Interval[1, 2] } and collapse { Inverval[null, 5], Interval[4, 6] }? I'd feel better about this code knowing those do what I expect :)

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.

2 participants