创建 pcollection
PCollection<Row> count = pt.apply(SqlTransform.query(Constants.total_count));
PCollectionView<Long> outputCount = detail_count
.apply("Row to long",
ParDo.of(new RowToLong())).apply(View.asSingleton());
查询
String total_count = select sum(cast(col1 as INT)) as total_count from <table>
转换 RowToInteger 方法
public class RowToLong extends DoFn<Row, Integer> {
public static final Logger LOG = LoggerFactory.getLogger(RowToLong.class.getName());
private PCollectionView<Integer> outputCount;
@ProcessElement
public void processElement(ProcessContext context) {
Integer total_count= Long.valueOf(context.element().getInt64("total_count"));
context.output(total_count);
}
}
错误
java.lang.Integer cannot be cast to java.lang.Long
最佳答案
String total_count = select sum(cast(col1 as bigint)) as total_count from <table>
Integer total_count = context.element().getInt64("total_count");
关于java - 如何使用 Java 在 Dataflow Apache Beam 中将 PCollection<Row> 转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71142185/