使用JDBC使用JDBC的DataBricks数据框架使用varchar(255)创建字符串列,而字符串值大于255。如何解决此问题?

发布于 2025-02-13 18:18:24 字数 989 浏览 0 评论 0原文

我使用以下Python命令将数据框写入Oracle DB和MS SQL DB。此数据框具有来自值生成的模式,其中包括数据类型的字符串类型字段/列。其中一些值非常大,例如尺寸为750或更高。

以下一个到MS SQL将字符串类型字段默认为VARCHAR(MAX)创建,因此没有问题。

usersDF.write \
  .format("jdbc") \
  .option("url", conn)\
  .option("user", sqlUserName)\
  .option("password", dbPassword)\
  .option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver")\
  .option("dbTable", "DBS_Processed_Users") \
  .mode('overwrite')\
  .save()

而尝试反对Oracle DB时,则将字符串类型字段作为Varchar(255)创建。

usersDF.write \
  .format("jdbc") \
  .option("url", oraConn)\
  .option("user", oraUserName)\
  .option("password", oraPassword)\
  .option("driver", "oracle.jdbc.driver.OracleDriver")\
  .option("dbTable", "Schema.DBS_Processed_Users") \
  .mode('overwrite')\
  .save()

确保将写入Oracle以Max或1000为精度创建Oracle的最佳方法是什么?我什至可以创建表,但是模式=覆盖,以某种方式将其覆盖为255并导致数据写故障。

这个问题或任何解决方案有更好的建议吗?

I am using below python command to write the dataframe to Oracle Db and MS SQL Db. This dataframe has schema generated out of the values, and that includes string type fields/columns by datatype. Some of the values are very larger like around size of 750 or above.

The below one to MS SQL creates the string type fields as varchar(max) by default and hence no issues.

usersDF.write \
  .format("jdbc") \
  .option("url", conn)\
  .option("user", sqlUserName)\
  .option("password", dbPassword)\
  .option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver")\
  .option("dbTable", "DBS_Processed_Users") \
  .mode('overwrite')\
  .save()

Whereas, the same when attempted against Oracle db, creates the string type fields as varchar(255) by default.

usersDF.write \
  .format("jdbc") \
  .option("url", oraConn)\
  .option("user", oraUserName)\
  .option("password", oraPassword)\
  .option("driver", "oracle.jdbc.driver.OracleDriver")\
  .option("dbTable", "Schema.DBS_Processed_Users") \
  .mode('overwrite')\
  .save()

What's the best way to ensure that the write to Oracle gets created with max or 1000 as precision? I can even create the table but the mode=overwrite, somehow overwrites it to 255 and causing the data write failures.

Is there any better recommendations to this problem or any solutions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文