muttakin2301/ccr2000 huggingface dataset:
Code review comment: It's very minor but could we call it `MONGODB_PANACHE` as the feature? See a few lines below.

Code under review:
CapabilityBuildItem capability() {
        return new CapabilityBuildItem(Capabilities.MONGO_PANACHE);
    }

Line commented on: return new CapabilityBuildItem(Capabilities.MONGO_PANACHE);

Revised code:
CapabilityBuildItem capability() {
        return new CapabilityBuildItem(Capabilities.MONGODB_PANACHE);
    }
Code review comment: should  be wrapped in a try-catch block

Code under review:
public void testLogicalScopeShouldIgnoreValueGroupName() {
		Configuration config = new Configuration();
		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());
		MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));
		GenericMetricGroup root = new GenericMetricGroup(registry, new DummyAbstractMetricGroup(registry), "root");

		String key = "key";
		String value = "value";

		MetricGroup group = root.addGroup(key, value);

		String logicalScope = ((AbstractMetricGroup) group)
			.getLogicalScope(new DummyCharacterFilter(), registry.getDelimiter(), 0);
		assertTrue("Key is missing from logical scope.", logicalScope.contains(key));
		assertFalse("Value is present in logical scope.", logicalScope.contains(value));
	}

Line commented on: MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));

Revised code:
public void testLogicalScopeShouldIgnoreValueGroupName() throws Exception {
		Configuration config = new Configuration();
		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());

		MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));
		try {
			GenericMetricGroup root = new GenericMetricGroup(registry, new DummyAbstractMetricGroup(registry), "root");

			String key = "key";
			String value = "value";

			MetricGroup group = root.addGroup(key, value);

			String logicalScope = ((AbstractMetricGroup) group)
				.getLogicalScope(new DummyCharacterFilter(), registry.getDelimiter(), 0);
			assertThat("Key is missing from logical scope.", logicalScope, containsString(key));
			assertThat("Value is present in logical scope.", logicalScope, not(containsString(value)));
		} finally {
			registry.shutdown().get();
		}
	}
Code review comment: throw new DdlException("Failed to remove worker. error: " + e.getMessage());

Code under review:
public void removeWorker(String workerIpPort) throws StarClientException {
        long workerId = -1;
        
        try {
            WorkerInfo workerInfo = client.getWorkerInfo(serviceId, workerIpPort);
            workerId = workerInfo.getWorkerId();
        } catch (StarClientException e2) {
            LOG.warn(e2);
            return;
        }

        try {
            client.removeWorker(serviceId, workerId);
        } catch (StarClientException e) {
            if (e.getCode() != StarClientException.ExceptionCode.NOT_EXIST) {
                throw new StarClientException(e.getCode(), "remove worker error");
            }
        }

        workerToBackend.remove(workerId);
        workerToId.remove(workerIpPort);
        LOG.info("remove worker {} success in StarOSAgent", workerIpPort);
    }

Line commented on: throw new StarClientException(e.getCode(), "remove worker error");

Revised code:
public void removeWorker(String workerIpPort) throws DdlException {
        long workerId = -1;
        if (workerToId.containsKey(workerIpPort)) {
            workerId = workerToId.get(workerIpPort);
        } else {
            
            
            try {
                WorkerInfo workerInfo = client.getWorkerInfo(serviceId, workerIpPort);
                workerId = workerInfo.getWorkerId();
            } catch (StarClientException e) {
                if (e.getCode() != StarClientException.ExceptionCode.NOT_EXIST) {
                    throw new DdlException("Failed to get worker id from starMgr. error: "
                            + e.getMessage());
                }

                LOG.info("worker {} not exist.", workerIpPort);
                return;
            }
        }

        try {
            client.removeWorker(serviceId, workerId);
        } catch (StarClientException e) {
            
            
            
            if (e.getCode() != StarClientException.ExceptionCode.NOT_EXIST) {
                throw new DdlException("Failed to remove worker. error: " + e.getMessage());
            }
        }

        workerToBackend.remove(workerId);
        workerToId.remove(workerIpPort);
        LOG.info("remove worker {} success from StarMgr", workerIpPort);
    }
Code review comment: ten parameters in a constructor, this is not that  elegant

