muttakin2301/ccr_train_1000 huggingface dataset:
Code review comment: The merge function itself now verifies this.

Code before review:
public PCollection<Row> expand(PCollectionList<Row> inputs) {
checkArgument(
inputs.size() == 2,
"Wrong number of arguments to %s: %s",
beamRelNode.getClass().getSimpleName(),
inputs);
PCollection<Row> leftRows = inputs.get(0);
PCollection<Row> rightRows = inputs.get(1);
WindowFn leftWindow = leftRows.getWindowingStrategy().getWindowFn();
WindowFn rightWindow = rightRows.getWindowingStrategy().getWindowFn();
if (!leftWindow.isCompatible(rightWindow)) {
throw new IllegalArgumentException(
"inputs of "
+ opType
+ " have different window strategy: "
+ leftWindow
+ " VS "
+ rightWindow);
}
final String lhsTag = "lhs";
final String rhsTag = "rhs";
PCollection<Row> joined =
PCollectionTuple.of(lhsTag, leftRows, rhsTag, rightRows)
.apply("CoGroup", CoGroup.join(By.fieldNames("*")));
return joined
.apply(
"FilterResults",
ParDo.of(
new BeamSetOperatorsTransforms.SetOperatorFilteringDoFn(
lhsTag, rhsTag, opType, all)))
.setRowSchema(joined.getSchema().getField("key").getType().getRowSchema());
}

Line under review: + rightWindow);

Code after addressing the review:
public PCollection<Row> expand(PCollectionList<Row> inputs) {
checkArgument(
inputs.size() == 2,
"Wrong number of arguments to %s: %s",
beamRelNode.getClass().getSimpleName(),
inputs);
PCollection<Row> leftRows = inputs.get(0);
PCollection<Row> rightRows = inputs.get(1);
WindowFn leftWindow = leftRows.getWindowingStrategy().getWindowFn();
WindowFn rightWindow = rightRows.getWindowingStrategy().getWindowFn();
if (!leftWindow.isCompatible(rightWindow)) {
throw new IllegalArgumentException(
"inputs of "
+ opType
+ " have different window strategy: "
+ leftWindow
+ " VS "
+ rightWindow);
}
final String lhsTag = "lhs";
final String rhsTag = "rhs";
PCollection<Row> joined =
PCollectionTuple.of(lhsTag, leftRows, rhsTag, rightRows)
.apply("CoGroup", CoGroup.join(By.fieldNames("*")));
return joined
.apply(
"FilterResults",
ParDo.of(
new BeamSetOperatorsTransforms.SetOperatorFilteringDoFn(
lhsTag, rhsTag, opType, all)))
.setRowSchema(joined.getSchema().getField("key").getType().getRowSchema());
}
Code review comment: Does this mean it use a expr parition?

Code before review:
public boolean hasPartitionTransformedEvolution() {
return getNativeTable().spec().fields().stream().anyMatch(field -> field.transform().isVoid());
}

Line under review: return getNativeTable().spec().fields().stream().anyMatch(field -> field.transform().isVoid());

Code after addressing the review:
public boolean hasPartitionTransformedEvolution() {
return getNativeTable().spec().fields().stream().anyMatch(field -> field.transform().isVoid());
}
Code review comment: shouldn't this also throw an `IllegalStateException` if `error == null` like `getRestartDelayMS` and `getVerticesToRestart`?

Code before review:
public Throwable getError() {
return error;
}

Line under review: return error;

Code after addressing the review:
public Throwable getError() {
if (canRestart()) {
throw new IllegalStateException("Cannot get error when the restarting is accepted.");
} else {
return error;
}
}
Code review comment: Replace if else return and assign statement with ternary operator in priority

Code before review:
private int getColumnsCount(final SQLStatement sqlStatement) {
if (sqlStatement instanceof SelectStatement) {
return ((SelectStatement) sqlStatement).getProjections().getProjections().size();
}
return 0;
}

Line under review: return 0;

Code after addressing the review:
private int getColumnsCount(final SQLStatement sqlStatement) {
return sqlStatement instanceof SelectStatement ? ((SelectStatement) sqlStatement).getProjections().getProjections().size() : 0;
}
Code review comment: This becomes `null` for the cases like this ```ballerina public function main() {     var a = flush; } ```

Code before review:
public void visit(BLangWorkerFlushExpr workerFlushExpr) {
if (workerFlushExpr.workerSymbol == null) {
return;
}
addIfSameSymbol(workerFlushExpr.workerSymbol, workerFlushExpr.workerIdentifier.pos);
}

Line under review: if (workerFlushExpr.workerSymbol == null) {

Code after addressing the review:
public void visit(BLangWorkerFlushExpr workerFlushExpr) {
if (workerFlushExpr.workerIdentifier == null) {
return;
}
addIfSameSymbol(workerFlushExpr.workerSymbol, workerFlushExpr.workerIdentifier.pos);
}
Code review comment: Maybe also check that `SomethingRemovable`  can be looked up independently?

Code before review:
public void testBeanNotRemoved() {
List<String> list = Arc.container().instance(new TypeLiteral<List<String>>() {
}).get();
assertNotNull(list);
assertEquals(1, list.size());
assertEquals(SomethingRemovable.STR, list.get(0));
}

Line under review: }

Code after addressing the review:
public void testBeanNotRemoved() {
List<String> list = Arc.container().instance(new TypeLiteral<List<String>>() {
}).get();
assertNotNull(list);
assertEquals(1, list.size());
assertEquals(SomethingRemovable.STR, list.get(0));
}
Code review comment: Could these lines be moved outside of `assertThatThrownBy`?

