一个 FileFormat 包含有关如何读取和解析 Dataset 中包含的文件信息。有对应的子类,用于支持的文件格式(ParquetFileFormat 和 IpcFileFormat)。
工厂
FileFormat$create() 接受以下参数
format: 文件格式的字符串标识符。当前支持的值"parquet"
"ipc"/"arrow"/"feather",彼此的别名;对于 Feather,请注意仅支持版本 2 文件
"csv"/"text",相同的别名(因为逗号是文本文件的默认分隔符)
"tsv",等效于传递
format = "text", delimiter = "\t"
...: 额外的特定于格式的选项format = "parquet":dict_columns: 应该作为字典读取的列名。FragmentScanOptions 中的任何 Parquet 选项。
format = "text": 请参阅 CsvParseOptions。请注意,您可以使用 Arrow C++ 库的命名("delimiter"、"quoting" 等)或read_csv_arrow()中使用的readr风格的命名("delim"、"quote" 等)来指定它们。目前并非所有readr选项都受支持;如果您遇到arrow应该支持的选项,请提出问题。此外,还支持以下选项。来自 CsvReadOptionsskip_rowscolumn_names。请注意,如果指定了 Schema,则column_names必须与 Schema 中指定的名称匹配。autogenerate_column_names来自 CsvFragmentScanOptions(这些值可以在扫描时被覆盖)convert_options: 一个 CsvConvertOptionsblock_size
它返回 FileFormat 的相应子类(例如 ParquetFileFormat)
示例
## Semi-colon delimited files
# Set up directory for examples
tf <- tempfile()
dir.create(tf)
on.exit(unlink(tf))
write.table(mtcars, file.path(tf, "file1.txt"), sep = ";", row.names = FALSE)
# Create FileFormat object
format <- FileFormat$create(format = "text", delimiter = ";")
open_dataset(tf, format = format)
#> FileSystemDataset with 1 csv file
#> 11 columns
#> mpg: double
#> cyl: int64
#> disp: double
#> hp: int64
#> drat: double
#> wt: double
#> qsec: double
#> vs: int64
#> am: int64
#> gear: int64
#> carb: int64