Skip to content

Commit 9c3500c

Browse files
committed
try/catch
1 parent 0b5e656 commit 9c3500c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sdks/python/apache_beam/io/hadoopfilesystem.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import re
2727
from typing import BinaryIO # pylint: disable=unused-import
2828

29-
import hdfs
30-
3129
from apache_beam.io import filesystemio
3230
from apache_beam.io.filesystem import BeamIOError
3331
from apache_beam.io.filesystem import CompressedFile
@@ -37,6 +35,11 @@
3735
from apache_beam.options.pipeline_options import HadoopFileSystemOptions
3836
from apache_beam.options.pipeline_options import PipelineOptions
3937

38+
try:
39+
import hdfs
40+
except ImportError:
41+
hdfs = None
42+
4043
__all__ = ['HadoopFileSystem']
4144

4245
_HDFS_PREFIX = 'hdfs:/'
@@ -108,6 +111,10 @@ def __init__(self, pipeline_options):
108111
See :class:`~apache_beam.options.pipeline_options.HadoopFileSystemOptions`.
109112
"""
110113
super().__init__(pipeline_options)
114+
if hdfs is None:
115+
raise ImportError(
116+
'Failed to import hdfs. You can ensure it is '
117+
'installed by installing the hadoop beam extra')
111118
logging.getLogger('hdfs.client').setLevel(logging.WARN)
112119
if pipeline_options is None:
113120
raise ValueError('pipeline_options is not set')

0 commit comments

Comments
 (0)