【发布时间】:2020-06-25 14:23:50
【问题描述】:
我正在使用 PrestoDB 查询一些 MongoDB 集合。 MongoDB 有一个 getTimestamp() method 来获取 ObjectId 的时间戳部分。如何在 PrestoDB 上获得类似的时间戳?
【问题讨论】:
我正在使用 PrestoDB 查询一些 MongoDB 集合。 MongoDB 有一个 getTimestamp() method 来获取 ObjectId 的时间戳部分。如何在 PrestoDB 上获得类似的时间戳?
【问题讨论】:
Presto 中没有实现,但是有一个 PR:https://github.com/prestosql/presto/pull/3089
你可以用 eg 来实现这个
@ScalarFunction("get_timestamp")
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) // ObjectId's timestamp is a point in time
public static long getTimestamp(@SqlType("ObjectId") Slice value)
{
int epochSeconds = new ObjectId(value.getBytes()).getTimestamp();
return DateTimeEncoding.packDateTimeWithZone(TimeUnit.SECONDS.toMillis(epochSeconds), UTC_KEY);
}
【讨论】: