Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public abstract class AbstractCli {
static final int CODE_ERROR = 1;

static final String ISO8601_ARGS = "disableISO8601";
static final List<String> AGGREGRATE_TIME_LIST = new ArrayList<>();
static final List<String> AGGREGATE_TIME_LIST = new ArrayList<>();
static final String RPC_COMPRESS_ARGS = "c";
private static final String RPC_COMPRESS_NAME = "rpcCompressed";
static final String TIMEOUT_ARGS = "timeout";
Expand Down
4 changes: 2 additions & 2 deletions iotdb-client/cli/src/main/java/org/apache/iotdb/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static void executeSql(CliContext ctx) throws TException {
connection.setQueryTimeout(queryTimeout);
properties = connection.getServerProperties();
timestampPrecision = properties.getTimestampPrecision();
AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
AGGREGATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
processCommand(ctx, execute, connection);
ctx.exit(lastProcessStatus);
} catch (SQLException e) {
Expand All @@ -200,7 +200,7 @@ private static void receiveCommands(CliContext ctx) throws TException {
DriverManager.getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", info)) {
connection.setQueryTimeout(queryTimeout);
properties = connection.getServerProperties();
AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
AGGREGATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
timestampPrecision = properties.getTimestampPrecision();

echoStarting(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ number
timeRange
: LS_BRACKET startTime=timeValue COMMA endTime=timeValue RR_BRACKET
| LR_BRACKET startTime=timeValue COMMA endTime=timeValue RS_BRACKET
| LS_BRACKET startTime=timeValue COMMA endTime=timeValue RS_BRACKET
;

// ---- Having Clause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class AggrWindowIterator implements ITimeRangeIterator {

private final boolean isAscending;
private final boolean leftCRightO;
private final boolean rightClosed;

private TimeRange curTimeRange;
private boolean hasCachedTimeRange;
Expand All @@ -58,13 +59,15 @@ public AggrWindowIterator(
TimeDuration slidingStep,
boolean isAscending,
boolean leftCRightO,
boolean rightClosed,
ZoneId zoneId) {
this.startTime = startTime;
this.endTime = endTime;
this.interval = interval;
this.slidingStep = slidingStep;
this.isAscending = isAscending;
this.leftCRightO = leftCRightO;
this.rightClosed = rightClosed;
this.timeRangeCount = 0;
this.zoneId = zoneId;
}
Expand Down Expand Up @@ -157,7 +160,7 @@ public boolean hasNextTimeRange() {
} else {
retStartTime = curStartTime + slidingStep.nonMonthDuration;
}
// This is an open interval , [0-100)
// This is an open interval, [0-100)
if (retStartTime >= endTime) {
return false;
}
Expand Down Expand Up @@ -197,6 +200,21 @@ public TimeRange nextTimeRange() {
return null;
}

@Override
public TimeRange getFinalTimeRange(TimeRange timeRange, boolean leftCRightO) {
// For rightClosed intervals ending at endTime, preserve the right boundary
if (rightClosed && timeRange.getMax() == endTime) {
// Still need to adjust left boundary if leftCRightO is false
return leftCRightO
? timeRange // [start, end] - no adjustment needed
: new TimeRange(timeRange.getMin() + 1, timeRange.getMax()); // (start, end]
}
// Standard adjustment for non-end windows
return leftCRightO
? new TimeRange(timeRange.getMin(), timeRange.getMax() - 1)
: new TimeRange(timeRange.getMin() + 1, timeRange.getMax());
}

@Override
public boolean isAscending() {
return isAscending;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class PreAggrWindowIterator implements ITimeRangeIterator {

private final boolean isAscending;
private final boolean leftCRightO;
private final boolean rightClosed;

private long curInterval;
private long curSlidingStep;
Expand All @@ -51,13 +52,15 @@ public PreAggrWindowIterator(
long interval,
long slidingStep,
boolean isAscending,
boolean leftCRightO) {
boolean leftCRightO,
boolean rightClosed) {
this.startTime = startTime;
this.endTime = endTime;
this.interval = interval;
this.slidingStep = slidingStep;
this.isAscending = isAscending;
this.leftCRightO = leftCRightO;
this.rightClosed = rightClosed;
initIntervalAndStep();
}

Expand Down Expand Up @@ -132,6 +135,21 @@ public TimeRange nextTimeRange() {
return null;
}

@Override
public TimeRange getFinalTimeRange(TimeRange timeRange, boolean leftCRightO) {
// For rightClosed intervals ending at endTime, preserve the right boundary
if (rightClosed && timeRange.getMax() == endTime) {
// Still need to adjust left boundary if leftCRightO is false
return leftCRightO
? timeRange // [start, end] - no adjustment needed
: new TimeRange(timeRange.getMin() + 1, timeRange.getMax()); // (start, end]
}
// Standard adjustment for non-end windows
return leftCRightO
? new TimeRange(timeRange.getMin(), timeRange.getMax() - 1)
: new TimeRange(timeRange.getMin() + 1, timeRange.getMax());
}

private void initIntervalAndStep() {
if (slidingStep >= interval) {
curInterval = interval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class PreAggrWindowWithNaturalMonthIterator implements ITimeRangeIterator

private final boolean isAscending;
private final boolean leftCRightO;
private final boolean rightClosed;
private final TimeSelector timeBoundaryHeap;

private final AggrWindowIterator aggrWindowIterator;
Expand All @@ -49,12 +50,21 @@ public PreAggrWindowWithNaturalMonthIterator(
TimeDuration slidingStep,
boolean isAscending,
boolean leftCRightO,
boolean rightClosed,
ZoneId zoneId) {
this.isAscending = isAscending;
this.rightClosed = rightClosed;
this.timeBoundaryHeap = new TimeSelector(HEAP_MAX_SIZE, isAscending);
this.aggrWindowIterator =
new AggrWindowIterator(
startTime, endTime, interval, slidingStep, isAscending, leftCRightO, zoneId);
startTime,
endTime,
interval,
slidingStep,
isAscending,
leftCRightO,
rightClosed,
zoneId);
this.leftCRightO = leftCRightO;
initHeap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static ITimeRangeIterator getTimeRangeIterator(
TimeDuration slidingStep,
boolean isAscending,
boolean leftCRightO,
boolean rightClosed,
boolean outputPartialTimeWindow,
ZoneId zoneId) {
if (outputPartialTimeWindow
Expand All @@ -54,14 +55,22 @@ public static ITimeRangeIterator getTimeRangeIterator(
interval.nonMonthDuration,
slidingStep.nonMonthDuration,
isAscending,
leftCRightO);
leftCRightO,
rightClosed);
} else {
return new PreAggrWindowWithNaturalMonthIterator(
startTime, endTime, interval, slidingStep, isAscending, leftCRightO, zoneId);
startTime,
endTime,
interval,
slidingStep,
isAscending,
leftCRightO,
rightClosed,
zoneId);
}
} else {
return new AggrWindowIterator(
startTime, endTime, interval, slidingStep, isAscending, leftCRightO, zoneId);
startTime, endTime, interval, slidingStep, isAscending, leftCRightO, rightClosed, zoneId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public static ITimeRangeIterator initTimeRangeIterator(
groupByTimeParameter.getSlidingStep(),
ascending,
groupByTimeParameter.isLeftCRightO(),
groupByTimeParameter.isRightClosed(),
outputPartialTimeWindow,
zoneId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,19 @@ public static BetweenExpression notBetween(
public static GroupByTimeExpression groupByTime(GroupByTimeParameter parameter) {
long startTime =
parameter.isLeftCRightO() ? parameter.getStartTime() : parameter.getStartTime() + 1;
long endTime = parameter.isLeftCRightO() ? parameter.getEndTime() : parameter.getEndTime() + 1;
long endTime =
parameter.isRightClosed()
? (parameter.getEndTime() == Long.MAX_VALUE
? Long.MAX_VALUE
: parameter.getEndTime() + 1)
: (parameter.isLeftCRightO() ? parameter.getEndTime() : parameter.getEndTime() + 1);
return new GroupByTimeExpression(
startTime, endTime, parameter.getInterval(), parameter.getSlidingStep());
startTime,
endTime,
parameter.getInterval(),
parameter.getSlidingStep(),
parameter.isLeftCRightO(),
parameter.isRightClosed());
}

public static GroupByTimeExpression groupByTime(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,39 @@ public class GroupByTimeExpression extends Expression {
// sliding step
private final TimeDuration slidingStep;

// if it is left close and right open interval
private final boolean leftCRightO;

// if the right boundary is closed (inclusive)
private final boolean rightClosed;

public GroupByTimeExpression(
long startTime, long endTime, TimeDuration interval, TimeDuration slidingStep) {
this(startTime, endTime, interval, slidingStep, true, false);
}

public GroupByTimeExpression(
long startTime,
long endTime,
TimeDuration interval,
TimeDuration slidingStep,
boolean leftCRightO,
boolean rightClosed) {
this.startTime = startTime;
this.endTime = endTime;
this.interval = interval;
this.slidingStep = slidingStep;
this.leftCRightO = leftCRightO;
this.rightClosed = rightClosed;
}

public GroupByTimeExpression(ByteBuffer byteBuffer) {
this.startTime = ReadWriteIOUtils.readLong(byteBuffer);
this.endTime = ReadWriteIOUtils.readLong(byteBuffer);
this.interval = TimeDuration.deserialize(byteBuffer);
this.slidingStep = TimeDuration.deserialize(byteBuffer);
this.leftCRightO = ReadWriteIOUtils.readBool(byteBuffer);
this.rightClosed = ReadWriteIOUtils.readBool(byteBuffer);
}

public long getStartTime() {
Expand All @@ -86,6 +106,14 @@ public TimeDuration getSlidingStep() {
return slidingStep;
}

public boolean isLeftCRightO() {
return leftCRightO;
}

public boolean isRightClosed() {
return rightClosed;
}

@Override
public ExpressionType getExpressionType() {
return ExpressionType.GROUP_BY_TIME;
Expand Down Expand Up @@ -147,6 +175,8 @@ protected void serialize(ByteBuffer byteBuffer) {
ReadWriteIOUtils.write(endTime, byteBuffer);
interval.serialize(byteBuffer);
slidingStep.serialize(byteBuffer);
ReadWriteIOUtils.write(leftCRightO, byteBuffer);
ReadWriteIOUtils.write(rightClosed, byteBuffer);
}

@Override
Expand All @@ -155,6 +185,8 @@ protected void serialize(DataOutputStream stream) throws IOException {
ReadWriteIOUtils.write(endTime, stream);
interval.serialize(stream);
slidingStep.serialize(stream);
ReadWriteIOUtils.write(leftCRightO, stream);
ReadWriteIOUtils.write(rightClosed, stream);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,7 @@ private GroupByTimeComponent parseGroupByTimeClause(
if (ctx.timeRange() != null) {
parseTimeRangeForGroupByTime(ctx.timeRange(), groupByTimeComponent);
groupByTimeComponent.setLeftCRightO(ctx.timeRange().LS_BRACKET() != null);
groupByTimeComponent.setRightClosed(ctx.timeRange().RS_BRACKET() != null);
}

// Parse time interval
Expand Down
Loading