Skip to content

Support times better#64

Merged
losipiuk merged 1 commit intotrinodb:masterfrom
JPMoresmau:jp/support_times_better
Jan 4, 2023
Merged

Support times better#64
losipiuk merged 1 commit intotrinodb:masterfrom
JPMoresmau:jp/support_times_better

Conversation

@JPMoresmau
Copy link
Copy Markdown
Member

Add support for full precision of subseconds, so PARAMETRIC_DATETIME works properly.

Add type wrappers in the manner of Numeric for the various date/time data types, so we can avoid casts and not leak the accepted formats to the client.

Copy link
Copy Markdown
Member

@nineinchnick nineinchnick left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on this. I did the first pass and expect at least one more round of reviews, but probably it'll take a while.

Comment thread trino/serial.go Outdated
Comment thread trino/serial_test.go Outdated
Comment thread trino/serial.go Outdated
Comment thread trino/trino_test.go Outdated
Comment thread trino/trino_test.go
columns, err := rows.Columns()
require.NoError(t, err, "Failed reading result columns")

assert.Equal(t, 4, len(columns), "Expected 4 result column")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this necessary? Wouldn't assert.Equal called on a slice verify this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I just copied the test code from another test :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We build another slice later on using that length, so I guess it's safer to verify it...

Comment thread trino/trino_test.go
Comment thread trino/trino_test.go Outdated
Comment thread trino/trino_test.go
Comment thread trino/trino.go Outdated
@nineinchnick
Copy link
Copy Markdown
Member

Looks like this would resolve #13

@JPMoresmau JPMoresmau force-pushed the jp/support_times_better branch from fa65ac0 to bbda22a Compare December 27, 2022 14:21
Copy link
Copy Markdown
Member

@nineinchnick nineinchnick 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 nitpicks, almost there!

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread trino/serial.go Outdated
Comment thread trino/serial.go
Comment thread trino/serial.go
Comment thread trino/serial.go Outdated
Comment thread trino/trino.go Outdated
Comment thread trino/serial_test.go Outdated
Comment thread trino/trino_test.go Outdated
@JPMoresmau
Copy link
Copy Markdown
Member Author

@nineinchnick I think I've merged your suggestions and addressed your comments, let me know. I suppose i can squash the commits once you're fine with my latest changes...

Copy link
Copy Markdown
Member

@nineinchnick nineinchnick left a comment

Choose a reason for hiding this comment

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

Thanks for bearing with me. This is the last round from me. LGTM % these nitpicks.

I'm not a maintainer, so we need @hashhar and/or @losipiuk to do the review now. You could squash commits to make reviewing easier for them.

Comment thread trino/serial.go Outdated
Comment thread trino/serial.go Outdated
Comment thread trino/serial.go Outdated
Comment thread trino/serial.go
Comment thread trino/trino_test.go Outdated
with specific functions to create Trino data types explicitly.
@JPMoresmau JPMoresmau force-pushed the jp/support_times_better branch from 95331a8 to d8b108f Compare January 2, 2023 12:39
Comment thread README.md
When reading response rows, the driver supports most Trino data types, except:
* time and timestamps with precision - all time types are returned as `time.Time`
* time and timestamps with precision - all time types are returned as `time.Time`.
All precisions up to nanoseconds (`TIMESTAMP(9)` or `TIME(9)`) are supported (since
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why exactly are we constraining ourselve to nanosecond precision? Would it be possible to support up to TIME*(12)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because Go's time.Time only supports nanoseconds. To support picoseconds, we'd have to define a custom data type. I'm not sure how much work it would be to make it compatible with time.Time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Recent work in the Python client in trinodb/trino-python-client#300 is also limited but to microseconds.

Comment thread trino/serial.go
// Timestamp indicates we want a TimeStamp type WITHOUT a time zone in Trino from a Golang time.
type trinoTimestamp time.Time

// Timestamp creates a representation of a Trino Timestamp(9) type.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

those comments are not really useful? @nineinchnick do we have check which enforces those?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't currently have a linter in the CI that would check for this. The built-in go vet doesn't, we'd have to use staticcheck (recommended after go lint was deprecated) or golangci-lint (which is huge but popular).

Having comments for all exported functions is idiomatic in Go and it would show up in online docs like here: https://pkg.go.dev/github.com/trinodb/trino-go-client@v0.308.0/trino

What would it take to make them more useful? Should it explain why time.Time is not used instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What would it take to make them more useful

Not sure. Presonally I would just drop it. But if we want to follow Go guildelines let's go with it :)

@JPMoresmau
Copy link
Copy Markdown
Member Author

Sorry, is anything more needed from me to get that PR approved?

@losipiuk losipiuk merged commit e7589ed into trinodb:master Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants