如何在 Presto 连接器中使用下推谓词

How to use pushdown predicates in Presto connector

我想扩展 Presto 的 example-http 连接器以将相关谓词添加到连接器发出的 REST API 调用以最小化数据传输。

我现在已经花了好几个小时查看文档、在线帖子和 presto 源代码,但我无法弄清楚涉及哪些调用以及如何处理。

很多地方都提到了它,但我找不到任何简单的代码示例或内部描述。我确定我在这里遗漏了一些明显的东西。

下载源代码并在调试器中 运行 之后,我发现它一方面相当简单,另一方面也有限制。

直接的部分是我们在实现 ConnectorMetadata 接口时只需覆盖 isPushdownFilterSupportedpushdownFilter

限制部分是查询规划器现在认为连接器可以处理 table 过滤器的任何类型和组合。就我而言,我只想处理这些,我正在呼叫的遥控器 API 正在支持并让 Presto 处理其余部分。

Presto 团队似乎完全意识到了这一点,因为 a) 这些方法被标记为 @Experimental 和 b) 各自的评论 This interface can be replaced with a connector optimizer rule once the engine supports these (#12546). 这显然是我使用的正确方法案例.

   /**
     * Experimental: if true, the engine will invoke pushdownFilter instead of getTableLayouts.
     *
     * This interface can be replaced with a connector optimizer rule once the engine supports these (#12546).
     */
    @Experimental
    default boolean isPushdownFilterSupported(ConnectorSession session, ConnectorTableHandle tableHandle)
    {
        return false;
    }

    /**
     * Experimental: returns table layout that encapsulates the given filter.
     *
     * This interface can be replaced with a connector optimizer rule once the engine supports these (#12546).
     */
    @Experimental
    default ConnectorPushdownFilterResult pushdownFilter(ConnectorSession session, ConnectorTableHandle tableHandle, RowExpression filter, Optional<ConnectorTableLayoutHandle> currentLayoutHandle)
    {
        throw new UnsupportedOperationException();
    }