У меня есть датафрейм, который содержит последовательность строк.Я хочу перебирать строки по очереди без изменения порядка.
Я попытался описать код ниже.
scala> val df = Seq(
| (0,"Load","employeeview", "employee.empdetails", null ),
| (1,"Query","employeecountview",null,"select count(*) from employeeview"),
| (2,"store", "employeecountview",null,null)
| ).toDF("id", "Operation","ViewName","DiectoryName","Query")
df: org.apache.spark.sql.DataFrame = [id: int, Operation: string ... 3 more fields]
scala> df.show()
+---+---------+-----------------+-------------------+--------------------+
| id|Operation| ViewName| DiectoryName| Query|
+---+---------+-----------------+-------------------+--------------------+
| 0| Load| employeeview|employee.empdetails| null|
| 1| Query|employeecountview| null|select count(*) f...|
| 2| store|employeecountview| null| null|
+---+---------+-----------------+-------------------+--------------------+
scala> val dfcount = df.count().toInt
dfcount: Int = 3
scala> for( a <- 0 to dfcount-1){
// first Iteration I want id =0 Operation="Load" ViewName="employeeview" DiectoryName="employee.empdetails" Query= null
// second iteration I want id=1 Operation="Query" ViewName="employeecountview" DiectoryName="null" Query= "select count(*) from employeeview"
// Third Iteration I want id= 2 Operation= "store" ViewName="employeecountview" DiectoryName="null" Query= "null"
//ignore below sample code
// val Operation = get(Operation(i))
// if (Operation=="Load"){
// based on operation type i am calling appropriate function and passing entire row as a parameter
// } else if(Operation= "Query"){
//
// } else if(Operation= "store"){
// }
}
примечание: порядок обработки не должен изменяться.(Здесь Unique Identification - это ID, поэтому мы должны выполнить строку 0,1,2 и т. Д.)
Заранее спасибо.