Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-parent</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</parent>
<artifactId>tsfile-cpp</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion java/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</parent>
<artifactId>common</artifactId>
<name>TsFile: Java: Common</name>
Expand Down
4 changes: 2 additions & 2 deletions java/examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</parent>
<artifactId>examples</artifactId>
<name>TsFile: Java: Examples</name>
Expand All @@ -36,7 +36,7 @@
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down
4 changes: 2 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-parent</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</parent>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>TsFile: Java</name>
<modules>
Expand Down
6 changes: 3 additions & 3 deletions java/tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</parent>
<artifactId>tools</artifactId>
<name>TsFile: Java: Tools</name>
<dependencies>
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>common</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand All @@ -50,7 +50,7 @@
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
4 changes: 2 additions & 2 deletions java/tsfile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.tsfile</groupId>
<artifactId>tsfile-java</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</parent>
<artifactId>tsfile</artifactId>
<name>TsFile: Java: TsFile</name>
Expand All @@ -38,7 +38,7 @@
<dependency>
<groupId>org.apache.tsfile</groupId>
<artifactId>common</artifactId>
<version>2.1.0-250325-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.luben</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@
import java.io.IOException;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -1492,6 +1494,11 @@ public Map<IDeviceID, List<TimeseriesMetadata>> getAllTimeseriesMetadata(
return timeseriesMetadataMap;
}

public Iterator<Pair<IDeviceID, List<TimeseriesMetadata>>> iterAllTimeseriesMetadata(
boolean needChunkMetadata) throws IOException {
return new TimeseriesMetadataIterator(needChunkMetadata);
}

/* This method will only deserialize the TimeseriesMetadata, not including chunk metadata list */
public List<TimeseriesMetadata> getDeviceTimeseriesMetadataWithoutChunkMetadata(IDeviceID device)
throws IOException {
Expand Down Expand Up @@ -2973,4 +2980,129 @@ public int hashCode() {
public DeserializeConfig getDeserializeContext() {
return deserializeConfig;
}

private class TimeseriesMetadataIterator
implements Iterator<Pair<IDeviceID, List<TimeseriesMetadata>>> {

private final Deque<MetadataIndexNode> nodeStack = new ArrayDeque<>();
private final boolean needChunkMetadata;
private Pair<IDeviceID, List<TimeseriesMetadata>> nextValue;
private MetadataIndexNode currentLeafDeviceNode;
private int currentLeafDeviceNodeIndex;

public TimeseriesMetadataIterator(boolean needChunkMetadata) throws IOException {
this.needChunkMetadata = needChunkMetadata;
if (tsFileMetaData == null) {
readFileMetadata();
}

nodeStack.addAll(tsFileMetaData.getTableMetadataIndexNodeMap().values());
}

@Override
public boolean hasNext() {
if (nextValue != null) {
return true;
}

try {
loadNextValue();
} catch (IOException e) {
logger.warn("Cannot read timeseries metadata from {},", file, e);
return false;
}
return nextValue != null;
}

@Override
public Pair<IDeviceID, List<TimeseriesMetadata>> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Pair<IDeviceID, List<TimeseriesMetadata>> ret = nextValue;
nextValue = null;
return ret;
}

private void loadNextLeafDeviceNode() throws IOException {
while (!nodeStack.isEmpty()) {
MetadataIndexNode node = nodeStack.pop();
MetadataIndexNodeType nodeType = node.getNodeType();
if (nodeType.equals(MetadataIndexNodeType.LEAF_DEVICE)) {
currentLeafDeviceNode = node;
currentLeafDeviceNodeIndex = 0;
return;
}

List<IMetadataIndexEntry> childrenIndex = node.getChildren();
for (int i = 0; i < childrenIndex.size(); i++) {
long endOffset;
IMetadataIndexEntry childIndex = childrenIndex.get(i);
endOffset = node.getEndOffset();
if (i != childrenIndex.size() - 1) {
endOffset = childrenIndex.get(i + 1).getOffset();
}

MetadataIndexNode child;
if (endOffset - childIndex.getOffset() < Integer.MAX_VALUE) {
ByteBuffer buffer = readData(childIndex.getOffset(), endOffset);
child = deserializeConfig.deserializeMetadataIndexNode(buffer, true);
} else {
tsFileInput.position(childIndex.getOffset());
child =
deserializeConfig.deserializeMetadataIndexNode(
tsFileInput.wrapAsInputStream(), true);
}
nodeStack.push(child);
}
}
}

private void loadNextValue() throws IOException {
if (currentLeafDeviceNode == null
|| currentLeafDeviceNodeIndex >= currentLeafDeviceNode.getChildren().size()) {
currentLeafDeviceNode = null;
loadNextLeafDeviceNode();
}
if (currentLeafDeviceNode == null) {
return;
}

IMetadataIndexEntry childIndex =
currentLeafDeviceNode.getChildren().get(currentLeafDeviceNodeIndex);
int childNum = currentLeafDeviceNode.getChildren().size();
IDeviceID deviceId = ((DeviceMetadataIndexEntry) childIndex).getDeviceID();

Map<IDeviceID, List<TimeseriesMetadata>> nextValueMap = new HashMap<>(1);
long endOffset = currentLeafDeviceNode.getEndOffset();
if (currentLeafDeviceNodeIndex != childNum - 1) {
endOffset =
currentLeafDeviceNode.getChildren().get(currentLeafDeviceNodeIndex + 1).getOffset();
}
if (endOffset - childIndex.getOffset() < Integer.MAX_VALUE) {
ByteBuffer nextBuffer = readData(childIndex.getOffset(), endOffset);
generateMetadataIndex(
childIndex,
nextBuffer,
deviceId,
currentLeafDeviceNode.getNodeType(),
nextValueMap,
needChunkMetadata);
} else {
// when the buffer length is over than Integer.MAX_VALUE,
// using tsFileInput to get timeseriesMetadataList
generateMetadataIndexUsingTsFileInput(
childIndex,
childIndex.getOffset(),
endOffset,
deviceId,
currentLeafDeviceNode.getNodeType(),
nextValueMap,
needChunkMetadata);
}
currentLeafDeviceNodeIndex++;
Entry<IDeviceID, List<TimeseriesMetadata>> entry = nextValueMap.entrySet().iterator().next();
nextValue = new Pair<>(entry.getKey(), entry.getValue());
}
}
}
Loading