Code before review:
void testCheckpointFailueOnClosedOperator() throws Exception {
ClosingOperator<Integer> operator = new ClosingOperator<>();
StreamTaskMailboxTestHarnessBuilder<Integer> builder =
new StreamTaskMailboxTestHarnessBuilder<>(
OneInputStreamTask::new, BasicTypeInfo.INT_TYPE_INFO)
.addInput(BasicTypeInfo.INT_TYPE_INFO);
try (StreamTaskMailboxTestHarness<Integer> harness =
builder.setupOutputForSingletonOperatorChain(operator).build()) {
assertThatThrownBy(
() -> {
harness.setAutoProcess(false);
harness.processElement(new StreamRecord<>(1));
harness.streamTask.operatorChain.finishOperators(
harness.streamTask.getActionExecutor(), StopMode.DRAIN);
harness.streamTask.operatorChain.closeAllOperators();
assertThat(ClosingOperator.closed.get()).isTrue();
harness.streamTask.triggerCheckpointOnBarrier(
new CheckpointMetaData(1, 0),
CheckpointOptions.forCheckpointWithDefaultLocation(),
new CheckpointMetricsBuilder());
})
.satisfies(
(Consumer<Throwable>)
throwable ->
ExceptionUtils.assertThrowableWithMessage(
throwable,
"OperatorChain and Task should never be closed at this point"));
}
}

Line under review: assertThat(ClosingOperator.closed.get()).isTrue();

Code after addressing the review:
void testCheckpointFailueOnClosedOperator() throws Exception {
ClosingOperator<Integer> operator = new ClosingOperator<>();
StreamTaskMailboxTestHarnessBuilder<Integer> builder =
new StreamTaskMailboxTestHarnessBuilder<>(
OneInputStreamTask::new, BasicTypeInfo.INT_TYPE_INFO)
.addInput(BasicTypeInfo.INT_TYPE_INFO);
try (StreamTaskMailboxTestHarness<Integer> harness =
builder.setupOutputForSingletonOperatorChain(operator).build()) {
harness.setAutoProcess(false);
harness.processElement(new StreamRecord<>(1));
harness.streamTask.operatorChain.finishOperators(
harness.streamTask.getActionExecutor(), StopMode.DRAIN);
harness.streamTask.operatorChain.closeAllOperators();
assertThat(ClosingOperator.closed.get()).isTrue();
assertThatThrownBy(
() ->
harness.streamTask.triggerCheckpointOnBarrier(
new CheckpointMetaData(1, 0),
CheckpointOptions.forCheckpointWithDefaultLocation(),
new CheckpointMetricsBuilder()))
.satisfies(
anyCauseMatches(
"OperatorChain and Task should never be closed at this point"));
}
}
Code review comment: ditto, here and other places for the new methods, the implementation is the same as parent class why are they needed in every child class?

Code before review:
public String getString(String propertyName) {
return super.getString(propertyName);
}

Line under review: return super.getString(propertyName);

Code after addressing the review:
public String getString(String propertyName) {
return super.getString(propertyName);
}
Code review comment: missing "that" after value, (more occurrences in other files)

Code before review:
public String getDescription() {
return "String value specifies the fully qualified name of the entry point class. " +
"Overrides the class defined in the jar file manifest.";
}

Line under review: return "String value specifies the fully qualified name of the entry point class. " +

Code after addressing the review:
public String getDescription() {
return "String value that specifies the fully qualified name of the entry point class. " +
"Overrides the class defined in the jar file manifest.";
}
Code review comment: I would instead do something like:  ```java for (Handler h : InitialConfigurator.DELAYED_HANDLER.clearHandlers()) {     try {         h.close();     } catch (Throwable ignored) {     } } ```  This way a subsequent dev mode iteration is more likely to work correctly.

Code before review:
public static void printStopTime(String name) {
final long stopTimeNanoSeconds = System.nanoTime() - bootStopTime;
final Logger logger = Logger.getLogger("io.quarkus");
final BigDecimal secondsRepresentation = convertToBigDecimalSeconds(stopTimeNanoSeconds);
logger.infof("%s stopped in %ss",
(UNSET_VALUE.equals(name) || name == null || name.trim().isEmpty()) ? "Quarkus" : name,
secondsRepresentation);
bootStopTime = -1;
/**
* We can safely close log handlers after stop time has been printed.
*/
InitialConfigurator.DELAYED_HANDLER.close();
}

Line under review: InitialConfigurator.DELAYED_HANDLER.close();

Code after addressing the review:
public static void printStopTime(String name) {
final long stopTimeNanoSeconds = System.nanoTime() - bootStopTime;
final Logger logger = Logger.getLogger("io.quarkus");
final BigDecimal secondsRepresentation = convertToBigDecimalSeconds(stopTimeNanoSeconds);
logger.infof("%s stopped in %ss",
(UNSET_VALUE.equals(name) || name == null || name.trim().isEmpty()) ? "Quarkus" : name,
secondsRepresentation);
bootStopTime = -1;
/**
* We can safely close log handlers after stop time has been printed.
*/
Handler[] handlers = InitialConfigurator.DELAYED_HANDLER.clearHandlers();
for (Handler handler : handlers) {
try {
handler.close();
} catch (Throwable ignored) {
}
}
}
Code review comment: Shall we use a meaningful variable name?

Code before review:
private String getClassPath() {
List<Path> dependencies = new ArrayList<>();
dependencies.add(ProjectUtils.getBallerinaRTJarPath());
dependencies.addAll(ProjectUtils.testDependencies());
StringJoiner cp = new StringJoiner(File.pathSeparator);
dependencies.stream().map(Path::toString).forEach(cp::add);
return cp.toString();
}

Line under review: StringJoiner cp = new StringJoiner(File.pathSeparator);

Code after addressing the review:
private String getClassPath() {
List<Path> dependencies = new ArrayList<>();
dependencies.add(ProjectUtils.getBallerinaRTJarPath());
dependencies.addAll(ProjectUtils.testDependencies());
StringJoiner classPath = new StringJoiner(File.pathSeparator);
dependencies.stream().map(Path::toString).forEach(classPath::add);
return classPath.toString();
}
Code review comment: use the min watermark as the initial watermark?

Code before review:
public void initializeState(StateInitializationContext context) throws Exception {
super.initializeState(context);
ListStateDescriptor<Long> watermarkStateDesc =
new ListStateDescriptor<>("watermark", LongSerializer.INSTANCE);
this.watermarkState = context.getOperatorStateStore().getListState(watermarkStateDesc);
if (context.isRestored()) {
this.currentWatermark = this.watermarkState.get().iterator().next();
}
}

Line under review: this.currentWatermark = this.watermarkState.get().iterator().next();

