pyspark.pandas.read_delta ¶
-
pyspark.pandas.
read_delta
( path : str , version : Optional [ str ] = None , timestamp : Optional [ str ] = None , index_col : Union[str, List[str], None] = None , ** options : Any ) → pyspark.pandas.frame.DataFrame [source] ¶ -
读取文件系统上的 Delta Lake 表并返回一个 DataFrame。
如果 Delta Lake 表已经存储在目录(即元存储)中,请使用‘read_table’。
- Parameters
-
- path string
-
Delta Lake 表的路径。
- version string, optional
-
指定要读取的表版本(基于Delta的内部事务版本),使用Delta的时间旅行功能。这将设置Delta的‘versionAsOf’选项。请注意,此参数和 timestamp 参数不能同时使用,否则将引发 ValueError 。
- timestamp string, optional
-
指定要读取的表版本(基于时间戳),使用 Delta 的时间旅行功能。这必须是 Spark 中有效的日期或时间戳字符串,并设置 Delta 的 ‘timestampAsOf’ 选项。请注意,此参数和 version 参数不能一起使用,否则将引发 ValueError 。
- index_col str or list of str, optional, default: None
-
Spark中表的索引列。
- options
-
可以传递给Delta的附加选项。
- Returns
-
- DataFrame
示例
>>> ps.range(1).to_delta('%s/read_delta/foo' % path) >>> ps.read_delta('%s/read_delta/foo' % path) id 0 0
>>> ps.range(10, 15, num_partitions=1).to_delta('%s/read_delta/foo' % path, ... mode='overwrite') >>> ps.read_delta('%s/read_delta/foo' % path) id 0 10 1 11 2 12 3 13 4 14
>>> ps.read_delta('%s/read_delta/foo' % path, version=0) id 0 0
您可以在往返过程中保留索引,如下所示。
>>> ps.range(10, 15, num_partitions=1).to_delta( ... '%s/read_delta/bar' % path, index_col="index") >>> ps.read_delta('%s/read_delta/bar' % path, index_col="index") id index 0 10 1 11 2 12 3 13 4 14