テキストファイルを読み取り、メモリ内の登録済み一時テーブルとして使用するための作業コードがあります。スクリプトまたはモジュールのインポートを使用してこれらのテーブルのセットをロードし、対話的にクエリを実行したいと考えています。このコードをスクリプトと関数に入れたら、どちらのオブジェクトを返す必要がありますか? sc コンテキスト? テーブル?HadoopRDD?
file = "/file.tsv"
lines = sc.textFile(file)
parts = lines.map(lambda l: l.split("\t")).filter(lambda line:len(line)==7)
active_sessions = parts.map(lambda p: Row(
session=p[0]
, user_id=p[1]
, created=p[2]
, updated=p[3]
, id=p[4]
, deleted=p[5]
, resource_id=p[6]))
schemaTable = sqlContext.inferSchema(active_sessions)
schemaTable.registerTempTable("active_sessions")
sqlContext.cacheTable("active_sessions")