Code after addressing the review:
public void initializeState(StateInitializationContext context) throws Exception {
super.initializeState(context);
ListStateDescriptor<Long> watermarkStateDesc =
new ListStateDescriptor<>("watermark", LongSerializer.INSTANCE);
this.watermarkState = context.getOperatorStateStore().getUnionListState(watermarkStateDesc);
if (context.isRestored()) {
Iterable<Long> watermarks = watermarkState.get();
if (watermarks != null) {
Long minWatermark = Long.MAX_VALUE;
for (Long watermark : watermarks) {
minWatermark = Math.min(watermark, minWatermark);
}
if (minWatermark != Long.MAX_VALUE) {
this.currentWatermark = minWatermark;
}
}
}
}
Code review comment: What is the default timeout? Could we make sure it doesn't wait too much?

Code before review:
public void testContextPropagationInFaultTolerance() {
try {
RestAssured.defaultParser = Parser.TEXT;
Response response = RestAssured.when().get("/faultTolerance");
response.then().statusCode(200);
Assertions.assertEquals("fallback", response.body().asString());
Awaitility.await().until(() -> mockTracer.finishedSpans().size() == 5);
List<MockSpan> spans = mockTracer.finishedSpans();
Assertions.assertEquals(5, spans.size());
for (MockSpan mockSpan : spans) {
Assertions.assertEquals(spans.get(0).context().traceId(), mockSpan.context().traceId());
}
Assertions.assertEquals("ft", mockTracer.finishedSpans().get(0).operationName());
Assertions.assertEquals("ft", mockTracer.finishedSpans().get(1).operationName());
Assertions.assertEquals("ft", mockTracer.finishedSpans().get(2).operationName());
Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.fallback",
mockTracer.finishedSpans().get(3).operationName());
Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.faultTolerance",
mockTracer.finishedSpans().get(4).operationName());
} finally {
RestAssured.reset();
}
}

Line under review: Awaitility.await().until(() -> mockTracer.finishedSpans().size() == 5);

Code after addressing the review:
public void testContextPropagationInFaultTolerance() {
try {
RestAssured.defaultParser = Parser.TEXT;
Response response = RestAssured.when().get("/faultTolerance");
response.then().statusCode(200);
Assertions.assertEquals("fallback", response.body().asString());
Awaitility.await().atMost(5, TimeUnit.SECONDS)
.until(() -> mockTracer.finishedSpans().size() == 5);
List<MockSpan> spans = mockTracer.finishedSpans();
Assertions.assertEquals(5, spans.size());
for (MockSpan mockSpan : spans) {
Assertions.assertEquals(spans.get(0).context().traceId(), mockSpan.context().traceId());
}
Assertions.assertEquals("ft", mockTracer.finishedSpans().get(0).operationName());
Assertions.assertEquals("ft", mockTracer.finishedSpans().get(1).operationName());
Assertions.assertEquals("ft", mockTracer.finishedSpans().get(2).operationName());
Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.fallback",
mockTracer.finishedSpans().get(3).operationName());
Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.faultTolerance",
mockTracer.finishedSpans().get(4).operationName());
} finally {
RestAssured.reset();
}
}
Code review comment: Or even better to get rid of `annotCount` from `startLambdaFunctionDef` because Lambdas can't have annotations anyway.

Code before review:
void startWorker(PackageID pkgID) {
this.startLambdaFunctionDef(pkgID, 0);
BLangFunction lambdaFunction = (BLangFunction) this.invokableNodeStack.peek();
lambdaFunction.addFlag(Flag.WORKER);
this.startBlock();
}

Line under review: this.startLambdaFunctionDef(pkgID, 0);

Code after addressing the review:
void startWorker(PackageID pkgID) {
this.startLambdaFunctionDef(pkgID);
BLangFunction lambdaFunction = (BLangFunction) this.invokableNodeStack.peek();
lambdaFunction.addFlag(Flag.WORKER);
this.startBlock();
}
Code review comment: Why should we add `synchronized`? `flush()` is already `synchronized`, right? 

Code before review:
public void open(int taskNumber, int numTasks) throws IOException {
try {
establishConnection();
if (keyFields == null || keyFields.length == 0) {
String insertSQL = dialect.getInsertIntoStatement(tableName, fieldNames);
jdbcWriter = new AppendOnlyWriter(insertSQL, fieldTypes);
} else {
jdbcWriter = UpsertWriter.create(
dialect, tableName, fieldNames, fieldTypes, keyFields,
getRuntimeContext().getExecutionConfig().isObjectReuseEnabled());
}
jdbcWriter.open(connection);
} catch (SQLException sqe) {
throw new IllegalArgumentException("open() failed.", sqe);
} catch (ClassNotFoundException cnfe) {
throw new IllegalArgumentException("JDBC driver class not found.", cnfe);
}
if (flushIntervalMills != 0) {
this.scheduler = Executors.newScheduledThreadPool(
1, new ExecutorThreadFactory("jdbc-upsert-output-format"));
this.scheduledFuture = this.scheduler.scheduleWithFixedDelay(() -> {
synchronized (JDBCUpsertOutputFormat.this) {
if (closed) {
return;
}
try {
flush();
} catch (Exception e) {
flushException = e;
}
}
}, flushIntervalMills, flushIntervalMills, TimeUnit.MILLISECONDS);
}
}

