在 Spark SQL 中显示在 Hive 表上创建表 - 将 CHAR、VARCHAR 视为字符串
我需要为 Hive 表和生成 DDL 语句。以编程方式查看。我尝试使用 Spark 和 Beeline 来完成此任务。 Beeline 每个语句大约需要 5-10 秒,而 Spark 在几毫秒内完成同样的事情。我计划使用 Spark,因为它比直线更快。使用 Spark 从配置单元获取 DDL 语句的一个缺点是,它将 CHAR、VARCHAR 字符视为字符串,并且不保留 CHAR、VARCHAR 数据类型附带的长度信息。同时beeline保留了CHAR、VARCHAR数据类型的数据类型和长度信息。我正在使用 Spark 2.4.1 和 Beeline 2.1.1。
下面给出了示例 create table 命令及其 show create table 输出。
直线输出:
Spark-Shell:
我想知道 Spark 端是否有任何配置需要保留CHAR、VARCHAR 数据类型的数据类型和长度信息。如果有其他方法可以快速从 Hive 获取 DDL,我也可以接受。
I have a need to generate DDL statements for Hive tables & views programmatically. I tried using Spark and Beeline for this task. Beeline takes around 5-10 seconds for each of the statements whereas Spark completes the same thing in a few milliseconds. I am planning to use Spark since it is faster compared to beeline. One downside of using spark for getting DDL statements from the hive is, it treats CHAR, VARCHAR characters as String and it doesn't preserve the length information that goes with CHAR,VARCHAR data types. At the same time beeline preserves the data type and the length information for CHAR,VARCHAR data types. I am using Spark 2.4.1 and Beeline 2.1.1.
Given below the sample create table command and its show create table output.
Beeline Output:
Spark-Shell:
I wanted to know if there is any configuration on the Spark side to preserve the data type and length information for CHAR,VARCHAR data types. If there are other ways to get DDL from Hive quickly, I will be fine with that also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是在
您提出的堆栈溢出问题中,我引用:
“我需要以编程方式为 Hive 表和视图生成 DDL 语句。我尝试使用 Spark 和 Beeline 来完成此任务。Beeline 每个任务大约需要 5-10 秒语句,而 Spark 在几毫秒内完成同样的事情,因为它比 beeline 更快,使用 Spark 从 hive 获取 DDL 语句的一个缺点是,它处理 CHAR, VARCHAR 字符作为字符串,它不保留 CHAR、VARCHAR 数据类型的长度信息,同时 beeline 保留 CHAR、VARCHAR 数据类型的数据类型和长度信息。 Beeline 2.1.1。下面给出了示例创建表命令及其显示创建表输出。”
在测试数据库的 Hive 中创建一个简单的表现
在让我们转到 Spark-Shell
您可以看到 Spark 正确显示列
现在让我们通过 beeline 在 Hive 中创建相同的表现
在再次在 Spark-Shell 中检查
它显示 OK。总之,您可以在 Spark 中获得列定义,就像在 Hive 中定义它们一样。
在上面的声明中,我引用“我正在使用 Spark 2.4.1 和 Beeline 2.1.1”,指的是旧版本的 Spark 和 hive 可能存在此类问题。
This is in
Your stack overflow issue raised and I quote:
"I have a need to generate DDL statements for Hive tables & views programmatically. I tried using Spark and Beeline for this task. Beeline takes around 5-10 seconds for each of the statements whereas Spark completes the same thing in a few milliseconds. I am planning to use Spark since it is faster compared to beeline. One downside of using spark for getting DDL statements from the hive is, it treats CHAR, VARCHAR characters as String and it doesn't preserve the length information that goes with CHAR,VARCHAR data types. At the same time beeline preserves the data type and the length information for CHAR,VARCHAR data types. I am using Spark 2.4.1 and Beeline 2.1.1. Given below the sample create table command and its show create table output."
Create a simple table in Hive in test database
Now let's go to spark-shell
You can see Spark shows columns correctly
Now let us go and create the same table in hive through beeline
Now check that in spark-shell again
It shows OK. So in summary you get column definitions in Spark as you have defined them in Hive.
In your statement above and I quote "I am using Spark 2.4.1 and Beeline 2.1.1", refers to older versions of Spark and hive which may have had such issues.