出于调试目的,我希望能够将无界PCollection转换为有界PCollection . 有一种直截了当的方式吗?在我看来,除此之外,这样做是为了强制管道完成,这将是有用的 .

我认为Sample.any()(这里是Javadoc:https://beam.apache.org/documentation/sdks/javadoc/2.5.0/org/apache/beam/sdk/transforms/Sample.html#any-long-)将是我需要的,但是PTransform似乎并没有改变管道的有限性 .

编辑:我尝试了the-hbar-tender的建议,但我没有't able to make it work. Here'我是如何尝试的:

BoundedReadFromUnboundedSource brfus = unbounded.withMaxNumRecords(10);

......这样就会创建无界限:

Read.Unbounded unbounded = new Read.Unbounded("some name", pubsubUnboundedSource);

...其中pubsubUnboundedSource将被创建如下:

PubsubUnboundedSource pubsubUnboundedSource = PubsubUnboundedSource(pubsubClientFactory, projectValueProvider, topicValueProvider, subscriptionValueProvider, "some timestamp attribute", "some id attribute", true)

...但是pubsubClientFactory无法实例化,因为PubsubClient不公开 . 我放弃了 . 也许还有另一种方法来实现这个目标 .