gpt4 book ai didi

scala - 如何在使用 spark 读取表时确定数据的大小?

转载 作者:行者123 更新时间:2023-12-05 07:21:31 25 4
gpt4 key购买 nike

我正在尝试使用 spark 读取 postgres 数据库上的表。为此,我编写了以下内容:

val yearDF = spark.read.format("jdbc").option("url", connectionUrl)
.option("dbtable", s"(${execQuery}) as year2016")
.option("user", devUserName)
.option("password", devPassword)
.option("partitionColumn","epochVals")
.option("lowerBound", minEp)
.option("upperBound", maxEp)
.option("numPartitions",15)
.load()

为了以高效的方式读取日期和写入输出文件,我试图查看是否可以找到一些在线资料来确定正在读取的数据大小以及我的工作应该使用多少分区、执行程序和输出文件来处理数据。我找到了这个 link其中包含有关相同的信息。

链接给出了一个公式:

number Of Megabytes = M = (N*V*W) / 1024^2
where

N = number of records
V = number of variables
W = average width in bytes of a variable

链接解释了如何为每个数据类型分配权重,如下所示。

Type of variables                               Width
Integers, −127 <= x <= 100 1
Integers, 32,767 <= x <= 32,740 2
Integers, -2,147,483,647 <= x <= 2,147,483,620 4
Floats single precision 4
Floats double precision 8
Strings maximum length

我的源表的列采用以下格式:

je_header_id:bigint
attribute10:character varying
doc_sequence_value:numeric
reference_date:date
source_transaction:numeric(30,6)
doc_sequence_id:numeric(15,0)
xx_last_update_tms:timestamp without time zone
xx_last_update_log_id:integer
xx_data_hash_id:bigint
xx_pk_id:bigint
mje_flag:character varying(1)

我了解如何根据定义方式将数字数据类型视为 Integer 或 Double。我不明白的是如何为 String 列赋予权重。该链接说要给出列中最大字符串的长度。但这是找出最大字符串的昂贵操作。如果数据类型类似于 character varying(100) -- Assuming 100 as weight in worst case,则很容易考虑字符串的最大大小如果列的character varying 没有任何大小限制,就会出现问题。谁能告诉我如何获取 String 列的权重,或者是否有任何其他方法来估计我们将要读取的输入的大小?

最佳答案

您可以在从源数据库中读取数据后获取该值。在阶段中,您可以在输入中获取此值:

enter image description here

关于scala - 如何在使用 spark 读取表时确定数据的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56866915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com