From 3745ef7845348700e2b250641a4fa48742007d99 Mon Sep 17 00:00:00 2001 From: Laljo John Pullokkaran Date: Thu, 22 Dec 2016 13:52:36 -0800 Subject: [PATCH] Fix approx numeric to integral numeric conversion in JS --- .../sparklinedata/druid/jscodegen/JSCast.scala | 2 +- .../druid/client/test/CodeGenTest.scala | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/scala/org/sparklinedata/druid/jscodegen/JSCast.scala b/src/main/scala/org/sparklinedata/druid/jscodegen/JSCast.scala index c3a0612..50f7a29 100644 --- a/src/main/scala/org/sparklinedata/druid/jscodegen/JSCast.scala +++ b/src/main/scala/org/sparklinedata/druid/jscodegen/JSCast.scala @@ -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 => diff --git a/src/test/scala/org/sparklinedata/druid/client/test/CodeGenTest.scala b/src/test/scala/org/sparklinedata/druid/client/test/CodeGenTest.scala index aa3012e..0b9b112 100644 --- a/src/test/scala/org/sparklinedata/druid/client/test/CodeGenTest.scala +++ b/src/test/scala/org/sparklinedata/druid/client/test/CodeGenTest.scala @@ -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) }