This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 20be40b [IOTDB-633]Update Session.java : Fix sort bug (#1141)
20be40b is described below
commit 20be40b7b0a8f1081b00ef7bdf59b1ec2bfd127b
Author: iiint <[email protected]>
AuthorDate: Sat May 2 21:54:28 2020 +0800
[IOTDB-633]Update Session.java : Fix sort bug (#1141)
* Update Session.java : fix sort bug
---
.../java/org/apache/iotdb/session/Session.java | 12 +--
.../java/org/apache/iotdb/session/SessionUT.java | 90 ++++++++++++++++++++++
2 files changed, 96 insertions(+), 6 deletions(-)
diff --git a/session/src/main/java/org/apache/iotdb/session/Session.java
b/session/src/main/java/org/apache/iotdb/session/Session.java
index 0407093..20dd400 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -718,42 +718,42 @@ public class Session {
boolean[] boolValues = (boolean[]) valueList;
boolean[] sortedValues = new boolean[boolValues.length];
for (int i = 0; i < index.length; i++) {
- sortedValues[index[i]] = boolValues[i];
+ sortedValues[i] = boolValues[index[i]];
}
return sortedValues;
case INT32:
int[] intValues = (int[]) valueList;
int[] sortedIntValues = new int[intValues.length];
for (int i = 0; i < index.length; i++) {
- sortedIntValues[index[i]] = intValues[i];
+ sortedIntValues[i] = intValues[index[i]];
}
return sortedIntValues;
case INT64:
long[] longValues = (long[]) valueList;
long[] sortedLongValues = new long[longValues.length];
for (int i = 0; i < index.length; i++) {
- sortedLongValues[index[i]] = longValues[i];
+ sortedLongValues[i] = longValues[index[i]];
}
return sortedLongValues;
case FLOAT:
float[] floatValues = (float[]) valueList;
float[] sortedFloatValues = new float[floatValues.length];
for (int i = 0; i < index.length; i++) {
- sortedFloatValues[index[i]] = floatValues[i];
+ sortedFloatValues[i] = floatValues[index[i]];
}
return sortedFloatValues;
case DOUBLE:
double[] doubleValues = (double[]) valueList;
double[] sortedDoubleValues = new double[doubleValues.length];
for (int i = 0; i < index.length; i++) {
- sortedDoubleValues[index[i]] = doubleValues[i];
+ sortedDoubleValues[i] = doubleValues[index[i]];
}
return sortedDoubleValues;
case TEXT:
Binary[] binaryValues = (Binary[]) valueList;
Binary[] sortedBinaryValues = new Binary[binaryValues.length];
for (int i = 0; i < index.length; i++) {
- sortedBinaryValues[index[i]] = binaryValues[i];
+ sortedBinaryValues[i] = binaryValues[index[i]];
}
return sortedBinaryValues;
default:
diff --git a/session/src/test/java/org/apache/iotdb/session/SessionUT.java
b/session/src/test/java/org/apache/iotdb/session/SessionUT.java
new file mode 100644
index 0000000..3f3c50e
--- /dev/null
+++ b/session/src/test/java/org/apache/iotdb/session/SessionUT.java
@@ -0,0 +1,90 @@
+/*
+ * 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.session;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+import org.junit.Test;
+
+public class SessionUT {
+
+ @Test
+ public void testSortTablet() {
+ /*
+ To test sortTablet in Class Session
+ !!!
+ Before testing, change the sortTablet from private method to public
method
+ !!!
+ */
+ Session session = new Session("127.0.0.1", 6667, "root", "root");
+ List<MeasurementSchema> schemaList = new ArrayList<>();
+ schemaList.add(new MeasurementSchema("s1",TSDataType.INT64,
TSEncoding.RLE));
+ // insert three rows data
+ Tablet tablet = new Tablet("root.sg1.d1", schemaList, 3);
+ long[] timestamps = tablet.timestamps;
+ Object[] values = tablet.values;
+
+ /*
+ inorder data before inserting
+ timestamp s1
+ 2 0
+ 0 1
+ 1 2
+ */
+ // inorder timestamps
+ timestamps[0] = 2;
+ timestamps[1] = 0;
+ timestamps[2] = 1;
+ // just one column INT64 data
+ long[] sensor = (long[]) values[0];
+ sensor[0] = 0;
+ sensor[1] = 1;
+ sensor[2] = 2;
+ tablet.rowSize = 3;
+
+ /*
+ After sorting, if the tablet data is sorted according to the
timestamps,
+ data in tablet will be
+ timestamp s1
+ 0 1
+ 1 2
+ 2 0
+
+ If the data equal to above tablet, test pass, otherwise test fialed
+ */
+ long[] resTimestamps = tablet.timestamps;
+ long[] resValues = (long[])tablet.values[0];
+ long[] expectedTimestamps = new long[]{0, 1, 2};
+ long[] expectedValues = new long[]{1,2,0};
+ try {
+ assertArrayEquals(expectedTimestamps, resTimestamps);
+ assertArrayEquals(expectedValues, resValues);
+ }
+ catch (Exception e) {
+ fail();
+ }
+ }
+}