Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vsihdfs Support #714

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions autotest/gcore/data/text.txt
@@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
193 changes: 193 additions & 0 deletions autotest/gcore/vsihdfs.py
@@ -0,0 +1,193 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# $Id$
#
# Project: GDAL/OGR Test Suite
# Purpose: Test VSI file primitives
# Author: James McClain <jmcclain@azavea.com>
#
###############################################################################
# Copyright (c) 2011-2013, Even Rouault <even dot rouault at mines-paris dot org>
# Copyright (c) 2018, Azavea
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
###############################################################################

import sys
import os
from osgeo import gdal

sys.path.append('../pymod')

import gdaltest

# Read test
def vsihdfs_1():
filename = '/vsihdfs/file:' + os.getcwd() + '/data/text.txt'
fp = gdal.VSIFOpenL(filename, 'rb')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could set here gdaltest.have_vsihdfs = False

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have done this.

if fp is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that this is an optionally compiled VFS, tests should return 'skip' if the VFS is not present. Unfortunately there's no easy way of knowing if a VFS is compiled in or not, so presumably you would use that initial failure as a sign it is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have implemented this.

gdaltest.have_vsihdfs = False
return 'skip'

gdaltest.have_vsihdfs = True

data = gdal.VSIFReadL(5, 1, fp)
if not data or data.decode('ascii') != 'Lorem':
return 'fail'

data = gdal.VSIFReadL(1, 6, fp)
if not data or data.decode('ascii') != ' ipsum':
return 'fail'

gdal.VSIFCloseL(fp)
return 'success'

# Seek test
def vsihdfs_2():
if gdaltest.have_vsihdfs == False:
return 'skip'

filename = '/vsihdfs/file:' + os.getcwd() + '/data/text.txt'
fp = gdal.VSIFOpenL(filename, 'rb')
if fp is None:
return 'fail'

gdal.VSIFSeekL(fp, 2, 0) # From beginning
gdal.VSIFSeekL(fp, 5, 0)
data = gdal.VSIFReadL(6, 1, fp)
if not data or data.decode('ascii') != ' ipsum':
return 'fail'

gdal.VSIFSeekL(fp, 7, 1) # From current
data = gdal.VSIFReadL(3, 1, fp)
if not data or data.decode('ascii') != 'sit':
return 'fail'

gdal.VSIFSeekL(fp, 9, 2) # From end
data = gdal.VSIFReadL(7, 1, fp)
if not data or data.decode('ascii') != 'laborum':
return 'fail'

gdal.VSIFCloseL(fp)
return 'success'

# Tell test
def vsihdfs_3():
if gdaltest.have_vsihdfs == False:
return 'skip'

filename = '/vsihdfs/file:' + os.getcwd() + '/data/text.txt'
fp = gdal.VSIFOpenL(filename, 'rb')
if fp is None:
return 'fail'

data = gdal.VSIFReadL(5, 1, fp)
if not data or data.decode('ascii') != 'Lorem':
return 'fail'

offset = gdal.VSIFTellL(fp)
if offset != 5:
return 'fail'

gdal.VSIFCloseL(fp)
return 'success'

# Write test
def vsihdfs_4():
return 'skip'

# EOF test
def vsihdfs_5():
if gdaltest.have_vsihdfs == False:
return 'skip'

filename = '/vsihdfs/file:' + os.getcwd() + '/data/text.txt'
fp = gdal.VSIFOpenL(filename, 'rb')
if fp is None:
return 'fail'

gdal.VSIFReadL(5, 1, fp)
eof = gdal.VSIFEofL(fp)
if eof != 0:
return 'fail'

gdal.VSIFReadL(1000000, 1, fp)
eof = gdal.VSIFEofL(fp)
if eof != 0:
return 'fail'

gdal.VSIFReadL(1, 1, fp)
eof = gdal.VSIFEofL(fp)
if eof != 1:
return 'fail'

