muttakin2301/ccr_train_1000 huggingface dataset:
Code review comment: I think this is in-correct. Don't we want to use `getIdleTcpConnectionTimeout` ?

Code before review:
public Builder(ConnectionPolicy connectionPolicy) {
this.bufferPageSize = DEFAULT_OPTIONS.bufferPageSize;
this.connectionAcquisitionTimeout = DEFAULT_OPTIONS.connectionAcquisitionTimeout;
this.connectTimeout = connectionPolicy.getConnectTimeout();
this.idleChannelTimeout = connectionPolicy.getIdleConnectionTimeout();
this.idleEndpointTimeout = DEFAULT_OPTIONS.idleEndpointTimeout;
this.maxBufferCapacity = DEFAULT_OPTIONS.maxBufferCapacity;
this.maxChannelsPerEndpoint = connectionPolicy.getMaxConnectionsPerEndpoint();
this.maxRequestsPerChannel = connectionPolicy.getMaxRequestsPerConnection();
this.receiveHangDetectionTime = DEFAULT_OPTIONS.receiveHangDetectionTime;
this.requestExpiryInterval = DEFAULT_OPTIONS.requestExpiryInterval;
this.requestTimeout = connectionPolicy.getRequestTimeout();
this.requestTimerResolution = DEFAULT_OPTIONS.requestTimerResolution;
this.sendHangDetectionTime = DEFAULT_OPTIONS.sendHangDetectionTime;
this.shutdownTimeout = DEFAULT_OPTIONS.shutdownTimeout;
this.threadCount = DEFAULT_OPTIONS.threadCount;
this.userAgent = DEFAULT_OPTIONS.userAgent;
}

Line under review: this.idleChannelTimeout = connectionPolicy.getIdleConnectionTimeout();

Code after addressing the review:
public Builder(ConnectionPolicy connectionPolicy) {
this.bufferPageSize = DEFAULT_OPTIONS.bufferPageSize;
this.connectionAcquisitionTimeout = DEFAULT_OPTIONS.connectionAcquisitionTimeout;
this.connectTimeout = connectionPolicy.getConnectTimeout();
this.idleChannelTimeout = connectionPolicy.getIdleTcpConnectionTimeout();
this.idleEndpointTimeout = DEFAULT_OPTIONS.idleEndpointTimeout;
this.maxBufferCapacity = DEFAULT_OPTIONS.maxBufferCapacity;
this.maxChannelsPerEndpoint = connectionPolicy.getMaxConnectionsPerEndpoint();
this.maxRequestsPerChannel = connectionPolicy.getMaxRequestsPerConnection();
this.receiveHangDetectionTime = DEFAULT_OPTIONS.receiveHangDetectionTime;
this.requestExpiryInterval = DEFAULT_OPTIONS.requestExpiryInterval;
this.requestTimeout = connectionPolicy.getRequestTimeout();
this.requestTimerResolution = DEFAULT_OPTIONS.requestTimerResolution;
this.sendHangDetectionTime = DEFAULT_OPTIONS.sendHangDetectionTime;
this.shutdownTimeout = DEFAULT_OPTIONS.shutdownTimeout;
this.threadCount = DEFAULT_OPTIONS.threadCount;
this.userAgent = DEFAULT_OPTIONS.userAgent;
}
Code review comment: Both JDK client and Netty client have to do the same logic for converting response byte array to string. It would be better to put this in Core utils somewhere to reduce duplication and if there are any fixes or updates to this logic, we don't need to update in two places.

Code before review:
public Mono<String> getBodyAsString() {
return getBodyAsByteArray().map(bytes -> {
if (bytes.length >= 3 && bytes[0] == (byte) 239 && bytes[1] == (byte) 187 && bytes[2] == (byte) 191) {
return new String(bytes, 3, bytes.length - 3, StandardCharsets.UTF_8);
} else if (bytes.length >= 2 && bytes[0] == (byte) 254 && bytes[1] == (byte) 255) {
return new String(bytes, 2, bytes.length - 2, StandardCharsets.UTF_16BE);
} else if (bytes.length >= 2 && bytes[0] == (byte) 255 && bytes[1] == (byte) 254) {
return new String(bytes, 2, bytes.length - 2, StandardCharsets.UTF_16LE);
} else {
/*
* Attempt to retrieve the default charset from the 'Content-Encoding' header, if the value isn't
* present or invalid fallback to 'UTF-8' for the default charset.
*/
try {
String contentType = reactorNettyResponse.responseHeaders()
.get("Content-Type", "charset=UTF-8");
Matcher charsetMatcher = CHARSET_PATTERN.matcher(contentType);
if (charsetMatcher.find()) {
return new String(bytes, Charset.forName(charsetMatcher.group(1)));
} else {
return new String(bytes, StandardCharsets.UTF_8);
}
} catch (IllegalCharsetNameException | UnsupportedCharsetException ex) {
return new String(bytes, StandardCharsets.UTF_8);
}
}
});
}

