【问题标题】:Get timestamp from MongoDB ObjectId though PrestoDB通过 PrestoDB 从 MongoDB ObjectId 获取时间戳
【发布时间】:2020-06-25 14:23:50
【问题描述】:

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

【问题讨论】:

    标签: mongodb presto trino


    【解决方案1】:

    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 类中添加这个

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-20
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多