当前位置: 首页>>代码示例>>Python>>正文


Python HDFileSystem.open方法代码示例

本文整理汇总了Python中hdfs3.HDFileSystem.open方法的典型用法代码示例。如果您正苦于以下问题:Python HDFileSystem.open方法的具体用法?Python HDFileSystem.open怎么用?Python HDFileSystem.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hdfs3.HDFileSystem的用法示例。


在下文中一共展示了HDFileSystem.open方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open_file_write_direct

# 需要导入模块: from hdfs3 import HDFileSystem [as 别名]
# 或者: from hdfs3.HDFileSystem import open [as 别名]
def open_file_write_direct(path, hdfs=None, **kwargs):
    if hdfs is None:
        hdfs = HDFileSystem(kwargs.get('host'), kwargs.get('port'))
    return hdfs.open(path, 'wb')
开发者ID:broxtronix,项目名称:distributed,代码行数:6,代码来源:hdfs.py

示例2: hdfs_open_file

# 需要导入模块: from hdfs3 import HDFileSystem [as 别名]
# 或者: from hdfs3.HDFileSystem import open [as 别名]
def hdfs_open_file(path, auth):
    hdfs = HDFileSystem(**auth)
    return hdfs.open(path, mode='rb')
开发者ID:broxtronix,项目名称:distributed,代码行数:5,代码来源:hdfs.py

示例3: HadoopFileSystem

# 需要导入模块: from hdfs3 import HDFileSystem [as 别名]
# 或者: from hdfs3.HDFileSystem import open [as 别名]

#.........这里部分代码省略.........
  def _mkdirs(self, path):
    self._hdfs_client.makedirs(path)

  def match(self, url_patterns, limits=None):
    if limits is None:
      limits = [None] * len(url_patterns)

    if len(url_patterns) != len(limits):
      raise BeamIOError(
          'Patterns and limits should be equal in length: %d != %d' % (
              len(url_patterns), len(limits)))

    # TODO(udim): Update client to allow batched results.
    def _match(path_pattern, limit):
      """Find all matching paths to the pattern provided."""
      file_infos = self._hdfs_client.ls(path_pattern, detail=True)[:limit]
      metadata_list = [FileMetadata(file_info['name'], file_info['size'])
                       for file_info in file_infos]
      return MatchResult(path_pattern, metadata_list)

    exceptions = {}
    result = []
    for url_pattern, limit in zip(url_patterns, limits):
      try:
        path_pattern = self._parse_url(url_pattern)
        result.append(_match(path_pattern, limit))
      except Exception as e:  # pylint: disable=broad-except
        exceptions[url_pattern] = e

    if exceptions:
      raise BeamIOError('Match operation failed', exceptions)
    return result

  def _open_hdfs(self, path, mode, mime_type, compression_type):
    if mime_type != 'application/octet-stream':
      logging.warning('Mime types are not supported. Got non-default mime_type:'
                      ' %s', mime_type)
    if compression_type == CompressionTypes.AUTO:
      compression_type = CompressionTypes.detect_compression_type(path)
    res = self._hdfs_client.open(path, mode)
    if compression_type != CompressionTypes.UNCOMPRESSED:
      res = CompressedFile(res)
    return res

  def create(self, url, mime_type='application/octet-stream',
             compression_type=CompressionTypes.AUTO):
    """
    Returns:
      *hdfs3.core.HDFile*: An Python File-like object.
    """
    path = self._parse_url(url)
    return self._create(path, mime_type, compression_type)

  def _create(self, path, mime_type='application/octet-stream',
              compression_type=CompressionTypes.AUTO):
    return self._open_hdfs(path, 'wb', mime_type, compression_type)

  def open(self, url, mime_type='application/octet-stream',
           compression_type=CompressionTypes.AUTO):
    """
    Returns:
      *hdfs3.core.HDFile*: An Python File-like object.
    """
    path = self._parse_url(url)
    return self._open(path, mime_type, compression_type)
开发者ID:aaltay,项目名称:incubator-beam,代码行数:69,代码来源:hadoopfilesystem.py

示例4: hdfs_open_file

# 需要导入模块: from hdfs3 import HDFileSystem [as 别名]
# 或者: from hdfs3.HDFileSystem import open [as 别名]
def hdfs_open_file(path, auth):
    from hdfs3 import HDFileSystem
    hdfs = HDFileSystem(**auth)
    return hdfs.open(path, mode='rb')
开发者ID:frol,项目名称:distributed,代码行数:6,代码来源:hdfs.py

示例5: open

# 需要导入模块: from hdfs3 import HDFileSystem [as 别名]
# 或者: from hdfs3.HDFileSystem import open [as 别名]
 def open(self, path, mode='rb', **kwargs):
     if path.startswith('hdfs://'):
         path = path[len('hdfs://'):]
     return HDFileSystem.open(self, path, mode, **kwargs)
开发者ID:dask,项目名称:distributed,代码行数:6,代码来源:hdfs.py


注:本文中的hdfs3.HDFileSystem.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。