Code under review:
private DataSourceParameter crateDataSourceParameter() {
        return new DataSourceParameter("jdbc:mysql:
    }

Line commented on: return new DataSourceParameter("jdbc:mysql:

Revised code:
private DataSourceParameter crateDataSourceParameter() {
        return new DataSourceParameter("jdbc:mysql:
    }
Code review comment: @bobby-richard Have a look at https://issues.apache.org/jira/browse/FLINK-29267

Code under review:
protected JdbcSerializationConverter createExternalConverter(LogicalType type) {
        switch (type.getTypeRoot()) {
            case CHAR:
            case VARCHAR:
                return (val, index, statement) -> {
                    String valString = val.getString(index).toString();

                    if (UUID_REGEX_PATTERN.matcher(valString).matches()) {
                        statement.setObject(index, UUID.fromString(valString));
                    } else {
                        statement.setString(index, valString);
                    }
                };
        }

        return super.createExternalConverter(type);
    }

Line commented on: if (UUID_REGEX_PATTERN.matcher(valString).matches()) {

Revised code:
protected JdbcSerializationConverter createExternalConverter(LogicalType type) {
        switch (type.getTypeRoot()) {
            case CHAR:
            case VARCHAR:
                return (val, index, statement) -> {
                    String valString = val.getString(index).toString();

                    if (UUID_REGEX_PATTERN.matcher(valString).matches()) {
                        statement.setObject(index, UUID.fromString(valString));
                    } else {
                        statement.setString(index, valString);
                    }
                };
        }

        return super.createExternalConverter(type);
    }
Code review comment: This is how the cool kids on the street do it

Code under review:
private static void addRestApiHandler(ContainerCluster<?> cluster, Options options) {
        String handlerClassName = options.useNewRestapiHandler
                ? "com.yahoo.document.restapi.resource.DocumentV1ApiHandler"
                : "com.yahoo.document.restapi.resource.RestApi";
        var handler = newVespaClientHandler(handlerClassName, "/document/v1/*", options);
        cluster.addComponent(handler);
        if (!options.useNewRestapiHandler) {
            var executor = new Threadpool(
                    "restapi-handler", cluster, options.restApiThreadpoolOptions, options.feedThreadPoolSizeFactor);
            handler.inject(executor);
            handler.addComponent(executor);
        }
    }

Line commented on: handler.inject(executor);

Revised code:
private static void addRestApiHandler(ContainerCluster<?> cluster, Options options) {
        String handlerClassName = options.useNewRestapiHandler
                ? "com.yahoo.document.restapi.resource.DocumentV1ApiHandler"
                : "com.yahoo.document.restapi.resource.RestApi";
        var handler = newVespaClientHandler(handlerClassName, "/document/v1/*", options);
        cluster.addComponent(handler);
        if (!options.useNewRestapiHandler) {
            var executor = new Threadpool(
                    "restapi-handler", cluster, options.restApiThreadpoolOptions, options.feedThreadPoolSizeFactor);
            handler.inject(executor);
            handler.addComponent(executor);
        }
    }
Code review comment: We should use default values if `locationHeader` and `allowedMethods` are null or *empty* and document it.

Code under review:
public DefaultRedirectStrategy(int maxAttempts, String locationHeader, Set<HttpMethod> allowedMethods) {
        if (maxAttempts < 0) {
            throw logger.logExceptionAsError(new IllegalArgumentException("Max attempts cannot be less than 0."));
        }
        this.maxAttempts = maxAttempts;
        this.locationHeader = locationHeader == null ? DEFAULT_REDIRECT_LOCATION_HEADER_NAME : locationHeader;
        this.redirectMethods = allowedMethods == null ? DEFAULT_REDIRECT_ALLOWED_METHODS : allowedMethods;
    }

Line commented on: this.redirectMethods = allowedMethods == null ? DEFAULT_REDIRECT_ALLOWED_METHODS : allowedMethods;

Revised code:
public DefaultRedirectStrategy(int maxAttempts, String locationHeader, Set<HttpMethod> allowedMethods) {
        if (maxAttempts < 0) {
            throw logger.logExceptionAsError(new IllegalArgumentException("Max attempts cannot be less than 0."));
        }
        this.maxAttempts = maxAttempts;
        if (CoreUtils.isNullOrEmpty(locationHeader)) {
            logger.error("'locationHeader' provided as null will be defaulted to {}",
                DEFAULT_REDIRECT_LOCATION_HEADER_NAME);
            this.locationHeader = DEFAULT_REDIRECT_LOCATION_HEADER_NAME;
        } else {
            this.locationHeader = locationHeader;
        }
        if (CoreUtils.isNullOrEmpty(allowedMethods)) {
            logger.error("'allowedMethods' provided as null will be defaulted to {}", DEFAULT_REDIRECT_ALLOWED_METHODS);
            this.redirectMethods = DEFAULT_REDIRECT_ALLOWED_METHODS;
        } else {
            this.redirectMethods = allowedMethods;
        }
    }
Code review comment: If return true constant, which means we need to keep all partitions or prunes all partitions?

Code under review:
public ScalarOperator visitBinaryPredicate(BinaryPredicateOperator predicate, Void context) {
        if (partitionColumnSet.containsAll(predicate.getUsedColumns())) {
            ScalarOperator left = predicate.getChild(0).accept(this, null);
            if (isShortCut(left)) {
                return ConstantOperator.createBoolean(true);
            }
            ScalarOperator right = predicate.getChild(1).accept(this, null);
            if (isShortCut(right)) {
                return ConstantOperator.createBoolean(true);
            }

            if (EQ_FOR_NULL == predicate.getBinaryType() || !isConstantNull(right)) {
                return predicate;
            } else {
                return ConstantOperator.createBoolean(false);
            }
        }
        return ConstantOperator.createBoolean(true);
    }

Line commented on: return ConstantOperator.createBoolean(true);

Revised code:
public ScalarOperator visitBinaryPredicate(BinaryPredicateOperator predicate, Void context) {
        if (partitionColumnSet.containsAll(predicate.getUsedColumns())) {
            ScalarOperator left = predicate.getChild(0).accept(this, null);
            if (isShortCut(left)) {
                return ConstantOperator.createBoolean(true);
            }
            ScalarOperator right = predicate.getChild(1).accept(this, null);
            if (isShortCut(right)) {
                return ConstantOperator.createBoolean(true);
            }

            if (EQ_FOR_NULL == predicate.getBinaryType() || !isConstantNull(right)) {
                return predicate;
            } else {
                return ConstantOperator.createBoolean(false);
            }
        }
        return ConstantOperator.createBoolean(true);
    }
Code review comment: That can be added any time when we feel comfortable with Spotless formatting the code in Monitor OpenTelemetry Exporter. I can file another PR after this for that if you want.

Code under review:
private static boolean isClient(String metricName) {
        return metricName.contains(".client.");
    }

Line commented on: return metricName.contains(".client.");

Revised code:
private static boolean isClient(String metricName) {
        return metricName.contains(".client.");
    }
Code review comment: Junit 5 has API to assert thrown exception,   ```java  assertThrows(            MyException.class,            () -> myObject.doThing(),            "Expected doThing() to throw, but it didn't"     ); ```

Code under review:
public void testInvalidScopeFromRequestSync(String invalidCharacter) {
        TokenRequestContext request = new TokenRequestContext().addScopes("scope" + invalidCharacter);

        AzureCliCredential credential = new AzureCliCredentialBuilder().build();
        try {
            credential.getTokenSync(request);
        } catch (Exception e) {
            assertTrue(e instanceof IllegalArgumentException);
        }
    }

Line commented on: credential.getTokenSync(request);

Revised code:
public void testInvalidScopeFromRequestSync(String invalidCharacter) {
        TokenRequestContext request = new TokenRequestContext().addScopes("scope" + invalidCharacter);

        AzureCliCredential credential = new AzureCliCredentialBuilder().build();
        assertThrows(IllegalArgumentException.class, () -> credential.getTokenSync(request));
    }
Code review comment: Not sure if this comment adds any value

Code under review:
OperationHandlerImpl createHandler() throws Exception {
            VisitorSession visitorSession = mock(VisitorSession.class);
            
            when(documentAccess.createVisitorSession(any(VisitorParameters.class))).thenAnswer(p -> {
                
                VisitorParameters params = (VisitorParameters)p.getArguments()[0];
                assignedParameters.set(params);

                VisitorStatistics statistics = new VisitorStatistics();
                statistics.setBucketsVisited(bucketsVisited);
                params.getControlHandler().onVisitorStatistics(statistics);

                ProgressToken progress = new ProgressToken();
                params.getControlHandler().onProgress(progress);

                params.getControlHandler().onDone(completionCode, "bork bork");
                return visitorSession;
            });
            OperationHandlerImpl.ClusterEnumerator clusterEnumerator = () -> Arrays.asList(new ClusterDef("foo", "configId"));
            return new OperationHandlerImpl(documentAccess, clusterEnumerator);
        }


Revised code:
OperationHandlerImpl createHandler() throws Exception {
            VisitorSession visitorSession = mock(VisitorSession.class);
            
            when(documentAccess.createVisitorSession(any(VisitorParameters.class))).thenAnswer(p -> {
                VisitorParameters params = (VisitorParameters)p.getArguments()[0];
                assignedParameters.set(params);

                VisitorStatistics statistics = new VisitorStatistics();
                statistics.setBucketsVisited(bucketsVisited);
                params.getControlHandler().onVisitorStatistics(statistics);

                ProgressToken progress = new ProgressToken();
                params.getControlHandler().onProgress(progress);

                params.getControlHandler().onDone(completionCode, "bork bork");
                return visitorSession;
            });
            OperationHandlerImpl.ClusterEnumerator clusterEnumerator = () -> Arrays.asList(new ClusterDef("foo", "configId"));
            return new OperationHandlerImpl(documentAccess, clusterEnumerator);
        }
Code review comment: Seems one `getSchemaLock` call is enough.

Code under review:
public void stopClusterWriteDB(final String schemaName, final String jobId) {
        LockContext lockContext = PipelineContext.getContextManager().getLockContext();
        ShardingSphereLock lock = lockContext.getSchemaLock(schemaName).orElse(lockContext.getSchemaLock(schemaName).orElse(null));
        if (null == lock) {
            log.info("stopClusterWriteDB, lock is null");
            throw new RuntimeException("Stop source writing failed");
        }
        boolean tryLockSuccess = lock.tryLock(schemaName);
        log.info("stopClusterWriteDB, tryLockSuccess={}", tryLockSuccess);
        if (!tryLockSuccess) {
            throw new RuntimeException("Stop source writing failed");
        }
    }

Line commented on: ShardingSphereLock lock = lockContext.getSchemaLock(schemaName).orElse(lockContext.getSchemaLock(schemaName).orElse(null));

Revised code:
public void stopClusterWriteDB(final String schemaName, final String jobId) {
        LockContext lockContext = PipelineContext.getContextManager().getLockContext();
        ShardingSphereLock lock = lockContext.getSchemaLock(schemaName).orElse(null);
        if (null == lock) {
            log.info("stopClusterWriteDB, lock is null");
            throw new RuntimeException("Stop source writing failed");
        }
        boolean tryLockSuccess = lock.tryLock(schemaName);
        log.info("stopClusterWriteDB, tryLockSuccess={}", tryLockSuccess);
        if (!tryLockSuccess) {
            throw new RuntimeException("Stop source writing failed");
        }
    }
Code review comment: Couldn't we remove the "primitive" attribute from the Read transform instead of introducing the additional logic? Runners could still decide whether they want to consider READ primitive.

Code under review:
static Collection<String> getPrimitiveTransformIds(RunnerApi.Components components) {
    Collection<String> ids = new LinkedHashSet<>();

    for (Map.Entry<String, PTransform> transformEntry : components.getTransformsMap().entrySet()) {
      PTransform transform = transformEntry.getValue();
      boolean isPrimitive = isPrimitiveTransform(transform);
      if (isPrimitive) {
        
        
        
        
        
        Deque<String> transforms = new ArrayDeque<>();
        transforms.push(transformEntry.getKey());
        while (!transforms.isEmpty()) {
          String id = transforms.pop();
          PTransform next = components.getTransformsMap().get(id);
          List<String> subtransforms = next.getSubtransformsList();
          if (subtransforms.isEmpty()) {
            ids.add(id);
          } else {
            transforms.addAll(subtransforms);
          }
        }
      }
    }
    return ids;
  }

Line commented on: if (isPrimitive) {

Revised code:
static Collection<String> getPrimitiveTransformIds(RunnerApi.Components components) {
    Collection<String> ids = new LinkedHashSet<>();

    for (Map.Entry<String, PTransform> transformEntry : components.getTransformsMap().entrySet()) {
      PTransform transform = transformEntry.getValue();
      boolean isPrimitive = isPrimitiveTransform(transform);
      if (isPrimitive) {
        
        
        
        
        
        Deque<String> transforms = new ArrayDeque<>();
        transforms.push(transformEntry.getKey());
        while (!transforms.isEmpty()) {
          String id = transforms.pop();
          PTransform next = components.getTransformsMap().get(id);
          List<String> subtransforms = next.getSubtransformsList();
          if (subtransforms.isEmpty()) {
            ids.add(id);
          } else {
            transforms.addAll(subtransforms);
          }
        }
      }
    }
    return ids;
  }
Code review comment: We don't need a variable 'contentType' here. Check all getPayload methods

Code under review:
public void testGetBinaryPayloadMethod() {
        BStruct request = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, requestStruct);
        BStruct entity = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, entityStruct);
        BStruct mediaType = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, mediaTypeStruct);
        HTTPCarbonMessage cMsg = HttpUtil.createHttpCarbonMessage(true);

        String payload = "ballerina";
        String contentType = OCTET_STREAM;
        MimeUtil.setContentType(mediaType, entity, contentType);
        entity.setBlobField(BYTE_DATA_INDEX, payload.getBytes());
        entity.setBooleanField(IS_IN_MEMORY_INDEX, 1);
        request.addNativeData(MESSAGE_ENTITY, entity);
        request.addNativeData(IS_ENTITY_BODY_PRESENT, true);

        HttpUtil.addCarbonMsg(request, cMsg);
        BValue[] inputArg = { request };
        BValue[] returnVals = BRunUtil.invoke(result, "testGetBinaryPayload", inputArg);
        Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null,
                "Invalid Return Values.");
        Assert.assertEquals(returnVals[0].stringValue(), payload);
    }

Line commented on: String contentType = OCTET_STREAM;

Revised code:
public void testGetBinaryPayloadMethod() {
        BStruct request = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, requestStruct);
        BStruct entity = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, entityStruct);
        BStruct mediaType = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, mediaTypeStruct);
        HTTPCarbonMessage cMsg = HttpUtil.createHttpCarbonMessage(true);

        String payload = "ballerina";
        MimeUtil.setContentType(mediaType, entity, OCTET_STREAM);
        entity.setBlobField(BYTE_DATA_INDEX, payload.getBytes());
        entity.setBooleanField(IS_IN_MEMORY_INDEX, 1);
        request.addNativeData(MESSAGE_ENTITY, entity);
        request.addNativeData(IS_ENTITY_BODY_PRESENT, true);

        HttpUtil.addCarbonMsg(request, cMsg);
        BValue[] inputArg = { request };
        BValue[] returnVals = BRunUtil.invoke(result, "testGetBinaryPayload", inputArg);
        Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null,
                "Invalid Return Values.");
        Assert.assertEquals(returnVals[0].stringValue(), payload);
    }
