muttakin2301/ccr2000 huggingface dataset:
Code review comment: `BuildContext` could only be null in tests. ISE is fine.

Code under review:
public Collection<AnnotationInstance> getAllAnnotations() {
            if (annotationStore == null) {
                throw new IllegalStateException(
                        "Attempted to use TransformationContext
            }
            return annotationStore.getAnnotations(getTarget());
        }

Line commented on: return annotationStore.getAnnotations(getTarget());

Revised code:
public Collection<AnnotationInstance> getAllAnnotations() {
            if (annotationStore == null) {
                throw new IllegalStateException(
                        "Attempted to use TransformationContext
            }
            return annotationStore.getAnnotations(getTarget());
        }
Code review comment: It's better put after `getAuthority`

Code under review:
public void assertLoadEmptyConfiguration() throws IOException {
        YamlProxyConfiguration actual = ProxyConfigurationLoader.load("/conf/empty/");
        YamlProxyServerConfiguration serverConfig = actual.getServerConfiguration();
        assertNull(serverConfig.getMode());
        assertNull(serverConfig.getAuthority());
        assertNull(serverConfig.getLabels());
        assertTrue(serverConfig.getProps().isEmpty());
        assertTrue(serverConfig.getRules().isEmpty());
        assertNull(serverConfig.getCdc());
        assertTrue(actual.getDatabaseConfigurations().isEmpty());
    }

Line commented on: assertNull(serverConfig.getCdc());

Revised code:
public void assertLoadEmptyConfiguration() throws IOException {
        YamlProxyConfiguration actual = ProxyConfigurationLoader.load("/conf/empty/");
        YamlProxyServerConfiguration serverConfig = actual.getServerConfiguration();
        assertNull(serverConfig.getMode());
        assertNull(serverConfig.getAuthority());
        assertNull(serverConfig.getCdc());
        assertNull(serverConfig.getLabels());
        assertTrue(serverConfig.getProps().isEmpty());
        assertTrue(serverConfig.getRules().isEmpty());
        assertTrue(actual.getDatabaseConfigurations().isEmpty());
    }
Code review comment: Yep, done. (I originally tried to do this the functional way using streams, but Java doesn't really let you throw checked exceptions from lambdas. 😢 )

Code under review:
public ClassLoader createClassLoader(List<String> inputJarPaths) throws IOException {
    List<File> localJars = new ArrayList<>();
    for (String inputJar : inputJarPaths) {
      localJars.add(getLocalJar(inputJar));
    }
    List<URL> urls = new ArrayList<>();
    for (File file : localJars) {
      urls.add(file.toURI().toURL());
    }
    return new URLClassLoader(urls.toArray(new URL[0]));
  }

Line commented on: localJars.add(getLocalJar(inputJar));

Revised code:
public ClassLoader createClassLoader(List<String> inputJarPaths) throws IOException {
    List<URL> urls = new ArrayList<>();
    for (String inputJar : inputJarPaths) {
      urls.add(getLocalJar(inputJar).toURI().toURL());
    }
    return createUrlClassLoader(urls.toArray(new URL[0]));
  }
Code review comment: Flink generates its MetricGroup from the operator name which contains the step id. I think it is fine to omit the step name from the generated name.

Code under review:
static String getFlinkMetricNameString(MetricResult<?> metricResult) {
    return METRIC_KEY_SEPARATOR
        + metricResult.getStep()
        + METRIC_KEY_SEPARATOR
        + metricResult.getName().getNamespace()
        + METRIC_KEY_SEPARATOR
        + metricResult.getName().getName();
  }

Line commented on: return METRIC_KEY_SEPARATOR

Revised code:
static String getFlinkMetricNameString(MetricResult<?> metricResult) {
    MetricName metricName = metricResult.getName();
    
    
    
    return metricName.getNamespace() + METRIC_KEY_SEPARATOR + metricName.getName();
  }
Code review comment: onNext should always contain an item... also, you haven't set `.verify();` on this, so it is not running this test at all.

Code under review:
public void testClaimOwnership() {
        List<PartitionOwnership> partitionOwnershipList = new ArrayList<>();
        StepVerifier.create(store.claimOwnership(partitionOwnershipList))
            .assertNext(partitionOwnership -> {
                Assertions.assertNull(partitionOwnership);
            });
    }

Line commented on: Assertions.assertNull(partitionOwnership);

Revised code:
public void testClaimOwnership() {
        
        List<PartitionOwnership> partitionOwnershipList = new ArrayList<>();
        StepVerifier.create(store.claimOwnership(partitionOwnershipList))
            .verifyComplete();
    }
Code review comment: Shouldn't we ideally pass the errors related to WebSocket connection in the onError resource? IMO all other internal errors should be logged in the internal log but should not appear in onError resource since they are not related to WebSocket connection. WDYT?

Code under review:
public static void dispatchError(WebSocketOpenConnectionInfo connectionInfo, Throwable throwable) {
        WebSocketService webSocketService = connectionInfo.getService();
        Resource onErrorResource = webSocketService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_ERROR);
        if (isUnexpectedError(throwable)) {
            log.error("Unexpected error", throwable);
            return;
        }
        if (onErrorResource == null) {
            ErrorHandlerUtils.printError(throwable);
            return;
        }
        BValue[] bValues = new BValue[onErrorResource.getParamDetails().size()];
        bValues[0] = connectionInfo.getWebSocketEndpoint();
        bValues[1] = getError(webSocketService, throwable);
        CallableUnitCallback onErrorCallback = new CallableUnitCallback() {
            @Override
            public void notifySuccess() {
                
            }

            @Override
            public void notifyFailure(BStruct error) {
                ErrorHandlerUtils.printError("error: " + BLangVMErrors.getPrintableStackTrace(error));
            }
        };
        Executor.submit(onErrorResource, onErrorCallback, null, null, bValues);
    }

Line commented on: if (isUnexpectedError(throwable)) {

Revised code:
public static void dispatchError(WebSocketOpenConnectionInfo connectionInfo, Throwable throwable) {
        WebSocketService webSocketService = connectionInfo.getService();
        Resource onErrorResource = webSocketService.getResourceByName(WebSocketConstants.RESOURCE_NAME_ON_ERROR);
        if (isUnexpectedError(throwable)) {
            log.error("Unexpected error", throwable);
        }
        if (onErrorResource == null) {
            ErrorHandlerUtils.printError(throwable);
            return;
        }
        BValue[] bValues = new BValue[onErrorResource.getParamDetails().size()];
        bValues[0] = connectionInfo.getWebSocketEndpoint();
        bValues[1] = getError(webSocketService, throwable);
        CallableUnitCallback onErrorCallback = new CallableUnitCallback() {
            @Override
            public void notifySuccess() {
                
            }

            @Override
            public void notifyFailure(BStruct error) {
                ErrorHandlerUtils.printError("error: " + BLangVMErrors.getPrintableStackTrace(error));
            }
        };
        Executor.submit(onErrorResource, onErrorCallback, null, null, bValues);
    }
Code review comment: Is it possible to have a method without any class?

Code under review:
private void checkMethodNamePrefix(DetailAST methodDefToken) {
        
        if (TokenUtil.findFirstTokenByPredicate(methodDefToken, parameters ->
            parameters.getType() == TokenTypes.PARAMETERS && parameters.getChildCount() != 1).isPresent()) {
            log(methodDefToken, "A fluent method should only has one parameter.");
        }

        if (classNameStack.isEmpty()) {
            return;
        }
        
        final DetailAST typeToken = methodDefToken.findFirstToken(TokenTypes.TYPE);
        if (TokenUtil.findFirstTokenByPredicate(typeToken, ident -> ident.getType() == TokenTypes.IDENT
            && !ident.getText().equals(classNameStack.peekLast())).isPresent()) {
            log(methodDefToken, "Return type of fluent method should be the class itself");
        }

        final String methodName = methodDefToken.findFirstToken(TokenTypes.IDENT).getText();
        
        avoidStartWords.forEach(avoidStartWord -> {
            if (methodName.length() >= avoidStartWord.length() && methodName.startsWith(avoidStartWord)) {
                log(methodDefToken, String.format(FLUENT_METHOD_ERR, methodName, avoidStartWord));
            }
        });
    }

Line commented on: if (classNameStack.isEmpty()) {

Revised code:
private void checkMethodNamePrefix(DetailAST methodDefToken) {
        
        if (TokenUtil.findFirstTokenByPredicate(methodDefToken, parameters ->
            parameters.getType() == TokenTypes.PARAMETERS && parameters.getChildCount() != 1).isPresent()) {
            log(methodDefToken, "A fluent method should only have one parameter.");
        }

        
        final DetailAST typeToken = methodDefToken.findFirstToken(TokenTypes.TYPE);
        if (TokenUtil.findFirstTokenByPredicate(typeToken, ident -> ident.getType() == TokenTypes.IDENT
            && !ident.getText().equals(classNameStack.peekLast())).isPresent()) {
            log(methodDefToken, "Return type of fluent method should be the class itself");
        }

        final String methodName = methodDefToken.findFirstToken(TokenTypes.IDENT).getText();
        
        avoidStartWords.forEach(avoidStartWord -> {
            if (methodName.length() >= avoidStartWord.length() && methodName.startsWith(avoidStartWord)) {
                log(methodDefToken, String.format("''%s'' fluent method name should not start with keyword ''%s''.",
                    methodName, avoidStartWord));
            }
        });
    }
Code review comment: Can you please make this move in a different commit? Because if we have to revert it something, we don't want to revert the whole thing

Code under review:
private Type getNonAsyncReturnType(Type returnType) {
        switch (returnType.kind()) {
            case ARRAY:
            case CLASS:
            case PRIMITIVE:
            case VOID:
                return returnType;
            case PARAMETERIZED_TYPE:
                
                ParameterizedType parameterizedType = returnType.asParameterizedType();
                if (COMPLETION_STAGE.equals(parameterizedType.name())
                        || COMPLETABLE_FUTURE.equals(parameterizedType.name())
                        || UNI.equals(parameterizedType.name())
                        || MULTI.equals(parameterizedType.name())
                        || REST_RESPONSE.equals(parameterizedType.name())) {
                    return parameterizedType.arguments().get(0);
                }
                return returnType;
            default:
        }
        return returnType;
    }


Revised code:
private Type getNonAsyncReturnType(Type returnType) {
        switch (returnType.kind()) {
            case ARRAY:
            case CLASS:
            case PRIMITIVE:
            case VOID:
                return returnType;
            case PARAMETERIZED_TYPE:
                
                ParameterizedType parameterizedType = returnType.asParameterizedType();
                if (COMPLETION_STAGE.equals(parameterizedType.name())
                        || COMPLETABLE_FUTURE.equals(parameterizedType.name())
                        || UNI.equals(parameterizedType.name())
                        || MULTI.equals(parameterizedType.name())
                        || REST_RESPONSE.equals(parameterizedType.name())) {
                    return parameterizedType.arguments().get(0);
                }
                return returnType;
            default:
        }
        return returnType;
    }
Code review comment: I think I wanted to put `this.getClass().getSimpleName()` there. Will update it.

Code under review:
public void close() throws Exception {
        synchronized (lock) {
            if (!running) {
                return;
            }
            running = false;

            LOG.info("Closing {}.", this);

            ExecutorUtils.gracefulShutdown(10L, TimeUnit.SECONDS, leadershipOperationExecutor);

            Exception exception = null;
            try {
                multipleComponentLeaderElectionDriver.close();
            } catch (Exception e) {
                exception = e;
            }

            ExceptionUtils.tryRethrowException(exception);
        }
    }

Line commented on: LOG.info("Closing {}.", this);

Revised code:
public void close() throws Exception {
        synchronized (lock) {
            if (!running) {
                return;
            }
            running = false;

            LOG.info("Closing {}.", this.getClass().getSimpleName());

            ExecutorUtils.gracefulShutdown(10L, TimeUnit.SECONDS, leadershipOperationExecutor);

            multipleComponentLeaderElectionDriver.close();
        }
    }
Code review comment: Whether this should be calling into the parent or not, I don't see getters for other properties. Shouldn't there be? In .NET, we almost never have write-only properties: just read-only or read-write.

Code under review:
public Integer getKeySize() {
        return this.keySize;
    }

Line commented on: return this.keySize;

Revised code:
public Integer getKeySize() {
        return this.keySize;
    }
Code review comment: updated. this TokenUtil would've made everything easier since the beginning. :)

Code under review:
private void checkForOnlyFinalFields(DetailAST objBlockToken) {
        for (DetailAST ast = objBlockToken.getFirstChild(); ast != null; ast = ast.getNextSibling()) {
            if (TokenTypes.VARIABLE_DEF == ast.getType()) {
                final DetailAST modifiersToken = ast.findFirstToken(TokenTypes.MODIFIERS);
                if (!modifiersToken.branchContains(TokenTypes.FINAL) && !Utils.hasIllegalCombination(modifiersToken)) {
                    log(modifiersToken, String.format(ERROR_MSG, ast.findFirstToken(TokenTypes.IDENT).getText(),
                        objBlockToken.getPreviousSibling().getText()));
                }
            }
        }
    }

Line commented on: for (DetailAST ast = objBlockToken.getFirstChild(); ast != null; ast = ast.getNextSibling()) {

Revised code:
private void checkForOnlyFinalFields(DetailAST objBlockToken) {
        Optional<DetailAST> nonFinalFieldFound = TokenUtil.findFirstTokenByPredicate(objBlockToken,
            node -> TokenTypes.VARIABLE_DEF == node.getType() && !node.branchContains(TokenTypes.FINAL)
                && !Utils.hasIllegalCombination(node.findFirstToken(TokenTypes.MODIFIERS)));

        if (nonFinalFieldFound.isPresent()) {
            DetailAST field = nonFinalFieldFound.get().findFirstToken(TokenTypes.IDENT);
            log(field, String.format(ERROR_MSG, field.getText()));
        }
    }
Code review comment: "lock" is already in the path so no need for it in the node name imho

Code under review:
public Lock lockVespaServerPool() {
        return lock(root.append("locks").append("vespaServerPoolLock"), defaultLockTimeout);
    }

Line commented on: return lock(root.append("locks").append("vespaServerPoolLock"), defaultLockTimeout);

Revised code:
public Lock lockVespaServerPool() {
        return lock(root.append("locks").append("vespaServerPoolLock"), Duration.ofSeconds(1));
    }
Code review comment: @gastaldi How does it look now ? (FYI, I've dropped a `dynamicTenantsConfig` map check as it is initialized in a `PostConstruct` method)

Code under review:
private TenantConfigContext getTenantConfigFromTenantResolver(RoutingContext context) {
        Assert.assertNotNull(staticTenantsConfig);

        String tenantId = null;

        if (tenantResolver.isResolvable()) {
            tenantId = tenantResolver.get().resolve(context);
        }

        TenantConfigContext configContext = tenantId != null ? staticTenantsConfig.get(tenantId) : null;
        if (configContext == null) {
            if (tenantId != null && !tenantId.isEmpty()) {
                LOG.debugf("No configuration with a tenant id '%s' has been found, using the default configuration");
            }
            configContext = defaultTenant;
        }
        return configContext;
    }

Line commented on: Assert.assertNotNull(staticTenantsConfig);

Revised code:
private TenantConfigContext getTenantConfigFromTenantResolver(RoutingContext context) {
        if (staticTenantsConfig == null) {
            throw new IllegalStateException("staticTenantsConfig is null");
        }

        String tenantId = null;

        if (tenantResolver.isResolvable()) {
            tenantId = tenantResolver.get().resolve(context);
        }

        TenantConfigContext configContext = tenantId != null ? staticTenantsConfig.get(tenantId) : null;
        if (configContext == null) {
            if (tenantId != null && !tenantId.isEmpty()) {
                LOG.debugf("No configuration with a tenant id '%s' has been found, using the default configuration");
            }
            configContext = defaultTenant;
        }
        return configContext;
    }
Code review comment: Don't use `+ exception`. Instead pass it as param `LOGGER.logExceptionAsError(new IllegalArgumentException(                 "Can't parse Feature Flag configuration setting value.", exception))`. Or use `exception.getMessage()`.

Code under review:
private void updateSettingValue() {
        try {
            super.setValue(writeFeatureFlagConfigurationSetting(this));
        } catch (IOException exception) {
            LOGGER.logExceptionAsError(new IllegalArgumentException(
                "Can't parse Feature Flag configuration setting value. Exception:" + exception));
        }
    }

Line commented on: "Can't parse Feature Flag configuration setting value. Exception:" + exception));

Revised code:
private void updateSettingValue() {
        try {
            super.setValue(writeFeatureFlagConfigurationSetting(this));
        } catch (IOException exception) {
            LOGGER.logExceptionAsError(new IllegalArgumentException(
                "Can't parse Feature Flag configuration setting value.", exception));
        }
    }
Code review comment: I wanted to say that what the user ultimately needs to do is _not_ setting our config property, but make sure that the app's service account has access to secrets.  Obviously `quarkus.kubernetes-config.secrets.enabled` is the easiest way, if people use the Kubernetes extension. But that doesn't always have to be the case.

Code under review:
public void warnAboutSecrets(KubernetesConfigSourceConfig config, KubernetesConfigBuildTimeConfig buildTimeConfig) {
        if (config.enabled
                && config.secrets.isPresent()
                && !config.secrets.get().isEmpty()
                && !buildTimeConfig.secretsEnabled) {
            log.warn("Configuration is read from Secrets " + config.secrets.get()
                    + ", but quarkus.kubernetes-config.secrets.enabled is false."
                    + " Check if your application's service account has enough permissions to read secrets.");
        }
    }

Line commented on: + " Check if your application's service account has enough permissions to read secrets.");

Revised code:
public void warnAboutSecrets(KubernetesConfigSourceConfig config, KubernetesConfigBuildTimeConfig buildTimeConfig) {
        if (config.enabled
                && config.secrets.isPresent()
                && !config.secrets.get().isEmpty()
                && !buildTimeConfig.secretsEnabled) {
            log.warn("Configuration is read from Secrets " + config.secrets.get()
                    + ", but quarkus.kubernetes-config.secrets.enabled is false."
                    + " Check if your application's service account has enough permissions to read secrets.");
        }
    }
Code review comment: why we can insert null partition?  There are many points that need to be adapted if we support it.

Code under review:
public static PartitionData partitionDataFromPath(String relativePartitionPath, PartitionSpec spec) {
        PartitionData data = new PartitionData(spec.fields().size());
        String[] partitions = relativePartitionPath.split("/", -1);
        List<PartitionField> partitionFields = spec.fields();

        for (int i = 0; i < partitions.length; i++) {
            PartitionField field = partitionFields.get(i);
            String[] parts = partitions[i].split("=", 2);
            Preconditions.checkArgument(parts.length == 2 && parts[0] != null &&
                    field.name().equals(parts[0]), "Invalid partition: %s", partitions[i]);

            org.apache.iceberg.types.Type sourceType = spec.partitionType().fields().get(i).type();
            if (parts[1].equals("null")) {
                data.set(i, null);
            } else {
                data.set(i, Conversions.fromPartitionString(sourceType, parts[1]));
            }
        }
        return data;
    }

Line commented on: if (parts[1].equals("null")) {

Revised code:
public static PartitionData partitionDataFromPath(String relativePartitionPath, PartitionSpec spec) {
        PartitionData data = new PartitionData(spec.fields().size());
        String[] partitions = relativePartitionPath.split("/", -1);
        List<PartitionField> partitionFields = spec.fields();

        for (int i = 0; i < partitions.length; i++) {
            PartitionField field = partitionFields.get(i);
            String[] parts = partitions[i].split("=", 2);
            Preconditions.checkArgument(parts.length == 2 && parts[0] != null &&
                    field.name().equals(parts[0]), "Invalid partition: %s", partitions[i]);

            org.apache.iceberg.types.Type sourceType = spec.partitionType().fields().get(i).type();
            if (parts[1].equals("null")) {
                data.set(i, null);
            } else {
                data.set(i, Conversions.fromPartitionString(sourceType, parts[1]));
            }
        }
        return data;
    }
Code review comment: I guess empty String is better.

Code under review:
public String getSchema() throws SQLException {
        return null;
    }

Line commented on: return null;

Revised code:
public String getSchema() throws SQLException {
        return "";
    }
Code review comment: Maybe `TableExtractor` could provide a `extractTablesFromDML` or `extractTablesFromSQLStatement` function to hide these calls.

Code under review:
private Collection<SimpleTableSegment> extractTablesFromExplain(final ExplainStatement sqlStatement) {
        Collection<SimpleTableSegment> result = new LinkedList<>();
        ExplainStatementHandler.getSimpleTableSegment(sqlStatement).ifPresent(result::add);
        SQLStatement explainableStatement = sqlStatement.getStatement().orElse(null);
        TableExtractor extractor = new TableExtractor();
        if (explainableStatement instanceof SelectStatement) {
            extractor.extractTablesFromSelect((SelectStatement) explainableStatement);
        } else if (explainableStatement instanceof InsertStatement) {
            extractor.extractTablesFromInsert((InsertStatement) explainableStatement);
        } else if (explainableStatement instanceof UpdateStatement) {
            extractor.extractTablesFromUpdate((UpdateStatement) explainableStatement);
        } else if (explainableStatement instanceof DeleteStatement) {
            extractor.extractTablesFromDelete((DeleteStatement) explainableStatement);
        }
        
        result.addAll(extractor.getRewriteTables());
        return result;
    }

Line commented on: extractor.extractTablesFromDelete((DeleteStatement) explainableStatement);

Revised code:
private Collection<SimpleTableSegment> extractTablesFromExplain(final ExplainStatement sqlStatement) {
        Collection<SimpleTableSegment> result = new LinkedList<>();
        ExplainStatementHandler.getSimpleTableSegment(sqlStatement).ifPresent(result::add);
        SQLStatement explainableStatement = sqlStatement.getStatement().orElse(null);
        TableExtractor extractor = new TableExtractor();
        
        extractor.extractTablesFromSQLStatement(explainableStatement);
        result.addAll(extractor.getRewriteTables());
        return result;
    }
Code review comment: Yes, according to the design doc, it has to go as POST.

Code under review:
private Mono<RxDocumentServiceResponse> deleteByPartitionKey(RxDocumentServiceRequest request) {
        return this.performRequest(request, HttpMethod.POST);
    }

Line commented on: return this.performRequest(request, HttpMethod.POST);

Revised code:
private Mono<RxDocumentServiceResponse> deleteByPartitionKey(RxDocumentServiceRequest request) {
        return this.performRequest(request, HttpMethod.POST);
    }
Code review comment: Ah yes, I can't read :man_facepalming:

Code under review:
private List<Path> getMatchingFiles(Instant from, Instant to) {
        Map<Path, Instant> paths = new HashMap<>();
        try {
            Files.walkFileTree(logDirectory, new SimpleFileVisitor<>() {

                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
                    if (logFilePattern.matcher(file.getFileName().toString()).matches())
                        paths.put(file, attrs.lastModifiedTime().toInstant());

                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
                    return FileVisitResult.CONTINUE;
                }
            });
        }
        catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        List<Path> sorted = new ArrayList<>();
        for (var entries = paths.entrySet().stream().sorted(comparing(Map.Entry::getValue)).iterator(); entries.hasNext(); ) {
            var entry = entries.next();
            if (entry.getValue().isAfter(from))
                sorted.add(entry.getKey());
            if (entry.getValue().isAfter(to))
                break;
        }
        return sorted;
    }

Line commented on: if (entry.getValue().isAfter(to))

Revised code:
private List<Path> getMatchingFiles(Instant from, Instant to) {
        Map<Path, Instant> paths = new HashMap<>();
        try {
            Files.walkFileTree(logDirectory, new SimpleFileVisitor<>() {

                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
                    if (logFilePattern.matcher(file.getFileName().toString()).matches())
                        paths.put(file, attrs.lastModifiedTime().toInstant());

                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
                    return FileVisitResult.CONTINUE;
                }
            });
        }
        catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        List<Path> sorted = new ArrayList<>();
        for (var entries = paths.entrySet().stream().sorted(comparing(Map.Entry::getValue)).iterator(); entries.hasNext(); ) {
            var entry = entries.next();
            if (entry.getValue().isAfter(from))
                sorted.add(entry.getKey());
            if (entry.getValue().isAfter(to))
                break;
        }
        return sorted;
    }
Code review comment: maybe ABORTED is better, didn't want to overload a status that is uses on the backend.  should we add a new enum value?

Code under review:
public static CompleteCommit forFailedWork(Commit commit) {
    return create(commit, CommitStatus.DEFAULT);
  }

Line commented on: return create(commit, CommitStatus.DEFAULT);

Revised code:
public static CompleteCommit forFailedWork(Commit commit) {
    return create(commit, CommitStatus.ABORTED);
  }
Code review comment: I don't think we can use `==` here

Code under review:
public static boolean decimalSubtypeContains(SubtypeData d, EnumerableDecimal f) {
        if (d instanceof AllOrNothingSubtype) {
            return ((AllOrNothingSubtype) d).isAllSubtype();
        }

        DecimalSubtype v = (DecimalSubtype) d;
        for (EnumerableType val : v.values) {
            if (val == f) {
                return v.allowed;
            }
        }
        return !v.allowed;
    }

Line commented on: if (val == f) {

Revised code:
public static boolean decimalSubtypeContains(SubtypeData d, EnumerableDecimal f) {
        if (d instanceof AllOrNothingSubtype) {
            return ((AllOrNothingSubtype) d).isAllSubtype();
        }

        DecimalSubtype v = (DecimalSubtype) d;
        for (EnumerableType val : v.values) {
            if (val == f) {
                return v.allowed;
            }
        }
        return !v.allowed;
    }
Code review comment: Ok,I will check if the return value of `getCatalog` is null

Code under review:
public void run() {
            for (Map.Entry<Long, Integer[]> entry : refreshMap.entrySet()) {
                Long catalogId = entry.getKey();
                Integer[] timeGroup = entry.getValue();
                Integer original = timeGroup[0];
                Integer current = timeGroup[1];
                if (current - REFRESH_TIME > 0) {
                    timeGroup[1] = current - REFRESH_TIME;
                    refreshMap.put(catalogId, timeGroup);
                } else {
                    String catalogName = Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogId).getName();
                    RefreshCatalogStmt refreshCatalogStmt = new RefreshCatalogStmt(catalogName, null);
                    try {
                        DdlExecutor.execute(Env.getCurrentEnv(), refreshCatalogStmt);
                    } catch (Exception e) {
                        LOG.warn("failed to refresh catalog {}", catalogName, e);
                    }
                    
                    timeGroup[1] = original;
                    refreshMap.put(catalogId, timeGroup);
                }
            }
        }

Line commented on: String catalogName = Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogId).getName();

Revised code:
public void run() {
            for (Map.Entry<Long, Integer[]> entry : refreshMap.entrySet()) {
                Long catalogId = entry.getKey();
                Integer[] timeGroup = entry.getValue();
                Integer original = timeGroup[0];
                Integer current = timeGroup[1];
                if (current - REFRESH_TIME_SEC > 0) {
                    timeGroup[1] = current - REFRESH_TIME_SEC;
                    refreshMap.put(catalogId, timeGroup);
                } else {
                    CatalogIf catalog = Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogId);
                    if (catalog != null) {
                        String catalogName = catalog.getName();
                        RefreshCatalogStmt refreshCatalogStmt = new RefreshCatalogStmt(catalogName, null);
                        try {
                            DdlExecutor.execute(Env.getCurrentEnv(), refreshCatalogStmt);
                        } catch (Exception e) {
                            LOG.warn("failed to refresh catalog {}", catalogName, e);
                        }
                        
                        timeGroup[1] = original;
                        refreshMap.put(catalogId, timeGroup);
                    }
                }
            }
        }
Code review comment: I saw you have tests with finish reasons `stop` and `length`. How about cases for `content_filter` or `null`?  I actually don't know how useful those would be, I only found them when searching for `finish_reason` [values](https://platform.openai.com/docs/guides/chat/response-format) (which I only could only find with an advanced Bing search query, does the OpenAI documentation really not have a "search" feature?)

Code under review:
static void assertCompletions(int choicesPerPrompt, Completions actual) {
        assertCompletions(choicesPerPrompt, "stop", actual);
    }

Line commented on: assertCompletions(choicesPerPrompt, "stop", actual);

Revised code:
static void assertCompletions(int choicesPerPrompt, Completions actual) {
        assertCompletions(choicesPerPrompt, "stop", actual);
    }
Code review comment: Please use the scheduled executor service from ExecutorOptions once it is merged from https://github.com/apache/beam/pull/23234

Code under review:
private void doClose() {

      try {
        closeAutoscaler();
        closeConsumer();
        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
        executorService.schedule(
            () -> {
              LOG.debug(
                  "Closing session and connection after delay {}", source.spec.getCloseTimeout());
              
              checkpointMark.discard();
              closeSession();
              closeConnection();
            },
            source.spec.getCloseTimeout(),
            TimeUnit.MILLISECONDS);

      } catch (Exception e) {
        LOG.error("Error closing reader", e);
      }
    }

Line commented on: ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();

Revised code:
private void doClose() {

      try {
        closeAutoscaler();
        closeConsumer();
        ScheduledExecutorService executorService =
            options.as(ExecutorOptions.class).getScheduledExecutorService();
        executorService.schedule(
            () -> {
              LOG.debug(
                  "Closing session and connection after delay {}", source.spec.getCloseTimeout());
              
              checkpointMark.discard();
              closeSession();
              closeConnection();
            },
            source.spec.getCloseTimeout().getMillis(),
            TimeUnit.MILLISECONDS);

      } catch (Exception e) {
        LOG.error("Error closing reader", e);
      }
    }
Code review comment: ## Accessing files should not lead to filesystem oracle attacks  <!--SONAR_ISSUE_KEY:AYtAxwZ6agaDI_wZ9Hvt-->Change this code to not construct the path from user-controlled data. <p>See more on <a href="https://sonarcloud.io/project/issues?id=metersphere_metersphere&issues=AYtAxwZ6agaDI_wZ9Hvt&open=AYtAxwZ6agaDI_wZ9Hvt&pullRequest=27130">SonarCloud</a></p>  [Show more details](https://github.com/metersphere/metersphere/security/code-scanning/109)

Code under review:
public String loadPlugin(String fileName) {
        String filePath = MsFileUtils.PLUGIN_DIR + "/" + fileName;
        File file = new File(filePath);
        if (!file.exists()) {
            
            downloadPluginFromRepository(fileName);
        }
        return msPluginManager.loadPlugin(Paths.get(filePath));
    }


Revised code:
public String loadPlugin(String fileName) {
        MsFileUtils.validateFileName(fileName);
        String filePath = MsFileUtils.PLUGIN_DIR + "/" + fileName;
        File file = new File(filePath);
        if (!file.exists()) {
            
            downloadPluginFromRepository(fileName);
        }
        return msPluginManager.loadPlugin(Paths.get(filePath));
    }
Code review comment: no idea why this particular zone requires 4G RAM, sounds wrong - should not be needed - you can leave be and we can remove once we know why we need this - @hmusum ?

Code under review:
private NodeResources defaultNodeResources(ClusterSpec.Type clusterType) {
        if (zone.system() == SystemName.PublicCd && clusterType == ClusterSpec.Type.admin && zone.environment() != Environment.prod)
            return new NodeResources(1, 3, 50);

        if (zone.system() == SystemName.cd && zone.environment() == Environment.dev && zone.region().value().equals("cd-us-west-1"))
            return new NodeResources(1, 4, 50);

        if (zone.system() == SystemName.cd && zone.environment() == Environment.test || zone.environment() == Environment.staging)
            return clusterType == ClusterSpec.Type.admin ? new NodeResources(1, 3, 50)
                                                         : new NodeResources(4, 4, 50);

        return new NodeResources(2, 8, 50);
    }

Line commented on: return new NodeResources(1, 4, 50);

Revised code:
private NodeResources defaultNodeResources(ClusterSpec.Type clusterType) {
        if (clusterType == ClusterSpec.Type.admin)
            return new NodeResources(0.5, 3, 50);

        if (zone.system() == SystemName.cd && zone.environment().isTest())
            new NodeResources(4, 4, 50);

        return new NodeResources(2, 8, 50);
    }
Code review comment: Can you add tests for some of the new utilities ? For example, PendingJobManager and PendingJob.

Code under review:
public void testWriteUnknown() throws Exception {
    p.apply(
            Create.of(
                    new TableRow().set("name", "a").set("number", 1),
                    new TableRow().set("name", "b").set("number", 2),
                    new TableRow().set("name", "c").set("number", 3))
                .withCoder(TableRowJsonCoder.of()))
        .apply(
            BigQueryIO.writeTableRows()
                .to("project-id:dataset-id.table-id")
                .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_NEVER)
                .withTestServices(fakeBqServices)
                .withoutValidation());

    thrown.expect(RuntimeException.class);
    thrown.expectMessage("Failed to create job");
    p.run();
  }

Line commented on: thrown.expectMessage("Failed to create job");

Revised code:
public void testWriteUnknown() throws Exception {
    p.apply(
            Create.of(
                    new TableRow().set("name", "a").set("number", 1),
                    new TableRow().set("name", "b").set("number", 2),
                    new TableRow().set("name", "c").set("number", 3))
                .withCoder(TableRowJsonCoder.of()))
        .apply(
            BigQueryIO.writeTableRows()
                .to("project-id:dataset-id.table-id")
                .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_NEVER)
                .withTestServices(fakeBqServices)
                .withoutValidation());

    thrown.expect(RuntimeException.class);
    thrown.expectMessage("Failed to create job");
    p.run();
  }
Code review comment: #37039 is resolved and add relevant changes in `2.0-stage` branch. So eventually it will merge into `2.x` branch and it will merge into the `master` branch as well.

Code under review:
public List<String> skipList() {
        
        return Arrays.asList("function_typedesc17.json");
    }


Revised code:
public List<String> skipList() {
        
        return Arrays.asList("function_typedesc17.json");
    }
Code review comment: We can say `isDuplicate` then. It's more intuitive.

Code under review:
private STNode createFuncDefNodeList(List<STNode> qualifierList) {
        
        
        List<STNode> validatedList = new ArrayList<>();

        for (int i = 0; i < qualifierList.size(); i++) {
            STNode qualifier = qualifierList.get(i);
            int nextIndex = i + 1;

            if (isNodeWithSyntaxKindInList(validatedList, qualifier.kind)) {
                updateLastNodeInListWithInvalidNode(validatedList, qualifier,
                        DiagnosticErrorCode.ERROR_DUPLICATE_QUALIFIER, ((STToken) qualifier).text());
            } else if (isValidFuncDefQualifier(qualifier.kind)) {
                validatedList.add(qualifier);
            } else if (qualifierList.size() != nextIndex) {
                updateANodeInListWithInvalidNode(qualifierList, nextIndex, qualifier,
                        DiagnosticErrorCode.ERROR_QUALIFIER_NOT_ALLOWED, ((STToken) qualifier).text());
            }
        }

        return STNodeFactory.createNodeList(validatedList);
    }

Line commented on: if (isNodeWithSyntaxKindInList(validatedList, qualifier.kind)) {

Revised code:
private STNode createFuncDefNodeList(List<STNode> qualifierList) {
        
        
        List<STNode> validatedList = new ArrayList<>();

        for (int i = 0; i < qualifierList.size(); i++) {
            STNode qualifier = qualifierList.get(i);
            int nextIndex = i + 1;

            if (isDuplicate(validatedList, qualifier.kind)) {
                updateLastNodeInListWithInvalidNode(validatedList, qualifier,
                        DiagnosticErrorCode.ERROR_DUPLICATE_QUALIFIER, ((STToken) qualifier).text());
            } else if (isValidFuncDefQualifier(qualifier.kind)) {
                validatedList.add(qualifier);
            } else if (qualifierList.size() != nextIndex) {
                updateANodeInListWithInvalidNode(qualifierList, nextIndex, qualifier,
                        DiagnosticErrorCode.ERROR_QUALIFIER_NOT_ALLOWED, ((STToken) qualifier).text());
            }
        }

        return STNodeFactory.createNodeList(validatedList);
    }
Code review comment: I'd prefer it to log and throw - it's an invalid Content-Range header and there is no recovery from it

Code under review:
public static long extractSizeFromContentRange(String contentRange) {
        Objects.requireNonNull(contentRange, "Cannot extract length from null 'contentRange'.");
        int index = contentRange.indexOf('/');

        if (index == -1) {
            
            return -2;
        }

        String sizeString = contentRange.substring(index + 1).trim();
        if ("*".equals(sizeString)) {
            
            return -1;
        }

        return Long.parseLong(sizeString);
    }

Line commented on: return -2;

Revised code:
public static long extractSizeFromContentRange(String contentRange) {
        Objects.requireNonNull(contentRange, "Cannot extract length from null 'contentRange'.");
        int index = contentRange.indexOf('/');

        if (index == -1) {
            
            throw LOGGER.logExceptionAsError(new IllegalArgumentException("The Content-Range header wasn't properly "
                + "formatted and didn't contain a '/size' segment. The 'contentRange' was: " + contentRange));
        }

        String sizeString = contentRange.substring(index + 1).trim();
        if ("*".equals(sizeString)) {
            
            return -1;
        }

        return Long.parseLong(sizeString);
    }
Code review comment: Not sure. So I made a new check here.

Code under review:
public void clearSparkLauncherLog() {
        String logPath = sparkLoadAppHandle.getLogPath();
        if (!Strings.isNullOrEmpty(logPath)) {
            File file = new File(logPath);
            if (file.exists()) {
                file.delete();
            }
        }
    }

Line commented on: String logPath = sparkLoadAppHandle.getLogPath();

Revised code:
public void clearSparkLauncherLog() {
        if (sparkLoadAppHandle != null) {
            String logPath = sparkLoadAppHandle.getLogPath();
            if (!Strings.isNullOrEmpty(logPath)) {
                File file = new File(logPath);
                if (file.exists()) {
                    file.delete();
                }
            }
        }
    }
Code review comment: ```suggestion         getProject().getLogger().warn("quarkus info is experimental, its options and output might change in future versions"); ```  In maven output this comes possibly many many lines away from what you just executed thus better to be explicit.

Code under review:
public void logInfo() {

        getProject().getLogger().warn("This task is experimental, its options and output might change in future versions");

        final QuarkusProject quarkusProject = getQuarkusProject(false);
        final Map<String, Object> params = new HashMap<>();
        params.put(UpdateCommandHandler.APP_MODEL, extension().getApplicationModel());
        params.put(UpdateCommandHandler.LOG_STATE_PER_MODULE, perModule);
        final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, params);
        final QuarkusCommandOutcome outcome;
        try {
            outcome = new InfoCommandHandler().execute(invocation);
        } catch (Exception e) {
            throw new GradleException("Failed to collect Quarkus project information", e);
        }
        if (outcome.getValue(InfoCommandHandler.RECOMMENDATIONS_AVAILABLE, false)) {
            this.getProject().getLogger().warn(
                    "Non-recommended Quarkus platform BOM and/or extension versions were found. For more details, please, execute 'gradle quarkusUpdate --rectify'");
        }
    }

Line commented on: getProject().getLogger().warn("This task is experimental, its options and output might change in future versions");

Revised code:
public void logInfo() {

        getProject().getLogger().warn(getName() + " is experimental, its options and output might change in future versions");

        final QuarkusProject quarkusProject = getQuarkusProject(false);
        final Map<String, Object> params = new HashMap<>();
        params.put(UpdateCommandHandler.APP_MODEL, extension().getApplicationModel());
        params.put(UpdateCommandHandler.LOG_STATE_PER_MODULE, perModule);
        final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, params);
        final QuarkusCommandOutcome outcome;
        try {
            outcome = new InfoCommandHandler().execute(invocation);
        } catch (Exception e) {
            throw new GradleException("Failed to collect Quarkus project information", e);
        }
        if (outcome.getValue(InfoCommandHandler.RECOMMENDATIONS_AVAILABLE, false)) {
            this.getProject().getLogger().warn(
                    "Non-recommended Quarkus platform BOM and/or extension versions were found. For more details, please, execute 'gradle quarkusUpdate --rectify'");
        }
    }
Code review comment: This should be in a try with resources block, or better yet just use Files.write()

Code under review:
public static void writeFile(OutputTargetBuildItem target, String name, String output) throws IOException {
        FileOutputStream os = new FileOutputStream(target.getOutputDirectory().resolve(name).toFile());
        os.write(output.getBytes(StandardCharsets.UTF_8));
        os.close();
    }

Line commented on: FileOutputStream os = new FileOutputStream(target.getOutputDirectory().resolve(name).toFile());

Revised code:
public static void writeFile(OutputTargetBuildItem target, String name, String output) throws IOException {
        Path artifact = target.getOutputDirectory().resolve(name);
        String targetUri = target.getOutputDirectory().resolve("function.zip").toUri().toString().replace("file:", "fileb:");
        output = output.replace("${artifactId}", target.getBaseName())
                .replace("${buildDir}", target.getOutputDirectory().toString())
                .replace("${targetUri}", targetUri);
        Files.write(artifact, output.getBytes(StandardCharsets.UTF_8));
    }