You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/07/22 04:51:20 UTC

[GitHub] [iotdb] irvine0109 commented on a diff in pull request #6747: [IOTDB-3923] Add Sorted Cluster Test ResultSet for the Function of last

irvine0109 commented on code in PR #6747:
URL: https://github.com/apache/iotdb/pull/6747#discussion_r927287046


##########
integration-test/src/main/java/org/apache/iotdb/itbase/runtime/SortedClusterTestResultSet.java:
##########
@@ -0,0 +1,1218 @@
+/*
+ * 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.itbase.runtime;
+
+import org.apache.iotdb.itbase.exception.InconsistentDataException;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class SortedClusterTestResultSet implements ResultSet {
+
+  private final List<ResultSet> resultSets;
+  private final List<String> endpoints;
+  private final int queryTimeoutSeconds;
+  private final List<List<StringBuilder>> cachedResult = new ArrayList<>();
+
+  public SortedClusterTestResultSet(
+      List<Statement> statements, List<String> endpoints, String sql, int queryTimeoutSeconds)
+      throws SQLException {
+    this.queryTimeoutSeconds = queryTimeoutSeconds;
+    this.endpoints = endpoints;
+    RequestDelegate<ResultSet> delegate = createRequestDelegate();
+    for (Statement st : statements) {
+      delegate.addRequest(() -> st.executeQuery(sql));
+      cachedResult.add(new ArrayList<>());
+    }
+    resultSets = delegate.requestAll();
+  }
+
+  @Override
+  public boolean next() throws SQLException {
+    RequestDelegate<Boolean> delegate = createRequestDelegate();
+    for (ResultSet rs : resultSets) {
+      delegate.addRequest(rs::next);
+    }
+
+    boolean result = delegate.requestAllAndCompare();
+    if (result) {
+      for (List<StringBuilder> list : cachedResult) {
+        list.add(new StringBuilder());
+      }
+    }
+    return result;
+  }
+
+  @Override
+  public void close() throws SQLException {
+    RequestDelegate<Void> delegate = createRequestDelegate();
+    for (ResultSet rs : resultSets) {
+      delegate.addRequest(
+          () -> {
+            rs.close();
+            return null;
+          });
+    }
+    delegate.requestAll();
+
+    List<String> result = new ArrayList<>();
+    for (StringBuilder item : cachedResult.get(0)) {
+      result.add(item.toString());
+      Collections.sort(result);
+    }
+
+    for (int i = 1; i < cachedResult.size(); i++) {
+      List<String> anotherResult = new ArrayList<>();
+
+      for (StringBuilder item : cachedResult.get(i)) {
+        anotherResult.add(item.toString());
+      }
+
+      Collections.sort(anotherResult);
+
+      if (!result.equals(anotherResult)) {
+        throw new InconsistentDataException(cachedResult, endpoints);
+      }
+    }
+  }
+
+  private <T> T cachedResultAndReturnOne(List<T> data) {
+    for (int i = 0; i < data.size(); i++) {
+      List<StringBuilder> list = cachedResult.get(i);
+      list.get(list.size() - 1).append(data.get(i).toString()).append(",");

Review Comment:
   Yeah, using `Set` to do the consistency check is simple, but using `Set` can't find the last record item, which used by getXXX() method like `getString(String columnLabel)` or `getString(int columnIndex)` in this ResultSet class. 
   
   The detail is that the record item is one line of data that includes all information about one timeseries, we use the `next()` method in this ResultSet class to change to a new record item to append the information of the next timeseries, if we don't invoke the `next()` method, all getXXX() method will append to the last record item in `cachedResult`, i.e. the sequence is a big key point.



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org