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 @@ -137,7 +137,10 @@
// todo implement storage for device of diverse data types
long memUsage = MAP_SIZE + RamUsageEstimator.NUM_BYTES_OBJECT_REF;
final Map<String, Binary> attributeMap = new HashMap<>();
for (int i = 0; i < nameList.size(); i++) {

Check warning on line 140 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Reduce the total number of break and continue statements in this loop to use at most one.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ3i3KtWxTbyeZtnd-Q0&open=AZ3i3KtWxTbyeZtnd-Q0&pullRequest=17593
if (valueList.length <= i) {
break;
}
if (valueList[i] == null || valueList[i] == Constants.NONE) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.schemaengine.schemaregion.attribute;

import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.Constants;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;

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

public class DeviceAttributeStoreTest {

@Test
public void testCreateAttributeIgnoresNamesWithoutValues() {
final DeviceAttributeStore store = new DeviceAttributeStore(null);
final Binary expectedValue = new Binary("v1", StandardCharsets.UTF_8);

final int pointer =
store.createAttribute(
Arrays.asList("attr1", "attr2"), new Object[] {expectedValue}, "table1");

final Map<String, Binary> attributes = store.getAttributes(pointer);
assertEquals(1, attributes.size());
assertEquals(expectedValue, attributes.get("attr1"));
assertFalse(attributes.containsKey("attr2"));
}

@Test
public void testCreateAttributeSkipsNoneValue() {
final DeviceAttributeStore store = new DeviceAttributeStore(null);
final Binary expectedValue = new Binary("v2", StandardCharsets.UTF_8);

final int pointer =
store.createAttribute(
Arrays.asList("attr1", "attr2"),
new Object[] {Constants.NONE, expectedValue},
"table1");

final Map<String, Binary> attributes = store.getAttributes(pointer);
assertEquals(1, attributes.size());
assertFalse(attributes.containsKey("attr1"));
assertTrue(attributes.containsKey("attr2"));
assertEquals(expectedValue, attributes.get("attr2"));
}
}
Loading