Skip to content

Commit

Permalink
add more tests to literal values type
Browse files Browse the repository at this point in the history
  • Loading branch information
3cham committed Apr 30, 2024
1 parent 8eef602 commit 32aa427
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
27 changes: 26 additions & 1 deletion logical-plan/src/main/kotlin/Expressions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,29 @@ class LiteralLong(val n: Long): LogicalExpr {
}
}

fun lit(value: Long) = LiteralLong(value)
fun lit(value: Long) = LiteralLong(value)

class LiteralFloat(val n: Float): LogicalExpr {
override fun toField(input: LogicalPlan): Field {
return Field(n.toString(), ArrowTypes.FloatType)
}

override fun toString(): String {
return n.toString()
}
}

fun lit(value: Float) = LiteralFloat(value)

class LiteralDouble(val n: Double): LogicalExpr {
override fun toField(input: LogicalPlan): Field {
return Field(n.toString(), ArrowTypes.DoubleType)
}

override fun toString(): String {
return n.toString()
}
}

fun lit(value: Double) = LiteralDouble(value)

14 changes: 14 additions & 0 deletions logical-plan/src/test/kotlin/ExpressionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ class ExpressionsTest {

assertEquals(litStr.toString(), "10000000000")
}

@Test
fun `test LiteralFloat toString`() {
val litStr = lit(1e10.toFloat())

assertEquals(litStr.toString(), "1.0E10")
}

@Test
fun `test LiteralDouble toString`() {
val litStr = lit(1e10)

assertEquals(litStr.toString(), "1.0E10")
}
}

0 comments on commit 32aa427

Please sign in to comment.