Last active
September 7, 2018 07:44
-
-
Save rintcius/49d1bfa161c53bdb733ab1a76fc19cbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[error] x perform a ToNumber transformation resulting in big decimals | |
[error] Stream(1.234567890123456789E+12345, 0.0, ?) != Stream(1.234567890123456789E+12345, 1E-400, 9223372036854775808) (TransformSpec.scala:2317) | |
[error] Added (2) | |
[error] 0.0 | |
[error] 9.223372036854776E18 | |
[error] | |
[error] Missing (2) | |
[error] 1E-400 | |
[error] 9223372036854775808 | |
[error] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def toNumber: Slice = { | |
def setNum(nc: ArrayNumColumn, i: Int, s: String): Unit = | |
try { | |
val n = BigDecimal(s) | |
nc.update(i, n) | |
} catch { | |
case _: NumberFormatException => | |
// don't set anything | |
} | |
val size = source.size | |
val columns = source.columns.get(ColumnRef(CPath.Identity, CString)) match { | |
case Some(c: StrColumn) => | |
val lc = ArrayLongColumn.empty(size) | |
val dc = ArrayDoubleColumn.empty(size) | |
val nc = ArrayNumColumn.empty(size) | |
RangeUtil.loopDefined(0 to size, c){ i => | |
val s = c(i) | |
try { | |
val l = java.lang.Long.parseLong(s) | |
lc.update(i, l) | |
} catch { | |
case _: NumberFormatException => | |
try { | |
val d = JDouble.parseDouble(s) | |
if (JDouble.isNaN(d) || JDouble.isInfinite(d)) | |
setNum(nc, i, s) | |
else | |
dc.update(i, d) | |
} catch { | |
case _: NumberFormatException => | |
setNum(nc, i, s) | |
} | |
} | |
} | |
Map[ColumnRef, BitsetColumn]( | |
ColumnRef(CPath.Identity, CLong) -> lc, | |
ColumnRef(CPath.Identity, CDouble) -> dc, | |
ColumnRef(CPath.Identity, CNum) -> nc).foldLeft(Map.empty[ColumnRef, Column]) | |
{ case (acc, (cref, col)) => | |
if (col.definedAt.size > 0) acc + (cref -> col.asInstanceOf[Column]) | |
else acc } | |
case _ => Map.empty[ColumnRef, Column] | |
} | |
Slice(size, columns) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment