LeiRui commented on a change in pull request #336: [ IOTDB-160]External sort
URL: https://github.com/apache/incubator-iotdb/pull/336#discussion_r320542474
 
 

 ##########
 File path: 
server/src/main/java/org/apache/iotdb/db/query/externalsort/SimpleExternalSortEngine.java
 ##########
 @@ -0,0 +1,160 @@
+ /**
+ * Copyright © 2019 Apache IoTDB(incubating) ([email protected])
+ *
+ * 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.externalsort;
+
+ import java.io.File;
+ import java.io.IOException;
+ import java.util.ArrayList;
+ import java.util.List;
+ import org.apache.commons.io.FileUtils;
+ import org.apache.iotdb.db.conf.IoTDBDescriptor;
+ import org.apache.iotdb.db.exception.StorageEngineFailureException;
+ import 
org.apache.iotdb.db.query.externalsort.adapter.ByTimestampReaderAdapter;
+ import org.apache.iotdb.db.query.reader.IPointReader;
+ import org.apache.iotdb.db.query.reader.IReaderByTimestamp;
+ import org.apache.iotdb.db.query.reader.chunkRelated.ChunkReaderWrap;
+
+
+ public class SimpleExternalSortEngine implements ExternalSortJobEngine {
+
+   private ExternalSortJobScheduler scheduler;
+
+   private String queryDir;
+   private int minExternalSortSourceCount;
+
+   private SimpleExternalSortEngine() {
+     queryDir = IoTDBDescriptor.getInstance().getConfig().getQueryDir();
+     minExternalSortSourceCount = IoTDBDescriptor.getInstance().getConfig()
+         .getExternalSortThreshold();
+     scheduler = ExternalSortJobScheduler.getInstance();
+
+     // create queryDir
+     try {
+       FileUtils.forceMkdir(new File(queryDir));
+     } catch (IOException e) {
+       throw new StorageEngineFailureException("create system directory 
failed!");
+     }
+   }
+
+   // This class is used in test.
+   public SimpleExternalSortEngine(String queryDir, int 
minExternalSortSourceCount) {
+     this.queryDir = queryDir;
+     this.minExternalSortSourceCount = minExternalSortSourceCount;
+     scheduler = ExternalSortJobScheduler.getInstance();
+   }
+
+   @Override
+   public List<IPointReader> executeForIPointReader(long queryId,
+       List<ChunkReaderWrap> chunkReaderWraps)
+       throws IOException {
+     if (chunkReaderWraps.size() < minExternalSortSourceCount) {
+       return generateIPointReader(chunkReaderWraps, 0, 
chunkReaderWraps.size());
+     }
+     ExternalSortJob job = createJob(queryId, chunkReaderWraps);
+     return job.executeWithGlobalTimeFilter();
+   }
+
+   @Override
+   public List<IReaderByTimestamp> executeForByTimestampReader(long queryId,
+       List<ChunkReaderWrap> chunkReaderWraps) throws IOException {
+     if (chunkReaderWraps.size() < minExternalSortSourceCount) {
+       return generateIReaderByTimestamp(chunkReaderWraps, 0, 
chunkReaderWraps.size());
+     }
+     ExternalSortJob job = createJob(queryId, chunkReaderWraps);
+     return convert(job.executeWithGlobalTimeFilter());
 
 Review comment:
   I think `job.executeForIPointReader` is better than 
`job.executeWithGlobalTimeFilter`.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to