This is an automated email from the ASF dual-hosted git repository.
zyk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 6a58af8c8b [IOTDB-3063] Set up SchemaReader and apply them in show
devices and show timeseries (#8677)
6a58af8c8b is described below
commit 6a58af8c8b92d576e142f4c5c390188f01cc4da1
Author: Marcos_Zyk <[email protected]>
AuthorDate: Tue Jan 3 17:13:56 2023 +0800
[IOTDB-3063] Set up SchemaReader and apply them in show devices and show
timeseries (#8677)
[IOTDB-3063] Set up SchemaReader and apply them in show devices and show
timeseries (#8677)
---
.../schemaregion/rocksdb/RSchemaRegion.java | 34 +++------
.../metadata/tagSchemaRegion/TagSchemaRegion.java | 16 ++---
.../utils/ShowTimeSeriesResultUtils.java | 41 ++++++-----
.../iotdb/db/metadata/mtree/IMTreeBelowSG.java | 12 +---
.../db/metadata/mtree/MTreeBelowSGCachedImpl.java | 59 ++++++----------
.../db/metadata/mtree/MTreeBelowSGMemoryImpl.java | 58 ++++++----------
.../schemaregion/result/ShowDevicesResult.java | 21 ++----
.../plan/schemaregion/result/ShowSchemaResult.java | 26 ++++---
.../schemaregion/result/ShowTimeSeriesResult.java | 55 +++++++--------
.../info/IDeviceSchemaInfo.java} | 32 ++-------
.../info/ISchemaInfo.java} | 32 ++-------
.../info/ITimeSeriesSchemaInfo.java} | 31 +++------
.../reader/ISchemaReader.java} | 33 ++-------
.../db/metadata/schemaregion/ISchemaRegion.java | 56 +++++++++++++--
.../schemaregion/SchemaRegionMemoryImpl.java | 70 ++++++-------------
.../schemaregion/SchemaRegionSchemaFileImpl.java | 64 ++++++-----------
.../operator/schema/DevicesSchemaScanOperator.java | 19 +++--
.../operator/schema/SchemaQueryScanOperator.java | 13 ++++
.../schema/TimeSeriesSchemaScanOperator.java | 37 +++++-----
.../schemaRegion/SchemaRegionAliasAndTagTest.java | 29 ++++----
.../schemaRegion/SchemaRegionBasicTest.java | 33 ++++-----
.../schemaRegion/SchemaRegionManagementTest.java | 21 +++---
.../schema/SchemaQueryScanOperatorTest.java | 80 +++++++++++++++-------
23 files changed, 377 insertions(+), 495 deletions(-)
diff --git
a/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
b/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
index b0623d3854..4f682369db 100644
---
a/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
+++
b/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
@@ -62,7 +62,6 @@ import
org.apache.iotdb.db.metadata.schemaregion.rocksdb.mnode.RMNodeValueType;
import
org.apache.iotdb.db.metadata.schemaregion.rocksdb.mnode.RMeasurementMNode;
import org.apache.iotdb.db.metadata.template.Template;
import org.apache.iotdb.db.metadata.utils.MetaFormatUtils;
-import org.apache.iotdb.db.metadata.utils.MetaUtils;
import org.apache.iotdb.db.utils.SchemaUtils;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -1039,20 +1038,18 @@ public class RSchemaRegion implements ISchemaRegion {
}
@Override
- public Pair<List<ShowDevicesResult>, Integer>
getMatchedDevices(IShowDevicesPlan plan)
- throws MetadataException {
+ public List<ShowDevicesResult> getMatchedDevices(IShowDevicesPlan plan)
throws MetadataException {
List<ShowDevicesResult> res = Collections.synchronizedList(new
ArrayList<>());
BiFunction<byte[], byte[], Boolean> function =
(a, b) -> {
String fullPath = RSchemaUtils.getPathByInnerName(new String(a));
- res.add(new ShowDevicesResult(fullPath, RSchemaUtils.isAligned(b),
storageGroupFullPath));
+ res.add(new ShowDevicesResult(fullPath, RSchemaUtils.isAligned(b)));
return true;
};
traverseOutcomeBasins(
plan.getPath().getNodes(), MAX_PATH_DEPTH, function, new Character[]
{NODE_TYPE_ENTITY});
- // todo Page query, record offset
- return new Pair<>(res, 1);
+ return res;
}
@Override
@@ -1094,7 +1091,7 @@ public class RSchemaRegion implements ISchemaRegion {
}
@Override
- public Pair<List<ShowTimeSeriesResult>, Integer>
showTimeseries(IShowTimeSeriesPlan plan)
+ public List<ShowTimeSeriesResult> showTimeseries(IShowTimeSeriesPlan plan)
throws MetadataException {
if (plan.getKey() != null && plan.getValue() != null) {
return showTimeseriesWithIndex(plan);
@@ -1103,15 +1100,14 @@ public class RSchemaRegion implements ISchemaRegion {
}
}
- private Pair<List<ShowTimeSeriesResult>, Integer> showTimeseriesWithIndex(
- IShowTimeSeriesPlan plan) {
+ private List<ShowTimeSeriesResult>
showTimeseriesWithIndex(IShowTimeSeriesPlan plan) {
// temporarily unsupported
throw new UnsupportedOperationException(
formatNotSupportInfo(Thread.currentThread().getStackTrace()[1].getMethodName()));
}
- private Pair<List<ShowTimeSeriesResult>, Integer> showTimeseriesWithoutIndex(
- IShowTimeSeriesPlan plan) throws MetadataException {
+ private List<ShowTimeSeriesResult>
showTimeseriesWithoutIndex(IShowTimeSeriesPlan plan)
+ throws MetadataException {
List<ShowTimeSeriesResult> res = new LinkedList<>();
Map<MeasurementPath, Pair<Map<String, String>, Map<String, String>>>
measurementPathsAndTags =
@@ -1119,24 +1115,16 @@ public class RSchemaRegion implements ISchemaRegion {
for (Entry<MeasurementPath, Pair<Map<String, String>, Map<String,
String>>> entry :
measurementPathsAndTags.entrySet()) {
MeasurementPath measurementPath = entry.getKey();
- Pair<String, String> deadbandInfo =
- MetaUtils.parseDeadbandInfo(
- ((MeasurementSchema)
measurementPath.getMeasurementSchema()).getProps());
res.add(
new ShowTimeSeriesResult(
measurementPath.getFullPath(),
measurementPath.getMeasurementAlias(),
- storageGroupFullPath,
- measurementPath.getMeasurementSchema().getType(),
- measurementPath.getMeasurementSchema().getEncodingType(),
- measurementPath.getMeasurementSchema().getCompressor(),
+ (MeasurementSchema) measurementPath.getMeasurementSchema(),
entry.getValue().left,
- entry.getValue().right,
- deadbandInfo.left,
- deadbandInfo.right));
+ entry.getValue().right));
}
- // todo Page query, record offset
- return new Pair<>(res, 1);
+
+ return res;
}
@SuppressWarnings("unchecked")
diff --git
a/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/TagSchemaRegion.java
b/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/TagSchemaRegion.java
index 89cba91f27..9e7d948988 100644
---
a/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/TagSchemaRegion.java
+++
b/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/TagSchemaRegion.java
@@ -478,8 +478,7 @@ public class TagSchemaRegion implements ISchemaRegion {
}
@Override
- public Pair<List<ShowDevicesResult>, Integer>
getMatchedDevices(IShowDevicesPlan plan)
- throws MetadataException {
+ public List<ShowDevicesResult> getMatchedDevices(IShowDevicesPlan plan)
throws MetadataException {
throw new UnsupportedOperationException("getMatchedDevices");
}
@@ -534,10 +533,9 @@ public class TagSchemaRegion implements ISchemaRegion {
}
@Override
- public Pair<List<ShowTimeSeriesResult>, Integer>
showTimeseries(IShowTimeSeriesPlan plan)
+ public List<ShowTimeSeriesResult> showTimeseries(IShowTimeSeriesPlan plan)
throws MetadataException {
- List<ShowTimeSeriesResult> ShowTimeSeriesResults = new ArrayList<>();
- Pair<List<ShowTimeSeriesResult>, Integer> result = new
Pair<>(ShowTimeSeriesResults, 0);
+ List<ShowTimeSeriesResult> showTimeSeriesResults = new ArrayList<>();
String path = plan.getPath().getFullPath();
// point query
if (!path.endsWith(TAIL)) {
@@ -547,19 +545,19 @@ public class TagSchemaRegion implements ISchemaRegion {
Map<String, SchemaEntry> measurementMap =
deviceEntry.getMeasurementMap();
for (String m : measurementMap.keySet()) {
SchemaEntry schemaEntry = measurementMap.get(m);
- ShowTimeSeriesResults.add(
+ showTimeSeriesResults.add(
ShowTimeSeriesResultUtils.generateShowTimeSeriesResult(
storageGroupFullPath, path, m, schemaEntry));
}
}
- return result;
+ return showTimeSeriesResults;
}
// batch query
List<IDeviceID> deviceIDs = getDeviceIdFromInvertedIndex(plan.getPath());
for (IDeviceID deviceID : deviceIDs) {
- getTimeSeriesResultOfDeviceFromIDTable(ShowTimeSeriesResults, deviceID);
+ getTimeSeriesResultOfDeviceFromIDTable(showTimeSeriesResults, deviceID);
}
- return result;
+ return showTimeSeriesResults;
}
private void getTimeSeriesResultOfDeviceFromIDTable(
diff --git
a/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/utils/ShowTimeSeriesResultUtils.java
b/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/utils/ShowTimeSeriesResultUtils.java
index fd759bbf36..d0dfab8571 100644
---
a/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/utils/ShowTimeSeriesResultUtils.java
+++
b/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/utils/ShowTimeSeriesResultUtils.java
@@ -18,8 +18,11 @@
*/
package org.apache.iotdb.db.metadata.tagSchemaRegion.utils;
+import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.db.metadata.idtable.entry.SchemaEntry;
import
org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowTimeSeriesResult;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import java.util.HashMap;
@@ -40,14 +43,13 @@ public class ShowTimeSeriesResultUtils {
return new ShowTimeSeriesResult(
devicePath + "." + measurement,
null,
- sgName,
- schemaEntry.getTSDataType(),
- schemaEntry.getTSEncoding(),
- schemaEntry.getCompressionType(),
+ new MeasurementSchema(
+ measurement,
+ schemaEntry.getTSDataType(),
+ schemaEntry.getTSEncoding(),
+ schemaEntry.getCompressionType()),
new HashMap<>(),
- new HashMap<>(),
- null,
- null);
+ new HashMap<>());
}
/**
@@ -60,16 +62,19 @@ public class ShowTimeSeriesResultUtils {
*/
public static ShowTimeSeriesResult generateShowTimeSeriesResult(
String sgName, String timeSeriesPath, SchemaEntry schemaEntry) {
- return new ShowTimeSeriesResult(
- timeSeriesPath,
- null,
- sgName,
- schemaEntry.getTSDataType(),
- schemaEntry.getTSEncoding(),
- schemaEntry.getCompressionType(),
- new HashMap<>(),
- new HashMap<>(),
- null,
- null);
+ try {
+ return new ShowTimeSeriesResult(
+ timeSeriesPath,
+ null,
+ new MeasurementSchema(
+ new PartialPath(timeSeriesPath).getMeasurement(),
+ schemaEntry.getTSDataType(),
+ schemaEntry.getTSEncoding(),
+ schemaEntry.getCompressionType()),
+ new HashMap<>(),
+ new HashMap<>());
+ } catch (IllegalPathException e) {
+ throw new RuntimeException(e);
+ }
}
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/IMTreeBelowSG.java
b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/IMTreeBelowSG.java
index b81ffecd3a..c97a42d0b6 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/IMTreeBelowSG.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/IMTreeBelowSG.java
@@ -25,7 +25,6 @@ import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.db.metadata.mnode.IMNode;
import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
import org.apache.iotdb.db.metadata.plan.schemaregion.read.IShowDevicesPlan;
-import org.apache.iotdb.db.metadata.plan.schemaregion.read.IShowTimeSeriesPlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowDevicesResult;
import org.apache.iotdb.db.metadata.template.Template;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
@@ -138,7 +137,7 @@ public interface IMTreeBelowSG {
Set<PartialPath> getDevices(PartialPath pathPattern, boolean isPrefixMatch)
throws MetadataException;
- Pair<List<ShowDevicesResult>, Integer> getDevices(IShowDevicesPlan plan)
throws MetadataException;
+ List<ShowDevicesResult> getDevices(IShowDevicesPlan plan) throws
MetadataException;
/**
* Get all measurement paths matching the given path pattern. If using
prefix match, the path
@@ -180,15 +179,6 @@ public interface IMTreeBelowSG {
PartialPath pathPattern, Map<Integer, Template> templateMap, boolean
withTags)
throws MetadataException;
- /**
- * Get all measurement schema matching the given path pattern
- *
- * <p>result: [name, alias, database, dataType, encoding, compression,
offset] and the current
- * offset
- */
- Pair<List<Pair<PartialPath, String[]>>, Integer>
getAllMeasurementSchema(IShowTimeSeriesPlan plan)
- throws MetadataException;
-
/**
* Get child node path in the next level of the given path pattern.
*
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java
b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java
index 960f110232..beddb20fa8 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java
@@ -52,14 +52,13 @@ import
org.apache.iotdb.db.metadata.mtree.traverser.counter.MeasurementGroupByLe
import org.apache.iotdb.db.metadata.plan.schemaregion.read.IShowDevicesPlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.read.IShowTimeSeriesPlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowDevicesResult;
+import
org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowTimeSeriesResult;
import org.apache.iotdb.db.metadata.template.Template;
import org.apache.iotdb.db.metadata.utils.MetaFormatUtils;
-import org.apache.iotdb.db.metadata.utils.MetaUtils;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
import org.apache.iotdb.tsfile.utils.Pair;
-import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import java.io.File;
@@ -681,8 +680,7 @@ public class MTreeBelowSGCachedImpl implements
IMTreeBelowSG {
}
@Override
- public Pair<List<ShowDevicesResult>, Integer> getDevices(IShowDevicesPlan
plan)
- throws MetadataException {
+ public List<ShowDevicesResult> getDevices(IShowDevicesPlan plan) throws
MetadataException {
List<ShowDevicesResult> res = new ArrayList<>();
EntityCollector<List<ShowDevicesResult>> collector =
new EntityCollector<List<ShowDevicesResult>>(
@@ -691,11 +689,7 @@ public class MTreeBelowSGCachedImpl implements
IMTreeBelowSG {
protected void collectEntity(IEntityMNode node) {
PartialPath device = getCurrentPartialPath(node);
if (plan.hasSgCol()) {
- res.add(
- new ShowDevicesResult(
- device.getFullPath(),
- node.isAligned(),
- getStorageGroupNodeInTraversePath(node).getFullPath()));
+ res.add(new ShowDevicesResult(device.getFullPath(),
node.isAligned()));
} else {
res.add(new ShowDevicesResult(device.getFullPath(),
node.isAligned()));
}
@@ -704,7 +698,7 @@ public class MTreeBelowSGCachedImpl implements
IMTreeBelowSG {
collector.setPrefixMatch(plan.isPrefixMatch());
collector.traverse();
- return new Pair<>(res, collector.getCurOffset() + 1);
+ return res;
}
// endregion
@@ -760,38 +754,27 @@ public class MTreeBelowSGCachedImpl implements
IMTreeBelowSG {
return new Pair<>(result, offset);
}
- /**
- * Get all measurement schema matching the given path pattern
- *
- * <p>result: [name, alias, database, dataType, encoding, compression,
offset] and the current
- * offset
- */
- @Override
- public Pair<List<Pair<PartialPath, String[]>>, Integer>
getAllMeasurementSchema(
- IShowTimeSeriesPlan plan) throws MetadataException {
-
+ public List<ShowTimeSeriesResult> getAllMeasurementSchema(
+ IShowTimeSeriesPlan plan,
+ Function<Long, Pair<Map<String, String>, Map<String, String>>>
tagAndAttributeProvider)
+ throws MetadataException {
int limit = plan.getLimit();
int offset = plan.getOffset();
- MeasurementCollector<List<Pair<PartialPath, String[]>>> collector =
- new MeasurementCollector<List<Pair<PartialPath, String[]>>>(
+ MeasurementCollector<List<ShowTimeSeriesResult>> collector =
+ new MeasurementCollector<List<ShowTimeSeriesResult>>(
storageGroupMNode, plan.getPath(), store, limit, offset) {
@Override
protected void collectMeasurement(IMeasurementMNode node) {
- IMeasurementSchema measurementSchema = node.getSchema();
- Pair<String, String> deadbandInfo =
- MetaUtils.parseDeadbandInfo(measurementSchema.getProps());
- String[] tsRow = new String[8];
- tsRow[0] = node.getAlias();
- tsRow[1] = getStorageGroupNodeInTraversePath(node).getFullPath();
- tsRow[2] = measurementSchema.getType().toString();
- tsRow[3] = measurementSchema.getEncodingType().toString();
- tsRow[4] = measurementSchema.getCompressor().toString();
- tsRow[5] = String.valueOf(node.getOffset());
- tsRow[6] = deadbandInfo.left;
- tsRow[7] = deadbandInfo.right;
- Pair<PartialPath, String[]> temp = new
Pair<>(getCurrentPartialPath(node), tsRow);
- resultSet.add(temp);
+ Pair<Map<String, String>, Map<String, String>> tagAndAttribute =
+ tagAndAttributeProvider.apply(node.getOffset());
+ resultSet.add(
+ new ShowTimeSeriesResult(
+ getCurrentPartialPath(node).getFullPath(),
+ node.getAlias(),
+ (MeasurementSchema) node.getSchema(),
+ tagAndAttribute.left,
+ tagAndAttribute.right));
}
};
collector.setPrefixMatch(plan.isPrefixMatch());
@@ -799,9 +782,7 @@ public class MTreeBelowSGCachedImpl implements
IMTreeBelowSG {
collector.setResultSet(new LinkedList<>());
collector.traverse();
- List<Pair<PartialPath, String[]>> result = collector.getResult();
-
- return new Pair<>(result, collector.getCurOffset() + 1);
+ return collector.getResult();
}
// endregion
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGMemoryImpl.java
b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGMemoryImpl.java
index 2bd6ecc68f..4105cfc826 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGMemoryImpl.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGMemoryImpl.java
@@ -52,14 +52,13 @@ import
org.apache.iotdb.db.metadata.mtree.traverser.counter.MeasurementGroupByLe
import org.apache.iotdb.db.metadata.plan.schemaregion.read.IShowDevicesPlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.read.IShowTimeSeriesPlan;
import org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowDevicesResult;
+import
org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowTimeSeriesResult;
import org.apache.iotdb.db.metadata.template.Template;
import org.apache.iotdb.db.metadata.utils.MetaFormatUtils;
-import org.apache.iotdb.db.metadata.utils.MetaUtils;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
import org.apache.iotdb.tsfile.utils.Pair;
-import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import java.io.File;
@@ -599,8 +598,7 @@ public class MTreeBelowSGMemoryImpl implements
IMTreeBelowSG {
}
@Override
- public Pair<List<ShowDevicesResult>, Integer> getDevices(IShowDevicesPlan
plan)
- throws MetadataException {
+ public List<ShowDevicesResult> getDevices(IShowDevicesPlan plan) throws
MetadataException {
List<ShowDevicesResult> res = new ArrayList<>();
EntityCollector<List<ShowDevicesResult>> collector =
new EntityCollector<List<ShowDevicesResult>>(
@@ -609,11 +607,7 @@ public class MTreeBelowSGMemoryImpl implements
IMTreeBelowSG {
protected void collectEntity(IEntityMNode node) {
PartialPath device = getCurrentPartialPath(node);
if (plan.hasSgCol()) {
- res.add(
- new ShowDevicesResult(
- device.getFullPath(),
- node.isAligned(),
- getStorageGroupNodeInTraversePath(node).getFullPath()));
+ res.add(new ShowDevicesResult(device.getFullPath(),
node.isAligned()));
} else {
res.add(new ShowDevicesResult(device.getFullPath(),
node.isAligned()));
}
@@ -622,7 +616,7 @@ public class MTreeBelowSGMemoryImpl implements
IMTreeBelowSG {
collector.setPrefixMatch(plan.isPrefixMatch());
collector.traverse();
- return new Pair<>(res, collector.getCurOffset() + 1);
+ return res;
}
// endregion
@@ -704,37 +698,27 @@ public class MTreeBelowSGMemoryImpl implements
IMTreeBelowSG {
return result;
}
- /**
- * Get all measurement schema matching the given path pattern
- *
- * <p>result: [name, alias, database, dataType, encoding, compression,
offset] and the current
- * offset
- */
- @Override
- public Pair<List<Pair<PartialPath, String[]>>, Integer>
getAllMeasurementSchema(
- IShowTimeSeriesPlan plan) throws MetadataException {
+ public List<ShowTimeSeriesResult> getAllMeasurementSchema(
+ IShowTimeSeriesPlan plan,
+ Function<Long, Pair<Map<String, String>, Map<String, String>>>
tagAndAttributeProvider)
+ throws MetadataException {
int limit = plan.getLimit();
int offset = plan.getOffset();
- MeasurementCollector<List<Pair<PartialPath, String[]>>> collector =
- new MeasurementCollector<List<Pair<PartialPath, String[]>>>(
+ MeasurementCollector<List<ShowTimeSeriesResult>> collector =
+ new MeasurementCollector<List<ShowTimeSeriesResult>>(
storageGroupMNode, plan.getPath(), store, limit, offset) {
@Override
protected void collectMeasurement(IMeasurementMNode node) {
- IMeasurementSchema measurementSchema = node.getSchema();
- Pair<String, String> deadbandInfo =
- MetaUtils.parseDeadbandInfo(measurementSchema.getProps());
- String[] tsRow = new String[8];
- tsRow[0] = node.getAlias();
- tsRow[1] = getStorageGroupNodeInTraversePath(node).getFullPath();
- tsRow[2] = measurementSchema.getType().toString();
- tsRow[3] = measurementSchema.getEncodingType().toString();
- tsRow[4] = measurementSchema.getCompressor().toString();
- tsRow[5] = String.valueOf(node.getOffset());
- tsRow[6] = deadbandInfo.left;
- tsRow[7] = deadbandInfo.right;
- Pair<PartialPath, String[]> temp = new
Pair<>(getCurrentPartialPath(node), tsRow);
- resultSet.add(temp);
+ Pair<Map<String, String>, Map<String, String>> tagAndAttribute =
+ tagAndAttributeProvider.apply(node.getOffset());
+ resultSet.add(
+ new ShowTimeSeriesResult(
+ getCurrentPartialPath(node).getFullPath(),
+ node.getAlias(),
+ (MeasurementSchema) node.getSchema(),
+ tagAndAttribute.left,
+ tagAndAttribute.right));
}
};
collector.setPrefixMatch(plan.isPrefixMatch());
@@ -742,9 +726,7 @@ public class MTreeBelowSGMemoryImpl implements
IMTreeBelowSG {
collector.setResultSet(new LinkedList<>());
collector.traverse();
- List<Pair<PartialPath, String[]>> result = collector.getResult();
-
- return new Pair<>(result, collector.getCurOffset() + 1);
+ return collector.getResult();
}
// endregion
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowDevicesResult.java
b/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowDevicesResult.java
index 9755bfee2f..5a6a4b4dd8 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowDevicesResult.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowDevicesResult.java
@@ -18,20 +18,13 @@
*/
package org.apache.iotdb.db.metadata.plan.schemaregion.result;
+import org.apache.iotdb.db.metadata.query.info.IDeviceSchemaInfo;
+
import java.util.Objects;
-public class ShowDevicesResult extends ShowSchemaResult {
+public class ShowDevicesResult extends ShowSchemaResult implements
IDeviceSchemaInfo {
private boolean isAligned;
- public ShowDevicesResult() {
- super();
- }
-
- public ShowDevicesResult(String name, boolean isAligned, String sgName) {
- super(name, sgName);
- this.isAligned = isAligned;
- }
-
public ShowDevicesResult(String name, boolean isAligned) {
super(name);
this.isAligned = isAligned;
@@ -49,8 +42,6 @@ public class ShowDevicesResult extends ShowSchemaResult {
+ '\''
+ ", isAligned = "
+ isAligned
- + ", sgName='"
- + database
+ '\''
+ "}";
}
@@ -64,13 +55,11 @@ public class ShowDevicesResult extends ShowSchemaResult {
return false;
}
ShowDevicesResult result = (ShowDevicesResult) o;
- return Objects.equals(path, result.path)
- && isAligned == result.isAligned
- && Objects.equals(database, result.database);
+ return Objects.equals(path, result.path) && isAligned == result.isAligned;
}
@Override
public int hashCode() {
- return Objects.hash(path, isAligned, database);
+ return Objects.hash(path, isAligned);
}
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
b/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
index 6731ea7e13..18955ec0c5 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
@@ -18,15 +18,13 @@
*/
package org.apache.iotdb.db.metadata.plan.schemaregion.result;
-public abstract class ShowSchemaResult implements Comparable<ShowSchemaResult>
{
+import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.db.metadata.query.info.ISchemaInfo;
- protected String path;
- protected String database;
+public abstract class ShowSchemaResult implements
Comparable<ShowSchemaResult>, ISchemaInfo {
- public ShowSchemaResult(String path, String database) {
- this.path = path;
- this.database = database;
- }
+ protected String path;
public ShowSchemaResult(String path) {
this.path = path;
@@ -38,8 +36,18 @@ public abstract class ShowSchemaResult implements
Comparable<ShowSchemaResult> {
return path;
}
- public String getDatabase() {
- return database;
+ @Override
+ public String getFullPath() {
+ return path;
+ }
+
+ @Override
+ public PartialPath getPartialPath() {
+ try {
+ return new PartialPath(path);
+ } catch (IllegalPathException e) {
+ throw new RuntimeException(e);
+ }
}
@Override
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowTimeSeriesResult.java
b/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowTimeSeriesResult.java
index bff1f5290e..5d0a08b9b9 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowTimeSeriesResult.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowTimeSeriesResult.java
@@ -18,45 +18,36 @@
*/
package org.apache.iotdb.db.metadata.plan.schemaregion.result;
+import org.apache.iotdb.db.metadata.query.info.ITimeSeriesSchemaInfo;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import java.util.Map;
import java.util.Objects;
-public class ShowTimeSeriesResult extends ShowSchemaResult {
+public class ShowTimeSeriesResult extends ShowSchemaResult implements
ITimeSeriesSchemaInfo {
private String alias;
- private TSDataType dataType;
- private TSEncoding encoding;
- private CompressionType compressor;
+
+ private MeasurementSchema measurementSchema;
+
private Map<String, String> tags;
private Map<String, String> attributes;
- private String deadband;
- private String deadbandParameters;
-
public ShowTimeSeriesResult(
String name,
String alias,
- String sgName,
- TSDataType dataType,
- TSEncoding encoding,
- CompressionType compressor,
+ MeasurementSchema measurementSchema,
Map<String, String> tags,
- Map<String, String> attributes,
- String deadband,
- String deadbandParameters) {
- super(name, sgName);
+ Map<String, String> attributes) {
+ super(name);
this.alias = alias;
- this.dataType = dataType;
- this.encoding = encoding;
- this.compressor = compressor;
+ this.measurementSchema = measurementSchema;
this.tags = tags;
this.attributes = attributes;
- this.deadband = deadband;
- this.deadbandParameters = deadbandParameters;
}
public ShowTimeSeriesResult() {
@@ -67,16 +58,26 @@ public class ShowTimeSeriesResult extends ShowSchemaResult {
return alias;
}
+ @Override
+ public MeasurementSchema getSchema() {
+ return measurementSchema;
+ }
+
+ @Override
+ public Pair<Map<String, String>, Map<String, String>> getTagAndAttribute() {
+ return new Pair<>(tags, attributes);
+ }
+
public TSDataType getDataType() {
- return dataType;
+ return measurementSchema.getType();
}
public TSEncoding getEncoding() {
- return encoding;
+ return measurementSchema.getEncodingType();
}
public CompressionType getCompressor() {
- return compressor;
+ return measurementSchema.getCompressor();
}
public Map<String, String> getTag() {
@@ -87,14 +88,6 @@ public class ShowTimeSeriesResult extends ShowSchemaResult {
return attributes;
}
- public String getDeadband() {
- return deadband;
- }
-
- public String getDeadbandParameters() {
- return deadbandParameters;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
b/server/src/main/java/org/apache/iotdb/db/metadata/query/info/IDeviceSchemaInfo.java
similarity index 52%
copy from
server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
copy to
server/src/main/java/org/apache/iotdb/db/metadata/query/info/IDeviceSchemaInfo.java
index 6731ea7e13..92f4b6bd99 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/query/info/IDeviceSchemaInfo.java
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -16,34 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.metadata.plan.schemaregion.result;
-public abstract class ShowSchemaResult implements Comparable<ShowSchemaResult>
{
+package org.apache.iotdb.db.metadata.query.info;
- protected String path;
- protected String database;
+public interface IDeviceSchemaInfo extends ISchemaInfo {
- public ShowSchemaResult(String path, String database) {
- this.path = path;
- this.database = database;
- }
-
- public ShowSchemaResult(String path) {
- this.path = path;
- }
-
- public ShowSchemaResult() {}
-
- public String getPath() {
- return path;
- }
-
- public String getDatabase() {
- return database;
- }
-
- @Override
- public int compareTo(ShowSchemaResult o) {
- return this.getPath().compareTo(o.getPath());
- }
+ boolean isAligned();
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
b/server/src/main/java/org/apache/iotdb/db/metadata/query/info/ISchemaInfo.java
similarity index 52%
copy from
server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
copy to
server/src/main/java/org/apache/iotdb/db/metadata/query/info/ISchemaInfo.java
index 6731ea7e13..d57635d7f9 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/query/info/ISchemaInfo.java
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -16,34 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.metadata.plan.schemaregion.result;
-public abstract class ShowSchemaResult implements Comparable<ShowSchemaResult>
{
+package org.apache.iotdb.db.metadata.query.info;
- protected String path;
- protected String database;
+import org.apache.iotdb.commons.path.PartialPath;
- public ShowSchemaResult(String path, String database) {
- this.path = path;
- this.database = database;
- }
+public interface ISchemaInfo {
- public ShowSchemaResult(String path) {
- this.path = path;
- }
+ String getFullPath();
- public ShowSchemaResult() {}
-
- public String getPath() {
- return path;
- }
-
- public String getDatabase() {
- return database;
- }
-
- @Override
- public int compareTo(ShowSchemaResult o) {
- return this.getPath().compareTo(o.getPath());
- }
+ PartialPath getPartialPath();
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
b/server/src/main/java/org/apache/iotdb/db/metadata/query/info/ITimeSeriesSchemaInfo.java
similarity index 56%
copy from
server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
copy to
server/src/main/java/org/apache/iotdb/db/metadata/query/info/ITimeSeriesSchemaInfo.java
index 6731ea7e13..9d68de4f64 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/query/info/ITimeSeriesSchemaInfo.java
@@ -16,34 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.metadata.plan.schemaregion.result;
-public abstract class ShowSchemaResult implements Comparable<ShowSchemaResult>
{
+package org.apache.iotdb.db.metadata.query.info;
- protected String path;
- protected String database;
+import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
- public ShowSchemaResult(String path, String database) {
- this.path = path;
- this.database = database;
- }
+import java.util.Map;
- public ShowSchemaResult(String path) {
- this.path = path;
- }
+public interface ITimeSeriesSchemaInfo extends ISchemaInfo {
- public ShowSchemaResult() {}
+ String getAlias();
- public String getPath() {
- return path;
- }
+ MeasurementSchema getSchema();
- public String getDatabase() {
- return database;
- }
-
- @Override
- public int compareTo(ShowSchemaResult o) {
- return this.getPath().compareTo(o.getPath());
- }
+ Pair<Map<String, String>, Map<String, String>> getTagAndAttribute();
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
b/server/src/main/java/org/apache/iotdb/db/metadata/query/reader/ISchemaReader.java
similarity index 52%
copy from
server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
copy to
server/src/main/java/org/apache/iotdb/db/metadata/query/reader/ISchemaReader.java
index 6731ea7e13..21e00b102a 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/plan/schemaregion/result/ShowSchemaResult.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/query/reader/ISchemaReader.java
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -16,34 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.metadata.plan.schemaregion.result;
-public abstract class ShowSchemaResult implements Comparable<ShowSchemaResult>
{
+package org.apache.iotdb.db.metadata.query.reader;
- protected String path;
- protected String database;
+import org.apache.iotdb.db.metadata.query.info.ISchemaInfo;
- public ShowSchemaResult(String path, String database) {
- this.path = path;
- this.database = database;
- }
+import java.util.Iterator;
- public ShowSchemaResult(String path) {
- this.path = path;
- }
-
- public ShowSchemaResult() {}
-
- public String getPath() {
- return path;
- }
-
- public String getDatabase() {
- return database;
- }
-
- @Override
- public int compareTo(ShowSchemaResult o) {
- return this.getPath().compareTo(o.getPath());
- }
-}
+public interface ISchemaReader<T extends ISchemaInfo> extends Iterator<T>,
AutoCloseable {}
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/ISchemaRegion.java
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/ISchemaRegion.java
index 1a76438657..e607e2aa2f 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/ISchemaRegion.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/ISchemaRegion.java
@@ -35,11 +35,15 @@ import
org.apache.iotdb.db.metadata.plan.schemaregion.write.ICreateTimeSeriesPla
import
org.apache.iotdb.db.metadata.plan.schemaregion.write.IDeactivateTemplatePlan;
import
org.apache.iotdb.db.metadata.plan.schemaregion.write.IPreDeactivateTemplatePlan;
import
org.apache.iotdb.db.metadata.plan.schemaregion.write.IRollbackPreDeactivateTemplatePlan;
+import org.apache.iotdb.db.metadata.query.info.IDeviceSchemaInfo;
+import org.apache.iotdb.db.metadata.query.info.ITimeSeriesSchemaInfo;
+import org.apache.iotdb.db.metadata.query.reader.ISchemaReader;
import org.apache.iotdb.db.metadata.template.Template;
import org.apache.iotdb.tsfile.utils.Pair;
import java.io.File;
import java.io.IOException;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -263,10 +267,9 @@ public interface ISchemaRegion {
* Get all device paths and corresponding database paths as
ShowDevicesResult.
*
* @param plan ShowDevicesPlan which contains the path pattern and
restriction params.
- * @return ShowDevicesResult and the current offset of this region after
traverse.
+ * @return ShowDevicesResult
*/
- Pair<List<ShowDevicesResult>, Integer> getMatchedDevices(IShowDevicesPlan
plan)
- throws MetadataException;
+ List<ShowDevicesResult> getMatchedDevices(IShowDevicesPlan plan) throws
MetadataException;
// endregion
// region Interfaces for timeseries, measurement and schema info Query
@@ -306,8 +309,7 @@ public interface ISchemaRegion {
* @param plan
* @throws MetadataException
*/
- Pair<List<ShowTimeSeriesResult>, Integer> showTimeseries(IShowTimeSeriesPlan
plan)
- throws MetadataException;
+ List<ShowTimeSeriesResult> showTimeseries(IShowTimeSeriesPlan plan) throws
MetadataException;
// endregion
// endregion
@@ -401,4 +403,48 @@ public interface ISchemaRegion {
throws MetadataException;
// endregion
+
+ // region Interfaces for SchemaReader
+
+ default ISchemaReader<IDeviceSchemaInfo> getDeviceReader(IShowDevicesPlan
showDevicesPlan)
+ throws MetadataException {
+ List<ShowDevicesResult> showDevicesResultList =
getMatchedDevices(showDevicesPlan);
+ Iterator<ShowDevicesResult> iterator = showDevicesResultList.iterator();
+ return new ISchemaReader<IDeviceSchemaInfo>() {
+ @Override
+ public void close() throws Exception {}
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public IDeviceSchemaInfo next() {
+ return iterator.next();
+ }
+ };
+ }
+
+ default ISchemaReader<ITimeSeriesSchemaInfo> getTimeSeriesReader(
+ IShowTimeSeriesPlan showTimeSeriesPlan) throws MetadataException {
+ List<ShowTimeSeriesResult> showTimeSeriesResultList =
showTimeseries(showTimeSeriesPlan);
+ Iterator<ShowTimeSeriesResult> iterator =
showTimeSeriesResultList.iterator();
+ return new ISchemaReader<ITimeSeriesSchemaInfo>() {
+ @Override
+ public void close() throws Exception {}
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public ITimeSeriesSchemaInfo next() {
+ return iterator.next();
+ }
+ };
+ }
+
+ // endregion
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
index 7053d732e3..2a265c3aab 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
@@ -69,14 +69,12 @@ import org.apache.iotdb.db.metadata.rescon.MemoryStatistics;
import org.apache.iotdb.db.metadata.rescon.SchemaStatisticsManager;
import org.apache.iotdb.db.metadata.tag.TagManager;
import org.apache.iotdb.db.metadata.template.Template;
-import org.apache.iotdb.db.metadata.utils.MetaUtils;
import org.apache.iotdb.db.utils.SchemaUtils;
import org.apache.iotdb.external.api.ISeriesNumerMonitor;
-import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
import org.apache.iotdb.tsfile.utils.Pair;
-import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -987,8 +985,7 @@ public class SchemaRegionMemoryImpl implements
ISchemaRegion {
* @return ShowDevicesResult and the current offset of this region after
traverse.
*/
@Override
- public Pair<List<ShowDevicesResult>, Integer>
getMatchedDevices(IShowDevicesPlan plan)
- throws MetadataException {
+ public List<ShowDevicesResult> getMatchedDevices(IShowDevicesPlan plan)
throws MetadataException {
return mtree.getDevices(plan);
}
// endregion
@@ -1032,7 +1029,7 @@ public class SchemaRegionMemoryImpl implements
ISchemaRegion {
}
@Override
- public Pair<List<ShowTimeSeriesResult>, Integer>
showTimeseries(IShowTimeSeriesPlan plan)
+ public List<ShowTimeSeriesResult> showTimeseries(IShowTimeSeriesPlan plan)
throws MetadataException {
// show timeseries with index
if (plan.getKey() != null && plan.getValue() != null) {
@@ -1043,8 +1040,8 @@ public class SchemaRegionMemoryImpl implements
ISchemaRegion {
}
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity
warning
- private Pair<List<ShowTimeSeriesResult>, Integer> showTimeseriesWithIndex(
- IShowTimeSeriesPlan plan) throws MetadataException {
+ private List<ShowTimeSeriesResult>
showTimeseriesWithIndex(IShowTimeSeriesPlan plan)
+ throws MetadataException {
List<IMeasurementMNode> allMatchedNodes =
tagManager.getMatchedTimeseriesInIndex(plan);
@@ -1068,21 +1065,13 @@ public class SchemaRegionMemoryImpl implements
ISchemaRegion {
try {
Pair<Map<String, String>, Map<String, String>> tagAndAttributePair =
tagManager.readTagFile(leaf.getOffset());
- IMeasurementSchema measurementSchema = leaf.getSchema();
- Pair<String, String> deadbandInfo =
- MetaUtils.parseDeadbandInfo(measurementSchema.getProps());
res.add(
new ShowTimeSeriesResult(
leaf.getFullPath(),
leaf.getAlias(),
- storageGroupFullPath,
- measurementSchema.getType(),
- measurementSchema.getEncodingType(),
- measurementSchema.getCompressor(),
+ (MeasurementSchema) leaf.getSchema(),
tagAndAttributePair.left,
- tagAndAttributePair.right,
- deadbandInfo.left,
- deadbandInfo.right));
+ tagAndAttributePair.right));
if (limit != 0) {
count++;
}
@@ -1093,7 +1082,7 @@ public class SchemaRegionMemoryImpl implements
ISchemaRegion {
}
}
- return new Pair<>(res, curOffset + 1);
+ return res;
}
/**
@@ -1101,37 +1090,18 @@ public class SchemaRegionMemoryImpl implements
ISchemaRegion {
*
* @param plan show time series query plan
*/
- private Pair<List<ShowTimeSeriesResult>, Integer> showTimeseriesWithoutIndex(
- IShowTimeSeriesPlan plan) throws MetadataException {
- Pair<List<Pair<PartialPath, String[]>>, Integer> ans =
mtree.getAllMeasurementSchema(plan);
- List<ShowTimeSeriesResult> res = new LinkedList<>();
- for (Pair<PartialPath, String[]> ansString : ans.left) {
- long tagFileOffset = Long.parseLong(ansString.right[5]);
- try {
- Pair<Map<String, String>, Map<String, String>> tagAndAttributePair =
- new Pair<>(Collections.emptyMap(), Collections.emptyMap());
- if (tagFileOffset >= 0) {
- tagAndAttributePair = tagManager.readTagFile(tagFileOffset);
- }
- res.add(
- new ShowTimeSeriesResult(
- ansString.left.getFullPath(),
- ansString.right[0],
- ansString.right[1],
- TSDataType.valueOf(ansString.right[2]),
- TSEncoding.valueOf(ansString.right[3]),
- CompressionType.valueOf(ansString.right[4]),
- tagAndAttributePair.left,
- tagAndAttributePair.right,
- ansString.right[6],
- ansString.right[7]));
- } catch (IOException e) {
- throw new MetadataException(
- "Something went wrong while deserialize tag info of " +
ansString.left.getFullPath(),
- e);
- }
- }
- return new Pair<>(res, ans.right);
+ private List<ShowTimeSeriesResult>
showTimeseriesWithoutIndex(IShowTimeSeriesPlan plan)
+ throws MetadataException {
+ return mtree.getAllMeasurementSchema(
+ plan,
+ offset -> {
+ try {
+ return tagManager.readTagFile(offset);
+ } catch (IOException e) {
+ logger.error("Failed to read tag and attribute info because {}",
e.getMessage(), e);
+ return new Pair<>(Collections.emptyMap(), Collections.emptyMap());
+ }
+ });
}
// endregion
// endregion
diff --git
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
index e8b26f737f..3167b29eea 100644
---
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
+++
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
@@ -72,6 +72,7 @@ import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
import org.apache.iotdb.tsfile.utils.Pair;
import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1044,8 +1045,7 @@ public class SchemaRegionSchemaFileImpl implements
ISchemaRegion {
* @return ShowDevicesResult and the current offset of this region after
traverse.
*/
@Override
- public Pair<List<ShowDevicesResult>, Integer>
getMatchedDevices(IShowDevicesPlan plan)
- throws MetadataException {
+ public List<ShowDevicesResult> getMatchedDevices(IShowDevicesPlan plan)
throws MetadataException {
return mtree.getDevices(plan);
}
// endregion
@@ -1089,7 +1089,7 @@ public class SchemaRegionSchemaFileImpl implements
ISchemaRegion {
}
@Override
- public Pair<List<ShowTimeSeriesResult>, Integer>
showTimeseries(IShowTimeSeriesPlan plan)
+ public List<ShowTimeSeriesResult> showTimeseries(IShowTimeSeriesPlan plan)
throws MetadataException {
// show timeseries with index
if (plan.getKey() != null && plan.getValue() != null) {
@@ -1100,8 +1100,8 @@ public class SchemaRegionSchemaFileImpl implements
ISchemaRegion {
}
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity
warning
- private Pair<List<ShowTimeSeriesResult>, Integer> showTimeseriesWithIndex(
- IShowTimeSeriesPlan plan) throws MetadataException {
+ private List<ShowTimeSeriesResult>
showTimeseriesWithIndex(IShowTimeSeriesPlan plan)
+ throws MetadataException {
List<IMeasurementMNode> allMatchedNodes =
tagManager.getMatchedTimeseriesInIndex(plan);
@@ -1132,14 +1132,9 @@ public class SchemaRegionSchemaFileImpl implements
ISchemaRegion {
new ShowTimeSeriesResult(
leaf.getFullPath(),
leaf.getAlias(),
- storageGroupFullPath,
- measurementSchema.getType(),
- measurementSchema.getEncodingType(),
- measurementSchema.getCompressor(),
+ (MeasurementSchema) leaf.getSchema(),
tagAndAttributePair.left,
- tagAndAttributePair.right,
- deadbandInfo.left,
- deadbandInfo.right));
+ tagAndAttributePair.right));
if (limit != 0) {
count++;
}
@@ -1150,7 +1145,7 @@ public class SchemaRegionSchemaFileImpl implements
ISchemaRegion {
}
}
- return new Pair<>(res, curOffset + 1);
+ return res;
}
/**
@@ -1158,37 +1153,18 @@ public class SchemaRegionSchemaFileImpl implements
ISchemaRegion {
*
* @param plan show time series query plan
*/
- private Pair<List<ShowTimeSeriesResult>, Integer> showTimeseriesWithoutIndex(
- IShowTimeSeriesPlan plan) throws MetadataException {
- Pair<List<Pair<PartialPath, String[]>>, Integer> ans =
mtree.getAllMeasurementSchema(plan);
- List<ShowTimeSeriesResult> res = new LinkedList<>();
- for (Pair<PartialPath, String[]> ansString : ans.left) {
- long tagFileOffset = Long.parseLong(ansString.right[5]);
- try {
- Pair<Map<String, String>, Map<String, String>> tagAndAttributePair =
- new Pair<>(Collections.emptyMap(), Collections.emptyMap());
- if (tagFileOffset >= 0) {
- tagAndAttributePair = tagManager.readTagFile(tagFileOffset);
- }
- res.add(
- new ShowTimeSeriesResult(
- ansString.left.getFullPath(),
- ansString.right[0],
- ansString.right[1],
- TSDataType.valueOf(ansString.right[2]),
- TSEncoding.valueOf(ansString.right[3]),
- CompressionType.valueOf(ansString.right[4]),
- tagAndAttributePair.left,
- tagAndAttributePair.right,
- ansString.right[6],
- ansString.right[7]));
- } catch (IOException e) {
- throw new MetadataException(
- "Something went wrong while deserialize tag info of " +
ansString.left.getFullPath(),
- e);
- }
- }
- return new Pair<>(res, ans.right);
+ private List<ShowTimeSeriesResult>
showTimeseriesWithoutIndex(IShowTimeSeriesPlan plan)
+ throws MetadataException {
+ return mtree.getAllMeasurementSchema(
+ plan,
+ offset -> {
+ try {
+ return tagManager.readTagFile(offset);
+ } catch (IOException e) {
+ logger.error("Failed to read tag and attribute info because {}",
e.getMessage(), e);
+ return new Pair<>(Collections.emptyMap(), Collections.emptyMap());
+ }
+ });
}
// endregion
// endregion
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/DevicesSchemaScanOperator.java
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/DevicesSchemaScanOperator.java
index c89c924eb2..35ff73f36a 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/DevicesSchemaScanOperator.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/DevicesSchemaScanOperator.java
@@ -21,7 +21,7 @@ package org.apache.iotdb.db.mpp.execution.operator.schema;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.path.PartialPath;
import
org.apache.iotdb.db.metadata.plan.schemaregion.impl.read.SchemaRegionReadPlanFactory;
-import org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowDevicesResult;
+import org.apache.iotdb.db.metadata.query.info.IDeviceSchemaInfo;
import org.apache.iotdb.db.mpp.common.header.ColumnHeader;
import org.apache.iotdb.db.mpp.common.header.ColumnHeaderConstant;
import org.apache.iotdb.db.mpp.execution.driver.SchemaDriverContext;
@@ -59,25 +59,24 @@ public class DevicesSchemaScanOperator extends
SchemaQueryScanOperator {
@Override
protected List<TsBlock> createTsBlockList() {
try {
- List<ShowDevicesResult> schemaRegionResult =
+ return SchemaTsBlockUtil.transferSchemaResultToTsBlockList(
((SchemaDriverContext)
operatorContext.getInstanceContext().getDriverContext())
.getSchemaRegion()
- .getMatchedDevices(
+ .getDeviceReader(
SchemaRegionReadPlanFactory.getShowDevicesPlan(
- partialPath, limit, offset, hasSgCol, false))
- .left;
- return SchemaTsBlockUtil.transferSchemaResultToTsBlockList(
- schemaRegionResult.iterator(), outputDataTypes, this::setColumns);
+ partialPath, limit, offset, hasSgCol, false)),
+ outputDataTypes,
+ this::setColumns);
} catch (MetadataException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
- private void setColumns(ShowDevicesResult device, TsBlockBuilder builder) {
+ private void setColumns(IDeviceSchemaInfo device, TsBlockBuilder builder) {
builder.getTimeColumnBuilder().writeLong(0L);
- builder.getColumnBuilder(0).writeBinary(new Binary(device.getPath()));
+ builder.getColumnBuilder(0).writeBinary(new Binary(device.getFullPath()));
if (hasSgCol) {
- builder.getColumnBuilder(1).writeBinary(new
Binary(device.getDatabase()));
+ builder.getColumnBuilder(1).writeBinary(new Binary(getDatabase()));
builder.getColumnBuilder(2).writeBinary(new
Binary(String.valueOf(device.isAligned())));
} else {
builder.getColumnBuilder(1).writeBinary(new
Binary(String.valueOf(device.isAligned())));
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaQueryScanOperator.java
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaQueryScanOperator.java
index 77bdc7b6cd..af550d6f8a 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaQueryScanOperator.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaQueryScanOperator.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.mpp.execution.operator.schema;
import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.db.mpp.execution.driver.SchemaDriverContext;
import org.apache.iotdb.db.mpp.execution.operator.OperatorContext;
import org.apache.iotdb.db.mpp.execution.operator.source.SourceOperator;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNodeId;
@@ -42,6 +43,8 @@ public abstract class SchemaQueryScanOperator implements
SourceOperator {
protected PlanNodeId sourceId;
+ private String database;
+
protected SchemaQueryScanOperator(
PlanNodeId sourceId,
OperatorContext operatorContext,
@@ -129,4 +132,14 @@ public abstract class SchemaQueryScanOperator implements
SourceOperator {
public long calculateRetainedSizeAfterCallingNext() {
return 0L;
}
+
+ protected String getDatabase() {
+ if (database == null) {
+ database =
+ ((SchemaDriverContext)
operatorContext.getInstanceContext().getDriverContext())
+ .getSchemaRegion()
+ .getStorageGroupFullPath();
+ }
+ return database;
+ }
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/TimeSeriesSchemaScanOperator.java
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/TimeSeriesSchemaScanOperator.java
index 8ab9473e1e..95b1da402b 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/TimeSeriesSchemaScanOperator.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/schema/TimeSeriesSchemaScanOperator.java
@@ -21,8 +21,9 @@ package org.apache.iotdb.db.mpp.execution.operator.schema;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.path.PartialPath;
import
org.apache.iotdb.db.metadata.plan.schemaregion.impl.read.SchemaRegionReadPlanFactory;
-import
org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowTimeSeriesResult;
+import org.apache.iotdb.db.metadata.query.info.ITimeSeriesSchemaInfo;
import org.apache.iotdb.db.metadata.template.Template;
+import org.apache.iotdb.db.metadata.utils.MetaUtils;
import org.apache.iotdb.db.mpp.common.header.ColumnHeader;
import org.apache.iotdb.db.mpp.common.header.ColumnHeaderConstant;
import org.apache.iotdb.db.mpp.execution.driver.SchemaDriverContext;
@@ -31,6 +32,7 @@ import
org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNodeId;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.block.TsBlock;
import org.apache.iotdb.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.iotdb.tsfile.utils.Pair;
import java.util.List;
import java.util.Map;
@@ -91,32 +93,33 @@ public class TimeSeriesSchemaScanOperator extends
SchemaQueryScanOperator {
@Override
protected List<TsBlock> createTsBlockList() {
try {
- List<ShowTimeSeriesResult> schemaRegionResult =
+ return SchemaTsBlockUtil.transferSchemaResultToTsBlockList(
((SchemaDriverContext)
operatorContext.getInstanceContext().getDriverContext())
.getSchemaRegion()
- .showTimeseries(
+ .getTimeSeriesReader(
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(
- partialPath, templateMap, isContains, key, value, limit,
offset, false))
- .left;
- return SchemaTsBlockUtil.transferSchemaResultToTsBlockList(
- schemaRegionResult.iterator(), outputDataTypes, this::setColumns);
+ partialPath, templateMap, isContains, key, value, limit,
offset, false)),
+ outputDataTypes,
+ this::setColumns);
} catch (MetadataException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
- private void setColumns(ShowTimeSeriesResult series, TsBlockBuilder builder)
{
+ private void setColumns(ITimeSeriesSchemaInfo series, TsBlockBuilder
builder) {
+ Pair<Map<String, String>, Map<String, String>> tagAndAttribute =
series.getTagAndAttribute();
+ Pair<String, String> deadbandInfo =
MetaUtils.parseDeadbandInfo(series.getSchema().getProps());
builder.getTimeColumnBuilder().writeLong(0);
- builder.writeNullableText(0, series.getPath());
+ builder.writeNullableText(0, series.getFullPath());
builder.writeNullableText(1, series.getAlias());
- builder.writeNullableText(2, series.getDatabase());
- builder.writeNullableText(3, series.getDataType().toString());
- builder.writeNullableText(4, series.getEncoding().toString());
- builder.writeNullableText(5, series.getCompressor().toString());
- builder.writeNullableText(6, mapToString(series.getTag()));
- builder.writeNullableText(7, mapToString(series.getAttribute()));
- builder.writeNullableText(8, series.getDeadband());
- builder.writeNullableText(9, series.getDeadbandParameters());
+ builder.writeNullableText(2, getDatabase());
+ builder.writeNullableText(3, series.getSchema().getType().toString());
+ builder.writeNullableText(4,
series.getSchema().getEncodingType().toString());
+ builder.writeNullableText(5,
series.getSchema().getCompressor().toString());
+ builder.writeNullableText(6, mapToString(tagAndAttribute.left));
+ builder.writeNullableText(7, mapToString(tagAndAttribute.right));
+ builder.writeNullableText(8, deadbandInfo.left);
+ builder.writeNullableText(9, deadbandInfo.right);
builder.declarePosition();
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
index 3531345015..5f013f9d14 100644
---
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
@@ -27,7 +27,6 @@ import
org.apache.iotdb.db.metadata.schemaregion.ISchemaRegion;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
-import org.apache.iotdb.tsfile.utils.Pair;
import org.junit.Assert;
import org.junit.Before;
@@ -145,14 +144,14 @@ public class SchemaRegionAliasAndTagTest extends
AbstractSchemaRegionTest {
private void checkAliasAndTagsAndAttributes(
String fullPath, String alias, Map<String, String> tags, Map<String,
String> attributes) {
try {
- Pair<List<ShowTimeSeriesResult>, Integer> result =
+ List<ShowTimeSeriesResult> result =
schemaRegion.showTimeseries(
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(new
PartialPath(fullPath)));
- Assert.assertEquals(1, result.left.size());
- Assert.assertEquals(fullPath, result.left.get(0).getPath());
- Assert.assertEquals(alias, result.left.get(0).getAlias());
- Assert.assertEquals(tags, result.left.get(0).getTag());
- Assert.assertEquals(attributes, result.left.get(0).getAttribute());
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(fullPath, result.get(0).getPath());
+ Assert.assertEquals(alias, result.get(0).getAlias());
+ Assert.assertEquals(tags, result.get(0).getTag());
+ Assert.assertEquals(attributes, result.get(0).getAttribute());
} catch (Exception e) {
logger.error(e.getMessage(), e);
Assert.fail(e.getMessage());
@@ -161,12 +160,12 @@ public class SchemaRegionAliasAndTagTest extends
AbstractSchemaRegionTest {
private void checkAttributes(String fullPath, Map<String, String>
attributes) {
try {
- Pair<List<ShowTimeSeriesResult>, Integer> result =
+ List<ShowTimeSeriesResult> result =
schemaRegion.showTimeseries(
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(new
PartialPath(fullPath)));
- Assert.assertEquals(1, result.left.size());
- Assert.assertEquals(fullPath, result.left.get(0).getPath());
- Assert.assertEquals(attributes, result.left.get(0).getAttribute());
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(fullPath, result.get(0).getPath());
+ Assert.assertEquals(attributes, result.get(0).getAttribute());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
@@ -175,12 +174,12 @@ public class SchemaRegionAliasAndTagTest extends
AbstractSchemaRegionTest {
private void checkTags(String fullPath, Map<String, String> tags) {
try {
- Pair<List<ShowTimeSeriesResult>, Integer> result =
+ List<ShowTimeSeriesResult> result =
schemaRegion.showTimeseries(
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(new
PartialPath(fullPath)));
- Assert.assertEquals(1, result.left.size());
- Assert.assertEquals(fullPath, result.left.get(0).getPath());
- Assert.assertEquals(tags, result.left.get(0).getTag());
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(fullPath, result.get(0).getPath());
+ Assert.assertEquals(tags, result.get(0).getTag());
} catch (Exception e) {
logger.error(e.getMessage(), e);
Assert.fail(e.getMessage());
diff --git
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
index f14e27ad9b..d7622fdf59 100644
---
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
@@ -35,7 +35,6 @@ import
org.apache.iotdb.db.metadata.schemaregion.ISchemaRegion;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
-import org.apache.iotdb.tsfile.utils.Pair;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
@@ -617,23 +616,23 @@ public class SchemaRegionBasicTest extends
AbstractSchemaRegionTest {
"root.laptop.d2.s2"));
Assert.assertEquals(
- new Pair<>(Arrays.asList(), 0),
+ Collections.emptyList(),
schemaRegion.getMatchedDevices(
SchemaRegionReadPlanFactory.getShowDevicesPlan(new
PartialPath("root.laptop.d0"))));
Assert.assertEquals(
- new Pair<>(Arrays.asList(new ShowDevicesResult("root.laptop.d1",
false)), 0),
+ Collections.singletonList(new ShowDevicesResult("root.laptop.d1",
false)),
schemaRegion.getMatchedDevices(
SchemaRegionReadPlanFactory.getShowDevicesPlan(new
PartialPath("root.laptop.d1"))));
Assert.assertEquals(
- new Pair<>(Arrays.asList(new ShowDevicesResult("root.laptop.d2",
false)), 0),
+ Collections.singletonList(new ShowDevicesResult("root.laptop.d2",
false)),
schemaRegion.getMatchedDevices(
SchemaRegionReadPlanFactory.getShowDevicesPlan(new
PartialPath("root.laptop.d2"))));
Assert.assertEquals(
- new Pair<>(Arrays.asList(new ShowDevicesResult("root.laptop", false)),
0),
+ Collections.singletonList(new ShowDevicesResult("root.laptop", false)),
schemaRegion.getMatchedDevices(
SchemaRegionReadPlanFactory.getShowDevicesPlan(new
PartialPath("root.laptop"))));
Assert.assertEquals(
- new Pair<>(Arrays.asList(new ShowDevicesResult("root.laptop", false)),
0),
+ Collections.singletonList(new ShowDevicesResult("root.laptop", false)),
schemaRegion.getMatchedDevices(
SchemaRegionReadPlanFactory.getShowDevicesPlan(new
PartialPath("root.*"))));
@@ -643,29 +642,27 @@ public class SchemaRegionBasicTest extends
AbstractSchemaRegionTest {
new ShowDevicesResult("root.laptop.d1", false),
new ShowDevicesResult("root.laptop.d2", false),
new ShowDevicesResult("root.laptop.d1.s2", false));
- Integer expectedOffset = 0;
- Pair<List<ShowDevicesResult>, Integer> actualResult =
+
+ List<ShowDevicesResult> actualResult =
schemaRegion.getMatchedDevices(
SchemaRegionReadPlanFactory.getShowDevicesPlan(new
PartialPath("root.**")));
// Compare hash sets because the order does not matter.
HashSet<ShowDevicesResult> expectedHashset = new HashSet<>(expectedList);
- HashSet<ShowDevicesResult> actualHashset = new
HashSet<>(actualResult.left);
+ HashSet<ShowDevicesResult> actualHashset = new HashSet<>(actualResult);
Assert.assertEquals(expectedHashset, actualHashset);
- Assert.assertEquals(expectedOffset, actualResult.right);
expectedList =
Arrays.asList(
new ShowDevicesResult("root.laptop.d1", false),
new ShowDevicesResult("root.laptop.d2", false));
- expectedOffset = 0;
+
actualResult =
schemaRegion.getMatchedDevices(
SchemaRegionReadPlanFactory.getShowDevicesPlan(new
PartialPath("root.**.d*")));
// Compare hash sets because the order does not matter.
expectedHashset = new HashSet<>(expectedList);
- actualHashset = new HashSet<>(actualResult.left);
+ actualHashset = new HashSet<>(actualResult);
Assert.assertEquals(expectedHashset, actualHashset);
- Assert.assertEquals(expectedOffset, actualResult.right);
}
@Test
@@ -683,7 +680,7 @@ public class SchemaRegionBasicTest extends
AbstractSchemaRegionTest {
"root.laptop.d2.s2"));
// case 01: all timeseries
- Pair<List<ShowTimeSeriesResult>, Integer> result =
+ List<ShowTimeSeriesResult> result =
schemaRegion.showTimeseries(
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(new
PartialPath("root.**")));
HashSet<String> expectedPathList =
@@ -696,10 +693,10 @@ public class SchemaRegionBasicTest extends
AbstractSchemaRegionTest {
"root.laptop.d2.s1",
"root.laptop.d2.s2"));
int expectedSize = 6;
- Assert.assertEquals(expectedSize, result.left.size());
+ Assert.assertEquals(expectedSize, result.size());
HashSet<String> actualPathList = new HashSet<>();
for (int index = 0; index < expectedSize; index++) {
- actualPathList.add(result.left.get(index).getPath());
+ actualPathList.add(result.get(index).getPath());
}
Assert.assertEquals(expectedPathList, actualPathList);
@@ -715,10 +712,10 @@ public class SchemaRegionBasicTest extends
AbstractSchemaRegionTest {
"root.laptop.d2.s1",
"root.laptop.d2.s2"));
expectedSize = 4;
- Assert.assertEquals(expectedSize, result.left.size());
+ Assert.assertEquals(expectedSize, result.size());
actualPathList = new HashSet<>();
for (int index = 0; index < expectedSize; index++) {
- actualPathList.add(result.left.get(index).getPath());
+ actualPathList.add(result.get(index).getPath());
}
Assert.assertEquals(expectedPathList, actualPathList);
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
index f7c13c883c..19bd2958f8 100644
---
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionManagementTest.java
@@ -34,7 +34,6 @@ import org.apache.iotdb.db.metadata.template.Template;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
-import org.apache.iotdb.tsfile.utils.Pair;
import org.junit.Assert;
import org.junit.Ignore;
@@ -95,12 +94,12 @@ public class SchemaRegionManagementTest extends
AbstractSchemaRegionTest {
schemaRegion.loadSnapshot(snapshotDir);
- Pair<List<ShowTimeSeriesResult>, Integer> result =
+ List<ShowTimeSeriesResult> result =
schemaRegion.showTimeseries(
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(
new PartialPath("root.sg.**"), false, "tag-key",
"tag-value"));
- ShowTimeSeriesResult seriesResult = result.left.get(0);
+ ShowTimeSeriesResult seriesResult = result.get(0);
Assert.assertEquals(new PartialPath("root.sg.d1.s1").getFullPath(),
seriesResult.getPath());
Map<String, String> resultTagMap = seriesResult.getTag();
Assert.assertEquals(1, resultTagMap.size());
@@ -115,7 +114,7 @@ public class SchemaRegionManagementTest extends
AbstractSchemaRegionTest {
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(
new PartialPath("root.sg.**"), false, "tag-key",
"tag-value"));
- seriesResult = result.left.get(0);
+ seriesResult = result.get(0);
Assert.assertEquals(new PartialPath("root.sg.d1.s1").getFullPath(),
seriesResult.getPath());
resultTagMap = seriesResult.getTag();
Assert.assertEquals(1, resultTagMap.size());
@@ -126,11 +125,9 @@ public class SchemaRegionManagementTest extends
AbstractSchemaRegionTest {
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(
new PartialPath("root.sg.*.s1"),
Collections.singletonMap(template.getId(), template)));
- result.left.sort(ShowTimeSeriesResult::compareTo);
- Assert.assertEquals(
- new PartialPath("root.sg.d1.s1").getFullPath(),
result.left.get(0).getPath());
- Assert.assertEquals(
- new PartialPath("root.sg.d2.s1").getFullPath(),
result.left.get(1).getPath());
+ result.sort(ShowTimeSeriesResult::compareTo);
+ Assert.assertEquals(new PartialPath("root.sg.d1.s1").getFullPath(),
result.get(0).getPath());
+ Assert.assertEquals(new PartialPath("root.sg.d2.s1").getFullPath(),
result.get(1).getPath());
} finally {
config.setSchemaRegionConsensusProtocolClass(schemaRegionConsensusProtocolClass);
@@ -170,12 +167,12 @@ public class SchemaRegionManagementTest extends
AbstractSchemaRegionTest {
schemaRegion.loadSnapshot(snapshotDir);
- Pair<List<ShowTimeSeriesResult>, Integer> result =
+ List<ShowTimeSeriesResult> result =
schemaRegion.showTimeseries(
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(
new PartialPath("root.sg.**"), false, "tag-key",
"tag-value"));
- Assert.assertEquals(0, result.left.size());
+ Assert.assertEquals(0, result.size());
simulateRestart();
@@ -186,7 +183,7 @@ public class SchemaRegionManagementTest extends
AbstractSchemaRegionTest {
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(
new PartialPath("root.sg.**"), false, "tag-key",
"tag-value"));
- Assert.assertEquals(0, result.left.size());
+ Assert.assertEquals(0, result.size());
} finally {
config.setSchemaRegionConsensusProtocolClass(schemaRegionConsensusProtocolClass);
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaQueryScanOperatorTest.java
b/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaQueryScanOperatorTest.java
index ef64e274fa..2e87aea031 100644
---
a/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaQueryScanOperatorTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/mpp/execution/operator/schema/SchemaQueryScanOperatorTest.java
@@ -22,8 +22,9 @@ import
org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.path.PartialPath;
import
org.apache.iotdb.db.metadata.plan.schemaregion.impl.read.SchemaRegionReadPlanFactory;
-import org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowDevicesResult;
-import
org.apache.iotdb.db.metadata.plan.schemaregion.result.ShowTimeSeriesResult;
+import org.apache.iotdb.db.metadata.query.info.IDeviceSchemaInfo;
+import org.apache.iotdb.db.metadata.query.info.ITimeSeriesSchemaInfo;
+import org.apache.iotdb.db.metadata.query.reader.ISchemaReader;
import org.apache.iotdb.db.metadata.schemaregion.ISchemaRegion;
import org.apache.iotdb.db.mpp.common.FragmentInstanceId;
import org.apache.iotdb.db.mpp.common.PlanFragmentId;
@@ -41,6 +42,7 @@ import org.apache.iotdb.tsfile.read.common.block.TsBlock;
import org.apache.iotdb.tsfile.read.common.block.column.BinaryColumn;
import org.apache.iotdb.tsfile.utils.Binary;
import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.junit.Assert;
import org.junit.Test;
@@ -49,6 +51,7 @@ import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
@@ -81,17 +84,30 @@ public class SchemaQueryScanOperatorTest {
1, planNodeId, SchemaQueryScanOperator.class.getSimpleName());
PartialPath partialPath = new PartialPath(META_SCAN_OPERATOR_TEST_SG +
".device0");
ISchemaRegion schemaRegion = Mockito.mock(ISchemaRegion.class);
+
Mockito.when(schemaRegion.getStorageGroupFullPath()).thenReturn(META_SCAN_OPERATOR_TEST_SG);
+ IDeviceSchemaInfo deviceSchemaInfo =
Mockito.mock(IDeviceSchemaInfo.class);
+ Mockito.when(deviceSchemaInfo.getFullPath())
+ .thenReturn(META_SCAN_OPERATOR_TEST_SG + ".device0");
+ Mockito.when(deviceSchemaInfo.isAligned()).thenReturn(false);
+ Iterator<IDeviceSchemaInfo> iterator =
Collections.singletonList(deviceSchemaInfo).iterator();
Mockito.when(
- schemaRegion.getMatchedDevices(
+ schemaRegion.getDeviceReader(
SchemaRegionReadPlanFactory.getShowDevicesPlan(partialPath,
10, 0, true, false)))
.thenReturn(
- new Pair<>(
- Collections.singletonList(
- new ShowDevicesResult(
- META_SCAN_OPERATOR_TEST_SG + ".device0",
- false,
- META_SCAN_OPERATOR_TEST_SG)),
- 0));
+ new ISchemaReader<IDeviceSchemaInfo>() {
+ @Override
+ public void close() throws Exception {}
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public IDeviceSchemaInfo next() {
+ return iterator.next();
+ }
+ });
operatorContext
.getInstanceContext()
.setDriverContext(new SchemaDriverContext(fragmentInstanceContext,
schemaRegion));
@@ -158,27 +174,41 @@ public class SchemaQueryScanOperatorTest {
1, planNodeId, SchemaQueryScanOperator.class.getSimpleName());
PartialPath partialPath = new PartialPath(META_SCAN_OPERATOR_TEST_SG +
".device0.*");
- List<ShowTimeSeriesResult> showTimeSeriesResults = new ArrayList<>();
+ List<ITimeSeriesSchemaInfo> showTimeSeriesResults = new ArrayList<>();
for (int i = 0; i < 10; i++) {
- showTimeSeriesResults.add(
- new ShowTimeSeriesResult(
- META_SCAN_OPERATOR_TEST_SG + ".device0" + "s" + i,
- null,
- META_SCAN_OPERATOR_TEST_SG,
- TSDataType.INT32,
- TSEncoding.PLAIN,
- CompressionType.UNCOMPRESSED,
- null,
- null,
- null,
- null));
+ ITimeSeriesSchemaInfo timeSeriesSchemaInfo =
Mockito.mock(ITimeSeriesSchemaInfo.class);
+ Mockito.when(timeSeriesSchemaInfo.getFullPath())
+ .thenReturn(META_SCAN_OPERATOR_TEST_SG + ".device0." + "s" + i);
+ Mockito.when(timeSeriesSchemaInfo.getAlias()).thenReturn(null);
+ Mockito.when(timeSeriesSchemaInfo.getSchema())
+ .thenReturn(
+ new MeasurementSchema(
+ "s" + i, TSDataType.INT32, TSEncoding.PLAIN,
CompressionType.UNCOMPRESSED));
+ Mockito.when(timeSeriesSchemaInfo.getTagAndAttribute()).thenReturn(new
Pair<>(null, null));
+ showTimeSeriesResults.add(timeSeriesSchemaInfo);
}
+ Iterator<ITimeSeriesSchemaInfo> iterator =
showTimeSeriesResults.iterator();
ISchemaRegion schemaRegion = Mockito.mock(ISchemaRegion.class);
+
Mockito.when(schemaRegion.getStorageGroupFullPath()).thenReturn(META_SCAN_OPERATOR_TEST_SG);
Mockito.when(
- schemaRegion.showTimeseries(
+ schemaRegion.getTimeSeriesReader(
SchemaRegionReadPlanFactory.getShowTimeSeriesPlan(partialPath, 10, 0)))
- .thenReturn(new Pair<>(showTimeSeriesResults, 0));
+ .thenReturn(
+ new ISchemaReader<ITimeSeriesSchemaInfo>() {
+ @Override
+ public void close() throws Exception {}
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public ITimeSeriesSchemaInfo next() {
+ return iterator.next();
+ }
+ });
operatorContext
.getInstanceContext()