Java 我得到一个错误:“quot;“过载分辨率模糊性”;使用Kotlin时从ApacheBeam中的MapElements转换
我正在探索Google CloudOn平台提供的Apache Beam数据流模板 特别是,我正在将模板从Java转换为Kotlin 通过这样做,我在Java 我得到一个错误:“quot;“过载分辨率模糊性”;使用Kotlin时从ApacheBeam中的MapElements转换,java,intellij-idea,kotlin,apache-beam,dataflow,Java,Intellij Idea,Kotlin,Apache Beam,Dataflow,我正在探索Google CloudOn平台提供的Apache Beam数据流模板 特别是,我正在将模板从Java转换为Kotlin 通过这样做,我在maplements.input(…).via(…)transform-on-line274中得到了一个重载歧义解决错误。错误消息是: Error:(62, 22) Kotlin: Cannot choose among the following candidates without completing type inference: publ
maplements.input(…).via(…)
transform-on-line274
中得到了一个重载歧义解决错误。错误消息是:
Error:(62, 22) Kotlin: Cannot choose among the following candidates without completing type inference:
public final fun <NewInputT : Any!> via(fn: ((input: BigQueryInsertError!) -> FailsafeElement<String!, String!>!)!): MapElements<BigQueryInsertError!, FailsafeElement<String!, String!>!>! defined in org.apache.beam.sdk.transforms.MapElements
public final fun <NewInputT : Any!> via(fn: ((input: BigQueryInsertError!) -> FailsafeElement<String!, String!>!)!): MapElements<BigQueryInsertError!, FailsafeElement<String!, String!>!>! defined in org.apache.beam.sdk.transforms.MapElements
错误:(62,22)Kotlin:未完成类型推断,无法在以下候选项中进行选择:
公共最终乐趣通过(fn:((输入:BigQueryInsertror!)->FailsafeElement!)):MapElements!在org.apache.beam.sdk.transforms.MapElements中定义
公共最终乐趣通过(fn:((输入:BigQueryInsertror!)->FailsafeElement!)):MapElements!在org.apache.beam.sdk.transforms.MapElements中定义
相关的Java代码片段是:
/*
* Step 3 Contd.
* Elements that failed inserts into BigQuery are extracted and converted to FailsafeElement
*/
PCollection<FailsafeElement<String, String>> failedInserts =
writeResult
.getFailedInsertsWithErr()
.apply(
"WrapInsertionErrors",
MapElements.into(FAILSAFE_ELEMENT_CODER.getEncodedTypeDescriptor())
.via((BigQueryInsertError e) -> wrapBigQueryInsertError(e)))
.setCoder(FAILSAFE_ELEMENT_CODER);
/*
*第三步继续。
*在BigQuery中插入失败的元素将被提取并转换为FailsafeElement
*/
P收集失败插入=
书面结果
.GetFailedInsertsWither()
.申请(
“WrapInsertionErrors”,
MapElements.into(FAILSAFE\u ELEMENT\u CODER.getEncodedTypeDescriptor())
.via((BigQueryInsertError e)->WrapBigQueryInSerror(e)))
.设置编码器(故障保护元件编码器);
Kotlin转换如下所示:
/*
* Step 3 Contd.
* Elements that failed inserts into BigQuery are extracted and converted to FailsafeElement
*/
val failedInserts: PCollection<FailsafeElement<String, String>> =
writeResult.failedInsertsWithErr
.apply(
"WrapInsertionErrors",
MapElements.into(FAILSAFE_ELEMENT_CODER.encodedTypeDescriptor)
.via { e: BigQueryInsertError -> wrapBigQueryInsertError(e) })
.setCoder(FAILSAFE_ELEMENT_CODER)
/*
*第三步继续。
*在BigQuery中插入失败的元素将被提取并转换为FailsafeElement
*/
val失败插入:PCollection=
writeResult.failedInsertsWither
.申请(
“WrapInsertionErrors”,
MapElements.into(FAILSAFE\u ELEMENT\u CODER.encodedTypeDescriptor)
.via{e:BigQueryInSer恐怖->WrapBigQueryInSer恐怖(e)})
.setCoder(故障保护元件编码器)
我不知道如何解决这个问题。任何帮助都很好。原因是Java和Kotlin之间的重载规则略有不同,这意味着Kotlin中有两个匹配的重载
public <NewInputT> MapElements<NewInputT, OutputT> via(ProcessFunction<NewInputT, OutputT> fn)
public <NewInputT> MapElements<NewInputT, OutputT> via(SerializableFunction<NewInputT, OutputT> fn)
.via<BigQueryInsertError> (SerializableFunction { e: BigQueryInsertError -> wrapBigQueryInsertError(e) }))