Skip to content

Commit

Permalink
add header and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaojialin committed Mar 3, 2020
1 parent b3f035b commit 5b8fd58
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* 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.qp.physical.crud;

import org.apache.iotdb.db.qp.logical.Operator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,24 @@ public class GroupByFillDataSet extends QueryDataSet {

private GroupByEngineDataSet groupByEngineDataSet;
private Map<TSDataType, IFill> fillTypes;
// the first value for each time series
private Object[] previousValue;
// last timestamp for each time series
private long[] lastTimeArray;

public GroupByFillDataSet(List<Path> paths, List<TSDataType> dataTypes, GroupByEngineDataSet groupByEngineDataSet,
Map<TSDataType, IFill> fillTypes, QueryContext context)
throws StorageEngineException, IOException, QueryProcessException {
public GroupByFillDataSet(List<Path> paths, List<TSDataType> dataTypes,
GroupByEngineDataSet groupByEngineDataSet,
Map<TSDataType, IFill> fillTypes, QueryContext context)
throws StorageEngineException, IOException, QueryProcessException {
super(paths, dataTypes);
this.groupByEngineDataSet = groupByEngineDataSet;
this.fillTypes = fillTypes;
initPreviousParis(context);
initLastTimeArray(context);
}

private void initPreviousParis(QueryContext context) throws StorageEngineException, IOException, UnSupportedFillTypeException {
private void initPreviousParis(QueryContext context)
throws StorageEngineException, IOException, UnSupportedFillTypeException {
previousValue = new Object[paths.size()];
for (int i = 0; i < paths.size(); i++) {
Path path = paths.get(i);
Expand All @@ -71,12 +75,13 @@ private void initPreviousParis(QueryContext context) throws StorageEngineExcepti
}
}

private void initLastTimeArray(QueryContext context) throws IOException, StorageEngineException, QueryProcessException {
private void initLastTimeArray(QueryContext context)
throws IOException, StorageEngineException, QueryProcessException {
lastTimeArray = new long[paths.size()];
Arrays.fill(lastTimeArray, Long.MAX_VALUE);
for (int i = 0; i < paths.size(); i++) {
TimeValuePair lastTimeValuePair =
LastQueryExecutor.calculateLastPairForOneSeries(paths.get(i), dataTypes.get(i), context);
LastQueryExecutor.calculateLastPairForOneSeries(paths.get(i), dataTypes.get(i), context);
if (lastTimeValuePair.getValue() != null) {
lastTimeArray[i] = lastTimeValuePair.getTimestamp();
}
Expand All @@ -96,9 +101,11 @@ protected RowRecord nextWithoutConstraint() throws IOException {
Field field = rowRecord.getFields().get(i);
// current group by result is null
if (field.getDataType() == null) {
// the previous value is not null and (fill type is not previous until last or now time is before last time)
// the previous value is not null and
// (fill type is not previous until last or now time is before last time)
if (previousValue[i] != null
&& (!((PreviousFill)fillTypes.get(dataTypes.get(i))).isUntilLast() || rowRecord.getTimestamp() <= lastTimeArray[i])) {
&& (!((PreviousFill) fillTypes.get(dataTypes.get(i))).isUntilLast()
|| rowRecord.getTimestamp() <= lastTimeArray[i])) {
rowRecord.getFields().set(i, Field.getField(previousValue[i], dataTypes.get(i)));
}
} else {
Expand Down

0 comments on commit 5b8fd58

Please sign in to comment.