首页 > 解决方案 > Rust parquet,按名称而不是按索引位置获取列值

问题描述

我想知道如何从镶木地板文件中按列名获取“item_id”和“idf_score”值。

我正在使用镶木地板 =“3.0”

这是一个玩具示例,我现在如何使用列索引获取值。

fn stackoverflow_example(dir: &str) -> HashMap<u64, f64> {
    let mut item_to_idf = HashMap::new();
    let dir_entry = fs::read_dir(dir).unwrap();
    for path in dir_entry {
        let full_path_to_file = path.unwrap().path().display().to_string();
        if full_path_to_file.ends_with(".parquet") {
            let file = File::open(&Path::new(&full_path_to_file)).unwrap();
            let reader = SerializedFileReader::new(file).unwrap();
            let mut row_iter = reader.get_row_iter(None).unwrap();
            while let Some(row) = row_iter.next() {
                let item_id = row.get_long(0).unwrap() as u64;
                let idf_score = row.get_double(1).unwrap();
                item_to_idf.insert(item_id, idf_score);
            }
        }
    }
    item_to_idf
}

标签: rustparquetcolumnname

解决方案


推荐阅读