Skip to content

Commit d00a089

Browse files
Add Support for modulus operation in substrait (#13108)
* Add modulus operation * change the producer to output `modulus` instead of `mod` for `modulo` operation * Add a roundtrip test case for modulus
1 parent 67b0f25 commit d00a089

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

datafusion/substrait/src/logical_plan/consumer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub fn name_to_op(name: &str) -> Option<Operator> {
118118
"multiply" => Some(Operator::Multiply),
119119
"divide" => Some(Operator::Divide),
120120
"mod" => Some(Operator::Modulo),
121+
"modulus" => Some(Operator::Modulo),
121122
"and" => Some(Operator::And),
122123
"or" => Some(Operator::Or),
123124
"is_distinct_from" => Some(Operator::IsDistinctFrom),

datafusion/substrait/src/logical_plan/producer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ pub fn operator_to_name(op: Operator) -> &'static str {
744744
Operator::Minus => "subtract",
745745
Operator::Multiply => "multiply",
746746
Operator::Divide => "divide",
747-
Operator::Modulo => "mod",
747+
Operator::Modulo => "modulus",
748748
Operator::And => "and",
749749
Operator::Or => "or",
750750
Operator::IsDistinctFrom => "is_distinct_from",

datafusion/substrait/tests/cases/roundtrip_logical_plan.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,11 @@ async fn roundtrip_ilike() -> Result<()> {
593593
roundtrip("SELECT f FROM data WHERE f ILIKE 'a%b'").await
594594
}
595595

596+
#[tokio::test]
597+
async fn roundtrip_modulus() -> Result<()> {
598+
roundtrip("SELECT a%3 from data").await
599+
}
600+
596601
#[tokio::test]
597602
async fn roundtrip_not() -> Result<()> {
598603
roundtrip("SELECT * FROM data WHERE NOT d").await

0 commit comments

Comments
 (0)