This is an automated email from the ASF dual-hosted git repository.
haonan 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 e5f213c [IOTDB-949] fix align by device bug (#1837)
e5f213c is described below
commit e5f213c9d898716ddaae2470e3ba2657776d65b2
Author: Jackie Tien <[email protected]>
AuthorDate: Wed Oct 21 20:50:49 2020 +0800
[IOTDB-949] fix align by device bug (#1837)
---
.../java/org/apache/iotdb/db/metadata/MTree.java | 11 +++-
.../iotdb/db/integration/IoTDBAlignByDeviceIT.java | 60 ++++++++++++++++++++++
2 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index 36fe579..1fa8160 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -1150,9 +1150,11 @@ public class MTree implements Serializable {
* @param idx the current index of array nodes
* @param res store all matched device names
*/
+ @SuppressWarnings("squid:S3776")
private void findDevices(MNode node, String[] nodes, int idx,
Set<PartialPath> res) {
String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes);
- if (!(PATH_WILDCARD).equals(nodeReg)) {
+ // the node path doesn't contains '*'
+ if (!nodeReg.contains(PATH_WILDCARD)) {
MNode next = node.getChild(nodeReg);
if (next != null) {
if (next instanceof MeasurementMNode && idx >= nodes.length) {
@@ -1161,9 +1163,14 @@ public class MTree implements Serializable {
findDevices(next, nodes, idx + 1, res);
}
}
- } else {
+ } else { // the node path contains '*'
boolean deviceAdded = false;
for (MNode child : node.getChildren().values()) {
+ // use '.*' to replace '*' to form a regex to match
+ // if the match failed, skip it.
+ if (!Pattern.matches(nodeReg.replace("*", ".*"), child.getName())) {
+ continue;
+ }
if (child instanceof MeasurementMNode && !deviceAdded && idx >=
nodes.length) {
res.add(node.getPartialPath());
deviceAdded = true;
diff --git
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
index 814bfe3..b93c08c 100644
---
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
+++
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
@@ -987,4 +987,64 @@ public class IoTDBAlignByDeviceIT {
}
return actualIndexToExpectedIndexList;
}
+
+ @Test
+ public void selectWithStarTest() throws ClassNotFoundException {
+ String[] retArray = new String[]{
+ "1,root.vehicle.d0,101,1101,null,null,null,",
+ "2,root.vehicle.d0,10000,40000,2.22,null,null,",
+ "3,root.vehicle.d0,null,null,3.33,null,null,",
+ "4,root.vehicle.d0,null,null,4.44,null,null,",
+ "50,root.vehicle.d0,10000,50000,null,null,null,",
+ "60,root.vehicle.d0,null,null,null,aaaaa,null,",
+ "70,root.vehicle.d0,null,null,null,bbbbb,null,",
+ "80,root.vehicle.d0,null,null,null,ccccc,null,",
+ "100,root.vehicle.d0,99,199,null,null,true,",
+ "101,root.vehicle.d0,99,199,null,ddddd,null,",
+ "102,root.vehicle.d0,80,180,10.0,fffff,null,",
+ "103,root.vehicle.d0,99,199,null,null,null,",
+ "104,root.vehicle.d0,90,190,null,null,null,",
+ "105,root.vehicle.d0,99,199,11.11,null,null,",
+ "106,root.vehicle.d0,99,null,null,null,null,",
+ "1000,root.vehicle.d0,22222,55555,1000.11,null,null,",
+ "946684800000,root.vehicle.d0,null,100,null,good,null,",
+ "1,root.vehicle.d1,999,null,null,null,null,",
+ "1000,root.vehicle.d1,888,null,null,null,null,",
+ };
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/",
"root", "root");
+ Statement statement = connection.createStatement()) {
+ boolean hasResultSet = statement.execute(
+ "select * from root.vehicle.d* align by device");
+ Assert.assertTrue(hasResultSet);
+
+ try (ResultSet resultSet = statement.getResultSet()) {
+ ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+ List<Integer> actualIndexToExpectedIndexList =
checkHeader(resultSetMetaData,
+ "Time,Device,s0,s1,s2,s3,s4",
+ new int[]{Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER,
Types.BIGINT, Types.FLOAT,
+ Types.VARCHAR, Types.BOOLEAN});
+
+ int cnt = 0;
+ while (resultSet.next()) {
+ String[] expectedStrings = retArray[cnt].split(",");
+ StringBuilder expectedBuilder = new StringBuilder();
+ StringBuilder actualBuilder = new StringBuilder();
+ for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
+ actualBuilder.append(resultSet.getString(i)).append(",");
+
expectedBuilder.append(expectedStrings[actualIndexToExpectedIndexList.get(i -
1)])
+ .append(",");
+ }
+ Assert.assertEquals(expectedBuilder.toString(),
actualBuilder.toString());
+ cnt++;
+ }
+ Assert.assertEquals(19, cnt);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
}