Line under review: return getBodyAsByteArray().map(bytes -> {

Code after addressing the review:
public Mono<String> getBodyAsString() {
return getBodyAsByteArray().map(bytes ->
CoreUtils.bomAwareToString(bytes, reactorNettyResponse.responseHeaders().get("Content-Type")));
}
Code review comment: Yes, sorry (I changed it but then accidentially rolled back together with type changes for other comment).

Code before review:
public void testMetadataOperationLogged() throws IOException {
TestingStateChangelogWriter writer = new TestingStateChangelogWriter();
InternalKeyContextImpl<String> keyContext =
new InternalKeyContextImpl<>(KeyGroupRange.of(1, 1000), 1000);
StateChangeLogger<String, Namespace> logger = getLogger(writer, keyContext);
List<Tuple2<Integer, StateChangeOperation>> expectedAppends = new ArrayList<>();
expectedAppends.add(
Tuple2.of(-1 /* see AbstractStateChangeLogger
int numOpTypes = StateChangeOperation.values().length;
for (int i = 0; i < numOpTypes * 7; i++) {
String element = Integer.toString(i);
StateChangeOperation operation = StateChangeOperation.byCode((byte) (i % numOpTypes));
log(operation, element, logger, keyContext).ifPresent(expectedAppends::add);
}
assertEquals(expectedAppends, writer.appends);
}

Line under review: Tuple2.of(-1 /* see AbstractStateChangeLogger

Code after addressing the review:
public void testMetadataOperationLogged() throws IOException {
TestingStateChangelogWriter writer = new TestingStateChangelogWriter();
InternalKeyContextImpl<String> keyContext =
new InternalKeyContextImpl<>(KeyGroupRange.of(1, 1000), 1000);
StateChangeLogger<String, Namespace> logger = getLogger(writer, keyContext);
List<Tuple2<Integer, StateChangeOperation>> expectedAppends = new ArrayList<>();
expectedAppends.add(Tuple2.of(COMMON_KEY_GROUP, METADATA));
int numOpTypes = StateChangeOperation.values().length;
for (int i = 0; i < numOpTypes * 7; i++) {
String element = Integer.toString(i);
StateChangeOperation operation = StateChangeOperation.byCode((byte) (i % numOpTypes));
log(operation, element, logger, keyContext).ifPresent(expectedAppends::add);
}
assertEquals(expectedAppends, writer.appends);
}
Code review comment: :( Waiting for a brain reboot

Code before review:
protected double maintain() {
Exception lastException = null;
int attempts = 0;
int failures = 0;
var metrics = collectClusterMetrics();
for (var application : applications.asList()) {
for (var instance : application.instances().values()) {
for (var deployment : instance.productionDeployments().values()) {
if (shuttingDown()) return 0.0;
try {
attempts++;
var bcpGroups = BcpGroup.groupsFrom(instance, application.deploymentSpec());
var patch = new ApplicationPatch();
addTrafficShare(deployment, bcpGroups, patch);
addBcpGroupInfo(deployment.zone().region(), metrics.get(instance.id()), bcpGroups, patch);
nodeRepository.patchApplication(deployment.zone(), instance.id(), patch);
}
catch (Exception e) {
failures++;
lastException = e;
}
}
}
}
double successFactorDeviation = asSuccessFactorDeviation(attempts, failures);
if ( successFactorDeviation == 1.0 )
log.log(Level.WARNING, "Could not update traffic share on any applications", lastException);
else if ( successFactorDeviation > 0.1 )
log.log(Level.FINE, "Could not update traffic share on all applications", lastException);
return successFactorDeviation;
}

Line under review: log.log(Level.FINE, "Could not update traffic share on all applications", lastException);

Code after addressing the review:
protected double maintain() {
Exception lastException = null;
int attempts = 0;
int failures = 0;
var metrics = collectClusterMetrics();
for (var application : applications.asList()) {
for (var instance : application.instances().values()) {
for (var deployment : instance.productionDeployments().values()) {
if (shuttingDown()) return 0.0;
try {
attempts++;
var bcpGroups = BcpGroup.groupsFrom(instance, application.deploymentSpec());
var patch = new ApplicationPatch();
addTrafficShare(deployment, bcpGroups, patch);
addBcpGroupInfo(deployment.zone().region(), metrics.get(instance.id()), bcpGroups, patch);
nodeRepository.patchApplication(deployment.zone(), instance.id(), patch);
}
catch (Exception e) {
failures++;
lastException = e;
}
}
}
}
double successFactorDeviation = asSuccessFactorDeviation(attempts, failures);
if ( successFactorDeviation == -successFactorBaseline )
log.log(Level.WARNING, "Could not update traffic share on any applications", lastException);
else if ( successFactorDeviation < -0.1 )
log.log(Level.FINE, "Could not update traffic share on all applications", lastException);
return successFactorDeviation;
}
Code review comment: By just looking at the code, I would say `newProducedType` should be initialized with only physical columns. Not sure what the tests say to this. But `toSourceRowDataType` includes also computed column which makes no sense for the DynamicTableSource as the source doesn't know this concept. After the spec is applied in the loop, the type changes to `PHYSICAL COLUMNS + METADATA COLUMNS`. In any case, the producedType should always contain what comes out of the source (not scan).

Code before review:
private DynamicTableSource getTableSource(FlinkContext context, FlinkTypeFactory typeFactory) {
if (tableSource == null) {
DynamicTableSourceFactory factory =
context.getModuleManager()
.getFactory(Module::getTableSourceFactory)
.orElse(null);
if (factory == null) {
Catalog catalog =
context.getCatalogManager()
.getCatalog(contextResolvedTable.getIdentifier().getCatalogName())
.orElse(null);
factory =
FactoryUtil.getDynamicTableFactory(DynamicTableSourceFactory.class, catalog)
.orElse(null);
}
tableSource =
FactoryUtil.createDynamicTableSource(
factory,
contextResolvedTable.getIdentifier(),
contextResolvedTable.getResolvedTable(),
loadOptionsFromCatalogTable(contextResolvedTable, context),
context.getTableConfig(),
context.getClassLoader(),
contextResolvedTable.isTemporary());
if (sourceAbilities != null) {
RowType newProducedType =
(RowType)
contextResolvedTable
.getResolvedSchema()
.toSourceRowDataType()
.getLogicalType();
for (SourceAbilitySpec spec : sourceAbilities) {
SourceAbilityContext sourceAbilityContext =
new SourceAbilityContext(context, typeFactory, newProducedType);
spec.apply(tableSource, sourceAbilityContext);
if (spec.getProducedType().isPresent()) {
newProducedType = spec.getProducedType().get();
}
}
}
}
return tableSource;
}

Line under review: .getLogicalType();

Code after addressing the review:
private DynamicTableSource getTableSource(FlinkContext context, FlinkTypeFactory typeFactory) {
if (tableSource == null) {
DynamicTableSourceFactory factory =
context.getModuleManager()
.getFactory(Module::getTableSourceFactory)
.orElse(null);
if (factory == null) {
Catalog catalog =
context.getCatalogManager()
.getCatalog(contextResolvedTable.getIdentifier().getCatalogName())
.orElse(null);
factory =
FactoryUtil.getDynamicTableFactory(DynamicTableSourceFactory.class, catalog)
.orElse(null);
}
tableSource =
FactoryUtil.createDynamicTableSource(
factory,
contextResolvedTable.getIdentifier(),
contextResolvedTable.getResolvedTable(),
loadOptionsFromCatalogTable(contextResolvedTable, context),
context.getTableConfig(),
context.getClassLoader(),
contextResolvedTable.isTemporary());
if (sourceAbilities != null) {
RowType newProducedType =
(RowType)
contextResolvedTable
.getResolvedSchema()
.toPhysicalRowDataType()
.getLogicalType();
for (SourceAbilitySpec spec : sourceAbilities) {
SourceAbilityContext sourceAbilityContext =
new SourceAbilityContext(context, typeFactory, newProducedType);
spec.apply(tableSource, sourceAbilityContext);
if (spec.getProducedType().isPresent()) {
newProducedType = spec.getProducedType().get();
}
}
}
}
return tableSource;
}
Code review comment: @mssfang please revert the changes where you got rid of the static import such as here. Once you've done that, please let me know what CheckStyle tests fail and we can work to modify that.

Code before review:
public void onDelivery(Event event) {
Delivery delivery = event.getDelivery();
while (delivery != null) {
Sender sender = (Sender) delivery.getLink();
if (TRACE_LOGGER.isTraceEnabled()) {
TRACE_LOGGER.trace(
"onDelivery linkName[" + sender.getName()
+ "], unsettled[" + sender.getUnsettled() + "], credit[" + sender.getRemoteCredit() + "], deliveryState[" + delivery.getRemoteState()
+ "], delivery.isBuffered[" + delivery.isBuffered() + "], delivery.id[" + new String(delivery.getTag(), StandardCharsets.UTF_8) + "]");
}
msgSender.onSendComplete(delivery);
delivery.settle();
delivery = sender.current();
}
}

Line under review: + "], delivery.isBuffered[" + delivery.isBuffered() + "], delivery.id[" + new String(delivery.getTag(), StandardCharsets.UTF_8) + "]");

Code after addressing the review:
public void onDelivery(Event event) {
Delivery delivery = event.getDelivery();
while (delivery != null) {
Sender sender = (Sender) delivery.getLink();
if (TRACE_LOGGER.isTraceEnabled()) {
TRACE_LOGGER.trace(
"onDelivery linkName[" + sender.getName()
+ "], unsettled[" + sender.getUnsettled() + "], credit[" + sender.getRemoteCredit() + "], deliveryState[" + delivery.getRemoteState()
+ "], delivery.isBuffered[" + delivery.isBuffered() + "], delivery.id[" + new String(delivery.getTag(), UTF_8) + "]");
}
msgSender.onSendComplete(delivery);
delivery.settle();
delivery = sender.current();
}
}
Code review comment: reach ```suggestion             for (ZoneId zone : controller.zoneRegistry().zones().reachable().ids()) { ```

Code before review:
private static Slime toSlime(Controller controller) {
try {
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor zonesArray = root.setArray("zones");
for (ZoneId zone : controller.zoneRegistry().zones().all().ids()) {
NodeRepoStats stats = controller.serviceRegistry().configServer().nodeRepository().getStats(zone);
if (stats.applicationStats().isEmpty()) continue;
Cursor zoneObject = zonesArray.addObject();
zoneObject.setString("id", zone.toString());
toSlime(stats.load(), zoneObject.setObject("load"));
toSlime(stats.load(), zoneObject.setObject("activeLoad"));
Cursor applicationsArray = zoneObject.setArray("applications");
for (var applicationStats : stats.applicationStats())
toSlime(applicationStats, applicationsArray.addObject());
}
return slime;
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
}

Line under review: for (ZoneId zone : controller.zoneRegistry().zones().all().ids()) {

Code after addressing the review:
private static Slime toSlime(Controller controller) {
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor zonesArray = root.setArray("zones");
for (ZoneId zone : controller.zoneRegistry().zones().reachable().ids()) {
NodeRepoStats stats = controller.serviceRegistry().configServer().nodeRepository().getStats(zone);
if (stats.applicationStats().isEmpty()) continue;
Cursor zoneObject = zonesArray.addObject();
zoneObject.setString("id", zone.toString());
toSlime(stats.load(), zoneObject.setObject("load"));
toSlime(stats.activeLoad(), zoneObject.setObject("activeLoad"));
Cursor applicationsArray = zoneObject.setArray("applications");
for (var applicationStats : stats.applicationStats())
toSlime(applicationStats, applicationsArray.addObject());
}
return slime;
}
Code review comment: It is likely that`value++` is time-consuming if there is a vast range. Here are some of my ideas. For instance,the shardings are as follows, 1,2 | 3,4,5 | 6,7,8,9 | 10,11 So the `range.partition.split.value` is `2,5,9,11` Imaging the query condition is `2 =< x <= 9`, then we just need to calcute 2==2 and 9<11, therefore the results is `0,1,2`. That is, we can get the critical values from `range.partition.split.value`, so we only need to compare the bottom point and the top point with those critical values.

Code before review:
public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Long> shardingValue) {
Preconditions.checkNotNull(properties.get(RANGE_PARTITION_SPLIT_VALUE), "Range sharding algorithm range partition split value cannot be null.");
Map<Integer, Range<Long>> partitionRangeMap = getPartitionRangeMap();
Collection<String> result = new LinkedHashSet<>(availableTargetNames.size());
for (long value = shardingValue.getValueRange().lowerEndpoint(); value <= shardingValue.getValueRange().upperEndpoint(); value++) {
for (String each : availableTargetNames) {
if (each.endsWith(getPartition(partitionRangeMap, value))) {
result.add(each);
}
}
}
return result;
}

Line under review: for (long value = shardingValue.getValueRange().lowerEndpoint(); value <= shardingValue.getValueRange().upperEndpoint(); value++) {

Code after addressing the review:
public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Long> shardingValue) {
Preconditions.checkNotNull(properties.get(RANGE_PARTITION_SPLIT_VALUE), "Range sharding algorithm range partition split value cannot be null.");
Map<Integer, Range<Long>> partitionRangeMap = getPartitionRangeMap();
Collection<String> result = new LinkedHashSet<>(availableTargetNames.size());
int lowerEndpointPartition = getPartition(partitionRangeMap, shardingValue.getValueRange().lowerEndpoint());
int upperEndpointPartition = getPartition(partitionRangeMap, shardingValue.getValueRange().upperEndpoint());
for (int partition = lowerEndpointPartition; partition <= upperEndpointPartition; partition++) {
for (String each : availableTargetNames) {
if (each.endsWith(partition + "")) {
result.add(each);
}
}
}
return result;
}
Code review comment: Hmm... good point. So far I could not figure out a solution. However I am wondering how important it is we cover all different configurations. In the end we are pretty much testing that java serialization works well here. Is that crucial that we test all possible values?

Code before review:
public void testSavepoint() throws Exception {
final Random rnd = new Random();
final byte[] locationBytes = new byte[rnd.nextInt(41) + 1];
rnd.nextBytes(locationBytes);
final SnapshotType[] snapshotTypes = {
CHECKPOINT,
FULL_CHECKPOINT,
SavepointType.savepoint(SavepointFormatType.CANONICAL),
SavepointType.suspend(SavepointFormatType.CANONICAL),
SavepointType.terminate(SavepointFormatType.CANONICAL)
};
final CheckpointOptions options =
new CheckpointOptions(
snapshotTypes[rnd.nextInt(snapshotTypes.length)],
new CheckpointStorageLocationReference(locationBytes));
final CheckpointOptions copy = CommonTestUtils.createCopySerializable(options);
assertEquals(options.getCheckpointType(), copy.getCheckpointType());
assertArrayEquals(locationBytes, copy.getTargetLocation().getReferenceBytes());
}

Line under review: };

Code after addressing the review:
public void testSavepoint() throws Exception {
final Random rnd = new Random();
final byte[] locationBytes = new byte[rnd.nextInt(41) + 1];
rnd.nextBytes(locationBytes);
final SnapshotType[] snapshotTypes = {
CHECKPOINT,
FULL_CHECKPOINT,
SavepointType.savepoint(SavepointFormatType.CANONICAL),
SavepointType.suspend(SavepointFormatType.CANONICAL),
SavepointType.terminate(SavepointFormatType.CANONICAL)
};
final CheckpointOptions options =
new CheckpointOptions(
snapshotTypes[rnd.nextInt(snapshotTypes.length)],
new CheckpointStorageLocationReference(locationBytes));
final CheckpointOptions copy = CommonTestUtils.createCopySerializable(options);
assertEquals(options.getCheckpointType(), copy.getCheckpointType());
assertArrayEquals(locationBytes, copy.getTargetLocation().getReferenceBytes());
}
Code review comment: Notable change since the last round of reviews: The documentation for `Source`'s `getCurrent`, `getCurrentRecordId` and `getCurrentTimestamp` include the following:  >      * @throws NoSuchElementException if the reader is at the beginning of the input and {@link >     *     #start} or {@link #advance} wasn't called, or if the last {@link #start} or {@link >     *     #advance} returned {@code false}.  This states that if `advance()` returns `false`, subsequent calls to these should throw `NoSuchElementException`. As such, I'm explicitly setting these to `null`.

Code before review:
public boolean advance() throws IOException {
try {
Channel channel = connectionHandler.getChannel();
GetResponse delivery = channel.basicGet(queueName, false);
if (delivery == null) {
current = null;
currentRecordId = null;
currentTimestamp = null;
checkpointMark.advanceWatermark(Instant.now());
return false;
}
if (source.spec.useCorrelationId()) {
String correlationId = delivery.getProps().getCorrelationId();
if (correlationId == null) {
throw new IOException(
"RabbitMqIO.Read uses message correlation ID, but received "
+ "message has a null correlation ID");
}
currentRecordId = correlationId.getBytes(StandardCharsets.UTF_8);
}
long deliveryTag = delivery.getEnvelope().getDeliveryTag();
checkpointMark.sessionIds.add(deliveryTag);
current = new RabbitMqMessage(source.spec.routingKey(), delivery);
Date deliveryTimestamp = delivery.getProps().getTimestamp();
currentTimestamp =
(deliveryTimestamp != null) ? new Instant(deliveryTimestamp) : Instant.now();
checkpointMark.advanceWatermark(currentTimestamp);
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
return true;
}

Line under review: current = null;

Code after addressing the review:
public boolean advance() throws IOException {
try {
Channel channel = connectionHandler.getChannel();
GetResponse delivery = channel.basicGet(queueName, false);
if (delivery == null) {
current = null;
currentRecordId = null;
currentTimestamp = null;
checkpointMark.advanceWatermark(Instant.now());
return false;
}
if (source.spec.useCorrelationId()) {
String correlationId = delivery.getProps().getCorrelationId();
if (correlationId == null) {
throw new IOException(
"RabbitMqIO.Read uses message correlation ID, but received "
+ "message has a null correlation ID");
}
currentRecordId = correlationId.getBytes(StandardCharsets.UTF_8);
}
long deliveryTag = delivery.getEnvelope().getDeliveryTag();
checkpointMark.sessionIds.add(deliveryTag);
current = new RabbitMqMessage(source.spec.routingKey(), delivery);
Date deliveryTimestamp = delivery.getProps().getTimestamp();
currentTimestamp =
(deliveryTimestamp != null) ? new Instant(deliveryTimestamp) : Instant.now();
checkpointMark.advanceWatermark(currentTimestamp);
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
return true;
}
Code review comment: @malinthar let's push this as a separate PR. 

Code before review:
private List<PackageInfo> getPackagesFromRepository(PackageRepository repository, List<String> skipList) {
Map<String, List<String>> packageMap = repository.getPackages();
List<PackageInfo> packages = new ArrayList<>();
packageMap.forEach((key, value) -> {
if (key.equals(Names.BALLERINA_INTERNAL_ORG.getValue())) {
return;
}
value.forEach(nameEntry -> {
String[] components = nameEntry.split(":");
if (components.length != 2 || skipList.contains(components[0])) {
return;
}
String nameComponent = components[0];
String version = components[1];
PackageOrg packageOrg = PackageOrg.from(key);
PackageName packageName = PackageName.from(nameComponent);
PackageVersion pkgVersion = PackageVersion.from(version);
try {
PackageDescriptor pkdDesc = PackageDescriptor.from(packageOrg, packageName, pkgVersion);
ResolutionRequest request = ResolutionRequest.from(pkdDesc, PackageDependencyScope.DEFAULT);
Optional<Package> repoPackage = repository.getPackage(request,
ResolutionOptions.builder().setOffline(true).build());
repoPackage.ifPresent(pkg -> packages.add(new PackageInfo(pkg)));
} catch (Throwable e) {
clientLogger.logTrace("Failed to resolve package "
+ packageOrg + (!packageOrg.value().isEmpty() ? "/" : ""
+ packageName + ":" + pkgVersion));
}
});
});
return packages;
}

Line under review: clientLogger.logTrace("Failed to resolve package "

Code after addressing the review:
private List<PackageInfo> getPackagesFromRepository(PackageRepository repository, List<String> skipList) {
Map<String, List<String>> packageMap = repository.getPackages();
List<PackageInfo> packages = new ArrayList<>();
packageMap.forEach((key, value) -> {
if (key.equals(Names.BALLERINA_INTERNAL_ORG.getValue())) {
return;
}
value.forEach(nameEntry -> {
String[] components = nameEntry.split(":");
if (components.length != 2 || skipList.contains(components[0])) {
return;
}
String nameComponent = components[0];
String version = components[1];
PackageOrg packageOrg = PackageOrg.from(key);
PackageName packageName = PackageName.from(nameComponent);
PackageVersion pkgVersion = PackageVersion.from(version);
try {
PackageDescriptor pkdDesc = PackageDescriptor.from(packageOrg, packageName, pkgVersion);
ResolutionRequest request = ResolutionRequest.from(pkdDesc, PackageDependencyScope.DEFAULT);
Optional<Package> repoPackage = repository.getPackage(request,
ResolutionOptions.builder().setOffline(true).build());
repoPackage.ifPresent(pkg -> packages.add(new PackageInfo(pkg)));
} catch (Throwable e) {
clientLogger.logTrace("Failed to resolve package "
+ packageOrg + (!packageOrg.value().isEmpty() ? "/" : ""
+ packageName + ":" + pkgVersion));
}
});
});
return packages;
}
Code review comment: I think we should stop discussing this here; this is relevant for the entirety of the documentation, and we could get much more experienced people involved if we target that instead.

Code before review:
private static Set<String> findEnabledReportersInConfiguration(Configuration configuration, String includedReportersString) {
Set<String> includedReporters = reporterListPattern.splitAsStream(includedReportersString)
.filter(r -> !r.isEmpty())
.collect(Collectors.toSet());
Set<String> namedOrderedReporters = new TreeSet<>(String::compareTo);
for (String key : configuration.keySet()) {
if (key.startsWith(ConfigConstants.METRICS_REPORTER_PREFIX)) {
Matcher matcher = reporterClassPattern.matcher(key);
if (matcher.matches()) {
String reporterName = matcher.group(1);
if (includedReporters.isEmpty() || includedReporters.contains(reporterName)) {
if (namedOrderedReporters.contains(reporterName)) {
LOG.warn("Duplicate class configuration detected for reporter {}.", reporterName);
} else {
namedOrderedReporters.add(reporterName);
}
} else {
LOG.info("Excluding reporter {}, not configured in reporter list ({}).", reporterName, includedReportersString);
}
}
}
}
return namedOrderedReporters;
}

Line under review: LOG.info("Excluding reporter {}, not configured in reporter list ({}).", reporterName, includedReportersString);

Code after addressing the review:
private static Set<String> findEnabledReportersInConfiguration(Configuration configuration, String includedReportersString) {
Set<String> includedReporters = reporterListPattern.splitAsStream(includedReportersString)
.filter(r -> !r.isEmpty())
.collect(Collectors.toSet());
Set<String> namedOrderedReporters = new TreeSet<>(String::compareTo);
for (String key : configuration.keySet()) {
if (key.startsWith(ConfigConstants.METRICS_REPORTER_PREFIX)) {
Matcher matcher = reporterClassPattern.matcher(key);
if (matcher.matches()) {
String reporterName = matcher.group(1);
if (includedReporters.isEmpty() || includedReporters.contains(reporterName)) {
if (namedOrderedReporters.contains(reporterName)) {
LOG.warn("Duplicate class configuration detected for reporter {}.", reporterName);
} else {
namedOrderedReporters.add(reporterName);
}
} else {
LOG.info("Excluding reporter {}, not configured in reporter list ({}).", reporterName, includedReportersString);
}
}
}
}
return namedOrderedReporters;
}
Code review comment: The output seems to be wrong. For the combination where Dependencies.toml exists and --sticky flag is given, we don't update automatically. Instead, we give a hint asking the user to set sticky to false.

Code before review:
public void testBuildProjectPrecompiledWithOlderDistWithStickyFlag() throws IOException {
Path projectPath = testResources.resolve("dep-dist-version-projects").resolve("preCompiledPackage");
replaceDependenciesTomlContent(projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", "2201.5.0");
System.setProperty("user.dir", projectPath.toString());
BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false);
new CommandLine(buildCommand).parseArgs("--sticky");
buildCommand.execute();
String buildLog = readOutput(true);
Assert.assertEquals(
buildLog.replaceAll("\r", ""),
getOutput("build-old-dist-precomp-proj-with-dep.txt")
.replaceAll("INSERT_NEW_DIST_VERSION_HERE", getNewVersionForOldDistWarning())
.replaceAll("INSERT_OLD_DIST_VERSION_HERE", getOldVersionForOldDistWarning("2201.5.0")));
Path actualDependenciesToml = projectPath.resolve("Dependencies.toml");
Path expectedDependenciesToml = testResources.resolve("dep-dist-version-projects").resolve("expected-dep-tomls")
.resolve("precomp-pkg-with-sticky.toml");
Assert.assertTrue(actualDependenciesToml.toFile().exists());
assertTomlFilesEquals(actualDependenciesToml, expectedDependenciesToml);
replaceDependenciesTomlContent(projectPath, RepoUtils.getBallerinaShortVersion(),
"**INSERT_DISTRIBUTION_VERSION_HERE**");
deleteDirectory(projectPath.resolve("target"));
}

Line under review: .replaceAll("INSERT_OLD_DIST_VERSION_HERE", getOldVersionForOldDistWarning("2201.5.0")));

Code after addressing the review:
public void testBuildProjectPrecompiledWithOlderDistWithStickyFlag() throws IOException {
Path projectPath = testResources.resolve("dep-dist-version-projects").resolve("preCompiledPackage");
replaceDependenciesTomlContent(projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", "2201.5.0");
System.setProperty("user.dir", projectPath.toString());
BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false);
new CommandLine(buildCommand).parseArgs("--sticky");
buildCommand.execute();
String buildLog = readOutput(true);
Assert.assertEquals(
buildLog.replaceAll("\r", ""),
getOutput("build-old-dist-precomp-proj-with-sticky.txt")
.replaceAll("INSERT_NEW_DIST_VERSION_HERE", getNewVersionForOldDistWarning())
.replaceAll("INSERT_OLD_DIST_VERSION_HERE", getOldVersionForOldDistWarning("2201.5.0")));
Path actualDependenciesToml = projectPath.resolve("Dependencies.toml");
Path expectedDependenciesToml = testResources.resolve("dep-dist-version-projects").resolve("expected-dep-tomls")
.resolve("precomp-pkg-with-sticky.toml");
Assert.assertTrue(actualDependenciesToml.toFile().exists());
assertTomlFilesEquals(actualDependenciesToml, expectedDependenciesToml);
replaceDependenciesTomlContent(projectPath, RepoUtils.getBallerinaShortVersion(),
"**INSERT_DISTRIBUTION_VERSION_HERE**");
deleteDirectory(projectPath.resolve("target"));
}
Code review comment: Immutable expression should not has mutable field. if we need some mutable state, we should depend the expression type to compute state, and change it when replace children  e.g. UnboundExression.isAnalyzed() = false. other expression.isAnalyzed() = Suppliers.memoized(() -> children().allMatch(Expression::isAnalyzed)).

Code before review:
public List<Rule> buildRules() {
return ImmutableList.of(
RuleType.ANALYZE_PROJECT_SUBQUERY.build(
logicalProject().thenApply(ctx -> {
LogicalProject<GroupPlan> project = ctx.root;
List<SubqueryExpr> subqueryExprs = new ArrayList<>();
project.getProjects()
.forEach(expr -> subqueryExprs.addAll(extractSubquery(expr)));
if (subqueryExprs.size() == 0) {
return project;
}
return new LogicalProject(project.getProjects(),
analyzedSubquery(subqueryExprs,
project.child(), ctx.plannerContext));
})
),
RuleType.ANALYZE_FILTER_SUBQUERY.build(
logicalFilter().thenApply(ctx -> {
LogicalFilter<GroupPlan> filter = ctx.root;
List<SubqueryExpr> subqueryExprs = extractSubquery(filter.getPredicates());
if (subqueryExprs.size() == 0) {
return filter;
}
return new LogicalFilter<>(filter.getPredicates(),
analyzedSubquery(subqueryExprs,
filter.child(), ctx.plannerContext));
})
),
RuleType.ANALYZE_AGGREGATE_SUBQUERY.build(
logicalAggregate().thenApply(ctx -> {
LogicalAggregate<GroupPlan> agg = ctx.root;
List<SubqueryExpr> subqueryExprs = new ArrayList<>();
agg.getGroupByExpressions().forEach(expr -> subqueryExprs.addAll(extractSubquery(expr)));
agg.getOutputExpressions().forEach(expr -> subqueryExprs.addAll(extractSubquery(expr)));
if (subqueryExprs.size() == 0) {
return agg;
}
return new LogicalAggregate<>(agg.getGroupByExpressions(), agg.getOutputExpressions(),
agg.isDisassembled(), agg.getAggPhase(),
analyzedSubquery(subqueryExprs, agg.child(), ctx.plannerContext));
})
),
RuleType.ANALYZE_SORT_SUBQUERY.build(
logicalSort().thenApply(ctx -> {
LogicalSort<GroupPlan> sort = ctx.root;
List<SubqueryExpr> subqueryExprs = new ArrayList<>();
sort.getOrderKeys().forEach(orderKey -> subqueryExprs.addAll(extractSubquery(
orderKey.getExpr())));
if (subqueryExprs.size() == 0) {
return sort;
}
return new LogicalSort<>(sort.getOrderKeys(),
analyzedSubquery(subqueryExprs, sort.child(), ctx.plannerContext));
})
)
);
}

Line under review: RuleType.ANALYZE_SORT_SUBQUERY.build(

Code after addressing the review:
public List<Rule> buildRules() {
return ImmutableList.of(
RuleType.ANALYZE_FILTER_SUBQUERY.build(
logicalFilter().thenApply(ctx -> {
LogicalFilter filter = ctx.root;
List<SubqueryExpr> subqueryExprs = filter.getPredicates()
.collect(SubqueryExpr.class::isInstance);
if (subqueryExprs.isEmpty()) {
return filter;
}
return new LogicalFilter<>(new ReplaceSubquery().replace(filter.getPredicates()),
analyzedSubquery(
subqueryExprs, (LogicalPlan) filter.child(), ctx.cascadesContext
));
})
)
);
}
Code review comment: We should generally avoid the use of [magic number ](https://stackoverflow.com/questions/47882/what-is-a-magic-number-and-why-is-it-bad) and replace it with what it stands for.

Code before review:
public static String parseOperationId(String operationLocation) {
if (!CoreUtils.isNullOrEmpty(operationLocation)) {
int lastIndex = operationLocation.lastIndexOf('/');
if (lastIndex != -1) {
return operationLocation.substring(lastIndex + 1, lastIndex + 37);
}
}
throw LOGGER.logExceptionAsError(
new RuntimeException("Failed to parse operation header for operation Id from: " + operationLocation));
}

Line under review: return operationLocation.substring(lastIndex + 1, lastIndex + 37);

Code after addressing the review:
public static String parseOperationId(String operationLocation) {
if (!CoreUtils.isNullOrEmpty(operationLocation)) {
final int indexBeforeOperationId = operationLocation.lastIndexOf('/');
if (indexBeforeOperationId != -1) {
return operationLocation.substring(indexBeforeOperationId + 1,
indexBeforeOperationId + OPERATION_ID_LENGTH);
}
}
throw LOGGER.logExceptionAsError(
new RuntimeException("Failed to parse operation header for operation Id from: " + operationLocation));
}
Code review comment: If the cluster is using FQDN, but the host specified in the external OLAP table is IP, this check will not work. But I think it's OK to keep this simple logic, because creating OLAP External table mapping to self is a rare case, and using FQDN but specified IP is rare too.

Code before review:
public boolean checkFeExistByRPCPort(String host, int rpcPort) {
try {
tryLock(true);
return frontends
.values()
.stream()
.anyMatch(fe -> fe.getHost().equals(host) && fe.getRpcPort() == rpcPort);
} finally {
unlock();
}
}

Line under review: .anyMatch(fe -> fe.getHost().equals(host) && fe.getRpcPort() == rpcPort);

Code after addressing the review:
public boolean checkFeExistByRPCPort(String host, int rpcPort) {
try {
tryLock(true);
return frontends
.values()
.stream()
.anyMatch(fe -> fe.getHost().equals(host) && fe.getRpcPort() == rpcPort);
} finally {
unlock();
}
}
Code review comment: There are more than one `JandexUtil` used inside the enhancer ? Stange ...

Code before review:
private String recursivelyFindEntityTypeFromClass(DotName clazz, DotName repositoryDotName) {
if (clazz.equals(OBJECT_DOT_NAME)) {
return null;
}
List<org.jboss.jandex.Type> typeParameters = io.quarkus.deployment.util.JandexUtil
.resolveTypeParameters(clazz, repositoryDotName, indexView);
if (typeParameters.isEmpty())
throw new IllegalStateException(
"Failed to find supertype " + repositoryDotName + " from entity class " + clazz);
org.jboss.jandex.Type entityType = typeParameters.get(0);
return entityType.name().toString().replace('.', '/');
}

Line under review: List<org.jboss.jandex.Type> typeParameters = io.quarkus.deployment.util.JandexUtil

Code after addressing the review:
private String recursivelyFindEntityTypeFromClass(DotName clazz, DotName repositoryDotName) {
if (clazz.equals(OBJECT_DOT_NAME)) {
return null;
}
List<org.jboss.jandex.Type> typeParameters = io.quarkus.deployment.util.JandexUtil
.resolveTypeParameters(clazz, repositoryDotName, indexView);
if (typeParameters.isEmpty())
throw new IllegalStateException(
"Failed to find supertype " + repositoryDotName + " from entity class " + clazz);
org.jboss.jandex.Type entityType = typeParameters.get(0);
return entityType.name().toString().replace('.', '/');
}
Code review comment: Variable name of `describeStatement` should be `result`.

Code before review:
public ASTNode visitDesc(final DescContext ctx) {
TableSegment tablename = (TableSegment) visit(ctx.tableName());
DescribeStatement describeStatement = new DescribeStatement();
describeStatement.setTableName(tablename);
return describeStatement;
}

Line under review: DescribeStatement describeStatement = new DescribeStatement();

Code after addressing the review:
public ASTNode visitDesc(final DescContext ctx) {
TableSegment table = (TableSegment) visit(ctx.tableName());
DescribeStatement result = new DescribeStatement();
result.setTable(table);
return result;
}
Code review comment: maybe a enum is better than a boolean

Code before review:
public SortItems genSortItems(SortItemContext ctx) {
boolean orderDirection = true;
if (ctx.DESC() != null) {
orderDirection = false;
} else {
orderDirection = true;
}
Expression expression = typedVisit(ctx.expression());
NamedExpression namedExpression;
if (expression instanceof NamedExpression) {
namedExpression =  (NamedExpression) expression;
} else {
namedExpression =  new UnboundAlias(expression);
}
return new SortItems(namedExpression, orderDirection);
}

Line under review: orderDirection = false;

Code after addressing the review:
public SortItems genSortItems(SortItemContext ctx) {
OrderDirection orderDirection;
if (ctx.DESC() != null) {
orderDirection = OrderDirection.DESC;
} else {
orderDirection = OrderDirection.ASC;
}
Expression expression = typedVisit(ctx.expression());
return new SortItems(expression, orderDirection);
}
Code review comment: If the thread is still alive, do we also need to `Thread.currentThread().interrupt()`?

Code before review:
public void close() throws IOException {
wasClosed = true;
while (thread.isAlive()) {
thread.interrupt();
try {
thread.join();
} catch (InterruptedException e) {
if (!thread.isAlive()) {
Thread.currentThread().interrupt();
}
LOG.debug("interrupted while waiting for the writer thread to die", e);
}
}
if (thrown != null) {
throw new IOException(thrown);
}
}

Line under review: thread.interrupt();

Code after addressing the review:
public void close() throws IOException {
wasClosed = true;
while (thread.isAlive()) {
thread.interrupt();
try {
thread.join();
} catch (InterruptedException e) {
if (!thread.isAlive()) {
Thread.currentThread().interrupt();
}
LOG.debug("interrupted while waiting for the writer thread to die", e);
}
}
if (thrown != null) {
throw new IOException(thrown);
}
}
Code review comment: Can we move this line into the open method?

Code before review:
public void emitResults() throws IOException {
byte[] udfResult;
while ((udfResult = userDefinedFunctionResultQueue.poll()) != null) {
bais.setBuffer(udfResult, 0, udfResult.length);
reader.loadNextBatch();
VectorSchemaRoot root = reader.getVectorSchemaRoot();
if (arrowReader == null) {
arrowReader = ArrowUtils.createBaseRowArrowReader(root);
}
for (int i = 0; i < root.getRowCount(); i++) {
BaseRow input = forwardedInputQueue.poll();
reuseJoinedRow.setHeader(input.getHeader());
baseRowWrapper.collect(reuseJoinedRow.replace(input, arrowReader.read(i)));
}
}
}

Line under review: arrowReader = ArrowUtils.createBaseRowArrowReader(root);

Code after addressing the review:
public void emitResults() throws IOException {
byte[] udfResult;
while ((udfResult = userDefinedFunctionResultQueue.poll()) != null) {
bais.setBuffer(udfResult, 0, udfResult.length);
reader.loadNextBatch();
VectorSchemaRoot root = reader.getVectorSchemaRoot();
if (arrowReader == null) {
arrowReader = ArrowUtils.createBaseRowArrowReader(root);
}
for (int i = 0; i < root.getRowCount(); i++) {
BaseRow input = forwardedInputQueue.poll();
reuseJoinedRow.setHeader(input.getHeader());
baseRowWrapper.collect(reuseJoinedRow.replace(input, arrowReader.read(i)));
}
}
}
Code review comment: I did another deep search - I found one case in SQL's codegen which I fixed, but can't find anything else.

Code before review:
private static List<TableFieldSchema> toTableFieldSchema(Schema schema) {
List<TableFieldSchema> fields = new ArrayList<>(schema.getFieldCount());
for (Field schemaField : schema.getFields()) {
FieldType type = schemaField.getType();
TableFieldSchema field = new TableFieldSchema().setName(schemaField.getName());
if (schemaField.getDescription() != null && !"".equals(schemaField.getDescription())) {
field.setDescription(schemaField.getDescription());
}
if (!schemaField.getType().getNullable()) {
field.setMode(Mode.REQUIRED.toString());
}
if (type.getTypeName().isCollectionType()) {
type = type.getCollectionElementType();
if (type.getTypeName().isCollectionType() || type.getTypeName().isMapType()) {
throw new IllegalArgumentException("Array of collection is not supported in BigQuery.");
}
field.setMode(Mode.REPEATED.toString());
}
if (TypeName.ROW == type.getTypeName()) {
Schema subType = type.getRowSchema();
field.setFields(toTableFieldSchema(subType));
}
if (TypeName.MAP == type.getTypeName()) {
throw new IllegalArgumentException("Maps are not supported in BigQuery.");
}
field.setType(toStandardSQLTypeName(type).toString());
fields.add(field);
}
return fields;
}

Line under review: if (type.getTypeName().isCollectionType()) {

Code after addressing the review:
private static List<TableFieldSchema> toTableFieldSchema(Schema schema) {
List<TableFieldSchema> fields = new ArrayList<>(schema.getFieldCount());
for (Field schemaField : schema.getFields()) {
FieldType type = schemaField.getType();
TableFieldSchema field = new TableFieldSchema().setName(schemaField.getName());
if (schemaField.getDescription() != null && !"".equals(schemaField.getDescription())) {
field.setDescription(schemaField.getDescription());
}
if (!schemaField.getType().getNullable()) {
field.setMode(Mode.REQUIRED.toString());
}
if (type.getTypeName().isCollectionType()) {
type = type.getCollectionElementType();
if (type.getTypeName().isCollectionType() || type.getTypeName().isMapType()) {
throw new IllegalArgumentException("Array of collection is not supported in BigQuery.");
}
field.setMode(Mode.REPEATED.toString());
}
if (TypeName.ROW == type.getTypeName()) {
Schema subType = type.getRowSchema();
field.setFields(toTableFieldSchema(subType));
}
if (TypeName.MAP == type.getTypeName()) {
throw new IllegalArgumentException("Maps are not supported in BigQuery.");
}
field.setType(toStandardSQLTypeName(type).toString());
fields.add(field);
}
return fields;
}
Code review comment: Hi @totalo  This change causes build failed on JDK11 and JDK17. Is there any problem before? ``` [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project shardingsphere-infra-common: Compilation failure [ERROR] /Users/wuweijie/IdeaProjects/shardingsphere/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/SchemaYamlSwapper.java:[48,25] incompatible types: java.lang.Object cannot be converted to java.util.Map<java.lang.String,org.apache.shardingsphere.infra.yaml.schema.pojo.YamlTableMetaData> [ERROR]  [ERROR] -> [Help 1] [ERROR]  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR]  [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [ERROR]  [ERROR] After correcting the problems, you can resume the build with the command [ERROR]   mvn <args> -rf :shardingsphere-infra-common ```

Code before review:
public YamlSchema swapToYamlConfiguration(final ShardingSphereSchema schema) {
Map<String, YamlTableMetaData> tables = schema.getAllTableNames().stream()
.collect(Collectors.<String, String, YamlTableMetaData, Map>toMap(each -> each, each -> swapYamlTable(schema.get(each)), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
YamlSchema result = new YamlSchema();
result.setTables(tables);
return result;
}

Line under review: .collect(Collectors.<String, String, YamlTableMetaData, Map>toMap(each -> each, each -> swapYamlTable(schema.get(each)), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));

Code after addressing the review:
public YamlSchema swapToYamlConfiguration(final ShardingSphereSchema schema) {
Map<String, YamlTableMetaData> tables = schema.getAllTableNames().stream()
.collect(Collectors.<String, String, YamlTableMetaData, Map>toMap(each -> each, each -> swapYamlTable(schema.get(each)), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
YamlSchema result = new YamlSchema();
result.setTables(tables);
return result;
}
Code review comment: consider putting `UnregisteredMetricGroups.createUnregisteredJobManagerJobMetricGroup()` into some static variable and using that.

Code before review:
void testRegisterConsumedPartitionGroupToEdgeManager() throws Exception {
JobVertex v1 = new JobVertex("source");
JobVertex v2 = new JobVertex("sink");
v1.setParallelism(2);
v2.setParallelism(2);
v2.connectNewDataSetAsInput(
v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);
List<JobVertex> ordered = new ArrayList<>(Arrays.asList(v1, v2));
ExecutionGraph eg = createDefaultExecutionGraph(ordered);
eg.attachJobGraph(
ordered, UnregisteredMetricGroups.createUnregisteredJobManagerJobMetricGroup());
IntermediateResult result =
Objects.requireNonNull(eg.getJobVertex(v1.getID())).getProducedDataSets()[0];
IntermediateResultPartition partition1 = result.getPartitions()[0];
IntermediateResultPartition partition2 = result.getPartitions()[1];
assertThat(partition2.getConsumedPartitionGroups().get(0))
.isEqualTo(partition1.getConsumedPartitionGroups().get(0));
ConsumedPartitionGroup consumedPartitionGroup =
partition1.getConsumedPartitionGroups().get(0);
Set<IntermediateResultPartitionID> partitionIds = new HashSet<>();
for (IntermediateResultPartitionID partitionId : consumedPartitionGroup) {
partitionIds.add(partitionId);
}
assertThat(partitionIds)
.containsExactlyInAnyOrder(
partition1.getPartitionId(), partition2.getPartitionId());
}

Line under review: ordered, UnregisteredMetricGroups.createUnregisteredJobManagerJobMetricGroup());

Code after addressing the review:
void testRegisterConsumedPartitionGroupToEdgeManager() throws Exception {
JobVertex v1 = new JobVertex("source");
JobVertex v2 = new JobVertex("sink");
v1.setParallelism(2);
v2.setParallelism(2);
v2.connectNewDataSetAsInput(
v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);
List<JobVertex> ordered = new ArrayList<>(Arrays.asList(v1, v2));
ExecutionGraph eg = createDefaultExecutionGraph(ordered);
eg.attachJobGraph(ordered, JOB_MANAGER_JOB_METRIC_GROUP);
IntermediateResult result =
Objects.requireNonNull(eg.getJobVertex(v1.getID())).getProducedDataSets()[0];
IntermediateResultPartition partition1 = result.getPartitions()[0];
IntermediateResultPartition partition2 = result.getPartitions()[1];
assertThat(partition2.getConsumedPartitionGroups().get(0))
.isEqualTo(partition1.getConsumedPartitionGroups().get(0));
ConsumedPartitionGroup consumedPartitionGroup =
partition1.getConsumedPartitionGroups().get(0);
Set<IntermediateResultPartitionID> partitionIds = new HashSet<>();
for (IntermediateResultPartitionID partitionId : consumedPartitionGroup) {
partitionIds.add(partitionId);
}
assertThat(partitionIds)
.containsExactlyInAnyOrder(
partition1.getPartitionId(), partition2.getPartitionId());
}