in s2core/src/main/scala/org/apache/s2graph/core/JSONParser.scala [179:238]
def toInnerVal(any: Any, dataType: String, version: String): InnerValLike = {
val dType = InnerVal.toInnerDataType(dataType)
val isNumeric = isNumericType(dType)
any match {
case v: VertexId => v.innerId
case a: InnerValLike => a
case n: BigDecimal =>
if (isNumeric) InnerVal.withNumber(n, version)
else if (dType == InnerVal.STRING) InnerVal.withStr(n.toString, version)
else throw new IllegalDataTypeException(s"[ValueType] = BigDecimal, [DataType]: $dataType, [Input]: $any")
case l: Long =>
if (isNumeric) InnerVal.withLong(l, version)
else if (dType == InnerVal.STRING) InnerVal.withStr(l.toString, version)
else throw new IllegalDataTypeException(s"[ValueType] = Long, [DataType]: $dataType, [Input]: $any")
case i: Int =>
if (isNumeric) InnerVal.withInt(i, version)
else if (dType == InnerVal.STRING) InnerVal.withStr(i.toString, version)
else throw new IllegalDataTypeException(s"[ValueType] = Int, [DataType]: $dataType, [Input]: $any")
case sh: Short =>
if (isNumeric) InnerVal.withInt(sh.toInt, version)
else if (dType == InnerVal.STRING) InnerVal.withStr(sh.toString, version)
else throw new IllegalDataTypeException(s"[ValueType] = Short, [DataType]: $dataType, [Input]: $any")
case b: Byte =>
if (isNumeric) InnerVal.withInt(b.toInt, version)
else if (dType == InnerVal.STRING) InnerVal.withStr(b.toString, version)
else throw new IllegalDataTypeException(s"[ValueType] = Byte, [DataType]: $dataType, [Input]: $any")
case f: Float =>
if (isNumeric) InnerVal.withFloat(f, version)
else if (dType == InnerVal.STRING) InnerVal.withStr(f.toString, version)
else throw new IllegalDataTypeException(s"[ValueType] = Float, [DataType]: $dataType, [Input]: $any")
case d: Double =>
if (isNumeric) InnerVal.withDouble(d, version)
else if (dType == InnerVal.STRING) InnerVal.withStr(d.toString, version)
else throw new IllegalDataTypeException(s"[ValueType] = Double, [DataType]: $dataType, [Input]: $any")
case bl: Boolean =>
if (dType == InnerVal.BOOLEAN) InnerVal.withBoolean(bl, version)
else if (dType == InnerVal.STRING) InnerVal.withStr(bl.toString, version)
else throw new IllegalDataTypeException(s"[ValueType] = Boolean, [DataType]: $dataType, [Input]: $any")
case _s: String =>
if (isNumeric) {
try {
val s = TemplateHelper.replaceVariable(System.currentTimeMillis(), _s.toString)
InnerVal.withNumber(BigDecimal(s), version)
} catch {
case e: Exception =>
throw new IllegalDataTypeException(s"[ValueType] = String, [DataType]: $dataType, [Input]: $any")
}
} else {
dType match {
case InnerVal.BOOLEAN => try {
InnerVal.withBoolean(_s.toBoolean, version)
} catch {
case e: Exception =>
throw new IllegalDataTypeException(s"[ValueType] = String, [DataType]: boolean, [Input]: $any")
}
case InnerVal.STRING => InnerVal.withStr(_s, version)
}
}
}
}