Skip to content
Merged
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 @@ -124,8 +124,12 @@ public Map<String, String> getAttributesWithSourceLooseRange() {
final String looseRangeValue =
attributes.getOrDefault(
TopicConstant.LOOSE_RANGE_KEY, TopicConstant.LOOSE_RANGE_DEFAULT_VALUE);
final String pipeLooseRangeValue =
looseRangeValue != null && Boolean.parseBoolean(looseRangeValue.trim())
? TopicConstant.LOOSE_RANGE_ALL_VALUE
: looseRangeValue;
return LOOSE_RANGE_KEY_SET.stream()
.collect(Collectors.toMap(key -> key, key -> looseRangeValue));
.collect(Collectors.toMap(key -> key, key -> pipeLooseRangeValue));
}

public Map<String, String> getAttributesWithSourcePrefix() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.rpc.subscription.config;

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

import java.util.Collections;
import java.util.Map;

public class TopicConfigTest {

@Test
public void testTrueLooseRangeMapsToAllSourceLooseRanges() {
final TopicConfig topicConfig =
new TopicConfig(Collections.singletonMap(TopicConstant.LOOSE_RANGE_KEY, " TRUE "));
final Map<String, String> sourceAttributes = topicConfig.getAttributesWithSourceLooseRange();

Assert.assertEquals(
TopicConstant.LOOSE_RANGE_ALL_VALUE, sourceAttributes.get("history.loose-range"));
Assert.assertEquals(
TopicConstant.LOOSE_RANGE_ALL_VALUE, sourceAttributes.get("realtime.loose-range"));
}

@Test
public void testFalseLooseRangeRemainsFalseForAllSourceLooseRanges() {
final TopicConfig topicConfig =
new TopicConfig(
Collections.singletonMap(TopicConstant.LOOSE_RANGE_KEY, Boolean.FALSE.toString()));
final Map<String, String> sourceAttributes = topicConfig.getAttributesWithSourceLooseRange();

Assert.assertEquals(Boolean.FALSE.toString(), sourceAttributes.get("history.loose-range"));
Assert.assertEquals(Boolean.FALSE.toString(), sourceAttributes.get("realtime.loose-range"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_HISTORY_START_TIME_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_HISTORY_TSFILE_ORDER_BY_QUERY_PRIORITY_DEFAULT_VALUE;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_HISTORY_TSFILE_ORDER_BY_QUERY_PRIORITY_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_LOOSE_RANGE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_MODS_ENABLE_DEFAULT_VALUE;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_MODS_ENABLE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_START_TIME_KEY;
Expand All @@ -103,6 +104,7 @@
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_HISTORY_LOOSE_RANGE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_HISTORY_START_TIME_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_HISTORY_TSFILE_ORDER_BY_QUERY_PRIORITY_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_LOOSE_RANGE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_MODS_ENABLE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_START_TIME_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_TSFILE_PARSER_KEY;
Expand Down Expand Up @@ -176,10 +178,19 @@ public void validate(final PipeParameterValidator validator) {
final String extractorHistoryLooseRangeValue =
parameters
.getStringOrDefault(
Arrays.asList(EXTRACTOR_HISTORY_LOOSE_RANGE_KEY, SOURCE_HISTORY_LOOSE_RANGE_KEY),
Arrays.asList(
EXTRACTOR_HISTORY_LOOSE_RANGE_KEY,
SOURCE_HISTORY_LOOSE_RANGE_KEY,
EXTRACTOR_LOOSE_RANGE_KEY,
SOURCE_LOOSE_RANGE_KEY),
EXTRACTOR_HISTORY_LOOSE_RANGE_DEFAULT_VALUE)
.trim();
if (EXTRACTOR_HISTORY_LOOSE_RANGE_ALL_VALUE.equalsIgnoreCase(extractorHistoryLooseRangeValue)) {
if (Boolean.FALSE.toString().equalsIgnoreCase(extractorHistoryLooseRangeValue)) {
sloppyTimeRange = false;
sloppyPattern = false;
} else if (EXTRACTOR_HISTORY_LOOSE_RANGE_ALL_VALUE.equalsIgnoreCase(
extractorHistoryLooseRangeValue)
|| Boolean.parseBoolean(extractorHistoryLooseRangeValue)) {
sloppyTimeRange = true;
sloppyPattern = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import java.util.stream.Collectors;

import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_END_TIME_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_LOOSE_RANGE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_MODS_ENABLE_DEFAULT_VALUE;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_MODS_ENABLE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_REALTIME_LOOSE_RANGE_ALL_VALUE;
Expand All @@ -76,6 +77,7 @@
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_START_TIME_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.EXTRACTOR_TSFILE_PARSER_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_END_TIME_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_LOOSE_RANGE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_MODS_ENABLE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_REALTIME_LOOSE_RANGE_KEY;
import static org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant.SOURCE_START_TIME_KEY;
Expand Down Expand Up @@ -169,11 +171,19 @@ public void validate(final PipeParameterValidator validator) throws Exception {
final String extractorRealtimeLooseRangeValue =
parameters
.getStringOrDefault(
Arrays.asList(EXTRACTOR_REALTIME_LOOSE_RANGE_KEY, SOURCE_REALTIME_LOOSE_RANGE_KEY),
Arrays.asList(
EXTRACTOR_REALTIME_LOOSE_RANGE_KEY,
SOURCE_REALTIME_LOOSE_RANGE_KEY,
EXTRACTOR_LOOSE_RANGE_KEY,
SOURCE_LOOSE_RANGE_KEY),
EXTRACTOR_REALTIME_LOOSE_RANGE_DEFAULT_VALUE)
.trim();
if (EXTRACTOR_REALTIME_LOOSE_RANGE_ALL_VALUE.equalsIgnoreCase(
extractorRealtimeLooseRangeValue)) {
if (Boolean.FALSE.toString().equalsIgnoreCase(extractorRealtimeLooseRangeValue)) {
sloppyTimeRange = false;
sloppyPattern = false;
} else if (EXTRACTOR_REALTIME_LOOSE_RANGE_ALL_VALUE.equalsIgnoreCase(
extractorRealtimeLooseRangeValue)
|| Boolean.parseBoolean(extractorRealtimeLooseRangeValue)) {
sloppyTimeRange = true;
sloppyPattern = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant;
import org.apache.iotdb.db.pipe.source.dataregion.IoTDBDataRegionSource;
import org.apache.iotdb.db.pipe.source.dataregion.historical.PipeHistoricalDataRegionTsFileSource;
import org.apache.iotdb.db.pipe.source.dataregion.realtime.PipeRealtimeDataRegionSource;
import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
import org.apache.iotdb.pipe.api.exception.PipeParameterNotValidException;
Expand All @@ -29,7 +31,10 @@
import org.junit.Ignore;
import org.junit.Test;

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

public class IoTDBDataRegionSourceTest {
@Test
Expand All @@ -54,6 +59,86 @@ public void testIoTDBDataRegionExtractor() {
}
}

@Test
public void testGlobalLooseRangeBooleanAndStageOverrides() throws Exception {
assertLooseRange(
Collections.singletonMap(
PipeSourceConstant.SOURCE_LOOSE_RANGE_KEY, Boolean.FALSE.toString()),
false,
false,
false,
false);
assertLooseRange(
Collections.singletonMap(PipeSourceConstant.SOURCE_LOOSE_RANGE_KEY, " TrUe "),
true,
true,
true,
true);
assertLooseRange(
Collections.singletonMap(PipeSourceConstant.EXTRACTOR_LOOSE_RANGE_KEY, "TRUE"),
true,
true,
true,
true);
assertLooseRange(
attributes(
PipeSourceConstant.SOURCE_LOOSE_RANGE_KEY,
"true",
PipeSourceConstant.SOURCE_HISTORY_LOOSE_RANGE_KEY,
"time",
PipeSourceConstant.SOURCE_REALTIME_LOOSE_RANGE_KEY,
"path"),
true,
false,
false,
true);
}

private static void assertLooseRange(
final Map<String, String> attributes,
final boolean historicalTime,
final boolean historicalPath,
final boolean realtimeTime,
final boolean realtimePath)
throws Exception {
try (final IoTDBDataRegionSource source = new IoTDBDataRegionSource()) {
source.validate(new PipeParameterValidator(new PipeParameters(attributes)));

final Object historicalSource =
readField(IoTDBDataRegionSource.class, source, "historicalExtractor");
final Object realtimeSource =
readField(IoTDBDataRegionSource.class, source, "realtimeExtractor");
Assert.assertEquals(
historicalTime,
readField(
PipeHistoricalDataRegionTsFileSource.class, historicalSource, "sloppyTimeRange"));
Assert.assertEquals(
historicalPath,
readField(PipeHistoricalDataRegionTsFileSource.class, historicalSource, "sloppyPattern"));
Assert.assertEquals(
realtimeTime,
readField(PipeRealtimeDataRegionSource.class, realtimeSource, "sloppyTimeRange"));
Assert.assertEquals(
realtimePath,
readField(PipeRealtimeDataRegionSource.class, realtimeSource, "sloppyPattern"));
}
}

private static Map<String, String> attributes(final String... entries) {
final Map<String, String> attributes = new HashMap<>();
for (int index = 0; index < entries.length; index += 2) {
attributes.put(entries[index], entries[index + 1]);
}
return attributes;
}

private static Object readField(final Class<?> type, final Object target, final String name)
throws ReflectiveOperationException {
final Field field = type.getDeclaredField(name);
field.setAccessible(true);
return field.get(target);
}

@Test
public void testTsFileParserParameter() throws Exception {
for (final String parser : new String[] {"query", "scan"}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public class PipeSourceConstant {
public static final String SOURCE_END_TIME_KEY = "source.end-time";
public static final String NOW_TIME_VALUE = "now";

public static final String EXTRACTOR_LOOSE_RANGE_KEY = "extractor.loose-range";
public static final String SOURCE_LOOSE_RANGE_KEY = "source.loose-range";

public static final String EXTRACTOR_WATERMARK_INTERVAL_KEY = "extractor.watermark-interval-ms";
public static final String SOURCE_WATERMARK_INTERVAL_KEY = "source.watermark-interval-ms";
public static final long EXTRACTOR_WATERMARK_INTERVAL_DEFAULT_VALUE = -1; // -1 means no watermark
Expand Down
Loading