title_wip

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/engines/table-engines/integrations/hdfs.md)

Not supported in ClickHouse Cloud

This engine provides integration with the [Apache Hadoop](https://en.wikipedia.org/wiki/Apache_Hadoop) ecosystem by allowing to manage data on [HDFS](https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html) via ClickHouse. This engine is similar to the [File](/docs/engines/table-engines/special/file) and [URL](/docs/engines/table-engines/special/url) engines, but provides Hadoop-specific features.

This feature is not supported by ClickHouse engineers, and it is known to have a sketchy quality. In case of any problems, fix them yourself and submit a pull request.

## Usage[​](#usage "Direct link to Usage")

```
ENGINE = HDFS(URI, format)
```

**Engine Parameters**

- `URI` - whole file URI in HDFS. The path part of `URI` may contain globs. In this case the table would be readonly.
- `format` - specifies one of the available file formats. To perform
  `SELECT` queries, the format must be supported for input, and to perform
  `INSERT` queries – for output. The available formats are listed in the
  [Formats](/docs/sql-reference/formats#formats-overview) section.
- [PARTITION BY expr]

### PARTITION BY[​](#partition-by "Direct link to PARTITION BY")

`PARTITION BY` — Optional. In most cases you don't need a partition key, and if it is needed you generally don't need a partition key more granular than by month. Partitioning does not speed up queries (in contrast to the ORDER BY expression). You should never use too granular partitioning. Don't partition your data by client identifiers or names (instead, make client identifier or name the first column in the ORDER BY expression).

For partitioning by month, use the `toYYYYMM(date_column)` expression, where `date_column` is a column with a date of the type [Date](/docs/sql-reference/data-types/date). The partition names here have the `"YYYYMM"` format.

**Example:**

**1.** Set up the `hdfs_engine_table` table:

```
CREATE TABLE hdfs_engine_table (name String, value UInt32) ENGINE=HDFS('hdfs://hdfs1:9000/other_storage', 'TSV')
```

**2.** Fill file:

```
INSERT INTO hdfs_engine_table VALUES ('one', 1), ('two', 2), ('three', 3)
```

**3.** Query the data:

```
SELECT * FROM hdfs_engine_table LIMIT 2
```

```
┌─name─┬─value─┐
│ one  │     1 │
│ two  │     2 │
└──────┴───────┘
```

## Implementation details[​](#implementation-details "Direct link to Implementation details")

- Reads and writes can be parallel.
- Not supported:

  - `ALTER` and `SELECT...SAMPLE` operations.
  - Indexes.
  - [Zero-copy](/docs/operations/storing-data#zero-copy) replication is possible, but not recommended.

  Zero-copy replication is not ready for production

  Zero-copy replication is disabled by default in ClickHouse version 22.8 and higher. This feature is not recommended for production use.

**Globs in path**

Multiple path components can have globs. For being processed file should exists and matches to the whole path pattern. Listing of files determines during `SELECT` (not at `CREATE` moment).

- `*` — Substitutes any number of any characters except `/` including empty string.
- `?` — 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.

Constructions with `{}` are similar to the [remote](/docs/sql-reference/table-functions/remote) table function.

**Example**

1. Suppose we have several files in TSV format with the following URIs on HDFS:

   - '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'
2. There are several ways to make a table consisting of all six files:

```
CREATE TABLE table_with_range (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/some_file_{1..3}', 'TSV')
```

Another way:

```
CREATE TABLE table_with_question_mark (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/some_file_?', 'TSV')
```

Table consists of all the files in both directories (all files should satisfy format and schema described in query):

```
CREATE TABLE table_with_asterisk (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/*', 'TSV')
```

Note

If the listing of files contains number ranges with leading zeros, use the construction with braces for each digit separately or use `?`.

**Example**

Create table with files named `file000`, `file001`, ... , `file999`:

```
CREATE TABLE big_table (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/big_dir/file{0..9}{0..9}{0..9}', 'CSV')
```

## Configuration[​](#configuration "Direct link to Configuration")

Similar to GraphiteMergeTree, the HDFS engine supports extended configuration using the ClickHouse config file. There are two configuration keys that you can use: global (`hdfs`) and user-level (`hdfs_*`). The global configuration is applied first, and then the user-level configuration is applied (if it exists).

```
<!-- Global configuration options for HDFS engine type -->
<hdfs>
  <hadoop_kerberos_keytab>/tmp/keytab/clickhouse.keytab</hadoop_kerberos_keytab>
  <hadoop_kerberos_principal>[email protected]</hadoop_kerberos_principal>
  <hadoop_security_authentication>kerberos</hadoop_security_authentication>
</hdfs>

<!-- Configuration specific for user "root" -->
<hdfs_root>
  <hadoop_kerberos_principal>[email protected]</hadoop_kerberos_principal>
</hdfs_root>
```

### Configuration options[​](#configuration-options "Direct link to Configuration options")

#### Supported by libhdfs3[​](#supported-by-libhdfs3 "Direct link to Supported by libhdfs3")