Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Added division and mod operations for NumericColumns #100

Merged
merged 2 commits into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions core/src/main/scala/doric/syntax/NumericColumns.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ private[syntax] trait NumericColumns {
def *(other: DoricColumn[T]): DoricColumn[T] =
sparkFunction(column, other, _ * _)

/**
* @group Numeric Type
*/
def /(other: DoricColumn[T]): DoricColumn[Double] =
sparkFunction(column, other, _ / _)

/**
* @group Numeric Type
*/
def %(other: DoricColumn[T]): DoricColumn[T] =
sparkFunction(column, other, _ % _)

/**
* @group Comparable Type
*/
Expand Down
14 changes: 13 additions & 1 deletion core/src/test/scala/doric/syntax/NumericOperationsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ trait NumericOperationsSpec extends AnyFunSpecLike with TypedColumnTest {
it("*") {
test[T, T, T]((a, b) => a * b)
}
it("/") {
test[T, T, Double]((a, b) => a / b)
}
it("%") {
test[T, T, T]((a, b) => a % b)
}
it(">") {
test[T, T, Boolean]((a, b) => a > b)
}
Expand Down Expand Up @@ -61,9 +67,15 @@ class NumericSpec extends NumericOperationsSpec with SparkSessionTestWrapper {
import spark.implicits._

def df: DataFrame =
List((1, 2f, 3L)).toDF(getName[Int](), getName[Float](), getName[Long]())
List((1, 2f, 3L, 4.toDouble)).toDF(
getName[Int](),
getName[Float](),
getName[Long](),
getName[Double]()
)

test[Int]()
test[Float]()
test[Long]()
test[Double]()
}