From f5fcf9d635cd02fe8c52bdd827dfecc555e61c57 Mon Sep 17 00:00:00 2001 From: Fernando Herrera Date: Thu, 13 May 2021 10:49:46 +0100 Subject: [PATCH] Dataframe feature for plugins (#3424) --- Cargo.toml | 4 +++- crates/nu_plugin_post/Cargo.toml | 4 ++++ crates/nu_plugin_post/src/post.rs | 8 ++++++++ crates/nu_plugin_to_bson/Cargo.toml | 3 +++ crates/nu_plugin_to_bson/src/to_bson.rs | 2 ++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e56b98bbf5..6412c549f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -159,7 +159,9 @@ dataframe = [ "nu-protocol/dataframe", "nu-command/dataframe", "nu-value-ext/dataframe", - "nu-data/dataframe" + "nu-data/dataframe", + "nu_plugin_post/dataframe", + "nu_plugin_to_bson/dataframe", ] diff --git a/crates/nu_plugin_post/Cargo.toml b/crates/nu_plugin_post/Cargo.toml index 2769c85e69..6ebc38d7d7 100644 --- a/crates/nu_plugin_post/Cargo.toml +++ b/crates/nu_plugin_post/Cargo.toml @@ -21,4 +21,8 @@ serde_json = "1.0.57" surf = "1.0.3" url = "2.1.1" +[features] +dataframe = ["nu-protocol/dataframe"] + + [build-dependencies] diff --git a/crates/nu_plugin_post/src/post.rs b/crates/nu_plugin_post/src/post.rs index 84f36e0ecd..0911b632d6 100644 --- a/crates/nu_plugin_post/src/post.rs +++ b/crates/nu_plugin_post/src/post.rs @@ -400,6 +400,14 @@ pub fn value_to_json_value(v: &Value) -> Result { } UntaggedValue::Table(l) => serde_json::Value::Array(json_list(l)?), + #[cfg(feature = "dataframe")] + UntaggedValue::Dataframe(_) => { + return Err(ShellError::labeled_error( + "Cannot convert dataframe", + "Cannot convert dataframe", + &v.tag, + )) + } UntaggedValue::Error(e) => return Err(e.clone()), UntaggedValue::Block(_) | UntaggedValue::Primitive(Primitive::Range(_)) => { serde_json::Value::Null diff --git a/crates/nu_plugin_to_bson/Cargo.toml b/crates/nu_plugin_to_bson/Cargo.toml index d0dae95533..7386fe233d 100644 --- a/crates/nu_plugin_to_bson/Cargo.toml +++ b/crates/nu_plugin_to_bson/Cargo.toml @@ -18,4 +18,7 @@ nu-source = { path = "../nu-source", version = "0.31.1" } nu-value-ext = { path = "../nu-value-ext", version = "0.31.1" } num-traits = "0.2.14" +[features] +dataframe = ["nu-protocol/dataframe"] + [build-dependencies] diff --git a/crates/nu_plugin_to_bson/src/to_bson.rs b/crates/nu_plugin_to_bson/src/to_bson.rs index ddaee3928f..a3dd911ff9 100644 --- a/crates/nu_plugin_to_bson/src/to_bson.rs +++ b/crates/nu_plugin_to_bson/src/to_bson.rs @@ -64,6 +64,8 @@ pub fn value_to_bson_value(v: &Value) -> Result { .collect::>()?, ), UntaggedValue::Block(_) | UntaggedValue::Primitive(Primitive::Range(_)) => Bson::Null, + #[cfg(feature = "dataframe")] + UntaggedValue::Dataframe(_) => Bson::Null, UntaggedValue::Error(e) => return Err(e.clone()), UntaggedValue::Primitive(Primitive::Binary(b)) => { Bson::Binary(BinarySubtype::Generic, b.clone())