-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Implement TIME
type in the backend
#628
Conversation
I'm curious how much we care about what type the API returns. Intuitively, I would guess that consistently returning |
@eito-fis I'm in favor of going with the simpler implementation. Please update the type mapping files in |
@mathemancer Is there a reason we use Happy to change the implementation of the current TIME types if there is a better way to go about this. |
Using separate types for {
"time with time zone": db.types.datetime.TIME_WITH_TIME_ZONE,
"time without time zone": db.types.datetime.TIME_WITHOUT_TIME_ZONE,
"time": db.types.datetime.TIME,
} Reflection is going to be a pain with that setup, but it solves a number of other issues. (See As for why those functions are used differently, the intent of |
This should be in an about functional place - the last question is about inference. In particular, both
Any thoughts on which would be preferred? |
@eito-fis I think it's fine to infer |
@kgodey I could take a shot at properly converting with timezone to without timezone, but I think it produces some un-intuitive behavior. The postgres documentation has a bit on this, but I think the core issue is about what happens when timezone causes the day to roll over. I guess it seems a bit hard to handle without date information. (In fact, re-reading the documentation, I wonder if its worth doing time with timezone at all?) |
@eito-fis After reading the Postgres docs, I think it's better to infer as Please make sure to document the reasoning for this in a comment somewhere so we have the context. |
@silentninja I added you as a reviewer here since you're working on |
It would be better if custom renders are listed explicitly as it is meant for rendering data from the user database. If we make it a default It would unnecessarily end up interfering with Mathesar related data(like datafile model, display_options) if we do end up extending the renderer in the future |
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.
Looks good to me, creating individual time types seems to be much better and flexible.
@@ -36,6 +37,9 @@ | |||
NUMERIC = PostgresType.NUMERIC.value.upper() | |||
REAL = PostgresType.REAL.value.upper() | |||
SMALLINT = PostgresType.SMALLINT.value.upper() | |||
DATE = PostgresType.DATE.value.upper() |
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.
Date constant has already been initialized at line 31. The types are arranged alphabetically, so this Date constant should be removed
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.
Looks good. I don't know this code area as well as some of the others, so I'll refrain from giving explicit approval.
I moved the status back to |
WITHOUT_TIME_ZONE_DB_TYPE = base.PostgresType.TIME_WITHOUT_TIME_ZONE.value | ||
|
||
|
||
class TIME_WITHOUT_TIME_ZONE(SA_TIME): |
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.
Converting the class to a string still returns Time
rather than TIME WITHOUT TIME ZONE
. The str
representation method should be overridden to return the appropriate value
super().__init__(*args, timezone=False, precision=precision, **kwargs) | ||
|
||
|
||
class TIME_WITH_TIME_ZONE(SA_TIME): |
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.
Converting the class to a string still returns Time
rather than TIME WITH TIME ZONE
. The str
representation method should be overridden to return the appropriate value
I think as-is is fine. |
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.
Okay, I've made a couple of minor changes as requested by @silentninja , and everything else looks good to me.
The |
Thank @mathemancer and @eito-fis |
Fixes #426
Implements the
TIME
type in the backend, with options for precision and timezone.Technical details
Some oddities due to how sqlalchemy handles
TIME
. In particular, it will compile using thetimezone
andprecision
attributes, but won't take them in at initialization time. As a result, we have use two additional custom types,TIME_WITH_TIMEZONE
andTIME_WITHOUT_TIMEZONE
, that simply extend the init method to taketimezone
andprecision
.Additional notes:
TIME_WITH_TIMEZONE
andTIME_WITHOUT_TIMEZONE
- justTIME
is not supported.TIME
has been removed from the type map to reflect this.time
object the data is reflected as doesn't really support precision. It hasmillisecond
, which is equivalent to a precision of 1, but no more. As a result, currently settings precision as anything valid but greater than 1 is the same as setting a precision of 1. (I believe this is why sqlalchemy doesn't support precision.)TIME_WITH_TIMEZONE
is not supported asTIME_WITH_TIMEZONE
is primarily intended to be used as support for legacy databases. See postgres documentation for details.Checklist
Update index.md
).master
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin