pan3793 commented on code in PR #7667: URL: https://github.com/apache/kyuubi/pull/7667#discussion_r3873736241
########## docs/connector/spark/hive.md: ########## @@ -0,0 +1,166 @@ +<!-- +- Licensed to the Apache Software Foundation (ASF) under one or more +- contributor license agreements. See the NOTICE file distributed with +- this work for additional information regarding copyright ownership. +- The ASF licenses this file to You under the Apache License, Version 2.0 +- (the "License"); you may not use this file except in compliance with +- the License. You may obtain a copy of the License at +- +- http://www.apache.org/licenses/LICENSE-2.0 +- +- Unless required by applicable law or agreed to in writing, software +- distributed under the License is distributed on an "AS IS" BASIS, +- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +- See the License for the specific language governing permissions and +- limitations under the License. +--> + +# Hive + +You may know that the Apache Spark has built-in support for accessing Hive tables, it works well in most cases, +but is limited to one Hive Metastore. The Kyuubi Spark Hive connector(KSHC) implemented a Hive connector based +on Spark DataSource V2 API, supports accessing multiple Hive Metastore in a single Spark application. + +## Hive Integration + +To enable the integration of Kyuubi Spark SQL engine and Hive connector through +Spark DataSource V2 API, you need to: + +- Referencing the Hive connector [dependencies](#kshc-dependencies) +- Setting the Spark catalog [configurations](#kshc-configurations) + +(kshc-dependencies)= + +### Dependencies + +The **classpath** of Kyuubi Spark SQL engine with Hive connector supported consists of + +1. kyuubi-spark-sql-engine-{{ release }}_2.12.jar, the engine jar deployed with a Kyuubi distribution +2. a copy of Spark distribution +3. kyuubi-spark-connector-hive_2.12-{{ release }}, which can be found in the [Maven Central](https://mvnrepository.com/artifact/org.apache.kyuubi/kyuubi-spark-connector-hive) + +In order to make the Hive connector packages visible for the runtime classpath of engines, we can use one of these methods: + +1. Put the Kyuubi Hive connector packages into `$SPARK_HOME/jars` directly +2. Set `spark.jars=/path/to/kyuubi-hive-connector` + +```{note} +Starting from v1.9.2 and v1.10.0, KSHC jars available in the [Maven Central](https://mvnrepository.com/artifact/org.apache.kyuubi/kyuubi-spark-connector-hive) guarantee binary compatibility across +multiple Spark versions, so a single jar works across them without rebuilding. +``` + +(kshc-configurations)= + +### Configurations + +To activate functionality of Kyuubi Spark Hive connector, we can set the following configurations: + +```properties +spark.sql.catalog.hive_catalog org.apache.kyuubi.spark.connector.hive.HiveTableCatalog +spark.sql.catalog.hive_catalog.hive.metastore.uris thrift://metastore-host:port +spark.sql.catalog.hive_catalog.<other.hive.conf> <value> +spark.sql.catalog.hive_catalog.<other.hadoop.conf> <value> +``` + +Besides the catalog-level configurations above, the Kyuubi Spark Hive connector provides the following configurations: + +| Key | Default | Meaning | Type | Since | +|----------------------------------------------------------------|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|--------| +| `spark.sql.kyuubi.hive.connector.externalCatalog.share.policy` | `ONE_FOR_ALL` | The share policy for the external catalog. `ONE_FOR_ONE` means an external catalog is used by only one `HiveTableCatalog`, while `ONE_FOR_ALL` shares an external catalog globally across the catalogs with the same name. | string | 1.7.0 | +| `spark.sql.catalog.<catalog>.delegation.token.renewal.enabled` | `true` | Whether to enable delegation token renewal for the Kerberized Hive Metastore of this catalog. | boolean | 1.8.0 | +| `spark.sql.kyuubi.hive.connector.read.convertMetastoreParquet` | `true` | When enabled, the data source Parquet reader is used to process Parquet tables created by HiveQL syntax, instead of the Hive SerDe. | boolean | 1.11.0 | +| `spark.sql.kyuubi.hive.connector.read.convertMetastoreOrc` | `true` | When enabled, the data source ORC reader is used to process ORC tables created by HiveQL syntax, instead of the Hive SerDe. | boolean | 1.11.0 | +| `spark.sql.kyuubi.hive.connector.dropTableAsPurgeTable` | `false` | When enabled, `DROP TABLE` completely removes its data by skipping HDFS trash, equivalent to the `PURGE TABLE` command. | boolean | 1.12.0 | +| `spark.sql.catalog.<catalog>.hive.metastore.warehouse.dir` | <undefined> | The default warehouse directory for the catalog, taking precedence over the global `spark.sql.warehouse.dir` when creating a database. | string | 1.12.0 | + +```{note} +Catalog-level configurations (`spark.sql.catalog.<catalog>.*`) are captured when the catalog is +initialized, so they must be present at the Spark application bootstrap (in `spark-defaults.conf` +or via `--conf`). Setting them through `SET` after the catalog has been created does not take +effect, e.g. `SET spark.sql.catalog.<catalog>.<key>=<value>`. +``` + +## Hive Connector Operations + +Taking `CREATE NAMESPACE` as an example, + +```sql +CREATE NAMESPACE ns; +``` + +Taking `CREATE TABLE` as an example, + +```sql +CREATE TABLE hive_catalog.ns.foo ( + id bigint COMMENT 'unique id', + data string) +USING parquet; +``` + +Taking `SELECT` as an example, + +```sql +SELECT * FROM hive_catalog.ns.foo; +``` + +Taking `INSERT` as an example, + +```sql +INSERT INTO hive_catalog.ns.foo VALUES (1, 'a'), (2, 'b'), (3, 'c'); +``` + +Taking `DROP TABLE` as an example, + +```sql +DROP TABLE hive_catalog.ns.foo; +``` + +Taking `DROP NAMESPACE` as an example, + +```sql +DROP NAMESPACE hive_catalog.ns; +``` + +## Features + +Since v1.11.0, KSHC uses the data source Parquet/ORC reader to process Parquet and ORC tables +created by HiveQL syntax by default, instead of the Hive SerDe. This enables vectorized reading. +Set `spark.sql.kyuubi.hive.connector.read.convertMetastoreParquet` and +`spark.sql.kyuubi.hive.connector.read.convertMetastoreOrc` to `false` to fall back to the Hive +SerDe. + +Since v1.12.0, KSHC supports the `PURGE TABLE` command. By default, `DROP TABLE` moves the table +data to the HDFS trash. Set `spark.sql.kyuubi.hive.connector.dropTableAsPurgeTable` to `true` to +make `DROP TABLE` skip the HDFS trash and completely remove its data, behaving like `PURGE TABLE`. + +Since v1.13.0, KSHC supports Dynamic Partition Pruning (DPP) for partitioned Hive tables, which +significantly reduces the amount of data scanned when joining against large partitioned tables. +DPP is implemented by wrapping Spark's built-in `ParquetScan` / `OrcScan`. As a result, native +engines such as Gluten and Comet cannot recognize these scans by class name, so KSHC-converted Review Comment: we can promise nothing for those ecosystem projects because they use the spark private api, I would drop this statement -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
