小编dto*_*nay的帖子

Spark Tachyon:如何删除文件?

在Scala中,作为一个实验,我使用Spark在Tachyon上创建一个序列文件并将其重新读入.我想使用Spark脚本从Tachyon中删除该文件.

val rdd =  sc.parallelize(Array(("a",2), ("b",3), ("c",1)))
rdd.saveAsSequenceFile("tachyon://127.0.0.1:19998/files/123.sf2")
val rdd2 = sc.sequenceFile[String,Int]("tachyon://127.0.0.1:19998/files/123.sf2")
Run Code Online (Sandbox Code Playgroud)

我不太了解Scala语言,我找不到有关文件路径操作的参考.我确实找到了一种在Scala中以某种方式使用Java来实现此目的的方法,但我无法使用Tachyon来使用它.

import java.io._
new File("tachyon://127.0.0.1:19998/files/123.sf2").delete()
Run Code Online (Sandbox Code Playgroud)

scala apache-spark alluxio

5
推荐指数
1
解决办法
1405
查看次数

如何在使用Serde库时禁用"unused attribute"警告?

除了禁用警告,为什么会发生?

use serde_json::from_str;
use serde_json::error::Result;

#[derive(Deserialize)]
pub struct Config {
    #[serde(rename="cudaBlasDylibPath")]
    pub cuda_blas_dylib_path: String,
}

impl Config {
    pub fn new() -> Result<Config> {
        from_str("{}")
    }
}
Run Code Online (Sandbox Code Playgroud)

src/config.rs:4:10:4:21警告:未使用的属性,#[warn(unused_attributes)]默认为src/config.rs:4#[derive(Deserialize)]

添加#[allow(unused_attributes)]没有帮助.

json rust deserialization serde

5
推荐指数
1
解决办法
364
查看次数

在Serde中处理混合对象数组

扩展我之前的问题,你如何处理包含混合的数组structs?我试过看serde_json::Value源头.但是它没有处理两种不同的情况structs.

我不能简单地合并它们,并且在它们的属性上使用Options,因为这会使单个struct变得难以处理,并且它们必须是不同的.

锈结构

#[derive(Clone, Debug, Deserialize)]
struct WebResponse {
    foo: Vec<Structs>,
}

enum Structs {
    Foo(Foo),
    Bar(Bar),
}

#[derive(Clone, Debug, Deserialize)]
struct Foo {
    name: String,
    baz: Vec<String>,
}

#[derive(Clone, Debug, Deserialize)]
struct Bar {
    quux: u64
}
Run Code Online (Sandbox Code Playgroud)

示例JSON