gdal.VSIFSeekL(fp, 0, 0)
eof = gdal.VSIFEofL(fp)
if eof != 0:
return 'fail'

gdal.VSIFCloseL(fp)
return 'success'

# Stat test
def vsihdfs_6():
if gdaltest.have_vsihdfs == False:
return 'skip'

filename = '/vsihdfs/file:' + os.getcwd() + '/data/text.txt'
statBuf = gdal.VSIStatL(filename, 0)
if not statBuf:
return 'fail'

filename = '/vsihdfs/file:' + os.getcwd() + '/data/no-such-file.txt'
statBuf = gdal.VSIStatL(filename, 0)
if statBuf:
return 'fail'

return 'success'

# ReadDir test
def vsihdfs_7():
if gdaltest.have_vsihdfs == False:
return 'skip'

dirname = '/vsihdfs/file:' + os.getcwd() + '/data/'
lst = gdal.ReadDir(dirname)
if len(lst) < 360:
return 'fail'

return 'success'


gdaltest_list = [vsihdfs_1,
vsihdfs_2,
vsihdfs_3,
vsihdfs_4,
vsihdfs_5,
vsihdfs_6,
vsihdfs_7]

if __name__ == '__main__':

gdaltest.setup_run('vsihdfs')

gdaltest.run_tests(gdaltest_list)

gdaltest.summarize()
1 change: 1 addition & 0 deletions gdal/Doxyfile
Expand Up @@ -943,6 +943,7 @@ PREDEFINED = HAVE_DLFCN_H \
__cplusplus \
DOXYGEN_SKIP \
HAVE_CURL \
HDFS_ENABLED \
CPL_UNUSED= \
UNUSED_IF_NO_GEOS= \
UNUSED_IF_NO_SFCGAL= \
Expand Down
12 changes: 10 additions & 2 deletions gdal/GDALmake.opt.in
Expand Up @@ -36,7 +36,8 @@ INSTALL_DIR = $(GDAL_ROOT)/install-sh -d
LIBS = $(SDE_LIB) @LIBS@ $(KAK_LIBS) $(DWG_LIBS) $(CURL_LIB) \
$(MRSID_LIBS) $(MRSID_LIDAR_LIBS) $(ECW_LIBS) $(INGRES_LIB) \
$(PCIDSK_LIB) $(RASDAMAN_LIB) $(SOSI_LIB) \
$(OPENCL_LIB) $(JVM_LIB) $(LIBICONV) $(FGDB_LIB) $(LIBXML2_LIB) $(MONGODB_LIB)
$(OPENCL_LIB) $(JVM_LIB) $(LIBICONV) $(FGDB_LIB) $(LIBXML2_LIB) $(MONGODB_LIB) \
$(JNI_LIB) $(HDFS_LIB)

SSEFLAGS = @SSEFLAGS@
SSSE3FLAGS = @SSSE3FLAGS@
Expand Down Expand Up @@ -371,7 +372,6 @@ SOSI_INC = @SOSI_INC@
SOSI_LIB = @SOSI_LIB@
HAVE_SOSI = @SOSI_ENABLED@


#
# PCIDSK SDK
#
Expand Down Expand Up @@ -534,6 +534,14 @@ MDB_ENABLED = @MDB_ENABLED@

HAVE_ARMADILLO = @HAVE_ARMADILLO@

#
# HDFS
#
HDFS_LIB = @HDFS_LIB@
HDFS_INC = @HDFS_INC@
HDFS_ENABLED = @HDFS_ENABLED@
JNI_LIB = @JNI_LIB@

#
# freexl stuff
#
Expand Down
4 changes: 2 additions & 2 deletions gdal/aclocal.m4
@@ -1,6 +1,6 @@
# generated automatically by aclocal 1.15 -*- Autoconf -*-
# generated automatically by aclocal 1.14.1 -*- Autoconf -*-

# Copyright (C) 1996-2014 Free Software Foundation, Inc.
# Copyright (C) 1996-2013 Free Software Foundation, Inc.

# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
Expand Down