-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Immutable casting of string > timestamp #60578
Comments
Hello, I am Blathers. I am here to help you get the issue triaged. It looks like you have not filled out the issue in the format of any of our templates. To best assist you, we advise you to use one of these templates. I have CC'd a few people who may be able to assist you:
If we have not gotten back to your issue within a few business days, you can try the following:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
CC @otan Sorry for the apparent regression, unfortunately these changes were necessary to ensure correctness in all cases. I am pretty sure we had an example for 1 where the result was different (it was surprising to me too). I can try to dig it out. With 2 the problem is that unfortunately things like 'now', 'tomorrow' can be cast to timestamps.. When the string is a constant literal, we make a best effort to determine if we're in one of these cases. But we can't do anything for variable inputs. I see two options: stop supporting 'now' etc when they are not constants (though this is fragile, as what is constant sometimes depends on how smart the optimizer is; and might break other uses). Or, add a special function to convert strings to timestamp which only supports absolute values. |
Also, I don't know if it's possible in your usecase, but consider using non-computed columns with default values instead. |
Here's an example for 1, with postgres:
|
Woah!!!
I see now that, indeed, "a day" is a localized interval! In some moments in time, in some places, a day is less than 24 hours. Fair enough! As for 2 - Hrm, yes if "now" can be cast into a timestamp, then indeed, I see that A pure function that casts strings into timestamps sounds like a totally reasonable thing to exist, to be honest! It would logically be very simple and maintainable and would be a matter of just extracting the default clause (https://github.com/cockroachdb/cockroach/blob/master/pkg/util/timeutil/pgdate/field_extract.go#L164) of the casting logic and exposing that for use by a wrapper function, no? |
(Ah, I'm afraid non-computed columns don't work for my use-case, as it's pulling from a quite flexible JSON object, but to be honest, my case my not be too representative. I've been pushing a lot of logic onto Cockroach via computed columns, which simplifies my life a lot and has so far been a quite elegant and relatively scalable, just write times slow down but that's easy to deal with, but it's not exactly traditional by any means) |
Indeed. I can add that, unless you want to work on it - you seem to be familiar with the code :) |
By the way, the next major release will likely add virtual computed columns (sounds like it might be useful to you). |
Ha, it would be fun for me to play around with the Cockroach code but I suspect you and your team will get to it before me if you think it's useful, I dunno when I would be able to prioritize this! Virtual? As in, computed at query time rather than write time? |
Yeah, exactly. |
Add a builtin that can be used to parse timestamp strings. This is like a cast, but it does not accept relative timestamps so it can be immutable. Only immutable expressions are allowed in computed column expressions or partial index predicates; unlike casts, the new function can be used in such expressions. Fixes cockroachdb#60578. Release notes (sql change): A new parse_timestamp function can be used to parse absolute timestamp strings in computed column expressions or partial index predicates.
Add a builtin that can be used to parse timestamp strings. This is like a cast, but it does not accept relative timestamps so it can be immutable. Only immutable expressions are allowed in computed column expressions or partial index predicates; unlike casts, the new function can be used in such expressions. Fixes cockroachdb#60578. Release notes (sql change): A new parse_timestamp function can be used to parse absolute timestamp strings in computed column expressions or partial index predicates.
Add a builtin that can be used to parse timestamp strings. This is like a cast, but it does not accept relative timestamps so it can be immutable. Only immutable expressions are allowed in computed column expressions or partial index predicates; unlike casts, the new function can be used in such expressions. Fixes cockroachdb#60578. Release notes (sql change): A new parse_timestamp function can be used to parse absolute timestamp strings in computed column expressions or partial index predicates.
@nandanrao I am adding a |
59566: kvserver: introduce a Raft-based transport for closedts r=andreimatei a=andreimatei This patch introduces a replacement for the existing closed timestamp mechanism / transport. The new mechanism is gated by a cluster version. Raft commands now carry increasing closed timestamps generated by the propBuf by using the recent request Tracker for synchronizing with in-flight requests (i.e. not closing timestamps below them). Raft commands get a closed ts field, and the range state gets the field as well. The propBuf pays attention to the range's closed timestamp policy for deciding whether to close lagging or leading timestamps. Release note: None 60753: kv: add TestStoreRangeSplitAndMergeWithGlobalReads r=nvanbenschoten a=nvanbenschoten Made possible by #60567. This commit adds a new test called TestStoreRangeSplitAndMergeWithGlobalReads that tests that a range configured to serve global reads can be split and merged. In essence, this tests whether the split and merge transactions can handle having their timestamp bumped by the closed timestamp on the ranges they're operating on. The test revealed that range merges did have issues in these cases, because SubsumeRequests assumed that the intent on the RHS's local descriptor was below the node's HLC clock. This is no longer always true, so we now perform the inconsistent scan at hlc.MaxTimestamp, just like QueryIntent requests do. 60772: sql: add parse_timestamp builtin r=RaduBerinde a=RaduBerinde Add a builtin that can be used to parse timestamp strings. This is like a cast, but it does not accept relative timestamps so it can be immutable. Only immutable expressions are allowed in computed column expressions or partial index predicates; unlike casts, the new function can be used in such expressions. Fixes #60578. Release notes (sql change): A new parse_timestamp function can be used to parse absolute timestamp strings in computed column expressions or partial index predicates. 60796: geo: replace GEOS with new WKT parser for EWKT parsing r=otan a=andyyang890 Previously, the `parseEWKT` function used GEOS to parse WKT strings. This was inadequate because GEOS has issues with parsing Z and M dimensions. To address this, a new WKT parser was implemented with goyacc and this patch integrates it into CockroachDB. Refs: #53091 Release note: None 60818: opt: add partition info to the opt catalog r=rytaft a=rytaft Prior to this commit, the opt catalog did not include zone information or prefixes specific to each partition of an index. This commit adds this information since it will be necessary to support locality optimized search in a future commit. Informs #55185 Release note: None Co-authored-by: Andrei Matei <andrei@cockroachlabs.com> Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com> Co-authored-by: Radu Berinde <radu@cockroachlabs.com> Co-authored-by: Andy Yang <ayang@cockroachlabs.com> Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
Ha, wow, amazing!!! Thanks a lot, @RaduBerinde, that's a big headache removed for me, personally. I really appreciate that. And it's a super clean implementation for something that seems useful! |
I have two needs for my computed columns that worked in v20.1.4 but no longer work in v20.2.4 due to the better checking of function volatility in computed columns (#51886):
timestamptz
+interval
string
>timestamptz
Now, the first I can solve by changing
timestamptz
totimestamp
(not an issue, all my clients run in UTC). Given that bothtimestamp
andtimestamptz
are stored in UTC under the hood and only displayed to the client in local time, I'm not sure what context the operation is dependent on, but I can work around it.The second I cannot work around because
string
>timestamp
is also not Immutable:cockroach/pkg/sql/sem/tree/casts.go
Line 249 in 9f97177
I'm sure there are issues that I'm not aware of, but it seems to me that it aught to be possible to express a timestamp in a string format in a way that corresponds to a UTC time in a non-context-dependent way, after all, the whole purpose of ISO formats and the like is to encode timestamps into strings such that they do indeed represent a single point in time.
Also, thanks for all the hard work :)
The text was updated successfully, but these errors were encountered: