You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2019/06/27 08:06:42 UTC
[incubator-iotdb] branch feature_async_close_tsfile updated: fix
sort in TVList
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch feature_async_close_tsfile
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/feature_async_close_tsfile by this push:
new 98dc4e0 fix sort in TVList
new 616362b Merge branch 'feature_async_close_tsfile' of github.com:apache/incubator-iotdb into feature_async_close_tsfile
98dc4e0 is described below
commit 98dc4e0bb3b987edf55adae03766ed4145f2faa0
Author: 江天 <jt...@163.com>
AuthorDate: Thu Jun 27 16:03:59 2019 +0800
fix sort in TVList
---
.../db/engine/memtable/WritableMemChunkV2.java | 151 +++++++++++++++++++++
.../iotdb/db/utils/datastructure/LongTVList.java | 8 +-
.../iotdb/db/utils/datastructure/TVList.java | 10 +-
3 files changed, 157 insertions(+), 12 deletions(-)
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/engine/memtable/WritableMemChunkV2.java b/iotdb/src/main/java/org/apache/iotdb/db/engine/memtable/WritableMemChunkV2.java
new file mode 100644
index 0000000..917515e
--- /dev/null
+++ b/iotdb/src/main/java/org/apache/iotdb/db/engine/memtable/WritableMemChunkV2.java
@@ -0,0 +1,151 @@
+/**
+ * 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.engine.memtable;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.iotdb.db.utils.PrimitiveArrayListV2;
+import org.apache.iotdb.db.utils.PrimitiveDataListPool;
+import org.apache.iotdb.db.utils.TimeValuePair;
+import org.apache.iotdb.db.utils.TsPrimitiveType;
+import org.apache.iotdb.db.utils.datastructure.LongTVList;
+import org.apache.iotdb.db.utils.datastructure.TVList;
+import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Binary;
+
+public class WritableMemChunkV2 {
+
+ private TSDataType dataType;
+ private TVList list;
+ private long timeOffset = 0;
+
+ public WritableMemChunkV2(TSDataType dataType) {
+ this.dataType = dataType;
+ this.list = getTVList(dataType);
+ }
+
+ public TVList getTVList(TSDataType dataType) {
+ switch (dataType) {
+ case BOOLEAN:
+ return null;
+ case INT32:
+ return null;
+ case INT64:
+ return new LongTVList();
+ case FLOAT:
+ return null;
+ case DOUBLE:
+ return null;
+ case TEXT:
+ return null;
+ default:
+ throw new UnSupportedDataTypeException("DataType: " + dataType);
+ }
+ }
+
+ public void write(long insertTime, String insertValue) {
+ switch (dataType) {
+ case BOOLEAN:
+ putBoolean(insertTime, Boolean.valueOf(insertValue));
+ break;
+ case INT32:
+ putInt(insertTime, Integer.valueOf(insertValue));
+ break;
+ case INT64:
+ putLong(insertTime, Long.valueOf(insertValue));
+ break;
+ case FLOAT:
+ putFloat(insertTime, Float.valueOf(insertValue));
+ break;
+ case DOUBLE:
+ putDouble(insertTime, Double.valueOf(insertValue));
+ break;
+ case TEXT:
+ putBinary(insertTime, Binary.valueOf(insertValue));
+ break;
+ default:
+ throw new UnSupportedDataTypeException("Unsupported data type:" + dataType);
+ }
+ }
+
+ public void write(long insertTime, Object value) {
+ switch (dataType) {
+ case BOOLEAN:
+ putBoolean(insertTime, (Boolean)value);
+ break;
+ case INT32:
+ putInt(insertTime, (Integer)value);
+ break;
+ case INT64:
+ putLong(insertTime, (Long)value);
+ break;
+ case FLOAT:
+ putFloat(insertTime, (Float)value);
+ break;
+ case DOUBLE:
+ putDouble(insertTime, (Double)value);
+ break;
+ case TEXT:
+ putBinary(insertTime, (Binary)value);
+ break;
+ default:
+ throw new UnSupportedDataTypeException("Unsupported data type:" + dataType);
+ }
+ }
+
+ public void putLong(long t, long v) {
+ list.putLong(t, v);
+ }
+
+ public void putInt(long t, int v) {
+ list.putInt(t, v);
+ }
+
+ public void putFloat(long t, float v) {
+ list.putFloat(t, v);
+ }
+
+ public void putDouble(long t, double v) {
+ list.putDouble(t, v);
+ }
+
+ public void putBinary(long t, Binary v) {
+ list.putBinary(t, v);
+ }
+
+ public void putBoolean(long t, boolean v) {
+ list.putBoolean(t, v);
+ }
+
+ public TSDataType getType() {
+ return dataType;
+ }
+
+ public void setTimeOffset(long offset) {
+ timeOffset = offset;
+ }
+
+ public TVList getSortedList() {
+ list.sort();
+ return list;
+ }
+}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
index 1fbcd07..64b10bf 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
@@ -106,6 +106,9 @@ public class LongTVList extends TVList {
sortedTimestamps = new long[size];
sortedValues = new long[size];
sort(0, size);
+ sorted = true;
+ values = null;
+ timestamps = null;
}
protected void merge(int lo, int mid, int hi) {
@@ -167,11 +170,6 @@ public class LongTVList extends TVList {
}
}
- @Override
- protected void cleanAfterSort() {
- values = null;
- }
-
private void set(int src, int dest) {
long srcT = getTime(src);
long srcV = getLong(src);
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
index 2d85fb0..6192058 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.utils.datastructure;
import java.util.ArrayList;
import java.util.List;
+import org.apache.iotdb.tsfile.utils.Binary;
public abstract class TVList {
@@ -71,7 +72,7 @@ public abstract class TVList {
throw new UnsupportedOperationException("DataType not consistent");
}
- public void putString(long time, String value) {
+ public void putBinary(long time, Binary value) {
throw new UnsupportedOperationException("DataType not consistent");
}
@@ -95,7 +96,7 @@ public abstract class TVList {
throw new UnsupportedOperationException("DataType not consistent");
}
- public String getString(int index) {
+ public Binary getBinary(int index) {
throw new UnsupportedOperationException("DataType not consistent");
}
@@ -109,8 +110,6 @@ public abstract class TVList {
protected abstract void merge(int lo, int mid, int hi);
- protected abstract void cleanAfterSort();
-
protected abstract void reverseRange(int lo, int hi);
protected long[] cloneTime(long[] array) {
@@ -129,9 +128,6 @@ public abstract class TVList {
sort(lo, mid);
sort(mid, hi);
merge(lo, mid, hi);
- sorted = true;
- cleanAfterSort();
- timestamps = null;
}
protected int countRunAndMakeAscending(int lo, int hi) {