Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs.rs #3580

Merged
merged 6 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl LineDelimiter {
} else if *is_quote {
None
} else {
(*v == NEWLINE).then(|| idx + 1)
(*v == NEWLINE).then_some(idx + 1)
}
});

Expand Down
4 changes: 2 additions & 2 deletions datafusion/core/src/physical_plan/hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,12 +1240,12 @@ fn produce_from_matched(
let indices = if unmatched {
UInt64Array::from_iter_values(
(0..visited_left_side.len())
.filter_map(|v| (!visited_left_side.get_bit(v)).then(|| v as u64)),
.filter_map(|v| (!visited_left_side.get_bit(v)).then_some(v as u64)),
)
} else {
UInt64Array::from_iter_values(
(0..visited_left_side.len())
.filter_map(|v| (visited_left_side.get_bit(v)).then(|| v as u64)),
.filter_map(|v| (visited_left_side.get_bit(v)).then_some(v as u64)),
)
};

Expand Down
3 changes: 3 additions & 0 deletions datafusion/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ keywords = ["arrow", "query", "sql"]
edition = "2021"
rust-version = "1.62"

[package.metadata.docs.rs]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs.rs will set this, according to their docs.

rustc-args = ["--cfg", "docsrs"]

[lib]
name = "datafusion_proto"
path = "src/lib.rs"
Expand Down
30 changes: 17 additions & 13 deletions datafusion/proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ fn main() -> Result<(), String> {
Ok(())
}

#[cfg(feature = "json")]
fn build() -> Result<(), String> {
use std::io::Write;

let out = std::path::PathBuf::from(
std::env::var("OUT_DIR").expect("Cannot find OUT_DIR environment vairable"),
std::env::var("OUT_DIR").expect("Cannot find OUT_DIR environment variable"),
);
let descriptor_path = out.join("proto_descriptor.bin");

Expand All @@ -44,9 +43,11 @@ fn build() -> Result<(), String> {
.compile_protos(&["proto/datafusion.proto"], &["proto"])
.map_err(|e| format!("protobuf compilation failed: {}", e))?;

#[cfg(feature = "json")]
let descriptor_set = std::fs::read(&descriptor_path)
.expect(&*format!("Cannot read {:?}", &descriptor_path));

#[cfg(feature = "json")]
pbjson_build::Builder::new()
.register_descriptors(&descriptor_set)
.expect(&*format!(
Expand All @@ -58,22 +59,25 @@ fn build() -> Result<(), String> {

// .serde.rs is not a valid package name, so append to datafusion.rs so we can treat it normally
let proto = std::fs::read_to_string(out.join("datafusion.rs")).unwrap();

#[cfg(feature = "json")]
let json = std::fs::read_to_string(out.join("datafusion.serde.rs")).unwrap();

#[cfg(feature = "docsrs")]
let path = out.join("datafusion.rs");
#[cfg(not(feature = "docsrs"))]
let path = "src/generated/datafusion.rs";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change generated path to src or out_dir as appropriate.


let mut file = std::fs::OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open("src/generated/datafusion_json.rs")
.open(path)
.unwrap();
file.write(proto.as_str().as_ref()).unwrap();
file.write(json.as_str().as_ref()).unwrap();
file.write_all(proto.as_str().as_ref()).unwrap();

Ok(())
}
#[cfg(feature = "json")]
file.write_all(json.as_str().as_ref()).unwrap();

#[cfg(not(feature = "json"))]
fn build() -> Result<(), String> {
prost_build::Config::new()
.out_dir("src/generated")
.compile_protos(&["proto/datafusion.proto"], &["proto"])
.map_err(|e| format!("protobuf compilation failed: {}", e))
Ok(())
}
13 changes: 8 additions & 5 deletions datafusion/proto/src/generated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
// specific language governing permissions and limitations
// under the License.

// include the generated protobuf source as a submodule
#[allow(clippy::all)]
#[rustfmt::skip]
#[cfg(not(feature = "json"))]
#[cfg(not(docsrs))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we have a writable source folder, generate into that.

pub mod datafusion;

#[cfg(docsrs)]
#[allow(clippy::all)]
#[rustfmt::skip]
#[cfg(feature = "json")]
pub mod datafusion_json;
pub mod datafusion {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When not writable, pull from OUT_DIR.

include!(concat!(env!("OUT_DIR"), "/datafusion.rs"));

#[cfg(feature = "json")]
include!(concat!(env!("OUT_DIR"), "/datafusion.serde.rs"));
}
3 changes: 0 additions & 3 deletions datafusion/proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ pub mod generated;
pub mod logical_plan;
pub mod to_proto;

#[cfg(not(feature = "json"))]
pub use generated::datafusion as protobuf;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the module name is always the same! :D

#[cfg(feature = "json")]
pub use generated::datafusion_json as protobuf;

#[cfg(doctest)]
doc_comment::doctest!("../README.md", readme_example_test);
Expand Down