Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
26 changes: 23 additions & 3 deletions dask_planner/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ impl PyExpr {
ScalarValue::Float32(_value) => Ok(String::from("Float32")),
ScalarValue::Float64(_value) => Ok(String::from("Float64")),
ScalarValue::Decimal128(_value, ..) => Ok(String::from("Decimal128")),
ScalarValue::Dictionary(..) => Ok(String::from("Dictionary")),
ScalarValue::Int8(_value) => Ok(String::from("Int8")),
ScalarValue::Int16(_value) => Ok(String::from("Int16")),
ScalarValue::Int32(_value) => Ok(String::from("Int32")),
Expand All @@ -418,9 +419,15 @@ impl PyExpr {
ScalarValue::Date32(_value) => Ok(String::from("Date32")),
ScalarValue::Date64(_value) => Ok(String::from("Date64")),
ScalarValue::Null => Ok(String::from("Null")),
_ => {
panic!("CatchAll")
}
ScalarValue::TimestampSecond(..) => Ok(String::from("TimestampSecond")),
ScalarValue::TimestampMillisecond(..) => Ok(String::from("TimestampMillisecond")),
ScalarValue::TimestampMicrosecond(..) => Ok(String::from("TimestampMicrosecond")),
ScalarValue::TimestampNanosecond(..) => Ok(String::from("TimestampNanosecond")),
ScalarValue::IntervalYearMonth(..) => Ok(String::from("IntervalYearMonth")),
ScalarValue::IntervalDayTime(..) => Ok(String::from("IntervalDayTime")),
ScalarValue::IntervalMonthDayNano(..) => Ok(String::from("IntervalMonthDayNano")),
ScalarValue::List(..) => Ok(String::from("List")),
ScalarValue::Struct(..) => Ok(String::from("Struct")),
},
Expr::ScalarFunction { fun, args: _ } => match fun {
BuiltinScalarFunction::Abs => Ok(String::from("Abs")),
Expand Down Expand Up @@ -628,6 +635,19 @@ impl PyExpr {
}
}

#[pyo3(name = "getIntervalDayTimeValue")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add methods to extract this information from interval yearMonth and MonthDayNano types

pub fn interval_day_time_value(&mut self) -> i64 {
match &self.expr {
Expr::Literal(scalar_value) => match scalar_value {
ScalarValue::IntervalDayTime(iv) => iv.clone().unwrap(),
_ => {
panic!("getValue<T>() - Unexpected value")
}
},
_ => panic!("getValue<T>() - Non literal value encountered"),
}
}

#[pyo3(name = "isNegated")]
pub fn is_negated(&self) -> PyResult<bool> {
match &self.expr {
Expand Down
7 changes: 6 additions & 1 deletion dask_sql/physical/rex/core/literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ def convert(
elif literal_type == "Null":
literal_type = SqlTypeName.NULL
literal_value = None
elif literal_type == "IntervalDayTime":
literal_type = SqlTypeName.INTERVAL
literal_value = rex.getIntervalDayTimeValue()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of literal_value is returned in this case? Is it a string or an integer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i64

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we might have to update the logic in sql to python value, since the conversion there seems to assume it's a string and do some computation instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think int should be fine as long as we update the logic here as well: https://github.com/dask-contrib/dask-sql/blob/datafusion-sql-planner/dask_sql/mappings.py#L131.

I'm surprised all tests passed. Maybe none actually test the case where an interval type is passed?

else:
raise RuntimeError("Failed to determine DataFusion Type in literal.py")
raise RuntimeError(
f"Failed to map literal type {literal_type} to python type in literal.py"
)

# if isinstance(literal_value, org.apache.calcite.util.Sarg):
# return SargPythonImplementation(literal_value, literal_type)
Expand Down