{
    "foo": [
        {
            "name": "John",
            "baz": ["Lorem", "Ipsum"]
        },
        {
            "quux": 17
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

serialization json rust serde

5
推荐指数
1
解决办法
676
查看次数

AWS Athena (JSON) 的 SerDe 属性列表

我正在测试 AWS 的 Athena 产品,到目前为止运行良好。但我想知道 SerDe 属性的列表。我找了很远很远也没有找到。例如"ignore.malformed.json" = "true",我正在使用这个,但我很确定还有很多其他选项可以调整查询。

例如,我找不到有关“路径”属性的作用的信息,因此拥有完整列表会很棒。

我查看了 Apache Hive 文档但找不到这个,在 AWS 文档/论坛上也没有。

谢谢!

amazon-web-services amazon-athena hive-serde

5
推荐指数
1
解决办法
3907
查看次数

如何在不清理整个项目的情况下强制`build.rs`再次运行?

如何build.rs在不清理整个项目的情况下强行再次运行?我查了cargo build --help但是找不到任何相关内容build.rs.

rust rust-cargo

5
推荐指数
4
解决办法
1448
查看次数

如何将 MongoDB 中的文档反序列化为 Rust 结构?

这是我迄今为止的尝试。我不明白如何告诉 Rust 将 MongoDB 结果反序列化为结构。

我已经定义了一个名为的结构Thing,我希望将数据映射到该结构。

#[macro_use(bson, doc)]
extern crate bson;
extern crate mongodb;
#[macro_use]
extern crate serde_derive;

use mongodb::db::ThreadedDatabase;
use mongodb::{Client, ThreadedClient};

fn main() {
    let client =
        Client::connect("localhost", 27017).expect("Failed to initialize standalone client.");

    let coll = client.db("bestestDB").collection("things");

    let doc = doc! {
        "$text": { "$search": "Love" },
    };

    #[derive(Serialize, Deserialize, Debug)]
    pub struct Thing {
        #[serde(rename = "_id")] // Use MongoDB's special primary key field name when serializing
        pub id: String,
        pub name: String,
        pub image: …
Run Code Online (Sandbox Code Playgroud)

mongodb rust serde

5
推荐指数
0
解决办法
1105
查看次数

如何将非静态数据发送到 Rust 中的线程?本示例中是否需要它?

我正在尝试使用 Rust 中的一些堆数据启动一个新线程,但我收到了一堆错误,这些错误源于数据需要具有'static生命周期。我已经按照我的方式倒退了我的程序,但遇到了问题。

use std::sync::Arc;
use std::thread;

struct ThreadData {
    vector_of_strings: Vec<String>,
    terms: Vec<&'static str>,
    quotient: usize,
}

fn perform_search(slice: &[String], terms: &[&str]) {
    /* ... */
}

fn threaded_search(td_arc: &Arc<ThreadData>) {
    let no_of_lines = td_arc.vector_of_strings.len();
    let new_tda1 = td_arc.clone();

    let strings_as_slice1 = new_tda1.vector_of_strings.as_slice();   

    thread::spawn(move || {
        perform_search(&strings_as_slice1[0..td_arc.quotient], &new_tda1.terms);
    });
}

fn main() {
    let td = ThreadData {
        vector_of_strings: Vec::new(),
        terms: Vec::new(),
        quotient: 0,
    };

    let td_arc = Arc::new(td);
    threaded_search(&td_arc);
}
Run Code Online (Sandbox Code Playgroud)

错误:

use std::sync::Arc;
use std::thread;

struct …
Run Code Online (Sandbox Code Playgroud)

concurrency multithreading thread-safety rust

5
推荐指数
1
解决办法
3011
查看次数

分布式缓存和Tachyon有什么区别?

分布式缓存是一种存储常见请求并支持快速检索的方法.

Tachyon是一个以内存为中心的分布式存储文件系统,可避免进入磁盘以加载经常读取的数据集.

这两者有什么不同?

distributed-cache distributed-caching apache-spark alluxio

4
推荐指数
2
解决办法
2440
查看次数

serde_json::from_str 错误,其中字符串来自文件

extern crate serde_json;

use serde_json::Value;

use std::fs::File;
use std::io::prelude::*;

fn main() {
    let filepath = "./map/test/anhui.txt";
    match File::open(filepath) {
        Err(why) => println!("Open file failed : {:?}", why.kind()),
        Ok(mut file) => {
            let mut content: String = String::new();
            file.read_to_string(&mut content);
            println!("{}", &mut content);
            serde_json::from_str(&mut content);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

错误信息:

extern crate serde_json;

use serde_json::Value;

use std::fs::File;
use std::io::prelude::*;

fn main() {
    let filepath = "./map/test/anhui.txt";
    match File::open(filepath) {
        Err(why) => println!("Open file failed : {:?}", why.kind()),
        Ok(mut file) => {
            let …
Run Code Online (Sandbox Code Playgroud)

generics parsing json rust serde

4
推荐指数
1
解决办法
3867
查看次数

使用 serde_json 反序列化 JSON 根数组

根据 JSON 规范,JSON 文档的根可以是对象,也可以是数组。第一种情况很容易通过serde_json使用反序列化struct

#[derive(Deserialize)]
struct Person {
    first_name: String,
    last_name: String,
}

fn main() {
    let s = r#"[{"first_name": "John", "last_name": "Doe"}]"#;

    // this will break because we have a top-level array
    let p: Person = serde_json::from_str(s).unwrap();
    println!("Name: {} {}", p.first_name, p.last_name);
}
Run Code Online (Sandbox Code Playgroud)

但是我找不到任何有关如何反序列化(未命名)数组的文档struct。

json rust serde

4
推荐指数
1
解决办法
3695
查看次数