Skip to content

Commit

Permalink
[Doc] Hive catalog supports orc and textfile formats (StarRocks#44628)
Browse files Browse the repository at this point in the history
  • Loading branch information
amber-create authored Apr 24, 2024
1 parent a857b9b commit 8729596
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 17 deletions.
32 changes: 25 additions & 7 deletions docs/en/data_source/catalog/hive_catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A Hive catalog is a kind of external catalog that is supported by StarRocks from

- Directly query data stored in Hive without the need to manually create tables.
- Use [INSERT INTO](../../sql-reference/sql-statements/data-manipulation/INSERT.md) or asynchronous materialized views (which are supported from v2.5 onwards) to process data stored in Hive and load the data into StarRocks.
- Perform operations on StarRocks to create or drop Hive databases and tables, or sink data from StarRocks tables to Parquet-formatted Hive tables by using [INSERT INTO](../../sql-reference/sql-statements/data-manipulation/INSERT.md) (this feature is supported from v3.2 onwards).
- Perform operations on StarRocks to create or drop Hive databases and tables, or sink data from StarRocks tables to Parquet-formatted (supported from v3.2 onwards) and ORC- or Textfile-formatted (supported from v3.3 onwards) Hive tables by using [INSERT INTO](../../sql-reference/sql-statements/data-manipulation/INSERT.md).

To ensure successful SQL workloads on your Hive cluster, your StarRocks cluster must be able to access the storage system and metastore of your Hive cluster. StarRocks supports the following storage systems and metastores:

Expand All @@ -25,14 +25,21 @@ To ensure successful SQL workloads on your Hive cluster, your StarRocks cluster

## Usage notes

- The file formats of Hive that StarRocks supports are Parquet, ORC, Textfile, Avro, RCFile, and SequenceFile:
- StarRocks supports queries against Hive tables in Parquet, ORC, Textfile, Avro, RCFile, and SequenceFile file formats:

- Parquet files support the following compression formats: SNAPPY, LZ4, ZSTD, GZIP, and NO_COMPRESSION. From v3.1.5 onwards, Parquet files also support the LZO compression format.
- ORC files support the following compression formats: ZLIB, SNAPPY, LZO, LZ4, ZSTD, and NO_COMPRESSION.
- Textfile files support the LZO compression format from v3.1.5 onwards.

- The data types of Hive that StarRocks does not support are INTERVAL, BINARY, and UNION. Additionally, StarRocks does not support the MAP and STRUCT data types for Textfile-formatted Hive tables.

- StarRocks supports sinking data to Parquet-formatted (supported from v3.2 onwards) and ORC- or Textfile-formatted (supported from v3.3 onwards) Hive tables:

- Parquet and ORC files support the following compression formats: NO_COMPRESSION, SNAPPY, LZ4, ZSTD, and GZIP.
- Textfile files support the NO_COMPRESSION compression format.

You can use the session variable [`connector_sink_compression_codec`](../../reference/System_variable.md#connector_sink_compression_codec) to specify the compression algorithm used for sinking data to Hive tables.

## Integration preparations

Before you create a Hive catalog, make sure your StarRocks cluster can integrate with the storage system and metastore of your Hive cluster.
Expand Down Expand Up @@ -943,7 +950,9 @@ DROP DATABASE <database_name>
## Create a Hive table
Similar to the internal databases of StarRocks, if you have the [CREATE TABLE](../../administration/user_privs/privilege_item.md#database) privilege on a Hive database, you can use the [CREATE TABLE](../../sql-reference/sql-statements/data-definition/CREATE_TABLE.md), [CREATE TABLE AS SELECT (CTAS)](../../sql-reference/sql-statements/data-definition/CREATE_TABLE_AS_SELECT.md), or [CREATE TABLE LIKE](../../sql-reference/sql-statements/data-definition/CREATE_TABLE_LIKE.md) statement to create a managed table in that Hive database. This feature is supported from v3.2 onwards.
Similar to the internal databases of StarRocks, if you have the [CREATE TABLE](../../administration/user_privs/privilege_item.md#database) privilege on a Hive database, you can use the [CREATE TABLE](../../sql-reference/sql-statements/data-definition/CREATE_TABLE.md), [CREATE TABLE AS SELECT (CTAS)](../../sql-reference/sql-statements/data-definition/CREATE_TABLE_AS_SELECT.md), or [CREATE TABLE LIKE](../../sql-reference/sql-statements/data-definition/CREATE_TABLE_LIKE.md) statement to create a managed table in that Hive database.
This feature is supported since v3.2 in which version StarRocks only supports creating Parquet-formatted Hive tables. From v3.3 onwards, StarRocks also supports creating ORC- and Textfile-formatted Hive tables.
:::note
Expand Down Expand Up @@ -1010,11 +1019,13 @@ The following table describes a few key properties.
| **Property** | **Description** |
| ----------------- | ------------------------------------------------------------ |
| location | The file path in which you want to create the managed table. When you use HMS as metastore, you do not need to specify the `location` parameter, because StarRocks will create the table in the default file path of the current Hive catalog. When you use AWS Glue as metadata service:<ul><li>If you have specified the `location` parameter for the database in which you want to create the table, you do not need to specify the `location` parameter for the table. As such, the table defaults to the file path of the database to which it belongs. </li><li>If you have not specified the `location` for the database in which you want to create the table, you must specify the `location` parameter for the table.</li></ul> |
| file_format | The file format of the managed table. Only the Parquet format is supported. Default value: `parquet`. |
| compression_codec | The compression algorithm used for the managed table. The supported compression algorithms are SNAPPY, GZIP, ZSTD, and LZ4. Default value: `gzip`. |
| file_format | The file format of the managed table. Supported file formats are Parquet, ORC, and Textfile. ORC and Textfile formats are supported from v3.3 onwards. Valid values: `parquet`, `orc`, and `textfile`. Default value: `parquet`. |
| compression_codec | The compression algorithm used for the managed table. This property is deprecated in v3.2.3, since which version the compression algorithm used for sinking data to Hive tables is uniformly controlled by the session variable [connector_sink_compression_codec](../../reference/System_variable.md#connector_sink_compression_codec). |
### Examples
The following DDLs use the default file format Parquet as an example.
1. Create a non-partitioned table named `unpartition_tbl`. The table consists of two columns, `id` and `score`, as shown below:
```SQL
Expand Down Expand Up @@ -1047,11 +1058,16 @@ The following table describes a few key properties.
## Sink data to a Hive table
Similar to the internal tables of StarRocks, if you have the [INSERT](../../administration/user_privs/privilege_item.md#table) privilege on a Hive table (which can be a managed table or an external table), you can use the [INSERT](../../sql-reference/sql-statements/data-manipulation/INSERT.md) statement to sink the data of a StarRocks table to that Hive table (currently only Parquet-formatted Hive tables are supported). This feature is supported from v3.2 onwards. Sinking data to external tables is disabled by default. To sink data to external tables, you must set the [system variable `ENABLE_WRITE_HIVE_EXTERNAL_TABLE`](../../reference/System_variable.md) to `true`.
Similar to the internal tables of StarRocks, if you have the [INSERT](../../administration/user_privs/privilege_item.md#table) privilege on a Hive table (which can be a managed table or an external table), you can use the [INSERT](../../sql-reference/sql-statements/data-manipulation/INSERT.md) statement to sink the data of a StarRocks table to that Hive table.
This feature is supported since v3.2 in which version data can be sunk only to Parquet-formatted Hive tables. From v3.3 onwards, StarRocks also supports sinking data to ORC- and Textfile-formatted Hive tables.
Note that sinking data to external tables is disabled by default. To sink data to external tables, you must set the [system variable `ENABLE_WRITE_HIVE_EXTERNAL_TABLE`](../../reference/System_variable.md) to `true`.
:::note
You can grant and revoke privileges by using [GRANT](../../sql-reference/sql-statements/account-management/GRANT.md) and [REVOKE](../../sql-reference/sql-statements/account-management/REVOKE.md).
- You can grant and revoke privileges by using [GRANT](../../sql-reference/sql-statements/account-management/GRANT.md) and [REVOKE](../../sql-reference/sql-statements/account-management/REVOKE.md).
- You can use the session variable [connector_sink_compression_codec](../../reference/System_variable.md#connector_sink_compression_codec) to specify the compression algorithm used for sinking data to Hive tables.
:::
Expand Down Expand Up @@ -1088,6 +1104,8 @@ PARTITION (par_col1=<value> [, par_col2=<value>...])
### Examples
The following DMLs use the default file format Parquet as an example.
1. Insert three data rows into the `partition_tbl_1` table:
```SQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Optional value: `mysql`, `elasticsearch`, `hive`, `jdbc` (2.3 and later), `icebe

**From v3.1 onwards, StarRocks supports creating Parquet-formatted tables in Iceberg catalogs, and you can insert data to these Parquet-formatted Iceberg tables by using [INSERT INTO](../data-manipulation/INSERT.md). See [Create an Iceberg table](../../../data_source/catalog/iceberg_catalog.md#create-an-iceberg-table).**

**From v3.2 onwards, StarRocks supports creating Parquet-formatted tables in Hive catalogs, and you can insert data to these Parquet-formatted Hive tables by using [INSERT INTO](../data-manipulation/INSERT.md). See [Create a Hive table](../../../data_source/catalog/hive_catalog.md#create-a-hive-table).**
**From v3.2 onwards, StarRocks supports creating Parquet-formatted tables in Hive catalogs, and supports sinking data to these Parquet-formatted Hive tables by using [INSERT INTO](../data-manipulation/INSERT.md). From v3.3 onwards, StarRocks supports creating ORC- and Textfile-formatted tables in Hive catalogs, and supports sinking data to these ORC- and Textfile-formatted Hive tables by using [INSERT INTO](../data-manipulation/INSERT.md). For more information, see [Create a Hive table](../../../data_source/catalog/hive_catalog.md#create-a-hive-table) and [Sink data to a Hive table](../../../data_source/catalog/hive_catalog.md#sink-data-to-a-hive-table).**

- For MySQL, specify the following properties:

Expand Down
34 changes: 26 additions & 8 deletions docs/zh/data_source/catalog/hive_catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Hive Catalog 是一种 External Catalog,自 2.3 版本开始支持。通过 Hi

- 无需手动建表,通过 Hive Catalog 直接查询 Hive 内的数据。
- 通过 [INSERT INTO](../../sql-reference/sql-statements/data-manipulation/INSERT.md) 或异步物化视图(3.1 版本及以上)将 Hive 内的数据进行加工建模,并导入至 StarRocks。
- 在 StarRocks 侧创建或删除 Hive 库表,或通过 [INSERT INTO](../../sql-reference/sql-statements/data-manipulation/INSERT.md) 把 StarRocks 表数据写入到 Parquet 格式的 Hive 表中(3.2 版本及以上)。
- 在 StarRocks 侧创建或删除 Hive 库表,或通过 [INSERT INTO](../../sql-reference/sql-statements/data-manipulation/INSERT.md) 把 StarRocks 表数据写入到 Parquet 格式(3.2 版本及以上)、以及 ORC 或 Textfile 格式(3.3 版本及以上)的 Hive 表中

为保证正常访问 Hive 内的数据,StarRocks 集群必须能够访问 Hive 集群的存储系统和元数据服务。目前 StarRocks 支持以下存储系统和元数据服务:

Expand All @@ -25,13 +25,20 @@ Hive Catalog 是一种 External Catalog,自 2.3 版本开始支持。通过 Hi

## 使用说明

- StarRocks 查询 Hive 数据时,支持 Parquet、ORC、Textfile、Avro、RCFile、SequenceFile 文件格式,其中:
- StarRocks 查询 Hive 内的数据时,支持 Parquet、ORC、Textfile、Avro、RCFile、SequenceFile 文件格式,其中:

- Parquet 文件支持 SNAPPY、LZ4、ZSTD、GZIP 和 NO_COMPRESSION 压缩格式。自 v3.1.5 起,Parquet 文件还支持 LZO 压缩格式。
- ORC 文件支持 ZLIB、SNAPPY、LZO、LZ4、ZSTD 和 NO_COMPRESSION 压缩格式。
- Textfile 文件从 v3.1.5 起支持 LZO 压缩格式。

- StarRocks 查询 Hive 数据时,不支持 INTERVAL、BINARY 和 UNION 三种数据类型。此外,对于 Textfile 格式的 Hive 表,StarRocks 不支持 MAP、STRUCT 数据类型。
- StarRocks 查询 Hive 内的数据时,不支持 INTERVAL、BINARY 和 UNION 三种数据类型。此外,对于 Textfile 格式的 Hive 表,StarRocks 不支持 MAP、STRUCT 数据类型。

- StarRocks 写入数据到 Hive 时,支持 Parquet(3.2 版本及以上)、以及 ORC 或 Textfile(3.3 版本及以上)文件格式,其中:

- Parquet 和 ORC 文件支持 NO_COMPRESSION、SNAPPY、LZ4、ZSTD 和 GZIP 压缩格式。
- Textfile 文件支持 NO_COMPRESSION 压缩格式。

您可以通过系统变量 [`connector_sink_compression_codec`](../../reference/System_variable.md#connector_sink_compression_codec) 来设置写入到 Hive 表时的压缩算法。

## 准备工作

Expand Down Expand Up @@ -952,7 +959,9 @@ DROP DATABASE <database_name>

## 创建 Hive 表

同 StarRocks 内部数据库一致,如果您拥有 Hive 数据库的 [CREATE TABLE](../../administration/user_privs/privilege_item.md#数据库权限-database) 权限,那么您可以使用 [CREATE TABLE](../../sql-reference/sql-statements/data-definition/CREATE_TABLE.md)、[CREATE TABLE AS SELECT (CTAS)](../../sql-reference/sql-statements/data-definition/CREATE_TABLE_AS_SELECT.md)、或 [CREATE TABLE LIKE](../../sql-reference/sql-statements/data-definition/CREATE_TABLE_LIKE.md) 在该 Hive 数据库下创建 Managed Table。本功能自 3.2 版本起开始支持。
同 StarRocks 内部数据库一致,如果您拥有 Hive 数据库的 [CREATE TABLE](../../administration/user_privs/privilege_item.md#数据库权限-database) 权限,那么您可以使用 [CREATE TABLE](../../sql-reference/sql-statements/data-definition/CREATE_TABLE.md)、[CREATE TABLE AS SELECT (CTAS)](../../sql-reference/sql-statements/data-definition/CREATE_TABLE_AS_SELECT.md)、或 [CREATE TABLE LIKE](../../sql-reference/sql-statements/data-definition/CREATE_TABLE_LIKE.md) 在该 Hive 数据库下创建 Managed Table。

本功能自 3.2 版本起开始支持,彼时只支持创建 Parquet 格式的 Hive 表。自 3.3 版本起,该功能还支持创建 ORC 及 Textfile 格式的 Hive 表。

:::note

Expand Down Expand Up @@ -1019,11 +1028,13 @@ PARTITION BY (par_col1[, par_col2...])
| **属性** | **描述** |
| ----------------- | ------------------------------------------------------------ |
| location | Managed Table 所在的文件路径。使用 HMS 作为元数据服务时,您无需指定 `location` 参数。使用 AWS Glue 作为元数据服务时:<ul><li>如果在创建当前数据库时指定了 `location` 参数,那么在当前数据库下建表时不需要再指定 `location` 参数,StarRocks 默认把表建在当前数据库所在的文件路径下。</li><li>如果在创建当前数据库时没有指定 `location` 参数,那么在当前数据库建表时必须指定 `location` 参数。</li></ul> |
| file_format | Managed Table 的文件格式。当前仅支持 Parquet 格式。默认值:`parquet`。 |
| compression_codec | Managed Table 的压缩格式。当前支持 SNAPPY、GZIP、ZSTD 和 LZ4。默认值:`gzip`。 |
| file_format | Managed Table 的文件格式。当前支持 Parquet、ORC、Textfile 文件格式,其中 ORC 和 Textfile 文件格式自 3.3 版本起支持。取值范围:`parquet``orc``textfile`。默认值:`parquet`。 |
| compression_codec | Managed Table 的压缩格式。该属性自 3.2.3 版本起弃用,此后写入 Hive 表时的压缩算法统一由会话变量 [connector_sink_compression_codec](../../reference/System_variable.md#connector_sink_compression_codec) 控制。 |

### 示例

以下建表语句以默认的 Parquet 格式为例。

1. 创建非分区表 `unpartition_tbl`,包含 `id``score` 两列,如下所示:

```SQL
Expand Down Expand Up @@ -1056,11 +1067,16 @@ PARTITION BY (par_col1[, par_col2...])

## 向 Hive 表中插入数据

同 StarRocks 内表一致,如果您拥有 Hive 表(Managed Table 或 External Table)的 [INSERT](../../administration/user_privs/privilege_item.md#表权限-table) 权限,那么您可以使用 [INSERT](../../sql-reference/sql-statements/data-manipulation/INSERT.md) 将 StarRocks 表数据写入到该 Hive 表中(当前仅支持写入到 Parquet 格式的 Hive 表)。本功能自 3.2 版本起开始支持。需要注意的是,写数据到 External Table 的功能默认是关闭的,您可以通过[系统变量 ENABLE_WRITE_HIVE_EXTERNAL_TABLE](../../reference/System_variable.md) 打开。
同 StarRocks 内表一致,如果您拥有 Hive 表(Managed Table 或 External Table)的 [INSERT](../../administration/user_privs/privilege_item.md#表权限-table) 权限,那么您可以使用 [INSERT](../../sql-reference/sql-statements/data-manipulation/INSERT.md) 将 StarRocks 表数据写入到该 Hive 表中。

本功能自 3.2 版本起开始支持,彼时只支持写入到 Parquet 格式的 Hive 表。自 3.3 版本起,该功能还支持写入到 ORC 及 Textfile 格式的 Hive 表。

需要注意的是,写数据到 External Table 的功能默认是关闭的,您需要通过[系统变量 ENABLE_WRITE_HIVE_EXTERNAL_TABLE](../../reference/System_variable.md) 打开。

:::note

您可以通过 [GRANT](../../sql-reference/sql-statements/account-management/GRANT.md) 和 [REVOKE](../../sql-reference/sql-statements/account-management/REVOKE.md) 操作对用户和角色进行权限的赋予和收回。
- 您可以通过 [GRANT](../../sql-reference/sql-statements/account-management/GRANT.md) 和 [REVOKE](../../sql-reference/sql-statements/account-management/REVOKE.md) 操作对用户和角色进行权限的赋予和收回。
- 您可以通过会话变量 [connector_sink_compression_codec](../../reference/System_variable.md#connector_sink_compression_codec) 来指定写入 Hive 表时的压缩算法。

:::

Expand Down Expand Up @@ -1097,6 +1113,8 @@ PARTITION (par_col1=<value> [, par_col2=<value>...])

### 示例

以下写入语句以默认的 Parquet 格式为例。

1. 向表 `partition_tbl_1` 中插入如下三行数据:

```SQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ INDEX index_name (col_name[, col_name, ...]) [USING BITMAP] [COMMENT '']

**从 3.1 版本起,支持直接在 Iceberg catalog 内创建表(当前仅支持 Parquet 格式的表),您可以通过 [INSERT INTO](../data-manipulation/INSERT.md) 把数据插入到 Iceberg 表中。参见 [创建 Iceberg 表](../../../data_source/catalog/iceberg_catalog.md#创建-iceberg-表)**

**从 3.2 版本起,支持直接在 Hive catalog 内创建表(当前仅支持 Parquet 格式的表),您可以通过 [INSERT INTO](../data-manipulation/INSERT.md) 把数据插入到 Hive 表中。参见 [创建 Hive 表](../../../data_source/catalog/hive_catalog.md#创建-hive-表)**
**从 3.2 版本起,支持直接在 Hive Catalog 内创建 Parquet 格式的表,并支持通过 [INSERT INTO](../data-manipulation/INSERT.md) 把数据插入到 Parquet 格式的 Hive 表中。从 3.3 版本起,支持直接在 Hive Catalog 中创建 ORC 及 Textfile 格式的表,并支持通过 [INSERT INTO](../data-manipulation/INSERT.md) 把数据插入到 ORC 及 Textfile 格式的 Hive 表中。参见[创建 Hive 表](../../../data_source/catalog/hive_catalog.md#创建-hive-表)[向 Hive 表中插入数据](../../../data_source/catalog/hive_catalog.md#向-hive-表中插入数据)**

1. 如果是 mysql,则需要在 properties 提供以下信息:

Expand Down

0 comments on commit 8729596

Please sign in to comment.