gpt4 book ai didi

java - Apache-beam Bigquery .fromQuery ClassCastException

转载 作者:行者123 更新时间:2023-12-01 18:14:28 25 4
gpt4 key购买 nike

我正在尝试对 BigQuery 表执行查询,提取一列并填充到文件中。下面的代码抛出异常。我可能是错的,但似乎该过程正在尝试将临时结果以 avro 格式写入临时位置,从中读取数据并抛出强制转换异常。

pipeLine.apply(
BigQueryIO.read(
(SchemaAndRecord elem) -> {
GenericRecord record = elem.getRecord();
return (String) record.get("column");
})
.fromQuery("SELECT column FROM `project.dataset.table`")
.usingStandardSql()
.withCoder(AvroCoder.of(String.class)))
.apply(TextIO.write().to("gs://bucket/test/result/data")
.withSuffix(TXT_EXT)
.withCompression(Compression.GZIP));

Caused by: java.lang.ClassCastException: org.apache.avro.util.Utf8 cannot be cast to java.lang.String at xxxxx.xxx.xxx.sampling.dataflow.samplingextractor.service.BigQueryExportService.lambda$export$43268ee4$1(BigQueryExportService.java:137) at org.apache.beam.sdk.io.gcp.bigquery.BigQuerySourceBase$1.apply(BigQuerySourceBase.java:242) at org.apache.beam.sdk.io.gcp.bigquery.BigQuerySourceBase$1.apply(BigQuerySourceBase.java:235) at org.apache.beam.sdk.io.AvroSource$AvroBlock.readNextRecord(AvroSource.java:597) at org.apache.beam.sdk.io.BlockBasedSource$BlockBasedReader.readNextRecord(BlockBasedSource.java:209) at org.apache.beam.sdk.io.FileBasedSource$FileBasedReader.advanceImpl(FileBasedSource.java:484) at org.apache.beam.sdk.io.FileBasedSource$FileBasedReader.startImpl(FileBasedSource.java:479) at org.apache.beam.sdk.io.OffsetBasedSource$OffsetBasedReader.start(OffsetBasedSource.java:249) at org.apache.beam.runners.dataflow.worker.WorkerCustomSources$BoundedReaderIterator.start(WorkerCustomSources.java:601)

最佳答案

我认为它建议您使用 .withCoder(AvroCoder.of(org.apache.avro.util.Utf8.class))) 因为 String 无法直接从 Avro Utf8 类转换。

关于java - Apache-beam Bigquery .fromQuery ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60400769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com