Code review comment: I'd just name this variable "errors". Feel like naming is not consistent with the previous variable (responses) :)

Code under review:
public void testCircuitBreaker() {
        
        int[] expectedStatusCodes = new int[] { 200, 200, 500, 503, 503, 200, 200, 200 };
        BValue[] returnVals = BRunUtil.invoke(compileResult, "testTypicalScenario");

        Assert.assertEquals(returnVals.length, 2);

        BRefValueArray responses = (BRefValueArray) returnVals[0];
        BRefValueArray errorsArray = (BRefValueArray) returnVals[1];

        for (int i = 0; i < responses.size(); i++) {
            long statusCode;
            
            
            if (i != CB_CLIENT_FIRST_ERROR_INDEX && i != CB_CLIENT_SECOND_ERROR_INDEX) {
                BMap<String, BValue> res = (BMap<String, BValue>) responses.get(i);
                statusCode = ((BInteger) res.get(STATUS_CODE_FIELD)).intValue();
                Assert.assertEquals(statusCode, expectedStatusCodes[i], "Status code does not match.");
            } else {
                Assert.assertNotNull(errorsArray.get(i)); 
                BError error = (BError) errorsArray.get(i);
                String errMsg = error.getReason();
                Assert.assertTrue(errMsg != null && errMsg.startsWith(CB_ERROR_MSG),
                        "Invalid error message from circuit breaker.");
            }
        }
    }

