-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add datafusion-json-functions as optional extension (#143)
Closes #130 Changes: 1. Integrates the functions https://github.com/datafusion-contrib/datafusion-functions-json 2. Adds some basic testing for these extensions (I need to figure out how to do something similar for s3 and delta)
- Loading branch information
Showing
10 changed files
with
464 additions
and
54 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! [datafusion-function-json] Integration: [JsonFunctionsExtension] | ||
//! | ||
//! [datafusion-function-json]: https://github.com/datafusion-contrib/datafusion-functions-json | ||
use crate::config::ExecutionConfig; | ||
use crate::extensions::{DftSessionStateBuilder, Extension}; | ||
use datafusion::prelude::SessionContext; | ||
use datafusion_common::Result; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct JsonFunctionsExtension {} | ||
|
||
impl JsonFunctionsExtension { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl Extension for JsonFunctionsExtension { | ||
fn register( | ||
&self, | ||
_config: &ExecutionConfig, | ||
builder: DftSessionStateBuilder, | ||
) -> datafusion_common::Result<DftSessionStateBuilder> { | ||
// | ||
Ok(builder) | ||
} | ||
|
||
fn register_on_ctx(&self, _config: &ExecutionConfig, ctx: &mut SessionContext) -> Result<()> { | ||
datafusion_functions_json::register_all(ctx)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! Tests for datafusion-function-json integration | ||
use crate::TestExecution; | ||
|
||
static TEST_TABLE: &str = r#" | ||
CREATE TABLE test_table ( | ||
id INT, | ||
json_col VARCHAR | ||
) AS VALUES | ||
(1, '{}'), | ||
(2, '{ "a": 1 }'), | ||
(3, '{ "a": 2 }'), | ||
(4, '{ "a": 1, "b": 2 }'), | ||
(5, '{ "a": 1, "b": 2, "c": 3 }') | ||
"#; | ||
|
||
/// Ensure one of the functions `json_contains` function is properly registered | ||
#[tokio::test] | ||
async fn test_basic() { | ||
let mut execution = TestExecution::new().with_setup(TEST_TABLE).await; | ||
|
||
let actual = execution | ||
.run_and_format("SELECT id, json_contains(json_col, 'b') as json_contains FROM test_table") | ||
.await; | ||
|
||
insta::assert_yaml_snapshot!(actual, @r###" | ||
- +----+---------------+ | ||
- "| id | json_contains |" | ||
- +----+---------------+ | ||
- "| 1 | false |" | ||
- "| 2 | false |" | ||
- "| 3 | false |" | ||
- "| 4 | true |" | ||
- "| 5 | true |" | ||
- +----+---------------+ | ||
"###); | ||
} | ||
|
||
/// ensure the json operators like -> are properly registered | ||
#[tokio::test] | ||
async fn test_operators() { | ||
let mut execution = TestExecution::new().with_setup(TEST_TABLE).await; | ||
|
||
let actual = execution | ||
.run_and_format("SELECT id, json_col->'a' as json_col_a FROM test_table") | ||
.await; | ||
|
||
insta::assert_yaml_snapshot!(actual, @r###" | ||
- +----+------------+ | ||
- "| id | json_col_a |" | ||
- +----+------------+ | ||
- "| 1 | {null=} |" | ||
- "| 2 | {int=1} |" | ||
- "| 3 | {int=2} |" | ||
- "| 4 | {int=1} |" | ||
- "| 5 | {int=1} |" | ||
- +----+------------+ | ||
"###); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#[cfg(feature = "functions-json")] | ||
mod functions_json; |
Oops, something went wrong.