【问题标题】:RowType support in PrestoPresto 中的 RowType 支持
【发布时间】:2020-04-15 15:39:27
【问题描述】:

对于那些知道 Presto API for plugins 的人的问题。

我实现了 BigQuery 插件。 BigQuery 支持struct 类型,在 Presto 中可以表示为RowType 类。

RowTypeRowType::createBlockBuilder 中创建RowBlockBuilder,它有RowBlockBuilder::appendStructure 方法,需要只接受AbstractSingleRowBlock 类的实例。

这意味着在我实现 Presto 的 RecordCursor BigQueryRecordCursor::getObject 方法时,我必须为类型为 RowType 的字段返回 AbstractSingleRowBlock

但是AbstractSingleRowBlock 有包私有抽象方法,这阻止了我实现这个类。唯一的孩子SingleRowBlock 有包私有构造函数,没有工厂或构建器可以为我构建实例。

如何在BigQueryRecordCursor::getObject 中实现struct 支持? (提醒:BigQueryRecordCursorRecordCursor 的孩子)。

【问题讨论】:

    标签: presto trino


    【解决方案1】:

    您需要通过调用beginBlockEntry 为行组装块,通过Type.writeXXX 将每列的值附加到列的类型,然后是closeEntry。这是一些伪代码。

    BlockBuilder builder = type.createBlockBuilder(..);
    
    builder = builder.beginBlockEntry();
    for each column {
        ...
    
        columnType.writeXXX(builder, ...);
    }
    builder.closeEntry();
    
    return (Block) type.getObject(builder, 0);
    

    但是,我建议您改用列式 API(即ConnectorPageSource 和朋友)。看看 Elasticsearch 连接器是如何实现的:

    https://github.com/prestosql/presto/blob/master/presto-elasticsearch/src/main/java/io/prestosql/elasticsearch/ElasticsearchPageSourceProvider.java https://github.com/prestosql/presto/blob/master/presto-elasticsearch/src/main/java/io/prestosql/elasticsearch/ElasticsearchPageSource.java

    这是它处理行类型的方式:

    https://github.com/prestosql/presto/blob/master/presto-elasticsearch/src/main/java/io/prestosql/elasticsearch/decoders/RowDecoder.java

    另外,我建议您加入 Presto Community Slack 上的 #dev 频道,所有 Presto 开发人员都在这里闲逛。

    【讨论】:

      猜你喜欢
      • 2018-01-22
      • 2013-11-25
      • 2018-12-20
      • 2013-12-02
      • 2016-05-07
      • 2023-03-06
      • 1970-01-01
      • 2021-12-16
      • 2016-09-13
      相关资源
      最近更新 更多