Line commented on: BRefValueArray errorsArray = (BRefValueArray) returnVals[1];

Revised code:
public void testCircuitBreaker() {
        
        int[] expectedStatusCodes = new int[] { 200, 200, 500, 503, 503, 200, 200, 200 };
        BValue[] returnVals = BRunUtil.invoke(compileResult, "testTypicalScenario");

        Assert.assertEquals(returnVals.length, 2);

        BRefValueArray responses = (BRefValueArray) returnVals[0];
        BRefValueArray errors = (BRefValueArray) returnVals[1];

        for (int i = 0; i < responses.size(); i++) {
            long statusCode;
            
            
            if (i != CB_CLIENT_FIRST_ERROR_INDEX && i != CB_CLIENT_SECOND_ERROR_INDEX) {
                BMap<String, BValue> res = (BMap<String, BValue>) responses.get(i);
                statusCode = ((BInteger) res.get(STATUS_CODE_FIELD)).intValue();
                Assert.assertEquals(statusCode, expectedStatusCodes[i], "Status code does not match.");
            } else {
                Assert.assertNotNull(errors.get(i)); 
                BError error = (BError) errors.get(i);
                String errMsg = error.getReason();
                Assert.assertTrue(errMsg != null && errMsg.startsWith(CB_ERROR_MSG),
                        "Invalid error message from circuit breaker.");
            }
        }
    }
