> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Cria uma tabela com base em arquivos no HDFS. Esta função de tabela é semelhante às funções de tabela url e file.

# Função de tabela hdfs

export const CloudNotSupportedBadge = () => {
  return <div className="cloudNotSupportedBadge">
            <div className="cloudNotSupportedIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.5" d="M6.33366 12.6666L12.3739 12.6667C13.6593 12.6667 14.7073 11.6187 14.7073 10.3334C14.7073 9.04804 13.6593 8.00003 12.3739 8.00003C12.3739 8.00003 12.3337 7.66659 12.0003 7.33325M10.667 5.33322C8.00033 2.33325 4.45395 4.78537 4.14195 6.68203C2.55728 6.7627 1.29395 8.06203 1.29395 9.6667C1.29395 11.3234 2.66699 12.6666 4.00033 12.6666" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.5" d="M2.66699 14L12.0003 4.66663" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>

        </div>
            Not supported in ClickHouse Cloud
        </div>;
};

export const ExperimentalBadge = () => {
  return <div className="experimentalBadge">
            <div className="experimentalIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.25" d="M5.5 2H10.5" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.25" d="M9.50015 2V6.19625L13.4283 12.7425C13.4738 12.8183 13.4985 12.9049 13.4996 12.9934C13.5008 13.0818 13.4785 13.169 13.435 13.246C13.3914 13.323 13.3283 13.3871 13.2519 13.4317C13.1755 13.4764 13.0886 13.4999 13.0002 13.5H3.00015C2.91164 13.5 2.8247 13.4766 2.74822 13.432C2.67174 13.3874 2.60847 13.3233 2.56487 13.2463C2.52126 13.1693 2.49889 13.082 2.50004 12.9935C2.50119 12.905 2.52582 12.8184 2.5714 12.7425L6.50015 6.19625V2" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.25" d="M4.47656 9.56754C5.30344 9.41254 6.47656 9.47942 7.99969 10.25C10.0153 11.2707 11.4216 11.0569 12.2184 10.7282" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
        </div>
            Experimental feature. <u><a href="/docs/beta-and-experimental-features#experimental-features">Learn more.</a></u>
        </div>;
};

Cria uma tabela com base em arquivos no HDFS. Esta função de tabela é semelhante às funções de tabela [url](/pt-BR/reference/functions/table-functions/url) e [file](/pt-BR/reference/functions/table-functions/file).

<div id="syntax">
  ## Sintaxe
</div>

```sql theme={null}
hdfs(URI, format, structure)
```

<div id="arguments">
  ## Argumentos
</div>

| Argumento   | Descrição                                                                                                                                                                                                           |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `URI`       | A URI relativa para o arquivo no HDFS. O caminho para o arquivo oferece suporte aos seguintes globs no modo somente leitura: `*`, `?`, `{abc,def}` e `{N..M}`, em que `N`, `M` — números, `'abc', 'def'` — strings. |
| `format`    | O [formato](/pt-BR/reference/formats) do arquivo.                                                                                                                                                                   |
| `structure` | Estrutura da tabela. Formato: `'column1_name column1_type, column2_name column2_type, ...'`.                                                                                                                        |

<div id="returned_value">
  ## Valor retornado
</div>

Uma tabela com a estrutura especificada para ler ou gravar dados no arquivo especificado.

**exemplo**

Tabela em `hdfs://hdfs1:9000/test` e seleção das duas primeiras linhas:

```sql theme={null}
SELECT *
FROM hdfs('hdfs://hdfs1:9000/test', 'TSV', 'column1 UInt32, column2 UInt32, column3 UInt32')
LIMIT 2
```

```text theme={null}
┌─column1─┬─column2─┬─column3─┐
│       1 │       2 │       3 │
│       3 │       2 │       1 │
└─────────┴─────────┴─────────┘
```

<div id="globs_in_path">
  ## Globs no caminho
</div>

Os caminhos podem usar globs. Os arquivos devem corresponder ao padrão do caminho completo, não apenas ao sufixo ou prefixo.

* `*` — Representa uma quantidade arbitrária de caracteres, exceto `/`, incluindo a string vazia.
* `**` — Representa todos os arquivos dentro de uma pasta, recursivamente.
* `?` — Representa um único caractere arbitrário.
* `{some_string,another_string,yet_another_one}` — Substitui qualquer uma das strings `'some_string', 'another_string', 'yet_another_one'`. As strings podem conter o símbolo `/`.
* `{N..M}` — Representa qualquer número `>= N` e `<= M`.

Construções com `{}` são semelhantes às funções de tabela [remote](/pt-BR/reference/functions/table-functions/remote) e [file](/pt-BR/reference/functions/table-functions/file).

**Exemplo**

1. Suponha que haja vários arquivos com os seguintes URIs no 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. Consulte a quantidade de linhas nesses arquivos:

```sql theme={null}
SELECT count(*)
FROM hdfs('hdfs://hdfs1:9000/{some,another}_dir/some_file_{1..3}', 'TSV', 'name String, value UInt32')
```

3. Consulte a quantidade de linhas de todos os arquivos nesses dois diretórios:

```sql theme={null}
SELECT count(*)
FROM hdfs('hdfs://hdfs1:9000/{some,another}_dir/*', 'TSV', 'name String, value UInt32')
```

<Note>
  Se a sua lista de arquivos contiver intervalos numéricos com zeros à esquerda, use a construção com chaves para cada dígito separadamente ou use `?`.
</Note>

**Exemplo**

Consulte os dados dos arquivos chamados `file000`, `file001`, ... , `file999`:

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

<div id="virtual-columns">
  ## Colunas virtuais
</div>

* `_path` — Caminho do arquivo. Tipo: `LowCardinality(String)`.
* `_file` — Nome do arquivo. Tipo: `LowCardinality(String)`.
* `_size` — Tamanho do arquivo em bytes. Tipo: `Nullable(UInt64)`. Se o tamanho for desconhecido, o valor será `NULL`.
* `_time` — Hora da última modificação do arquivo. Tipo: `Nullable(DateTime)`. Se a hora for desconhecida, o valor será `NULL`.

<div id="hive-style-partitioning">
  ## configuração `use_hive_partitioning`
</div>

Quando a configuração `use_hive_partitioning` é definida como 1, o ClickHouse detecta o particionamento no estilo Hive no caminho (`/name=value/`) e permite usar colunas de partição como colunas virtuais na consulta. Essas colunas virtuais terão os mesmos nomes do caminho particionado.

**Exemplo**

Usar a coluna virtual criada com o particionamento no estilo Hive

```sql theme={null}
SELECT * FROM HDFS('hdfs://hdfs1:9000/data/path/date=*/country=*/code=*/*.parquet') WHERE date > '2020-01-01' AND country = 'Netherlands' AND code = 42;
```

<div id="storage-settings">
  ## Configurações de armazenamento
</div>

* [hdfs\_truncate\_on\_insert](/pt-BR/reference/settings/session-settings#hdfs_truncate_on_insert) - permite truncar o arquivo antes de inserir dados nele. Desativado por padrão.
* [hdfs\_create\_new\_file\_on\_insert](/pt-BR/reference/settings/session-settings#hdfs_create_new_file_on_insert) - permite criar um novo arquivo a cada inserção se o formato tiver sufixo. Desativado por padrão.
* [hdfs\_skip\_empty\_files](/pt-BR/reference/settings/session-settings#hdfs_skip_empty_files) - permite ignorar arquivos vazios durante a leitura. Desativado por padrão.

<div id="related">
  ## Relacionados
</div>

* [Colunas virtuais](/pt-BR/reference/engines/table-engines#table_engines-virtual_columns)
