Skip to content

Commit

Permalink
Update TableDeviceSchemaFetcher.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Caideyipi committed Aug 1, 2024
1 parent 8748574 commit 7d42b3d
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,19 @@ private boolean tryGetDeviceInCache(
final Predicate<DeviceEntry> check,
final List<String> attributeColumns,
final List<IDeviceID> fetchPaths) {
final String[] idValues = new String[tableInstance.getIdNums()];
String[] idValues = new String[tableInstance.getIdNums()];
for (final List<SchemaFilter> schemaFilters : idFilters.values()) {
final IdFilter idFilter = (IdFilter) schemaFilters.get(0);
final SchemaFilter childFilter = idFilter.getChild();
idValues[idFilter.getIndex()] = ((PreciseFilter) childFilter).getValue();
}

final String[] idValuesWithoutTailingNull = (String[]) truncateTailingNull(idValues);
idValues = (String[]) truncateTailingNull(idValues);
final Map<String, String> attributeMap =
cache.getDeviceAttribute(
database, tableInstance.getTableName(), idValuesWithoutTailingNull);
cache.getDeviceAttribute(database, tableInstance.getTableName(), idValues);
if (attributeMap == null) {
if (Objects.nonNull(fetchPaths)) {
fetchPaths.add(convertIdValuesToDeviceID(idValuesWithoutTailingNull, tableInstance));
fetchPaths.add(convertIdValuesToDeviceID(idValues, tableInstance));
}
return false;
}
Expand All @@ -302,12 +301,11 @@ private boolean tryGetDeviceInCache(
if (!attributeMap.containsKey(attributeKey)) {
// The attributes may be updated and the cache entry is stale
if (Objects.nonNull(fetchPaths)) {
fetchPaths.add(convertIdValuesToDeviceID(idValuesWithoutTailingNull, tableInstance));
fetchPaths.add(convertIdValuesToDeviceID(idValues, tableInstance));
}
return false;
}
String value = attributeMap.get(attributeKey);
attributeValues.add(value);
attributeValues.add(attributeMap.get(attributeKey));
}

final DeviceEntry deviceEntry =
Expand Down Expand Up @@ -381,11 +379,12 @@ private void fetchMissingDeviceSchemaForQuery(
}
final Column[] columns = tsBlock.get().getValueColumns();
for (int i = 0; i < tsBlock.get().getPositionCount(); i++) {
final String[] nodes = new String[idLength + 1];
String[] nodes = new String[idLength + 1];
nodes[0] = table;
final Map<String, String> attributeMap = new HashMap<>();
constructNodsArrayAndAttributeMap(
attributeMap, nodes, 1, columnHeaderList, columns, tableInstance, i);
nodes = (String[]) truncateTailingNull(nodes);
final IDeviceID deviceID = IDeviceID.Factory.DEFAULT_FACTORY.create(nodes);
// TODO table metadata: add memory control in query
deviceEntryList.add(
Expand All @@ -395,11 +394,7 @@ private void fetchMissingDeviceSchemaForQuery(
// Only cache those exact device query
// Fetch paths is null iff there are fuzzy queries related to id columns
if (Objects.nonNull(fetchPaths)) {
cache.put(
database,
table,
(String[]) truncateTailingNull(Arrays.copyOfRange(nodes, 1, nodes.length)),
attributeMap);
cache.put(database, table, Arrays.copyOfRange(nodes, 1, nodes.length), attributeMap);
}
}
}
Expand Down

0 comments on commit 7d42b3d

Please sign in to comment.