[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380518901
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MNode.java
 ##
 @@ -22,10 +22,15 @@
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
+
+import com.sun.rowset.internal.Row;
 import org.apache.iotdb.db.conf.IoTDBConstant;
 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.read.TimeValuePair;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
 
 Review comment:
   this import is not used, please remove it.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380532638
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
 ##
 @@ -0,0 +1,201 @@
+/*
+ * 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.iotdb.db.query.executor;
+
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.exception.path.PathException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.db.metadata.MNode;
+import org.apache.iotdb.db.qp.constant.SQLConstant;
+import org.apache.iotdb.db.qp.physical.crud.AggregationPlan;
+import org.apache.iotdb.db.qp.physical.crud.LastQueryPlan;
+import org.apache.iotdb.db.query.aggregation.AggregateResult;
+import org.apache.iotdb.db.query.context.QueryContext;
+import org.apache.iotdb.db.query.control.QueryResourceManager;
+import org.apache.iotdb.db.query.dataset.SingleDataSet;
+import org.apache.iotdb.db.query.factory.AggreResultFactory;
+import org.apache.iotdb.db.query.reader.series.IAggregateReader;
+import org.apache.iotdb.db.query.reader.series.SeriesAggregateReader;
+import org.apache.iotdb.tsfile.exception.cache.CacheException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
+import org.apache.iotdb.tsfile.utils.TsPrimitiveType;
+import org.omg.CORBA.TIMEOUT;
 
 Review comment:
   A lot of imports are not used. You should check that and delete them


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380540330
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java
 ##
 @@ -185,4 +190,13 @@ public void deserializeFrom(ByteBuffer buffer) {
   public String toString() {
 return "deviceId: " + deviceId + ", time: " + time;
   }
+
+  public void updateMNodeLastValues(MNode node) throws QueryProcessException {
+for (int i = 0; i < measurements.length; i++) {
+  if (node.hasChild(measurements[i])) {
+Object value = CommonUtils.parseValue(dataTypes[i], values[i]);
+node.getChild(measurements[i]).updateCachedLast(time, value, 
dataTypes[i]);
+  }
+}
+  }
 
 Review comment:
   Same as before 


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380518625
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MNode.java
 ##
 @@ -22,10 +22,15 @@
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
+
+import com.sun.rowset.internal.Row;
 
 Review comment:
   what's this for?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380537858
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
 ##
 @@ -680,6 +674,7 @@ public void insert(InsertPlan insertPlan) throws 
QueryProcessException {
   }
   insertPlan.setDataTypes(dataTypes);
   storageEngine.insert(insertPlan);
+  insertPlan.updateMNodeLastValues(node);
 
 Review comment:
   It is not suitable to put the updateMNodeLastValues method in the InsertPlan.
   You can update the last value in the before loop, there you already got the 
measurementNode.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380531833
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
 ##
 @@ -0,0 +1,201 @@
+/*
+ * 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.iotdb.db.query.executor;
+
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.exception.path.PathException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.db.metadata.MNode;
+import org.apache.iotdb.db.qp.constant.SQLConstant;
+import org.apache.iotdb.db.qp.physical.crud.AggregationPlan;
+import org.apache.iotdb.db.qp.physical.crud.LastQueryPlan;
+import org.apache.iotdb.db.query.aggregation.AggregateResult;
+import org.apache.iotdb.db.query.context.QueryContext;
+import org.apache.iotdb.db.query.control.QueryResourceManager;
+import org.apache.iotdb.db.query.dataset.SingleDataSet;
+import org.apache.iotdb.db.query.factory.AggreResultFactory;
+import org.apache.iotdb.db.query.reader.series.IAggregateReader;
+import org.apache.iotdb.db.query.reader.series.SeriesAggregateReader;
+import org.apache.iotdb.tsfile.exception.cache.CacheException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
+import org.apache.iotdb.tsfile.utils.TsPrimitiveType;
+import org.omg.CORBA.TIMEOUT;
+
+import java.io.IOException;
+import java.sql.Time;
+import java.util.*;
+
+public class LastQueryExecutor {
+private List selectedSeries;
+private List dataTypes;
+
+public LastQueryExecutor(LastQueryPlan lastQueryPlan) {
+this.selectedSeries = lastQueryPlan.getPaths();
+this.dataTypes = lastQueryPlan.getDataTypes();
+}
+
+/**
+ * execute last function
+ *
+ * @param context query context
+ */
+public QueryDataSet execute(QueryContext context)
+throws StorageEngineException, IOException, QueryProcessException {
+
+List lastQueryResultList = new ArrayList<>();
+for (int i = 0; i < selectedSeries.size(); i++) {
+LastQueryResult lastQueryResult = 
calculateLastPairForOneSeries(selectedSeries.get(i), dataTypes.get(i), context);
+lastQueryResultList.add(lastQueryResult);
+}
+
+RowRecord resultRecord = constructLastRowRecord(lastQueryResultList);
+SingleDataSet dataSet = new SingleDataSet(selectedSeries, dataTypes);
+dataSet.setRecord(resultRecord);
+return dataSet;
+}
+
+/**
+ * get aggregation result for one series
+ *
+ * @param context query context
+ * @return AggregateResult list
+ */
+private LastQueryResult calculateLastPairForOneSeries(
+Path seriesPath, TSDataType tsDataType,
+QueryContext context)
+throws IOException, QueryProcessException, StorageEngineException {
+LastQueryResult queryResult = new LastQueryResult();
+MNode node = null;
+try {
+node = 
MManager.getInstance().getNodeByPathFromCache(seriesPath.toString());
+} catch (PathException e) {
+throw new QueryProcessException(e);
+} catch (CacheException e) {
+throw new QueryProcessException(e.getMessage());
+}
+if (node.getCachedLast() != null) {
+queryResult.setPairResult(node.getCachedLast());
+return queryResult;
+}
+
+// construct series reader without value filter
+Filter timeFilter = null;
+IAggregateReader seriesReader = new SeriesAggregateReader(
+seriesPath, tsDataType, context, 
QueryResourceManager.getInstance()
+

[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380541185
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
 ##
 @@ -196,6 +196,7 @@ public static TSDataType getSeriesType(String path) throws 
QueryProcessException
 case SQLConstant.FIRST_VALUE:
 case SQLConstant.MIN_VALUE:
 case SQLConstant.MAX_VALUE:
+//case SQLConstant.LAST:
 
 Review comment:
   delete it


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380538229
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
 ##
 @@ -772,8 +767,9 @@ private void checkPathExists(MNode node, String fullPath, 
MeasurementSchema sche
   measurementNode.getSchema().getType()));
 }
   }
-  return storageEngine.insertBatch(batchInsertPlan);
-
+  Integer[] results = storageEngine.insertBatch(batchInsertPlan);
+  batchInsertPlan.updateMNodeLastValues(node);
 
 Review comment:
   The same as before


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380540195
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/physical/crud/BatchInsertPlan.java
 ##
 @@ -288,6 +292,23 @@ public long getMaxTime() {
 return maxTime;
   }
 
+  public void updateMNodeLastValues(MNode node) {
+long maxTime = Long.MIN_VALUE;
+int maxIndex = 0;
+for (int i = 0; i < times.length; i++) {
+  if (times[i] > maxTime) {
+maxTime = times[i];
+maxIndex = i;
+  }
+}
+for (int i = 0; i < measurements.length; i++) {
+  if (node.hasChild(measurements[i])) {
+Object[] column = (Object[]) columns[i];
+node.getChild(measurements[i]).updateCachedLast(maxTime, 
column[maxIndex], dataTypes[i]);
+  }
+}
+  }
+
 
 Review comment:
   This function is not the InsertPlan's responsibility


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380539293
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/qp/logical/Operator.java
 ##
 @@ -68,7 +68,7 @@ public String toString() {
   public enum OperatorType {
 SFW, JOIN, UNION, FILTER, GROUPBY, ORDERBY, LIMIT, SELECT, SEQTABLESCAN, 
HASHTABLESCAN,
 MERGEJOIN, FILEREAD, NULL, TABLESCAN, UPDATE, INSERT, BATCHINSERT, DELETE, 
BASIC_FUNC, IN, QUERY, MERGEQUERY,
-AGGREGATION, AUTHOR, FROM, FUNC, LOADDATA, METADATA, PROPERTY, INDEX, 
INDEXQUERY, FILL,
+AGGREGATION, AUTHOR, FROM, FUNC, LOADDATA, METADATA, PROPERTY, INDEX, 
INDEXQUERY, FILL, LAST,
 
 Review comment:
   It's better to add it to the last, because you don't know whether the 
programmers are using the enum's ordinal() function


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380542837
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole series

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380550422
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole series

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380489630
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
+
+  /**
+   * Constructor of MNode.
+   */
+  public MNode(String name, MNode parent) {
+this.setName(name);
+this.parent = parent;
+  }
+
+  abstract public boolean isNodeType(MNodeType nodeType);
+
+  /**
+   * Set storage group
+   */
+  public void setStorageGroup() {
+nodeType = MNodeType.STORAGE_GROUP_MNODE;
+schemaMap = new HashMap<>();
+  }
+
+  public Map getSchemaMap() {
+return schemaMap;
+  }
+
+  /**
+   * check whether the MNode has children
+   */
+  abstract public boolean hasChildren();
+
+  /**
+   * check whether the MNode has child with the given key
+   *
+   * @param key key
+   */
+  abstract public boolean hasChildWithKey(String key);
+
+  /**
+   * add the given key to given child MNode
+   *
+   * @param key key
+   * @param child child MNode
+   */
+  abstract public void addChild(String key, MNode child);
+
+  /**
+   * delete key from given child MNode
+   *
+   * @param key key
+   */
+  abstract public void deleteChild(String key);
+
+  /**
+   * get the child MNode under the given key.
+   *
+   * @param key key
+   */
+  abstract public MNode getChild(String key);
+
+  /**
+   * get the count of all leaves whose ancestor is current node
+   */
+  abstract public int getLeafCount();
+
+  /**
+   * get full path
+   */
+  public String getFullPath() {
+if (fullPath != null) {
+  return fullPath;
+}
+StringBuilder builder = new StringBuilder(name);
+MNode curr = this;
+while (curr.parent != null) {
+  curr = curr.parent;
+  builder.insert(0, IoTDBConstant.PATH_SEPARATOR).insert(0, curr.name);
+}
+return fullPath = builder.toString();
+  }
+
+  public String getStorageGroupName() {
+return storageGroupName;
+  }
+
+  public void setStorageGroupName(String storageGroupName) {
+this.storageGroupName = storageGroupName;
+  }
+
+  @Override
+  public String toString() {
+return this.getName();
+  }
+
+  public MeasurementSchema getSchema() {
+return schema;
+  }
+
+  public MNode getParent() {
+return parent;
+  }
+
+  abstract public Map getChildren();
+
+  public String getName() {
+return name;
+  }
+
+  public void setName(String name) {
+this.name = name;
+  }
+
+  public long getDataTTL() {
+return dataTTL;
+  }
+
+  public void setDataTTL(long dataTTL) {
 
 Review comment:
   use a StorageGroupMNode, move this method into it


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.
 
For queries about this service, please c

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380434562
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
 ##
 @@ -18,27 +18,33 @@
  */
 package org.apache.iotdb.db.metadata;
 
-public class MetaUtils {
-  public static String[] getNodeNames(String path, String separator) {
+import static org.apache.iotdb.db.conf.IoTDBConstant.PATH_WILDCARD;
+
+class MetaUtils {
+
+  private static final String PATH_SEPARATOR = "\\.";
+
+  private MetaUtils() {
+
+  }
+
+  static String[] getNodeNames(String path) {
 String[] nodeNames;
-path = path.trim();
 if (path.contains("\"") || path.contains("\'")) {
-  String[] deviceAndMeasurement;
-  if (path.contains("\"")) {
-deviceAndMeasurement = path.split("\"");
-  } else {
-deviceAndMeasurement = path.split("\'");
-  }
-  String device = deviceAndMeasurement[0];
-  String measurement = deviceAndMeasurement[1];
-  String[] deviceNodeName = device.split(separator);
+  path = path.trim().replace("\'", "\"");
+  String measurement = path.split("\"")[1];
 
 Review comment:
   cache path.split to avoid splitting twice


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380505126
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
 
 Review comment:
   move this to StorageGroupMNode


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380551514
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
+
+  /**
+   * Constructor of MNode.
+   */
+  public MNode(String name, MNode parent) {
+this.setName(name);
+this.parent = parent;
+  }
+
+  abstract public boolean isNodeType(MNodeType nodeType);
+
+  /**
+   * Set storage group
+   */
+  public void setStorageGroup() {
+nodeType = MNodeType.STORAGE_GROUP_MNODE;
+schemaMap = new HashMap<>();
+  }
+
+  public Map getSchemaMap() {
+return schemaMap;
+  }
+
+  /**
+   * check whether the MNode has children
+   */
+  abstract public boolean hasChildren();
+
+  /**
+   * check whether the MNode has child with the given key
+   *
+   * @param key key
+   */
+  abstract public boolean hasChildWithKey(String key);
 
 Review comment:
   ```suggestion
 abstract public boolean hasChild(String childName);
   ```


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380553188
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole series

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380535004
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/metadata/mnode/InternalMNode.java
 ##
 @@ -0,0 +1,108 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public class InternalMNode extends MNode {
+
+  private static final long serialVersionUID = 7999036474525817732L;
+
+  public InternalMNode(String name, MNode parent) {
+super(name, parent);
+this.nodeType = MNodeType.INTERNAL_MNODE;
+this.children = new LinkedHashMap<>();
+  }
+
+  @Override
+  public boolean isNodeType(MNodeType nodeType) {
+return this.nodeType.equals(nodeType);
+  }
+
+  /**
+   * check whether the MNode has children
+   */
+  @Override
+  public boolean hasChildren() {
+return true;
+  }
+
+  /**
+   * check whether the MNode has child with the given key
+   *
+   * @param key key
+   */
+  @Override
+  public boolean hasChildWithKey(String key) {
+return this.children.containsKey(key);
+  }
+
+  /**
+   * add the given key to given child MNode
+   *
+   * @param key key
+   * @param child child MNode
+   */
+  @Override
+  public void addChild(String key, MNode child) {
+this.children.put(key, child);
+  }
+
+  /**
+   * delete key from given child MNode
+   *
+   * @param key key
 
 Review comment:
   ```suggestion
  * @param key deleted child name
   ```


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380501850
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
+
+  /**
+   * Constructor of MNode.
+   */
+  public MNode(String name, MNode parent) {
+this.setName(name);
+this.parent = parent;
+  }
+
+  abstract public boolean isNodeType(MNodeType nodeType);
+
+  /**
+   * Set storage group
+   */
+  public void setStorageGroup() {
+nodeType = MNodeType.STORAGE_GROUP_MNODE;
 
 Review comment:
   the nodeType could be retained, add a getter


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380550921
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole series

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380489698
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/metadata/mnode/LeafMNode.java
 ##
 @@ -0,0 +1,99 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.util.Collections;
+import java.util.Map;
+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.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public class LeafMNode extends MNode {
+
+  private static final long serialVersionUID = -1199657856921206435L;
+
+  public LeafMNode(String name, MNode parent) {
+super(name, parent);
+  }
+
+  public LeafMNode(String name, MNode parent, TSDataType dataType, TSEncoding 
encoding,
+  CompressionType type) {
 
 Review comment:
   add props map


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380504789
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
 
 Review comment:
   move this to LeafNode. I wonder if this will occupy much memory.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380503888
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
 
 Review comment:
   move this to StorageGroupMNode


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380540800
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole series

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380501678
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
+
+  /**
+   * Constructor of MNode.
+   */
+  public MNode(String name, MNode parent) {
+this.setName(name);
+this.parent = parent;
+  }
+
+  abstract public boolean isNodeType(MNodeType nodeType);
 
 Review comment:
   if we use Class type to distinguish the types, this method could be removed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380503943
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
 
 Review comment:
   move this to LeafNode


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380549297
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole series

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380534706
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/metadata/mnode/InternalMNode.java
 ##
 @@ -0,0 +1,108 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public class InternalMNode extends MNode {
+
+  private static final long serialVersionUID = 7999036474525817732L;
+
+  public InternalMNode(String name, MNode parent) {
+super(name, parent);
+this.nodeType = MNodeType.INTERNAL_MNODE;
+this.children = new LinkedHashMap<>();
+  }
+
+  @Override
+  public boolean isNodeType(MNodeType nodeType) {
+return this.nodeType.equals(nodeType);
+  }
+
+  /**
+   * check whether the MNode has children
+   */
+  @Override
+  public boolean hasChildren() {
+return true;
+  }
+
+  /**
+   * check whether the MNode has child with the given key
+   *
+   * @param key key
+   */
+  @Override
+  public boolean hasChildWithKey(String key) {
+return this.children.containsKey(key);
+  }
+
+  /**
+   * add the given key to given child MNode
+   *
+   * @param key key
+   * @param child child MNode
+   */
+  @Override
+  public void addChild(String key, MNode child) {
+this.children.put(key, child);
+  }
+
+  /**
+   * delete key from given child MNode
+   *
+   * @param key key
+   */
+  @Override
+  public void deleteChild(String key) {
+children.remove(key);
+  }
+
+  /**
+   * get the child MNode under the given key.
+   *
+   * @param key key
 
 Review comment:
   ```suggestion
  * @param key the queried child name
   ```


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380541020
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
 
 Review comment:
   ```suggestion
  * Add an interval path to 

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380548246
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole series

[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380561106
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MNode.java
 ##
 @@ -22,10 +22,15 @@
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
+
+import com.sun.rowset.internal.Row;
 
 Review comment:
   Removed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] qiaojialin merged pull request #818: [IOTDB-482] Vectorized TimeGenerator

2020-02-18 Thread GitBox
qiaojialin merged pull request #818: [IOTDB-482] Vectorized TimeGenerator
URL: https://github.com/apache/incubator-iotdb/pull/818
 
 
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380561185
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MNode.java
 ##
 @@ -22,10 +22,15 @@
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
+
+import com.sun.rowset.internal.Row;
 import org.apache.iotdb.db.conf.IoTDBConstant;
 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.read.TimeValuePair;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
 
 Review comment:
   Fixed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380561357
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
 ##
 @@ -0,0 +1,201 @@
+/*
+ * 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.iotdb.db.query.executor;
+
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.exception.path.PathException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.db.metadata.MNode;
+import org.apache.iotdb.db.qp.constant.SQLConstant;
+import org.apache.iotdb.db.qp.physical.crud.AggregationPlan;
+import org.apache.iotdb.db.qp.physical.crud.LastQueryPlan;
+import org.apache.iotdb.db.query.aggregation.AggregateResult;
+import org.apache.iotdb.db.query.context.QueryContext;
+import org.apache.iotdb.db.query.control.QueryResourceManager;
+import org.apache.iotdb.db.query.dataset.SingleDataSet;
+import org.apache.iotdb.db.query.factory.AggreResultFactory;
+import org.apache.iotdb.db.query.reader.series.IAggregateReader;
+import org.apache.iotdb.db.query.reader.series.SeriesAggregateReader;
+import org.apache.iotdb.tsfile.exception.cache.CacheException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
+import org.apache.iotdb.tsfile.utils.TsPrimitiveType;
+import org.omg.CORBA.TIMEOUT;
 
 Review comment:
   Fixed, thanks


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader

2020-02-18 Thread GitBox
sonarcloud[bot] commented on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-587395775
 
 
   SonarCloud Quality Gate failed.
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=BUG)
 [1 
Bug](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=CODE_SMELL)
 [19 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=713&metric=new_duplicated_lines_density&view=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=713&metric=new_duplicated_lines_density&view=list)
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader

2020-02-18 Thread GitBox
sonarcloud[bot] removed a comment on issue #713: [IOTDB-418] New series reader
URL: https://github.com/apache/incubator-iotdb/pull/713#issuecomment-587229353
 
 
   SonarCloud Quality Gate failed.
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=BUG)
 [1 
Bug](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=CODE_SMELL)
 [14 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=713&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=713)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=713&metric=new_duplicated_lines_density&view=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=713&metric=new_duplicated_lines_density&view=list)
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380596490
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
 ##
 @@ -196,6 +196,7 @@ public static TSDataType getSeriesType(String path) throws 
QueryProcessException
 case SQLConstant.FIRST_VALUE:
 case SQLConstant.MIN_VALUE:
 case SQLConstant.MAX_VALUE:
+//case SQLConstant.LAST:
 
 Review comment:
   Fixed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380597536
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/qp/logical/Operator.java
 ##
 @@ -68,7 +68,7 @@ public String toString() {
   public enum OperatorType {
 SFW, JOIN, UNION, FILTER, GROUPBY, ORDERBY, LIMIT, SELECT, SEQTABLESCAN, 
HASHTABLESCAN,
 MERGEJOIN, FILEREAD, NULL, TABLESCAN, UPDATE, INSERT, BATCHINSERT, DELETE, 
BASIC_FUNC, IN, QUERY, MERGEQUERY,
-AGGREGATION, AUTHOR, FROM, FUNC, LOADDATA, METADATA, PROPERTY, INDEX, 
INDEXQUERY, FILL,
+AGGREGATION, AUTHOR, FROM, FUNC, LOADDATA, METADATA, PROPERTY, INDEX, 
INDEXQUERY, FILL, LAST,
 
 Review comment:
   Modified


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380646350
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/exception/metadata/RootNotExistException.java
 ##
 @@ -15,16 +15,16 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
+ *
  */
 
-package org.apache.iotdb.db.exception.storageGroup;
+package org.apache.iotdb.db.exception.metadata;
 
-public class StorageGroupPathException extends StorageGroupException {
+public class RootNotExistException extends MetadataException {
 
 Review comment:
   Renamed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380646512
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
 ##
 @@ -18,27 +18,33 @@
  */
 package org.apache.iotdb.db.metadata;
 
-public class MetaUtils {
-  public static String[] getNodeNames(String path, String separator) {
+import static org.apache.iotdb.db.conf.IoTDBConstant.PATH_WILDCARD;
+
+class MetaUtils {
+
+  private static final String PATH_SEPARATOR = "\\.";
+
+  private MetaUtils() {
+
+  }
+
+  static String[] getNodeNames(String path) {
 String[] nodeNames;
-path = path.trim();
 if (path.contains("\"") || path.contains("\'")) {
-  String[] deviceAndMeasurement;
-  if (path.contains("\"")) {
-deviceAndMeasurement = path.split("\"");
-  } else {
-deviceAndMeasurement = path.split("\'");
-  }
-  String device = deviceAndMeasurement[0];
-  String measurement = deviceAndMeasurement[1];
-  String[] deviceNodeName = device.split(separator);
+  path = path.trim().replace("\'", "\"");
+  String measurement = path.split("\"")[1];
 
 Review comment:
   Fixed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380646635
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/metadata/mnode/LeafMNode.java
 ##
 @@ -0,0 +1,99 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.util.Collections;
+import java.util.Map;
+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.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public class LeafMNode extends MNode {
+
+  private static final long serialVersionUID = -1199657856921206435L;
+
+  public LeafMNode(String name, MNode parent) {
+super(name, parent);
+  }
+
+  public LeafMNode(String name, MNode parent, TSDataType dataType, TSEncoding 
encoding,
+  CompressionType type) {
 
 Review comment:
   Fixed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380646956
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/metadata/mnode/InternalMNode.java
 ##
 @@ -0,0 +1,108 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public class InternalMNode extends MNode {
+
+  private static final long serialVersionUID = 7999036474525817732L;
+
+  public InternalMNode(String name, MNode parent) {
+super(name, parent);
+this.nodeType = MNodeType.INTERNAL_MNODE;
+this.children = new LinkedHashMap<>();
+  }
+
+  @Override
+  public boolean isNodeType(MNodeType nodeType) {
+return this.nodeType.equals(nodeType);
+  }
+
+  /**
+   * check whether the MNode has children
+   */
+  @Override
+  public boolean hasChildren() {
+return true;
+  }
+
+  /**
+   * check whether the MNode has child with the given key
+   *
+   * @param key key
+   */
+  @Override
+  public boolean hasChildWithKey(String key) {
+return this.children.containsKey(key);
+  }
+
+  /**
+   * add the given key to given child MNode
+   *
+   * @param key key
+   * @param child child MNode
+   */
+  @Override
+  public void addChild(String key, MNode child) {
+this.children.put(key, child);
+  }
+
+  /**
+   * delete key from given child MNode
+   *
+   * @param key key
+   */
+  @Override
+  public void deleteChild(String key) {
+children.remove(key);
+  }
+
+  /**
+   * get the child MNode under the given key.
+   *
+   * @param key key
 
 Review comment:
   Updated.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380647119
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
 
 Review comment:
   Updated.

-

[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380646982
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/metadata/mnode/InternalMNode.java
 ##
 @@ -0,0 +1,108 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public class InternalMNode extends MNode {
+
+  private static final long serialVersionUID = 7999036474525817732L;
+
+  public InternalMNode(String name, MNode parent) {
+super(name, parent);
+this.nodeType = MNodeType.INTERNAL_MNODE;
+this.children = new LinkedHashMap<>();
+  }
+
+  @Override
+  public boolean isNodeType(MNodeType nodeType) {
+return this.nodeType.equals(nodeType);
+  }
+
+  /**
+   * check whether the MNode has children
+   */
+  @Override
+  public boolean hasChildren() {
+return true;
+  }
+
+  /**
+   * check whether the MNode has child with the given key
+   *
+   * @param key key
+   */
+  @Override
+  public boolean hasChildWithKey(String key) {
+return this.children.containsKey(key);
+  }
+
+  /**
+   * add the given key to given child MNode
+   *
+   * @param key key
+   * @param child child MNode
+   */
+  @Override
+  public void addChild(String key, MNode child) {
+this.children.put(key, child);
+  }
+
+  /**
+   * delete key from given child MNode
+   *
+   * @param key key
 
 Review comment:
   Updated.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380648752
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole ser

[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r380648844
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
+
+  /**
+   * Constructor of MNode.
+   */
+  public MNode(String name, MNode parent) {
+this.setName(name);
+this.parent = parent;
+  }
+
+  abstract public boolean isNodeType(MNodeType nodeType);
+
+  /**
+   * Set storage group
+   */
+  public void setStorageGroup() {
+nodeType = MNodeType.STORAGE_GROUP_MNODE;
+schemaMap = new HashMap<>();
+  }
+
+  public Map getSchemaMap() {
+return schemaMap;
+  }
+
+  /**
+   * check whether the MNode has children
+   */
+  abstract public boolean hasChildren();
+
+  /**
+   * check whether the MNode has child with the given key
+   *
+   * @param key key
+   */
+  abstract public boolean hasChildWithKey(String key);
 
 Review comment:
   Fixed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense opened a new pull request #822: [IOTDB-502] NPE bug in `org.apache.iotdb.db.service.TSServiceImpl`

2020-02-18 Thread GitBox
vesense opened a new pull request #822: [IOTDB-502] NPE bug in 
`org.apache.iotdb.db.service.TSServiceImpl`
URL: https://github.com/apache/incubator-iotdb/pull/822
 
 
   The IoTDB server throws the following error when accessing 0.10 
server(master) by 0.9 shell client (latest release).
   
   Exception trace:
   
   > org.apache.iotdb.db.service.TSServiceImpl#getTimeZone
   > java.lang.NullPointerException: null at 
org.apache.iotdb.db.service.TSServiceImpl.getTimeZone(TSServiceImpl.java:1120) 
at 
org.apache.iotdb.service.rpc.thrift.TSIService$Processor$getTimeZone.getResult(TSIService.java:1853)
 at 
org.apache.iotdb.service.rpc.thrift.TSIService$Processor$getTimeZone.getResult(TSIService.java:1833)
 at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:38) at 
org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:38) at 
org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:313)
 at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 
at java.lang.Thread.run(Thread.java:748)
   
    


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
sonarcloud[bot] removed a comment on issue #793: [IOTDB-274] Refactor MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#issuecomment-587260689
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [17 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
sonarcloud[bot] commented on issue #793: [IOTDB-274] Refactor MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#issuecomment-587446643
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [17 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] jixuan1989 opened a new pull request #823: [IOTDB-309] add Dockerfiles for 0.8.1, 0.9.0, and 0.9.1

2020-02-18 Thread GitBox
jixuan1989 opened a new pull request #823: [IOTDB-309] add Dockerfiles for 
0.8.1, 0.9.0, and 0.9.1
URL: https://github.com/apache/incubator-iotdb/pull/823
 
 
   I add the dockerfiles which can build images on dockerhub/apache/iotdb.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #823: [IOTDB-309] add Dockerfiles for 0.8.1, 0.9.0, and 0.9.1

2020-02-18 Thread GitBox
sonarcloud[bot] commented on issue #823: [IOTDB-309] add Dockerfiles for 0.8.1, 
0.9.0, and 0.9.1
URL: https://github.com/apache/incubator-iotdb/pull/823#issuecomment-587470014
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=CODE_SMELL)
 [0 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=823&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=823)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=823&metric=duplicated_lines_density&view=list)
 No Duplication information
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense opened a new pull request #824: [IOTDB-503] Add checkTimeseriesExists for session

2020-02-18 Thread GitBox
vesense opened a new pull request #824: [IOTDB-503] Add checkTimeseriesExists 
for session
URL: https://github.com/apache/incubator-iotdb/pull/824
 
 
   In most scenarios, we should check whether timeseries already exists before 
creating, otherwise the following exception may be thrown from server:
   
    
   
   > org.apache.iotdb.db.exception.query.QueryProcessException: Timeseries 
[root.sg.d1.s1] already 
existorg.apache.iotdb.db.exception.query.QueryProcessException: Timeseries 
[root.sg.d1.s1] already exist at 
org.apache.iotdb.db.qp.executor.QueryProcessExecutor.createTimeSeries(QueryProcessExecutor.java:552)
 at 
org.apache.iotdb.db.qp.executor.QueryProcessExecutor.processNonQuery(QueryProcessExecutor.java:122)
 at 
org.apache.iotdb.db.service.TSServiceImpl.executeNonQuery(TSServiceImpl.java:1044)
 at 
org.apache.iotdb.db.service.TSServiceImpl.executePlan(TSServiceImpl.java:1387) 
at 
org.apache.iotdb.db.service.TSServiceImpl.createTimeseries(TSServiceImpl.java:1342)
 at 
org.apache.iotdb.service.rpc.thrift.TSIService$Processor$createTimeseries.getResult(TSIService.java:1953)
 at 
org.apache.iotdb.service.rpc.thrift.TSIService$Processor$createTimeseries.getResult(TSIService.java:1933)
 at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:38) at 
org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:38) at 
org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:313)
 at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 
at java.lang.Thread.run(Thread.java:748)
   
    The changes are as following:
   * Added method `checkTimeseriesExists` for `org.apache.iotdb.session.Session`
   * Updated the `SessionExample` 
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] jixuan1989 commented on issue #822: [IOTDB-502] Fix possible NPE in `org.apache.iotdb.db.service.TSServiceImpl`

2020-02-18 Thread GitBox
jixuan1989 commented on issue #822: [IOTDB-502] Fix possible NPE in 
`org.apache.iotdb.db.service.TSServiceImpl`
URL: https://github.com/apache/incubator-iotdb/pull/822#issuecomment-587490819
 
 
   I tried. In this way, the start-client.sh tool will report: 
   ```
   IoTDB> Can not establish connection with jdbc:iotdb://127.0.0.1:6667/. Host 
is 127.0.0.1, port is 6667.
   ```
   
   If we use JDCB like 
   ```
   Connection connection = 
DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root")
   ```
   
then an exception will be thrown:
   ```
   Exception in thread "main" java.sql.SQLException: Can not establish 
connection with jdbc:iotdb://127.0.0.1:6667/.
at 
org.apache.iotdb.jdbc.IoTDBConnection.openSession(IoTDBConnection.java:435)
at org.apache.iotdb.jdbc.IoTDBConnection.(IoTDBConnection.java:84)
at org.apache.iotdb.jdbc.IoTDBDriver.connect(IoTDBDriver.java:63)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at org.apache.iotdb.JDBCExample.main(JDBCExample.java:32)
   Caused by: org.apache.thrift.TApplicationException: getTimeZone failed: 
unknown result
at 
org.apache.iotdb.service.rpc.thrift.TSIService$Client.recv_getTimeZone(TSIService.java:405)
at 
org.apache.iotdb.service.rpc.thrift.TSIService$Client.getTimeZone(TSIService.java:389)
at 
org.apache.iotdb.jdbc.IoTDBConnection.getTimeZone(IoTDBConnection.java:475)
at 
org.apache.iotdb.jdbc.IoTDBConnection.openSession(IoTDBConnection.java:431)
... 5 more
   ```
   
   It is accepted, at least better than the current status.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] jixuan1989 commented on issue #822: [IOTDB-502] Fix possible NPE in `org.apache.iotdb.db.service.TSServiceImpl`

2020-02-18 Thread GitBox
jixuan1989 commented on issue #822: [IOTDB-502] Fix possible NPE in 
`org.apache.iotdb.db.service.TSServiceImpl`
URL: https://github.com/apache/incubator-iotdb/pull/822#issuecomment-587491374
 
 
   One more thing, we need to put "how to detect whether a client is 
compatible" on the agenda.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense commented on issue #817: [IOTDB-497] Apache Flink Connector Support

2020-02-18 Thread GitBox
vesense commented on issue #817: [IOTDB-497] Apache Flink Connector Support
URL: https://github.com/apache/incubator-iotdb/pull/817#issuecomment-587491834
 
 
   I will update the PR after 
https://github.com/apache/incubator-iotdb/pull/824 getting merged, to add 
timeseries checks like this:
   
   ```
   for (String path : options.getTimeseries()) {
   if (!session.checkTimeseriesExists(path)) {
   session.createTimeseries(path, TSDataType.TEXT, 
TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
   }
   }
   
   ```


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense commented on issue #822: [IOTDB-502] Fix possible NPE in `org.apache.iotdb.db.service.TSServiceImpl`

2020-02-18 Thread GitBox
vesense commented on issue #822: [IOTDB-502] Fix possible NPE in 
`org.apache.iotdb.db.service.TSServiceImpl`
URL: https://github.com/apache/incubator-iotdb/pull/822#issuecomment-587494625
 
 
   @jixuan1989 You're right. I also found some other compatibility errors.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] jixuan1989 commented on issue #817: [IOTDB-497] Apache Flink Connector Support

2020-02-18 Thread GitBox
jixuan1989 commented on issue #817: [IOTDB-497] Apache Flink Connector Support
URL: https://github.com/apache/incubator-iotdb/pull/817#issuecomment-587495426
 
 
   > I will update the PR after #824 getting merged, to add timeseries checks 
like this:
   > 
   > ```
   > for (String path : options.getTimeseries()) {
   > if (!session.checkTimeseriesExists(path)) {
   > session.createTimeseries(path, TSDataType.TEXT, 
TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
   > }
   > }
   > ```
   
   Hi, adding a check is ok. 
   
   I just want to point out that from  v0.9.* on, IoTDB supports create 
timeseries automatically. 
   Which means you can directly write "insert into..."
   
   Two things that we need to know if we want to use the feature:
   
   1. You need to modify the configuration file to claim which level of a path 
is the "storage group". It is 2 by default, which means if you write data into 
"root.a.b.c.e", then "root.a" is the storage group. Or, you can use 
`session.setStorageGroup()` to create a SG manually and then create timeseries 
automatically.
   
   2. If automatically creating time series is enabled, then the data type is 
inferred by the first data points of a time series. e.g., if the first data is 
an integer, then it is long; if the first data is a float, then it is double, 
otherwise, it is TEXT.
 
   
   
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense commented on issue #822: [IOTDB-502] Fix possible NPE in `org.apache.iotdb.db.service.TSServiceImpl`

2020-02-18 Thread GitBox
vesense commented on issue #822: [IOTDB-502] Fix possible NPE in 
`org.apache.iotdb.db.service.TSServiceImpl`
URL: https://github.com/apache/incubator-iotdb/pull/822#issuecomment-587495697
 
 
   We should pay attention to the compatibility. Otherwise, it will cause big 
trouble to users.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] jixuan1989 commented on a change in pull request #817: [IOTDB-497] Apache Flink Connector Support

2020-02-18 Thread GitBox
jixuan1989 commented on a change in pull request #817: [IOTDB-497] Apache Flink 
Connector Support
URL: https://github.com/apache/incubator-iotdb/pull/817#discussion_r380720981
 
 

 ##
 File path: 
flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java
 ##
 @@ -0,0 +1,155 @@
+/*
+ * 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.iotdb.flink;
+
+import com.google.common.collect.Lists;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.state.FunctionInitializationContext;
+import org.apache.flink.runtime.state.FunctionSnapshotContext;
+import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;
+import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
+import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
+import org.apache.iotdb.service.rpc.thrift.TSStatus;
+import org.apache.iotdb.session.Session;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+public class IoTDBSink extends RichSinkFunction implements 
CheckpointedFunction {
+
+private static final long serialVersionUID = 1L;
+private static final Logger LOG = LoggerFactory.getLogger(IoTDBSink.class);
+
+private IoTSerializationSchema serializationSchema;
+private IoTDBOptions options;
+private transient Session session;
+
+private boolean batchFlushOnCheckpoint; // false by default
+private int batchSize = 100;
+private List batchList;
+
+public IoTDBSink(IoTDBOptions options, IoTSerializationSchema schema) {
+this.options = options;
+this.serializationSchema = schema;
+}
+
+@Override
+public void open(Configuration parameters) throws Exception {
+batchList = new LinkedList<>();
+
+session = new Session(options.getHost(), options.getPort(), 
options.getUser(), options.getPassword());
+session.open();
+
+session.setStorageGroup(options.getStorageGroup());
+for (String sensor : options.getTimeseries()) {
+session.createTimeseries(sensor, TSDataType.TEXT, 
TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
 
 Review comment:
   Hi, is that possible to get the datatype of the sensor?
   As IoTDB compresses int/long/float/double better than text, and in some 
applications, users know what data type their data is.
   
   By the way, it is recommended that using CompressionType.SNAPPY by default.  
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense commented on issue #817: [IOTDB-497] Apache Flink Connector Support

2020-02-18 Thread GitBox
vesense commented on issue #817: [IOTDB-497] Apache Flink Connector Support
URL: https://github.com/apache/incubator-iotdb/pull/817#issuecomment-587499682
 
 
   In most of our actual scenarios, automatic creation will not be enabled, 
such as Kafka's topic, because it is not conducive to control, but also may 
bring some risks.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense commented on a change in pull request #817: [IOTDB-497] Apache Flink Connector Support

2020-02-18 Thread GitBox
vesense commented on a change in pull request #817: [IOTDB-497] Apache Flink 
Connector Support
URL: https://github.com/apache/incubator-iotdb/pull/817#discussion_r380725257
 
 

 ##
 File path: 
flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java
 ##
 @@ -0,0 +1,155 @@
+/*
+ * 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.iotdb.flink;
+
+import com.google.common.collect.Lists;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.state.FunctionInitializationContext;
+import org.apache.flink.runtime.state.FunctionSnapshotContext;
+import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;
+import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
+import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
+import org.apache.iotdb.service.rpc.thrift.TSStatus;
+import org.apache.iotdb.session.Session;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+public class IoTDBSink extends RichSinkFunction implements 
CheckpointedFunction {
+
+private static final long serialVersionUID = 1L;
+private static final Logger LOG = LoggerFactory.getLogger(IoTDBSink.class);
+
+private IoTSerializationSchema serializationSchema;
+private IoTDBOptions options;
+private transient Session session;
+
+private boolean batchFlushOnCheckpoint; // false by default
+private int batchSize = 100;
+private List batchList;
+
+public IoTDBSink(IoTDBOptions options, IoTSerializationSchema schema) {
+this.options = options;
+this.serializationSchema = schema;
+}
+
+@Override
+public void open(Configuration parameters) throws Exception {
+batchList = new LinkedList<>();
+
+session = new Session(options.getHost(), options.getPort(), 
options.getUser(), options.getPassword());
+session.open();
+
+session.setStorageGroup(options.getStorageGroup());
+for (String sensor : options.getTimeseries()) {
+session.createTimeseries(sensor, TSDataType.TEXT, 
TSEncoding.PLAIN, CompressionType.UNCOMPRESSED);
 
 Review comment:
   Good idea, I will update later.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] jixuan1989 commented on a change in pull request #817: [IOTDB-497] Apache Flink Connector Support

2020-02-18 Thread GitBox
jixuan1989 commented on a change in pull request #817: [IOTDB-497] Apache Flink 
Connector Support
URL: https://github.com/apache/incubator-iotdb/pull/817#discussion_r380725643
 
 

 ##
 File path: 
flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/Event.java
 ##
 @@ -0,0 +1,49 @@
+/*
+ * 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.iotdb.flink;
+
+public class Event {
+private String device;
+private Long timestamp;
+private String measurement;
 
 Review comment:
   In many applications, when a monitored device sends data to the server, it 
does not just send one data point. 
   Instead, it sends a "row", i.e., several measurements and their values. (And 
in some applications, they even sends data with several timestamps, but it is 
not very common.) 
   As far as I know, a device may have more than 100 measurements in the 
industrial applications. In this case, splitting a "row" into many Events may 
burden Flink as well as IoTDB (because there are too many small TCP packets).
   
   How do you think?
   



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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] jixuan1989 commented on a change in pull request #824: [IOTDB-503] Add checkTimeseriesExists for session

2020-02-18 Thread GitBox
jixuan1989 commented on a change in pull request #824: [IOTDB-503] Add 
checkTimeseriesExists for session
URL: https://github.com/apache/incubator-iotdb/pull/824#discussion_r380730096
 
 

 ##
 File path: session/src/main/java/org/apache/iotdb/session/Session.java
 ##
 @@ -558,6 +558,15 @@ public TSStatus createTimeseries(String path, TSDataType 
dataType,
 }
   }
 
+  public boolean checkTimeseriesExists(String path) throws 
IoTDBSessionException {
+checkPathValidity(path);
+try {
+  return executeQueryStatement(String.format("SHOW TIMESERIES %s", 
path)).hasNext();
 
 Review comment:
   This is an interesting usage and it works...
   
   Do we need to add an RPC interface for checking whether a time series exist? 


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense commented on a change in pull request #817: [IOTDB-497] Apache Flink Connector Support

2020-02-18 Thread GitBox
vesense commented on a change in pull request #817: [IOTDB-497] Apache Flink 
Connector Support
URL: https://github.com/apache/incubator-iotdb/pull/817#discussion_r380733819
 
 

 ##
 File path: 
flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/Event.java
 ##
 @@ -0,0 +1,49 @@
+/*
+ * 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.iotdb.flink;
+
+public class Event {
+private String device;
+private Long timestamp;
+private String measurement;
 
 Review comment:
   Make sense. We should support most scenarios. Will update. 
   @jixuan1989 Thanks for your input.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] vesense commented on a change in pull request #824: [IOTDB-503] Add checkTimeseriesExists for session

2020-02-18 Thread GitBox
vesense commented on a change in pull request #824: [IOTDB-503] Add 
checkTimeseriesExists for session
URL: https://github.com/apache/incubator-iotdb/pull/824#discussion_r380739860
 
 

 ##
 File path: session/src/main/java/org/apache/iotdb/session/Session.java
 ##
 @@ -558,6 +558,15 @@ public TSStatus createTimeseries(String path, TSDataType 
dataType,
 }
   }
 
+  public boolean checkTimeseriesExists(String path) throws 
IoTDBSessionException {
+checkPathValidity(path);
+try {
+  return executeQueryStatement(String.format("SHOW TIMESERIES %s", 
path)).hasNext();
 
 Review comment:
   I think this is enough at present(as a tool method). If there are other 
inputting scenes later, we can file another PR to do that.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380796485
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/physical/crud/BatchInsertPlan.java
 ##
 @@ -288,6 +292,23 @@ public long getMaxTime() {
 return maxTime;
   }
 
+  public void updateMNodeLastValues(MNode node) {
+long maxTime = Long.MIN_VALUE;
+int maxIndex = 0;
+for (int i = 0; i < times.length; i++) {
+  if (times[i] > maxTime) {
+maxTime = times[i];
+maxIndex = i;
+  }
+}
+for (int i = 0; i < measurements.length; i++) {
+  if (node.hasChild(measurements[i])) {
+Object[] column = (Object[]) columns[i];
+node.getChild(measurements[i]).updateCachedLast(maxTime, 
column[maxIndex], dataTypes[i]);
+  }
+}
+  }
+
 
 Review comment:
   Agree. Moved it out of InsertPlan


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380796650
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java
 ##
 @@ -185,4 +190,13 @@ public void deserializeFrom(ByteBuffer buffer) {
   public String toString() {
 return "deviceId: " + deviceId + ", time: " + time;
   }
+
+  public void updateMNodeLastValues(MNode node) throws QueryProcessException {
+for (int i = 0; i < measurements.length; i++) {
+  if (node.hasChild(measurements[i])) {
+Object value = CommonUtils.parseValue(dataTypes[i], values[i]);
+node.getChild(measurements[i]).updateCachedLast(time, value, 
dataTypes[i]);
+  }
+}
+  }
 
 Review comment:
   Fixed


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380815684
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
 ##
 @@ -0,0 +1,201 @@
+/*
+ * 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.iotdb.db.query.executor;
+
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.exception.path.PathException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.db.metadata.MNode;
+import org.apache.iotdb.db.qp.constant.SQLConstant;
+import org.apache.iotdb.db.qp.physical.crud.AggregationPlan;
+import org.apache.iotdb.db.qp.physical.crud.LastQueryPlan;
+import org.apache.iotdb.db.query.aggregation.AggregateResult;
+import org.apache.iotdb.db.query.context.QueryContext;
+import org.apache.iotdb.db.query.control.QueryResourceManager;
+import org.apache.iotdb.db.query.dataset.SingleDataSet;
+import org.apache.iotdb.db.query.factory.AggreResultFactory;
+import org.apache.iotdb.db.query.reader.series.IAggregateReader;
+import org.apache.iotdb.db.query.reader.series.SeriesAggregateReader;
+import org.apache.iotdb.tsfile.exception.cache.CacheException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.read.filter.basic.Filter;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
+import org.apache.iotdb.tsfile.utils.TsPrimitiveType;
+import org.omg.CORBA.TIMEOUT;
+
+import java.io.IOException;
+import java.sql.Time;
+import java.util.*;
+
+public class LastQueryExecutor {
+private List selectedSeries;
+private List dataTypes;
+
+public LastQueryExecutor(LastQueryPlan lastQueryPlan) {
+this.selectedSeries = lastQueryPlan.getPaths();
+this.dataTypes = lastQueryPlan.getDataTypes();
+}
+
+/**
+ * execute last function
+ *
+ * @param context query context
+ */
+public QueryDataSet execute(QueryContext context)
+throws StorageEngineException, IOException, QueryProcessException {
+
+List lastQueryResultList = new ArrayList<>();
+for (int i = 0; i < selectedSeries.size(); i++) {
+LastQueryResult lastQueryResult = 
calculateLastPairForOneSeries(selectedSeries.get(i), dataTypes.get(i), context);
+lastQueryResultList.add(lastQueryResult);
+}
+
+RowRecord resultRecord = constructLastRowRecord(lastQueryResultList);
+SingleDataSet dataSet = new SingleDataSet(selectedSeries, dataTypes);
+dataSet.setRecord(resultRecord);
+return dataSet;
+}
+
+/**
+ * get aggregation result for one series
+ *
+ * @param context query context
+ * @return AggregateResult list
+ */
+private LastQueryResult calculateLastPairForOneSeries(
+Path seriesPath, TSDataType tsDataType,
+QueryContext context)
+throws IOException, QueryProcessException, StorageEngineException {
+LastQueryResult queryResult = new LastQueryResult();
+MNode node = null;
+try {
+node = 
MManager.getInstance().getNodeByPathFromCache(seriesPath.toString());
+} catch (PathException e) {
+throw new QueryProcessException(e);
+} catch (CacheException e) {
+throw new QueryProcessException(e.getMessage());
+}
+if (node.getCachedLast() != null) {
+queryResult.setPairResult(node.getCachedLast());
+return queryResult;
+}
+
+// construct series reader without value filter
+Filter timeFilter = null;
+IAggregateReader seriesReader = new SeriesAggregateReader(
+seriesPath, tsDataType, context, 
QueryResourceManager.getInstance()
+ 

[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380821805
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
 ##
 @@ -680,6 +674,7 @@ public void insert(InsertPlan insertPlan) throws 
QueryProcessException {
   }
   insertPlan.setDataTypes(dataTypes);
   storageEngine.insert(insertPlan);
+  insertPlan.updateMNodeLastValues(node);
 
 Review comment:
   The update function is moved into MNode structure.
   I added a loop to update the last value after storageEngine.insert() 
instead, since it is possible that insert() could fail and throw exceptions. In 
such case the last value cache should not be updated.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
wshao08 commented on a change in pull request #821: [IOTDB-298]Last time-value 
query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r380821805
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
 ##
 @@ -680,6 +674,7 @@ public void insert(InsertPlan insertPlan) throws 
QueryProcessException {
   }
   insertPlan.setDataTypes(dataTypes);
   storageEngine.insert(insertPlan);
+  insertPlan.updateMNodeLastValues(node);
 
 Review comment:
   The update function is moved into MNode structure.
   I added a loop to update the last value after storageEngine.insert(). It is 
possible that insert() could fail and throw exceptions. In such case the last 
value cache will not be updated.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381033163
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole ser

[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381035223
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole ser

[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381035443
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole ser

[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r381024249
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
 ##
 @@ -680,6 +683,10 @@ public void insert(InsertPlan insertPlan) throws 
QueryProcessException {
   }
   insertPlan.setDataTypes(dataTypes);
   storageEngine.insert(insertPlan);
+  for (int i = 0; i < measurementList.length; i++) {
+MNode measurementNode = node.getChild(measurementList[i]);
+measurementNode.updateCachedLast(insertPlan.composeTimeValuePair(i));
+  }
 
 Review comment:
   Why not combine this loop with the before one.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r381032153
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
 ##
 @@ -772,8 +779,12 @@ private void checkPathExists(MNode node, String fullPath, 
MeasurementSchema sche
   measurementNode.getSchema().getType()));
 }
   }
-  return storageEngine.insertBatch(batchInsertPlan);
-
+  Integer[] results = storageEngine.insertBatch(batchInsertPlan);
+  for (int i = 0; i < measurementList.length; i++) {
+MNode measurementNode = node.getChild(measurementList[i]);
+
measurementNode.updateCachedLast(batchInsertPlan.composeLastTimeValuePair(i));
+  }
 
 Review comment:
   same as before.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last time-value query

2020-02-18 Thread GitBox
JackieTien97 commented on a change in pull request #821: [IOTDB-298]Last 
time-value query
URL: https://github.com/apache/incubator-iotdb/pull/821#discussion_r381034539
 
 

 ##
 File path: 
server/src/main/java/org/apache/iotdb/db/qp/physical/crud/BatchInsertPlan.java
 ##
 @@ -288,6 +291,19 @@ public long getMaxTime() {
 return maxTime;
   }
 
+  public TimeValuePair composeLastTimeValuePair(int measurementIndex) {
+long maxTime = Long.MIN_VALUE;
+int maxIndex = 0;
+for (int i = 0; i < times.length; i++) {
+  if (times[i] > maxTime) {
+maxTime = times[i];
+maxIndex = i;
+  }
+}
 
 Review comment:
   No matter what measurementIndex is, this calculation process is the same. It 
only needs to be called once.
   You can extract that method outside the the calling loop.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381036974
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
 
 Review comment:
   Moved.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381038901
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
 
 Review comment:
   An internal node may also need this method. For example, the fullpath of 
node `sg1` is `root.sg1`, and this could be used for setting storage group.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381043895
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##
 @@ -50,131 +56,111 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
-
-  MTree(String rootName) {
-this.root = new MNode(rootName, null, false);
-  }
-
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
+   * dummy node is used for the default param of traverse methods
*/
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-  CompressionType compressor, Map props) throws 
PathException {
-String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
-if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", timeseriesPath);
-}
-MNode cur = findLeafParent(nodeNames);
-String levelPath = cur.getDataFileName();
+  private MNode dummyNode;
 
-MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
-if (props != null && !props.isEmpty()) {
-  leaf.getSchema().setProps(props);
-}
-leaf.setDataFileName(levelPath);
-if (cur.isLeaf()) {
-  throw new MTreePathException(timeseriesPath, "can't be created",
-  String.format("node [%s] is left node", cur.getName()));
-}
-cur.addChild(nodeNames[nodeNames.length - 1], leaf);
+  MTree(String rootName) {
+this.root = new InternalMNode(rootName, null);
+this.dummyNode = new InternalMNode("dummy", null);
   }
 
   /**
-   * function for adding deviceId
-   */
-  MNode addDeviceId(String deviceId) throws PathException {
-String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+   * Add path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+  CompressionType compressor, Map props) throws 
MetadataException {
+String[] nodeNames = MetaUtils.getNodeNames(path);
 if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-  throw new MTreePathException("Timeseries", deviceId);
-}
-MNode cur = getRoot();
-for (int i = 1; i < nodeNames.length; i++) {
-  if (!cur.hasChild(nodeNames[i])) {
-cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
-  }
-  cur = cur.getChild(nodeNames[i]);
+  throw new IllegalPathException(path);
 }
-return cur;
-  }
-
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
 MNode cur = root;
-String levelPath = null;
+String storageGroupName = null;
 int i = 1;
 while (i < nodeNames.length - 1) {
   String nodeName = nodeNames[i];
-  if (cur.isStorageGroup()) {
-levelPath = cur.getDataFileName();
+  if (cur.isNodeType(MNodeType.STORAGE_GROUP_MNODE)) {
+storageGroupName = cur.getStorageGroupName();
   }
-  if (!cur.hasChild(nodeName)) {
-if (cur.isLeaf()) {
-  throw new MTreePathException(String.join(",", nodeNames), "can't be 
created",
-  String.format("node [%s] is left node", cur.getName()));
+  if (!cur.hasChildWithKey(nodeName)) {
+if (cur.isNodeType(MNodeType.LEAF_MNODE)) {
+  throw new PathAlreadyExistException(cur.getFullPath());
 }
-cur.addChild(nodeName, new MNode(nodeName, cur, false));
+cur.addChild(nodeName, new InternalMNode(nodeName, cur));
   }
-  cur.setDataFileName(levelPath);
+  cur.setStorageGroupName(storageGroupName);
   cur = cur.getChild(nodeName);
-  if (levelPath == null) {
-levelPath = cur.getDataFileName();
+  if (storageGroupName == null) {
+storageGroupName = cur.getStorageGroupName();
   }
   i++;
 }
-cur.setDataFileName(levelPath);
-return cur;
+cur.setStorageGroupName(storageGroupName);
+MNode leaf = new LeafMNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding,
+compressor);
+leaf.getSchema().setProps(props);
+leaf.setStorageGroupName(cur.getStorageGroupName());
+cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
-
   /**
-   * function for checking whether the given path exists.
+   * Add path to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
*
-   * @param path -seriesPath not necessarily the whole ser

[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381044232
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
+
+  /**
+   * Constructor of MNode.
+   */
+  public MNode(String name, MNode parent) {
+this.setName(name);
+this.parent = parent;
+  }
+
+  abstract public boolean isNodeType(MNodeType nodeType);
+
+  /**
+   * Set storage group
+   */
+  public void setStorageGroup() {
+nodeType = MNodeType.STORAGE_GROUP_MNODE;
+schemaMap = new HashMap<>();
+  }
+
+  public Map getSchemaMap() {
+return schemaMap;
+  }
+
+  /**
+   * check whether the MNode has children
+   */
+  abstract public boolean hasChildren();
+
+  /**
+   * check whether the MNode has child with the given key
+   *
+   * @param key key
+   */
+  abstract public boolean hasChildWithKey(String key);
+
+  /**
+   * add the given key to given child MNode
+   *
+   * @param key key
+   * @param child child MNode
+   */
+  abstract public void addChild(String key, MNode child);
+
+  /**
+   * delete key from given child MNode
+   *
+   * @param key key
+   */
+  abstract public void deleteChild(String key);
+
+  /**
+   * get the child MNode under the given key.
+   *
+   * @param key key
+   */
+  abstract public MNode getChild(String key);
+
+  /**
+   * get the count of all leaves whose ancestor is current node
+   */
+  abstract public int getLeafCount();
+
+  /**
+   * get full path
+   */
+  public String getFullPath() {
+if (fullPath != null) {
+  return fullPath;
+}
+StringBuilder builder = new StringBuilder(name);
+MNode curr = this;
+while (curr.parent != null) {
+  curr = curr.parent;
+  builder.insert(0, IoTDBConstant.PATH_SEPARATOR).insert(0, curr.name);
+}
+return fullPath = builder.toString();
+  }
+
+  public String getStorageGroupName() {
+return storageGroupName;
+  }
+
+  public void setStorageGroupName(String storageGroupName) {
+this.storageGroupName = storageGroupName;
+  }
+
+  @Override
+  public String toString() {
+return this.getName();
+  }
+
+  public MeasurementSchema getSchema() {
+return schema;
+  }
+
+  public MNode getParent() {
+return parent;
+  }
+
+  abstract public Map getChildren();
+
+  public String getName() {
+return name;
+  }
+
+  public void setName(String name) {
+this.name = name;
+  }
+
+  public long getDataTTL() {
+return dataTTL;
+  }
+
+  public void setDataTTL(long dataTTL) {
 
 Review comment:
   Moved.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.ap

[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381044690
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
 
 Review comment:
   Moved.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381054275
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
+
+  /**
+   * Constructor of MNode.
+   */
+  public MNode(String name, MNode parent) {
+this.setName(name);
+this.parent = parent;
+  }
+
+  abstract public boolean isNodeType(MNodeType nodeType);
 
 Review comment:
   Removed.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381054364
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
+
+  /**
+   * Corresponding storage group name for current node
+   */
+  private String storageGroupName;
+
+  private MNode parent;
+
+  private String fullPath;
+
+  /**
+   * Column's Schema for one timeseries represented by current node if current 
node is one leaf
+   */
+  MeasurementSchema schema;
+
+  Map children;
+
+  MNodeType nodeType;
+
+  /**
+   * when the data in a storage group is older than dataTTL, it is considered 
invalid and will be
+   * eventually removed. only set at storage group level.
+   */
+  private long dataTTL = Long.MAX_VALUE;
+
+  /**
+   * Constructor of MNode.
+   */
+  public MNode(String name, MNode parent) {
+this.setName(name);
+this.parent = parent;
+  }
+
+  abstract public boolean isNodeType(MNodeType nodeType);
+
+  /**
+   * Set storage group
+   */
+  public void setStorageGroup() {
+nodeType = MNodeType.STORAGE_GROUP_MNODE;
 
 Review comment:
   If it is used in the future, I'd like to add it back.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
samperson1997 commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r381054383
 
 

 ##
 File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
 ##
 @@ -0,0 +1,184 @@
+/*
+ * 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.iotdb.db.metadata.mnode;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+/**
+ * This class is the implementation of Metadata Node. One MNode instance 
represents one node in the
+ * Metadata Tree
+ */
+public abstract class MNode implements Serializable {
+
+  private static final long serialVersionUID = -770028375899514063L;
+
+  /**
+   * Name of the MNode
+   */
+  private String name;
+
+  /**
+   * Map for the schema in this storage group
+   */
+  private Map schemaMap;
 
 Review comment:
   Moved.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
sonarcloud[bot] commented on issue #793: [IOTDB-274] Refactor MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#issuecomment-588013803
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
sonarcloud[bot] removed a comment on issue #793: [IOTDB-274] Refactor MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#issuecomment-587446643
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [17 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] commented on issue #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
sonarcloud[bot] commented on issue #793: [IOTDB-274] Refactor MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#issuecomment-588044595
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [6 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on issue #793: [IOTDB-274] Refactor MManager

2020-02-18 Thread GitBox
sonarcloud[bot] removed a comment on issue #793: [IOTDB-274] Refactor MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#issuecomment-588013803
 
 
   Kudos, SonarCloud Quality Gate passed!
   
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
 [0 
Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=BUG)
  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 [0 
Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=VULNERABILITY)
 (and [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 [0 Security 
Hotspots](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=SECURITY_HOTSPOT)
 to review)  
   [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
 [11 Code 
Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=793&resolved=false&types=CODE_SMELL)
   
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793)
 No Coverage information  
   [](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
 [0.0% 
Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=793&metric=new_duplicated_lines_density&view=list)
   
   


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services