使用Apache beam io.jdbc.ReadFromJdbc时出错beam:logical_type:javasdk:v1

2024-09-29 21:55:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用ApacheBeam的PythonSDK从postgres表中读取数据。我已经按照文档中的说明安装了JavaSDK。我正在使用最新版本。 我的守则如下:

import logging
import typing

import apache_beam as beam
from apache_beam import coders
from apache_beam.io.jdbc import ReadFromJdbc
from apache_beam.options.pipeline_options import PipelineOptions
from past.builtins import unicode


def run(argv=None):
    beam_options = PipelineOptions()

    ExampleRow = typing.NamedTuple('ExampleRow', [('id', int), ('name', unicode)])

    coders.registry.register_coder(ExampleRow, coders.RowCoder)

    with beam.Pipeline(options=beam_options) as p:
        result = (
            p
            | 'Read from jdbc' >> ReadFromJdbc(
                                    table_name='jdbc_external_test_read',
                                    driver_class_name='org.postgresql.Driver',
                                    jdbc_url='jdbc:postgresql://localhost:5432/example',
                                    username='postgres',
                                    password='postgres')
        )


if __name__ == '__main__':
    logging.getLogger(__name__).setLevel(logging.INFO)
    run()

但是当我运行它时,我得到了错误ValueError: No logical type registered for URN 'beam:logical_type:javasdk:v1'


Tags: namefromimporttypingapacheloggingaspostgres

热门问题