Skip to content
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

feat(type): add support for type PrecisionTimestamp and PrecisionTimestampTz #41

Merged

Conversation

anshuldata
Copy link
Contributor

  • Introduced type "PrecisionTimeStampType" and "PrecisionTimeStampTzType" which implements Type interface
  • Support for Literal expression using PrecisionTimestamp and PrecisionTimestampTz
  • Fixed "ProtoLiteral" ToProtoLiteral API to switch on type instead of value. Felt this is cleaner and extensible since converting based on type. Used "ProtoLiteral" to create Literal interface for PrecisionTimestamp and PrecisionTimestampTz

…stampTz

* Support for Literal expression using these types
Copy link

codecov bot commented Aug 7, 2024

Codecov Report

Attention: Patch coverage is 78.40000% with 27 lines in your changes missing coverage. Please review.

Project coverage is 47.31%. Comparing base (0ea5482) to head (d6f0560).

Files Patch % Lines
expr/literals.go 58.33% 21 Missing and 4 partials ⚠️
types/precison_timestamp_types.go 96.92% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
+ Coverage   46.38%   47.31%   +0.92%     
==========================================
  Files          15       16       +1     
  Lines        5553     5664     +111     
==========================================
+ Hits         2576     2680     +104     
- Misses       2809     2812       +3     
- Partials      168      172       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jacques-n jacques-n left a comment

Choose a reason for hiding this comment

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

It looks like a bunch of the code you introduced doesn't have test cases

Can you resolve that as well as the other comments? We should at least have test cases for the production paths (even if we don't for things like String() and weird error conditions)

go.mod Outdated
@@ -6,23 +6,29 @@ go 1.20

require (
github.com/alecthomas/participle/v2 v2.0.0
github.com/cockroachdb/errors v1.11.3
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think it makes sense to source the cockroachdb errors package for a test. Let's revert the go.mod/go.sum changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a utility library which has useful function to construct meaningful error. So good to keep it

Copy link
Contributor

Choose a reason for hiding this comment

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

how is it different than just using fmt.Errorf instead? I agree with @jacques-n that I don't see the benefit in the cockroachdb errors package. What functionality is it providing that we can't already get from errors.New and fmt.Errorf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I felt instead of using some methods from fmt and some from standard "errors". It is good to use one library. This cockroach library has much richer APIs (e.g. adding Hint to errors) too. Hence I used it so that we can use a single lib for errors and augment errors to be more informative
Though, for this task I could use existing fmt.Errorf. So I reverted back to fmt instead of using cockroach/errors. I still feel this API will be useful to report more meaningful error. I will reintroduce in future when I use APIs of this lib which aren't available in standard package

expr/literals.go Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
@anshuldata anshuldata force-pushed the anshul/AddPrecisionTimeStampLiteral branch from 32156e3 to ad153da Compare August 8, 2024 13:00
@anshuldata
Copy link
Contributor Author

We should at least have test cases for the production paths (even if we don't for things like String() and weird error conditions)

Added unit tests for below parts

  1. Creation of PrecisionTimeStamp and PrecisionTimeStampTz type
  2. Conversion to proto from both types
  3. Conversion from proto for both types

I found a bug too in my code because of above. Thanks

@anshuldata
Copy link
Contributor Author

We will add tests for other types (existing ones) as part of #33

Copy link
Contributor

@zeroshade zeroshade left a comment

Choose a reason for hiding this comment

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

A few nitpicks

@@ -7,13 +7,13 @@ package expr
import (
"bytes"
"fmt"
"google.golang.org/protobuf/types/known/anypb"
Copy link
Contributor

Choose a reason for hiding this comment

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

why did this import move? Can we please put it back in the import list with the rest of the imports that are not stdlib imports?

Copy link
Contributor

Choose a reason for hiding this comment

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

as elsewhere, -1 on review comments around import order. If we want a specific order, add as precommit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it should be fixed by pre-commit. I will add a pre-commit action to detect imports in future PR

expr/literals.go Outdated Show resolved Hide resolved
go.mod Outdated
@@ -6,23 +6,29 @@ go 1.20

require (
github.com/alecthomas/participle/v2 v2.0.0
github.com/cockroachdb/errors v1.11.3
Copy link
Contributor

Choose a reason for hiding this comment

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

how is it different than just using fmt.Errorf instead? I agree with @jacques-n that I don't see the benefit in the cockroachdb errors package. What functionality is it providing that we can't already get from errors.New and fmt.Errorf?

types/precison_timestamp_types.go Outdated Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
types/precison_timestamp_types.go Show resolved Hide resolved
types/precison_timestamp_types.go Show resolved Hide resolved
@@ -7,13 +7,13 @@ package expr
import (
"bytes"
"fmt"
"google.golang.org/protobuf/types/known/anypb"
Copy link
Contributor

Choose a reason for hiding this comment

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

as elsewhere, -1 on review comments around import order. If we want a specific order, add as precommit tests.

types/precison_timestamp_types.go Outdated Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
@jacques-n
Copy link
Contributor

Note that your patch only appears to have 34% code coverage. We should strive for patches to meet or exceed existing coverage.

@anshuldata anshuldata force-pushed the anshul/AddPrecisionTimeStampLiteral branch from 3a9d814 to e24f72b Compare August 9, 2024 06:35
@anshuldata
Copy link
Contributor Author

Note that your patch only appears to have 34% code coverage. We should strive for patches to meet or exceed existing coverage.

Fixed it by adding more tests which covers code which was missing coverage.

@anshuldata anshuldata force-pushed the anshul/AddPrecisionTimeStampLiteral branch from e24f72b to 799211f Compare August 9, 2024 06:58
@anshuldata
Copy link
Contributor Author

how is it different than just using fmt.Errorf instead? I agree with @jacques-n that I don't see the benefit in the cockroachdb errors package. What functionality is it providing that we can't already get from errors.New and fmt.Errorf?

Replied in this comment

Copy link
Contributor

@zeroshade zeroshade left a comment

Choose a reason for hiding this comment

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

Just a few other nitpicks, everything else looks good to me besides agreeing with @jacques-n that we should raise the test coverage

types/precison_timestamp_types.go Show resolved Hide resolved
types/precison_timestamp_types.go Outdated Show resolved Hide resolved
@anshuldata
Copy link
Contributor Author

anshuldata commented Aug 9, 2024

we should raise the test coverage

I did fix it with last commit and now coverage for type change is around 97%.
For literal it covers mostly PreisionTimeStamp/Tz test cases. For other literals, it should get increased by #33 . It is showing up in my PR because I modified function func (t *ProtoLiteral) ToProtoLiteral() and it has other types too

@anshuldata
Copy link
Contributor Author

anshuldata commented Aug 9, 2024

Can you merge this @zeroshade ? I don't have write permission

Thanks

Copy link
Contributor

@jacques-n jacques-n left a comment

Choose a reason for hiding this comment

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

Looks good. Test coverage is well above codebase. Thanks @anshuldata

@jacques-n jacques-n merged commit 5040d09 into substrait-io:main Aug 10, 2024
7 checks passed
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.

3 participants