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
@@ -0,0 +1,60 @@
/*
* 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.calc.execution.operator.process.fill.linear;

import org.apache.tsfile.block.column.Column;
import org.apache.tsfile.read.common.block.column.DoubleColumn;
import org.apache.tsfile.read.common.block.column.TimeColumn;
import org.junit.Test;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class LinearFillTest {

@Test
public void testInterpolationAcrossLongRange() {
assertMidpoint(new long[] {Long.MIN_VALUE, 0, Long.MAX_VALUE});
}

@Test
public void testDescendingInterpolationAcrossLongRange() {
assertMidpoint(new long[] {Long.MAX_VALUE, 0, Long.MIN_VALUE});
}

@Test
public void testSmallTimeDifferencesNearLongMaxValueRemainExact() {
assertMidpoint(new long[] {Long.MAX_VALUE - 2, Long.MAX_VALUE - 1, Long.MAX_VALUE});
}

private void assertMidpoint(long[] times) {
Column values =
new DoubleColumn(
3, Optional.of(new boolean[] {false, true, false}), new double[] {0, 0, 10});
Column filled = new DoubleLinearFill().fill(new TimeColumn(3, times), values, 0);
assertEquals(3, filled.getPositionCount());
for (int i = 0; i < 3; i++) {
assertFalse(filled.isNull(i));
assertEquals(i * 5.0, filled.getDouble(i), 1e-12);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.calc.transformation.dag.column.unary.scalar;

import org.apache.iotdb.calc.transformation.dag.column.leaf.IdentityColumnTransformer;

import org.junit.Test;

import java.time.ZoneOffset;

import static org.apache.iotdb.calc.transformation.dag.column.unary.scalar.DateBinFunctionColumnTransformer.dateBin;
import static org.apache.iotdb.calc.transformation.dag.column.unary.scalar.DateBinFunctionColumnTransformer.nextDateBin;
import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class DateBinFunctionColumnTransformerTest {

@Test
public void testSourceMinusOriginOverflows() {
assertBin(
Long.MAX_VALUE, Long.MIN_VALUE, 10, Long.MAX_VALUE - 5, Long.MAX_VALUE, Long.MAX_VALUE);
}

@Test
public void testNegativeDifferenceRoundsDownBeforeClamping() {
// The mathematical start is MIN_VALUE - 5; its end must be computed before clamping.
assertBin(
Long.MIN_VALUE, Long.MAX_VALUE, 10, Long.MIN_VALUE, Long.MIN_VALUE + 5, Long.MIN_VALUE + 4);
}

@Test
public void testStepProductOverflowsButBinStartIsRepresentable() {
assertBin(-1, Long.MAX_VALUE - 1, Long.MAX_VALUE - 1, Long.MIN_VALUE + 2, 0, -1);
}

@Test
public void testClosedEndIncludesLongMaxValue() {
assertBin(Long.MAX_VALUE, 0, 2, Long.MAX_VALUE - 1, Long.MAX_VALUE, Long.MAX_VALUE);
}

@Test
public void testNextBinSaturatesWithoutWrapping() {
assertEquals(Long.MAX_VALUE, nextDateBin(10, Long.MAX_VALUE - 5));
assertEquals(Long.MAX_VALUE, nextDateBin(10, Long.MAX_VALUE));
assertEquals(Long.MIN_VALUE + 10, nextDateBin(10, Long.MIN_VALUE));
}

private void assertBin(
long source, long origin, long duration, long start, long end, long closedEnd) {
DateBinFunctionColumnTransformer transformer =
new DateBinFunctionColumnTransformer(
TIMESTAMP,
0,
duration,
new IdentityColumnTransformer(TIMESTAMP, 0),
origin,
ZoneOffset.UTC);
assertEquals(start, dateBin(source, origin, 0, duration, ZoneOffset.UTC));
assertArrayEquals(new long[] {start, end}, transformer.dateBinStartEnd(source));
assertArrayEquals(new long[] {start, closedEnd}, transformer.dateBinStartEndClosed(source));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.exception.query;

import org.apache.iotdb.rpc.TSStatusCode;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class QueryTimeoutRuntimeExceptionTest {

@Test
public void testDeadlineSaturatesAtLongMaxValue() {
final long startTime = Long.MAX_VALUE - 1;
final long currentTime = Long.MAX_VALUE;
final QueryTimeoutRuntimeException exception =
new QueryTimeoutRuntimeException(startTime, currentTime, 10);

assertEquals(
String.format(
QueryTimeoutRuntimeException.QUERY_TIMEOUT_EXCEPTION_MESSAGE,
startTime,
Long.MAX_VALUE,
currentTime),
exception.getMessage());
assertEquals(TSStatusCode.QUERY_TIMEOUT.getStatusCode(), exception.getErrorCode());
assertTrue(exception.isUserException());
}

@Test
public void testDeadlineSaturatesAtLongMinValue() {
final long startTime = Long.MIN_VALUE + 1;
final long currentTime = Long.MIN_VALUE;
final QueryTimeoutRuntimeException exception =
new QueryTimeoutRuntimeException(startTime, currentTime, -10);

assertEquals(
String.format(
QueryTimeoutRuntimeException.QUERY_TIMEOUT_EXCEPTION_MESSAGE,
startTime,
Long.MIN_VALUE,
currentTime),
exception.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,73 @@

package org.apache.iotdb.db.pipe.source.dataregion.realtime;

import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.consensus.index.impl.MinimumProgressIndex;
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeTaskMeta;
import org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant;
import org.apache.iotdb.commons.pipe.config.plugin.configuraion.PipeTaskRuntimeConfiguration;
import org.apache.iotdb.commons.pipe.config.plugin.env.PipeTaskSourceRuntimeEnvironment;
import org.apache.iotdb.commons.pipe.event.ProgressReportEvent;
import org.apache.iotdb.commons.utils.TimePartitionUtils;
import org.apache.iotdb.db.pipe.event.common.heartbeat.PipeHeartbeatEvent;
import org.apache.iotdb.db.pipe.event.realtime.PipeRealtimeEvent;
import org.apache.iotdb.db.pipe.event.realtime.PipeRealtimeEventFactory;
import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
import org.apache.iotdb.pipe.api.event.Event;

import org.junit.Assert;
import org.junit.Test;

import java.lang.reflect.Field;
import java.util.HashMap;

public class PipeRealtimeDataRegionSourceTest {

private static final String TEST_REFERENCE_HOLDER =
PipeRealtimeDataRegionSourceTest.class.getName();

@Test
public void customizeUsesConfiguredTimePartitionOriginForBounds() throws Exception {
final long previousOrigin = CommonDescriptor.getInstance().getConfig().getTimePartitionOrigin();
final long previousInterval =
CommonDescriptor.getInstance().getConfig().getTimePartitionInterval();

try {
final long origin = 1_000L;
final long interval = 3_600_000L;
CommonDescriptor.getInstance().getConfig().setTimePartitionOrigin(origin);
CommonDescriptor.getInstance().getConfig().setTimePartitionInterval(interval);
TimePartitionUtils.setTimePartitionOrigin(origin);
TimePartitionUtils.setTimePartitionInterval(interval);

final PipeParameters parameters =
new PipeParameters(
new HashMap<String, String>() {
{
put(PipeSourceConstant.EXTRACTOR_START_TIME_KEY, "0");
put(PipeSourceConstant.EXTRACTOR_END_TIME_KEY, "3600000");
}
});
try (final ProgressReportTestSource source = new ProgressReportTestSource()) {
source.validate(new PipeParameterValidator(parameters));
source.customize(
parameters,
new PipeTaskRuntimeConfiguration(
new PipeTaskSourceRuntimeEnvironment(
"pipe", 1L, -1, new PipeTaskMeta(MinimumProgressIndex.INSTANCE, 1))));

Assert.assertEquals(0, getPrivateLong(source, "startTimePartitionIdLowerBound"));
Assert.assertEquals(-1, getPrivateLong(source, "endTimePartitionIdUpperBound"));
}
} finally {
CommonDescriptor.getInstance().getConfig().setTimePartitionOrigin(previousOrigin);
CommonDescriptor.getInstance().getConfig().setTimePartitionInterval(previousInterval);
TimePartitionUtils.setTimePartitionOrigin(previousOrigin);
TimePartitionUtils.setTimePartitionInterval(previousInterval);
}
}

@Test
public void progressReportEventReleasesDroppedHeartbeatEvent() throws Exception {
try (final ProgressReportTestSource source = new ProgressReportTestSource()) {
Expand Down Expand Up @@ -84,6 +136,12 @@ private static PipeRealtimeEvent createProgressReportEvent() {
return event;
}

private static long getPrivateLong(final Object target, final String fieldName) throws Exception {
final Field field = PipeRealtimeDataRegionSource.class.getDeclaredField(fieldName);
field.setAccessible(true);
return field.getLong(target);
}

private static class ProgressReportTestSource extends PipeRealtimeDataRegionSource {

@Override
Expand Down
Loading
Loading