Line under review: synchronized (JDBCUpsertOutputFormat.this) {

Code after addressing the review:
public void open(int taskNumber, int numTasks) throws IOException {
try {
establishConnection();
if (keyFields == null || keyFields.length == 0) {
String insertSQL = dialect.getInsertIntoStatement(tableName, fieldNames);
jdbcWriter = new AppendOnlyWriter(insertSQL, fieldTypes);
} else {
jdbcWriter = UpsertWriter.create(
dialect, tableName, fieldNames, fieldTypes, keyFields,
getRuntimeContext().getExecutionConfig().isObjectReuseEnabled());
}
jdbcWriter.open(connection);
} catch (SQLException sqe) {
throw new IllegalArgumentException("open() failed.", sqe);
} catch (ClassNotFoundException cnfe) {
throw new IllegalArgumentException("JDBC driver class not found.", cnfe);
}
if (flushIntervalMills != 0) {
this.scheduler = Executors.newScheduledThreadPool(
1, new ExecutorThreadFactory("jdbc-upsert-output-format"));
this.scheduledFuture = this.scheduler.scheduleWithFixedDelay(() -> {
synchronized (JDBCUpsertOutputFormat.this) {
if (closed) {
return;
}
try {
flush();
} catch (Exception e) {
flushException = e;
}
}
}, flushIntervalMills, flushIntervalMills, TimeUnit.MILLISECONDS);
}
}
Code review comment: Wonder if we need some cleanup registry in the future to close all these connections when we shutdown the JVM.

Code before review:
public void close() throws Exception {
try (CloseableResource<JobServiceBlockingStub> jobService = this.jobService) {}
}

Line under review: try (CloseableResource<JobServiceBlockingStub> jobService = this.jobService) {}

Code after addressing the review:
public void close() {
try (CloseableResource<JobServiceBlockingStub> jobService = this.jobService) {
} catch (Exception e) {
LOG.warn("Error cleaning up job service", e);
}
}
Code review comment: Because projection has put all join output columns(JoinOrder.java:312), maybe contains some unnecessary columns, we need prune again,

Code before review:
public OptExpression rewrite(OptExpression optExpression, ColumnRefSet requiredColumns) {
Operator operator = optExpression.getOp();
if (operator.getProjection() != null && operator.getProjection().getColumnRefMap().size() > 1) {
Projection projection = operator.getProjection();
List<ColumnRefOperator> outputColumns = Lists.newArrayList();
for (ColumnRefOperator key : projection.getColumnRefMap().keySet()) {
if (requiredColumns.contains(key)) {
outputColumns.add(key);
}
}
if (outputColumns.size() == 0) {
outputColumns.add(Utils.findSmallestColumnRef(projection.getOutputColumns()));
}
if (outputColumns.size() != projection.getColumnRefMap().size()) {
Map<ColumnRefOperator, ScalarOperator> newOutputProjections = Maps.newHashMap();
for (ColumnRefOperator ref : outputColumns) {
newOutputProjections.put(ref, projection.getColumnRefMap().get(ref));
}
optExpression.getOp().setProjection(new Projection(newOutputProjections));
}
for (ScalarOperator value : optExpression.getOp().getProjection().getColumnRefMap().values()) {
requiredColumns.union(value.getUsedColumns());
}
}
return optExpression.getOp().accept(this, optExpression, requiredColumns);
}

Line under review: if (outputColumns.size() != projection.getColumnRefMap().size()) {

Code after addressing the review:
public OptExpression rewrite(OptExpression optExpression, ColumnRefSet requiredColumns) {
Operator operator = optExpression.getOp();
if (operator.getProjection() != null && operator.getProjection().getColumnRefMap().size() > 1) {
Projection projection = operator.getProjection();
List<ColumnRefOperator> outputColumns = Lists.newArrayList();
for (ColumnRefOperator key : projection.getColumnRefMap().keySet()) {
if (requiredColumns.contains(key)) {
outputColumns.add(key);
}
}
if (outputColumns.size() == 0) {
outputColumns.add(Utils.findSmallestColumnRef(projection.getOutputColumns()));
}
if (outputColumns.size() != projection.getColumnRefMap().size()) {
Map<ColumnRefOperator, ScalarOperator> newOutputProjections = Maps.newHashMap();
for (ColumnRefOperator ref : outputColumns) {
newOutputProjections.put(ref, projection.getColumnRefMap().get(ref));
}
optExpression.getOp().setProjection(new Projection(newOutputProjections));
}
for (ScalarOperator value : optExpression.getOp().getProjection().getColumnRefMap().values()) {
requiredColumns.union(value.getUsedColumns());
}
}
return optExpression.getOp().accept(this, optExpression, requiredColumns);
}
Code review comment: We can not assert just one file, This is because `ParallelFiniteTestSource` may spread data across multiple checkpoints.

Code before review:
public void testNonPartition() throws Exception {
tEnv().executeSql("CREATE TABLE sink_table (a int, b string, c string) with (" + options() + ")");
tEnv().executeSql("insert into sink_table select * from my_table").await();
List<Row> results = toListAndClose(tEnv().executeSql("select * from sink_table").collect());
results.sort(Comparator.comparingInt(o -> (Integer) o.getField(0)));
assertEquals(rows, results);
File[] files = new File(URI.create(resultPath)).listFiles(
(dir, name) -> name.startsWith("compacted-part-"));
assertEquals(Arrays.toString(files), 1, files.length);
String fileName = files[0].getName();
assertTrue(fileName, fileName.startsWith("compacted-part-"));
}

Line under review: assertEquals(Arrays.toString(files), 1, files.length);

Code after addressing the review:
public void testNonPartition() throws Exception {
tEnv().executeSql("CREATE TABLE sink_table (a int, b string, c string) with (" + options() + ")");
tEnv().executeSql("insert into sink_table select * from my_table").await();
assertIterator(tEnv().executeSql("select * from sink_table").collect());
assertFiles(new File(URI.create(resultPath)).listFiles(), false);
}
Code review comment: Can remove the todo as the root validity check is gone. 

Code before review:
public Path normalize() {
Deque<String> stack = new ArrayDeque<>();
String[] pathElements = this.splitToElements();
Path root = this.getRoot();
String rootStr = root == null ? null : root.toString();
for (String element : pathElements) {
if (element.equals(".")) {
continue;
} else if (element.equals("..")) {
if (rootStr != null) {
if (!stack.isEmpty() && stack.peekLast().equals(rootStr)) {
continue;
} else {
stack.removeLast();
}
} else {
if (stack.isEmpty()) {
stack.addLast(element);
} else if (stack.peek().equals("..")) {
stack.addLast(element);
} else {
stack.removeLast();
}
}
} else {
stack.addLast(element);
}
}
return this.parentFileSystem.getPath("", Arrays.copyOf(stack.toArray(), stack.size(), String[].class));
}

Line under review: Path root = this.getRoot();

Code after addressing the review:
public Path normalize() {
Deque<String> stack = new ArrayDeque<>();
String[] pathElements = this.splitToElements();
Path root = this.getRoot();
String rootStr = root == null ? null : root.toString();
for (String element : pathElements) {
if (element.equals(".")) {
continue;
} else if (element.equals("..")) {
if (rootStr != null) {
if (!stack.isEmpty() && stack.peekLast().equals(rootStr)) {
continue;
} else {
stack.removeLast();
}
} else {
if (stack.isEmpty()) {
stack.addLast(element);
} else if (stack.peek().equals("..")) {
stack.addLast(element);
} else {
stack.removeLast();
}
}
} else {
stack.addLast(element);
}
}
return this.parentFileSystem.getPath("", stack.toArray(new String[0]));
}
Code review comment: @pedroigor Right, at the moment no local JWE decryption is possible, so they are technically opaque for Quarkus

Code before review:
public static boolean isOpaqueToken(String token) {
return new StringTokenizer(token, ".").countTokens() != 3;
}

Line under review: return new StringTokenizer(token, ".").countTokens() != 3;

Code after addressing the review:
public static boolean isOpaqueToken(String token) {
return new StringTokenizer(token, ".").countTokens() != 3;
}
Code review comment: There probably should be some abstract code based on what Stuart @stuartwdouglas did, so that the default authorizer and this one do not duplicate.  What was the problem with only plugging in a custom `HttpSecurityPolicy` ?

Code before review:
public CompletionStage<SecurityIdentity> checkPermission(RoutingContext routingContext) {
VertxHttpFacade httpFacade = new VertxHttpFacade(routingContext);
AuthorizationContext result = delegate.authorize(httpFacade);
if (result.isGranted()) {
QuarkusHttpUser user = (QuarkusHttpUser) routingContext.user();
if (user == null) {
return attemptAnonymousAuthentication(routingContext);
}
return enhanceSecurityIdentity(user.getSecurityIdentity(), result);
}
return CompletableFuture.completedFuture(null);
}

Line under review: if (result.isGranted()) {

Code after addressing the review:
public CompletionStage<SecurityIdentity> checkPermission(RoutingContext routingContext) {
VertxHttpFacade httpFacade = new VertxHttpFacade(routingContext);
AuthorizationContext result = delegate.authorize(httpFacade);
if (result.isGranted()) {
QuarkusHttpUser user = (QuarkusHttpUser) routingContext.user();
if (user == null) {
return attemptAnonymousAuthentication(routingContext);
}
return enhanceSecurityIdentity(user.getSecurityIdentity(), result);
}
return CompletableFuture.completedFuture(null);
}
Code review comment: > Actually with this implementation, synchronization is not required unless conf.write will explode if there is some concurrent modification.  Yeah thinking again if conf is modified half way the whole writeExternal won't work anyways, going to remove the synchronized block

Code before review:
public void writeExternal(ObjectOutput out) throws IOException {
String canonicalName;
synchronized (this) {
canonicalName = conf.getClass().getCanonicalName();
if (confMutated) {
confMutated = false;
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
try (DataOutputStream dos = new DataOutputStream(baos)) {
conf.write(dos);
serializationCache = baos.toByteArray();
}
}
}
out.writeUTF(canonicalName);
out.write(serializationCache);
}

Line under review: out.writeUTF(canonicalName);

Code after addressing the review:
public void writeExternal(ObjectOutput out) throws IOException {
if (confMutated || serializationCache == null) {
confMutated = false;
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
try (DataOutputStream dos = new DataOutputStream(baos)) {
conf.write(dos);
serializationCache = baos.toByteArray();
}
}
out.writeUTF(conf.getClass().getCanonicalName());
out.write(serializationCache);
}
Code review comment: actually this a little confused to me, QualifiedNameContext named as db. but we get catalog from this db variable. how about renaming the QualifiedNameContext variable name of ShowDatabasesStatementContext

Code before review:
public ParseNode visitShowDatabasesStatement(StarRocksParser.ShowDatabasesStatementContext context) {
String catalog = null;
if (context.db != null) {
QualifiedName qualifiedName = getQualifiedName(context.db);
catalog = qualifiedName.toString();
}
if (catalog == null) {
if (context.pattern != null) {
StringLiteral stringLiteral = (StringLiteral) visit(context.pattern);
return new ShowDbStmt(stringLiteral.getValue());
} else if (context.expression() != null) {
return new ShowDbStmt(null, (Expr) visit(context.expression()));
} else {
return new ShowDbStmt(null, null, null);
}
} else {
if (context.pattern != null) {
StringLiteral stringLiteral = (StringLiteral) visit(context.pattern);
return new ShowDbStmt(stringLiteral.getValue(), catalog);
} else if (context.expression() != null) {
return new ShowDbStmt(null, (Expr) visit(context.expression()), catalog);
} else {
return new ShowDbStmt(null, null, catalog);
}
}
}

Line under review: QualifiedName qualifiedName = getQualifiedName(context.db);

Code after addressing the review:
public ParseNode visitShowDatabasesStatement(StarRocksParser.ShowDatabasesStatementContext context) {
String catalog = null;
if (context.catalog != null) {
QualifiedName dbName = getQualifiedName(context.catalog);
catalog = dbName.toString();
}
if (context.pattern != null) {
StringLiteral stringLiteral = (StringLiteral) visit(context.pattern);
return new ShowDbStmt(stringLiteral.getValue(), catalog);
} else if (context.expression() != null) {
return new ShowDbStmt(null, (Expr) visit(context.expression()), catalog);
} else {
return new ShowDbStmt(null, null, catalog);
}
}
Code review comment: It does (if argument is deployment id the config server will be used)

Code before review:
private boolean testerContainersAreUp(ApplicationId id, ZoneId zoneId, DualLogger logger) {
if (useConfigServerForTesterAPI(zoneId)) {
DeploymentId deploymentId = new DeploymentId(id, zoneId);
if (controller.jobController().cloud().testerReady(deploymentId)) {
return true;
} else {
logger.log("Failed to get 100 consecutive OKs from tester container for " + deploymentId);
return false;
}
} else {
return containersAreUp(id, zoneId, logger);
}
}

Line under review: if (controller.jobController().cloud().testerReady(deploymentId)) {

Code after addressing the review:
private boolean testerContainersAreUp(ApplicationId id, ZoneId zoneId, DualLogger logger) {
if (useConfigServerForTesterAPI(zoneId)) {
DeploymentId deploymentId = new DeploymentId(id, zoneId);
if (controller.jobController().cloud().testerReady(deploymentId)) {
return true;
} else {
logger.log("Failed to get 100 consecutive OKs from tester container for " + deploymentId);
return false;
}
} else {
return containersAreUp(id, zoneId, logger);
}
}
Code review comment: ```suggestion                 .setDescription("The temperature unit to use. Infer this from the user's location."); ```

Code before review:
private static FunctionParameters getCurrentWeatherFunctionParameters() {
FunctionProperties location = new FunctionProperties()
.setType("string")
.setDescription("The city and state, e.g. San Francisco, CA");
FunctionProperties unit = new FunctionProperties()
.setType("string")
.setEnumString(Arrays.asList("celsius", "fahrenheit"))
.setDescription("The temperature unit to use. Infer this from the users location.");
Map<String, FunctionProperties> props = new HashMap<>();
props.put("location", location);
props.put("unit", unit);
return new FunctionParameters()
.setType("object")
.setRequiredPropertyNames(Arrays.asList("location", "unit"))
.setProperties(props);
}

Line under review: .setDescription("The temperature unit to use. Infer this from the users location.");

Code after addressing the review:
private static FunctionParameters getCurrentWeatherFunctionParameters() {
FunctionProperties location = new FunctionProperties()
.setType("string")
.setDescription("The city and state, e.g. San Francisco, CA");
FunctionProperties unit = new FunctionProperties()
.setType("string")
.setEnumString(Arrays.asList("celsius", "fahrenheit"))
.setDescription("The temperature unit to use. Infer this from the user's location.");
Map<String, FunctionProperties> props = new HashMap<>();
props.put("location", location);
props.put("unit", unit);
return new FunctionParameters()
.setType("object")
.setRequiredPropertyNames(Arrays.asList("location", "unit"))
.setProperties(props);
}
Code review comment: consider calling drain here to avoid returning a single frame even if multiple frames could be decoded

Code before review:
public int read(ByteBuffer dst) throws IOException {
verifyHandshakeCompleted();
int bytesUnwrapped = applicationDataUnwrap(dst);
if (bytesUnwrapped > 0) return bytesUnwrapped;
int bytesRead = channelRead();
if (bytesRead == 0) return 0;
return drain(dst);
}

Line under review: int bytesUnwrapped = applicationDataUnwrap(dst);

Code after addressing the review:
public int read(ByteBuffer dst) throws IOException {
verifyHandshakeCompleted();
int bytesUnwrapped = drain(dst);
if (bytesUnwrapped > 0) return bytesUnwrapped;
int bytesRead = channelRead();
if (bytesRead == 0) return 0;
return drain(dst);
}
Code review comment: Move this line to `else` block

Code before review:
public void createFunction(CreateFunctionStmt stmt) throws UserException {
FunctionName name = stmt.getFunctionName();
InternalCatalog internalCatalog = getInternalCatalog();
if (SetType.GLOBAL.equals(stmt.getType())) {
globalFunctionMgr.addFunction(stmt.getFunction(), stmt.isIfNotExists());
} else {
Database db = internalCatalog.getDbOrDdlException(name.getDb());
db.addFunction(stmt.getFunction(), stmt.isIfNotExists());
}
}

Line under review: InternalCatalog internalCatalog = getInternalCatalog();

Code after addressing the review:
public void createFunction(CreateFunctionStmt stmt) throws UserException {
if (SetType.GLOBAL.equals(stmt.getType())) {
globalFunctionMgr.addFunction(stmt.getFunction(), stmt.isIfNotExists());
} else {
Database db = getInternalCatalog().getDbOrDdlException(stmt.getFunctionName().getDb());
db.addFunction(stmt.getFunction(), stmt.isIfNotExists());
}
}
Code review comment: @SupunS No switch case means, `( )` is considered to be `NIL_LITERAL` kind and `NULL` is considered to be `NULL_KEYWORD` kind, and will have separate `pareseNilLiteral( )`, `pareseNullKeyword( )` methods ?  

Code before review:
private STNode parseNilLiteral() {
STToken token = peek();
switch (token.kind) {
case NULL_KEYWORD:
STNode nullKeyword = consume();
STNode emptyNode = STNodeFactory.createEmptyNode();
return STNodeFactory.createNilLiteral(nullKeyword, emptyNode);
case OPEN_PAREN_TOKEN:
startContext(ParserRuleContext.NIL_LITERAL);
STNode openParenthesisToken = parseOpenParenthesis();
STNode closeParenthesisToken = parseCloseParenthesis();
endContext();
return STNodeFactory.createNilLiteral(openParenthesisToken, closeParenthesisToken);
default:
Solution sol = recover(token, ParserRuleContext.NIL_LITERAL);
return sol.recoveredNode;
}
}

Line under review: }

Code after addressing the review:
private STNode parseNilLiteral() {
startContext(ParserRuleContext.NIL_LITERAL);
STNode openParenthesisToken = parseOpenParenthesis();
STNode closeParenthesisToken = parseCloseParenthesis();
endContext();
return STNodeFactory.createNilLiteralNode(openParenthesisToken, closeParenthesisToken);
}
Code review comment: Technically, there is no problem of passing beans there.

Code before review:
public boolean implies(Permission permission) {
if (permission instanceof WorkdayPermission) {
WorkdayPermission that = (WorkdayPermission) permission;
if (that.getName().equals("worker") && that.getActions().contains("adult")) {
final WorkdayEvaluator workdayEvaluator = Arc.container().instance(WorkdayEvaluator.class).get();
return workdayEvaluator.isWorkday(that.day);
}
}
return false;
}

Line under review: if (that.getName().equals("worker") && that.getActions().contains("adult")) {

Code after addressing the review:
public boolean implies(Permission permission) {
if (permission instanceof WorkdayPermission) {
WorkdayPermission that = (WorkdayPermission) permission;
if (that.getName().equals("worker") && that.getActions().contains("adult")) {
final WorkdayEvaluator workdayEvaluator = Arc.container().instance(WorkdayEvaluator.class).get();
return workdayEvaluator.isWorkday(that.day);
}
}
return false;
}
Code review comment: @cheese8 What is the difference between this change and the original logic?

Code before review:
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
Preconditions.checkState(((WhereAvailable) sqlStatementContext).getWhere().isPresent());
Collection<SubstitutableColumnNameToken> result = new LinkedHashSet<>();
ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates);
andPredicates.forEach(each -> result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames)));
return result;
}

Line under review: andPredicates.forEach(each -> result.addAll(generateSQLTokens(each.getPredicates(), columnTableNames)));

Code after addressing the review:
public Collection<SubstitutableColumnNameToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
Collection<SubstitutableColumnNameToken> result = new LinkedHashSet<>();
Collection<AndPredicate> andPredicates = new LinkedHashSet<>();
if (isGenerateSQLTokenForEncryptOnWhereAvailable(sqlStatementContext)) {
ExpressionSegment expression = ((WhereAvailable) sqlStatementContext).getWhere().get().getExpr();
andPredicates.addAll(ExpressionExtractUtil.getAndPredicates(expression));
}
Collection<WhereSegment> whereSegments = Collections.emptyList();
if (sqlStatementContext instanceof SelectStatementContext) {
whereSegments = WhereExtractUtil.getJoinWhereSegments((SelectStatement) sqlStatementContext.getSqlStatement());
andPredicates.addAll(whereSegments.stream().map(each -> ExpressionExtractUtil.getAndPredicates(each.getExpr())).flatMap(Collection::stream).collect(Collectors.toList()));
}
Map<String, String> columnTableNames = getColumnTableNames(sqlStatementContext, andPredicates, whereSegments);
result.addAll(andPredicates.stream().map(each -> generateSQLTokens(each.getPredicates(), columnTableNames)).flatMap(Collection::stream).collect(Collectors.toList()));
return result;
}
Code review comment: shouldn't we iterate over the whole set of messages? It might not be the last one.

