我有多个函数定义来编写一个Parquet文件,但我宁愿有一个通用函数。我怎样才能使一个通用功能工作?问题是一个通用函数返回错误 could not find implicit value for parameter writerFactory: com.github.mjakubowski84.parquet4s.ParquetWriter.ParquetWriterFactory[Product]
多种功能:
import com.github.mjakubowski84.parquet4s.ParquetWriter
import org.apache.parquet.hadoop.metadata.CompressionCodecName
import org.apache.parquet.hadoop.ParquetFileWriter
import java.time.format.DateTimeFormatter
import java.time.LocalDate
def writeParquetUnsegmented(rows: List[ACaseClass], date: String) = {
val outPath = s"s3a://redacted/path-$date.parquet"
ParquetWriter.writeAndClose(outPath,
rows,
ParquetWriter.Options(
writeMode = ParquetFileWriter.Mode.OVERWRITE,
compressionCodecName = CompressionCodecName.SNAPPY
))
}
def writeParquetSegmented(rows: List[BCaseClass], date: String) = {
val outPath = s"s3a://redacted/path-$date.parquet"
ParquetWriter.writeAndClose(outPath,
rows,
ParquetWriter.Options(
writeMode = ParquetFileWriter.Mode.OVERWRITE,
compressionCodecName = CompressionCodecName.SNAPPY
))
}
一个功能:
def writeParquetSegmented(rows: List[Product], date: String) = {
val outPath = s"s3a://redacted/path-$date.parquet"
ParquetWriter.writeAndClose(outPath,
rows,
ParquetWriter.Options(
writeMode = ParquetFileWriter.Mode.OVERWRITE,
compressionCodecName = CompressionCodecName.SNAPPY
))
}
我也尝试了不同的函数签名,得到了相同的错误。
def writeParquetSegmented[A](rows: List[A], date: String)
def writeParquetSegmented[A :< RowParent](rows: List[A], date: String)
2条答案
按热度按时间mbzjlibv1#
只需将函数设置为泛型:
vdzxcuhz2#
我想试试这个签名:
编译器将打开上下文绑定
[A : ParquetWriterFactory]
错误消息所抱怨的隐式参数。