简体   繁体   English

在 scala 中使用函数时出现错误类型不匹配

[英]Getting the error type mismatch while using functions in scala

import org.apache.spark.sql.{SparkSession, DataFrame}
import org.apache.spark.sql.functions._

object sparkcpp
{

  val spark = SparkSession.builder().getOrCreate()
  import spark.implicits._
  def extract(): DataFrame =
    {
      val df = spark.read.option("inferschema","true").option("header","true").csv("olive\\A.csv")
     }
 
  def transform(df: DataFrame): DataFrame =
    {

      val df = df.select(df("name"),df("age"))
    }
  def load(df: DataFrame): DataFrame =
    {
      val df = df.write.csv("testing.csv")
    }

  def main(args: Array[String]): Unit =
    {
      load(transform(extract()))
    }
}

*In the above code i'm getting the 'type mismatch error' when I try to load the dataframe in a csv file *在上面的代码中,当我尝试在 csv 文件中加载 dataframe 时出现“类型不匹配错误”

*This is the first time i'm working with scala using function. *这是我第一次使用 function 与 scala 合作。 Am I doing it right?我做对了吗?

*The aim of the program is to load the dataframe defined to the specified location using function. *该程序的目的是使用 function 将定义的 dataframe 加载到指定位置。

  • My major concern is the functions that i've used..is it right?我主要关心的是我使用过的功能……对吗? please make changes as required.请根据需要进行更改。
import org.apache.spark.sql.{SparkSession, DataFrame}
import org.apache.spark.sql.functions._

object sparkcpp
{

  val spark = SparkSession.builder().getOrCreate()
  import spark.implicits._
  def extract(): DataFrame =
    {
       spark.read.option("inferschema","true").option("header","true").csv("olive\\A.csv")
      

     }
 
  def transform(df: DataFrame): DataFrame =
    {

      df.select(df("name"),df("age"))
      
    }
  def load(df: DataFrame): DataFrame =
    {
      df.write.csv("testing.csv")
    }

  def main(args: Array[String]): Unit =
    {
      load(transform(extract()))
    }
}

You should return the dataframe from extract and load method您应该从提取和加载方法中返回 dataframe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Pandas 转换时的值错误不匹配 - Value Error Mismatch While Converting Using Pandas Spark/Scala - 在执行 withColumn 操作时加入结果集给出类型不匹配错误; 发现:org.apache.spark.sql.Column required: Boolean - Spark/Scala - Join resultset giving type mismatch error while performing withColumn operation; found : org.apache.spark.sql.Column required: Boolean 类型不匹配错误。 在 Scala Spark 中找到 Array[String] 需要 Seq[?] - Type mismatch error. found Array[String] requires Seq[?] in Scala Spark 在列表Python上使用Apply时出错 - Getting error while using apply on a list python 在scala列表中输入不匹配项。 如何从序列中获取List [String] - Type mismatch in scala list. How to get List[String] from a sequence SPARK 数据帧错误:无法在使用 UDF 拆分列中的字符串时转换为 scala.Function2 - SPARK dataframe error: cannot be cast to scala.Function2 while using a UDF to split strings in column 使用jsonlite将json文件转换为数据框时出现错误 - Getting error while converting json file to a data frame using jsonlite 在python中使用scipy.stats时出错 - Error getting while using scipy.stats in python 使用Pandas.Series.quantile()时出错 - Getting an error while using Pandas.Series.quantile() 在Python中使用Dataframe和numpy数组时出现错误 - Getting error while using Dataframe and numpy array in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM