AmrDeveloper / GQL

Git Query language is a SQL like language to perform queries on .git files with supports of most of SQL features such as grouping, ordering and aggregations functions
https://amrdeveloper.github.io/GQL/
MIT License
3.3k stars 90 forks source link

Incorrect equals for DateTime and Time #71

Closed craftslab closed 10 months ago

craftslab commented 10 months ago

Describe the bug

Incorrect equals for DateTime and Time

To Reproduce

// https://github.com/AmrDeveloper/GQL/blob/master/crates/gitql-ast/src/value.rs
let value = Value::DateTime(1704890191);
let other = Value::DateTime(1704890192);
let ret = value.equals(&other);
assert_eq!(ret, false); // fails

Expected behavior

assert_eq!(ret, false);  // ret is false

GQL (please complete the following information):

Version 0.11.0

Screenshots

screenshots
craftslab commented 10 months ago

See: https://github.com/AmrDeveloper/GQL/blob/master/crates/gitql-ast/src/value.rs

Incorrect

pub fn equals(&self, other: &Self) -> bool {
        if self.data_type() != other.data_type() {
            return false;
        }

        match self.data_type() {
            DataType::Any => true,
            DataType::Text => self.as_text() == other.as_text(),
            DataType::Integer => self.as_int() == other.as_int(),
            DataType::Float => self.as_float() == other.as_float(),
            DataType::Boolean => self.as_bool() == other.as_bool(),
            DataType::DateTime => self.as_date() == other.as_date(),
            DataType::Date => self.as_date() == other.as_date(),
            DataType::Time => self.as_date() == other.as_date(),
            DataType::Undefined => true,
            DataType::Null => true,
            _ => false,
        }
    }

Expected

DataType::DateTime => self.as_date_time() == other.as_date_time(),
DataType::Date => self.as_date() == other.as_date(),
DataType::Time => self.as_time() == other.as_time(),
AmrDeveloper commented 10 months ago

Hello @craftslab,

Thank you for reporting, i fixed it now and will release it on 0.12.0 this week

Thank you, Amr Hesham

AmrDeveloper commented 10 months ago

Fixed and released on 0.12.0