Code review comment: ```suggestion         assertThat(group.getScopeComponents()).containsExactly("constant", "host", "foo", "host"); ```

Code under review:
void testGenerateScopeCustom() throws Exception {
        Configuration cfg = new Configuration();
        cfg.setString(MetricOptions.SCOPE_NAMING_TM, "constant.<host>.foo.<host>");
        MetricRegistryImpl registry =
                new MetricRegistryImpl(MetricRegistryTestUtils.fromConfiguration(cfg));
        TaskManagerMetricGroup group =
                TaskManagerMetricGroup.createTaskManagerMetricGroup(
                        registry, "host", new ResourceID("id"));

        assertThat(group.getScopeComponents()).containsAnyOf("constant", "host", "foo", "host");
        assertThat(group.getMetricIdentifier("name")).isEqualTo("constant.host.foo.host.name");
        registry.closeAsync().get();
    }

Line commented on: assertThat(group.getScopeComponents()).containsAnyOf("constant", "host", "foo", "host");

Revised code:
void testGenerateScopeCustom() throws Exception {
        Configuration cfg = new Configuration();
        cfg.setString(MetricOptions.SCOPE_NAMING_TM, "constant.<host>.foo.<host>");
        MetricRegistryImpl registry =
                new MetricRegistryImpl(MetricRegistryTestUtils.fromConfiguration(cfg));
        TaskManagerMetricGroup group =
                TaskManagerMetricGroup.createTaskManagerMetricGroup(
                        registry, "host", new ResourceID("id"));

        assertThat(group.getScopeComponents()).containsExactly("constant", "host", "foo", "host");
        assertThat(group.getMetricIdentifier("name")).isEqualTo("constant.host.foo.host.name");
        registry.closeAsync().get();
    }
Code review comment: What do you think about making `ModuleManager.loadedModules` to be `LinkedHashMap`? This can provide deterministic result for `listFullModules` and make the testing easier.   If we do this, we should add a comment on the `loadedModules` to explain why we use `LinkedHashMap`.

Code under review:
public void testListFullModules() {
        ModuleMock.ModuleZ x = new ModuleMock.ModuleZ("x");
        ModuleMock.ModuleY y = new ModuleMock.ModuleY("y");
        ModuleMock.ModuleZ z = new ModuleMock.ModuleZ("z");

        manager.loadModule("y", y);
        manager.loadModule("x", x);
        manager.loadModule("z", z);
        manager.useModules("z", "y");

        assertEquals(
                getExpectedModuleEntries(2, "z", "y", MODULE_TYPE_CORE, "x"),
                getActualModuleEntries());
    }

Line commented on: getActualModuleEntries());

Revised code:
public void testListFullModules() {
        ModuleMock x = new ModuleMock("x");
        ModuleMock y = new ModuleMock("y");
        ModuleMock z = new ModuleMock("z");

        manager.loadModule("y", y);
        manager.loadModule("x", x);
        manager.loadModule("z", z);
        manager.useModules("z", "y");

        assertEquals(
                getExpectedModuleEntries(2, "z", "y", MODULE_TYPE_CORE, "x"),
                manager.listFullModules());
    }
