Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Commit

Permalink
Fix approx numeric to integral numeric conversion in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
jpullokkaran committed Dec 22, 2016
1 parent 9ff31cf commit 3745ef7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ case class JSCast(from: JSExpr, toDT: DataType, ctx: JSCodeGenerator) {
case BooleanType | StringType =>
Some(JSExpr(None, from.linesSoFar, s"Number(${from.getRef})", outDt))
case (FloatType | DoubleType) if ctx.SPIntegralNumeric(outDt) =>
Some (JSExpr(None, from.linesSoFar, s"Math.round(${from.getRef})", outDt))
Some (JSExpr(None, from.linesSoFar, s"Math.floor(${from.getRef})", outDt))
case ShortType | IntegerType | LongType| FloatType | DoubleType =>
Some (JSExpr(None, from.linesSoFar, from.getRef, outDt))
case DateType =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,5 +966,20 @@ class CodeGenTest extends BaseTest with BeforeAndAfterAll with Logging {
""".stripMargin
, 1, true, true)

test("tscomp3",
"""
|select sum(c_acctbal), o_orderdate from orderLineItemPartSupplier
|where CAST((MONTH(CAST(CONCAT(TO_DATE(o_orderdate),' 00:00:00') AS TIMESTAMP)) - 1) / 3 + 1 AS BIGINT) < 2
|group by c_name, o_orderdate
""".stripMargin
, 1, true, true)

test("binaryunhex1",
"""
|select sum(c_acctbal), o_orderdate from orderLineItemPartSupplier
|where c_nation < concat(CAST(UNHEX('c2a3') AS string), '349- W10_HulfordsOLVPen15Sub_UK_640x480_ISV_V2_x264')
|group by c_name, o_orderdate
""".stripMargin
, 1, true, true)
}

0 comments on commit 3745ef7

Please sign in to comment.