-
Notifications
You must be signed in to change notification settings - Fork 2k
/
pyunit_HDFS_basic.py
56 lines (47 loc) · 2.31 KB
/
pyunit_HDFS_basic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#----------------------------------------------------------------------
# Purpose: This test exercises HDFS operations from python.
#----------------------------------------------------------------------
import sys
sys.path.insert(1, "../../")
import h2o
def hdfs_basic(ip, port):
h2o.init(ip, port)
# Check if we are running inside the H2O network by seeing if we can touch
# the namenode.
running_inside_h2o = h2o.is_running_internal_to_h2o()
if running_inside_h2o:
hdfs_name_node = h2o.get_h2o_internal_hdfs_name_node()
hdfs_iris_file = "/datasets/runit/iris_wheader.csv"
hdfs_iris_dir = "/datasets/runit/iris_test_train"
#----------------------------------------------------------------------
# Single file cases.
#----------------------------------------------------------------------
print "Testing single file importHDFS"
url = "hdfs://{0}{1}".format(hdfs_name_node, hdfs_iris_file)
iris_h2o = h2o.import_frame(url)
iris_h2o.head()
iris_h2o.tail()
n = iris_h2o.nrow()
print "rows: {0}".format(n)
assert n == 150, "Wrong number of rows. Got {0}. Should have got {1}".format(n, 150)
assert isinstance(iris_h2o, h2o.H2OFrame), "Wrong type. Expected H2OFrame, but got {0}".format(type(iris_h2o))
print "Import worked"
#----------------------------------------------------------------------
# Directory file cases.
#----------------------------------------------------------------------
print "Testing directory importHDFS"
urls = ["hdfs://{0}{1}/iris_test.csv".format(hdfs_name_node, hdfs_iris_dir),
"hdfs://{0}{1}/iris_train.csv".format(hdfs_name_node, hdfs_iris_dir)]
iris_dir_h2o = h2o.import_frame(urls)
iris_dir_h2o.head()
iris_dir_h2o.tail()
n = iris_dir_h2o.nrow()
print "rows: {0}".format(n)
assert n == 150, "Wrong number of rows. Got {0}. Should have got {1}".format(n, 150)
assert isinstance(iris_dir_h2o, h2o.H2OFrame), "Wrong type. Expected H2OFrame, but got {0}".\
format(type(iris_dir_h2o))
print "Import worked"
else:
print "Not running on H2O internal network. No access to HDFS."
if __name__ == "__main__":
h2o.run_test(sys.argv, hdfs_basic)