回答

1

這裏的方式,

dataset.foreachPartition(new ForeachPartitionFunction<Row>() { 
      public void call(Iterator<Row> t) throws Exception { 
       while (t.hasNext()){ 

        Row row = t.next(); 
        System.out.println(row.getString(2)); 
       } 
      } 
     }); 
-1
def foreach(func: ForeachFunction[T]): Unit 
(Java-specific) Runs func on each ***element*** of this Dataset. 

def foreach(f: (T) ⇒ Unit): Unit 
Applies a function f to all ***rows***. 

def foreachPartition(func: ForeachPartitionFunction[T]): Unit 
(Java-specific) Runs func on each partition of this Dataset. 

def foreachPartition(f: (Iterator[T]) ⇒ Unit): Unit 
Applies a function f to each partition of this Dataset.