通过 PrestoDB 从 MongoDB ObjectId 获取时间戳

Get timestamp from MongoDB ObjectId though 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);
}

-- 在 https://github.com/prestosql/presto/blob/master/presto-mongodb/src/main/java/io/prestosql/plugin/mongodb/ObjectIdFunctions.java class

中添加