ClickHouse/docs/fa/sql-reference/table-functions/hdfs.md
Ivan Blinkov d91c97d15d
[docs] replace underscores with hyphens (#10606)
* Replace underscores with hyphens

* remove temporary code

* fix style check

* fix collapse
2020-04-30 21:19:18 +03:00

3.9 KiB
Raw Blame History

machine_translated machine_translated_rev toc_priority toc_title
true d734a8e46d 45 hdfs

hdfs

ایجاد یک جدول از فایل ها در اچ دی. این جدول عملکرد شبیه به نشانی وب و پرونده یکی

hdfs(URI, format, structure)

پارامترهای ورودی

  • URI — The relative URI to the file in HDFS. Path to file support following globs in readonly mode: *, ?, {abc,def} و {N..M} کجا N, M — numbers, `'abc', 'def' — strings.
  • format — The قالب پرونده
  • structure — Structure of the table. Format 'column1_name column1_type, column2_name column2_type, ...'.

مقدار بازگشتی

یک جدول با ساختار مشخص شده برای خواندن یا نوشتن داده ها در فایل مشخص شده است.

مثال

جدول از hdfs://hdfs1:9000/test و انتخاب دو ردیف اول:

SELECT *
FROM hdfs('hdfs://hdfs1:9000/test', 'TSV', 'column1 UInt32, column2 UInt32, column3 UInt32')
LIMIT 2
┌─column1─┬─column2─┬─column3─┐
│       1 │       2 │       3 │
│       3 │       2 │       1 │
└─────────┴─────────┴─────────┘

دل تنگی در مسیر

اجزای مسیر چندگانه می تواند دل تنگی دارند. برای پردازش فایل باید وجود داشته باشد و مسابقات به الگوی کل مسیر (نه تنها پسوند یا پیشوند).

  • * — Substitutes any number of any characters except / از جمله رشته خالی.
  • ? — Substitutes any single character.
  • {some_string,another_string,yet_another_one} — Substitutes any of strings 'some_string', 'another_string', 'yet_another_one'.
  • {N..M} — Substitutes any number in range from N to M including both borders.

سازه با {} شبیه به عملکرد جدول از راه دور).

مثال

  1. فرض کنید که ما چندین فایل با اوریس زیر در اچ دی ها داریم:
  • hdfs://hdfs1:9000/some_dir/some_file_1
  • hdfs://hdfs1:9000/some_dir/some_file_2
  • hdfs://hdfs1:9000/some_dir/some_file_3
  • hdfs://hdfs1:9000/another_dir/some_file_1
  • hdfs://hdfs1:9000/another_dir/some_file_2
  • hdfs://hdfs1:9000/another_dir/some_file_3
  1. پرس و جو مقدار ردیف در این فایل ها:
SELECT count(*)
FROM hdfs('hdfs://hdfs1:9000/{some,another}_dir/some_file_{1..3}', 'TSV', 'name String, value UInt32')
  1. پرس و جو مقدار ردیف در تمام فایل های این دو دایرکتوری:
SELECT count(*)
FROM hdfs('hdfs://hdfs1:9000/{some,another}_dir/*', 'TSV', 'name String, value UInt32')

!!! warning "اخطار" اگر لیست خود را از فایل های حاوی محدوده تعداد با صفر پیشرو, استفاده از ساخت و ساز با پرانتز برای هر رقم به طور جداگانه و یا استفاده ?.

مثال

پرس و جو داده ها از فایل های به نام file000, file001, … , file999:

SELECT count(*)
FROM hdfs('hdfs://hdfs1:9000/big_dir/file{0..9}{0..9}{0..9}', 'CSV', 'name String, value UInt32')

ستونهای مجازی

  • _path — Path to the file.
  • _file — Name of the file.

همچنین نگاه کنید به

مقاله اصلی