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

Expose some more internal types #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn dict_key_type(d: &DataType) -> Option<DataType> {
None
}

/// Parsed representation of a JSON path element.
#[derive(Debug)]
pub enum JsonPath<'s> {
Key(&'s str),
Expand Down Expand Up @@ -97,13 +98,17 @@ impl From<i64> for JsonPath<'_> {
}

#[derive(Debug)]
enum JsonPathArgs<'a> {
pub enum JsonPathArgs<'a> {
Array(&'a ArrayRef),
Scalars(Vec<JsonPath<'a>>),
}

impl<'s> JsonPathArgs<'s> {
fn extract_path(path_args: &'s [ColumnarValue]) -> DataFusionResult<Self> {
/// Extract the JSON path from the arguments to a json function.
/// The path can be:
/// - A single array argument (`json_get(json_data, keys_column)`)
/// - One or more scalar arguments (`json_get(json_data, 'foo', 0)`)
pub fn extract_path(path_args: &'s [ColumnarValue]) -> DataFusionResult<Self> {
// If there is a single argument as an array, we know how to handle it
if let Some((ColumnarValue::Array(array), &[])) = path_args.split_first() {
return Ok(Self::Array(array));
Expand Down
7 changes: 7 additions & 0 deletions src/common_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ impl JsonUnion {
}
}

/// Get the `DataType` for a `JsonUnion`.
/// This will be the data type of the result of `json_array->'field'`.
#[must_use]
pub fn json_union_data_type() -> DataType {
JsonUnion::data_type()
}

/// So we can do `collect::<JsonUnion>()`
impl FromIterator<Option<JsonUnionField>> for JsonUnion {
fn from_iter<I: IntoIterator<Item = Option<JsonUnionField>>>(iter: I) -> Self {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ mod json_length;
mod json_object_keys;
mod rewrite;

pub use common_union::{JsonUnionEncoder, JsonUnionValue};
pub use common_union::{json_union_data_type, JsonUnionEncoder, JsonUnionValue};

pub use common::JsonPath;

pub mod functions {
pub use crate::json_as_text::json_as_text;
Expand Down