Pyspark如何在设置为true时自动确定列的数据类型,后台会发生什么

发布于 2025-02-06 20:43:49 字数 309 浏览 3 评论 0 原文

根据文档,

Inferschema:自动进化列类型。需要一个额外的 传递数据,默认情况下是错误的

,我知道Spark将读取CSV以确定数据类型并相应地分配。

我很想知道背景中发生了什么。

  1. 火花扫描整个CSV吗?
  2. 如果仅扫描示例数据,那么它将扫描多少行?
  3. Spark如何得出结论,因此列是特定数据类型并在InferSchema = true上分配的?

有人可以帮助我更好地理解它或分享一些链接!

谢谢。

According to documentation,

inferSchema: automatically infers column types. It requires one extra
pass over the data and is false by default

alright, I understood that spark will read the CSV to determine the data type and assigns accordingly.

I am curious to know what is happening in the background.

  1. Does spark scans whole csv?
  2. if it scans only a sample data, then how many rows will it scan?
  3. How does spark conclude that so and so column is of a particular datatype and assigns it on inferSchema = true?

Can someone help me to understand it better or share some links!

Thank you.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

完美的未来在梦里 2025-02-13 20:43:50

默认情况下回答您的一些问题

  1. 是的,但是在新版本中引入了采样比率,您可以在其中定义需要扫描以推断模式(默认为1)的值的比例,
  2. 默认情况下,所有行都需要额外的通行证。在数据上,
  3. 它将其分析为整数,长,双重,bool且最终字符串或例外,如果解析失败并提供了最终模式,则可以阅读代码的早期版本在这里

Answering some of your questions

  1. By default yes but sampling ratio was introduced in new version where you can define the fraction of values which need to be scanned to infer schema (default is 1)
  2. By default all rows as it mentions it will need one extra pass over data
  3. it parses it each as integer, long, double, bool and finally string or exception if parsing fails and gives the final schema you can read an early version of code here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文