-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
implementing quarter()
function
#2258
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f2928bd
implementing quarter
8362774
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor 5ab44bd
more test
29991fa
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor 9745502
Merge branch 'main' into james/quarter
dc3187d
test
7be69d5
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor 34e84af
return nil for bad dates, and fix bad test
8413637
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor c33ebc5
fixing unit tests
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 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 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 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 |
---|---|---|
|
@@ -92,6 +92,127 @@ func TestTime_Month(t *testing.T) { | |
} | ||
} | ||
|
||
func TestTime_Quarter(t *testing.T) { | ||
ctx := sql.NewEmptyContext() | ||
f := NewQuarter(expression.NewGetField(0, types.LongText, "foo", false)) | ||
|
||
testCases := []struct { | ||
name string | ||
row sql.Row | ||
expected interface{} | ||
err bool | ||
}{ | ||
{ | ||
name: "null date", | ||
row: sql.NewRow(nil), | ||
expected: nil, | ||
}, | ||
{ | ||
name: "1", | ||
row: sql.NewRow(1), | ||
expected: int32(1), | ||
}, | ||
{ | ||
name: "1.1", | ||
row: sql.NewRow(1.1), | ||
expected: int32(1), | ||
}, | ||
{ | ||
name: "invalid type", | ||
row: sql.NewRow([]byte{0, 1, 2}), | ||
expected: int32(1), | ||
}, | ||
{ | ||
name: "date as string", | ||
row: sql.NewRow(stringDate), | ||
expected: int32(1), | ||
}, | ||
{ | ||
name: "another date as string", | ||
row: sql.NewRow("2008-08-01"), | ||
expected: int32(3), | ||
}, | ||
{ | ||
name: "january", | ||
row: sql.NewRow("2008-01-01"), | ||
expected: int32(1), | ||
}, | ||
{ | ||
name: "february", | ||
row: sql.NewRow("2008-02-01"), | ||
expected: int32(1), | ||
}, | ||
{ | ||
name: "march", | ||
row: sql.NewRow("2008-03-01"), | ||
expected: int32(1), | ||
}, | ||
{ | ||
name: "april", | ||
row: sql.NewRow("2008-04-01"), | ||
expected: int32(2), | ||
}, | ||
{ | ||
name: "may", | ||
row: sql.NewRow("2008-05-01"), | ||
expected: int32(2), | ||
}, | ||
{ | ||
name: "june", | ||
row: sql.NewRow("2008-06-01"), | ||
expected: int32(2), | ||
}, | ||
{ | ||
name: "july", | ||
row: sql.NewRow("2008-07-01"), | ||
expected: int32(3), | ||
}, | ||
{ | ||
name: "august", | ||
row: sql.NewRow("2008-08-01"), | ||
expected: int32(3), | ||
}, | ||
{ | ||
name: "septemeber", | ||
row: sql.NewRow("2008-09-01"), | ||
expected: int32(3), | ||
}, | ||
{ | ||
name: "october", | ||
row: sql.NewRow("2008-10-01"), | ||
expected: int32(4), | ||
}, | ||
{ | ||
name: "november", | ||
row: sql.NewRow("2008-11-01"), | ||
expected: int32(4), | ||
}, | ||
{ | ||
name: "december", | ||
row: sql.NewRow("2008-12-01"), | ||
expected: int32(4), | ||
}, | ||
{ | ||
name: "date as time", | ||
row: sql.NewRow(time.Now()), | ||
expected: int32(time.Now().UTC().Month()), | ||
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. Seems like this test will only pass in the month of January? 🤔 |
||
}, | ||
} | ||
|
||
for _, tt := range testCases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
require := require.New(t) | ||
val, err := f.Eval(ctx, tt.row) | ||
if tt.err { | ||
require.Error(err) | ||
} else { | ||
require.NoError(err) | ||
require.Equal(tt.expected, val) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestTime_Day(t *testing.T) { | ||
ctx := sql.NewEmptyContext() | ||
f := NewDay(expression.NewGetField(0, types.LongText, "foo", false)) | ||
|
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.
Seems like all of these should return
NULL
, right?Here's the MySQL behavior: