2016-10-21 7 views
1

の多くの関数言語では、mapのように機能しますが、多くの関数言語ではflatten戻り値が定義されています。 Spark/pysparkにはそれがありますhttp://spark.apache.org/docs/latest/api/python/pyspark.html#pyspark.RDD.flatMapdaskのflatMap

daskに入れるにはどうすればいいですか? dictsの

import dask.bag as db 
import json 
from tools import get_records 

records = db.read_text(json_file).map(json.loads).map(get_records) 

get_records戻りリスト: 私のコードは次のようになります。私はちょうど1つのシーケンスにそれらをチェーンする必要があります。

答えて

2

は、おそらく二つの動作は、「マップ」とあなたが好むようあなたが個別に使用したり、チェーンできる「連結」がある.concat method

In [1]: import dask.bag as db 

In [2]: b = db.from_sequence([1, 2, 3, 4, 5]) 

In [3]: def f(i): 
    ...:  return list(range(i)) 
    ...: 

In [4]: b.map(f).compute() 
Out[4]: [[0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] 

In [5]: b.map(f).concat().compute() 
Out[5]: [0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4] 

ので、代わりの参加「flatMap」の操作をします。