[Doc] Separator and Delimiter with Multiple Non-printable Characters (backport #62744) (#62747)

Co-authored-by: 絵空事スピリット <wanglichen@starrocks.com>
This commit is contained in:
mergify[bot] 2025-09-04 19:08:14 +08:00 committed by GitHub
parent 96b335c9ad
commit 419b803d98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 6 deletions

View File

@ -107,8 +107,8 @@ The parameters in the `data_desc` descriptor can be divided into three types: co
| Parameter | Required | Description |
| ---------------- | -------- | ------------------------------------------------------------ |
| column_separator | No | The characters that are used in the data file to separate fields. If you do not specify this parameter, this parameter defaults to `\t`, which indicates tab.<br/>Make sure that the column separator you specify by using this parameter is the same as the column separator used in the data file.<br/>**NOTE**<br/>For CSV data, you can use a UTF-8 string, such as a comma (,), tab, or pipe (\|), whose length does not exceed 50 bytes as a text delimiter. |
| row_delimiter | No | The characters that are used in the data file to separate rows. If you do not specify this parameter, this parameter defaults to `\n`. |
| column_separator | No | The characters that are used in the data file to separate fields. If you do not specify this parameter, this parameter defaults to `\t`, which indicates tab.<br/>Make sure that the column separator you specify by using this parameter is the same as the column separator used in the data file.<br/>**NOTE**<br/>- For CSV data, you can use a UTF-8 string, such as a comma (,), tab, or pipe (\|), whose length does not exceed 50 bytes as a text delimiter.<br />- If the data file uses consecutive non-printable characters (for example, `\r\n`) as the column separator, you must set this parameter as `\\x0D0A`. |
| row_delimiter | No | The characters that are used in the data file to separate rows. If you do not specify this parameter, this parameter defaults to `\n`.<br />**NOTE**<br />If the data file uses consecutive non-printable characters (for example, `\r\n`) as the row delimiter, you must set this parameter as `\\x0D0A`. |
| skip_header | No | Specifies whether to skip the first few rows of the data file when the data file is in CSV format. Type: INTEGER. Default value: `0`.<br />In some CSV-formatted data files, the first few rows at the beginning are used to define metadata such as column names and column data types. By setting the `skip_header` parameter, you can enable StarRocks to skip the first few rows of the data file during data loading. For example, if you set this parameter to `1`, StarRocks skips the first row of the data file during data loading.<br />The first few rows at the beginning in the data file must be separated by using the row separator that you specify in the load command. |
| trim_space | No | Specifies whether to remove spaces preceding and following column separators from the data file when the data file is in CSV format. Type: BOOLEAN. Default value: `false`.<br />For some databases, spaces are added to column separators when you export data as a CSV-formatted data file. Such spaces are called leading spaces or trailing spaces depending on their locations. By setting the `trim_space` parameter, you can enable StarRocks to remove such unnecessary spaces during data loading.<br />Note that StarRocks does not remove the spaces (including leading spaces and trailing spaces) within a field wrapped in a pair of `enclose`-specified characters. For example, the following field values use pipe (<code class="language-text">&#124;</code>) as the column separator and double quotation marks (`"`) as the `enclose`-specified character:<br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> <br /><code class="language-text">&#124;" Love StarRocks "&#124;</code> <br /><code class="language-text">&#124; "Love StarRocks" &#124;</code> <br />If you set `trim_space` to `true`, StarRocks processes the preceding field values as follows:<br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> <br /><code class="language-text">&#124;" Love StarRocks "&#124;</code> <br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> |
| enclose | No | Specifies the character that is used to wrap the field values in the data file according to [RFC4180](https://www.rfc-editor.org/rfc/rfc4180) when the data file is in CSV format. Type: single-byte character. Default value: `NONE`. The most prevalent characters are single quotation mark (`'`) and double quotation mark (`"`).<br />All special characters (including row separators and column separators) wrapped by using the `enclose`-specified character are considered normal symbols. StarRocks can do more than RFC4180 as it allows you to specify any single-byte character as the `enclose`-specified character.<br />If a field value contains an `enclose`-specified character, you can use the same character to escape that `enclose`-specified character. For example, you set `enclose` to `"`, and a field value is `a "quoted" c`. In this case, you can enter the field value as `"a ""quoted"" c"` into the data file. |
@ -466,6 +466,23 @@ curl --location-trusted -u <username>:<password> -H "label:3875" \
http://<fe_host>:<fe_http_port>/api/test_db/tbl9/_stream_load
```
#### Set `column_separator` and `row_delimiter`
Your StarRocks database `test_db` contains a table named `table10`. The table consists of three columns, which are `col1`, `col2`, and `col3` in sequence.
Your data file `example10.csv` also consists of three columns, which can be mapped in sequence onto `col1`, `col2`, and `col3` of `table10`. The columns in a data row are separated by commas (`,`), and data rows are separated by two consecutive non-printable characters `\r\n`.
If you want to load all data from `example10.csv` into `table10`, run the following command:
```Bash
curl --location-trusted -u <username>:<password> -H "label:label10" \
-H "Expect:100-continue" \
-H "column_separator:," \
-H "row_delimiter:\\x0D0A" \
-T example10.csv -XPUT \
http://<fe_host>:<fe_http_port>/api/test_db/table10/_stream_load
```
### Load JSON data
This section describes the parameter settings that you need to take note of when you load JSON data.

View File

@ -109,8 +109,8 @@ http://<fe_host>:<fe_http_port>/api/<database_name>/<table_name>/_stream_load
| パラメータ | 必須 | 説明 |
| ---------------- | ---- | ----------------------------------------------------- |
| column_separator | いいえ | データファイルでフィールドを区切るために使用される文字。指定しない場合、このパラメータはデフォルトで `\t`(タブ)になります。<br/>このパラメータで指定する列セパレータがデータファイルで使用されている列セパレータと同じであることを確認してください。<br/>**注意**<br/>CSV データの場合、カンマ (,) やタブ、パイプ (\|) などの UTF-8 文字列をテキストデリミタとして使用できますが、その長さは 50 バイトを超えてはなりません。 |
| row_delimiter | いいえ | データファイルで行を区切るために使用される文字。指定しない場合、このパラメータはデフォルトで `\n` になります。 |
| column_separator | いいえ | データファイルでフィールドを区切るために使用される文字。指定しない場合、このパラメータはデフォルトで `\t`(タブ)になります。<br/>このパラメータで指定する列セパレータがデータファイルで使用されている列セパレータと同じであることを確認してください。<br/>**注意**<br/>- CSV データの場合、カンマ (,) やタブ、パイプ (\|) などの UTF-8 文字列をテキストデリミタとして使用できますが、その長さは 50 バイトを超えてはなりません<br />- データファイルが連続した非表示文字(例:`\r\n`)を列区切り文字として使用している場合、このパラメータを `\\x0D0A` に設定する必要があります。 |
| row_delimiter | いいえ | データファイルで行を区切るために使用される文字。指定しない場合、このパラメータはデフォルトで `\n` になります。<br />**注意**<br />データファイルが連続して非表示文字(例:`\r\n`)を行区切り文字として使用している場合、このパラメータを`\\x0D0A`に設定する必要があります。 |
| skip_header | いいえ | データファイルが CSV 形式の場合、データファイルの最初の数行をスキップするかどうかを指定します。タイプ: INTEGER。デフォルト値: `0`<br />一部の CSV 形式のデータファイルでは、最初の数行が列名や列データ型などのメタデータを定義するために使用されます。`skip_header` パラメータを設定することで、StarRocks がデータロード中にデータファイルの最初の数行をスキップするようにできます。たとえば、このパラメータを `1` に設定すると、StarRocks はデータロード中にデータファイルの最初の行をスキップします。<br />データファイルの最初の数行は、ロードコマンドで指定した行セパレータで区切られている必要があります。 |
| trim_space | いいえ | データファイルが CSV 形式の場合、データファイルから列セパレータの前後のスペースを削除するかどうかを指定します。タイプ: BOOLEAN。デフォルト値: `false`<br />一部のデータベースでは、データを CSV 形式のデータファイルとしてエクスポートする際に、列セパレータにスペースが追加されます。これらのスペースは、その位置に応じて先行スペースまたは後続スペースと呼ばれます。`trim_space` パラメータを設定することで、StarRocks がデータロード中にこれらの不要なスペースを削除するようにできます。<br />StarRocks は、`enclose` で指定された文字で囲まれたフィールド内のスペース(先行スペースおよび後続スペースを含む)を削除しないことに注意してください。たとえば、次のフィールド値は、列セパレータとしてパイプ (<code class="language-text">&#124;</code>) を使用し、`enclose` で指定された文字として二重引用符 (`"`) を使用しています:<br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> <br /><code class="language-text">&#124;" Love StarRocks "&#124;</code> <br /><code class="language-text">&#124; "Love StarRocks" &#124;</code> <br />`trim_space` を `true` に設定すると、StarRocks は前述のフィールド値を次のように処理します:<br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> <br /><code class="language-text">&#124;" Love StarRocks "&#124;</code> <br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> |
| enclose | いいえ | データファイルが CSV 形式の場合、[RFC4180](https://www.rfc-editor.org/rfc/rfc4180) に従ってフィールド値を囲むために使用される文字を指定します。タイプ: 単一バイト文字。デフォルト値: `NONE`。最も一般的な文字は、単一引用符 (`'`) および二重引用符 (`"`) です。<br />`enclose` で指定された文字で囲まれたすべての特殊文字行セパレータや列セパレータを含むは通常の記号と見なされます。StarRocks は、`enclose` で指定された文字として任意の単一バイト文字を指定できるため、RFC4180 よりも多くのことができます。<br />フィールド値に `enclose` で指定された文字が含まれている場合、同じ文字を使用してその `enclose` で指定された文字をエスケープできます。たとえば、`enclose` を `"` に設定し、フィールド値が `a "quoted" c` の場合、このフィールド値をデータファイルに `"a ""quoted"" c"` として入力できます。 |
@ -468,6 +468,23 @@ curl --location-trusted -u <username>:<password> -H "label:3875" \
http://<fe_host>:<fe_http_port>/api/test_db/tbl9/_stream_load
```
#### `column_separator``row_delimiter` の設定
StarRocks データベース `test_db` には、`table10` という名前のテーブルがあります。このテーブルは、順番に `col1`、`col2`、`col3` の 3 つの列で構成されています。
データファイル `example10.csv` も 3 つの列で構成されており、`table10` の `col1`、`col2`、`col3` に順番にマッピングできます。データ行内の列はカンマ(`,`で区切られ、データ行は2つの連続した非表示文字 `\r\n` で区切られます。
`example10.csv` のすべてのデータを `table10` にロードしたい場合、次のコマンドを実行します:
```Bash
curl --location-trusted -u <username>:<password> -H "label:label10" \
-H "Expect:100-continue" \
-H "column_separator:," \
-H "row_delimiter:\\x0D0A" \
-T example10.csv -XPUT \
http://<fe_host>:<fe_http_port>/api/test_db/table10/_stream_load
```
### JSON データのロード
このセクションでは、JSON データをロードする際に注意すべきパラメータ設定を説明します。

View File

@ -106,8 +106,8 @@ http://<fe_host>:<fe_http_port>/api/<database_name>/<table_name>/_stream_load
| **参数名称** | **是否必选** | **参数说明** |
| ---------------- | ------------ | ------------------------------------------------------------ |
| column_separator | 否 | 用于指定源数据文件中的列分隔符。如果不指定该参数,则默认为 `\t`,即 Tab。必须确保这里指定的列分隔符与源数据文件中的列分隔符一致。<br />**说明**<br />StarRocks 支持设置长度最大不超过 50 个字节的 UTF-8 编码字符串作为列分隔符,包括常见的逗号 (,)、Tab 和 Pipe (\|)。 |
| row_delimiter | 否 | 用于指定源数据文件中的行分隔符。如果不指定该参数,则默认为 `\n`。 |
| column_separator | 否 | 用于指定源数据文件中的列分隔符。如果不指定该参数,则默认为 `\t`,即 Tab。必须确保这里指定的列分隔符与源数据文件中的列分隔符一致。<br />**说明**<br />- StarRocks 支持设置长度最大不超过 50 个字节的 UTF-8 编码字符串作为列分隔符,包括常见的逗号 (,)、Tab 和 Pipe (\|)。- 若数据文件使用连续的不可打印字符(例如 `\r\n`)作为列分隔符,则必须将此参数设置为 `\\x0D0A`。 |
| row_delimiter | 否 | 用于指定源数据文件中的行分隔符。如果不指定该参数,则默认为 `\n`<br />**注意**<br />如果数据文件使用连续的不可打印字符(例如 `\r\n`)作为行分隔符,则必须将此参数设置为 `\\x0D0A` |
| skip_header | 否 | 用于指定跳过 CSV 文件最开头的几行数据。取值类型INTEGER。默认值`0`。<br />在某些 CSV 文件里,最开头的几行数据会用来定义列名、列类型等元数据信息。通过设置该参数,可以使 StarRocks 在导入数据时忽略 CSV 文件的前面几行。例如,如果设置该参数为 `1`,则 StarRocks 会在导入数据时忽略 CSV 文件的第一行。<br />这里的行所使用的分隔符须与您在导入命令中所设定的行分隔符一致。 |
| trim_space | 否 | 用于指定是否去除 CSV 文件中列分隔符前后的空格。取值类型BOOLEAN。默认值`false`。<br />有些数据库在导出数据为 CSV 文件时,会在列分隔符的前后添加一些空格。根据位置的不同,这些空格可以称为“前导空格”或者“尾随空格”。通过设置该参数,可以使 StarRocks 在导入数据时删除这些不必要的空格。<br />需要注意的是StarRocks 不会去除被 `enclose` 指定字符括起来的字段内的空格(包括字段的前导空格和尾随空格)。例如,列分隔符是竖线 (<code class="language-text">&#124;</code>)`enclose` 指定的字符是双引号 (`"`)<br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> <br /><code class="language-text">&#124;" Love StarRocks "&#124;</code> <br /><code class="language-text">&#124; "Love StarRocks" &#124;</code> <br />如果设置 `trim_space``true`,则 StarRocks 处理后的结果数据如下:<br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> <br /><code class="language-text">&#124;" Love StarRocks "&#124;</code> <br /><code class="language-text">&#124;"Love StarRocks"&#124;</code> |
| enclose | 否 | 根据 [RFC4180](https://www.rfc-editor.org/rfc/rfc4180),用于指定把 CSV 文件中的字段括起来的字符。取值类型:单字节字符。默认值:`NONE`。最常用 `enclose` 字符为单引号 (`'`) 或双引号 (`"`)。<br />`enclose` 指定字符括起来的字段内的所有特殊字符(包括行分隔符、列分隔符等)均看做是普通符号。比 RFC4180 标准更进一步的是StarRocks 提供的 `enclose` 属性支持设置任意单个字节的字符。<br />如果一个字段内包含了 `enclose` 指定字符,则可以使用同样的字符对 `enclose` 指定字符进行转义。例如,在设置了`enclose` 为双引号 (`"`) 时,字段值 `a "quoted" c` 在 CSV 文件中应该写作 `"a ""quoted"" c"`。 |
@ -465,6 +465,23 @@ curl --location-trusted -u <username>:<password> -H "label:3875" \
http://<fe_host>:<fe_http_port>/api/test_db/tbl9/_stream_load
```
#### 设置 `column_separator``row_delimiter`
StarRocks 数据库 `test_db` 里的表 `table10` 包含三列,按顺序依次为 `col1`、`col2`、`col3`。
数据文件 `example10.csv` 也包含三列,按顺序一一对应 `table10` 中的三列 `col1`、`col2`、`col3`。数据行中的列以逗号(`,`)分隔,数据行之间以两个连续的不可打印字符 `\r\n` 分隔。
如果要把 `example10.csv` 中所有的数据都导入到 `table10` 中,可以执行如下命令:
```Bash
curl --location-trusted -u <username>:<password> -H "label:label10" \
-H "Expect:100-continue" \
-H "column_separator:," \
-H "row_delimiter:\\x0D0A" \
-T example10.csv -XPUT \
http://<fe_host>:<fe_http_port>/api/test_db/table10/_stream_load
```
### **导入 JSON 格式的数据**
本小节主要描述导入 JSON 格式的数据时,需要关注的一些参数配置。