Skip to content

Commit

Permalink
make lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyass committed Apr 13, 2022
1 parent dcfa039 commit 8a62419
Show file tree
Hide file tree
Showing 60 changed files with 105 additions and 205 deletions.
9 changes: 1 addition & 8 deletions common/datablocks/src/kernels/data_block_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,7 @@ impl DataBlock {
Ok(Arc::new(ConstColumn::new(inner_boolean, col.len())))
} else if predict.is_nullable() {
let col: &NullableColumn = unsafe { Series::static_cast(predict) };
let inner = col.inner();
if inner.is_const() {
let col: &ConstColumn = unsafe { Series::static_cast(inner) };
let inner_boolean = Self::cast_to_nonull_boolean(inner)?;
return Ok(Arc::new(ConstColumn::new(inner_boolean, col.len())));
}

let inner_boolean = Self::cast_to_nonull_boolean(inner)?;
let inner_boolean = Self::cast_to_nonull_boolean(col.inner())?;
// no const nullable or nullable constant
let inner: &BooleanColumn = Series::check_get(&inner_boolean)?;
let validity = col.ensure_validity();
Expand Down
2 changes: 1 addition & 1 deletion common/datavalues/src/columns/nullable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Column for NullableColumn {

fn data_type(&self) -> DataTypePtr {
let nest = self.column.data_type();
Arc::new(NullableType::create(nest))
NullableType::arc(nest)
}

fn column_type_name(&self) -> String {
Expand Down
4 changes: 2 additions & 2 deletions common/datavalues/src/types/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn from_arrow_field(f: &ArrowField) -> DataTypePtr {

let is_nullable = f.is_nullable;
if is_nullable && ty.can_inside_nullable() {
Arc::new(NullableType::create(ty))
NullableType::arc(ty)
} else {
ty
}
Expand Down Expand Up @@ -209,7 +209,7 @@ pub fn wrap_nullable(data_type: &DataTypePtr) -> DataTypePtr {
if !data_type.can_inside_nullable() {
return data_type.clone();
}
Arc::new(NullableType::create(data_type.clone()))
NullableType::arc(data_type.clone())
}

pub fn remove_nullable(data_type: &DataTypePtr) -> DataTypePtr {
Expand Down
2 changes: 1 addition & 1 deletion common/datavalues/src/types/type_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl TypeFactory {
let mut nulls = HashMap::new();
for (k, v) in self.case_insensitive_types.iter() {
if v.can_inside_nullable() {
let data_type: DataTypePtr = Arc::new(NullableType::create(v.clone()));
let data_type: DataTypePtr = NullableType::arc(v.clone());
nulls.insert(
format!("Nullable({})", k).to_ascii_lowercase(),
data_type.clone(),
Expand Down
5 changes: 1 addition & 4 deletions common/datavalues/src/types/type_nullable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ pub struct NullableType {

impl NullableType {
pub fn arc(inner: DataTypePtr) -> DataTypePtr {
Arc::new(Self {
name: format!("Nullable({})", inner.name()),
inner,
})
Arc::new(Self::create(inner))
}

pub fn create(inner: DataTypePtr) -> Self {
Expand Down
4 changes: 1 addition & 3 deletions common/datavalues/tests/it/types/create_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;

use common_datavalues::prelude::*;
use common_exception::Result;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -82,7 +80,7 @@ fn test_create_constant() -> Result<()> {
},
Test {
name: "nullable_i32",
data_type: Arc::new(NullableType::create(Int32Type::arc())),
data_type: NullableType::arc(Int32Type::arc()),
value: DataValue::Null,
size: 2,
column_expected: Series::from_data(&[None, None, Some(1i32)][0..2]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use num_traits::AsPrimitive;

use super::utils::rem_scalar;
use crate::scalars::Function;
use crate::scalars::FunctionContext;
use crate::scalars::FunctionDescription;
use crate::scalars::FunctionFeatures;

Expand Down Expand Up @@ -160,4 +161,3 @@ where
write!(f, "div")
}
}
use crate::scalars::FunctionContext;
5 changes: 1 addition & 4 deletions common/functions/src/scalars/contexts/current_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ use crate::scalars::FunctionFeatures;
pub struct CurrentUserFunction {}

impl CurrentUserFunction {
pub fn try_create(
_display_name: &str,
_args: &[&common_datavalues::DataTypePtr],
) -> Result<Box<dyn Function>> {
pub fn try_create(_display_name: &str, _args: &[&DataTypePtr]) -> Result<Box<dyn Function>> {
Ok(Box::new(CurrentUserFunction {}))
}

Expand Down
5 changes: 1 addition & 4 deletions common/functions/src/scalars/contexts/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ pub struct DatabaseFunction {}

// we bind database as first argument in eval
impl DatabaseFunction {
pub fn try_create(
_display_name: &str,
_args: &[&common_datavalues::DataTypePtr],
) -> Result<Box<dyn Function>> {
pub fn try_create(_display_name: &str, _args: &[&DataTypePtr]) -> Result<Box<dyn Function>> {
Ok(Box::new(DatabaseFunction {}))
}

Expand Down
5 changes: 1 addition & 4 deletions common/functions/src/scalars/contexts/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ pub struct VersionFunction {
}

impl VersionFunction {
pub fn try_create(
display_name: &str,
_args: &[&common_datavalues::DataTypePtr],
) -> Result<Box<dyn Function>> {
pub fn try_create(display_name: &str, _args: &[&DataTypePtr]) -> Result<Box<dyn Function>> {
Ok(Box::new(VersionFunction {
_display_name: display_name.to_string(),
}))
Expand Down
4 changes: 2 additions & 2 deletions common/functions/src/scalars/function_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use common_exception::Result;
use super::Function;
use super::FunctionDescription;
use super::Monotonicity;
use crate::scalars::FunctionContext;

#[derive(Clone)]
pub struct FunctionAdapter {
Expand Down Expand Up @@ -127,7 +128,7 @@ impl Function for FunctionAdapter {
.collect::<Vec<_>>();

let col = self.eval(&columns, 1, func_ctx)?;
let col = if col.is_const() && col.len() != 1 {
let col = if col.is_const() && col.len() != input_rows {
col.replicate(&[input_rows])
} else if col.is_null() {
NullColumn::new(input_rows).arc()
Expand Down Expand Up @@ -216,4 +217,3 @@ impl std::fmt::Display for FunctionAdapter {
}
}
}
use crate::scalars::FunctionContext;
36 changes: 19 additions & 17 deletions common/functions/src/scalars/function_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub type FactoryCreator =

pub struct FunctionDescription {
pub(crate) features: FunctionFeatures,
pub function_creator: FactoryCreator,
pub(crate) function_creator: FactoryCreator,
}

impl FunctionDescription {
Expand Down Expand Up @@ -106,28 +106,30 @@ impl FunctionFactory {
let origin_name = name.as_ref();
let lowercase_name = origin_name.to_lowercase();

// TODO(Winter): we should write similar function names into error message if function name is not found.
match self.case_insensitive_desc.get(&lowercase_name) {
Some(desc) => FunctionAdapter::try_create(desc, origin_name, args),
None => Err(ErrorCode::UnknownFunction(format!(
"Unsupported Function: {}",
origin_name
))),
}
let desc = self
.case_insensitive_desc
.get(&lowercase_name)
.ok_or_else(|| {
// TODO(Winter): we should write similar function names into error message if function name is not found.
ErrorCode::UnknownFunction(format!("Unsupported Function: {}", origin_name))
})?;

FunctionAdapter::try_create(desc, origin_name, args)
}

pub fn get_features(&self, name: impl AsRef<str>) -> Result<FunctionFeatures> {
let origin_name = name.as_ref();
let lowercase_name = origin_name.to_lowercase();

// TODO(Winter): we should write similar function names into error message if function name is not found.
match self.case_insensitive_desc.get(&lowercase_name) {
Some(desc) => Ok(desc.features.clone()),
None => Err(ErrorCode::UnknownFunction(format!(
"Unsupported Function: {}",
origin_name
))),
}
let desc = self
.case_insensitive_desc
.get(&lowercase_name)
.ok_or_else(|| {
// TODO(Winter): we should write similar function names into error message if function name is not found.
ErrorCode::UnknownFunction(format!("Unsupported Function: {}", origin_name))
})?;

Ok(desc.features.clone())
}

pub fn check(&self, name: impl AsRef<str>) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions common/functions/src/scalars/logics/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;

use common_datavalues::prelude::*;
use common_exception::Result;

Expand Down
2 changes: 1 addition & 1 deletion common/functions/src/scalars/logics/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct LogicFunctionImpl<F> {
}

pub trait LogicExpression: Sync + Send {
fn eval(columns: &ColumnsWithField, input_rows: usize, _nullable: bool) -> Result<ColumnRef>;
fn eval(columns: &ColumnsWithField, input_rows: usize, nullable: bool) -> Result<ColumnRef>;
}

impl<F> LogicFunctionImpl<F>
Expand Down
2 changes: 1 addition & 1 deletion common/functions/src/scalars/logics/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ macro_rules! impl_logic_expression {
impl LogicExpression for $name {
fn eval(columns: &ColumnsWithField, input_rows: usize, nullable: bool) -> Result<ColumnRef> {
let dt = if nullable {
Arc::new(NullableType::create(BooleanType::arc()))
NullableType::arc(BooleanType::arc())
} else {
BooleanType::arc()
};
Expand Down
2 changes: 0 additions & 2 deletions common/functions/src/scalars/logics/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;

use common_datavalues::prelude::*;
use common_exception::Result;

Expand Down
2 changes: 1 addition & 1 deletion common/functions/src/scalars/maths/floor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::scalars::function_factory::FunctionDescription;
use crate::scalars::scalar_unary_op;
use crate::scalars::EvalContext;
use crate::scalars::Function;
use crate::scalars::FunctionContext;
use crate::scalars::FunctionFeatures;
use crate::scalars::Monotonicity;

Expand Down Expand Up @@ -92,4 +93,3 @@ impl fmt::Display for FloorFunction {
write!(f, "{}", self.display_name.to_uppercase())
}
}
use crate::scalars::FunctionContext;
2 changes: 1 addition & 1 deletion common/functions/src/scalars/maths/pi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use common_exception::Result;

use crate::scalars::function_factory::FunctionDescription;
use crate::scalars::Function;
use crate::scalars::FunctionContext;
use crate::scalars::FunctionFeatures;

#[derive(Clone)]
Expand Down Expand Up @@ -64,4 +65,3 @@ impl fmt::Display for PiFunction {
write!(f, "{}", self.display_name)
}
}
use crate::scalars::FunctionContext;
5 changes: 1 addition & 4 deletions common/functions/src/scalars/others/exists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ use crate::scalars::FunctionFeatures;
pub struct ExistsFunction;

impl ExistsFunction {
pub fn try_create(
_display_name: &str,
_args: &[&common_datavalues::DataTypePtr],
) -> Result<Box<dyn Function>> {
pub fn try_create(_display_name: &str, _args: &[&DataTypePtr]) -> Result<Box<dyn Function>> {
Ok(Box::new(ExistsFunction {}))
}

Expand Down
5 changes: 1 addition & 4 deletions common/functions/src/scalars/others/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ pub struct IgnoreFunction {
}

impl IgnoreFunction {
pub fn try_create(
display_name: &str,
_args: &[&common_datavalues::DataTypePtr],
) -> Result<Box<dyn Function>> {
pub fn try_create(display_name: &str, _args: &[&DataTypePtr]) -> Result<Box<dyn Function>> {
Ok(Box::new(IgnoreFunction {
display_name: display_name.to_string(),
}))
Expand Down
5 changes: 1 addition & 4 deletions common/functions/src/scalars/others/inet_aton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ pub struct InetAtonFunctionImpl<const SUPPRESS_PARSE_ERROR: bool> {
}

impl<const SUPPRESS_PARSE_ERROR: bool> InetAtonFunctionImpl<SUPPRESS_PARSE_ERROR> {
pub fn try_create(
display_name: &str,
args: &[&common_datavalues::DataTypePtr],
) -> Result<Box<dyn Function>> {
pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result<Box<dyn Function>> {
assert_string(args[0])?;

Ok(Box::new(InetAtonFunctionImpl::<SUPPRESS_PARSE_ERROR> {
Expand Down
3 changes: 1 addition & 2 deletions common/functions/src/scalars/others/inet_ntoa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use std::fmt;
use std::net::Ipv4Addr;
use std::str;
use std::sync::Arc;

use common_datavalues::prelude::*;
use common_exception::Result;
Expand Down Expand Up @@ -76,7 +75,7 @@ impl<const SUPPRESS_CAST_ERROR: bool> Function for InetNtoaFunctionImpl<SUPPRESS
_func_ctx: FunctionContext,
) -> Result<ColumnRef> {
if SUPPRESS_CAST_ERROR {
let cast_to: DataTypePtr = Arc::new(NullableType::create(UInt32Type::arc()));
let cast_to: DataTypePtr = NullableType::arc(UInt32Type::arc());
let cast_options = CastOptions {
// we allow cast failure
exception_mode: ExceptionMode::Zero,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl RunningDifferenceFunction {
| TypeID::DateTime64
| TypeID::Interval => Ok(type_primitive::Int64Type::arc()),
TypeID::Float32 | TypeID::Float64 => Ok(type_primitive::Float64Type::arc()),
_ => Result::Err(ErrorCode::IllegalDataType(
_ => Err(ErrorCode::IllegalDataType(
"Argument for function runningDifference must have numeric type",
)),
}?;
Expand Down
5 changes: 1 addition & 4 deletions common/functions/src/scalars/others/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ pub struct SleepFunction {
}

impl SleepFunction {
pub fn try_create(
display_name: &str,
args: &[&common_datavalues::DataTypePtr],
) -> Result<Box<dyn Function>> {
pub fn try_create(display_name: &str, args: &[&DataTypePtr]) -> Result<Box<dyn Function>> {
assert_numeric(args[0])?;
Ok(Box::new(SleepFunction {
display_name: display_name.to_string(),
Expand Down
5 changes: 1 addition & 4 deletions common/functions/src/scalars/others/to_type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ pub struct ToTypeNameFunction {
}

impl ToTypeNameFunction {
pub fn try_create(
display_name: &str,
_args: &[&common_datavalues::DataTypePtr],
) -> Result<Box<dyn Function>> {
pub fn try_create(display_name: &str, _args: &[&DataTypePtr]) -> Result<Box<dyn Function>> {
Ok(Box::new(ToTypeNameFunction {
_display_name: display_name.to_string(),
}))
Expand Down
3 changes: 1 addition & 2 deletions common/functions/src/scalars/semi_structureds/check_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

use std::fmt;
use std::sync::Arc;

use common_datavalues::prelude::*;
use common_exception::ErrorCode;
Expand Down Expand Up @@ -49,7 +48,7 @@ impl Function for CheckJsonFunction {
}

fn return_type(&self) -> DataTypePtr {
Arc::new(NullableType::create(StringType::arc()))
NullableType::arc(StringType::arc())
}

fn eval(
Expand Down
9 changes: 2 additions & 7 deletions common/functions/src/scalars/semi_structureds/parse_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,7 @@ impl<const SUPPRESS_PARSE_ERROR: bool> Function for ParseJsonFunctionImpl<SUPPRE
if column.is_nullable() {
let (_, valids) = column.validity();
let nullable_column: &NullableColumn = Series::check_get(column)?;
let mut inner = nullable_column.inner();
if inner.is_const() {
let const_column: &ConstColumn = unsafe { Series::static_cast(inner) };
inner = const_column.inner();
}

let column = nullable_column.inner();
let data_type = remove_nullable(data_type);

let mut builder = NullableColumnBuilder::<JsonValue>::with_capacity(input_rows);
Expand All @@ -138,7 +133,7 @@ impl<const SUPPRESS_PARSE_ERROR: bool> Function for ParseJsonFunctionImpl<SUPPRE
|| data_type.data_type_id() == TypeID::Variant
{
let serializer = data_type.create_serializer();
match serializer.serialize_json_object(inner, valids) {
match serializer.serialize_json_object(column, valids) {
Ok(values) => {
for (i, v) in values.iter().enumerate() {
if let Some(valids) = valids {
Expand Down
Loading

0 comments on commit 8a62419

Please sign in to comment.