Code before review:
public void testRegisterHealthOnBlockingThreadStep1() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
try {
RestAssured.defaultParser = Parser.JSON;
for (int i = 0; i < 3; i++) {
RestAssured.when().get("/q/health").then()
.body("status", is("UP"),
"checks.status", contains("UP"),
"checks.name", contains("blocking"));
}
} finally {
RestAssured.reset();
}
if (!inMemoryLogHandler.getRecords().isEmpty()) {
LogRecord logRecord = inMemoryLogHandler.getRecords().get(0);
assertEquals(Level.WARNING, logRecord.getLevel());
assertFalse(logRecord.getMessage().contains("has been blocked for"),
"The blocking health check ran on eventloop thread");
}
}

Line under review: assertFalse(logRecord.getMessage().contains("has been blocked for"),

Code after addressing the review:
public void testRegisterHealthOnBlockingThreadStep1() {
given()
.when().get("/start-health")
.then().statusCode(200);
try {
RestAssured.defaultParser = Parser.JSON;
for (int i = 0; i < 3; i++) {
RestAssured.when().get("/q/health").then()
.body("status", is("UP"),
"checks.status", contains("UP"),
"checks.name", contains("blocking"));
}
} finally {
RestAssured.reset();
}
}
Code review comment: If we are to introduce error reporting will need considerable changes. error reporting require package to be loaded atm (ie; for it to be in `BLangDiagnosticLog.packageCache`).  Hence, going with throwing exception

Code before review:
private void defineImportPackage(DataInputStream dataInStream) throws IOException {
String orgName = getStringCPEntryValue(dataInStream);
String pkgName = getStringCPEntryValue(dataInStream);
String moduleName = getStringCPEntryValue(dataInStream);
String pkgVersion = getStringCPEntryValue(dataInStream);
PackageID importPkgID = createPackageID(orgName, pkgName, moduleName, pkgVersion);
BPackageSymbol importPackageSymbol = packageCache.getSymbol(importPkgID);
if (importPackageSymbol == null) {
throw new BLangCompilerException("cannot resolve module " + importPkgID);
}
this.env.pkgSymbol.scope.define(importPkgID.name, importPackageSymbol);
this.env.pkgSymbol.imports.add(importPackageSymbol);
}

Line under review: throw new BLangCompilerException("cannot resolve module " + importPkgID);

Code after addressing the review:
private void defineImportPackage(DataInputStream dataInStream) throws IOException {
String orgName = getStringCPEntryValue(dataInStream);
String pkgName = getStringCPEntryValue(dataInStream);
String moduleName = getStringCPEntryValue(dataInStream);
String pkgVersion = getStringCPEntryValue(dataInStream);
PackageID importPkgID = createPackageID(orgName, pkgName, moduleName, pkgVersion);
BPackageSymbol importPackageSymbol = packageCache.getSymbol(importPkgID);
if (importPackageSymbol == null) {
throw new BLangCompilerException("cannot resolve module " + importPkgID);
}
this.env.pkgSymbol.scope.define(importPkgID.name, importPackageSymbol);
this.env.pkgSymbol.imports.add(importPackageSymbol);
}
Code review comment: P: (p(col) or col is null) and q(col)  if when element in col is null,  both p(col) and q(col) is false, then P is false, p(col) and q(col) is false too, if when element in col is not null, then P can be reduced p(col) and q(col),  so P can be always reduced to p(col) and q(col) if col=false implies p(col) and q(col) is false

Code before review:
public ScalarOperator visitInPredicate(InPredicateOperator predicate, Void context) {
ScalarOperator negation = new InPredicateOperator(!predicate.isNotIn(), predicate.getChildren());
if (predicate.getChild(0).isNullable()) {
ScalarOperator isNull = new IsNullPredicateOperator(predicate.getChild(0));
return new CompoundPredicateOperator(CompoundType.OR, negation, isNull);
} else {
return negation;
}
}

Line under review: return new CompoundPredicateOperator(CompoundType.OR, negation, isNull);

Code after addressing the review:
public ScalarOperator visitInPredicate(InPredicateOperator predicate, Void context) {
ScalarOperator negation = new InPredicateOperator(!predicate.isNotIn(), predicate.getChildren());
if (predicate.getChild(0).isNullable()) {
ScalarOperator isNull = new IsNullPredicateOperator(predicate.getChild(0));
return new CompoundPredicateOperator(CompoundType.OR, negation, isNull);
} else {
return negation;
}
}
Code review comment: Any reason to have it as 'guessOrgName' ? Can change it to 'orgName'

Code before review:
private String getOrgName() {
String guessOrgName = System.getProperty("user.name");
if (guessOrgName == null) {
guessOrgName = "my_org";
} else {
guessOrgName = guessOrgName.toLowerCase(Locale.getDefault());
}
return guessOrgName;
}

Line under review: String guessOrgName = System.getProperty("user.name");

Code after addressing the review:
private String getOrgName() {
String orgName = System.getProperty("user.name");
if (orgName == null) {
orgName = "my_org";
} else {
orgName = orgName.toLowerCase(Locale.getDefault());
}
return orgName;
}
Code review comment: Yes, unfortunately the open project that I used for POM parsing only parses a BOM file (packaging as POM).  I will be removing that dependency completely due to some other issues like it does not support adding comments to the POM file (which we need for versioning management in engsys).

Code before review:
static List<BomDependency> parsePomFileContent(Reader responseStream) {
List<BomDependency> bomDependencies = new ArrayList<>();
ObjectMapper mapper = new XmlMapper();
try {
HashMap<String, Object> value = mapper.readValue(responseStream, HashMap.class);
Object packagingProp = value.getOrDefault("packaging", null);
if(packagingProp != null && packagingProp.toString().equalsIgnoreCase("pom")) {
return parsePomFileContent(responseStream);
}
HashMap<String, Object> dependenciesTag = (HashMap<String, Object>)value.getOrDefault("dependencies", null);
if(dependenciesTag == null) {
return null;
}
ArrayList<HashMap<String, Object>> dependencies =  (ArrayList<HashMap<String, Object>>) dependenciesTag.getOrDefault("dependency", null);
for(HashMap<String, Object> dependency: dependencies) {
String groupId = (String) dependency.getOrDefault("groupId", null);
String artifactId = (String) dependency.getOrDefault("artifactId", null);
String version = (String) dependency.getOrDefault("version", null);
String scope = (String) dependency.getOrDefault("scope", ScopeType.COMPILE.toString());
ScopeType scopeType = ScopeType.COMPILE;
switch(scope) {
case "test" : scopeType = ScopeType.TEST;
break;
default: scopeType = ScopeType.COMPILE;
}
bomDependencies.add(new BomDependency(groupId, artifactId, version, scopeType));
}
} catch (IOException exception) {
exception.printStackTrace();
}
return bomDependencies.stream().distinct().collect(Collectors.toList());
}

Line under review: ObjectMapper mapper = new XmlMapper();

Code after addressing the review:
static List<BomDependency> parsePomFileContent(Reader responseStream) {
List<BomDependency> bomDependencies = new ArrayList<>();
ObjectMapper mapper = new XmlMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
try {
Model value = mapper.readValue(responseStream, Model.class);
List<Dependency> dependencies = value.getDependencies();
if(dependencies == null) {
return bomDependencies;
}
for(Dependency dependency : dependencies) {
ScopeType scopeType = ScopeType.COMPILE;
if("test".equals(dependency.getScope())) {
scopeType = ScopeType.TEST;
}
bomDependencies.add(new BomDependency(
dependency.getGroupId(),
dependency.getArtifactId(),
dependency.getVersion(),
scopeType));
}
} catch (IOException exception) {
exception.printStackTrace();
}
return bomDependencies.stream().distinct().collect(Collectors.toList());
}
Code review comment: The recording for this test turned out empty because we are not waiting for the async operation to complete. ```suggestion                 }).verifyComplete(); ```

Code before review:
public void importPemCertificate(HttpClient httpClient, CertificateServiceVersion serviceVersion) throws IOException {
createCertificateAsyncClient(httpClient, serviceVersion);
importPemCertificateRunner((importCertificateOptions) -> {
StepVerifier.create(certificateAsyncClient.importCertificate(importCertificateOptions))
.assertNext(importedCertificate -> {
assertEquals(importCertificateOptions.isEnabled(), importedCertificate.getProperties().isEnabled());
assertEquals(CertificateContentType.PEM, importedCertificate.getPolicy().getContentType());
});
});
}

Line under review: });

