Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark 给定值未在Spark Scala中的if语句中赋值?_Apache Spark_If Statement_Apache Spark Sql_String Interpolation - Fatal编程技术网

Apache spark 给定值未在Spark Scala中的if语句中赋值?

Apache spark 给定值未在Spark Scala中的if语句中赋值?,apache-spark,if-statement,apache-spark-sql,string-interpolation,Apache Spark,If Statement,Apache Spark Sql,String Interpolation,我指定了以下值。问题是,在if语句中使用end1和end2值时,没有赋值。 我使用了字符串插值,但仍然没有指定 我的示例代码如下,三个if条件,一个如下 if(tp <="1.0") { end1="nd" end2="ms" } breakable { for (row <- df.rdd.collect) { var ts=row.mkString(",").split(",")(1) var nd=row.mkString(",").split(",

我指定了以下值。问题是,在if语句中使用end1和end2值时,没有赋值。 我使用了字符串插值,但仍然没有指定

我的示例代码如下,三个if条件,一个如下

if(tp <="1.0")
 {   
   end1="nd"
   end2="ms"
 }


breakable {

for (row <- df.rdd.collect) {
var ts=row.mkString(",").split(",")(1)
var nd=row.mkString(",").split(",")(2)
var tp=row.mkString(",").split(",")(3)
var ms=row.mkString(",").split(",")(4)

    println(end1)  // this prints nd
    println(end2) // this prints ms

  // but in if statement end1 and end2 values doesn't assign with nd and ms 
   - neither it shows any error nor assigning the values

 if( end1 <="0.5" || end2 <="0.5")
   endtime=ts
   println("end timestamp is" + endtime)
   break()
   }
 }

if(tp我假设这些值只是在if内部分配的,而当它们在if外部时,它们的引用就丢失了,所以我建议您首先初始化变量,然后在需要的地方传递它们,这样引用就不会丢失,并且每次更新时都会更新这些值

if( nd <="0.5" || ms <="0.5")  
// end1 and end2 changes as per the condition