Skip to content

Commit 7dc21a9

Browse files
authored
merge to stable-25-2 YDBDOCS-1245 add docs for import / export (ch 1) (#24782)
2 parents 32b712e + c396c3d commit 7dc21a9

File tree

10 files changed

+97
-22
lines changed

10 files changed

+97
-22
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
|Name|Description|Example|
2+
|---|---|---|
3+
|`POSIX`|String in `%Y-%m-%d %H:%M:%S` format|2001-03-26 16:10:00|
4+
|`ISO`|Format, corresponding to the [ISO 8601](https://ru.wikipedia.org/wiki/ISO_8601) standard|2001-03-26 16:10:00Z|
5+
|`UNIX_TIME_SECONDS`|Number of seconds that have elapsed since the 1st of january 1970 (00:00:00 UTC)|985623000|
6+
|`UNIX_TIME_MILLISECONDS`|Number of milliseconds that have elapsed since the 1st of january 1970 (00:00:00 UTC)|985623000000|
7+
|`UNIX_TIME_MICROSECONDS`|Number of microseconds that have elapsed since the 1st of january 1970 (00:00:00 UTC)|985623000000000|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|Setting name|Description|Possible values|
2+
|----|----|---|
3+
|`file_pattern`|File name template|File name template string. Wildcards `*` are supported.|
4+
|`data.interval.unit`|Unit for parsing `Interval` type|`MICROSECONDS`, `MILLISECONDS`, `SECONDS`, `MINUTES`, `HOURS`, `DAYS`, `WEEKS`|
5+
|`data.datetime.format_name`|Predefined format in which `Datetime` data is stored|`POSIX`, `ISO`|
6+
|`data.datetime.format`|Strftime-like template which defines how `Datetime` data is stored|Formatting string, for example: `%Y-%m-%dT%H-%M`|
7+
|`date.timestamp.format_name`|Predefined format in which `Timestamp` data is stored|`POSIX`, `ISO`, `UNIX_TIME_SECONDS`, `UNIX_TIME_MILLISECONDS`, `UNIX_TIME_MICROSECONDS`|
8+
|`data.timestamp.format`|Strftime-like template which defines how `Timestamp` data is stored|Formatting string, for example: `%Y-%m-%dT%H-%M-%S`|
9+
|`data.date.format`|The format in which `Date` data is stored|Formatting string, for example: `%Y-%m-%d`|
10+
|`csv_delimiter`|Delimeter for `csv_with_names` format|Any character (UTF-8)|
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
|Path format|Description|Example|
22
|----|----|---|
3-
|Path ends with a `/`|Path to a directory|The path `/a` addresses all contents of the directory:<br/>`/a/b/c/d/1.txt`<br/>`/a/b/2.csv`|
3+
|Path ends with a `/`|Path to a directory|The path `/a/` addresses all contents of the directory:<br/>`/a/b/c/d/1.txt`<br/>`/a/b/2.csv`|
44
|Path contains a wildcard character `*`|Any files nested in the path|The path `/a/*.csv` addresses files in directories:<br/>`/a/b/c/1.csv`<br/>`/a/2.csv`<br/>`/a/b/c/d/e/f/g/2.csv`|
55
|Path does not end with `/` and does not contain wildcard characters|Path to a single file|The path `/a/b.csv` addresses the specific file `/a/b.csv`|

ydb/docs/en/core/concepts/federated_query/s3/external_data_source.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ FROM
3434
WITH(
3535
FORMAT = "<file_format>",
3636
COMPRESSION = "<compression>",
37-
SCHEMA = (<schema_definition>))
37+
SCHEMA = (<schema_definition>),
38+
<format_settings>)
3839
WHERE
3940
<filter>;
4041
```
@@ -46,6 +47,7 @@ Where:
4647
* `file_format` — the [data format](formats.md#formats) in the files.
4748
* `compression` — the [compression format](formats.md#compression_formats) of the files.
4849
* `schema_definition` — the [schema definition](#schema) of the data stored in the files.
50+
* `format_settings` — optional [format settings](#format_settings)
4951

5052
### Data schema description {#schema}
5153

@@ -97,12 +99,22 @@ Where:
9799

98100
As a result of executing such a query, the names and types of fields will be inferred.
99101

100-
### Data path formats {#path_format}
102+
### Data path formats specified in `file_path` {#path_format}
101103

102-
In {{ ydb-full-name }}, the following data paths are supported:
104+
In {{ ydb-full-name }}, the followingdata paths are supported:
103105

104106
{% include [!](_includes/path_format.md) %}
105107

108+
### Format settings {#format_settings}
109+
110+
In {{ ydb-full-name }}, the following format settings are supported:
111+
112+
{% include [!](_includes/format_settings.md) %}
113+
114+
You can only specify `file_pattern` setting if `file_path` is a path to a directory. Any conversion specifiers supported by [`strftime`(C99)](https://en.cppreference.com/w/c/chrono/strftime) function can be used in formatting strings. In {{ ydb-full-name }}, the following `Datetime` and `Timestamp` formats are supported:
115+
116+
{% include [!](_includes/date_formats.md) %}
117+
106118
## Example {#read_example}
107119

108120
Example query to read data from S3 ({{ objstorage-full-name }}):
@@ -111,21 +123,28 @@ Example query to read data from S3 ({{ objstorage-full-name }}):
111123
SELECT
112124
*
113125
FROM
114-
connection.`folder/filename.csv`
126+
connection.`folder/`
115127
WITH(
116128
FORMAT = "csv_with_names",
129+
COMPRESSION="gzip"
117130
SCHEMA =
118131
(
119-
Year Int32,
120-
Manufacturer Utf8,
121-
Model Utf8,
122-
Price Double
123-
)
132+
Id Int32 NOT NULL,
133+
UserId Int32 NOT NULL,
134+
TripDate Date NOT NULL,
135+
TripDistance Double NOT NULL,
136+
UserComment Utf8
137+
),
138+
FILE_PATTERN="*.csv.gz",
139+
`DATA.DATE.FORMAT`="%Y-%m-%d",
140+
CSV_DELIMITER='/'
124141
);
125142
```
126143

127144
Where:
128145

129146
* `connection` — the name of the external data source leading to the S3 bucket ({{ objstorage-full-name }}).
130-
* `folder/filename.csv` — the path to the file in the S3 bucket ({{ objstorage-full-name }}).
131-
* `SCHEMA` — the data schema description in the file.
147+
* `folder/filename.csv` — the path to the directory in the S3 bucket ({{ objstorage-full-name }}).
148+
* `SCHEMA` — the data schema description in the file.
149+
* `*.csv.gz` — file name template.
150+
* `%Y-%m-%d` — format in which `Date` type is stored in S3.

ydb/docs/en/core/concepts/federated_query/s3/external_table.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Where:
3737
- `csv_with_names` - one of the [permitted data storage formats](formats.md);
3838
- `gzip` - one of the [permitted compression algorithms](formats.md#compression).
3939

40+
You can also specify [format settings](external_data_source.md#format_settings).
41+
4042
## Data model {#data-model}
4143

4244
Reading data using external tables from S3 ({{ objstorage-name }}) is done with regular SQL queries as if querying a normal table.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
|Имя|Описание|Пример|
2+
|---|---|---|
3+
|`POSIX`|Строка формата `%Y-%m-%d %H:%M:%S`|2001-03-26 16:10:00|
4+
|`ISO`|Формат, соответствующий стандарту [ISO 8601](https://ru.wikipedia.org/wiki/ISO_8601)|2001-03-26 16:10:00Z|
5+
|`UNIX_TIME_SECONDS`|Количество секунд прошедших с 1 января 1970 года (00:00:00 UTC)|985623000|
6+
|`UNIX_TIME_MILLISECONDS`|Количество миллисекунд прошедших с 1 января 1970 года (00:00:00 UTC)|985623000000|
7+
|`UNIX_TIME_MICROSECONDS`|Количество микросекунд прошедших с 1 января 1970 года (00:00:00 UTC)|985623000000000|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|Имя параметра|Описание|Принимаемые значения|
2+
|----|----|---|
3+
|`file_pattern`|Шаблон имени файла|Строка шаблона имени. Поддерживаются wildcards `*`.|
4+
|`data.interval.unit`|Единица измерения для парсинга типа `Interval`|`MICROSECONDS`, `MILLISECONDS`, `SECONDS`, `MINUTES`, `HOURS`, `DAYS`, `WEEKS`|
5+
|`data.datetime.format_name`|Предопределенный формат, в котором записаны данные типа `Datetime`|`POSIX`, `ISO`|
6+
|`data.datetime.format`|Шаблон, определяющий как записаны данные типа `Datetime`|Строка форматирования, например: `%Y-%m-%dT%H-%M`|
7+
|`data.timestamp.format_name`|Предопределенный формат, в котором записаны данные типа `Timestamp`|`POSIX`, `ISO`, `UNIX_TIME_SECONDS`, `UNIX_TIME_MILLISECONDS`, `UNIX_TIME_MICROSECONDS`|
8+
|`data.timestamp.format`|Шаблон, определяющий как записаны данные типа `Timestamp`|Строка форматирования, например: `%Y-%m-%dT%H-%M-%S`|
9+
|`data.date.format`|Формат, в котором записаны данные типа `Date`|Строка форматирования, например: `%Y-%m-%d`|
10+
|`csv_delimiter`|Разделитель данных в формате `csv_with_names`|Любой символ (UTF-8)|
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
|Формат пути|Описание|Пример|
22
|----|----|---|
3-
|Путь завершается символом `/`|Путь к каталогу|Путь `/a` адресует все содержимое каталога:<br/>`/a/b/c/d/1.txt`<br/>`/a/b/2.csv`|
3+
|Путь завершается символом `/`|Путь к каталогу|Путь `/a/` адресует все содержимое каталога:<br/>`/a/b/c/d/1.txt`<br/>`/a/b/2.csv`|
44
|Путь содержит символ макроподстановки `*`|Любые файлы, вложенные в путь|Путь `/a/*.csv` адресует файлы в каталогах:<br/>`/a/b/c/1.csv`<br/>`/a/2.csv`<br/>`/a/b/c/d/e/f/g/2.csv`|
55
|Путь не завершается символом `/` и не содержит символов макроподстановок|Путь к отдельному файлу|Путь `/a/b.csv` адресует конкретный файл `/a/b.csv`|

ydb/docs/ru/core/concepts/federated_query/s3/external_data_source.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ FROM
3434
WITH(
3535
FORMAT = "<file_format>",
3636
COMPRESSION = "<compression>",
37-
SCHEMA = (<schema_definition>))
37+
SCHEMA = (<schema_definition>),
38+
<format_settings>)
3839
WHERE
3940
<filter>;
4041
```
@@ -46,6 +47,7 @@ WHERE
4647
* `file_format`[формат данных](formats.md#formats) в файлах.
4748
* `compression`[формат сжатия](formats.md#compression_formats) файлов.
4849
* `schema_definition`[описание схемы хранимых данных](#schema) в файлах.
50+
* `format_settings` — опциональные [параметры форматирования](#format_settings)
4951

5052
### Описание схемы данных {#schema}
5153

@@ -97,12 +99,22 @@ WHERE
9799

98100
В результате выполнения такого запроса будут автоматически выведены названия и типы полей.
99101

100-
### Форматы путей к данным {#path_format}
102+
### Форматы путей к данным задаваемых в параметре `file_path` {#path_format}
101103

102104
В {{ ydb-full-name }} поддерживаются следующие пути к данным:
103105

104106
{% include [!](_includes/path_format.md) %}
105107

108+
### Параметры форматирования {#format_settings}
109+
110+
В {{ ydb-full-name }} поддерживаются следующие параметры форматирования:
111+
112+
{% include [!](_includes/format_settings.md) %}
113+
114+
Параметр `file_pattern` можно использовать только в том случае, если `file_path` – путь к каталогу. В строках форматирования можно использовать любые шаблонные переменные, поддерживаемые функцией [`strftime`(C99)](https://en.cppreference.com/w/c/chrono/strftime). В {{ ydb-full-name }} поддерживаются следующие форматы типов `Datetime` и `Timestamp`:
115+
116+
{% include [!](_includes/date_formats.md) %}
117+
106118
## Пример {#read_example}
107119

108120
Пример запроса для чтения данных из S3 ({{ objstorage-full-name }}):
@@ -111,21 +123,28 @@ WHERE
111123
SELECT
112124
*
113125
FROM
114-
connection.`folder/filename.csv`
126+
connection.`folder/`
115127
WITH(
116128
FORMAT = "csv_with_names",
129+
COMPRESSION="gzip"
117130
SCHEMA =
118131
(
119-
Year Int32,
120-
Manufacturer Utf8,
121-
Model Utf8,
122-
Price Double
123-
)
132+
Id Int32 NOT NULL,
133+
UserId Int32 NOT NULL,
134+
TripDate Date NOT NULL,
135+
TripDistance Double NOT NULL,
136+
UserComment Utf8
137+
),
138+
FILE_PATTERN="*.csv.gz",
139+
`DATA.DATE.FORMAT`="%Y-%m-%d",
140+
CSV_DELIMITER='/'
124141
);
125142
```
126143

127144
Где:
128145

129146
* `connection` — название внешнего источника данных, ведущего на бакет S3 ({{ objstorage-full-name }}).
130-
* `folder/filename.csv` — путь к файлу в бакете S3 ({{ objstorage-full-name }}).
147+
* `folder/` — путь к папке с данными в бакете S3 ({{ objstorage-full-name }}).
131148
* `SCHEMA` — описание схемы данных в файле.
149+
* `*.csv.gz` — шаблон имени файлов с данными.
150+
* `%Y-%m-%d` — формат записи данных типа `Date` в S3.

ydb/docs/ru/core/concepts/federated_query/s3/external_table.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CREATE EXTERNAL TABLE `s3_test_data` (
3737
- `csv_with_names` - один из [допустимых типов хранения данных](formats.md);
3838
- `gzip` - один из [допустимых алгоритмов сжатия](formats.md#compression).
3939

40+
Также при создании внешних таблиц поддерживаются [параметры форматирования](external_data_source.md#format_settings).
4041

4142
## Модель данных {#data-model}
4243

0 commit comments

Comments
 (0)