This is an automated email from the ASF dual-hosted git repository. jt2594838 pushed a commit to branch add_interfaces_for_type in repository https://gitbox.apache.org/repos/asf/tsfile.git
commit 3fd8785edbad576d0ec525ff7b29b5322bc93579 Author: Tian Jiang <[email protected]> AuthorDate: Mon Jul 20 11:51:24 2026 +0800 refactor RecordUtils --- .../org/apache/tsfile/i18n/messages.properties | 12 ++++++ .../org/apache/tsfile/i18n/messages_zh.properties | 12 ++++++ .../java/org/apache/tsfile/utils/RecordUtils.java | 45 +++++----------------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/java/common/src/main/resources/org/apache/tsfile/i18n/messages.properties b/java/common/src/main/resources/org/apache/tsfile/i18n/messages.properties index 98909f7a6..59679f6fd 100644 --- a/java/common/src/main/resources/org/apache/tsfile/i18n/messages.properties +++ b/java/common/src/main/resources/org/apache/tsfile/i18n/messages.properties @@ -1320,6 +1320,18 @@ log.utils.bytes_int_to_bytes_error = tsfile-common BytesUtils: cannot convert an # BytesUtils.longToBytes — cannot convert long to byte array (3 args: srcNum, pos, width) log.utils.bytes_long_to_bytes_error = tsfile-common BytesUtils: cannot convert a long {} to a byte array, pos {}, width {} +# RecordUtils.parseSimpleTupleRecord — invalid timestamp +log.utils.record_timestamp_illegal = Given timestamp is illegal: {} + +# RecordUtils.parseSimpleTupleRecord — measurement type not found +log.utils.record_measurement_type_not_found = Type not found for measurement ID {}; skipping + +# RecordUtils.parseSimpleTupleRecord — failed to parse measurement +log.utils.record_parse_measurement_error = Failed to parse measurement; omitting it + +# RecordUtils.parseSimpleTupleRecord — unsupported data type +log.utils.record_unsupported_data_type = Unsupported data type: {} + # TsFileSketchTool — cannot load file (filename arg) error.utils.sketch_tool_cannot_load = Cannot load file %1$s because the file has crashed. diff --git a/java/common/src/main/resources/org/apache/tsfile/i18n/messages_zh.properties b/java/common/src/main/resources/org/apache/tsfile/i18n/messages_zh.properties index a1a437cfb..c2406b634 100644 --- a/java/common/src/main/resources/org/apache/tsfile/i18n/messages_zh.properties +++ b/java/common/src/main/resources/org/apache/tsfile/i18n/messages_zh.properties @@ -1320,6 +1320,18 @@ log.utils.bytes_int_to_bytes_error = tsfile-common BytesUtils: 无法将 integer # BytesUtils.longToBytes — cannot convert long to byte array (3 args: srcNum, pos, width) log.utils.bytes_long_to_bytes_error = tsfile-common BytesUtils: 无法将 long {} 转换为 byte 数组,pos {},width {} +# RecordUtils.parseSimpleTupleRecord — 时间戳非法 +log.utils.record_timestamp_illegal = 给定的时间戳非法:{} + +# RecordUtils.parseSimpleTupleRecord — 未找到测点类型 +log.utils.record_measurement_type_not_found = 未找到 measurement ID {} 的类型,跳过该测点 + +# RecordUtils.parseSimpleTupleRecord — 测点解析失败 +log.utils.record_parse_measurement_error = 解析测点时出错,已忽略 + +# RecordUtils.parseSimpleTupleRecord — 不支持的数据类型 +log.utils.record_unsupported_data_type = 不支持的数据类型:{} + # TsFileSketchTool — cannot load file (filename arg) error.utils.sketch_tool_cannot_load = 无法加载文件 %1$s,因为文件已损坏。 diff --git a/java/tsfile/src/test/java/org/apache/tsfile/utils/RecordUtils.java b/java/tsfile/src/test/java/org/apache/tsfile/utils/RecordUtils.java index 7e623590b..f67f82a0b 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/utils/RecordUtils.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/utils/RecordUtils.java @@ -21,13 +21,10 @@ package org.apache.tsfile.utils; import org.apache.tsfile.common.constant.JsonFormatConstant; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.file.metadata.IDeviceID.Factory; +import org.apache.tsfile.i18n.Messages; +import org.apache.tsfile.read.common.type.Type; +import org.apache.tsfile.write.UnSupportedDataTypeException; import org.apache.tsfile.write.record.TSRecord; -import org.apache.tsfile.write.record.datapoint.BooleanDataPoint; -import org.apache.tsfile.write.record.datapoint.DoubleDataPoint; -import org.apache.tsfile.write.record.datapoint.FloatDataPoint; -import org.apache.tsfile.write.record.datapoint.IntDataPoint; -import org.apache.tsfile.write.record.datapoint.LongDataPoint; -import org.apache.tsfile.write.record.datapoint.StringDataPoint; import org.apache.tsfile.write.schema.IMeasurementSchema; import org.apache.tsfile.write.schema.Schema; @@ -56,7 +53,7 @@ public class RecordUtils { try { timestamp = Long.parseLong(items[1].trim()); } catch (NumberFormatException e) { - LOG.warn("given timestamp is illegal:{}", str); + LOG.warn(Messages.get("log.utils.record_timestamp_illegal"), str); // return a TSRecord without any data points return new TSRecord(deviceId, -1); } @@ -75,7 +72,7 @@ public class RecordUtils { ? null : measurementGroup.getMeasurementSchemaMap().get(measurementId); if (measurementSchema == null) { - LOG.warn("measurementId:{},type not found, pass", measurementId); + LOG.warn(Messages.get("log.utils.record_measurement_type_not_found"), measurementId); continue; } type = measurementSchema.getType(); @@ -84,35 +81,11 @@ public class RecordUtils { // TSRecord if (!"".equals(value)) { try { - switch (type) { - case INT32: - case DATE: - ret.addTuple(new IntDataPoint(measurementId, Integer.parseInt(value))); - break; - case INT64: - case TIMESTAMP: - ret.addTuple(new LongDataPoint(measurementId, Long.parseLong(value))); - break; - case FLOAT: - ret.addTuple(new FloatDataPoint(measurementId, Float.parseFloat(value))); - break; - case DOUBLE: - ret.addTuple(new DoubleDataPoint(measurementId, Double.parseDouble(value))); - break; - case BOOLEAN: - ret.addTuple(new BooleanDataPoint(measurementId, Boolean.parseBoolean(value))); - break; - case TEXT: - case BLOB: - case STRING: - ret.addTuple(new StringDataPoint(measurementId, BytesUtils.valueOf(items[i + 1]))); - break; - default: - LOG.warn("unsupported data type:{}", type); - break; - } + ret.addTuple(Type.fromTsDataType(type).getDataPoint(measurementId, value)); } catch (NumberFormatException e) { - LOG.warn("parsing measurement meets error, omit it", e); + LOG.warn(Messages.get("log.utils.record_parse_measurement_error"), e); + } catch (UnSupportedDataTypeException e) { + LOG.warn(Messages.get("log.utils.record_unsupported_data_type"), type); } } }
