通过PrestoDB从MongoDB ObjectId获取时间戳



我正在使用PrestoDB查询一些MongoDB集合。MongoDB有一个getTimestamp()方法来获取ObjectId的时间戳部分。如何在PrestoDB上获得类似的时间戳?

它没有在Presto中实现,但有一个PR:https://github.com/prestosql/presto/pull/3089

你可以用例如来实现这一点

@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类

最新更新