Code after addressing the review:
public void importPemCertificate(HttpClient httpClient, CertificateServiceVersion serviceVersion) throws IOException {
createCertificateAsyncClient(httpClient, serviceVersion);
importPemCertificateRunner((importCertificateOptions) -> {
StepVerifier.create(certificateAsyncClient.importCertificate(importCertificateOptions))
.assertNext(importedCertificate -> {
assertEquals(importCertificateOptions.isEnabled(), importedCertificate.getProperties().isEnabled());
assertEquals(CertificateContentType.PEM, importedCertificate.getPolicy().getContentType());
}).verifyComplete();
});
}
Code review comment: Any particular reason to use 100_000 ?

Code before review:
private int fluxSequentialMergePrefetch(FeedOptions options, int numberOfPartitions, int pageSize, int fluxConcurrency) {
int maxBufferedItemCount = options.getMaxBufferedItemCount();
if (maxBufferedItemCount <= 0) {
maxBufferedItemCount = Math.min(Configs.CPU_CNT * numberOfPartitions * pageSize, 100_000);
}
int fluxPrefetch = Math.max(maxBufferedItemCount / (Math.max(fluxConcurrency * pageSize, 1)), 1);
return Math.min(fluxPrefetch, Queues.XS_BUFFER_SIZE);
}

Line under review: maxBufferedItemCount = Math.min(Configs.CPU_CNT * numberOfPartitions * pageSize, 100_000);

Code after addressing the review:
private int fluxSequentialMergePrefetch(FeedOptions options, int numberOfPartitions, int pageSize, int fluxConcurrency) {
int maxBufferedItemCount = options.getMaxBufferedItemCount();
if (maxBufferedItemCount <= 0) {
maxBufferedItemCount = Math.min(Configs.getCPUCnt() * numberOfPartitions * pageSize, 100_000);
}
int fluxPrefetch = Math.max(maxBufferedItemCount / (Math.max(fluxConcurrency * pageSize, 1)), 1);
return Math.min(fluxPrefetch, Queues.XS_BUFFER_SIZE);
}