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
DM-30124: Use native timestamp comparison for ingest_date #544
Conversation
94e3e8d
to
feb8722
Compare
dt = value.to_datetime() | ||
return ScalarWhereClauseConverter.fromLiteral(dt) | ||
else: | ||
return ScalarWhereClauseConverter.fromLiteral(value) |
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.
I think the approach you've taken here is fine, but I'll mention another one here in case you like it better:
- Make a new
TimeLiteralWhereClauseConverter
subclass for time literals that only stores thestr
from the expression, and does not coerce it to eitherastropy.time.Time
, but still declares itsdtype
to beastropy.time.Time
. - Remove
Time
from theregisterBinary
calls for other comparison operators, and instead registerTime
-only ones that delegate to a func that coerces those literals according to the other operand.
I think that generalizes better to other kinds of context-dependent coercion, though of course it'd be nice if we didn't need any more of that.
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.
@TallJimbo, thanks for suggestion! I have decided to simplify things based on that idea and remove two-pass tree analysis in favor of doing what you suggest based on type of operands in comparison operators. This greatly simplifies the whole thing but with a caveat of not supporting some complex expressions of a kind ingest_date < MAX(time_literal1, time_literal2)
but we do not currently support this syntax anyways. I think we'll be OK with this for now, and if we need to extend our language support for more complex expressions we'll need to rethink how the whole conversion works (or do something with Time/datetime duality).
One thing that I noticed is that we do not handle timestamps in IN
operator, even though documentation says it should work. I'll open a new ticket for that.
Could you look at it once again, should be shorter commit this time.
8030f0a
to
93e94df
Compare
Can we have a test where we put a dataset and then use ingest date in a queryDatasets call constrained to the now and 10 seconds in the past. If everything works we will get the dataset back, if we have the 37s offset we won't. Also check that this works with |
@timj, I'll try to make this sort of test, need to remember how to make a working registry for this test. |
@andy-slac I think you can probably add it in test_butler.py immediately after one of the butler.put calls in there. |
Looks like registry test class already has a |
None of those tests do a |
I think we always use current timestamp in UTC for ingest_date, |
Do not convert ingest_date to nanoseconds, instead use native time functions for all operations. This requires some time literals to be converted from astropy Time to datetime. The change implies that we cannot use ingest_date with other TAI-based timestamp columns in the same sub-expression. If we need that feature then ingest_date needs to be migrated to TAI nanoseconds.
93e94df
to
02a617a
Compare
I have extended unit test for ingest date but now have to run it in Postgres which means that I have to recall how to build everything on my desktop. |
I'm pretty sure the github action runs the postgres unittests. |
Indeed, even better. Tests are all successful. |
Co-authored-by: Jim Bosch <jbosch@astro.princeton.edu>
Do not convert ingest_date to nanoseconds, instead use native time
functions for all operations. This requires some time literals to be
converted from astropy Time to datetime. The change implies that we
cannot use ingest_date with other TAI-based timestamp columns in the
same sub-expression. If we need that feature then ingest_date needs to
be migrated to TAI nanoseconds.
Checklist
doc/changes