Code review comment: ```suggestion                     deployLogger.logApplicationPackage(Level.WARNING, msg); ``` To show this as a notification in console, e.g.: ![Screenshot from 2021-09-08 18-25-41](https://user-images.githubusercontent.com/3785505/132547847-87c8befe-3809-480a-a4cf-2b4ed6f13d74.png)

Code under review:
private RankProfile getInherited() {
        if (inheritedName == null) return null;
        if (inherited == null) {
            inherited = resolveInherited();
            if (inherited == null) {
                String msg = "rank-profile '" + getName() + "' inherits '" + inheritedName +
                        "', but it does not exist anywhere in the inheritance of search '" +
                        ((getSearch() != null) ? getSearch().getName() : " global rank profiles") + "'.";
                if (search.getDeployProperties().featureFlags().enforceRankProfileInheritance()) {
                    throw new IllegalArgumentException(msg);
                } else {
                    deployLogger.log(Level.WARNING, msg);
                    inherited = resolveIndependentOfInheritance();
                }
            } else {
                List<String> children = new ArrayList<>();
                children.add(createFullyQualifiedName());
                verifyNoInheritanceCycle(children, inherited);
            }
        }
        return inherited;
    }

Line commented on: deployLogger.log(Level.WARNING, msg);

Revised code:
private RankProfile getInherited() {
        if (inheritedName == null) return null;
        if (inherited == null) {
            inherited = resolveInherited();
            if (inherited == null) {
                String msg = "rank-profile '" + getName() + "' inherits '" + inheritedName +
                        "', but it does not exist anywhere in the inheritance of search '" +
                        ((getSearch() != null) ? getSearch().getName() : " global rank profiles") + "'.";
                if (search.getDeployProperties().featureFlags().enforceRankProfileInheritance()) {
                    throw new IllegalArgumentException(msg);
                } else {
                    deployLogger.log(Level.WARNING, msg);
                    inherited = resolveIndependentOfInheritance();
                }
            } else {
                List<String> children = new ArrayList<>();
                children.add(createFullyQualifiedName());
                verifyNoInheritanceCycle(children, inherited);
            }
        }
        return inherited;
    }
Code review comment: shouldn't we check `containsKey` here as well?

Code under review:
private Optional<ExecutionVertex> updateAndGet(ExecutionAttemptID id) {
        synchronized (tasks) {
            ExecutionVertex vertex = cachedTasksById.get(id);
            if (vertex != null) {
                return Optional.of(vertex);
            }

            Map<ExecutionAttemptID, ExecutionVertex> mappings = getCurrentAttemptMappings();
            if (!mappings.containsKey(id)) {
                mappings.put(id, null);
            }
            cachedTasksById = mappings;
            return Optional.ofNullable(cachedTasksById.get(id));
        }
    }

Line commented on: if (vertex != null) {

Revised code:
private Optional<ExecutionVertex> updateAndGet(ExecutionAttemptID id) {
        synchronized (tasks) {
            ExecutionVertex vertex = cachedTasksById.get(id);
            if (vertex != null || cachedTasksById.containsKey(id)) {
                return Optional.ofNullable(vertex);
            }

            Map<ExecutionAttemptID, ExecutionVertex> mappings = getCurrentAttemptMappings();
            if (!mappings.containsKey(id)) {
                mappings.put(id, null);
            }
            cachedTasksById = mappings;
            return Optional.ofNullable(cachedTasksById.get(id));
        }
    }
Code review comment: Any reason to not use `Text.format`?

Code under review:
private Mail mailOf(Notification n, Collection<String> recipients) {
        var subject = new Formatter().format("[%s] Vespa Notification for %s", n.level().toString().toUpperCase(), n.type().name());
        var body = new StringBuilder();
        body.append("Source: ").append(n.source().toString()).append("\n")
                .append("\n")
                .append(String.join("\n", n.messages()));
        return new Mail(recipients, subject.toString(), body.toString());
    }

Line commented on: var subject = new Formatter().format("[%s] Vespa Notification for %s", n.level().toString().toUpperCase(), n.type().name());

Revised code:
private Mail mailOf(Notification n, Collection<String> recipients) {
        var subject = Text.format("[%s] Vespa Notification for %s", n.level().toString().toUpperCase(), n.type().name());
        var body = new StringBuilder();
        body.append("Source: ").append(n.source().toString()).append("\n")
                .append("\n")
                .append(String.join("\n", n.messages()));
        return new Mail(recipients, subject.toString(), body.toString());
    }
Code review comment: Sorry for the confusion.  No, there is no case that `preposition` is `not null` and `catalog` is `null`.  In fact, based on our discussion, I have already removed `preposition` field from `ShowDatabasesOperation`.  `catalog` is null (so the `preposition` that doesn't exist now) only when there is no `FROM/IN` clause.   Do the changes in `ShowDatabasesOperation` reflect your comments or did I miss something?

Code under review:
public Operation convertSqlNode(SqlShowDatabases sqlShowDatabases, ConvertContext context) {
        if (sqlShowDatabases.getPreposition() == null) {
            return new ShowDatabasesOperation(
                    sqlShowDatabases.getLikeType(),
                    sqlShowDatabases.getLikeSqlPattern(),
                    sqlShowDatabases.isNotLike());
        } else {
            CatalogManager catalogManager = context.getCatalogManager();
            String[] fullCatalogName = sqlShowDatabases.getCatalog();
            String catalogName =
                    fullCatalogName.length == 0
                            ? catalogManager.getCurrentCatalog()
                            : fullCatalogName[0];
            return new ShowDatabasesOperation(
                    sqlShowDatabases.getPreposition(),
                    catalogName,
                    sqlShowDatabases.getLikeType(),
                    sqlShowDatabases.getLikeSqlPattern(),
                    sqlShowDatabases.isNotLike());
        }
    }

Line commented on: : fullCatalogName[0];

Revised code:
public Operation convertSqlNode(SqlShowDatabases sqlShowDatabases, ConvertContext context) {
        if (sqlShowDatabases.getPreposition() == null) {
            return new ShowDatabasesOperation(
                    sqlShowDatabases.getLikeType(),
                    sqlShowDatabases.getLikeSqlPattern(),
                    sqlShowDatabases.isNotLike());
        } else {
            return new ShowDatabasesOperation(
                    sqlShowDatabases.getCatalog()[0],
                    sqlShowDatabases.getLikeType(),
                    sqlShowDatabases.getLikeSqlPattern(),
                    sqlShowDatabases.isNotLike());
        }
    }
Code review comment: HBase and JDBC DataSource should be process in pluggable way. I will refactor here after merged

Code under review:
public static YamlProxyConfiguration load(final String path) throws IOException {
        YamlProxyServerConfiguration serverConfig = loadServerConfiguration(getResourceFile(String.join("/", path, SERVER_CONFIG_FILE)));
        File configPath = getResourceFile(path);
        Collection<YamlProxyDatabaseConfiguration> databaseConfigs = loadDatabaseConfigurations(configPath);
        Collection<YamlHBaseConfiguration> hbaseConfigs = loadHBaseConfigurations(configPath);
        return new YamlProxyConfiguration(serverConfig, databaseConfigs.stream().collect(Collectors.toMap(
                YamlProxyDatabaseConfiguration::getDatabaseName, each -> each, (oldValue, currentValue) -> oldValue,
                LinkedHashMap::new)), hbaseConfigs.stream().collect(
                        Collectors.toMap(
                                YamlHBaseConfiguration::getDatabaseName, each -> each, (oldValue, currentValue) -> oldValue,
                                LinkedHashMap::new)));
    }

Line commented on: LinkedHashMap::new)));

