Skip to content

Commit

Permalink
Removed unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dadepo committed Nov 18, 2023
1 parent 16db1c5 commit 1588d56
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
13 changes: 3 additions & 10 deletions common/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,22 @@ pub fn set_up_test_datafusion() -> Result<SessionContext> {
let batch = RecordBatch::try_new(
schema,
vec![
Arc::new(UInt8Array::from_iter_values([
1,
2,
3,
4,
5,
6
])),
Arc::new(UInt8Array::from_iter_values([1, 2, 3, 4, 5, 6])),
Arc::new(StringArray::from(vec![
Some("192.168.1.5/24"),
Some("172.16.0.0/20"),
Some("10.0.0.0/16"),
Some("2001:0db8::/32"),
Some("2001:db8:abcd::/48"),
None
None,
])),
Arc::new(StringArray::from(vec![
Some("192.168.1.5"),
Some("172.16.0.0"),
Some("10.0.0.0"),
Some("2001:0db8::"),
Some("2001:db8:abcd::"),
None
None,
])),
],
)?;
Expand Down
33 changes: 22 additions & 11 deletions df_extras_postgres/src/network_udfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub fn broadcast(args: &[ArrayRef]) -> Result<ArrayRef> {
let broadcast_address = IpNet::from_str(ip_string)
.map_err(|e| {
DataFusionError::Internal(format!("Parsing {ip_string} failed with error {e}"))
})?.broadcast();
})?
.broadcast();
string_builder.append_value(broadcast_address.to_string());
Ok::<(), DataFusionError>(())
} else {
Expand All @@ -37,9 +38,10 @@ pub fn host(args: &[ArrayRef]) -> Result<ArrayRef> {
ip_string.iter().try_for_each(|ip_string| {
if let Some(ip_string) = ip_string {
let host_address = IpNet::from_str(ip_string)
.map_err(|e| {
DataFusionError::Internal(format!("Parsing {ip_string} failed with error {e}"))
})?.network();
.map_err(|e| {
DataFusionError::Internal(format!("Parsing {ip_string} failed with error {e}"))
})?
.network();
string_builder.append_value(host_address.to_string());
Ok::<(), DataFusionError>(())
} else {
Expand All @@ -57,7 +59,6 @@ pub fn family(args: &[ArrayRef]) -> Result<ArrayRef> {
let mut int8array = UInt8Array::builder(args[0].len());
let ip_string = datafusion::common::cast::as_string_array(&args[0])?;
ip_string.iter().try_for_each(|ip_string| {

if let Some(ip_string) = ip_string {
let family = if ip_string.parse::<Ipv4Net>().is_ok() {
4
Expand Down Expand Up @@ -89,7 +90,8 @@ pub fn hostmask(args: &[ArrayRef]) -> Result<ArrayRef> {
let hostmask = IpNet::from_str(ip_string)
.map_err(|e| {
DataFusionError::Internal(format!("Parsing {ip_string} failed with error {e}"))
})?.hostmask();
})?
.hostmask();
string_builder.append_value(hostmask.to_string());
Ok::<(), DataFusionError>(())
} else {
Expand Down Expand Up @@ -150,7 +152,9 @@ pub fn inet_merge(args: &[ArrayRef]) -> Result<ArrayRef> {

let first = Ipv4Net::new(Ipv4Addr::from(first_addr_bit), common_bits as u8)
.map_err(|e| {
DataFusionError::Internal(format!("Create IPv4 failed with error {e}"))
DataFusionError::Internal(format!(
"Create IPv4 failed with error {e}"
))
})?
.network();

Expand All @@ -170,7 +174,9 @@ pub fn inet_merge(args: &[ArrayRef]) -> Result<ArrayRef> {

let first = Ipv6Net::new(Ipv6Addr::from(first_addr_bit), common_bits as u8)
.map_err(|e| {
DataFusionError::Internal(format!("Create IPv6 failed with error {e}"))
DataFusionError::Internal(format!(
"Create IPv6 failed with error {e}"
))
})?
.network();

Expand Down Expand Up @@ -277,7 +283,8 @@ pub fn netmask(args: &[ArrayRef]) -> Result<ArrayRef> {
let netmask = IpNet::from_str(ip_string)
.map_err(|e| {
DataFusionError::Internal(format!("Parsing {ip_string} failed with error {e}"))
})?.netmask();
})?
.netmask();
string_builder.append_value(netmask.to_string());
Ok::<(), DataFusionError>(())
} else {
Expand Down Expand Up @@ -426,7 +433,9 @@ mod tests {
async fn test_broadcast() -> Result<()> {
let ctx = register_udfs_for_test()?;
let df = ctx
.sql("select index, broadcast(cidr) as col_result from network_table ORDER BY index ASC")
.sql(
"select index, broadcast(cidr) as col_result from network_table ORDER BY index ASC",
)
.await?;

let batches = df.clone().collect().await?;
Expand Down Expand Up @@ -492,7 +501,9 @@ mod tests {
#[tokio::test]
async fn test_host() -> Result<()> {
let ctx = register_udfs_for_test()?;
let df = ctx.sql("select index, host(cidr) as col_result from network_table ORDER BY index ASC").await?;
let df = ctx
.sql("select index, host(cidr) as col_result from network_table ORDER BY index ASC")
.await?;

let batches = df.clone().collect().await?;

Expand Down
6 changes: 2 additions & 4 deletions df_extras_sqlite/src/json_udfs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use datafusion::arrow::array::{Array, ArrayRef, BooleanArray, StringBuilder, UInt8Array};
use datafusion::arrow::array::{Array, ArrayRef, StringBuilder, UInt8Array};
use datafusion::common::DataFusionError;
use datafusion::error::Result;
use serde_json::Value;
Expand Down Expand Up @@ -80,9 +80,7 @@ mod tests {
#[tokio::test]
async fn test_json_valid() -> Result<()> {
let ctx = register_udfs_for_test()?;
let df = ctx
.sql(r#"select json_valid(null) as col_result"#)
.await?;
let df = ctx.sql(r#"select json_valid(null) as col_result"#).await?;

let batches = df.clone().collect().await?;

Expand Down
2 changes: 1 addition & 1 deletion df_extras_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod json_udfs;

use crate::json_udfs::{json, json_valid};
use datafusion::arrow::datatypes::DataType::{Boolean, UInt8, Utf8};
use datafusion::arrow::datatypes::DataType::{UInt8, Utf8};
use datafusion::error::Result;
use datafusion::logical_expr::{ReturnTypeFunction, ScalarUDF, Signature, Volatility};
use datafusion::physical_expr::functions::make_scalar_function;
Expand Down

0 comments on commit 1588d56

Please sign in to comment.