in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java [76:169]
public static Object parseValue(TSDataType dataType, String value, ZoneId zoneId)
throws QueryProcessException {
try {
if ("null".equals(value) || "NULL".equals(value)) {
return null;
}
switch (dataType) {
case BOOLEAN:
return parseBoolean(value);
case INT32:
try {
return Integer.parseInt(StringUtils.trim(value));
} catch (NumberFormatException e) {
throw new NumberFormatException(
"data type is not consistent, input " + value + ", registered " + dataType);
}
case INT64:
try {
return Long.parseLong(StringUtils.trim(value));
} catch (NumberFormatException e) {
throw new NumberFormatException(
"data type is not consistent, input " + value + ", registered " + dataType);
}
case TIMESTAMP:
try {
if (TypeInferenceUtils.isNumber(value)) {
return Long.parseLong(value);
} else {
return DateTimeUtils.parseDateTimeExpressionToLong(StringUtils.trim(value), zoneId);
}
} catch (Throwable e) {
throw new NumberFormatException(
"data type is not consistent, input "
+ value
+ ", registered "
+ dataType
+ " because "
+ e.getMessage());
}
case DATE:
return parseIntFromString(value);
case FLOAT:
float f;
try {
f = Float.parseFloat(value);
} catch (NumberFormatException e) {
throw new NumberFormatException(
"data type is not consistent, input " + value + ", registered " + dataType);
}
if (Float.isInfinite(f)) {
throw new NumberFormatException("The input float value is Infinity");
}
return f;
case DOUBLE:
double d;
try {
d = Double.parseDouble(value);
} catch (NumberFormatException e) {
throw new NumberFormatException(
"data type is not consistent, input " + value + ", registered " + dataType);
}
if (Double.isInfinite(d)) {
throw new NumberFormatException("The input double value is Infinity");
}
return d;
case TEXT:
case STRING:
if ((value.startsWith(SqlConstant.QUOTE) && value.endsWith(SqlConstant.QUOTE))
|| (value.startsWith(SqlConstant.DQUOTE) && value.endsWith(SqlConstant.DQUOTE))) {
if (value.length() == 1) {
return new Binary(value, TSFileConfig.STRING_CHARSET);
} else {
return new Binary(
value.substring(1, value.length() - 1), TSFileConfig.STRING_CHARSET);
}
}
return new Binary(value, TSFileConfig.STRING_CHARSET);
case BLOB:
if ((value.startsWith(SqlConstant.QUOTE) && value.endsWith(SqlConstant.QUOTE))
|| (value.startsWith(SqlConstant.DQUOTE) && value.endsWith(SqlConstant.DQUOTE))) {
if (value.length() == 1) {
return new Binary(parseBlobStringToByteArray(value));
} else {
return new Binary(parseBlobStringToByteArray(value.substring(1, value.length() - 1)));
}
}
return new Binary(parseBlobStringToByteArray(value));
default:
throw new QueryProcessException("Unsupported data type:" + dataType);
}
} catch (NumberFormatException e) {
throw new QueryProcessException(e.getMessage());
}
}