You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by bl...@apache.org on 2019/12/16 18:35:36 UTC
[flink] branch release-1.10 updated: [FLINK-15263][hive][doc] add
dedicated page for HiveCatalog
This is an automated email from the ASF dual-hosted git repository.
bli pushed a commit to branch release-1.10
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.10 by this push:
new 1d41cae [FLINK-15263][hive][doc] add dedicated page for HiveCatalog
1d41cae is described below
commit 1d41caee1a2cb4ade9039a66bf9bb273107393e1
Author: bowen.li <bo...@gmail.com>
AuthorDate: Sun Dec 15 00:44:22 2019 -0800
[FLINK-15263][hive][doc] add dedicated page for HiveCatalog
this closes #10581.
---
docs/dev/table/hive/hive_catalog.md | 248 +++++++++++++++++++++++++++++++++
docs/dev/table/hive/hive_catalog.zh.md | 248 +++++++++++++++++++++++++++++++++
docs/dev/table/hive/index.md | 25 +++-
docs/dev/table/hive/index.zh.md | 25 +++-
4 files changed, 536 insertions(+), 10 deletions(-)
diff --git a/docs/dev/table/hive/hive_catalog.md b/docs/dev/table/hive/hive_catalog.md
new file mode 100644
index 0000000..81b3b1e
--- /dev/null
+++ b/docs/dev/table/hive/hive_catalog.md
@@ -0,0 +1,248 @@
+---
+title: "HiveCatalog"
+nav-parent_id: hive_tableapi
+nav-pos: 1
+---
+<!--
+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 Metastore has evolved into the de facto metadata hub over the years in Hadoop ecosystem. Many companies have a single
+Hive Metastore service instance in their production to manage all of their metadata, either Hive metadata or non-Hive metadata,
+ as the source of truth.
+
+For users who have both Hive and Flink deployments, `HiveCatalog` enables them to use Hive Metastore to manage Flink's metadata.
+
+For users who have just Flink deployment, `HiveCatalog` is the only persistent catalog provided out-of-box by Flink.
+Without a persistent catalog, users using [Flink SQL DDL]({{ site.baseurl }}/dev/table/sql.html#specifying-a-ddl) have to repeatedly
+create meta-objects like a Kafka table in each session, which wastes a lot of time. `HiveCatalog` fills this gap by empowering
+users to create tables and other meta-objects only once, and reference and manage them with convenience later on across sessions.
+
+
+## Set up HiveCatalog
+
+### Dependencies
+
+Setting up a `HiveCatalog` in Flink requires the same [dependencies]({{ site.baseurl }}/dev/table/hive/#dependencies)
+as those of an overall Flink-Hive integration.
+
+### Configuration
+
+Setting up a `HiveCatalog` in Flink requires the same [configuration]({{ site.baseurl }}/dev/table/hive/#connecting-to-hive)
+as those of an overall Flink-Hive integration.
+
+
+## How to use HiveCatalog
+
+Once configured properly, `HiveCatalog` should just work out of box. Users can create Flink meta-objects with DDL, and shoud
+see them immediately afterwards.
+
+### Example
+
+We will walk through a simple example here.
+
+#### step 1: set up a Hive Metastore
+
+Have a Hive Metastore running.
+
+Here, we set up a local Hive Metastore and our `hive-site.xml` file in local path `/opt/hive-conf/hive-site.xml`.
+We have some configs like the following:
+
+{% highlight xml %}
+
+<configuration>
+ <property>
+ <name>javax.jdo.option.ConnectionURL</name>
+ <value>jdbc:mysql://localhost/metastore?createDatabaseIfNotExist=true</value>
+ <description>metadata is stored in a MySQL server</description>
+ </property>
+
+ <property>
+ <name>javax.jdo.option.ConnectionDriverName</name>
+ <value>com.mysql.jdbc.Driver</value>
+ <description>MySQL JDBC driver class</description>
+ </property>
+
+ <property>
+ <name>javax.jdo.option.ConnectionUserName</name>
+ <value>...</value>
+ <description>user name for connecting to mysql server</description>
+ </property>
+
+ <property>
+ <name>javax.jdo.option.ConnectionPassword</name>
+ <value>...</value>
+ <description>password for connecting to mysql server</description>
+ </property>
+
+ <property>
+ <name>hive.metastore.uris</name>
+ <value>thrift://localhost:9083</value>
+ <description>IP address (or fully-qualified domain name) and port of the metastore host</description>
+ </property>
+
+ <property>
+ <name>hive.metastore.schema.verification</name>
+ <value>true</value>
+ </property>
+
+</configuration>
+{% endhighlight %}
+
+
+Test connection to the HMS with Hive Cli. Running some commands, we can see we have a database named `default` and there's no table in it.
+
+
+{% highlight bash %}
+
+hive> show databases;
+OK
+default
+Time taken: 0.032 seconds, Fetched: 1 row(s)
+
+hive> show tables;
+OK
+Time taken: 0.028 seconds, Fetched: 0 row(s)
+{% endhighlight %}
+
+
+#### step 2: configure Flink cluster and SQL CLI
+
+Add all Hive dependencies to `/lib` dir in Flink distribution, and modify SQL CLI's yaml config file `sql-cli-defaults.yaml` as following:
+
+{% highlight yaml %}
+
+execution:
+ planner: blink
+ type: streaming
+ ...
+ current-catalog: myhive # set the HiveCatalog as the current catalog of the session
+ current-database: mydatabase
+
+catalogs:
+ - name: myhive
+ type: hive
+ hive-conf-dir: /opt/hive-conf # contains hive-site.xml
+ hive-version: 2.3.4
+{% endhighlight %}
+
+
+#### step 3: set up a Kafka cluster
+
+Bootstrap a local Kafka 2.3.0 cluster with a topic named "test", and produce some simple data to the topic as tuple of name and age.
+
+{% highlight bash %}
+
+localhost$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
+>tom,15
+>john,21
+
+{% endhighlight %}
+
+
+These message can be seen by starting a Kafka console consumer.
+
+{% highlight bash %}
+localhost$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
+
+tom,15
+john,21
+
+{% endhighlight %}
+
+
+#### step 4: start SQL Client, and create a Kafka table with Flink SQL DDL
+
+Start Flink SQL Client, create a simple Kafka 2.3.0 table via DDL, and verify its schema.
+
+{% highlight bash %}
+
+Flink SQL> CREATE TABLE mykafka (name String, age Int) WITH (
+ 'connector.type' = 'kafka',
+ 'connector.version' = 'universal',
+ 'connector.topic' = 'test',
+ 'connector.properties.zookeeper.connect' = 'localhost:2181',
+ 'connector.properties.bootstrap.servers' = 'localhost:9092',
+ 'format.type' = 'csv',
+ 'update-mode' = 'append'
+);
+[INFO] Table has been created.
+
+Flink SQL> DESCRIBE mykafka;
+root
+ |-- name: STRING
+ |-- age: INT
+
+{% endhighlight %}
+
+Verify the table from Hive side via Hive Cli:
+
+{% highlight bash %}
+hive> show tables;
+OK
+mykafka
+Time taken: 0.038 seconds, Fetched: 1 row(s)
+
+hive> describe mykafka;
+OK
+name string
+age int
+Time taken: 0.056 seconds, Fetched: 2 row(s)
+
+{% endhighlight %}
+
+
+#### step 5: run Flink SQL to query the Kakfa table
+
+Run a simple select query from Flink SQL Client in a Flink cluster, either standalone or yarn-session.
+
+{% highlight bash %}
+Flink SQL> select * from mykafka;
+
+{% endhighlight %}
+
+
+Produce some more messages in the Kafka topic
+
+{% highlight bash %}
+localhost$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
+
+tom,15
+john,21
+kitty,30
+amy,24
+kaiky,18
+
+{% endhighlight %}
+
+
+You should see results produced by Flink in SQL Client now, as:
+
+
+{% highlight bash %}
+ SQL Query Result (Table)
+ Refresh: 1 s Page: Last of 1
+
+ name age
+ tom 15
+ john 21
+ kitty 30
+ amy 24
+ kaiky 18
+
+{% endhighlight %}
diff --git a/docs/dev/table/hive/hive_catalog.zh.md b/docs/dev/table/hive/hive_catalog.zh.md
new file mode 100644
index 0000000..81b3b1e
--- /dev/null
+++ b/docs/dev/table/hive/hive_catalog.zh.md
@@ -0,0 +1,248 @@
+---
+title: "HiveCatalog"
+nav-parent_id: hive_tableapi
+nav-pos: 1
+---
+<!--
+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 Metastore has evolved into the de facto metadata hub over the years in Hadoop ecosystem. Many companies have a single
+Hive Metastore service instance in their production to manage all of their metadata, either Hive metadata or non-Hive metadata,
+ as the source of truth.
+
+For users who have both Hive and Flink deployments, `HiveCatalog` enables them to use Hive Metastore to manage Flink's metadata.
+
+For users who have just Flink deployment, `HiveCatalog` is the only persistent catalog provided out-of-box by Flink.
+Without a persistent catalog, users using [Flink SQL DDL]({{ site.baseurl }}/dev/table/sql.html#specifying-a-ddl) have to repeatedly
+create meta-objects like a Kafka table in each session, which wastes a lot of time. `HiveCatalog` fills this gap by empowering
+users to create tables and other meta-objects only once, and reference and manage them with convenience later on across sessions.
+
+
+## Set up HiveCatalog
+
+### Dependencies
+
+Setting up a `HiveCatalog` in Flink requires the same [dependencies]({{ site.baseurl }}/dev/table/hive/#dependencies)
+as those of an overall Flink-Hive integration.
+
+### Configuration
+
+Setting up a `HiveCatalog` in Flink requires the same [configuration]({{ site.baseurl }}/dev/table/hive/#connecting-to-hive)
+as those of an overall Flink-Hive integration.
+
+
+## How to use HiveCatalog
+
+Once configured properly, `HiveCatalog` should just work out of box. Users can create Flink meta-objects with DDL, and shoud
+see them immediately afterwards.
+
+### Example
+
+We will walk through a simple example here.
+
+#### step 1: set up a Hive Metastore
+
+Have a Hive Metastore running.
+
+Here, we set up a local Hive Metastore and our `hive-site.xml` file in local path `/opt/hive-conf/hive-site.xml`.
+We have some configs like the following:
+
+{% highlight xml %}
+
+<configuration>
+ <property>
+ <name>javax.jdo.option.ConnectionURL</name>
+ <value>jdbc:mysql://localhost/metastore?createDatabaseIfNotExist=true</value>
+ <description>metadata is stored in a MySQL server</description>
+ </property>
+
+ <property>
+ <name>javax.jdo.option.ConnectionDriverName</name>
+ <value>com.mysql.jdbc.Driver</value>
+ <description>MySQL JDBC driver class</description>
+ </property>
+
+ <property>
+ <name>javax.jdo.option.ConnectionUserName</name>
+ <value>...</value>
+ <description>user name for connecting to mysql server</description>
+ </property>
+
+ <property>
+ <name>javax.jdo.option.ConnectionPassword</name>
+ <value>...</value>
+ <description>password for connecting to mysql server</description>
+ </property>
+
+ <property>
+ <name>hive.metastore.uris</name>
+ <value>thrift://localhost:9083</value>
+ <description>IP address (or fully-qualified domain name) and port of the metastore host</description>
+ </property>
+
+ <property>
+ <name>hive.metastore.schema.verification</name>
+ <value>true</value>
+ </property>
+
+</configuration>
+{% endhighlight %}
+
+
+Test connection to the HMS with Hive Cli. Running some commands, we can see we have a database named `default` and there's no table in it.
+
+
+{% highlight bash %}
+
+hive> show databases;
+OK
+default
+Time taken: 0.032 seconds, Fetched: 1 row(s)
+
+hive> show tables;
+OK
+Time taken: 0.028 seconds, Fetched: 0 row(s)
+{% endhighlight %}
+
+
+#### step 2: configure Flink cluster and SQL CLI
+
+Add all Hive dependencies to `/lib` dir in Flink distribution, and modify SQL CLI's yaml config file `sql-cli-defaults.yaml` as following:
+
+{% highlight yaml %}
+
+execution:
+ planner: blink
+ type: streaming
+ ...
+ current-catalog: myhive # set the HiveCatalog as the current catalog of the session
+ current-database: mydatabase
+
+catalogs:
+ - name: myhive
+ type: hive
+ hive-conf-dir: /opt/hive-conf # contains hive-site.xml
+ hive-version: 2.3.4
+{% endhighlight %}
+
+
+#### step 3: set up a Kafka cluster
+
+Bootstrap a local Kafka 2.3.0 cluster with a topic named "test", and produce some simple data to the topic as tuple of name and age.
+
+{% highlight bash %}
+
+localhost$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
+>tom,15
+>john,21
+
+{% endhighlight %}
+
+
+These message can be seen by starting a Kafka console consumer.
+
+{% highlight bash %}
+localhost$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
+
+tom,15
+john,21
+
+{% endhighlight %}
+
+
+#### step 4: start SQL Client, and create a Kafka table with Flink SQL DDL
+
+Start Flink SQL Client, create a simple Kafka 2.3.0 table via DDL, and verify its schema.
+
+{% highlight bash %}
+
+Flink SQL> CREATE TABLE mykafka (name String, age Int) WITH (
+ 'connector.type' = 'kafka',
+ 'connector.version' = 'universal',
+ 'connector.topic' = 'test',
+ 'connector.properties.zookeeper.connect' = 'localhost:2181',
+ 'connector.properties.bootstrap.servers' = 'localhost:9092',
+ 'format.type' = 'csv',
+ 'update-mode' = 'append'
+);
+[INFO] Table has been created.
+
+Flink SQL> DESCRIBE mykafka;
+root
+ |-- name: STRING
+ |-- age: INT
+
+{% endhighlight %}
+
+Verify the table from Hive side via Hive Cli:
+
+{% highlight bash %}
+hive> show tables;
+OK
+mykafka
+Time taken: 0.038 seconds, Fetched: 1 row(s)
+
+hive> describe mykafka;
+OK
+name string
+age int
+Time taken: 0.056 seconds, Fetched: 2 row(s)
+
+{% endhighlight %}
+
+
+#### step 5: run Flink SQL to query the Kakfa table
+
+Run a simple select query from Flink SQL Client in a Flink cluster, either standalone or yarn-session.
+
+{% highlight bash %}
+Flink SQL> select * from mykafka;
+
+{% endhighlight %}
+
+
+Produce some more messages in the Kafka topic
+
+{% highlight bash %}
+localhost$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
+
+tom,15
+john,21
+kitty,30
+amy,24
+kaiky,18
+
+{% endhighlight %}
+
+
+You should see results produced by Flink in SQL Client now, as:
+
+
+{% highlight bash %}
+ SQL Query Result (Table)
+ Refresh: 1 s Page: Last of 1
+
+ name age
+ tom 15
+ john 21
+ kitty 30
+ amy 24
+ kaiky 18
+
+{% endhighlight %}
diff --git a/docs/dev/table/hive/index.md b/docs/dev/table/hive/index.md
index 879e9e9..28cc118 100644
--- a/docs/dev/table/hive/index.md
+++ b/docs/dev/table/hive/index.md
@@ -238,11 +238,14 @@ but users can pick their own hadoop version, as long as it's compatible with Had
## Connecting To Hive
-Connect to an existing Hive installation using the Hive [Catalog]({{ site.baseurl }}/dev/table/catalogs.html) through the table environment or YAML configuration.
+Connect to an existing Hive installation using the [catalog interface]({{ site.baseurl }}/dev/table/catalogs.html)
+and [HiveCatalog]({{ site.baseurl }}/dev/table/hive/hive_catalog.html) through the table environment or YAML configuration.
If the `hive-conf/hive-site.xml` file is stored in remote storage system, users should download
the hive configuration file to their local environment first.
+Take Hive version 2.3.4 for example:
+
<div class="codetabs" markdown="1">
<div data-lang="Java" markdown="1">
{% highlight java %}
@@ -250,10 +253,13 @@ the hive configuration file to their local environment first.
String name = "myhive";
String defaultDatabase = "mydatabase";
String hiveConfDir = "/opt/hive-conf"; // a local path
-String version = "2.3.4"; // or 1.2.1
+String version = "2.3.4";
HiveCatalog hive = new HiveCatalog(name, defaultDatabase, hiveConfDir, version);
tableEnv.registerCatalog("myhive", hive);
+
+// set the HiveCatalog as the current catalog of the session
+tableEnv.useCatalog("myhive");
{% endhighlight %}
</div>
<div data-lang="Scala" markdown="1">
@@ -262,20 +268,29 @@ tableEnv.registerCatalog("myhive", hive);
val name = "myhive"
val defaultDatabase = "mydatabase"
val hiveConfDir = "/opt/hive-conf" // a local path
-val version = "2.3.4" // or 1.2.1
+val version = "2.3.4"
val hive = new HiveCatalog(name, defaultDatabase, hiveConfDir, version)
tableEnv.registerCatalog("myhive", hive)
+
+// set the HiveCatalog as the current catalog of the session
+tableEnv.useCatalog("myhive")
{% endhighlight %}
</div>
<div data-lang="YAML" markdown="1">
{% highlight yaml %}
+
+execution:
+ planner: blink
+ ...
+ current-catalog: myhive # set the HiveCatalog as the current catalog of the session
+ current-database: mydatabase
+
catalogs:
- name: myhive
type: hive
- property-version: 1
hive-conf-dir: /opt/hive-conf
- hive-version: 2.3.4 # or 1.2.1
+ hive-version: 2.3.4
{% endhighlight %}
</div>
</div>
diff --git a/docs/dev/table/hive/index.zh.md b/docs/dev/table/hive/index.zh.md
index 879e9e9..28cc118 100644
--- a/docs/dev/table/hive/index.zh.md
+++ b/docs/dev/table/hive/index.zh.md
@@ -238,11 +238,14 @@ but users can pick their own hadoop version, as long as it's compatible with Had
## Connecting To Hive
-Connect to an existing Hive installation using the Hive [Catalog]({{ site.baseurl }}/dev/table/catalogs.html) through the table environment or YAML configuration.
+Connect to an existing Hive installation using the [catalog interface]({{ site.baseurl }}/dev/table/catalogs.html)
+and [HiveCatalog]({{ site.baseurl }}/dev/table/hive/hive_catalog.html) through the table environment or YAML configuration.
If the `hive-conf/hive-site.xml` file is stored in remote storage system, users should download
the hive configuration file to their local environment first.
+Take Hive version 2.3.4 for example:
+
<div class="codetabs" markdown="1">
<div data-lang="Java" markdown="1">
{% highlight java %}
@@ -250,10 +253,13 @@ the hive configuration file to their local environment first.
String name = "myhive";
String defaultDatabase = "mydatabase";
String hiveConfDir = "/opt/hive-conf"; // a local path
-String version = "2.3.4"; // or 1.2.1
+String version = "2.3.4";
HiveCatalog hive = new HiveCatalog(name, defaultDatabase, hiveConfDir, version);
tableEnv.registerCatalog("myhive", hive);
+
+// set the HiveCatalog as the current catalog of the session
+tableEnv.useCatalog("myhive");
{% endhighlight %}
</div>
<div data-lang="Scala" markdown="1">
@@ -262,20 +268,29 @@ tableEnv.registerCatalog("myhive", hive);
val name = "myhive"
val defaultDatabase = "mydatabase"
val hiveConfDir = "/opt/hive-conf" // a local path
-val version = "2.3.4" // or 1.2.1
+val version = "2.3.4"
val hive = new HiveCatalog(name, defaultDatabase, hiveConfDir, version)
tableEnv.registerCatalog("myhive", hive)
+
+// set the HiveCatalog as the current catalog of the session
+tableEnv.useCatalog("myhive")
{% endhighlight %}
</div>
<div data-lang="YAML" markdown="1">
{% highlight yaml %}
+
+execution:
+ planner: blink
+ ...
+ current-catalog: myhive # set the HiveCatalog as the current catalog of the session
+ current-database: mydatabase
+
catalogs:
- name: myhive
type: hive
- property-version: 1
hive-conf-dir: /opt/hive-conf
- hive-version: 2.3.4 # or 1.2.1
+ hive-version: 2.3.4
{% endhighlight %}
</div>
</div>