Revised code:
public static YamlProxyConfiguration load(final String path) throws IOException {
        YamlProxyServerConfiguration serverConfig = loadServerConfiguration(getResourceFile(String.join("/", path, SERVER_CONFIG_FILE)));
        File configPath = getResourceFile(path);
        Collection<YamlProxyDatabaseConfiguration> databaseConfigs = loadDatabaseConfigurations(configPath);
        return new YamlProxyConfiguration(serverConfig, databaseConfigs.stream().collect(Collectors.toMap(
                YamlProxyDatabaseConfiguration::getDatabaseName, each -> each, (oldValue, currentValue) -> oldValue,
                LinkedHashMap::new)));
    }
Code review comment: Simplified the logic. Currently, we are allowing empty application Id. @JonathanGiles do we want to disallow empty application Id?

Code under review:
public HttpLogOptions setApplicationId(final String applicationId) {
        if (applicationId != null
            && (applicationId.length() > MAX_APPLICATION_ID_LENGTH || applicationId.contains(" "))) {
            if (applicationId.contains(" ")) {
                throw logger
                    .logExceptionAsError(new IllegalArgumentException("'applicationId' must not contain a space."));
            } else {
                throw logger
                    .logExceptionAsError(new IllegalArgumentException("'applicationId' length cannot be greater than "
                        + MAX_APPLICATION_ID_LENGTH));
            }
        } else {
            this.applicationId = applicationId;
        }
        return this;
    }

