jt2594838 commented on code in PR #568:
URL: https://github.com/apache/tsfile/pull/568#discussion_r2281940694
##########
java/tsfile/src/main/java/org/apache/tsfile/file/metadata/IDeviceID.java:
##########
@@ -47,6 +47,8 @@ public interface IDeviceID extends Comparable<IDeviceID>,
Accountable, Serializa
boolean isTableModel();
+ String getDeviceID();
Review Comment:
May just use toString().
##########
java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/TreeResultSet.java:
##########
@@ -56,6 +72,92 @@ public void close() {
@Override
public Iterator<TSRecord> recordIterator() {
- return null;
+ return new TreeResultSet.RecordIterator();
+ }
+
+ private class RecordIterator implements Iterator<TSRecord> {
+ private final LinkedList<TSRecord> recordBuffer = new LinkedList<>();
+ private boolean exhausted = false;
+
+ @Override
+ public boolean hasNext() {
+ if (!recordBuffer.isEmpty()) {
+ return true;
+ }
+ if (exhausted) {
+ return false;
+ }
+
+ try {
+ return fetchRecords();
+ } catch (IOException e) {
+ throw new NoSuchElementException(e.toString());
+ }
+ }
+
+ private boolean fetchRecords() throws IOException {
+ boolean hasNewRecords = false;
+ while (TreeResultSet.this.next()) {
+ for (String device : deviceList) {
+ TSRecord record = new TSRecord(device, getLong("Time"));
+ record.addPoint("id", device);
+
+ for (String measurement : measurementList) {
+ Integer pathIdx =
+ pathIndexMap.get(new Path(new StringArrayDeviceID(device),
measurement, false));
Review Comment:
May cache the DeviceIds (or the paths) as a list. Recalculating them each
time can be costly.
##########
java/tsfile/src/test/java/org/apache/tsfile/tableview/PerformanceTest.java:
##########
@@ -1,51 +1,27 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
Review Comment:
Why is the license removed
##########
java/tsfile/src/main/java/org/apache/tsfile/write/schema/MeasurementSchemaBuilder.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tsfile.write.schema;
+
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.file.metadata.enums.CompressionType;
+import org.apache.tsfile.file.metadata.enums.TSEncoding;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A builder class for constructing {@link MeasurementSchema} instances.
+ *
+ * <p>This builder provides a fluent API for setting various properties of a
measurement schema,
+ * including required fields (name and data type) and optional fields
(encoding and compression).
+ *
+ * <p>Example usage:
+ *
+ * <pre>{@code
+ * MeasurementSchema schema = new MeasurementSchemaBuilder("temperature",
TSDataType.FLOAT)
+ * .withEncoding(TSEncoding.RLE)
+ * .withCompression(CompressionType.SNAPPY)
+ * .build();
+ * }</pre>
+ */
+public class MeasurementSchemaBuilder {
+ private String measurementName;
+ private TSDataType dataType;
+ private TSEncoding encoding;
+ private CompressionType compressionType;
+ private Map<String, String> props;
+
+ /**
+ * Creates a new builder with the required fields.
+ *
+ * @param measurementName the name of the measurement (cannot be null or
empty)
+ * @param dataType the data type of the measurement (cannot be null)
+ * @throws IllegalArgumentException if required parameters are null or empty
+ */
+ public MeasurementSchemaBuilder(String measurementName, TSDataType dataType)
{
+ if (measurementName == null || measurementName.trim().isEmpty()) {
+ throw new IllegalArgumentException("Measurement name cannot be null or
empty");
+ }
+ if (dataType == null) {
+ throw new IllegalArgumentException("Data type cannot be null");
+ }
+
+ this.measurementName = measurementName;
+ this.dataType = dataType;
+ // Set default values from TSFile configuration
+ this.encoding =
+
TSEncoding.valueOf(TSFileDescriptor.getInstance().getConfig().getValueEncoder(dataType));
+ this.compressionType =
TSFileDescriptor.getInstance().getConfig().getCompressor();
Review Comment:
Compression can also be determined by type now.
##########
java/tsfile/src/main/java/org/apache/tsfile/read/v4/TsFileTreeReader.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tsfile.read.v4;
+
+import org.apache.tsfile.annotations.TreeModel;
+import org.apache.tsfile.annotations.TsFileApi;
+import org.apache.tsfile.file.metadata.PlainDeviceID;
+import org.apache.tsfile.read.TsFileReader;
+import org.apache.tsfile.read.common.Path;
+import org.apache.tsfile.read.expression.IExpression;
+import org.apache.tsfile.read.expression.QueryExpression;
+import org.apache.tsfile.read.expression.impl.GlobalTimeExpression;
+import org.apache.tsfile.read.filter.operator.TimeFilterOperators;
+import org.apache.tsfile.read.query.dataset.QueryDataSet;
+import org.apache.tsfile.read.query.dataset.ResultSet;
+import org.apache.tsfile.read.query.dataset.TreeResultSet;
+import org.apache.tsfile.write.schema.MeasurementSchema;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * TsFileTreeReader is an implementation of ITsFileTreeReader that provides
query capability for
+ * TsFile with a tree-style interface. It internally wraps {@link
TsFileReader}.
+ */
+public class TsFileTreeReader implements ITsFileTreeReader {
+ private final TsFileReader tsfileReader;
+
+ /**
+ * Construct a TsFileTreeReader with the given TsFile.
+ *
+ * @param file the TsFile to read
+ * @throws IOException if an I/O error occurs during file opening
+ */
+ @TsFileApi
+ @TreeModel
+ public TsFileTreeReader(File file) throws IOException {
+ tsfileReader = new TsFileReader(file);
+ }
+
+ /**
+ * Execute a query on the given devices and measurements within the
specified time range.
+ *
+ * @param deviceIds list of device IDs to query
+ * @param measurementNames list of measurement names to query
+ * @param startTime query start timestamp (inclusive)
+ * @param endTime query end timestamp (inclusive)
+ * @return a {@link ResultSet} containing the query results
+ * @throws IOException if an I/O error occurs during query execution
+ */
+ @TsFileApi
+ @TreeModel
+ @Override
+ public ResultSet query(
+ List<String> deviceIds, List<String> measurementNames, long startTime,
long endTime)
+ throws IOException {
+ List<Path> paths = new ArrayList<>();
+ for (String deviceId : deviceIds) {
+ for (String measurementName : measurementNames) {
+ paths.add(new Path(deviceId, measurementName, true));
+ }
+ }
+ IExpression expression =
+ new GlobalTimeExpression(new
TimeFilterOperators.TimeBetweenAnd(startTime, endTime));
+ QueryExpression queryExpression = QueryExpression.create(paths,
expression);
+ QueryDataSet queryDataSet = tsfileReader.query(queryExpression);
+ return new TreeResultSet(queryDataSet, deviceIds, measurementNames);
+ }
+
+ /**
+ * Get all device IDs existing in the TsFile.
+ *
+ * @return list of all device IDs
+ * @throws IOException if an I/O error occurs during metadata fetching
+ */
+ @TsFileApi
+ @TreeModel
+ @Override
+ public List<String> getAllDeviceIds() throws IOException {
+ return tsfileReader.getAllDeviceIds();
+ }
+
+ /**
+ * Get the measurement schema of the given device.
+ *
+ * @param deviceId the target device ID
+ * @return list of {@link MeasurementSchema} for the device
+ * @throws IOException if an I/O error occurs during schema fetching
+ */
+ @TsFileApi
+ @TreeModel
+ @Override
+ public List<MeasurementSchema> getDeviceSchema(String deviceId) throws
IOException {
+ return tsfileReader.getMeasurement(new PlainDeviceID(deviceId));
Review Comment:
Do not use PlainDeviceID anymore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]