docs/content/docs/sql/hive-compatibility/hive-dialect/overview.md
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 using
SQL Client, SQL Gateway configured with HiveServer2 Endpoint 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.
{{< hint warning >}} Note:
default dialect.
When using SQL Gateway configured with [HiveServer2 Endpoint]({{< ref "docs/sql/interfaces/sql-gateway/hiveserver2" >}}), the current catalog will be a HiveCatalog by default.SQL dialect can be specified via the table.sql-dialect property.
Therefore,you can set the dialect after the SQL Client has launched.
Flink SQL> SET table.sql-dialect = hive; -- to use Hive dialect
[INFO] Session property has been set.
Flink SQL> SET table.sql-dialect = default; -- to use Flink default dialect
[INFO] Session property has been set.
When using the [SQL Gateway configured with HiveServer2 Endpoint]({{<ref "docs/sql/interfaces/sql-gateway/hiveserver2">}}), the dialect will be Hive dialect by default, so you don't need to do anything if you want to use Hive dialect. But you can still change the dialect to Flink default dialect.
# assuming has connected to SQL Gateway with beeline
jdbc:hive2> SET table.sql-dialect = default; -- to use Flink default dialect
jdbc:hive2> SET table.sql-dialect = hive; -- to use Hive dialect
You can set dialect for your TableEnvironment with Table API.
{{< tabs "f19e5e09-c58d-424d-999d-275106d1d5b3" >}} {{< tab "Java" >}}
EnvironmentSettings settings = EnvironmentSettings.inStreamingMode();
TableEnvironment tableEnv = TableEnvironment.create(settings);
// to use hive dialect
tableEnv.getConfig().setSqlDialect(SqlDialect.HIVE);
// to use default dialect
tableEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT);
{{< /tab >}} {{< tab "Python" >}}
from pyflink.table import *
settings = EnvironmentSettings.in_batch_mode()
t_env = TableEnvironment.create(settings)
# to use Hive dialect
t_env.get_config().set_sql_dialect(SqlDialect.HIVE)
# to use Flink default dialect
t_env.get_config().set_sql_dialect(SqlDialect.DEFAULT)
{{< /tab >}} {{< /tabs >}}