将Spark dataFrames保存为镶木地板文件 - 没有错误,但没有保存数据

时间:2015-10-04 20:59:54

标签: dataframe apache-spark-sql parquet

我想在Python中将数据框保存为镶木地板文件,但我只能保存模式,而不是数据本身。

我已将问题简化为一个非常简单的Python测试用例,我将其从IPYNB复制到下面。

有关可能发生的事情的任何建议?

In [2]:

import math
import string
import datetime
import numpy as np
import matplotlib.pyplot
from pyspark.sql import *
import pylab
import random
import time

In [3]:

sqlContext = SQLContext(sc)
​#create a simple 1 column dataframe a single row of data
df = sqlContext.createDataFrame(sc.parallelize(xrange(1)).flatMap(lambda x[Row(col1="Test row")]))
df.show()
df.count()

Out[3]:
col1    
Test row

1L

In [4]:
# Persist the dataframe as a parquet file
df.saveAsParquetFile("test.parquet")

In [5]: 
ls

TrapezoidRule.ipynb         metastore_db/
WeatherPrecipitation.ipynb  derby.log                  test.parquet/

In [6]: 
ls -l test.parquet
total 4
-rw-r--r-- 1 s26e-5a5fbda111ac17-5edfd8a0d95d users   0 Oct  4 14:13 _SUCCESS
-rw-r--r-- 1 s26e-5a5fbda111ac17-5edfd8a0d95d users 188 Oct  4 14:13 _common_metadata

In [7]: 
# The directory listing shows that the test parquet was created, but there are no data files.
# load the parquet file into another df and show that no data was saved or loaded... only the schema
newDF = sqlContext.parquetFile("test.parquet")
newDF.show()
newDF.count()

Out[7]: 
col1

0L

0 个答案:

没有答案