跳转至内容

FileFormat 包含关于如何读取和解析 Dataset 中包含的文件的信息。 存在与支持的文件格式对应的子类(ParquetFileFormatIpcFileFormat)。

工厂

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 应该支持的选项,请提交问题。 此外,还支持以下选项。 来自 CsvReadOptions

    • skip_rows(跳过行数)

    • column_names(列名)。请注意,如果指定了 Schema,则 column_names 必须与 schema 中指定的名称匹配。

    • autogenerate_column_names 来自 CsvFragmentScanOptions(这些值可以在扫描时覆盖)

    • convert_options:一个 CsvConvertOptions

    • block_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