HDFS

Name

SinceVersion 1.2

hdfs

Description

HDFS表函数(table-valued-function,tvf),可以让用户像访问关系表格式数据一样,读取并访问 HDFS 上的文件内容。目前支持csv/csv_with_names/csv_with_names_and_types/json/parquet/orc文件格式。

语法

  1. hdfs(
  2. "uri" = "..",
  3. "fs.defaultFS" = "...",
  4. "hadoop.username" = "...",
  5. "format" = "csv",
  6. "keyn" = "valuen"
  7. ...
  8. );

参数说明

访问hdfs相关参数:

  • uri:(必填) 访问hdfs的uri。
  • fs.defaultFS:(必填)
  • hadoop.username: (必填)可以是任意字符串,但不能为空
  • hadoop.security.authentication:(选填)
  • hadoop.username:(选填)
  • hadoop.kerberos.principal:(选填)
  • hadoop.kerberos.keytab:(选填)
  • dfs.client.read.shortcircuit:(选填)
  • dfs.domain.socket.path:(选填)

文件格式相关参数

  • format:(必填) 目前支持 csv/csv_with_names/csv_with_names_and_types/json/parquet/orc

  • column_separator:(选填) 列分割符, 默认为,

  • line_delimiter:(选填) 行分割符,默认为\n

    下面6个参数是用于json格式的导入,具体使用方法可以参照:Json Load

  • read_json_by_line: (选填) 默认为 "true"

  • strip_outer_array: (选填) 默认为 "false"

  • json_root: (选填) 默认为空

  • json_paths: (选填) 默认为空

  • num_as_string: (选填) 默认为 false

  • fuzzy_parse: (选填) 默认为 false

Examples

读取并访问 HDFS 存储上的csv格式文件

  1. MySQL [(none)]> select * from hdfs(
  2. "uri" = "hdfs://127.0.0.1:842/user/doris/csv_format_test/student.csv",
  3. "fs.defaultFS" = "hdfs://127.0.0.1:8424",
  4. "hadoop.username" = "doris",
  5. "format" = "csv");
  6. +------+---------+------+
  7. | c1 | c2 | c3 |
  8. +------+---------+------+
  9. | 1 | alice | 18 |
  10. | 2 | bob | 20 |
  11. | 3 | jack | 24 |
  12. | 4 | jackson | 19 |
  13. | 5 | liming | 18 |
  14. +------+---------+------+

可以配合desc function使用

  1. MySQL [(none)]> desc function hdfs(
  2. "uri" = "hdfs://127.0.0.1:8424/user/doris/csv_format_test/student_with_names.csv",
  3. "fs.defaultFS" = "hdfs://127.0.0.1:8424",
  4. "hadoop.username" = "doris",
  5. "format" = "csv_with_names");

Keywords

  1. hdfs, table-valued-function, tvf

Best Practice

关于HDFS tvf的更详细使用方法可以参照 S3 tvf, 唯一不同的是访问存储系统的方式不一样。