Line commented on: if (applicationId != null

Revised code:
public HttpLogOptions setApplicationId(final String applicationId) {
        if (!CoreUtils.isNullOrEmpty(applicationId)) {
            if (applicationId.length() > MAX_APPLICATION_ID_LENGTH) {
                throw logger
                    .logExceptionAsError(new IllegalArgumentException("'applicationId' length cannot be greater than "
                        + MAX_APPLICATION_ID_LENGTH));
            } else if (applicationId.contains(" ")) {
                throw logger
                    .logExceptionAsError(new IllegalArgumentException("'applicationId' must not contain a space."));
            } else {
                this.applicationId = applicationId;
            }
        }
        return this;
    }
Code review comment: We can use a constant for ".balo". There is already one in ProjectDirConstants. We can copy it to ProjectConstants and use it.

Code under review:
private static Path validateBaloPath(String baloPath) {
        if (baloPath == null) {
            throw new IllegalArgumentException("baloPath cannot be null");
        }

        Path absBaloPath = Paths.get(baloPath).toAbsolutePath();
        if (!absBaloPath.toFile().canRead()) {
            throw new RuntimeException("insufficient privileges to balo: " + absBaloPath);
        }
        if (!absBaloPath.toFile().exists()) {
            throw new RuntimeException("balo does not exists: " + baloPath);
        }

        if (!absBaloPath.toString().endsWith(".balo")) {
            throw new RuntimeException("Not a balo: " + baloPath);
        }
        return absBaloPath;
    }

Line commented on: if (!absBaloPath.toString().endsWith(".balo")) {

Revised code:
private static Path validateBaloPath(String baloPath) {
        if (baloPath == null) {
            throw new IllegalArgumentException("baloPath cannot be null");
        }

        Path absBaloPath = Paths.get(baloPath).toAbsolutePath();
        if (!absBaloPath.toFile().canRead()) {
            throw new RuntimeException("insufficient privileges to balo: " + absBaloPath);
        }
        if (!absBaloPath.toFile().exists()) {
            throw new RuntimeException("balo does not exists: " + baloPath);
        }

        if (!absBaloPath.toString().endsWith(BLANG_COMPILED_PKG_BINARY_EXT)) {
            throw new RuntimeException("Not a balo: " + baloPath);
        }
        return absBaloPath;
    }
Code review comment: Could `3L` be replaced to `columnNames.size()`? So if `columnNames` value changed, it's not necessary to change the hard coded `3L`.

Code under review:
public void assertCalculateSuccess() {
        Iterable<Object> calculate = new CRC32MatchMySQLSingleTableDataCalculator().calculate(dataCalculateParameter);
        long calculateSize = StreamSupport.stream(calculate.spliterator(), false).count();
        assertThat(calculateSize, is(3L));
    }

Line commented on: assertThat(calculateSize, is(3L));

Revised code:
public void assertCalculateSuccess() {
        Iterable<Object> calculate = new CRC32MatchMySQLSingleTableDataCalculator().calculate(dataCalculateParameter);
        long actualDatabaseTypesSize = StreamSupport.stream(calculate.spliterator(), false).count();
        long expectedDatabaseTypesSize = dataCalculateParameter.getColumnNames().size();
        assertThat(actualDatabaseTypesSize, is(expectedDatabaseTypesSize));
    }
Code review comment: You can use the constant for "UTF-8" from StandardCharsets class[1]  [1] https://docs.oracle.com/javase/8/docs/api/index.html?java/nio/charset/StandardCharsets.html

Code under review:
public void execute(Context context) {
        BMap<String, BValue> channelObject = (BMap<String, BValue>) context.getRefArgument(0);
        Channel channel = RabbitMQUtils.getNativeObject(channelObject, RabbitMQConstants.CHANNEL_NATIVE_OBJECT,
                Channel.class, context);
        BValue msgContent = context.getRefArgument(1);
        String routingKey = context.getStringArgument(0);
        String exchange = context.getStringArgument(1);
        try {
            ChannelUtils.basicPublish(channel, routingKey, msgContent.stringValue().getBytes(Charset.forName("UTF-8")),
                    exchange);
        } catch (BallerinaException exception) {
            LOGGER.error("I/O exception while publishing a message", exception);
            RabbitMQUtils.returnError("RabbitMQ Client Error:", context, exception);
        }
    }

Line commented on: ChannelUtils.basicPublish(channel, routingKey, msgContent.stringValue().getBytes(Charset.forName("UTF-8")),

Revised code:
public void execute(Context context) {
        BMap<String, BValue> channelObject = (BMap<String, BValue>) context.getRefArgument(0);
        Channel channel = RabbitMQUtils.getNativeObject(channelObject, RabbitMQConstants.CHANNEL_NATIVE_OBJECT,
                Channel.class, context);
        BValue msgContent = context.getRefArgument(1);
        String routingKey = context.getStringArgument(0);
        String exchange = context.getStringArgument(1);
        try {
            ChannelUtils.basicPublish(channel, routingKey, msgContent.stringValue().getBytes(StandardCharsets.UTF_8),
                    exchange);
        } catch (BallerinaException exception) {
            LOGGER.error("I/O exception while publishing a message", exception);
            RabbitMQUtils.returnError("RabbitMQ Client Error:", context, exception);
        }
    }
Code review comment: This is a nice one-liner!

Code under review:
public void updateKeyStore(KeyStore keyStore, String password) {
        updateKeyStore(sslContextFactory -> {
            sslContextFactory.setKeyStore(keyStore);
            if (password != null) {
                sslContextFactory.setKeyStorePassword(null);
            }
        });
    }

Line commented on: if (password != null) {

Revised code:
public void updateKeyStore(KeyStore keyStore, String password) {
        updateKeyStore(sslContextFactory -> {
            sslContextFactory.setKeyStore(keyStore);
            if (password != null) {
                sslContextFactory.setKeyStorePassword(null);
            }
        });
    }
Code review comment: @simplynaveen20   In Spring, you can have duplicate parameters in query which are of the same name - for example this query - `Iterable<Project> findByNameAndCreatorOrNameAndCreator(String name, String creator, String name2, String creator2);` This would get converted to this -  `select * from c where c.name = @name and c.creator = @creator OR c.name = @name and c.creator = @creator` This cause problems when running the query - as Gateway throws exception saying 400 bad request.  To avoid this issue, when we are generating the query params, we were appending random UUID to have different query param names for same fields.  However, that was resulting in a different query text for the same query if executed twice in the same JVM.  To solve the query text issue, now I am using a counter - which gets initialized when generating a query text. That way, same queries (conceptually) now will have same query text. Which is what we want.

Code under review:
private String generateQueryParameter(@NonNull String subject, int counter) {
        
        return subject.replaceAll("[^a-zA-Z\\d]", "_") + counter;
    }

Line commented on: return subject.replaceAll("[^a-zA-Z\\d]", "_") + counter;

Revised code:
private String generateQueryParameter(@NonNull String subject, int counter) {
        
        return subject.replaceAll("[^a-zA-Z\\d]", "_") + counter;
    }
Code review comment: this is test and it doesn't matter much.  but in general you should not create a ObjectMapper per method invocation, This is costly timewise.

Code under review:
private void validateJson(String jsonInString) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            mapper.readTree(jsonInString);
        } catch(JsonProcessingException ex) {
            fail("Diagnostic string is not in json format");
        }
    }

Line commented on: ObjectMapper mapper = new ObjectMapper();

Revised code:
private void validateJson(String jsonInString) {
        try {
            OBJECT_MAPPER.readTree(jsonInString);
        } catch(JsonProcessingException ex) {
            fail("Diagnostic string is not in json format");
        }
    }
Code review comment: Why the model name has Schema, can we call it PackageSearchResult etc

Code under review:
private static void searchInCentral(String query) {
        try {
            CentralAPIClient client = new CentralAPIClient();
            PackageSearchJsonSchema packageSearchJsonSchema = client.searchPackage(query);

            if (packageSearchJsonSchema.getCount() > 0) {
                printPackages(packageSearchJsonSchema.getPackages(), RepoUtils.getTerminalWidth());
            } else {
                outStream.println("no modules found");
            }
        } catch (CommandException e) {
            String errorMessage = e.getMessage();
            if (null != errorMessage && !"".equals(errorMessage.trim())) {
                
                if (errorMessage.contains("\n\tat")) {
                    errorMessage = errorMessage.substring(0, errorMessage.indexOf("\n\tat"));
                }

                outStream.println(errorMessage);
            }
        }
    }

Line commented on: PackageSearchJsonSchema packageSearchJsonSchema = client.searchPackage(query);

Revised code:
private static void searchInCentral(String query) {
        try {
            CentralAPIClient client = new CentralAPIClient();
            PackageSearchResult packageSearchResult = client.searchPackage(query);

            if (packageSearchResult.getCount() > 0) {
                printPackages(packageSearchResult.getPackages(), RepoUtils.getTerminalWidth());
            } else {
                outStream.println("no modules found");
            }
        } catch (CentralClientException e) {
            String errorMessage = e.getMessage();
            if (null != errorMessage && !"".equals(errorMessage.trim())) {
                
                if (errorMessage.contains("\n\tat")) {
                    errorMessage = errorMessage.substring(0, errorMessage.indexOf("\n\tat"));
                }

                outStream.println(errorMessage);
            }
        }
    }