This documentation is for an out-of-date version of Apache Flink. We recommend you use the latest stable version.
Starting from 1.11.0, Flink allows users to write SQL statements in Hive syntax when Hive dialect
is used. By providing compatibility with Hive syntax, we aim to improve the interoperability with
Hive and reduce the scenarios when users need to switch between Flink and Hive in order to execute
different statements.
Flink currently supports two SQL dialects: default and hive. You need to switch to Hive dialect
before you can write in Hive syntax. The following describes how to set dialect with
SQL Client and Table API. Also notice that you can dynamically switch dialect for each
statement you execute. There’s no need to restart a session to use a different dialect.
SQL Client
SQL dialect can be specified via the table.sql-dialect property. Therefore you can set the initial dialect to use in
the configuration section of the yaml file for your SQL Client.
You can also set the dialect after the SQL Client has launched.
Table API
You can set dialect for your TableEnvironment with Table API.
DDL
This section lists the supported DDLs with the Hive dialect. We’ll mainly focus on the syntax
here. You can refer to Hive doc
for the semantics of each DDL statement.
CATALOG
Show
DATABASE
Show
Create
Alter
Update Properties
Update Owner
Update Location
Drop
Use
TABLE
Show
Create
Alter
Rename
Update Properties
Update Location
The partition_spec, if present, needs to be a full spec, i.e. has values for all partition columns. And when it’s
present, the operation will be applied to the corresponding partition instead of the table.
Update File Format
The partition_spec, if present, needs to be a full spec, i.e. has values for all partition columns. And when it’s
present, the operation will be applied to the corresponding partition instead of the table.
Update SerDe Properties
The partition_spec, if present, needs to be a full spec, i.e. has values for all partition columns. And when it’s
present, the operation will be applied to the corresponding partition instead of the table.
Add Partitions
Drop Partitions
Add/Replace Columns
Change Column
Drop
VIEW
Create
Alter
NOTE: Altering view only works in Table API, but not supported via SQL client.
Rename
Update Properties
Update As Select
Drop
FUNCTION
Show
Create
Drop
DML
INSERT
The partition_spec, if present, can be either a full spec or partial spec. If the partition_spec is a partial
spec, the dynamic partition column names can be omitted.
DQL
At the moment, Hive dialect supports the same syntax as Flink SQL for DQLs. Refer to
Flink SQL queries for more details. And it’s recommended to switch to
default dialect to execute DQLs.
Notice
The following are some precautions for using the Hive dialect.
Hive dialect should only be used to manipulate Hive tables, not generic tables. And Hive dialect should be used together
with a HiveCatalog.
While all Hive versions support the same syntax, whether a specific feature is available still depends on the
Hive version you use. For example, updating database
location is only supported in Hive-2.4.0 or later.
Hive and Calcite have different sets of reserved keywords. For example, default is a reserved keyword in Calcite and
a non-reserved keyword in Hive. Even with Hive dialect, you have to quote such keywords with backtick ( ` ) in order to
use them as identifiers.
Due to expanded query incompatibility, views created in Flink cannot be queried in Hive.